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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 .AppendASCII("none")); | 287 .AppendASCII("none")); |
287 ASSERT_TRUE(extension.get()); | 288 ASSERT_TRUE(extension.get()); |
288 | 289 |
289 // Process manager gains a background host. | 290 // Process manager gains a background host. |
290 EXPECT_EQ(1u, pm->background_hosts().size()); | 291 EXPECT_EQ(1u, pm->background_hosts().size()); |
291 EXPECT_EQ(1u, pm->GetAllFrames().size()); | 292 EXPECT_EQ(1u, pm->GetAllFrames().size()); |
292 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); | 293 EXPECT_TRUE(pm->GetBackgroundHostForExtension(extension->id())); |
293 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); | 294 EXPECT_TRUE(pm->GetSiteInstanceForURL(extension->url())); |
294 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); | 295 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension->id()).size()); |
295 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); | 296 EXPECT_FALSE(pm->IsBackgroundHostClosing(extension->id())); |
296 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(extension.get())); | 297 |
298 EXPECT_TRUE(BackgroundInfo::HasPersistentBackgroundPage(extension.get())); | |
299 EXPECT_EQ(-1, 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())); | |
309 } | 311 } |
310 | 312 |
311 // Test that loading an extension with a browser action does not create a | 313 // 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 | 314 // background page and that clicking on the action creates the appropriate |
313 // ExtensionHost. | 315 // ExtensionHost. |
314 // Disabled due to flake, see http://crbug.com/315242 | 316 // Disabled due to flake, see http://crbug.com/315242 |
315 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, | 317 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, |
316 DISABLED_PopupHostCreation) { | 318 DISABLED_PopupHostCreation) { |
317 ProcessManager* pm = ProcessManager::Get(profile()); | 319 ProcessManager* pm = ProcessManager::Get(profile()); |
318 | 320 |
319 // Load an extension with the ability to open a popup but no background | 321 // Load an extension with the ability to open a popup but no background |
320 // page. | 322 // page. |
321 scoped_refptr<const Extension> popup = | 323 scoped_refptr<const Extension> popup = |
322 LoadExtension(test_data_dir_.AppendASCII("api_test") | 324 LoadExtension(test_data_dir_.AppendASCII("api_test") |
323 .AppendASCII("browser_action") | 325 .AppendASCII("browser_action") |
324 .AppendASCII("popup")); | 326 .AppendASCII("popup")); |
325 ASSERT_TRUE(popup.get()); | 327 ASSERT_TRUE(popup.get()); |
326 | 328 |
327 // No background host was added. | 329 // No background host was added. |
328 EXPECT_EQ(0u, pm->background_hosts().size()); | 330 EXPECT_EQ(0u, pm->background_hosts().size()); |
329 EXPECT_EQ(0u, pm->GetAllFrames().size()); | 331 EXPECT_EQ(0u, pm->GetAllFrames().size()); |
330 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); | 332 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
331 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); | 333 EXPECT_EQ(0u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); |
332 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); | 334 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
333 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); | 335 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
334 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get())); | |
Devlin
2017/02/14 16:18:24
Any reason to not update these, rather than remove
Wez
2017/02/14 17:39:16
D'oh; done. Good point, although this test is DISA
| |
335 | 336 |
336 // Simulate clicking on the action to open a popup. | 337 // Simulate clicking on the action to open a popup. |
337 BrowserActionTestUtil test_util(browser()); | 338 BrowserActionTestUtil test_util(browser()); |
338 content::WindowedNotificationObserver frame_observer( | 339 content::WindowedNotificationObserver frame_observer( |
339 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 340 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
340 content::NotificationService::AllSources()); | 341 content::NotificationService::AllSources()); |
341 // Open popup in the first extension. | 342 // Open popup in the first extension. |
342 test_util.Press(0); | 343 test_util.Press(0); |
343 frame_observer.Wait(); | 344 frame_observer.Wait(); |
344 ASSERT_TRUE(test_util.HasPopup()); | 345 ASSERT_TRUE(test_util.HasPopup()); |
345 | 346 |
346 // We now have a view, but still no background hosts. | 347 // We now have a view, but still no background hosts. |
347 EXPECT_EQ(0u, pm->background_hosts().size()); | 348 EXPECT_EQ(0u, pm->background_hosts().size()); |
348 EXPECT_EQ(1u, pm->GetAllFrames().size()); | 349 EXPECT_EQ(1u, pm->GetAllFrames().size()); |
349 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); | 350 EXPECT_FALSE(pm->GetBackgroundHostForExtension(popup->id())); |
350 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); | 351 EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(popup->id()).size()); |
351 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); | 352 EXPECT_TRUE(pm->GetSiteInstanceForURL(popup->url())); |
352 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); | 353 EXPECT_FALSE(pm->IsBackgroundHostClosing(popup->id())); |
353 EXPECT_EQ(0, pm->GetLazyKeepaliveCount(popup.get())); | |
354 } | 354 } |
355 | 355 |
356 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not | 356 // Content loaded from http://hlogonemlfkgpejgnedahbkiabcdhnnn should not |
357 // interact with an installed extension with that ID. Regression test | 357 // interact with an installed extension with that ID. Regression test |
358 // for bug 357382. | 358 // for bug 357382. |
359 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { | 359 IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, HttpHostMatchingExtensionId) { |
360 ProcessManager* pm = ProcessManager::Get(profile()); | 360 ProcessManager* pm = ProcessManager::Get(profile()); |
361 | 361 |
362 // We start with no background hosts. | 362 // We start with no background hosts. |
363 ASSERT_EQ(0u, pm->background_hosts().size()); | 363 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()); | 602 ASSERT_TRUE(extension.get()); |
603 | 603 |
604 ProcessManager* pm = ProcessManager::Get(profile()); | 604 ProcessManager* pm = ProcessManager::Get(profile()); |
605 ProcessManager::FrameSet frames = | 605 ProcessManager::FrameSet frames = |
606 pm->GetRenderFrameHostsForExtension(extension->id()); | 606 pm->GetRenderFrameHostsForExtension(extension->id()); |
607 ASSERT_EQ(1u, frames.size()); | 607 ASSERT_EQ(1u, frames.size()); |
608 | 608 |
609 // Keepalive count at this point is unpredictable as there may be an | 609 // Keepalive count at this point is unpredictable as there may be an |
610 // outstanding event dispatch. We use the current keepalive count as a | 610 // outstanding event dispatch. We use the current keepalive count as a |
611 // reliable baseline for future expectations. | 611 // reliable baseline for future expectations. |
612 EXPECT_FALSE(BackgroundInfo::HasPersistentBackgroundPage(extension.get())); | |
Devlin
2017/02/14 16:18:24
nit: prefer EXPECT_TRUE(BackgroundInfo::HasLazyBac
Wez
2017/02/14 17:39:16
Done. Also added a sanity-check for the baseline k
| |
612 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); | 613 int baseline_keepalive = pm->GetLazyKeepaliveCount(extension.get()); |
613 | 614 |
614 // Simulate some network events. This test assumes no other network requests | 615 // 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 | 616 // 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 | 617 // 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. | 618 // wait for loads to complete, and we don't run the message loop otherwise. |
618 content::RenderFrameHost* frame_host = *frames.begin(); | 619 content::RenderFrameHost* frame_host = *frames.begin(); |
619 pm->OnNetworkRequestStarted(frame_host, 1); | 620 pm->OnNetworkRequestStarted(frame_host, 1); |
620 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); | 621 EXPECT_EQ(baseline_keepalive + 1, pm->GetLazyKeepaliveCount(extension.get())); |
621 pm->OnNetworkRequestDone(frame_host, 1); | 622 pm->OnNetworkRequestDone(frame_host, 1); |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 1157 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
1157 popup, "window.domAutomationController.send(!!window.opener)", | 1158 popup, "window.domAutomationController.send(!!window.opener)", |
1158 &is_opener_defined)); | 1159 &is_opener_defined)); |
1159 EXPECT_TRUE(is_opener_defined); | 1160 EXPECT_TRUE(is_opener_defined); |
1160 | 1161 |
1161 // Verify that postMessage to window.opener works. | 1162 // Verify that postMessage to window.opener works. |
1162 VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame); | 1163 VerifyPostMessageToOpener(popup->GetMainFrame(), extension_frame); |
1163 } | 1164 } |
1164 | 1165 |
1165 } // namespace extensions | 1166 } // namespace extensions |
OLD | NEW |