[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] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 5 | #include "base/command_line.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 6 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 7 | #include "chrome/browser/extensions/extension_apitest.h" |
| 8 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 11 | #include "chrome/browser/extensions/process_map.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 12 | #include "chrome/browser/profiles/profile.h" |
[email protected] | e0731d7 | 2013-07-25 12:39:46 | [diff] [blame] | 13 | #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 16 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 17 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 18 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 19 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 20 | #include "chrome/common/chrome_switches.h" |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 21 | #include "chrome/common/extensions/extension.h" |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 22 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 23 | #include "chrome/test/base/test_switches.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 24 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 25 | #include "content/public/browser/navigation_entry.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 26 | #include "content/public/browser/notification_service.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 27 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 28 | #include "content/public/browser/render_view_host.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 29 | #include "content/public/browser/web_contents.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 30 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 5b8ff1c | 2012-06-02 20:42:20 | [diff] [blame] | 31 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 32 | #include "net/dns/mock_host_resolver.h" |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 33 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 34 | #include "sync/api/string_ordinal.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 35 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 36 | using content::NavigationController; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 37 | using content::RenderViewHost; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 38 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 39 | using extensions::Extension; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 40 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 41 | class AppApiTest : public ExtensionApiTest { |
| 42 | protected: |
| 43 | // Gets the base URL for files for a specific test, making sure that it uses |
| 44 | // "localhost" as the hostname, since that is what the extent is declared |
| 45 | // as in the test apps manifests. |
| 46 | GURL GetTestBaseURL(std::string test_directory) { |
| 47 | GURL::Replacements replace_host; |
| 48 | std::string host_str("localhost"); // must stay in scope with replace_host |
| 49 | replace_host.SetHostStr(host_str); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 50 | GURL base_url = embedded_test_server()->GetURL( |
| 51 | "/extensions/api_test/" + test_directory + "/"); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 52 | return base_url.ReplaceComponents(replace_host); |
| 53 | } |
| 54 | |
| 55 | // Pass flags to make testing apps easier. |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 56 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 57 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 58 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 59 | switches::kDisablePopupBlocking); |
| 60 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 61 | switches::kAllowHTTPBackgroundPage); |
| 62 | } |
| 63 | |
| 64 | // Helper function to test that independent tabs of the named app are loaded |
| 65 | // into separate processes. |
| 66 | void TestAppInstancesHelper(std::string app_name) { |
| 67 | LOG(INFO) << "Start of test."; |
| 68 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 69 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 70 | browser()->profile())->extension_service()->process_map(); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 71 | |
| 72 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 73 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 74 | |
| 75 | ASSERT_TRUE(LoadExtension( |
| 76 | test_data_dir_.AppendASCII(app_name))); |
[email protected] | 50686c3b | 2013-04-27 00:26:27 | [diff] [blame] | 77 | const Extension* extension = GetSingleLoadedExtension(); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 78 | |
| 79 | // Open two tabs in the app, one outside it. |
| 80 | GURL base_url = GetTestBaseURL(app_name); |
| 81 | |
| 82 | // Test both opening a URL in a new tab, and opening a tab and then |
| 83 | // navigating it. Either way, app tabs should be considered extension |
| 84 | // processes, but they have no elevated privileges and thus should not |
| 85 | // have WebUI bindings. |
| 86 | ui_test_utils::NavigateToURLWithDisposition( |
| 87 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 88 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 89 | LOG(INFO) << "Nav 1."; |
| 90 | EXPECT_TRUE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 91 | browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 92 | GetRenderProcessHost()->GetID())); |
| 93 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI()); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 94 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 95 | content::WindowedNotificationObserver tab_added_observer( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 96 | chrome::NOTIFICATION_TAB_ADDED, |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 97 | content::NotificationService::AllSources()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 98 | chrome::NewTab(browser()); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 99 | tab_added_observer.Wait(); |
| 100 | LOG(INFO) << "New tab."; |
| 101 | ui_test_utils::NavigateToURL(browser(), |
| 102 | base_url.Resolve("path2/empty.html")); |
| 103 | LOG(INFO) << "Nav 2."; |
| 104 | EXPECT_TRUE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 105 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 106 | GetRenderProcessHost()->GetID())); |
| 107 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI()); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 108 | |
| 109 | // We should have opened 2 new extension tabs. Including the original blank |
| 110 | // tab, we now have 3 tabs. The two app tabs should not be in the same |
| 111 | // process, since they do not have the background permission. (Thus, we |
| 112 | // want to separate them to improve responsiveness.) |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 113 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
| 114 | WebContents* tab1 = browser()->tab_strip_model()->GetWebContentsAt(1); |
| 115 | WebContents* tab2 = browser()->tab_strip_model()->GetWebContentsAt(2); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 116 | EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost()); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 117 | |
| 118 | // Opening tabs with window.open should keep the page in the opener's |
| 119 | // process. |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 120 | ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 121 | browser()->host_desktop_type())); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 122 | OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 123 | LOG(INFO) << "WindowOpenHelper 1."; |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 124 | OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 125 | LOG(INFO) << "End of test."; |
[email protected] | 50686c3b | 2013-04-27 00:26:27 | [diff] [blame] | 126 | UnloadExtension(extension->id()); |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 127 | } |
| 128 | }; |
| 129 | |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 130 | // Omits the disable-popup-blocking flag so we can cover that case. |
| 131 | class BlockedAppApiTest : public AppApiTest { |
| 132 | protected: |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 133 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 134 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 135 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 136 | switches::kAllowHTTPBackgroundPage); |
| 137 | } |
| 138 | }; |
| 139 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 140 | // Tests that hosted apps with the background permission get a process-per-app |
| 141 | // model, since all pages need to be able to script the background page. |
[email protected] | c9c20608 | 2013-01-29 00:42:56 | [diff] [blame] | 142 | // http://crbug.com/172750 |
[email protected] | 2340a3c | 2013-06-17 20:54:36 | [diff] [blame] | 143 | IN_PROC_BROWSER_TEST_F(AppApiTest, DISABLED_AppProcess) { |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 144 | LOG(INFO) << "Start of test."; |
[email protected] | 9b60083 | 2011-10-26 20:31:59 | [diff] [blame] | 145 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 146 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 147 | browser()->profile())->extension_service()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 148 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 149 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 150 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 151 | |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 152 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 153 | |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 154 | LOG(INFO) << "Loaded extension."; |
| 155 | |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 156 | // Open two tabs in the app, one outside it. |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 157 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 158 | |
[email protected] | f0e1333 | 2011-05-20 22:41:14 | [diff] [blame] | 159 | // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 160 | // it. Either way, app tabs should be considered extension processes, but |
| 161 | // they have no elevated privileges and thus should not have WebUI bindings. |
| 162 | ui_test_utils::NavigateToURLWithDisposition( |
| 163 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 164 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 165 | EXPECT_TRUE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 166 | browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 167 | GetRenderProcessHost()->GetID())); |
| 168 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI()); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 169 | LOG(INFO) << "Nav 1."; |
| 170 | |
| 171 | ui_test_utils::NavigateToURLWithDisposition( |
| 172 | browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, |
| 173 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 174 | EXPECT_TRUE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 175 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 176 | GetRenderProcessHost()->GetID())); |
| 177 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI()); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 178 | LOG(INFO) << "Nav 2."; |
| 179 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 180 | content::WindowedNotificationObserver tab_added_observer( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 181 | chrome::NOTIFICATION_TAB_ADDED, |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 182 | content::NotificationService::AllSources()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 183 | chrome::NewTab(browser()); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 184 | tab_added_observer.Wait(); |
| 185 | LOG(INFO) << "New tab."; |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 186 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 187 | LOG(INFO) << "Nav 3."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 188 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 189 | browser()->tab_strip_model()->GetWebContentsAt(3)-> |
| 190 | GetRenderProcessHost()->GetID())); |
| 191 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(3)->GetWebUI()); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 192 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 193 | // We should have opened 3 new extension tabs. Including the original blank |
| 194 | // tab, we now have 4 tabs. Because the app_process app has the background |
| 195 | // permission, all of its instances are in the same process. Thus two tabs |
| 196 | // should be part of the extension app and grouped in the same process. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 197 | ASSERT_EQ(4, browser()->tab_strip_model()->count()); |
| 198 | WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1); |
[email protected] | cbf4d191 | 2010-08-12 18:24:57 | [diff] [blame] | 199 | |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 200 | EXPECT_EQ(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 201 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 202 | GetRenderProcessHost()); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 203 | EXPECT_NE(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 204 | browser()->tab_strip_model()->GetWebContentsAt(3)-> |
| 205 | GetRenderProcessHost()); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 206 | |
| 207 | // Now let's do the same using window.open. The same should happen. |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 208 | ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 209 | browser()->host_desktop_type())); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 210 | OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 211 | LOG(INFO) << "WindowOpenHelper 1."; |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 212 | OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 213 | LOG(INFO) << "WindowOpenHelper 2."; |
[email protected] | 361a5f1f | 2011-10-05 20:11:15 | [diff] [blame] | 214 | // 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] | 215 | // argument), but we temporarily avoid swapping processes away from a hosted |
| 216 | // app if it has an opener, because some OAuth providers make script calls |
| 217 | // between non-app popups and non-app iframes in the app process. |
[email protected] | 361a5f1f | 2011-10-05 20:11:15 | [diff] [blame] | 218 | // See crbug.com/59285. |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 219 | OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 220 | LOG(INFO) << "WindowOpenHelper 3."; |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 221 | |
| 222 | // Now let's have these pages navigate, into or out of the extension web |
| 223 | // extent. They should switch processes. |
[email protected] | 9a1e6d4 | 2010-04-26 22:29:36 | [diff] [blame] | 224 | const GURL& app_url(base_url.Resolve("path1/empty.html")); |
| 225 | const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 226 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2), |
| 227 | non_app_url); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 228 | LOG(INFO) << "NavigateTabHelper 1."; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 229 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(3), |
| 230 | app_url); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 231 | LOG(INFO) << "NavigateTabHelper 2."; |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 232 | EXPECT_NE(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 233 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 234 | GetRenderProcessHost()); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 235 | EXPECT_EQ(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 236 | browser()->tab_strip_model()->GetWebContentsAt(3)-> |
| 237 | GetRenderProcessHost()); |
[email protected] | 08e94b8 | 2010-12-15 22:51:04 | [diff] [blame] | 238 | |
| 239 | // If one of the popup tabs navigates back to the app, window.opener should |
| 240 | // be valid. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 241 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(6), |
| 242 | app_url); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 243 | LOG(INFO) << "NavigateTabHelper 3."; |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 244 | EXPECT_EQ(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 245 | browser()->tab_strip_model()->GetWebContentsAt(6)-> |
| 246 | GetRenderProcessHost()); |
[email protected] | 08e94b8 | 2010-12-15 22:51:04 | [diff] [blame] | 247 | bool windowOpenerValid = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 248 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 249 | browser()->tab_strip_model()->GetWebContentsAt(6), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 250 | "window.domAutomationController.send(window.opener != null)", |
[email protected] | 08e94b8 | 2010-12-15 22:51:04 | [diff] [blame] | 251 | &windowOpenerValid)); |
| 252 | ASSERT_TRUE(windowOpenerValid); |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 253 | |
| 254 | LOG(INFO) << "End of test."; |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 255 | } |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 256 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 257 | // Test that hosted apps without the background permission use a process per app |
| 258 | // instance model, such that separate instances are in separate processes. |
[email protected] | 4ef849e | 2013-06-10 08:36:59 | [diff] [blame] | 259 | // Flaky on Windows. http://crbug.com/248047 |
| 260 | #if defined(OS_WIN) |
| 261 | #define MAYBE_AppProcessInstances DISABLED_AppProcessInstances |
| 262 | #else |
| 263 | #define MAYBE_AppProcessInstances AppProcessInstances |
| 264 | #endif |
| 265 | IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 266 | TestAppInstancesHelper("app_process_instances"); |
| 267 | } |
[email protected] | 87c7c29 | 2011-10-27 16:16:41 | [diff] [blame] | 268 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 269 | // Test that hosted apps with the background permission but that set |
| 270 | // allow_js_access to false also use a process per app instance model. |
| 271 | // Separate instances should be in separate processes. |
[email protected] | 0d70b7d4 | 2012-12-13 01:14:20 | [diff] [blame] | 272 | // Flaky on XP: http://crbug.com/165834 |
[email protected] | 0cfb748b | 2012-12-13 01:10:11 | [diff] [blame] | 273 | #if defined(OS_WIN) |
| 274 | #define MAYBE_AppProcessBackgroundInstances \ |
| 275 | DISABLED_AppProcessBackgroundInstances |
| 276 | #else |
| 277 | #define MAYBE_AppProcessBackgroundInstances AppProcessBackgroundInstances |
| 278 | #endif |
| 279 | IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessBackgroundInstances) { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 280 | TestAppInstancesHelper("app_process_background_instances"); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 283 | // Tests that bookmark apps do not use the app process model and are treated |
| 284 | // like normal web pages instead. http://crbug.com/104636. |
[email protected] | b3b3967 | 2013-05-07 20:02:43 | [diff] [blame] | 285 | // Timing out on Windows. http://crbug.com/238777 |
| 286 | #if defined(OS_WIN) |
| 287 | #define MAYBE_BookmarkAppGetsNormalProcess DISABLED_BookmarkAppGetsNormalProcess |
| 288 | #else |
| 289 | #define MAYBE_BookmarkAppGetsNormalProcess BookmarkAppGetsNormalProcess |
| 290 | #endif |
| 291 | IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_BookmarkAppGetsNormalProcess) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 292 | ExtensionService* service = extensions::ExtensionSystem::Get( |
| 293 | browser()->profile())->extension_service(); |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 294 | extensions::ProcessMap* process_map = service->process_map(); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 295 | |
| 296 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 297 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 298 | GURL base_url = GetTestBaseURL("app_process"); |
| 299 | |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 300 | // Load an app as a bookmark app. |
| 301 | std::string error; |
| 302 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
| 303 | test_data_dir_.AppendASCII("app_process"), |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 304 | extensions::Manifest::UNPACKED, |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 305 | Extension::FROM_BOOKMARK, |
| 306 | &error)); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 307 | service->OnExtensionInstalled(extension.get(), |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 308 | syncer::StringOrdinal::CreateInitialOrdinal(), |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 309 | false /* no requirement errors */, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 310 | extensions::Blacklist::NOT_BLACKLISTED, |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 311 | false /* don't wait for idle */); |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 312 | ASSERT_TRUE(extension.get()); |
| 313 | ASSERT_TRUE(extension->from_bookmark()); |
| 314 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 315 | // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 316 | // it. Either way, bookmark app tabs should be considered normal processes |
| 317 | // with no elevated privileges and no WebUI bindings. |
| 318 | ui_test_utils::NavigateToURLWithDisposition( |
| 319 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 320 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 321 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 322 | browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 323 | GetRenderProcessHost()->GetID())); |
| 324 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 325 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 326 | content::WindowedNotificationObserver tab_added_observer( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 327 | chrome::NOTIFICATION_TAB_ADDED, |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 328 | content::NotificationService::AllSources()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 329 | chrome::NewTab(browser()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 330 | tab_added_observer.Wait(); |
| 331 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 332 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 333 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 334 | GetRenderProcessHost()->GetID())); |
| 335 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 336 | |
| 337 | // We should have opened 2 new bookmark app tabs. Including the original blank |
| 338 | // tab, we now have 3 tabs. Because normal pages use the |
| 339 | // process-per-site-instance model, each should be in its own process. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 340 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
| 341 | WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 342 | EXPECT_NE(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 343 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 344 | GetRenderProcessHost()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 345 | |
| 346 | // Now let's do the same using window.open. The same should happen. |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 347 | ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 348 | browser()->host_desktop_type())); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 349 | OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); |
| 350 | OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 351 | |
| 352 | // Now let's have a tab navigate out of and back into the app's web |
| 353 | // extent. Neither navigation should switch processes. |
| 354 | const GURL& app_url(base_url.Resolve("path1/empty.html")); |
| 355 | const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 356 | RenderViewHost* host2 = |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 357 | browser()->tab_strip_model()->GetWebContentsAt(2)->GetRenderViewHost(); |
| 358 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2), |
| 359 | non_app_url); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 360 | EXPECT_EQ(host2->GetProcess(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 361 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 362 | GetRenderProcessHost()); |
| 363 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2), |
| 364 | app_url); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 365 | EXPECT_EQ(host2->GetProcess(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 366 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 367 | GetRenderProcessHost()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 370 | // Tests that app process switching works properly in the following scenario: |
| 371 | // 1. navigate to a page1 in the app |
| 372 | // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") |
| 373 | // 3. page2 redirects back to a page in the app |
| 374 | // The final navigation should end up in the app process. |
| 375 | // See http://crbug.com/61757 |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 376 | IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) { |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 377 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 378 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 379 | |
| 380 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 381 | |
| 382 | // Open two tabs in the app. |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 383 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 384 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 385 | chrome::NewTab(browser()); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 386 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 387 | chrome::NewTab(browser()); |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 388 | // Wait until the second tab finishes its redirect train (2 hops). |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 389 | // 1. We navigate to redirect.html |
| 390 | // 2. Renderer navigates and finishes, counting as a load stop. |
| 391 | // 3. Renderer issues the meta refresh to navigate to server-redirect. |
| 392 | // 4. Renderer is now in a "provisional load", waiting for navigation to |
| 393 | // complete. |
| 394 | // 5. Browser sees a redirect response from server-redirect to empty.html, and |
| 395 | // transfers that to a new navigation, using RequestTransferURL. |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 396 | // 6. Renderer navigates to empty.html, and finishes loading, counting as the |
| 397 | // second load stop |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 398 | ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 399 | browser(), base_url.Resolve("path1/redirect.html"), 2); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 400 | |
| 401 | // 3 tabs, including the initial about:blank. The last 2 should be the same |
| 402 | // process. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 403 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 404 | EXPECT_EQ("/extensions/api_test/app_process/path1/empty.html", |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 405 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 406 | GetController().GetLastCommittedEntry()->GetURL().path()); |
| 407 | EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 408 | GetRenderProcessHost(), |
| 409 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 410 | GetRenderProcessHost()); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 411 | } |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 412 | |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 413 | // Ensure that re-navigating to a URL after installing or uninstalling it as an |
| 414 | // app correctly swaps the tab to the app process. (http://crbug.com/80621) |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 415 | // |
[email protected] | bc857a6 | 2013-05-08 16:44:53 | [diff] [blame] | 416 | // Fails on Windows. http://crbug.com/238670 |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 417 | // Added logging to help diagnose the location of the problem. |
| 418 | IN_PROC_BROWSER_TEST_F(AppApiTest, NavigateIntoAppProcess) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 419 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 420 | browser()->profile())->extension_service()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 421 | |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 422 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 423 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 424 | |
| 425 | // The app under test acts on URLs whose host is "localhost", |
| 426 | // so the URLs we navigate to must have host "localhost". |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 427 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 428 | |
| 429 | // Load an app URL before loading the app. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 430 | LOG(INFO) << "Loading path1/empty.html."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 431 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 432 | LOG(INFO) << "Loading path1/empty.html - done."; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 433 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 434 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 435 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 436 | |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 437 | // Load app and re-navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 438 | LOG(INFO) << "Loading extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 439 | const Extension* app = |
| 440 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 441 | LOG(INFO) << "Loading extension - done."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 442 | ASSERT_TRUE(app); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 443 | LOG(INFO) << "Loading path1/empty.html."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 444 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 445 | LOG(INFO) << "Loading path1/empty.html - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 446 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 447 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 448 | |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 449 | // Disable app and re-navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 450 | LOG(INFO) << "Disabling extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 451 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 452 | LOG(INFO) << "Disabling extension - done."; |
| 453 | LOG(INFO) << "Loading path1/empty.html."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 454 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 455 | LOG(INFO) << "Loading path1/empty.html - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 456 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 457 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // Ensure that reloading a URL after installing or uninstalling it as an app |
| 461 | // correctly swaps the tab to the app process. (http://crbug.com/80621) |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 462 | // |
| 463 | // Added logging to help diagnose the location of the problem. |
| 464 | // http://crbug.com/238670 |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 465 | IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) { |
| 466 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 467 | browser()->profile())->extension_service()->process_map(); |
| 468 | |
| 469 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 470 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 471 | |
| 472 | // The app under test acts on URLs whose host is "localhost", |
| 473 | // so the URLs we navigate to must have host "localhost". |
| 474 | GURL base_url = GetTestBaseURL("app_process"); |
| 475 | |
| 476 | // Load app, disable it, and navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 477 | LOG(INFO) << "Loading extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 478 | const Extension* app = |
| 479 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 480 | LOG(INFO) << "Loading extension - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 481 | ASSERT_TRUE(app); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 482 | LOG(INFO) << "Disabling extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 483 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 484 | LOG(INFO) << "Disabling extension - done."; |
| 485 | LOG(INFO) << "Navigate to path1/empty.html."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 486 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 487 | LOG(INFO) << "Navigate to path1/empty.html - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 488 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 489 | EXPECT_FALSE(process_map->Contains( |
| 490 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 491 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 492 | // Enable app and reload the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 493 | LOG(INFO) << "Enabling extension."; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 494 | EnableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 495 | LOG(INFO) << "Enabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 496 | content::WindowedNotificationObserver reload_observer( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 497 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 498 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 499 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 500 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 501 | LOG(INFO) << "Reloading."; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 502 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 503 | reload_observer.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 504 | LOG(INFO) << "Reloading - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 505 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 506 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 507 | |
| 508 | // Disable app and reload the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 509 | LOG(INFO) << "Disabling extension."; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 510 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 511 | LOG(INFO) << "Disabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 512 | content::WindowedNotificationObserver reload_observer2( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 513 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 514 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 515 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 516 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 517 | LOG(INFO) << "Reloading."; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 518 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 519 | reload_observer2.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 520 | LOG(INFO) << "Reloading - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 521 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 522 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // Ensure that reloading a URL with JavaScript after installing or uninstalling |
| 526 | // it as an app correctly swaps the process. (http://crbug.com/80621) |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 527 | // |
| 528 | // Crashes on Windows and Mac. http://crbug.com/238670 |
| 529 | // Added logging to help diagnose the location of the problem. |
| 530 | IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcessWithJavaScript) { |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 531 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 532 | browser()->profile())->extension_service()->process_map(); |
| 533 | |
| 534 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 535 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 536 | |
| 537 | // The app under test acts on URLs whose host is "localhost", |
| 538 | // so the URLs we navigate to must have host "localhost". |
| 539 | GURL base_url = GetTestBaseURL("app_process"); |
| 540 | |
| 541 | // Load app, disable it, and navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 542 | LOG(INFO) << "Loading extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 543 | const Extension* app = |
| 544 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 545 | LOG(INFO) << "Loading extension - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 546 | ASSERT_TRUE(app); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 547 | LOG(INFO) << "Disabling extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 548 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 549 | LOG(INFO) << "Disabling extension - done."; |
| 550 | LOG(INFO) << "Navigate to path1/empty.html."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 551 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 552 | LOG(INFO) << "Navigate to path1/empty.html - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 553 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 554 | EXPECT_FALSE(process_map->Contains( |
| 555 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 556 | |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 557 | // Enable app and reload via JavaScript. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 558 | LOG(INFO) << "Enabling extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 559 | EnableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 560 | LOG(INFO) << "Enabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 561 | content::WindowedNotificationObserver js_reload_observer( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 562 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 563 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 564 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 565 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 566 | LOG(INFO) << "Executing location.reload()."; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 567 | ASSERT_TRUE(content::ExecuteScript(contents, "location.reload();")); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 568 | js_reload_observer.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 569 | LOG(INFO) << "Executing location.reload() - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 570 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 571 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 572 | |
| 573 | // Disable app and reload via JavaScript. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 574 | LOG(INFO) << "Disabling extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 575 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 576 | LOG(INFO) << "Disabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 577 | content::WindowedNotificationObserver js_reload_observer2( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 578 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 579 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 580 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 581 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 582 | LOG(INFO) << "Executing location = location."; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 583 | ASSERT_TRUE(content::ExecuteScript(contents, "location = location;")); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 584 | js_reload_observer2.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 585 | LOG(INFO) << "Executing location = location - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 586 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 587 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 588 | } |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 589 | |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 590 | namespace { |
| 591 | |
| 592 | void RenderViewHostCreated(std::vector<content::RenderViewHost*>* rvh_vector, |
| 593 | content::RenderViewHost* rvh) { |
| 594 | rvh_vector->push_back(rvh); |
| 595 | } |
| 596 | |
| 597 | } // namespace |
| 598 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 599 | // Tests that if we have a non-app process (path3/container.html) that has an |
| 600 | // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
| 601 | // link from that iframe to a new window to a URL in the app's extent (path1/ |
| 602 | // empty.html) results in the new window being in an app process. See |
| 603 | // http://crbug.com/89272 for more details. |
[email protected] | 1f4495b | 2012-10-12 05:51:05 | [diff] [blame] | 604 | IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 605 | #if defined(OS_WIN) && defined(USE_ASH) |
| 606 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
[email protected] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 607 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 608 | return; |
| 609 | #endif |
| 610 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 611 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 612 | browser()->profile())->extension_service()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 613 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 614 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 615 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 616 | |
| 617 | GURL base_url = GetTestBaseURL("app_process"); |
| 618 | |
| 619 | // Load app and start URL (not in the app). |
| 620 | const Extension* app = |
| 621 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 622 | ASSERT_TRUE(app); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 623 | |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 624 | std::vector<content::RenderViewHost*> rvh_vector; |
| 625 | content::RenderViewHost::CreatedCallback rvh_callback( |
| 626 | base::Bind(&RenderViewHostCreated, &rvh_vector)); |
| 627 | content::RenderViewHost::AddCreatedCallback(rvh_callback); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 628 | ui_test_utils::NavigateToURL(browser(), |
| 629 | base_url.Resolve("path3/container.html")); |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 630 | content::RenderViewHost::RemoveCreatedCallback(rvh_callback); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 631 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 632 | browser()->tab_strip_model()->GetWebContentsAt(0)-> |
| 633 | GetRenderProcessHost()->GetID())); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 634 | |
| 635 | // Popup window should be in the app's process. |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 636 | ASSERT_EQ(3U, rvh_vector.size()); |
| 637 | RenderViewHost* popup_host = rvh_vector[2]; |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 638 | EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 639 | } |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 640 | |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 641 | // Similar to the previous test, but ensure that popup blocking bypass |
| 642 | // isn't granted to the iframe. See crbug.com/117446. |
[email protected] | 1f4495b | 2012-10-12 05:51:05 | [diff] [blame] | 643 | #if defined(OS_CHROMEOS) |
| 644 | // http://crbug.com/153513 |
| 645 | #define MAYBE_OpenAppFromIframe DISABLED_OpenAppFromIframe |
| 646 | #else |
| 647 | #define MAYBE_OpenAppFromIframe OpenAppFromIframe |
| 648 | #endif |
| 649 | IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, MAYBE_OpenAppFromIframe) { |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 650 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 651 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 652 | |
| 653 | // Load app and start URL (not in the app). |
| 654 | const Extension* app = |
| 655 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 656 | ASSERT_TRUE(app); |
| 657 | |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 658 | ui_test_utils::NavigateToURL( |
| 659 | browser(), GetTestBaseURL("app_process").Resolve("path3/container.html")); |
| 660 | |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 661 | WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | e0731d7 | 2013-07-25 12:39:46 | [diff] [blame] | 662 | PopupBlockerTabHelper* popup_blocker_tab_helper = |
| 663 | PopupBlockerTabHelper::FromWebContents(tab); |
[email protected] | 992e291 | 2013-08-19 15:05:24 | [diff] [blame] | 664 | if (!popup_blocker_tab_helper->GetBlockedPopupsCount()) { |
[email protected] | e0731d7 | 2013-07-25 12:39:46 | [diff] [blame] | 665 | content::WindowedNotificationObserver observer( |
| 666 | chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 667 | content::NotificationService::AllSources()); |
| 668 | observer.Wait(); |
| 669 | } |
| 670 | |
[email protected] | 992e291 | 2013-08-19 15:05:24 | [diff] [blame] | 671 | EXPECT_EQ(1u, popup_blocker_tab_helper->GetBlockedPopupsCount()); |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 674 | // Tests that if an extension launches an app via chrome.tabs.create with an URL |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 675 | // that's not in the app's extent but that server redirects to it, we still end |
| 676 | // up with an app process. See http://crbug.com/99349 for more details. |
| 677 | IN_PROC_BROWSER_TEST_F(AppApiTest, ServerRedirectToAppFromExtension) { |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 678 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 679 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 680 | |
| 681 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 682 | const Extension* launcher = |
| 683 | LoadExtension(test_data_dir_.AppendASCII("app_launcher")); |
| 684 | |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 685 | // There should be two navigations by the time the app page is loaded. |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 686 | // 1. The extension launcher page. |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 687 | // 2. The app's URL (which includes a server redirect). |
| 688 | // Note that the server redirect does not generate a navigation event. |
[email protected] | 5b8ff1c | 2012-06-02 20:42:20 | [diff] [blame] | 689 | content::TestNavigationObserver test_navigation_observer( |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 690 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 691 | 2); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 692 | test_navigation_observer.StartWatchingNewWebContents(); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 693 | |
| 694 | // Load the launcher extension, which should launch the app. |
| 695 | ui_test_utils::NavigateToURLWithDisposition( |
| 696 | browser(), |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 697 | launcher->GetResourceURL("server_redirect.html"), |
| 698 | CURRENT_TAB, |
| 699 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 700 | |
| 701 | // Wait for app tab to be created and loaded. |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame^] | 702 | test_navigation_observer.Wait(); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 703 | |
| 704 | // App has loaded, and chrome.app.isInstalled should be true. |
| 705 | bool is_installed = false; |
| 706 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 707 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 708 | "window.domAutomationController.send(chrome.app.isInstalled)", |
| 709 | &is_installed)); |
| 710 | ASSERT_TRUE(is_installed); |
| 711 | } |
| 712 | |
| 713 | // Tests that if an extension launches an app via chrome.tabs.create with an URL |
| 714 | // that's not in the app's extent but that client redirects to it, we still end |
| 715 | // up with an app process. |
| 716 | IN_PROC_BROWSER_TEST_F(AppApiTest, ClientRedirectToAppFromExtension) { |
| 717 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 718 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 719 | |
| 720 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 721 | const Extension* launcher = |
| 722 | LoadExtension(test_data_dir_.AppendASCII("app_launcher")); |
| 723 | |
| 724 | // There should be three navigations by the time the app page is loaded. |
| 725 | // 1. The extension launcher page. |
| 726 | // 2. The URL that the extension launches, which client redirects. |
| 727 | // 3. The app's URL. |
| 728 | content::TestNavigationObserver test_navigation_observer( |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 729 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 730 | 3); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 731 | test_navigation_observer.StartWatchingNewWebContents(); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 732 | |
| 733 | // Load the launcher extension, which should launch the app. |
| 734 | ui_test_utils::NavigateToURLWithDisposition( |
| 735 | browser(), |
| 736 | launcher->GetResourceURL("client_redirect.html"), |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 737 | CURRENT_TAB, |
| 738 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 739 | |
| 740 | // Wait for app tab to be created and loaded. |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame^] | 741 | test_navigation_observer.Wait(); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 742 | |
| 743 | // App has loaded, and chrome.app.isInstalled should be true. |
| 744 | bool is_installed = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 745 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 746 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 747 | "window.domAutomationController.send(chrome.app.isInstalled)", |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 748 | &is_installed)); |
| 749 | ASSERT_TRUE(is_installed); |
| 750 | } |
| 751 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 752 | // Tests that if we have an app process (path1/container.html) with a non-app |
| 753 | // iframe (path3/iframe.html), then opening a link from that iframe to a new |
| 754 | // window to a same-origin non-app URL (path3/empty.html) should keep the window |
| 755 | // in the app process. |
| 756 | // This is in contrast to OpenAppFromIframe, since here the popup will not be |
| 757 | // missing special permissions and should be scriptable from the iframe. |
| 758 | // See http://crbug.com/92669 for more details. |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 759 | IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 760 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 761 | browser()->profile())->extension_service()->process_map(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 762 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 763 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 764 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 765 | |
| 766 | GURL base_url = GetTestBaseURL("app_process"); |
| 767 | |
| 768 | // Load app and start URL (in the app). |
| 769 | const Extension* app = |
| 770 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 771 | ASSERT_TRUE(app); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 772 | |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 773 | std::vector<content::RenderViewHost*> rvh_vector; |
| 774 | content::RenderViewHost::CreatedCallback rvh_callback( |
| 775 | base::Bind(&RenderViewHostCreated, &rvh_vector)); |
| 776 | content::RenderViewHost::AddCreatedCallback(rvh_callback); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 777 | ui_test_utils::NavigateToURL(browser(), |
| 778 | base_url.Resolve("path1/container.html")); |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 779 | content::RenderViewHost::RemoveCreatedCallback(rvh_callback); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 780 | content::RenderProcessHost* process = |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 781 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetRenderProcessHost(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 782 | EXPECT_TRUE(process_map->Contains(process->GetID())); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 783 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 784 | // Popup window should be in the app's process. |
[email protected] | eab2943 | 2013-04-09 21:30:47 | [diff] [blame] | 785 | ASSERT_EQ(2U, rvh_vector.size()); |
| 786 | RenderViewHost* popup_host = rvh_vector[1]; |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 787 | EXPECT_EQ(process, popup_host->GetProcess()); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 788 | } |
| 789 | |
[email protected] | a344b76 | 2012-03-16 18:53:49 | [diff] [blame] | 790 | // http://crbug.com/118502 |
| 791 | #if defined(OS_MACOSX) || defined(OS_LINUX) |
| 792 | #define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash |
| 793 | #else |
| 794 | #define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash |
| 795 | #endif |
| 796 | IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 797 | extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get( |
| 798 | browser()->profile())->extension_service()->process_map(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 799 | |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 800 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 801 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 802 | |
| 803 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 804 | |
| 805 | GURL base_url = GetTestBaseURL("app_process"); |
| 806 | |
| 807 | // Load the app, chrome.app.isInstalled should be true. |
| 808 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 809 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 810 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 811 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 812 | bool is_installed = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 813 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 814 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 815 | "window.domAutomationController.send(chrome.app.isInstalled)", |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 816 | &is_installed)); |
| 817 | ASSERT_TRUE(is_installed); |
| 818 | |
| 819 | // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 820 | content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 821 | content::WindowedNotificationObserver observer( |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 822 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 823 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 824 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 825 | GetController())); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 826 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 827 | observer.Wait(); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 828 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 829 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 830 | "window.domAutomationController.send(chrome.app.isInstalled)", |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 831 | &is_installed)); |
| 832 | ASSERT_TRUE(is_installed); |
| 833 | } |