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