[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | ce7f62e3 | 2010-08-10 23:43:59 | [diff] [blame] | 5 | #include "base/utf_string_conversions.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 6 | #include "chrome/browser/extensions/extension_apitest.h" |
| 7 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_service.h" |
| 9 | #include "chrome/browser/extensions/process_map.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 11 | #include "chrome/browser/ui/browser.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 14 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 15 | #include "chrome/common/chrome_switches.h" |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 16 | #include "chrome/common/extensions/extension.h" |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame^] | 17 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 18 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | a035dfda | 2011-03-02 01:01:49 | [diff] [blame] | 19 | #include "content/browser/renderer_host/render_view_host.h" |
| 20 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 21 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 22 | #include "net/base/mock_host_resolver.h" |
| 23 | |
| 24 | class AppApiTest : public ExtensionApiTest { |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 25 | protected: |
| 26 | // Gets the base URL for files for a specific test, making sure that it uses |
| 27 | // "localhost" as the hostname, since that is what the extent is declared |
| 28 | // as in the test apps manifests. |
| 29 | GURL GetTestBaseURL(std::string test_directory) { |
| 30 | GURL::Replacements replace_host; |
| 31 | std::string host_str("localhost"); // must stay in scope with replace_host |
| 32 | replace_host.SetHostStr(host_str); |
| 33 | GURL base_url = test_server()->GetURL( |
| 34 | "files/extensions/api_test/" + test_directory + "/"); |
| 35 | return base_url.ReplaceComponents(replace_host); |
| 36 | } |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | // Simulates a page calling window.open on an URL, and waits for the navigation. |
| 40 | static void WindowOpenHelper(Browser* browser, |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 41 | RenderViewHost* opener_host, |
| 42 | const GURL& url, |
| 43 | bool newtab_process_should_equal_opener) { |
[email protected] | 3114db2c | 2011-09-12 20:09:05 | [diff] [blame] | 44 | ui_test_utils::WindowedNotificationObserver observer( |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 45 | content::NOTIFICATION_LOAD_STOP, |
| 46 | content::NotificationService::AllSources()); |
[email protected] | 9fabbf7 | 2010-09-30 21:50:05 | [diff] [blame] | 47 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 48 | opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');")); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 49 | |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 50 | // The above window.open call is not user-initiated, it will create |
| 51 | // a popup window instead of a new tab in current window. |
| 52 | // Now the active tab in last active window should be the new tab. |
| 53 | Browser* last_active_browser = BrowserList::GetLastActive(); |
| 54 | EXPECT_TRUE(last_active_browser); |
| 55 | TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
| 56 | EXPECT_TRUE(newtab); |
[email protected] | 3114db2c | 2011-09-12 20:09:05 | [diff] [blame] | 57 | observer.Wait(); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 58 | EXPECT_EQ(url, newtab->controller().GetLastCommittedEntry()->url()); |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 59 | if (newtab_process_should_equal_opener) |
| 60 | EXPECT_EQ(opener_host->process(), newtab->render_view_host()->process()); |
| 61 | else |
| 62 | EXPECT_NE(opener_host->process(), newtab->render_view_host()->process()); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Simulates a page navigating itself to an URL, and waits for the navigation. |
| 66 | static void NavigateTabHelper(TabContents* contents, const GURL& url) { |
| 67 | bool result = false; |
[email protected] | 3114db2c | 2011-09-12 20:09:05 | [diff] [blame] | 68 | ui_test_utils::WindowedNotificationObserver observer( |
| 69 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 70 | content::NotificationService::AllSources()); |
[email protected] | 9fabbf7 | 2010-09-30 21:50:05 | [diff] [blame] | 71 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 72 | contents->render_view_host(), L"", |
[email protected] | d38f83f | 2010-04-30 23:25:57 | [diff] [blame] | 73 | L"window.addEventListener('unload', function() {" |
| 74 | L" window.domAutomationController.send(true);" |
| 75 | L"}, false);" |
| 76 | L"window.location = '" + UTF8ToWide(url.spec()) + L"';", |
[email protected] | 9fabbf7 | 2010-09-30 21:50:05 | [diff] [blame] | 77 | &result)); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 78 | ASSERT_TRUE(result); |
[email protected] | 3114db2c | 2011-09-12 20:09:05 | [diff] [blame] | 79 | observer.Wait(); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 80 | EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); |
| 81 | } |
| 82 | |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 83 | IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) { |
| 84 | LOG(INFO) << "Start of test."; |
[email protected] | 9b60083 | 2011-10-26 20:31:59 | [diff] [blame] | 85 | |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 86 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 87 | switches::kDisablePopupBlocking); |
| 88 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 89 | extensions::ProcessMap* process_map = |
| 90 | browser()->profile()->GetExtensionService()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 91 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 92 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | 95409e1 | 2010-08-17 20:07:11 | [diff] [blame] | 93 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 94 | |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 95 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 96 | |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 97 | LOG(INFO) << "Loaded extension."; |
| 98 | |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 99 | // Open two tabs in the app, one outside it. |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 100 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 101 | |
[email protected] | f0e1333 | 2011-05-20 22:41:14 | [diff] [blame] | 102 | // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 103 | // it. Either way, app tabs should be considered extension processes, but |
| 104 | // they have no elevated privileges and thus should not have WebUI bindings. |
| 105 | ui_test_utils::NavigateToURLWithDisposition( |
| 106 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 107 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 108 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 109 | browser()->GetTabContentsAt(1)->render_view_host()->process()->GetID())); |
[email protected] | f0e1333 | 2011-05-20 22:41:14 | [diff] [blame] | 110 | EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 111 | LOG(INFO) << "Nav 1."; |
| 112 | |
| 113 | ui_test_utils::NavigateToURLWithDisposition( |
| 114 | browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, |
| 115 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 116 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 117 | browser()->GetTabContentsAt(2)->render_view_host()->process()->GetID())); |
[email protected] | f0e1333 | 2011-05-20 22:41:14 | [diff] [blame] | 118 | EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 119 | LOG(INFO) << "Nav 2."; |
| 120 | |
| 121 | ui_test_utils::WindowedNotificationObserver tab_added_observer( |
| 122 | content::NOTIFICATION_TAB_ADDED, |
| 123 | content::NotificationService::AllSources()); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 124 | browser()->NewTab(); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 125 | tab_added_observer.Wait(); |
| 126 | LOG(INFO) << "New tab."; |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 127 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 128 | LOG(INFO) << "Nav 3."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 129 | EXPECT_FALSE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 130 | browser()->GetTabContentsAt(3)->render_view_host()->process()->GetID())); |
[email protected] | f0e1333 | 2011-05-20 22:41:14 | [diff] [blame] | 131 | EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 132 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 133 | // We should have opened 3 new extension tabs. Including the original blank |
| 134 | // tab, we now have 4 tabs. Because the app_process app has the background |
| 135 | // permission, all of its instances are in the same process. Thus two tabs |
| 136 | // should be part of the extension app and grouped in the same process. |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 137 | ASSERT_EQ(4, browser()->tab_count()); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 138 | RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 139 | |
| 140 | EXPECT_EQ(host->process(), |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 141 | browser()->GetTabContentsAt(2)->render_view_host()->process()); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 142 | EXPECT_NE(host->process(), |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 143 | browser()->GetTabContentsAt(3)->render_view_host()->process()); |
| 144 | |
| 145 | // Now let's do the same using window.open. The same should happen. |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 146 | ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 147 | WindowOpenHelper(browser(), host, |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 148 | base_url.Resolve("path1/empty.html"), true); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 149 | LOG(INFO) << "WindowOpenHelper 1."; |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 150 | WindowOpenHelper(browser(), host, |
[email protected] | 12ea9b27 | 2010-08-24 11:31:40 | [diff] [blame] | 151 | base_url.Resolve("path2/empty.html"), true); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 152 | LOG(INFO) << "WindowOpenHelper 2."; |
[email protected] | 361a5f1f | 2011-10-05 20:11:15 | [diff] [blame] | 153 | // TODO(creis): This should open in a new process (i.e., false for the last |
| 154 | // argument), but we temporarily avoid swapping processes away from an app |
| 155 | // until we're able to support cross-process postMessage calls. |
| 156 | // See crbug.com/59285. |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 157 | WindowOpenHelper(browser(), host, |
[email protected] | 361a5f1f | 2011-10-05 20:11:15 | [diff] [blame] | 158 | base_url.Resolve("path3/empty.html"), true); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 159 | LOG(INFO) << "WindowOpenHelper 3."; |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 160 | |
| 161 | // Now let's have these pages navigate, into or out of the extension web |
| 162 | // extent. They should switch processes. |
[email protected] | 9a1e6d4 | 2010-04-26 22:29:36 | [diff] [blame] | 163 | const GURL& app_url(base_url.Resolve("path1/empty.html")); |
| 164 | const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 165 | NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 166 | LOG(INFO) << "NavigateTabHelper 1."; |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 167 | NavigateTabHelper(browser()->GetTabContentsAt(3), app_url); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 168 | LOG(INFO) << "NavigateTabHelper 2."; |
[email protected] | 361a5f1f | 2011-10-05 20:11:15 | [diff] [blame] | 169 | // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE), |
| 170 | // but we temporarily avoid swapping away from an app in case the window |
| 171 | // tries to send a postMessage to the app. See crbug.com/59285. |
| 172 | EXPECT_EQ(host->process(), |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 173 | browser()->GetTabContentsAt(2)->render_view_host()->process()); |
| 174 | EXPECT_EQ(host->process(), |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 175 | browser()->GetTabContentsAt(3)->render_view_host()->process()); |
[email protected] | 08e94b8 | 2010-12-15 22:51:04 | [diff] [blame] | 176 | |
| 177 | // If one of the popup tabs navigates back to the app, window.opener should |
| 178 | // be valid. |
| 179 | NavigateTabHelper(browser()->GetTabContentsAt(6), app_url); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 180 | LOG(INFO) << "NavigateTabHelper 3."; |
[email protected] | 08e94b8 | 2010-12-15 22:51:04 | [diff] [blame] | 181 | EXPECT_EQ(host->process(), |
| 182 | browser()->GetTabContentsAt(6)->render_view_host()->process()); |
| 183 | bool windowOpenerValid = false; |
| 184 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 185 | browser()->GetTabContentsAt(6)->render_view_host(), L"", |
| 186 | L"window.domAutomationController.send(window.opener != null)", |
| 187 | &windowOpenerValid)); |
| 188 | ASSERT_TRUE(windowOpenerValid); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 189 | |
| 190 | LOG(INFO) << "End of test."; |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 191 | } |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 192 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 193 | // Test that hosted apps without the background permission use a process per app |
| 194 | // instance model, such that separate instances are in separate processes. |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 195 | IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) { |
| 196 | LOG(INFO) << "Start of test."; |
| 197 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 198 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 199 | switches::kDisablePopupBlocking); |
| 200 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 201 | extensions::ProcessMap* process_map = |
| 202 | browser()->profile()->GetExtensionService()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 203 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 204 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 205 | ASSERT_TRUE(test_server()->Start()); |
| 206 | |
| 207 | ASSERT_TRUE(LoadExtension( |
| 208 | test_data_dir_.AppendASCII("app_process_instances"))); |
| 209 | |
| 210 | // Open two tabs in the app, one outside it. |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 211 | GURL base_url = GetTestBaseURL("app_process_instances"); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 212 | |
| 213 | // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 214 | // it. Either way, app tabs should be considered extension processes, but |
| 215 | // they have no elevated privileges and thus should not have WebUI bindings. |
| 216 | ui_test_utils::NavigateToURLWithDisposition( |
| 217 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 218 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 219 | LOG(INFO) << "Nav 1."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 220 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 221 | browser()->GetTabContentsAt(1)->render_view_host()->process()->GetID())); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 222 | EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 223 | |
| 224 | ui_test_utils::WindowedNotificationObserver tab_added_observer( |
| 225 | content::NOTIFICATION_TAB_ADDED, |
| 226 | content::NotificationService::AllSources()); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 227 | browser()->NewTab(); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 228 | tab_added_observer.Wait(); |
| 229 | LOG(INFO) << "New tab."; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 230 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 231 | LOG(INFO) << "Nav 2."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 232 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 233 | browser()->GetTabContentsAt(2)->render_view_host()->process()->GetID())); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 234 | EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
| 235 | |
| 236 | // We should have opened 2 new extension tabs. Including the original blank |
| 237 | // tab, we now have 3 tabs. The two app tabs should not be in the same |
| 238 | // process, since they do not have the background permission. (Thus, we want |
| 239 | // to separate them to improve responsiveness.) |
| 240 | ASSERT_EQ(3, browser()->tab_count()); |
| 241 | RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host(); |
| 242 | RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host(); |
| 243 | EXPECT_NE(host1->process(), host2->process()); |
| 244 | |
| 245 | // Opening tabs with window.open should keep the page in the opener's process. |
| 246 | ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); |
| 247 | WindowOpenHelper(browser(), host1, |
| 248 | base_url.Resolve("path1/empty.html"), true); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 249 | LOG(INFO) << "WindowOpenHelper 1."; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 250 | WindowOpenHelper(browser(), host2, |
| 251 | base_url.Resolve("path2/empty.html"), true); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 252 | LOG(INFO) << "End of test."; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 255 | // Tests that bookmark apps do not use the app process model and are treated |
| 256 | // like normal web pages instead. http://crbug.com/104636. |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame^] | 257 | IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) { |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 258 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 259 | switches::kDisablePopupBlocking); |
| 260 | |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame^] | 261 | ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 262 | extensions::ProcessMap* process_map = service->process_map(); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 263 | |
| 264 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 265 | ASSERT_TRUE(test_server()->Start()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 266 | GURL base_url = GetTestBaseURL("app_process"); |
| 267 | |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame^] | 268 | // Load an app as a bookmark app. |
| 269 | std::string error; |
| 270 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
| 271 | test_data_dir_.AppendASCII("app_process"), |
| 272 | Extension::LOAD, |
| 273 | Extension::FROM_BOOKMARK, |
| 274 | &error)); |
| 275 | service->OnExtensionInstalled(extension, false, 0); |
| 276 | ASSERT_TRUE(extension.get()); |
| 277 | ASSERT_TRUE(extension->from_bookmark()); |
| 278 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 279 | // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 280 | // it. Either way, bookmark app tabs should be considered normal processes |
| 281 | // with no elevated privileges and no WebUI bindings. |
| 282 | ui_test_utils::NavigateToURLWithDisposition( |
| 283 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 284 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 285 | EXPECT_FALSE(process_map->Contains( |
| 286 | browser()->GetTabContentsAt(1)->render_view_host()->process()->GetID())); |
| 287 | EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
| 288 | |
| 289 | ui_test_utils::WindowedNotificationObserver tab_added_observer( |
| 290 | content::NOTIFICATION_TAB_ADDED, |
| 291 | content::NotificationService::AllSources()); |
| 292 | browser()->NewTab(); |
| 293 | tab_added_observer.Wait(); |
| 294 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 295 | EXPECT_FALSE(process_map->Contains( |
| 296 | browser()->GetTabContentsAt(2)->render_view_host()->process()->GetID())); |
| 297 | EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
| 298 | |
| 299 | // We should have opened 2 new bookmark app tabs. Including the original blank |
| 300 | // tab, we now have 3 tabs. Because normal pages use the |
| 301 | // process-per-site-instance model, each should be in its own process. |
| 302 | ASSERT_EQ(3, browser()->tab_count()); |
| 303 | RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); |
| 304 | EXPECT_NE(host->process(), |
| 305 | browser()->GetTabContentsAt(2)->render_view_host()->process()); |
| 306 | |
| 307 | // Now let's do the same using window.open. The same should happen. |
| 308 | ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); |
| 309 | WindowOpenHelper(browser(), host, |
| 310 | base_url.Resolve("path1/empty.html"), true); |
| 311 | WindowOpenHelper(browser(), host, |
| 312 | base_url.Resolve("path2/empty.html"), true); |
| 313 | |
| 314 | // Now let's have a tab navigate out of and back into the app's web |
| 315 | // extent. Neither navigation should switch processes. |
| 316 | const GURL& app_url(base_url.Resolve("path1/empty.html")); |
| 317 | const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
| 318 | RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host(); |
| 319 | NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url); |
| 320 | EXPECT_EQ(host2->process(), |
| 321 | browser()->GetTabContentsAt(2)->render_view_host()->process()); |
| 322 | NavigateTabHelper(browser()->GetTabContentsAt(2), app_url); |
| 323 | EXPECT_EQ(host2->process(), |
| 324 | browser()->GetTabContentsAt(2)->render_view_host()->process()); |
| 325 | } |
| 326 | |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 327 | // Tests that app process switching works properly in the following scenario: |
| 328 | // 1. navigate to a page1 in the app |
| 329 | // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") |
| 330 | // 3. page2 redirects back to a page in the app |
| 331 | // The final navigation should end up in the app process. |
| 332 | // See http://crbug.com/61757 |
[email protected] | c374f8a8 | 2011-12-01 00:45:08 | [diff] [blame] | 333 | // This test occasionally timeout on aura. See crbug.com/105957. |
| 334 | #if defined(USE_AURA) |
| 335 | #define MAYBE_AppProcessRedirectBack DISABLED_AppProcessRedirectBack |
| 336 | #else |
| 337 | #define MAYBE_AppProcessRedirectBack AppProcessRedirectBack |
| 338 | #endif |
| 339 | IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessRedirectBack) { |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 340 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 341 | switches::kDisablePopupBlocking); |
| 342 | |
| 343 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 344 | ASSERT_TRUE(test_server()->Start()); |
| 345 | |
| 346 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 347 | |
| 348 | // Open two tabs in the app. |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 349 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 350 | |
| 351 | browser()->NewTab(); |
| 352 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 353 | browser()->NewTab(); |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 354 | // Wait until the second tab finishes its redirect train (3 hops). |
| 355 | // 1. We navigate to redirect.html |
| 356 | // 2. Renderer navigates and finishes, counting as a load stop. |
| 357 | // 3. Renderer issues the meta refresh to navigate to server-redirect. |
| 358 | // 4. Renderer is now in a "provisional load", waiting for navigation to |
| 359 | // complete. |
| 360 | // 5. Browser sees a redirect response from server-redirect to empty.html, and |
| 361 | // transfers that to a new navigation, using RequestTransferURL. |
| 362 | // 6. We navigate to empty.html. |
| 363 | // 7. Renderer is still in a provisional load to server-redirect, so that is |
| 364 | // cancelled, and counts as a load stop |
| 365 | // 8. Renderer navigates to empty.html, and finishes loading, counting as the |
| 366 | // third load stop |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 367 | ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 368 | browser(), base_url.Resolve("path1/redirect.html"), 3); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 369 | |
| 370 | // 3 tabs, including the initial about:blank. The last 2 should be the same |
| 371 | // process. |
| 372 | ASSERT_EQ(3, browser()->tab_count()); |
[email protected] | 089e8c33 | 2011-01-06 21:37:29 | [diff] [blame] | 373 | EXPECT_EQ("/files/extensions/api_test/app_process/path1/empty.html", |
| 374 | browser()->GetTabContentsAt(2)->controller(). |
| 375 | GetLastCommittedEntry()->url().path()); |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 376 | EXPECT_EQ(browser()->GetTabContentsAt(1)->render_view_host()->process(), |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 377 | browser()->GetTabContentsAt(2)->render_view_host()->process()); |
| 378 | } |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 379 | |
| 380 | // Ensure that reloading a URL after installing or uninstalling it as an app |
| 381 | // correctly swaps the process. (http://crbug.com/80621) |
[email protected] | 95df17a | 2011-11-03 23:03:06 | [diff] [blame] | 382 | // Disabled until we get a correct fix for 80621. See http://crbug.com/102408. |
| 383 | IN_PROC_BROWSER_TEST_F(AppApiTest, DISABLED_ReloadIntoAppProcess) { |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 384 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 385 | switches::kDisablePopupBlocking); |
| 386 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 387 | extensions::ProcessMap* process_map = |
| 388 | browser()->profile()->GetExtensionService()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 389 | |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 390 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 391 | ASSERT_TRUE(test_server()->Start()); |
| 392 | |
| 393 | // The app under test acts on URLs whose host is "localhost", |
| 394 | // so the URLs we navigate to must have host "localhost". |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 395 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 396 | |
| 397 | // Load an app URL before loading the app. |
| 398 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 399 | TabContents* contents = browser()->GetTabContentsAt(0); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 400 | EXPECT_FALSE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 401 | contents->render_view_host()->process()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 402 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 403 | // Load app and navigate to the page. |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 404 | const Extension* app = |
| 405 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 406 | ASSERT_TRUE(app); |
| 407 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 408 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 409 | contents->render_view_host()->process()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 410 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 411 | // Disable app and navigate to the page. |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 412 | DisableExtension(app->id()); |
| 413 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 414 | EXPECT_FALSE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 415 | contents->render_view_host()->process()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 416 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 417 | // Enable app and reload the page. |
| 418 | EnableExtension(app->id()); |
| 419 | ui_test_utils::WindowedNotificationObserver reload_observer( |
| 420 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 421 | content::Source<NavigationController>( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 422 | &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 423 | controller())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 424 | browser()->Reload(CURRENT_TAB); |
| 425 | reload_observer.Wait(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 426 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 427 | contents->render_view_host()->process()->GetID())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 428 | |
| 429 | // Disable app and reload the page. |
| 430 | DisableExtension(app->id()); |
| 431 | ui_test_utils::WindowedNotificationObserver reload_observer2( |
| 432 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 433 | content::Source<NavigationController>( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 434 | &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 435 | controller())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 436 | browser()->Reload(CURRENT_TAB); |
| 437 | reload_observer2.Wait(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 438 | EXPECT_FALSE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 439 | contents->render_view_host()->process()->GetID())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 440 | |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 441 | // Enable app and reload via JavaScript. |
| 442 | EnableExtension(app->id()); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 443 | ui_test_utils::WindowedNotificationObserver js_reload_observer( |
| 444 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 445 | content::Source<NavigationController>( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 446 | &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 447 | controller())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 448 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), |
| 449 | L"", L"location.reload();")); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 450 | js_reload_observer.Wait(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 451 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 452 | contents->render_view_host()->process()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 453 | |
| 454 | // Disable app and reload via JavaScript. |
| 455 | DisableExtension(app->id()); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 456 | ui_test_utils::WindowedNotificationObserver js_reload_observer2( |
| 457 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 458 | content::Source<NavigationController>( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 459 | &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 460 | controller())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 461 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), |
| 462 | L"", L"location.reload();")); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 463 | js_reload_observer2.Wait(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 464 | EXPECT_FALSE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 465 | contents->render_view_host()->process()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 466 | } |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 467 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 468 | // Tests that if we have a non-app process (path3/container.html) that has an |
| 469 | // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
| 470 | // link from that iframe to a new window to a URL in the app's extent (path1/ |
| 471 | // empty.html) results in the new window being in an app process. See |
| 472 | // http://crbug.com/89272 for more details. |
| 473 | IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { |
| 474 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 475 | switches::kDisablePopupBlocking); |
| 476 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 477 | extensions::ProcessMap* process_map = |
| 478 | browser()->profile()->GetExtensionService()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 479 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 480 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 481 | ASSERT_TRUE(test_server()->Start()); |
| 482 | |
| 483 | GURL base_url = GetTestBaseURL("app_process"); |
| 484 | |
| 485 | // Load app and start URL (not in the app). |
| 486 | const Extension* app = |
| 487 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 488 | ASSERT_TRUE(app); |
| 489 | ui_test_utils::NavigateToURLWithDisposition( |
| 490 | browser(), |
| 491 | base_url.Resolve("path3/container.html"), |
| 492 | CURRENT_TAB, |
| 493 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | |
| 494 | ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 495 | EXPECT_FALSE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 496 | browser()->GetTabContentsAt(0)->render_view_host()->process()->GetID())); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 497 | |
| 498 | // Wait for popup window to appear. |
| 499 | GURL app_url = base_url.Resolve("path1/empty.html"); |
| 500 | Browser* last_active_browser = BrowserList::GetLastActive(); |
| 501 | EXPECT_TRUE(last_active_browser); |
| 502 | ASSERT_NE(browser(), last_active_browser); |
| 503 | TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
| 504 | EXPECT_TRUE(newtab); |
| 505 | if (!newtab->controller().GetLastCommittedEntry() || |
[email protected] | 160f17f1 | 2011-10-19 00:40:00 | [diff] [blame] | 506 | newtab->controller().GetLastCommittedEntry()->url() != app_url) { |
| 507 | // TODO(gbillock): This still looks racy. Need to make a custom |
| 508 | // observer to intercept new window creation and then look for |
| 509 | // NAV_ENTRY_COMMITTED on the new tab there. |
| 510 | ui_test_utils::WindowedNotificationObserver observer( |
| 511 | content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
[email protected] | 86ab86b | 2011-10-19 03:07:55 | [diff] [blame] | 512 | content::Source<NavigationController>(&(newtab->controller()))); |
[email protected] | 160f17f1 | 2011-10-19 00:40:00 | [diff] [blame] | 513 | observer.Wait(); |
| 514 | } |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 515 | |
| 516 | // Popup window should be in the app's process. |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 517 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 518 | last_active_browser->GetTabContentsAt(0)->render_view_host()->process()-> |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 519 | GetID())); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 520 | } |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 521 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 522 | // Tests that if we have an app process (path1/container.html) with a non-app |
| 523 | // iframe (path3/iframe.html), then opening a link from that iframe to a new |
| 524 | // window to a same-origin non-app URL (path3/empty.html) should keep the window |
| 525 | // in the app process. |
| 526 | // This is in contrast to OpenAppFromIframe, since here the popup will not be |
| 527 | // missing special permissions and should be scriptable from the iframe. |
| 528 | // See http://crbug.com/92669 for more details. |
| 529 | IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { |
| 530 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 531 | switches::kDisablePopupBlocking); |
| 532 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 533 | extensions::ProcessMap* process_map = |
| 534 | browser()->profile()->GetExtensionService()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 535 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 536 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 537 | ASSERT_TRUE(test_server()->Start()); |
| 538 | |
| 539 | GURL base_url = GetTestBaseURL("app_process"); |
| 540 | |
| 541 | // Load app and start URL (in the app). |
| 542 | const Extension* app = |
| 543 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 544 | ASSERT_TRUE(app); |
[email protected] | 160f17f1 | 2011-10-19 00:40:00 | [diff] [blame] | 545 | ui_test_utils::WindowedNotificationObserver observer( |
| 546 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 547 | content::NotificationService::AllSources()); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 548 | ui_test_utils::NavigateToURLWithDisposition( |
| 549 | browser(), |
| 550 | base_url.Resolve("path1/container.html"), |
| 551 | CURRENT_TAB, |
| 552 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | |
| 553 | ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 554 | content::RenderProcessHost* process = |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 555 | browser()->GetTabContentsAt(0)->render_view_host()->process(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 556 | EXPECT_TRUE(process_map->Contains(process->GetID())); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 557 | |
| 558 | // Wait for popup window to appear. The new Browser may not have been |
| 559 | // added with SetLastActive, in which case we need to show it first. |
| 560 | // This is necessary for popup windows without a cross-site transition. |
| 561 | if (browser() == BrowserList::GetLastActive()) { |
| 562 | // Grab the second window and show it. |
| 563 | ASSERT_TRUE(BrowserList::size() == 2); |
| 564 | Browser* popup_browser = *(++BrowserList::begin()); |
| 565 | popup_browser->window()->Show(); |
| 566 | } |
| 567 | Browser* last_active_browser = BrowserList::GetLastActive(); |
| 568 | EXPECT_TRUE(last_active_browser); |
| 569 | ASSERT_NE(browser(), last_active_browser); |
| 570 | TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
| 571 | EXPECT_TRUE(newtab); |
| 572 | GURL non_app_url = base_url.Resolve("path3/empty.html"); |
[email protected] | 160f17f1 | 2011-10-19 00:40:00 | [diff] [blame] | 573 | observer.Wait(); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 574 | |
| 575 | // Popup window should be in the app's process. |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 576 | content::RenderProcessHost* popup_process = |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 577 | last_active_browser->GetTabContentsAt(0)->render_view_host()->process(); |
| 578 | EXPECT_EQ(process, popup_process); |
| 579 | } |
| 580 | |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 581 | IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadAppAfterCrash) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 582 | extensions::ProcessMap* process_map = |
| 583 | browser()->profile()->GetExtensionService()->process_map(); |
| 584 | |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 585 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 586 | ASSERT_TRUE(test_server()->Start()); |
| 587 | |
| 588 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 589 | |
| 590 | GURL base_url = GetTestBaseURL("app_process"); |
| 591 | |
| 592 | // Load the app, chrome.app.isInstalled should be true. |
| 593 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 594 | TabContents* contents = browser()->GetTabContentsAt(0); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 595 | EXPECT_TRUE(process_map->Contains( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 596 | contents->render_view_host()->process()->GetID())); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 597 | bool is_installed = false; |
| 598 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 599 | contents->render_view_host(), L"", |
| 600 | L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 601 | &is_installed)); |
| 602 | ASSERT_TRUE(is_installed); |
| 603 | |
| 604 | // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
| 605 | ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 606 | ui_test_utils::WindowedNotificationObserver observer( |
| 607 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 608 | content::Source<NavigationController>( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 609 | &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
| 610 | controller())); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 611 | browser()->Reload(CURRENT_TAB); |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 612 | observer.Wait(); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 613 | ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 614 | contents->render_view_host(), L"", |
| 615 | L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 616 | &is_installed)); |
| 617 | ASSERT_TRUE(is_installed); |
| 618 | } |