OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/background/background_contents_service.h" | 11 #include "chrome/browser/background/background_contents_service.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 13 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
14 #include "chrome/browser/tab_contents/background_contents.h" | 14 #include "chrome/browser/tab_contents/background_contents.h" |
15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/testing_browser_process.h" | 18 #include "chrome/test/testing_browser_process.h" |
18 #include "chrome/test/testing_browser_process_test.h" | 19 #include "chrome/test/testing_browser_process_test.h" |
19 #include "chrome/test/testing_profile.h" | 20 #include "chrome/test/testing_profile.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
23 | 24 |
24 class BackgroundContentsServiceTest : public TestingBrowserProcessTest { | 25 class BackgroundContentsServiceTest : public TestingBrowserProcessTest { |
25 public: | 26 public: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void SendOpenedNotification(BackgroundContentsService* service) { | 67 void SendOpenedNotification(BackgroundContentsService* service) { |
67 string16 frame_name = ASCIIToUTF16("background"); | 68 string16 frame_name = ASCIIToUTF16("background"); |
68 BackgroundContentsOpenedDetails details = { | 69 BackgroundContentsOpenedDetails details = { |
69 this, frame_name, appid_ }; | 70 this, frame_name, appid_ }; |
70 service->BackgroundContentsOpened(&details); | 71 service->BackgroundContentsOpened(&details); |
71 } | 72 } |
72 | 73 |
73 virtual void Navigate(GURL url) { | 74 virtual void Navigate(GURL url) { |
74 url_ = url; | 75 url_ = url; |
75 NotificationService::current()->Notify( | 76 NotificationService::current()->Notify( |
76 NotificationType::BACKGROUND_CONTENTS_NAVIGATED, | 77 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
77 Source<Profile>(profile_), | 78 Source<Profile>(profile_), |
78 Details<BackgroundContents>(this)); | 79 Details<BackgroundContents>(this)); |
79 } | 80 } |
80 virtual const GURL& GetURL() const { return url_; } | 81 virtual const GURL& GetURL() const { return url_; } |
81 | 82 |
82 void MockClose(Profile* profile) { | 83 void MockClose(Profile* profile) { |
83 NotificationService::current()->Notify( | 84 NotificationService::current()->Notify( |
84 NotificationType::BACKGROUND_CONTENTS_CLOSED, | 85 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, |
85 Source<Profile>(profile), | 86 Source<Profile>(profile), |
86 Details<BackgroundContents>(this)); | 87 Details<BackgroundContents>(this)); |
87 delete this; | 88 delete this; |
88 } | 89 } |
89 | 90 |
90 ~MockBackgroundContents() { | 91 ~MockBackgroundContents() { |
91 NotificationService::current()->Notify( | 92 NotificationService::current()->Notify( |
92 NotificationType::BACKGROUND_CONTENTS_DELETED, | 93 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
93 Source<Profile>(profile_), | 94 Source<Profile>(profile_), |
94 Details<BackgroundContents>(this)); | 95 Details<BackgroundContents>(this)); |
95 } | 96 } |
96 | 97 |
97 const string16& appid() { return appid_; } | 98 const string16& appid() { return appid_; } |
98 | 99 |
99 private: | 100 private: |
100 GURL url_; | 101 GURL url_; |
101 | 102 |
102 // The ID of our parent application | 103 // The ID of our parent application |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 contents->Navigate(url); | 223 contents->Navigate(url); |
223 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 224 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
224 contents2->Navigate(url2); | 225 contents2->Navigate(url2); |
225 EXPECT_EQ(2U, GetPrefs(&profile)->size()); | 226 EXPECT_EQ(2U, GetPrefs(&profile)->size()); |
226 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); | 227 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); |
227 EXPECT_FALSE(service.IsTracked(contents)); | 228 EXPECT_FALSE(service.IsTracked(contents)); |
228 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); | 229 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); |
229 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 230 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
230 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); | 231 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); |
231 } | 232 } |
OLD | NEW |