OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/extensions/extension_host.h" | 6 #include "chrome/browser/extensions/extension_host.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/process_map.h" | 8 #include "chrome/browser/extensions/process_map.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Opening tabs with window.open should keep the page in the opener's | 111 // Opening tabs with window.open should keep the page in the opener's |
112 // process. | 112 // process. |
113 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); | 113 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
114 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); | 114 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); |
115 LOG(INFO) << "WindowOpenHelper 1."; | 115 LOG(INFO) << "WindowOpenHelper 1."; |
116 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); | 116 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); |
117 LOG(INFO) << "End of test."; | 117 LOG(INFO) << "End of test."; |
118 } | 118 } |
119 }; | 119 }; |
120 | 120 |
| 121 // Omits the disable-popup-blocking flag so we can cover that case. |
| 122 class BlockedAppApiTest : public AppApiTest { |
| 123 protected: |
| 124 void SetUpCommandLine(CommandLine* command_line) { |
| 125 ExtensionApiTest::SetUpCommandLine(command_line); |
| 126 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 127 switches::kAllowHTTPBackgroundPage); |
| 128 } |
| 129 }; |
| 130 |
121 // Tests that hosted apps with the background permission get a process-per-app | 131 // Tests that hosted apps with the background permission get a process-per-app |
122 // model, since all pages need to be able to script the background page. | 132 // model, since all pages need to be able to script the background page. |
123 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { | 133 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { |
124 LOG(INFO) << "Start of test."; | 134 LOG(INFO) << "Start of test."; |
125 | 135 |
126 extensions::ProcessMap* process_map = | 136 extensions::ProcessMap* process_map = |
127 browser()->profile()->GetExtensionService()->process_map(); | 137 browser()->profile()->GetExtensionService()->process_map(); |
128 | 138 |
129 host_resolver()->AddRule("*", "127.0.0.1"); | 139 host_resolver()->AddRule("*", "127.0.0.1"); |
130 ASSERT_TRUE(test_server()->Start()); | 140 ASSERT_TRUE(test_server()->Start()); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 ASSERT_TRUE(test_server()->Start()); | 456 ASSERT_TRUE(test_server()->Start()); |
447 | 457 |
448 GURL base_url = GetTestBaseURL("app_process"); | 458 GURL base_url = GetTestBaseURL("app_process"); |
449 | 459 |
450 // Load app and start URL (not in the app). | 460 // Load app and start URL (not in the app). |
451 const Extension* app = | 461 const Extension* app = |
452 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 462 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
453 ASSERT_TRUE(app); | 463 ASSERT_TRUE(app); |
454 | 464 |
455 content::WindowedNotificationObserver popup_observer( | 465 content::WindowedNotificationObserver popup_observer( |
456 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 466 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
457 content::NotificationService::AllSources()); | 467 content::NotificationService::AllSources()); |
458 ui_test_utils::NavigateToURL(browser(), | 468 ui_test_utils::NavigateToURL(browser(), |
459 base_url.Resolve("path3/container.html")); | 469 base_url.Resolve("path3/container.html")); |
460 EXPECT_FALSE(process_map->Contains( | 470 EXPECT_FALSE(process_map->Contains( |
461 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); | 471 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); |
462 popup_observer.Wait(); | 472 popup_observer.Wait(); |
463 | 473 |
464 // Popup window should be in the app's process. | 474 // Popup window should be in the app's process. |
465 RenderViewHost* popup_host = | 475 RenderViewHost* popup_host = |
466 content::Source<RenderViewHost>(popup_observer.source()).ptr(); | 476 content::Source<RenderViewHost>(popup_observer.source()).ptr(); |
467 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); | 477 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); |
468 } | 478 } |
469 | 479 |
| 480 // Similar to the previous test, but ensure that popup blocking bypass |
| 481 // isn't granted to the iframe. See crbug.com/117446. |
| 482 IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, OpenAppFromIframe) { |
| 483 host_resolver()->AddRule("*", "127.0.0.1"); |
| 484 ASSERT_TRUE(test_server()->Start()); |
| 485 |
| 486 // Load app and start URL (not in the app). |
| 487 const Extension* app = |
| 488 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 489 ASSERT_TRUE(app); |
| 490 |
| 491 content::WindowedNotificationObserver blocker_observer( |
| 492 chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED, |
| 493 content::NotificationService::AllSources()); |
| 494 ui_test_utils::NavigateToURL( |
| 495 browser(), GetTestBaseURL("app_process").Resolve("path3/container.html")); |
| 496 |
| 497 blocker_observer.Wait(); |
| 498 EXPECT_TRUE(*content::Details<bool>(blocker_observer.details()).ptr()); |
| 499 } |
| 500 |
470 // Tests that if an extension launches an app via chrome.tabs.create with an URL | 501 // Tests that if an extension launches an app via chrome.tabs.create with an URL |
471 // that's not in the app's extent but that redirects to it, we still end up with | 502 // that's not in the app's extent but that redirects to it, we still end up with |
472 // an app process. See http://crbug.com/99349 for more details. | 503 // an app process. See http://crbug.com/99349 for more details. |
473 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) { | 504 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) { |
474 host_resolver()->AddRule("*", "127.0.0.1"); | 505 host_resolver()->AddRule("*", "127.0.0.1"); |
475 ASSERT_TRUE(StartTestServer()); | 506 ASSERT_TRUE(StartTestServer()); |
476 | 507 |
477 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 508 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
478 const Extension* launcher = | 509 const Extension* launcher = |
479 LoadExtension(test_data_dir_.AppendASCII("app_launcher")); | 510 LoadExtension(test_data_dir_.AppendASCII("app_launcher")); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 content::Source<NavigationController>( | 615 content::Source<NavigationController>( |
585 &chrome::GetActiveWebContents(browser())->GetController())); | 616 &chrome::GetActiveWebContents(browser())->GetController())); |
586 chrome::Reload(browser(), CURRENT_TAB); | 617 chrome::Reload(browser(), CURRENT_TAB); |
587 observer.Wait(); | 618 observer.Wait(); |
588 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 619 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
589 contents->GetRenderViewHost(), L"", | 620 contents->GetRenderViewHost(), L"", |
590 L"window.domAutomationController.send(chrome.app.isInstalled)", | 621 L"window.domAutomationController.send(chrome.app.isInstalled)", |
591 &is_installed)); | 622 &is_installed)); |
592 ASSERT_TRUE(is_installed); | 623 ASSERT_TRUE(is_installed); |
593 } | 624 } |
OLD | NEW |