OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/process_manager.h" | 5 #include "extensions/browser/process_manager.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | |
8 #include "content/public/browser/content_browser_client.h" | 7 #include "content/public/browser/content_browser_client.h" |
9 #include "content/public/browser/notification_service.h" | 8 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/site_instance.h" | 9 #include "content/public/browser/site_instance.h" |
11 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
12 #include "content/public/test/test_browser_context.h" | 11 #include "content/public/test/test_browser_context.h" |
13 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" |
14 #include "extensions/browser/extensions_test.h" | 13 #include "extensions/browser/extensions_test.h" |
| 14 #include "extensions/browser/notification_types.h" |
15 #include "extensions/browser/process_manager_delegate.h" | 15 #include "extensions/browser/process_manager_delegate.h" |
16 #include "extensions/browser/test_extensions_browser_client.h" | 16 #include "extensions/browser/test_extensions_browser_client.h" |
17 | 17 |
18 using content::BrowserContext; | 18 using content::BrowserContext; |
19 using content::SiteInstance; | 19 using content::SiteInstance; |
20 using content::TestBrowserContext; | 20 using content::TestBrowserContext; |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 | 23 |
24 namespace { | 24 namespace { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) { | 101 TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) { |
102 // Test for a normal context ProcessManager. | 102 // Test for a normal context ProcessManager. |
103 scoped_ptr<ProcessManager> manager1(ProcessManager::CreateForTesting( | 103 scoped_ptr<ProcessManager> manager1(ProcessManager::CreateForTesting( |
104 original_context(), extension_registry())); | 104 original_context(), extension_registry())); |
105 | 105 |
106 EXPECT_EQ(original_context(), manager1->GetBrowserContext()); | 106 EXPECT_EQ(original_context(), manager1->GetBrowserContext()); |
107 EXPECT_EQ(0u, manager1->background_hosts().size()); | 107 EXPECT_EQ(0u, manager1->background_hosts().size()); |
108 | 108 |
109 // It observes other notifications from this context. | 109 // It observes other notifications from this context. |
110 EXPECT_TRUE(IsRegistered(manager1.get(), | 110 EXPECT_TRUE(IsRegistered(manager1.get(), |
111 chrome::NOTIFICATION_EXTENSIONS_READY, | 111 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
112 original_context())); | 112 original_context())); |
113 EXPECT_TRUE(IsRegistered(manager1.get(), | 113 EXPECT_TRUE(IsRegistered(manager1.get(), |
114 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 114 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
115 original_context())); | 115 original_context())); |
| 116 EXPECT_TRUE( |
| 117 IsRegistered(manager1.get(), |
| 118 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 119 original_context())); |
116 EXPECT_TRUE(IsRegistered(manager1.get(), | 120 EXPECT_TRUE(IsRegistered(manager1.get(), |
117 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 121 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
118 original_context())); | |
119 EXPECT_TRUE(IsRegistered(manager1.get(), | |
120 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | |
121 original_context())); | 122 original_context())); |
122 | 123 |
123 // Test for an incognito context ProcessManager. | 124 // Test for an incognito context ProcessManager. |
124 scoped_ptr<ProcessManager> manager2( | 125 scoped_ptr<ProcessManager> manager2( |
125 ProcessManager::CreateIncognitoForTesting(incognito_context(), | 126 ProcessManager::CreateIncognitoForTesting(incognito_context(), |
126 original_context(), | 127 original_context(), |
127 manager1.get(), | 128 manager1.get(), |
128 extension_registry())); | 129 extension_registry())); |
129 | 130 |
130 EXPECT_EQ(incognito_context(), manager2->GetBrowserContext()); | 131 EXPECT_EQ(incognito_context(), manager2->GetBrowserContext()); |
131 EXPECT_EQ(0u, manager2->background_hosts().size()); | 132 EXPECT_EQ(0u, manager2->background_hosts().size()); |
132 | 133 |
133 // Some notifications are observed for the original context. | 134 // Some notifications are observed for the original context. |
134 EXPECT_TRUE(IsRegistered(manager2.get(), | 135 EXPECT_TRUE(IsRegistered(manager2.get(), |
135 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 136 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
136 original_context())); | 137 original_context())); |
137 | 138 |
138 // Some notifications are observed for the incognito context. | 139 // Some notifications are observed for the incognito context. |
139 EXPECT_TRUE(IsRegistered(manager2.get(), | 140 EXPECT_TRUE(IsRegistered(manager2.get(), |
140 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 141 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
141 incognito_context())); | 142 incognito_context())); |
142 | 143 |
143 // Some are not observed at all. | 144 // Some are not observed at all. |
144 EXPECT_FALSE(IsRegistered(manager2.get(), | 145 EXPECT_FALSE( |
145 chrome::NOTIFICATION_EXTENSIONS_READY, | 146 IsRegistered(manager2.get(), |
146 original_context())); | 147 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 148 original_context())); |
147 } | 149 } |
148 | 150 |
149 // Test that startup background hosts are created when the extension system | 151 // Test that startup background hosts are created when the extension system |
150 // becomes ready. | 152 // becomes ready. |
151 // | 153 // |
152 // NOTE: This test and those that follow do not try to create ExtensionsHosts | 154 // NOTE: This test and those that follow do not try to create ExtensionsHosts |
153 // because ExtensionHost is tightly coupled to WebContents and can't be | 155 // because ExtensionHost is tightly coupled to WebContents and can't be |
154 // constructed in unit tests. | 156 // constructed in unit tests. |
155 TEST_F(ProcessManagerTest, CreateBackgroundHostsOnExtensionsReady) { | 157 TEST_F(ProcessManagerTest, CreateBackgroundHostsOnExtensionsReady) { |
156 scoped_ptr<ProcessManager> manager(ProcessManager::CreateForTesting( | 158 scoped_ptr<ProcessManager> manager(ProcessManager::CreateForTesting( |
157 original_context(), extension_registry())); | 159 original_context(), extension_registry())); |
158 ASSERT_FALSE(manager->startup_background_hosts_created_for_test()); | 160 ASSERT_FALSE(manager->startup_background_hosts_created_for_test()); |
159 | 161 |
160 // Simulate the extension system becoming ready. | 162 // Simulate the extension system becoming ready. |
161 content::NotificationService::current()->Notify( | 163 content::NotificationService::current()->Notify( |
162 chrome::NOTIFICATION_EXTENSIONS_READY, | 164 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
163 content::Source<BrowserContext>(original_context()), | 165 content::Source<BrowserContext>(original_context()), |
164 content::NotificationService::NoDetails()); | 166 content::NotificationService::NoDetails()); |
165 EXPECT_TRUE(manager->startup_background_hosts_created_for_test()); | 167 EXPECT_TRUE(manager->startup_background_hosts_created_for_test()); |
166 } | 168 } |
167 | 169 |
168 // Test that startup background hosts can be created explicitly before the | 170 // Test that startup background hosts can be created explicitly before the |
169 // extension system is ready (this is the normal pattern in Chrome). | 171 // extension system is ready (this is the normal pattern in Chrome). |
170 TEST_F(ProcessManagerTest, CreateBackgroundHostsExplicitly) { | 172 TEST_F(ProcessManagerTest, CreateBackgroundHostsExplicitly) { |
171 scoped_ptr<ProcessManager> manager(ProcessManager::CreateForTesting( | 173 scoped_ptr<ProcessManager> manager(ProcessManager::CreateForTesting( |
172 original_context(), extension_registry())); | 174 original_context(), extension_registry())); |
(...skipping 12 matching lines...) Expand all Loading... |
185 original_context(), extension_registry())); | 187 original_context(), extension_registry())); |
186 ASSERT_FALSE(manager->startup_background_hosts_created_for_test()); | 188 ASSERT_FALSE(manager->startup_background_hosts_created_for_test()); |
187 | 189 |
188 // Don't create background hosts if the delegate says to defer them. | 190 // Don't create background hosts if the delegate says to defer them. |
189 process_manager_delegate()->defer_creating_startup_background_hosts_ = true; | 191 process_manager_delegate()->defer_creating_startup_background_hosts_ = true; |
190 manager->MaybeCreateStartupBackgroundHosts(); | 192 manager->MaybeCreateStartupBackgroundHosts(); |
191 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); | 193 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); |
192 | 194 |
193 // The extension system becoming ready still doesn't create the hosts. | 195 // The extension system becoming ready still doesn't create the hosts. |
194 content::NotificationService::current()->Notify( | 196 content::NotificationService::current()->Notify( |
195 chrome::NOTIFICATION_EXTENSIONS_READY, | 197 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
196 content::Source<BrowserContext>(original_context()), | 198 content::Source<BrowserContext>(original_context()), |
197 content::NotificationService::NoDetails()); | 199 content::NotificationService::NoDetails()); |
198 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); | 200 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); |
199 | 201 |
200 // Once the embedder is ready the background hosts can be created. | 202 // Once the embedder is ready the background hosts can be created. |
201 process_manager_delegate()->defer_creating_startup_background_hosts_ = false; | 203 process_manager_delegate()->defer_creating_startup_background_hosts_ = false; |
202 manager->MaybeCreateStartupBackgroundHosts(); | 204 manager->MaybeCreateStartupBackgroundHosts(); |
203 EXPECT_TRUE(manager->startup_background_hosts_created_for_test()); | 205 EXPECT_TRUE(manager->startup_background_hosts_created_for_test()); |
204 } | 206 } |
205 | 207 |
206 // Test that the embedder can disallow background host creation. | 208 // Test that the embedder can disallow background host creation. |
207 // Chrome OS does this in guest mode. | 209 // Chrome OS does this in guest mode. |
208 TEST_F(ProcessManagerTest, IsBackgroundHostAllowed) { | 210 TEST_F(ProcessManagerTest, IsBackgroundHostAllowed) { |
209 scoped_ptr<ProcessManager> manager(ProcessManager::CreateForTesting( | 211 scoped_ptr<ProcessManager> manager(ProcessManager::CreateForTesting( |
210 original_context(), extension_registry())); | 212 original_context(), extension_registry())); |
211 ASSERT_FALSE(manager->startup_background_hosts_created_for_test()); | 213 ASSERT_FALSE(manager->startup_background_hosts_created_for_test()); |
212 | 214 |
213 // Don't create background hosts if the delegate disallows them. | 215 // Don't create background hosts if the delegate disallows them. |
214 process_manager_delegate()->is_background_page_allowed_ = false; | 216 process_manager_delegate()->is_background_page_allowed_ = false; |
215 manager->MaybeCreateStartupBackgroundHosts(); | 217 manager->MaybeCreateStartupBackgroundHosts(); |
216 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); | 218 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); |
217 | 219 |
218 // The extension system becoming ready still doesn't create the hosts. | 220 // The extension system becoming ready still doesn't create the hosts. |
219 content::NotificationService::current()->Notify( | 221 content::NotificationService::current()->Notify( |
220 chrome::NOTIFICATION_EXTENSIONS_READY, | 222 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
221 content::Source<BrowserContext>(original_context()), | 223 content::Source<BrowserContext>(original_context()), |
222 content::NotificationService::NoDetails()); | 224 content::NotificationService::NoDetails()); |
223 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); | 225 EXPECT_FALSE(manager->startup_background_hosts_created_for_test()); |
224 } | 226 } |
225 | 227 |
226 // Test that extensions get grouped in the right SiteInstance (and therefore | 228 // Test that extensions get grouped in the right SiteInstance (and therefore |
227 // process) based on their URLs. | 229 // process) based on their URLs. |
228 TEST_F(ProcessManagerTest, ProcessGrouping) { | 230 TEST_F(ProcessManagerTest, ProcessGrouping) { |
229 // Extensions in different browser contexts should always be different | 231 // Extensions in different browser contexts should always be different |
230 // SiteInstances. | 232 // SiteInstances. |
(...skipping 21 matching lines...) Expand all Loading... |
252 scoped_refptr<SiteInstance> site21 = | 254 scoped_refptr<SiteInstance> site21 = |
253 manager1->GetSiteInstanceForURL(ext2_url1); | 255 manager1->GetSiteInstanceForURL(ext2_url1); |
254 EXPECT_NE(site11, site21); | 256 EXPECT_NE(site11, site21); |
255 | 257 |
256 scoped_refptr<SiteInstance> other_profile_site = | 258 scoped_refptr<SiteInstance> other_profile_site = |
257 manager2->GetSiteInstanceForURL(ext1_url1); | 259 manager2->GetSiteInstanceForURL(ext1_url1); |
258 EXPECT_NE(site11, other_profile_site); | 260 EXPECT_NE(site11, other_profile_site); |
259 } | 261 } |
260 | 262 |
261 } // namespace extensions | 263 } // namespace extensions |
OLD | NEW |