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