OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
31 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/browser_side_navigation_policy.h" | 33 #include "content/public/common/browser_side_navigation_policy.h" |
34 #include "content/public/test/browser_test_utils.h" | 34 #include "content/public/test/browser_test_utils.h" |
35 #include "content/public/test/test_navigation_observer.h" | 35 #include "content/public/test/test_navigation_observer.h" |
36 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
37 #include "extensions/browser/app_window/app_window.h" | 37 #include "extensions/browser/app_window/app_window.h" |
38 #include "extensions/browser/app_window/app_window_registry.h" | 38 #include "extensions/browser/app_window/app_window_registry.h" |
39 #include "extensions/browser/process_manager.h" | 39 #include "extensions/browser/process_manager.h" |
| 40 #include "extensions/common/manifest_handlers/background_info.h" |
40 #include "extensions/common/permissions/permissions_data.h" | 41 #include "extensions/common/permissions/permissions_data.h" |
41 #include "extensions/common/value_builder.h" | 42 #include "extensions/common/value_builder.h" |
42 #include "extensions/test/background_page_watcher.h" | 43 #include "extensions/test/background_page_watcher.h" |
43 #include "net/dns/mock_host_resolver.h" | 44 #include "net/dns/mock_host_resolver.h" |
44 #include "net/test/embedded_test_server/embedded_test_server.h" | 45 #include "net/test/embedded_test_server/embedded_test_server.h" |
45 | 46 |
46 namespace extensions { | 47 namespace extensions { |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 278 |
278 // We start with no background hosts. | 279 // We start with no background hosts. |
279 ASSERT_EQ(0u, pm->background_hosts().size()); | 280 ASSERT_EQ(0u, pm->background_hosts().size()); |
280 ASSERT_EQ(0u, pm->GetAllFrames().size()); | 281 ASSERT_EQ(0u, pm->GetAllFrames().size()); |
281 | 282 |
282 // Load an extension with a background page. | 283 // Load an extension with a background page. |
283 scoped_refptr<const Extension> extension = | 284 scoped_refptr<const Extension> extension = |
284 LoadExtension(test_data_dir_.AppendASCII("api_test") | 285 LoadExtension(test_data_dir_.AppendASCII("api_test") |
285 .AppendASCII("browser_action") | 286 .AppendASCII("browser_action") |
286 .AppendASCII("none")); | 287 .AppendASCII("none")); |
287 ASSERT_TRUE(extension.get()); | 288 ASSERT_TRUE(extension); |
| 289 |
| 290 EXPECT_TRUE(BackgroundInfo::HasPersistentBackgroundPage(extension.get())); |
| 291 EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(extension.get())); |
288 | 292 |
289 // Process manager gains a background host. | 293 // Process manager gains a background host. |
290 EXPECT_EQ(1u, pm->background_hosts().size()); | 294 EXPECT_EQ(1u, pm->background_hosts().size()); |
291 EXPECT_EQ(1u, pm->GetAllFrames().size()); | 295 EXPECT_EQ(1u, pm->GetAllFrames().size()); |
292 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); | 296 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); |
293 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); | 297 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); |
294 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); | 298 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
295 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); | 299 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); |
296 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get())); | |
297 | 300 |
298 // Unload the extension. | 301 // Unload the extension. |
299 UnloadExtension(extension->id()); | 302 UnloadExtension(extension->id()); |
300 | 303 |
301 // Background host disappears. | 304 // Background host disappears. |
302 EXPECT_EQ(0u, pm->background_hosts().size()); | 305 EXPECT_EQ(0u, pm->background_hosts().size()); |
303 EXPECT_EQ(0u, pm->GetAllFrames().size()); | 306 EXPECT_EQ(0u, pm->GetAllFrames().size()); |
304 EXPECT_FALSE(pm->GetBackgroundHostForExtension(extension->id())); | 307 EXPECT_FALSE(pm->GetBackgroundHostForExtension(extension->id())); |
305 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); | 308 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); |
306 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); | 309 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
307 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); | 310 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); |
308 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get())); | 311 EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(extension.get())); |
309 } | 312 } |
310 | 313 |
311 // Test that loading an extension with a browser action does not create a | 314 // Test that loading an extension with a browser action does not create a |
312 // background page and that clicking on the action creates the appropriate | 315 // background page and that clicking on the action creates the appropriate |
313 // ExtensionHost. | 316 // ExtensionHost. |
314 // Disabled due to flake, see http://crbug.com/315242 | 317 // Disabled due to flake, see http://crbug.com/315242 |
315 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, | 318 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
316 DISABLED_PopupHostCreation) { | 319 DISABLED_PopupHostCreation) { |
317 ProcessManager* pm = ProcessManager::Get(profile()); | 320 ProcessManager* pm = ProcessManager::Get(profile()); |
318 | 321 |
319 // Load an extension with the ability to open a popup but no background | 322 // Load an extension with the ability to open a popup but no background |
320 // page. | 323 // page. |
321 scoped_refptr<const Extension> popup = | 324 scoped_refptr<const Extension> popup = |
322 LoadExtension(test_data_dir_.AppendASCII("api_test") | 325 LoadExtension(test_data_dir_.AppendASCII("api_test") |
323 .AppendASCII("browser_action") | 326 .AppendASCII("browser_action") |
324 .AppendASCII("popup")); | 327 .AppendASCII("popup")); |
325 ASSERT_TRUE(popup.get()); | 328 ASSERT_TRUE(popup); |
| 329 |
| 330 EXPECT_FALSE(BackgroundInfo::HasBackgroundPage(popup.get())); |
| 331 EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(popup.get())); |
326 | 332 |
327 // No background host was added. | 333 // No background host was added. |
328 EXPECT_EQ(0u, pm->background_hosts().size()); | 334 EXPECT_EQ(0u, pm->background_hosts().size()); |
329 EXPECT_EQ(0u, pm->GetAllFrames().size()); | 335 EXPECT_EQ(0u, pm->GetAllFrames().size()); |
330 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); | 336 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
331 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); | 337 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); |
332 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); | 338 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
333 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); | 339 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
334 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get())); | |
335 | 340 |
336 // Simulate clicking on the action to open a popup. | 341 // Simulate clicking on the action to open a popup. |
337 BrowserActionTestUtil test_util(browser()); | 342 BrowserActionTestUtil test_util(browser()); |
338 content::WindowedNotificationObserver frame_observer( | 343 content::WindowedNotificationObserver frame_observer( |
339 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 344 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
340 content::NotificationService::AllSources()); | 345 content::NotificationService::AllSources()); |
341 // Open popup in the first extension. | 346 // Open popup in the first extension. |
342 test_util.Press(0); | 347 test_util.Press(0); |
343 frame_observer.Wait(); | 348 frame_observer.Wait(); |
344 ASSERT_TRUE(test_util.HasPopup()); | 349 ASSERT_TRUE(test_util.HasPopup()); |
345 | 350 |
346 // We now have a view, but still no background hosts. | 351 // We now have a view, but still no background hosts. |
347 EXPECT_EQ(0u, pm->background_hosts().size()); | 352 EXPECT_EQ(0u, pm->background_hosts().size()); |
348 EXPECT_EQ(1u, pm->GetAllFrames().size()); | 353 EXPECT_EQ(1u, pm->GetAllFrames().size()); |
349 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); | 354 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
350 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); | 355 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); |
351 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); | 356 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
352 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); | 357 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
353 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get())); | 358 EXPECT_EQ(-1, pm->GetLazyKeepaliveCount(popup.get())); |
354 } | 359 } |
355 | 360 |
356 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not | 361 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not |
357 // interact with an installed extension with that ID. Regression test | 362 // interact with an installed extension with that ID. Regression test |
358 // for bug 357382. | 363 // for bug 357382. |
359 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { | 364 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { |
360 ProcessManager* pm = ProcessManager::Get(profile()); | 365 ProcessManager* pm = ProcessManager::Get(profile()); |
361 | 366 |
362 // We start with no background hosts. | 367 // We start with no background hosts. |
363 ASSERT_EQ(0u, pm->background_hosts().size()); | 368 ASSERT_EQ(0u, pm->background_hosts().size()); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 ASSERT_TRUE(extension.get()); | 607 ASSERT_TRUE(extension.get()); |
603 | 608 |
604 ProcessManager* pm = ProcessManager::Get(profile()); | 609 ProcessManager* pm = ProcessManager::Get(profile()); |
605 ProcessManager::FrameSet frames = | 610 ProcessManager::FrameSet frames = |
606 pm->GetRenderFrameHostsForExtension(extension->id()); | 611 pm->GetRenderFrameHostsForExtension(extension->id()); |
607 ASSERT_EQ(1u, frames.size()); | 612 ASSERT_EQ(1u, frames.size()); |
608 | 613 |
609 // Keepalive count at this point is unpredictable as there may be an | 614 // Keepalive count at this point is unpredictable as there may be an |
610 // outstanding event dispatch. We use the current keepalive count as a | 615 // outstanding event dispatch. We use the current keepalive count as a |
611 // reliable baseline for future expectations. | 616 // reliable baseline for future expectations. |
| 617 EXPECT_TRUE(BackgroundInfo::HasLazyBackgroundPage(extension.get())); |
612 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); | 618 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); |
| 619 EXPECT_LE(0, baseline_keepalive); |
613 | 620 |
614 // Simulate some network events. This test assumes no other network requests | 621 // Simulate some network events. This test assumes no other network requests |
615 // are pending, i.e., that there are no conflicts with the fake request IDs | 622 // are pending, i.e., that there are no conflicts with the fake request IDs |
616 // we're using. This should be a safe assumption because LoadExtension should | 623 // we're using. This should be a safe assumption because LoadExtension should |
617 // wait for loads to complete, and we don't run the message loop otherwise. | 624 // wait for loads to complete, and we don't run the message loop otherwise. |
618 content::RenderFrameHost* frame_host = *frames.begin(); | 625 content::RenderFrameHost* frame_host = *frames.begin(); |
619 pm->OnNetworkRequestStarted(frame_host, 1); | 626 pm->OnNetworkRequestStarted(frame_host, 1); |
620 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); | 627 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); |
621 pm->OnNetworkRequestDone(frame_host, 1); | 628 pm->OnNetworkRequestDone(frame_host, 1); |
622 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); | 629 EXPECT_EQ(baseline_keepalive, pm->GetLazyKeepaliveCount(extension.get())); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1163 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
1157 popup, "window.domAutomationController.send(!!window.opener)", | 1164 popup, "window.domAutomationController.send(!!window.opener)", |
1158 &is_opener_defined)); | 1165 &is_opener_defined)); |
1159 EXPECT_TRUE(is_opener_defined); | 1166 EXPECT_TRUE(is_opener_defined); |
1160 | 1167 |
1161 // Verify that postMessage to window.opener works. | 1168 // Verify that postMessage to window.opener works. |
1162 VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame); | 1169 VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame); |
1163 } | 1170 } |
1164 | 1171 |
1165 } // namespace extensions | 1172 } // namespace extensions |
OLD | NEW |