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