[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] | b65d4bdcc | 2013-07-31 00:37:33 | [diff] [blame] | 18 | #include "chrome/test/base/test_switches.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 19 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 20 | #include "content/public/browser/navigation_entry.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 21 | #include "content/public/browser/notification_service.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 22 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 23 | #include "content/public/browser/render_view_host.h" |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 24 | #include "content/public/browser/site_instance.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 25 | #include "content/public/browser/web_contents.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 26 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 5b8ff1c | 2012-06-02 20:42:20 | [diff] [blame] | 27 | #include "content/public/test/test_navigation_observer.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 28 | #include "extensions/browser/extension_host.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 29 | #include "extensions/browser/extension_system.h" |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 30 | #include "extensions/browser/install_flag.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] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 33 | #include "extensions/common/file_util.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 34 | #include "extensions/common/switches.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 35 | #include "net/dns/mock_host_resolver.h" |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 36 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 37 | #include "sync/api/string_ordinal.h" |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 38 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 39 | using content::NavigationController; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 40 | using content::RenderViewHost; |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 41 | using content::SiteInstance; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 42 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 43 | using extensions::Extension; |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 44 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 45 | class AppApiTest : public ExtensionApiTest { |
| 46 | protected: |
| 47 | // Gets the base URL for files for a specific test, making sure that it uses |
| 48 | // "localhost" as the hostname, since that is what the extent is declared |
| 49 | // as in the test apps manifests. |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 50 | GURL GetTestBaseURL(const std::string& test_directory) { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 51 | GURL::Replacements replace_host; |
mgiuca | 77752c3 | 2015-02-05 07:31:18 | [diff] [blame^] | 52 | replace_host.SetHostStr("localhost"); |
[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. |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 59 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 60 | ExtensionApiTest::SetUpCommandLine(command_line); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 61 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 62 | switches::kDisablePopupBlocking); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 63 | base::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. |
[email protected] | 0bb29bd | 2014-04-30 21:39:18 | [diff] [blame] | 69 | void TestAppInstancesHelper(const std::string& app_name) { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 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: |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 136 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 137 | ExtensionApiTest::SetUpCommandLine(command_line); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 138 | base::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; |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 306 | scoped_refptr<const Extension> extension(extensions::file_util::LoadExtension( |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 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] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 313 | extensions::kInstallFlagInstallImmediately); |
[email protected] | c2f36e3a | 2011-12-14 01:27:19 | [diff] [blame] | 314 | ASSERT_TRUE(extension.get()); |
| 315 | ASSERT_TRUE(extension->from_bookmark()); |
| 316 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 317 | // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 318 | // it. Either way, bookmark app tabs should be considered normal processes |
| 319 | // with no elevated privileges and no WebUI bindings. |
| 320 | ui_test_utils::NavigateToURLWithDisposition( |
| 321 | browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 322 | ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 323 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 324 | browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 325 | GetRenderProcessHost()->GetID())); |
| 326 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 327 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 328 | content::WindowedNotificationObserver tab_added_observer( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 329 | chrome::NOTIFICATION_TAB_ADDED, |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 330 | content::NotificationService::AllSources()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 331 | chrome::NewTab(browser()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 332 | tab_added_observer.Wait(); |
| 333 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 334 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 335 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 336 | GetRenderProcessHost()->GetID())); |
| 337 | EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 338 | |
| 339 | // We should have opened 2 new bookmark app tabs. Including the original blank |
| 340 | // tab, we now have 3 tabs. Because normal pages use the |
| 341 | // process-per-site-instance model, each should be in its own process. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 342 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
| 343 | WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 344 | EXPECT_NE(tab->GetRenderProcessHost(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 345 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 346 | GetRenderProcessHost()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 347 | |
| 348 | // Now let's do the same using window.open. The same should happen. |
[email protected] | c987a24 | 2013-02-28 01:17:41 | [diff] [blame] | 349 | ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 350 | browser()->host_desktop_type())); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 351 | OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); |
| 352 | OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 353 | |
| 354 | // Now let's have a tab navigate out of and back into the app's web |
| 355 | // extent. Neither navigation should switch processes. |
| 356 | const GURL& app_url(base_url.Resolve("path1/empty.html")); |
| 357 | const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 358 | RenderViewHost* host2 = |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 359 | browser()->tab_strip_model()->GetWebContentsAt(2)->GetRenderViewHost(); |
| 360 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2), |
| 361 | non_app_url); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 362 | EXPECT_EQ(host2->GetProcess(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 363 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 364 | GetRenderProcessHost()); |
| 365 | NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2), |
| 366 | app_url); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 367 | EXPECT_EQ(host2->GetProcess(), |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 368 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 369 | GetRenderProcessHost()); |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 370 | } |
| 371 | |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 372 | // Tests that app process switching works properly in the following scenario: |
| 373 | // 1. navigate to a page1 in the app |
| 374 | // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") |
| 375 | // 3. page2 redirects back to a page in the app |
| 376 | // The final navigation should end up in the app process. |
| 377 | // See http://crbug.com/61757 |
John Abd-El-Malek | 3f7aec31 | 2014-08-27 03:18:10 | [diff] [blame] | 378 | // Flaky. http://crbug.com/341898 |
| 379 | IN_PROC_BROWSER_TEST_F(AppApiTest, DISABLED_AppProcessRedirectBack) { |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 380 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 381 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 382 | |
| 383 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 384 | |
| 385 | // Open two tabs in the app. |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 386 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 387 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 388 | chrome::NewTab(browser()); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 389 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 390 | chrome::NewTab(browser()); |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 391 | // Wait until the second tab finishes its redirect train (2 hops). |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 392 | // 1. We navigate to redirect.html |
| 393 | // 2. Renderer navigates and finishes, counting as a load stop. |
| 394 | // 3. Renderer issues the meta refresh to navigate to server-redirect. |
| 395 | // 4. Renderer is now in a "provisional load", waiting for navigation to |
| 396 | // complete. |
| 397 | // 5. Browser sees a redirect response from server-redirect to empty.html, and |
| 398 | // transfers that to a new navigation, using RequestTransferURL. |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 399 | // 6. Renderer navigates to empty.html, and finishes loading, counting as the |
| 400 | // second load stop |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 401 | ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
[email protected] | ea7b7d8 | 2012-05-25 17:29:17 | [diff] [blame] | 402 | browser(), base_url.Resolve("path1/redirect.html"), 2); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 403 | |
| 404 | // 3 tabs, including the initial about:blank. The last 2 should be the same |
| 405 | // process. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 406 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 407 | EXPECT_EQ("/extensions/api_test/app_process/path1/empty.html", |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 408 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 409 | GetController().GetLastCommittedEntry()->GetURL().path()); |
| 410 | EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 411 | GetRenderProcessHost(), |
| 412 | browser()->tab_strip_model()->GetWebContentsAt(2)-> |
| 413 | GetRenderProcessHost()); |
[email protected] | faf407b | 2011-01-05 01:24:32 | [diff] [blame] | 414 | } |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 415 | |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 416 | // Ensure that re-navigating to a URL after installing or uninstalling it as an |
| 417 | // app correctly swaps the tab to the app process. (http://crbug.com/80621) |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 418 | // |
[email protected] | bc857a6 | 2013-05-08 16:44:53 | [diff] [blame] | 419 | // Fails on Windows. http://crbug.com/238670 |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 420 | // Added logging to help diagnose the location of the problem. |
[email protected] | 11170a77 | 2013-12-13 11:38:32 | [diff] [blame] | 421 | IN_PROC_BROWSER_TEST_F(AppApiTest, NavigateIntoAppProcess) { |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 422 | extensions::ProcessMap* process_map = |
| 423 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 424 | |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 425 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 426 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 427 | |
| 428 | // The app under test acts on URLs whose host is "localhost", |
| 429 | // so the URLs we navigate to must have host "localhost". |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 430 | GURL base_url = GetTestBaseURL("app_process"); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 431 | |
| 432 | // Load an app URL before loading the app. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 433 | LOG(INFO) << "Loading path1/empty.html."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 434 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 435 | LOG(INFO) << "Loading path1/empty.html - done."; |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 436 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 437 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 438 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 439 | |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 440 | // Load app and re-navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 441 | LOG(INFO) << "Loading extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 442 | const Extension* app = |
| 443 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 444 | LOG(INFO) << "Loading extension - done."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 445 | ASSERT_TRUE(app); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 446 | LOG(INFO) << "Loading path1/empty.html."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 447 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 448 | LOG(INFO) << "Loading path1/empty.html - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 449 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 450 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 451 | |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 452 | // Disable app and re-navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 453 | LOG(INFO) << "Disabling extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 454 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 455 | LOG(INFO) << "Disabling extension - done."; |
| 456 | LOG(INFO) << "Loading path1/empty.html."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 457 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 458 | LOG(INFO) << "Loading path1/empty.html - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 459 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 460 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | // Ensure that reloading a URL after installing or uninstalling it as an app |
| 464 | // correctly swaps the tab to the app process. (http://crbug.com/80621) |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 465 | // |
| 466 | // Added logging to help diagnose the location of the problem. |
| 467 | // http://crbug.com/238670 |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 468 | IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) { |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 469 | extensions::ProcessMap* process_map = |
| 470 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 471 | |
| 472 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 473 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 474 | |
| 475 | // The app under test acts on URLs whose host is "localhost", |
| 476 | // so the URLs we navigate to must have host "localhost". |
| 477 | GURL base_url = GetTestBaseURL("app_process"); |
| 478 | |
| 479 | // Load app, disable it, and navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 480 | LOG(INFO) << "Loading extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 481 | const Extension* app = |
| 482 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 483 | LOG(INFO) << "Loading extension - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 484 | ASSERT_TRUE(app); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 485 | LOG(INFO) << "Disabling extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 486 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 487 | LOG(INFO) << "Disabling extension - done."; |
| 488 | LOG(INFO) << "Navigate to path1/empty.html."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 489 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 490 | LOG(INFO) << "Navigate to path1/empty.html - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 491 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 492 | EXPECT_FALSE(process_map->Contains( |
| 493 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 494 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 495 | // Enable app and reload the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 496 | LOG(INFO) << "Enabling extension."; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 497 | EnableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 498 | LOG(INFO) << "Enabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 499 | content::WindowedNotificationObserver reload_observer( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 500 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 501 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 502 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 503 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 504 | LOG(INFO) << "Reloading."; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 505 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 506 | reload_observer.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 507 | LOG(INFO) << "Reloading - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 508 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 509 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 510 | |
| 511 | // Disable app and reload the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 512 | LOG(INFO) << "Disabling extension."; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 513 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 514 | LOG(INFO) << "Disabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 515 | content::WindowedNotificationObserver reload_observer2( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 516 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 517 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 518 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 519 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 520 | LOG(INFO) << "Reloading."; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 521 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 522 | reload_observer2.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 523 | LOG(INFO) << "Reloading - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 524 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 525 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | // Ensure that reloading a URL with JavaScript after installing or uninstalling |
| 529 | // it as an app correctly swaps the process. (http://crbug.com/80621) |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 530 | // |
| 531 | // Crashes on Windows and Mac. http://crbug.com/238670 |
| 532 | // Added logging to help diagnose the location of the problem. |
| 533 | IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcessWithJavaScript) { |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 534 | extensions::ProcessMap* process_map = |
| 535 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 536 | |
| 537 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 538 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 539 | |
| 540 | // The app under test acts on URLs whose host is "localhost", |
| 541 | // so the URLs we navigate to must have host "localhost". |
| 542 | GURL base_url = GetTestBaseURL("app_process"); |
| 543 | |
| 544 | // Load app, disable it, and navigate to the page. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 545 | LOG(INFO) << "Loading extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 546 | const Extension* app = |
| 547 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 548 | LOG(INFO) << "Loading extension - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 549 | ASSERT_TRUE(app); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 550 | LOG(INFO) << "Disabling extension."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 551 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 552 | LOG(INFO) << "Disabling extension - done."; |
| 553 | LOG(INFO) << "Navigate to path1/empty.html."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 554 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 555 | LOG(INFO) << "Navigate to path1/empty.html - done."; |
[email protected] | aaef475 | 2013-03-02 10:10:51 | [diff] [blame] | 556 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 557 | EXPECT_FALSE(process_map->Contains( |
| 558 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 559 | |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 560 | // Enable app and reload via JavaScript. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 561 | LOG(INFO) << "Enabling extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 562 | EnableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 563 | LOG(INFO) << "Enabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 564 | content::WindowedNotificationObserver js_reload_observer( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 565 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 566 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 567 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 568 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 569 | LOG(INFO) << "Executing location.reload()."; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 570 | ASSERT_TRUE(content::ExecuteScript(contents, "location.reload();")); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 571 | js_reload_observer.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 572 | LOG(INFO) << "Executing location.reload() - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 573 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 574 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 575 | |
| 576 | // Disable app and reload via JavaScript. |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 577 | LOG(INFO) << "Disabling extension."; |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 578 | DisableExtension(app->id()); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 579 | LOG(INFO) << "Disabling extension - done."; |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 580 | content::WindowedNotificationObserver js_reload_observer2( |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 581 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 582 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 583 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 584 | GetController())); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 585 | LOG(INFO) << "Executing location = location."; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 586 | ASSERT_TRUE(content::ExecuteScript(contents, "location = location;")); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 587 | js_reload_observer2.Wait(); |
[email protected] | 4c9d0208 | 2013-05-15 15:38:36 | [diff] [blame] | 588 | LOG(INFO) << "Executing location = location - done."; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 589 | EXPECT_FALSE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 590 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 591 | } |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 592 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 593 | // Tests that if we have a non-app process (path3/container.html) that has an |
| 594 | // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
| 595 | // link from that iframe to a new window to a URL in the app's extent (path1/ |
| 596 | // empty.html) results in the new window being in an app process. See |
| 597 | // http://crbug.com/89272 for more details. |
[email protected] | 1f4495b | 2012-10-12 05:51:05 | [diff] [blame] | 598 | IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 599 | #if defined(OS_WIN) && defined(USE_ASH) |
| 600 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 601 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 602 | switches::kAshBrowserTests)) |
[email protected] | 988e658 | 2013-07-22 19:32:47 | [diff] [blame] | 603 | return; |
| 604 | #endif |
| 605 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 606 | extensions::ProcessMap* process_map = |
| 607 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 608 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 609 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 610 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 611 | |
| 612 | GURL base_url = GetTestBaseURL("app_process"); |
| 613 | |
| 614 | // Load app and start URL (not in the app). |
| 615 | const Extension* app = |
| 616 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 617 | ASSERT_TRUE(app); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 618 | |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 619 | ui_test_utils::NavigateToURL(browser(), |
| 620 | base_url.Resolve("path3/container.html")); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 621 | EXPECT_FALSE(process_map->Contains( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 622 | browser()->tab_strip_model()->GetWebContentsAt(0)-> |
| 623 | GetRenderProcessHost()->GetID())); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 624 | |
[email protected] | 415dc6161 | 2013-10-29 04:35:27 | [diff] [blame] | 625 | const BrowserList* active_browser_list = |
| 626 | BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 627 | EXPECT_EQ(2U, active_browser_list->size()); |
| 628 | content::WebContents* popup_contents = |
| 629 | active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents(); |
| 630 | content::WaitForLoadStop(popup_contents); |
| 631 | |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 632 | // Popup window should be in the app's process. |
[email protected] | 415dc6161 | 2013-10-29 04:35:27 | [diff] [blame] | 633 | RenderViewHost* popup_host = popup_contents->GetRenderViewHost(); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 634 | EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); |
[email protected] | 118d312 | 2011-08-10 17:09:53 | [diff] [blame] | 635 | } |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 636 | |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 637 | // Similar to the previous test, but ensure that popup blocking bypass |
| 638 | // isn't granted to the iframe. See crbug.com/117446. |
[email protected] | 1f4495b | 2012-10-12 05:51:05 | [diff] [blame] | 639 | #if defined(OS_CHROMEOS) |
| 640 | // http://crbug.com/153513 |
| 641 | #define MAYBE_OpenAppFromIframe DISABLED_OpenAppFromIframe |
| 642 | #else |
| 643 | #define MAYBE_OpenAppFromIframe OpenAppFromIframe |
| 644 | #endif |
| 645 | IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, MAYBE_OpenAppFromIframe) { |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 646 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 647 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 648 | |
| 649 | // Load app and start URL (not in the app). |
| 650 | const Extension* app = |
| 651 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 652 | ASSERT_TRUE(app); |
| 653 | |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 654 | ui_test_utils::NavigateToURL( |
| 655 | browser(), GetTestBaseURL("app_process").Resolve("path3/container.html")); |
| 656 | |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 657 | WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
[email protected] | e0731d7 | 2013-07-25 12:39:46 | [diff] [blame] | 658 | PopupBlockerTabHelper* popup_blocker_tab_helper = |
| 659 | PopupBlockerTabHelper::FromWebContents(tab); |
[email protected] | 992e291 | 2013-08-19 15:05:24 | [diff] [blame] | 660 | if (!popup_blocker_tab_helper->GetBlockedPopupsCount()) { |
[email protected] | e0731d7 | 2013-07-25 12:39:46 | [diff] [blame] | 661 | content::WindowedNotificationObserver observer( |
| 662 | chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 663 | content::NotificationService::AllSources()); |
| 664 | observer.Wait(); |
| 665 | } |
| 666 | |
[email protected] | 992e291 | 2013-08-19 15:05:24 | [diff] [blame] | 667 | EXPECT_EQ(1u, popup_blocker_tab_helper->GetBlockedPopupsCount()); |
[email protected] | 079b3cc | 2012-09-26 19:59:13 | [diff] [blame] | 668 | } |
| 669 | |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 670 | // 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] | 671 | // that's not in the app's extent but that server redirects to it, we still end |
| 672 | // up with an app process. See http://crbug.com/99349 for more details. |
| 673 | IN_PROC_BROWSER_TEST_F(AppApiTest, ServerRedirectToAppFromExtension) { |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 674 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 675 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 676 | |
| 677 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 678 | const Extension* launcher = |
| 679 | LoadExtension(test_data_dir_.AppendASCII("app_launcher")); |
| 680 | |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 681 | // There should be two navigations by the time the app page is loaded. |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 682 | // 1. The extension launcher page. |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 683 | // 2. The app's URL (which includes a server redirect). |
| 684 | // Note that the server redirect does not generate a navigation event. |
[email protected] | 5b8ff1c | 2012-06-02 20:42:20 | [diff] [blame] | 685 | content::TestNavigationObserver test_navigation_observer( |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 686 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 6169a577 | 2013-05-29 17:41:14 | [diff] [blame] | 687 | 2); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 688 | test_navigation_observer.StartWatchingNewWebContents(); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 689 | |
| 690 | // Load the launcher extension, which should launch the app. |
thestig | 53986dc | 2014-12-16 06:09:18 | [diff] [blame] | 691 | ui_test_utils::NavigateToURL( |
| 692 | browser(), launcher->GetResourceURL("server_redirect.html")); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 693 | |
| 694 | // Wait for app tab to be created and loaded. |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame] | 695 | test_navigation_observer.Wait(); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 696 | |
| 697 | // App has loaded, and chrome.app.isInstalled should be true. |
| 698 | bool is_installed = false; |
| 699 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 700 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 701 | "window.domAutomationController.send(chrome.app.isInstalled)", |
| 702 | &is_installed)); |
| 703 | ASSERT_TRUE(is_installed); |
| 704 | } |
| 705 | |
| 706 | // Tests that if an extension launches an app via chrome.tabs.create with an URL |
| 707 | // that's not in the app's extent but that client redirects to it, we still end |
| 708 | // up with an app process. |
| 709 | IN_PROC_BROWSER_TEST_F(AppApiTest, ClientRedirectToAppFromExtension) { |
| 710 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 711 | ASSERT_TRUE(StartEmbeddedTestServer()); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 712 | |
| 713 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 714 | const Extension* launcher = |
| 715 | LoadExtension(test_data_dir_.AppendASCII("app_launcher")); |
| 716 | |
| 717 | // There should be three navigations by the time the app page is loaded. |
| 718 | // 1. The extension launcher page. |
| 719 | // 2. The URL that the extension launches, which client redirects. |
| 720 | // 3. The app's URL. |
| 721 | content::TestNavigationObserver test_navigation_observer( |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 722 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 723 | 3); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 724 | test_navigation_observer.StartWatchingNewWebContents(); |
[email protected] | b0a29f2 | 2013-05-30 23:00:09 | [diff] [blame] | 725 | |
| 726 | // Load the launcher extension, which should launch the app. |
thestig | 53986dc | 2014-12-16 06:09:18 | [diff] [blame] | 727 | ui_test_utils::NavigateToURL( |
| 728 | browser(), launcher->GetResourceURL("client_redirect.html")); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 729 | |
| 730 | // Wait for app tab to be created and loaded. |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame] | 731 | test_navigation_observer.Wait(); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 732 | |
| 733 | // App has loaded, and chrome.app.isInstalled should be true. |
| 734 | bool is_installed = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 735 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 736 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 737 | "window.domAutomationController.send(chrome.app.isInstalled)", |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 738 | &is_installed)); |
| 739 | ASSERT_TRUE(is_installed); |
| 740 | } |
| 741 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 742 | // Tests that if we have an app process (path1/container.html) with a non-app |
| 743 | // iframe (path3/iframe.html), then opening a link from that iframe to a new |
| 744 | // window to a same-origin non-app URL (path3/empty.html) should keep the window |
| 745 | // in the app process. |
| 746 | // This is in contrast to OpenAppFromIframe, since here the popup will not be |
| 747 | // missing special permissions and should be scriptable from the iframe. |
| 748 | // See http://crbug.com/92669 for more details. |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 749 | IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 750 | extensions::ProcessMap* process_map = |
| 751 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 752 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 753 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 754 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 755 | |
| 756 | GURL base_url = GetTestBaseURL("app_process"); |
| 757 | |
| 758 | // Load app and start URL (in the app). |
| 759 | const Extension* app = |
| 760 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 761 | ASSERT_TRUE(app); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 762 | |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 763 | ui_test_utils::NavigateToURL(browser(), |
| 764 | base_url.Resolve("path1/container.html")); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 765 | content::RenderProcessHost* process = |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 766 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetRenderProcessHost(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 767 | EXPECT_TRUE(process_map->Contains(process->GetID())); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 768 | |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 769 | // Popup window should be in the app's process. |
[email protected] | 415dc6161 | 2013-10-29 04:35:27 | [diff] [blame] | 770 | const BrowserList* active_browser_list = |
| 771 | BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 772 | EXPECT_EQ(2U, active_browser_list->size()); |
| 773 | content::WebContents* popup_contents = |
| 774 | active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents(); |
| 775 | content::WaitForLoadStop(popup_contents); |
| 776 | |
| 777 | RenderViewHost* popup_host = popup_contents->GetRenderViewHost(); |
[email protected] | 19da16a9 | 2012-05-23 17:11:29 | [diff] [blame] | 778 | EXPECT_EQ(process, popup_host->GetProcess()); |
[email protected] | d55c238 | 2011-08-18 23:10:36 | [diff] [blame] | 779 | } |
| 780 | |
[email protected] | a344b76 | 2012-03-16 18:53:49 | [diff] [blame] | 781 | // http://crbug.com/118502 |
| 782 | #if defined(OS_MACOSX) || defined(OS_LINUX) |
| 783 | #define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash |
| 784 | #else |
| 785 | #define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash |
| 786 | #endif |
| 787 | IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) { |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 788 | extensions::ProcessMap* process_map = |
| 789 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 790 | |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 791 | host_resolver()->AddRule("*", "127.0.0.1"); |
[email protected] | c1dffe8 | 2013-06-26 20:59:05 | [diff] [blame] | 792 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 793 | |
| 794 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 795 | |
| 796 | GURL base_url = GetTestBaseURL("app_process"); |
| 797 | |
| 798 | // Load the app, chrome.app.isInstalled should be true. |
| 799 | ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 800 | WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 801 | EXPECT_TRUE(process_map->Contains( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 802 | contents->GetRenderProcessHost()->GetID())); |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 803 | bool is_installed = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 804 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 805 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 806 | "window.domAutomationController.send(chrome.app.isInstalled)", |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 807 | &is_installed)); |
| 808 | ASSERT_TRUE(is_installed); |
| 809 | |
| 810 | // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 811 | content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 812 | content::WindowedNotificationObserver observer( |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 813 | content::NOTIFICATION_LOAD_STOP, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 814 | content::Source<NavigationController>( |
[email protected] | e044887 | 2013-01-11 19:35:02 | [diff] [blame] | 815 | &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 816 | GetController())); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 817 | chrome::Reload(browser(), CURRENT_TAB); |
[email protected] | ae67374 | 2011-08-24 19:48:37 | [diff] [blame] | 818 | observer.Wait(); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 819 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 820 | contents, |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 821 | "window.domAutomationController.send(chrome.app.isInstalled)", |
[email protected] | a09add5 | 2011-08-12 03:59:23 | [diff] [blame] | 822 | &is_installed)); |
| 823 | ASSERT_TRUE(is_installed); |
| 824 | } |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 825 | |
| 826 | // Test that a cross-process navigation away from a hosted app stays in the same |
| 827 | // BrowsingInstance, so that postMessage calls to the app's other windows still |
| 828 | // work. |
| 829 | IN_PROC_BROWSER_TEST_F(AppApiTest, SameBrowsingInstanceAfterSwap) { |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 830 | extensions::ProcessMap* process_map = |
| 831 | extensions::ProcessMap::Get(browser()->profile()); |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 832 | |
| 833 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 834 | ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 835 | |
| 836 | GURL base_url = GetTestBaseURL("app_process"); |
| 837 | |
| 838 | // Load app and start URL (in the app). |
| 839 | const Extension* app = |
| 840 | LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 841 | ASSERT_TRUE(app); |
| 842 | |
| 843 | ui_test_utils::NavigateToURL(browser(), |
| 844 | base_url.Resolve("path1/iframe.html")); |
| 845 | content::SiteInstance* app_instance = |
| 846 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetSiteInstance(); |
| 847 | EXPECT_TRUE(process_map->Contains(app_instance->GetProcess()->GetID())); |
| 848 | |
| 849 | // Popup window should be in the app's process. |
| 850 | const BrowserList* active_browser_list = |
| 851 | BrowserList::GetInstance(chrome::GetActiveDesktop()); |
| 852 | EXPECT_EQ(2U, active_browser_list->size()); |
| 853 | content::WebContents* popup_contents = |
| 854 | active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents(); |
| 855 | content::WaitForLoadStop(popup_contents); |
| 856 | |
| 857 | SiteInstance* popup_instance = popup_contents->GetSiteInstance(); |
| 858 | EXPECT_EQ(app_instance, popup_instance); |
| 859 | |
| 860 | // Navigate the popup to another process outside the app. |
| 861 | GURL non_app_url(base_url.Resolve("path3/empty.html")); |
| 862 | ui_test_utils::NavigateToURL(active_browser_list->get(1), non_app_url); |
| 863 | SiteInstance* new_instance = popup_contents->GetSiteInstance(); |
| 864 | EXPECT_NE(app_instance, new_instance); |
| 865 | |
| 866 | // It should still be in the same BrowsingInstance, allowing postMessage to |
| 867 | // work. |
| 868 | EXPECT_TRUE(app_instance->IsRelatedSiteInstance(new_instance)); |
| 869 | } |