| 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/blocked_content/blocked_content_tab_helper.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| (...skipping 91 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 | 112 // Opening tabs with window.open should keep the page in the opener's |
| 112 // process. | 113 // process. |
| 113 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); | 114 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
| 114 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); | 115 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); |
| 115 LOG(INFO) << "WindowOpenHelper 1."; | 116 LOG(INFO) << "WindowOpenHelper 1."; |
| 116 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); | 117 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); |
| 117 LOG(INFO) << "End of test."; | 118 LOG(INFO) << "End of test."; |
| 118 } | 119 } |
| 119 }; | 120 }; |
| 120 | 121 |
| 122 // Omits the disable-popup-blocking flag so we can cover that case. |
| 123 class BlockedAppApiTest : public AppApiTest { |
| 124 protected: |
| 125 void SetUpCommandLine(CommandLine* command_line) { |
| 126 ExtensionApiTest::SetUpCommandLine(command_line); |
| 127 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 128 switches::kAllowHTTPBackgroundPage); |
| 129 } |
| 130 }; |
| 131 |
| 121 // Tests that hosted apps with the background permission get a process-per-app | 132 // 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. | 133 // model, since all pages need to be able to script the background page. |
| 123 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { | 134 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { |
| 124 LOG(INFO) << "Start of test."; | 135 LOG(INFO) << "Start of test."; |
| 125 | 136 |
| 126 extensions::ProcessMap* process_map = | 137 extensions::ProcessMap* process_map = |
| 127 browser()->profile()->GetExtensionService()->process_map(); | 138 browser()->profile()->GetExtensionService()->process_map(); |
| 128 | 139 |
| 129 host_resolver()->AddRule("*", "127.0.0.1"); | 140 host_resolver()->AddRule("*", "127.0.0.1"); |
| 130 ASSERT_TRUE(test_server()->Start()); | 141 ASSERT_TRUE(test_server()->Start()); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 ASSERT_TRUE(test_server()->Start()); | 457 ASSERT_TRUE(test_server()->Start()); |
| 447 | 458 |
| 448 GURL base_url = GetTestBaseURL("app_process"); | 459 GURL base_url = GetTestBaseURL("app_process"); |
| 449 | 460 |
| 450 // Load app and start URL (not in the app). | 461 // Load app and start URL (not in the app). |
| 451 const Extension* app = | 462 const Extension* app = |
| 452 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 463 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 453 ASSERT_TRUE(app); | 464 ASSERT_TRUE(app); |
| 454 | 465 |
| 455 content::WindowedNotificationObserver popup_observer( | 466 content::WindowedNotificationObserver popup_observer( |
| 456 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 467 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 457 content::NotificationService::AllSources()); | 468 content::NotificationService::AllSources()); |
| 458 ui_test_utils::NavigateToURL(browser(), | 469 ui_test_utils::NavigateToURL(browser(), |
| 459 base_url.Resolve("path3/container.html")); | 470 base_url.Resolve("path3/container.html")); |
| 460 EXPECT_FALSE(process_map->Contains( | 471 EXPECT_FALSE(process_map->Contains( |
| 461 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); | 472 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); |
| 462 popup_observer.Wait(); | 473 popup_observer.Wait(); |
| 463 | 474 |
| 464 // Popup window should be in the app's process. | 475 // Popup window should be in the app's process. |
| 465 RenderViewHost* popup_host = | 476 RenderViewHost* popup_host = |
| 466 content::Source<RenderViewHost>(popup_observer.source()).ptr(); | 477 content::Source<RenderViewHost>(popup_observer.source()).ptr(); |
| 467 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); | 478 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); |
| 468 } | 479 } |
| 469 | 480 |
| 481 // Similar to the previous test, but ensure that popup blocking bypass |
| 482 // isn't granted to the iframe. See crbug.com/117446. |
| 483 IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, OpenAppFromIframe) { |
| 484 host_resolver()->AddRule("*", "127.0.0.1"); |
| 485 ASSERT_TRUE(test_server()->Start()); |
| 486 |
| 487 // Load app and start URL (not in the app). |
| 488 const Extension* app = |
| 489 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 490 ASSERT_TRUE(app); |
| 491 |
| 492 content::WindowedNotificationObserver blocker_observer( |
| 493 chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED, |
| 494 content::NotificationService::AllSources()); |
| 495 ui_test_utils::NavigateToURL( |
| 496 browser(), GetTestBaseURL("app_process").Resolve("path3/container.html")); |
| 497 |
| 498 blocker_observer.Wait(); |
| 499 |
| 500 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 501 BlockedContentTabHelper* blocked_content_tab_helper = |
| 502 BlockedContentTabHelper::FromWebContents(tab); |
| 503 std::vector<WebContents*> blocked_contents; |
| 504 blocked_content_tab_helper->GetBlockedContents(&blocked_contents); |
| 505 EXPECT_EQ(blocked_contents.size(), 1u); |
| 506 } |
| 507 |
| 470 // Tests that if an extension launches an app via chrome.tabs.create with an URL | 508 // 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 | 509 // 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. | 510 // an app process. See http://crbug.com/99349 for more details. |
| 473 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) { | 511 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) { |
| 474 host_resolver()->AddRule("*", "127.0.0.1"); | 512 host_resolver()->AddRule("*", "127.0.0.1"); |
| 475 ASSERT_TRUE(StartTestServer()); | 513 ASSERT_TRUE(StartTestServer()); |
| 476 | 514 |
| 477 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 515 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 478 const Extension* launcher = | 516 const Extension* launcher = |
| 479 LoadExtension(test_data_dir_.AppendASCII("app_launcher")); | 517 LoadExtension(test_data_dir_.AppendASCII("app_launcher")); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 content::Source<NavigationController>( | 622 content::Source<NavigationController>( |
| 585 &chrome::GetActiveWebContents(browser())->GetController())); | 623 &chrome::GetActiveWebContents(browser())->GetController())); |
| 586 chrome::Reload(browser(), CURRENT_TAB); | 624 chrome::Reload(browser(), CURRENT_TAB); |
| 587 observer.Wait(); | 625 observer.Wait(); |
| 588 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 626 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 589 contents->GetRenderViewHost(), L"", | 627 contents->GetRenderViewHost(), L"", |
| 590 L"window.domAutomationController.send(chrome.app.isInstalled)", | 628 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 591 &is_installed)); | 629 &is_installed)); |
| 592 ASSERT_TRUE(is_installed); | 630 ASSERT_TRUE(is_installed); |
| 593 } | 631 } |
| OLD | NEW |