| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 L"window.addEventListener('unload', function() {" | 71 L"window.addEventListener('unload', function() {" |
| 72 L" window.domAutomationController.send(true);" | 72 L" window.domAutomationController.send(true);" |
| 73 L"}, false);" | 73 L"}, false);" |
| 74 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", | 74 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", |
| 75 &result)); | 75 &result)); |
| 76 ASSERT_TRUE(result); | 76 ASSERT_TRUE(result); |
| 77 observer.Wait(); | 77 observer.Wait(); |
| 78 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); | 78 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { | 81 #if defined(OS_WIN) |
| 82 // AppProcess sometimes hangs on Windows |
| 83 // http://crbug.com/88316 |
| 84 #define MAYBE_AppProcess DISABLED_AppProcess |
| 85 #else |
| 86 #define MAYBE_AppProcess AppProcess |
| 87 #endif |
| 88 |
| 89 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) { |
| 82 CommandLine::ForCurrentProcess()->AppendSwitch( | 90 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 83 switches::kDisablePopupBlocking); | 91 switches::kDisablePopupBlocking); |
| 84 | 92 |
| 85 ExtensionProcessManager* extension_process_manager = | 93 ExtensionProcessManager* extension_process_manager = |
| 86 browser()->profile()->GetExtensionProcessManager(); | 94 browser()->profile()->GetExtensionProcessManager(); |
| 87 | 95 |
| 88 host_resolver()->AddRule("*", "127.0.0.1"); | 96 host_resolver()->AddRule("*", "127.0.0.1"); |
| 89 ASSERT_TRUE(test_server()->Start()); | 97 ASSERT_TRUE(test_server()->Start()); |
| 90 | 98 |
| 91 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 99 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 92 | 100 |
| 93 // Open two tabs in the app, one outside it. | 101 // Open two tabs in the app, one outside it. |
| 94 GURL base_url = GetTestBaseURL("app_process"); | 102 GURL base_url = GetTestBaseURL("app_process"); |
| 95 | 103 |
| 96 // Test both opening a URL in a new tab, and opening a tab and then navigating | 104 // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 97 // it. Either way, app tabs should be considered extension processes, but | 105 // it. Either way, app tabs should be considered extension processes, but |
| 98 // they have no elevated privileges and thus should not have WebUI bindings. | 106 // they have no elevated privileges and thus should not have WebUI bindings. |
| 99 ui_test_utils::NavigateToURLWithDisposition( | 107 ui_test_utils::NavigateToURLWithDisposition( |
| 100 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 108 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 101 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 109 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 102 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( | 110 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 103 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); | 111 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); |
| 104 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); | 112 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
| 105 | 113 browser()->NewTab(); |
| 106 ui_test_utils::NavigateToURLWithDisposition( | 114 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 107 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, | |
| 108 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 109 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( | 115 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 110 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); | 116 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); |
| 111 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); | 117 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
| 112 | |
| 113 ui_test_utils::WindowedNotificationObserver tab_added_observer( | |
| 114 content::NOTIFICATION_TAB_ADDED, | |
| 115 content::NotificationService::AllSources()); | |
| 116 browser()->NewTab(); | 118 browser()->NewTab(); |
| 117 tab_added_observer.Wait(); | |
| 118 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); | 119 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); |
| 119 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( | 120 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( |
| 120 browser()->GetTabContentsAt(3)->render_view_host()->process()->id())); | 121 browser()->GetTabContentsAt(3)->render_view_host()->process()->id())); |
| 121 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); | 122 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); |
| 122 | 123 |
| 123 // We should have opened 3 new extension tabs. Including the original blank | 124 // We should have opened 3 new extension tabs. Including the original blank |
| 124 // tab, we now have 4 tabs. Because the app_process app has the background | 125 // tab, we now have 4 tabs. Because the app_process app has the background |
| 125 // permission, all of its instances are in the same process. Thus two tabs | 126 // permission, all of its instances are in the same process. Thus two tabs |
| 126 // should be part of the extension app and grouped in the same process. | 127 // should be part of the extension app and grouped in the same process. |
| 127 ASSERT_EQ(4, browser()->tab_count()); | 128 ASSERT_EQ(4, browser()->tab_count()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 EXPECT_EQ(host->process(), | 166 EXPECT_EQ(host->process(), |
| 166 browser()->GetTabContentsAt(6)->render_view_host()->process()); | 167 browser()->GetTabContentsAt(6)->render_view_host()->process()); |
| 167 bool windowOpenerValid = false; | 168 bool windowOpenerValid = false; |
| 168 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 169 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 169 browser()->GetTabContentsAt(6)->render_view_host(), L"", | 170 browser()->GetTabContentsAt(6)->render_view_host(), L"", |
| 170 L"window.domAutomationController.send(window.opener != null)", | 171 L"window.domAutomationController.send(window.opener != null)", |
| 171 &windowOpenerValid)); | 172 &windowOpenerValid)); |
| 172 ASSERT_TRUE(windowOpenerValid); | 173 ASSERT_TRUE(windowOpenerValid); |
| 173 } | 174 } |
| 174 | 175 |
| 176 |
| 177 #if defined(OS_WIN) |
| 178 // Seems to timeout sometimes on Windows: http://crbug.com/89766 |
| 179 #define MAYBE_AppProcessInstances FLAKY_AppProcessInstances |
| 180 #else |
| 181 #define MAYBE_AppProcessInstances AppProcessInstances |
| 182 #endif |
| 183 |
| 175 // Test that hosted apps without the background permission use a process per app | 184 // Test that hosted apps without the background permission use a process per app |
| 176 // instance model, such that separate instances are in separate processes. | 185 // instance model, such that separate instances are in separate processes. |
| 177 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) { | 186 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) { |
| 178 CommandLine::ForCurrentProcess()->AppendSwitch( | 187 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 179 switches::kDisablePopupBlocking); | 188 switches::kDisablePopupBlocking); |
| 180 | 189 |
| 181 ExtensionProcessManager* extension_process_manager = | 190 ExtensionProcessManager* extension_process_manager = |
| 182 browser()->profile()->GetExtensionProcessManager(); | 191 browser()->profile()->GetExtensionProcessManager(); |
| 183 | 192 |
| 184 host_resolver()->AddRule("*", "127.0.0.1"); | 193 host_resolver()->AddRule("*", "127.0.0.1"); |
| 185 ASSERT_TRUE(test_server()->Start()); | 194 ASSERT_TRUE(test_server()->Start()); |
| 186 | 195 |
| 187 ASSERT_TRUE(LoadExtension( | 196 ASSERT_TRUE(LoadExtension( |
| 188 test_data_dir_.AppendASCII("app_process_instances"))); | 197 test_data_dir_.AppendASCII("app_process_instances"))); |
| 189 | 198 |
| 190 // Open two tabs in the app, one outside it. | 199 // Open two tabs in the app, one outside it. |
| 191 GURL base_url = GetTestBaseURL("app_process_instances"); | 200 GURL base_url = GetTestBaseURL("app_process_instances"); |
| 192 | 201 |
| 193 // Test both opening a URL in a new tab, and opening a tab and then navigating | 202 // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 194 // it. Either way, app tabs should be considered extension processes, but | 203 // it. Either way, app tabs should be considered extension processes, but |
| 195 // they have no elevated privileges and thus should not have WebUI bindings. | 204 // they have no elevated privileges and thus should not have WebUI bindings. |
| 196 ui_test_utils::NavigateToURLWithDisposition( | 205 ui_test_utils::NavigateToURLWithDisposition( |
| 197 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 206 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 198 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 207 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 199 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( | 208 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 200 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); | 209 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); |
| 201 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); | 210 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
| 202 | |
| 203 ui_test_utils::WindowedNotificationObserver tab_added_observer( | |
| 204 content::NOTIFICATION_TAB_ADDED, | |
| 205 content::NotificationService::AllSources()); | |
| 206 browser()->NewTab(); | 211 browser()->NewTab(); |
| 207 tab_added_observer.Wait(); | |
| 208 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); | 212 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 209 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( | 213 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 210 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); | 214 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); |
| 211 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); | 215 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
| 212 | 216 |
| 213 // We should have opened 2 new extension tabs. Including the original blank | 217 // We should have opened 2 new extension tabs. Including the original blank |
| 214 // tab, we now have 3 tabs. The two app tabs should not be in the same | 218 // tab, we now have 3 tabs. The two app tabs should not be in the same |
| 215 // process, since they do not have the background permission. (Thus, we want | 219 // process, since they do not have the background permission. (Thus, we want |
| 216 // to separate them to improve responsiveness.) | 220 // to separate them to improve responsiveness.) |
| 217 ASSERT_EQ(3, browser()->tab_count()); | 221 ASSERT_EQ(3, browser()->tab_count()); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 content::Source<NavigationController>( | 494 content::Source<NavigationController>( |
| 491 &browser()->GetSelectedTabContentsWrapper()->controller())); | 495 &browser()->GetSelectedTabContentsWrapper()->controller())); |
| 492 browser()->Reload(CURRENT_TAB); | 496 browser()->Reload(CURRENT_TAB); |
| 493 observer.Wait(); | 497 observer.Wait(); |
| 494 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 498 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 495 contents->render_view_host(), L"", | 499 contents->render_view_host(), L"", |
| 496 L"window.domAutomationController.send(chrome.app.isInstalled)", | 500 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 497 &is_installed)); | 501 &is_installed)); |
| 498 ASSERT_TRUE(is_installed); | 502 ASSERT_TRUE(is_installed); |
| 499 } | 503 } |
| OLD | NEW |