blob: 58dece721ba4f560c832cc05a793aab40f17f432 [file] [log] [blame]
[email protected]c333e792012-01-06 16:57:391// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]3a8eecb2010-04-22 23:56:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b65d4bdcc2013-07-31 00:37:335#include "base/command_line.h"
[email protected]fdf40f3e2013-07-11 23:55:466#include "chrome/browser/chrome_notification_types.h"
[email protected]3a8eecb2010-04-22 23:56:307#include "chrome/browser/extensions/extension_apitest.h"
[email protected]6f371442011-11-09 06:45:468#include "chrome/browser/extensions/extension_service.h"
[email protected]8ecad5e2010-12-02 21:18:339#include "chrome/browser/profiles/profile.h"
[email protected]e0731d72013-07-25 12:39:4610#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]7b5dc002010-11-16 23:08:1011#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1012#include "chrome/browser/ui/browser_commands.h"
[email protected]d8748142012-05-16 21:13:4313#include "chrome/browser/ui/browser_finder.h"
[email protected]71b73f02011-04-06 15:57:2914#include "chrome/browser/ui/browser_list.h"
[email protected]d55c2382011-08-18 23:10:3615#include "chrome/browser/ui/browser_window.h"
[email protected]e0448872013-01-11 19:35:0216#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]3a8eecb2010-04-22 23:56:3017#include "chrome/common/chrome_switches.h"
[email protected]c2f36e3a2011-12-14 01:27:1918#include "chrome/common/extensions/extension_file_util.h"
[email protected]b65d4bdcc2013-07-31 00:37:3319#include "chrome/test/base/test_switches.h"
[email protected]af44e7fb2011-07-29 18:32:3220#include "chrome/test/base/ui_test_utils.h"
[email protected]ad23a092011-12-28 07:02:0421#include "content/public/browser/navigation_entry.h"
[email protected]ad50def52011-10-19 23:17:0722#include "content/public/browser/notification_service.h"
[email protected]c333e792012-01-06 16:57:3923#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3324#include "content/public/browser/render_view_host.h"
[email protected]2aca9a92013-12-03 05:16:0725#include "content/public/browser/site_instance.h"
[email protected]6acde6352012-01-04 16:52:2026#include "content/public/browser/web_contents.h"
[email protected]7d478cb2012-07-24 17:19:4227#include "content/public/test/browser_test_utils.h"
[email protected]5b8ff1c2012-06-02 20:42:2028#include "content/public/test/test_navigation_observer.h"
[email protected]22401dc2014-03-21 01:38:5729#include "extensions/browser/extension_host.h"
[email protected]59b0e602014-01-30 00:41:2430#include "extensions/browser/extension_system.h"
[email protected]50de9aa22013-11-14 06:30:3431#include "extensions/browser/process_map.h"
[email protected]e4452d32013-11-15 23:07:4132#include "extensions/common/extension.h"
[email protected]558878cc82013-11-09 01:25:5133#include "extensions/common/switches.h"
[email protected]f2cb3cf2013-03-21 01:40:5334#include "net/dns/mock_host_resolver.h"
[email protected]c1dffe82013-06-26 20:59:0535#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]36b643212012-09-07 12:53:0036#include "sync/api/string_ordinal.h"
[email protected]3a8eecb2010-04-22 23:56:3037
[email protected]c5eed492012-01-04 17:07:5038using content::NavigationController;
[email protected]eaabba22012-03-07 15:02:1139using content::RenderViewHost;
[email protected]2aca9a92013-12-03 05:16:0740using content::SiteInstance;
[email protected]4ca15302012-01-03 05:53:2041using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:3442using extensions::Extension;
[email protected]4ca15302012-01-03 05:53:2043
[email protected]7b54ca02012-03-02 18:06:5344class AppApiTest : public ExtensionApiTest {
45 protected:
46 // Gets the base URL for files for a specific test, making sure that it uses
47 // "localhost" as the hostname, since that is what the extent is declared
48 // as in the test apps manifests.
49 GURL GetTestBaseURL(std::string test_directory) {
50 GURL::Replacements replace_host;
51 std::string host_str("localhost"); // must stay in scope with replace_host
52 replace_host.SetHostStr(host_str);
[email protected]c1dffe82013-06-26 20:59:0553 GURL base_url = embedded_test_server()->GetURL(
54 "/extensions/api_test/" + test_directory + "/");
[email protected]7b54ca02012-03-02 18:06:5355 return base_url.ReplaceComponents(replace_host);
56 }
57
58 // Pass flags to make testing apps easier.
[email protected]49aeab62013-02-07 02:53:1159 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]7b54ca02012-03-02 18:06:5360 ExtensionApiTest::SetUpCommandLine(command_line);
61 CommandLine::ForCurrentProcess()->AppendSwitch(
62 switches::kDisablePopupBlocking);
63 CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]558878cc82013-11-09 01:25:5164 extensions::switches::kAllowHTTPBackgroundPage);
[email protected]7b54ca02012-03-02 18:06:5365 }
66
67 // Helper function to test that independent tabs of the named app are loaded
68 // into separate processes.
69 void TestAppInstancesHelper(std::string app_name) {
70 LOG(INFO) << "Start of test.";
71
[email protected]fafdc842014-01-17 18:09:0872 extensions::ProcessMap* process_map =
73 extensions::ProcessMap::Get(browser()->profile());
[email protected]7b54ca02012-03-02 18:06:5374
75 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:0576 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]7b54ca02012-03-02 18:06:5377
78 ASSERT_TRUE(LoadExtension(
79 test_data_dir_.AppendASCII(app_name)));
[email protected]50686c3b2013-04-27 00:26:2780 const Extension* extension = GetSingleLoadedExtension();
[email protected]7b54ca02012-03-02 18:06:5381
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]e0448872013-01-11 19:35:0294 browser()->tab_strip_model()->GetWebContentsAt(1)->
95 GetRenderProcessHost()->GetID()));
96 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
[email protected]7b54ca02012-03-02 18:06:5397
[email protected]a7fe9112012-07-20 02:34:4598 content::WindowedNotificationObserver tab_added_observer(
[email protected]19506d542013-10-15 23:11:0699 chrome::NOTIFICATION_TAB_ADDED,
[email protected]7b54ca02012-03-02 18:06:53100 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:10101 chrome::NewTab(browser());
[email protected]7b54ca02012-03-02 18:06:53102 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]e0448872013-01-11 19:35:02108 browser()->tab_strip_model()->GetWebContentsAt(2)->
109 GetRenderProcessHost()->GetID()));
110 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
[email protected]7b54ca02012-03-02 18:06:53111
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]e0448872013-01-11 19:35:02116 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]19da16a92012-05-23 17:11:29119 EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
[email protected]7b54ca02012-03-02 18:06:53120
121 // Opening tabs with window.open should keep the page in the opener's
122 // process.
[email protected]c987a242013-02-28 01:17:41123 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
124 browser()->host_desktop_type()));
[email protected]19da16a92012-05-23 17:11:29125 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL);
[email protected]7b54ca02012-03-02 18:06:53126 LOG(INFO) << "WindowOpenHelper 1.";
[email protected]19da16a92012-05-23 17:11:29127 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL);
[email protected]7b54ca02012-03-02 18:06:53128 LOG(INFO) << "End of test.";
[email protected]50686c3b2013-04-27 00:26:27129 UnloadExtension(extension->id());
[email protected]7b54ca02012-03-02 18:06:53130 }
131};
132
[email protected]079b3cc2012-09-26 19:59:13133// Omits the disable-popup-blocking flag so we can cover that case.
134class BlockedAppApiTest : public AppApiTest {
135 protected:
[email protected]49aeab62013-02-07 02:53:11136 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]079b3cc2012-09-26 19:59:13137 ExtensionApiTest::SetUpCommandLine(command_line);
138 CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]558878cc82013-11-09 01:25:51139 extensions::switches::kAllowHTTPBackgroundPage);
[email protected]079b3cc2012-09-26 19:59:13140 }
141};
142
[email protected]7b54ca02012-03-02 18:06:53143// 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]c9c206082013-01-29 00:42:56145// http://crbug.com/172750
[email protected]2340a3c2013-06-17 20:54:36146IN_PROC_BROWSER_TEST_F(AppApiTest, DISABLED_AppProcess) {
[email protected]87c7c292011-10-27 16:16:41147 LOG(INFO) << "Start of test.";
[email protected]9b600832011-10-26 20:31:59148
[email protected]fafdc842014-01-17 18:09:08149 extensions::ProcessMap* process_map =
150 extensions::ProcessMap::Get(browser()->profile());
[email protected]718eab62011-10-05 21:16:52151
[email protected]3a8eecb2010-04-22 23:56:30152 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05153 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]3a8eecb2010-04-22 23:56:30154
[email protected]cbf4d1912010-08-12 18:24:57155 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
[email protected]3a8eecb2010-04-22 23:56:30156
[email protected]87c7c292011-10-27 16:16:41157 LOG(INFO) << "Loaded extension.";
158
[email protected]cbf4d1912010-08-12 18:24:57159 // Open two tabs in the app, one outside it.
[email protected]118d3122011-08-10 17:09:53160 GURL base_url = GetTestBaseURL("app_process");
[email protected]fe3048872010-10-18 14:58:59161
[email protected]f0e13332011-05-20 22:41:14162 // 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]6f371442011-11-09 06:45:46168 EXPECT_TRUE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02169 browser()->tab_strip_model()->GetWebContentsAt(1)->
170 GetRenderProcessHost()->GetID()));
171 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
[email protected]87c7c292011-10-27 16:16:41172 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]6f371442011-11-09 06:45:46177 EXPECT_TRUE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02178 browser()->tab_strip_model()->GetWebContentsAt(2)->
179 GetRenderProcessHost()->GetID()));
180 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
[email protected]87c7c292011-10-27 16:16:41181 LOG(INFO) << "Nav 2.";
182
[email protected]a7fe9112012-07-20 02:34:45183 content::WindowedNotificationObserver tab_added_observer(
[email protected]884033e2012-04-16 19:38:42184 chrome::NOTIFICATION_TAB_ADDED,
[email protected]87c7c292011-10-27 16:16:41185 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:10186 chrome::NewTab(browser());
[email protected]87c7c292011-10-27 16:16:41187 tab_added_observer.Wait();
188 LOG(INFO) << "New tab.";
[email protected]cbf4d1912010-08-12 18:24:57189 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
[email protected]87c7c292011-10-27 16:16:41190 LOG(INFO) << "Nav 3.";
[email protected]6f371442011-11-09 06:45:46191 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02192 browser()->tab_strip_model()->GetWebContentsAt(3)->
193 GetRenderProcessHost()->GetID()));
194 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(3)->GetWebUI());
[email protected]3a8eecb2010-04-22 23:56:30195
[email protected]056ad2a2011-07-12 02:13:55196 // 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]e0448872013-01-11 19:35:02200 ASSERT_EQ(4, browser()->tab_strip_model()->count());
201 WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
[email protected]cbf4d1912010-08-12 18:24:57202
[email protected]19da16a92012-05-23 17:11:29203 EXPECT_EQ(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02204 browser()->tab_strip_model()->GetWebContentsAt(2)->
205 GetRenderProcessHost());
[email protected]19da16a92012-05-23 17:11:29206 EXPECT_NE(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02207 browser()->tab_strip_model()->GetWebContentsAt(3)->
208 GetRenderProcessHost());
[email protected]3a8eecb2010-04-22 23:56:30209
210 // Now let's do the same using window.open. The same should happen.
[email protected]c987a242013-02-28 01:17:41211 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
212 browser()->host_desktop_type()));
[email protected]19da16a92012-05-23 17:11:29213 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
[email protected]87c7c292011-10-27 16:16:41214 LOG(INFO) << "WindowOpenHelper 1.";
[email protected]19da16a92012-05-23 17:11:29215 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
[email protected]87c7c292011-10-27 16:16:41216 LOG(INFO) << "WindowOpenHelper 2.";
[email protected]361a5f1f2011-10-05 20:11:15217 // TODO(creis): This should open in a new process (i.e., false for the last
[email protected]ea7b7d82012-05-25 17:29:17218 // 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]361a5f1f2011-10-05 20:11:15221 // See crbug.com/59285.
[email protected]19da16a92012-05-23 17:11:29222 OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL);
[email protected]87c7c292011-10-27 16:16:41223 LOG(INFO) << "WindowOpenHelper 3.";
[email protected]3a8eecb2010-04-22 23:56:30224
225 // Now let's have these pages navigate, into or out of the extension web
226 // extent. They should switch processes.
[email protected]9a1e6d42010-04-26 22:29:36227 const GURL& app_url(base_url.Resolve("path1/empty.html"));
228 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
[email protected]e0448872013-01-11 19:35:02229 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
230 non_app_url);
[email protected]87c7c292011-10-27 16:16:41231 LOG(INFO) << "NavigateTabHelper 1.";
[email protected]e0448872013-01-11 19:35:02232 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(3),
233 app_url);
[email protected]87c7c292011-10-27 16:16:41234 LOG(INFO) << "NavigateTabHelper 2.";
[email protected]ea7b7d82012-05-25 17:29:17235 EXPECT_NE(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02236 browser()->tab_strip_model()->GetWebContentsAt(2)->
237 GetRenderProcessHost());
[email protected]19da16a92012-05-23 17:11:29238 EXPECT_EQ(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02239 browser()->tab_strip_model()->GetWebContentsAt(3)->
240 GetRenderProcessHost());
[email protected]08e94b82010-12-15 22:51:04241
242 // If one of the popup tabs navigates back to the app, window.opener should
243 // be valid.
[email protected]e0448872013-01-11 19:35:02244 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(6),
245 app_url);
[email protected]87c7c292011-10-27 16:16:41246 LOG(INFO) << "NavigateTabHelper 3.";
[email protected]19da16a92012-05-23 17:11:29247 EXPECT_EQ(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02248 browser()->tab_strip_model()->GetWebContentsAt(6)->
249 GetRenderProcessHost());
[email protected]08e94b82010-12-15 22:51:04250 bool windowOpenerValid = false;
[email protected]b6987e02013-01-04 18:30:43251 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]e0448872013-01-11 19:35:02252 browser()->tab_strip_model()->GetWebContentsAt(6),
[email protected]06bc5d92013-01-02 22:44:13253 "window.domAutomationController.send(window.opener != null)",
[email protected]08e94b82010-12-15 22:51:04254 &windowOpenerValid));
255 ASSERT_TRUE(windowOpenerValid);
[email protected]87c7c292011-10-27 16:16:41256
257 LOG(INFO) << "End of test.";
[email protected]3a8eecb2010-04-22 23:56:30258}
[email protected]faf407b2011-01-05 01:24:32259
[email protected]056ad2a2011-07-12 02:13:55260// 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]4ef849e2013-06-10 08:36:59262// 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
268IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) {
[email protected]7b54ca02012-03-02 18:06:53269 TestAppInstancesHelper("app_process_instances");
270}
[email protected]87c7c292011-10-27 16:16:41271
[email protected]7b54ca02012-03-02 18:06:53272// 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]0d70b7d42012-12-13 01:14:20275// Flaky on XP: http://crbug.com/165834
[email protected]0cfb748b2012-12-13 01:10:11276#if defined(OS_WIN)
277#define MAYBE_AppProcessBackgroundInstances \
278 DISABLED_AppProcessBackgroundInstances
279#else
280#define MAYBE_AppProcessBackgroundInstances AppProcessBackgroundInstances
281#endif
282IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessBackgroundInstances) {
[email protected]7b54ca02012-03-02 18:06:53283 TestAppInstancesHelper("app_process_background_instances");
[email protected]056ad2a2011-07-12 02:13:55284}
285
[email protected]15877ca2011-11-18 22:40:52286// 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]19506d542013-10-15 23:11:06288// 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
294IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_BookmarkAppGetsNormalProcess) {
[email protected]06bdd2b2012-11-30 18:47:13295 ExtensionService* service = extensions::ExtensionSystem::Get(
296 browser()->profile())->extension_service();
[email protected]fafdc842014-01-17 18:09:08297 extensions::ProcessMap* process_map =
298 extensions::ProcessMap::Get(browser()->profile());
[email protected]15877ca2011-11-18 22:40:52299
300 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05301 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]15877ca2011-11-18 22:40:52302 GURL base_url = GetTestBaseURL("app_process");
303
[email protected]c2f36e3a2011-12-14 01:27:19304 // Load an app as a bookmark app.
305 std::string error;
306 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
307 test_data_dir_.AppendASCII("app_process"),
[email protected]12075d12013-02-27 05:38:05308 extensions::Manifest::UNPACKED,
[email protected]c2f36e3a2011-12-14 01:27:19309 Extension::FROM_BOOKMARK,
310 &error));
[email protected]dc24976f2013-06-02 21:15:09311 service->OnExtensionInstalled(extension.get(),
[email protected]98270432012-09-11 20:51:24312 syncer::StringOrdinal::CreateInitialOrdinal(),
[email protected]0db124b02012-11-07 04:55:05313 false /* no requirement errors */,
[email protected]8e289f0b2013-12-17 17:49:07314 extensions::NOT_BLACKLISTED,
[email protected]0db124b02012-11-07 04:55:05315 false /* don't wait for idle */);
[email protected]c2f36e3a2011-12-14 01:27:19316 ASSERT_TRUE(extension.get());
317 ASSERT_TRUE(extension->from_bookmark());
318
[email protected]15877ca2011-11-18 22:40:52319 // Test both opening a URL in a new tab, and opening a tab and then navigating
320 // it. Either way, bookmark app tabs should be considered normal processes
321 // with no elevated privileges and no WebUI bindings.
322 ui_test_utils::NavigateToURLWithDisposition(
323 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
324 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
325 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02326 browser()->tab_strip_model()->GetWebContentsAt(1)->
327 GetRenderProcessHost()->GetID()));
328 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
[email protected]15877ca2011-11-18 22:40:52329
[email protected]a7fe9112012-07-20 02:34:45330 content::WindowedNotificationObserver tab_added_observer(
[email protected]884033e2012-04-16 19:38:42331 chrome::NOTIFICATION_TAB_ADDED,
[email protected]15877ca2011-11-18 22:40:52332 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:10333 chrome::NewTab(browser());
[email protected]15877ca2011-11-18 22:40:52334 tab_added_observer.Wait();
335 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
336 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02337 browser()->tab_strip_model()->GetWebContentsAt(2)->
338 GetRenderProcessHost()->GetID()));
339 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
[email protected]15877ca2011-11-18 22:40:52340
341 // We should have opened 2 new bookmark app tabs. Including the original blank
342 // tab, we now have 3 tabs. Because normal pages use the
343 // process-per-site-instance model, each should be in its own process.
[email protected]e0448872013-01-11 19:35:02344 ASSERT_EQ(3, browser()->tab_strip_model()->count());
345 WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
[email protected]19da16a92012-05-23 17:11:29346 EXPECT_NE(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02347 browser()->tab_strip_model()->GetWebContentsAt(2)->
348 GetRenderProcessHost());
[email protected]15877ca2011-11-18 22:40:52349
350 // Now let's do the same using window.open. The same should happen.
[email protected]c987a242013-02-28 01:17:41351 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
352 browser()->host_desktop_type()));
[email protected]19da16a92012-05-23 17:11:29353 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
354 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
[email protected]15877ca2011-11-18 22:40:52355
356 // Now let's have a tab navigate out of and back into the app's web
357 // extent. Neither navigation should switch processes.
358 const GURL& app_url(base_url.Resolve("path1/empty.html"));
359 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
[email protected]52877dbc62012-06-29 22:22:03360 RenderViewHost* host2 =
[email protected]e0448872013-01-11 19:35:02361 browser()->tab_strip_model()->GetWebContentsAt(2)->GetRenderViewHost();
362 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
363 non_app_url);
[email protected]9f76c1e2012-03-05 15:15:58364 EXPECT_EQ(host2->GetProcess(),
[email protected]e0448872013-01-11 19:35:02365 browser()->tab_strip_model()->GetWebContentsAt(2)->
366 GetRenderProcessHost());
367 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
368 app_url);
[email protected]9f76c1e2012-03-05 15:15:58369 EXPECT_EQ(host2->GetProcess(),
[email protected]e0448872013-01-11 19:35:02370 browser()->tab_strip_model()->GetWebContentsAt(2)->
371 GetRenderProcessHost());
[email protected]15877ca2011-11-18 22:40:52372}
373
[email protected]faf407b2011-01-05 01:24:32374// Tests that app process switching works properly in the following scenario:
375// 1. navigate to a page1 in the app
376// 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
377// 3. page2 redirects back to a page in the app
378// The final navigation should end up in the app process.
379// See http://crbug.com/61757
[email protected]31f68b62014-02-07 18:36:02380// Flaky on Linux. http://crbug.com/341898
381#if defined(OS_LINUX)
382#define MAYBE_AppProcessRedirectBack DISABLED_AppProcessRedirectBack
383#else
384#define MAYBE_AppProcessRedirectBack AppProcessRedirectBack
385#endif
386IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessRedirectBack) {
[email protected]faf407b2011-01-05 01:24:32387 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05388 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]faf407b2011-01-05 01:24:32389
390 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
391
392 // Open two tabs in the app.
[email protected]118d3122011-08-10 17:09:53393 GURL base_url = GetTestBaseURL("app_process");
[email protected]faf407b2011-01-05 01:24:32394
[email protected]a37d4b02012-06-25 21:56:10395 chrome::NewTab(browser());
[email protected]faf407b2011-01-05 01:24:32396 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]a37d4b02012-06-25 21:56:10397 chrome::NewTab(browser());
[email protected]ea7b7d82012-05-25 17:29:17398 // Wait until the second tab finishes its redirect train (2 hops).
[email protected]4ad5d77d2011-12-03 02:00:48399 // 1. We navigate to redirect.html
400 // 2. Renderer navigates and finishes, counting as a load stop.
401 // 3. Renderer issues the meta refresh to navigate to server-redirect.
402 // 4. Renderer is now in a "provisional load", waiting for navigation to
403 // complete.
404 // 5. Browser sees a redirect response from server-redirect to empty.html, and
405 // transfers that to a new navigation, using RequestTransferURL.
[email protected]ea7b7d82012-05-25 17:29:17406 // 6. Renderer navigates to empty.html, and finishes loading, counting as the
407 // second load stop
[email protected]4ad5d77d2011-12-03 02:00:48408 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
[email protected]ea7b7d82012-05-25 17:29:17409 browser(), base_url.Resolve("path1/redirect.html"), 2);
[email protected]faf407b2011-01-05 01:24:32410
411 // 3 tabs, including the initial about:blank. The last 2 should be the same
412 // process.
[email protected]e0448872013-01-11 19:35:02413 ASSERT_EQ(3, browser()->tab_strip_model()->count());
[email protected]c1dffe82013-06-26 20:59:05414 EXPECT_EQ("/extensions/api_test/app_process/path1/empty.html",
[email protected]e0448872013-01-11 19:35:02415 browser()->tab_strip_model()->GetWebContentsAt(2)->
416 GetController().GetLastCommittedEntry()->GetURL().path());
417 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1)->
418 GetRenderProcessHost(),
419 browser()->tab_strip_model()->GetWebContentsAt(2)->
420 GetRenderProcessHost());
[email protected]faf407b2011-01-05 01:24:32421}
[email protected]d292d8a2011-05-25 03:47:11422
[email protected]aaef4752013-03-02 10:10:51423// Ensure that re-navigating to a URL after installing or uninstalling it as an
424// app correctly swaps the tab to the app process. (http://crbug.com/80621)
[email protected]4c9d02082013-05-15 15:38:36425//
[email protected]bc857a62013-05-08 16:44:53426// Fails on Windows. http://crbug.com/238670
[email protected]4c9d02082013-05-15 15:38:36427// Added logging to help diagnose the location of the problem.
[email protected]11170a772013-12-13 11:38:32428IN_PROC_BROWSER_TEST_F(AppApiTest, NavigateIntoAppProcess) {
[email protected]fafdc842014-01-17 18:09:08429 extensions::ProcessMap* process_map =
430 extensions::ProcessMap::Get(browser()->profile());
[email protected]718eab62011-10-05 21:16:52431
[email protected]d292d8a2011-05-25 03:47:11432 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05433 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]d292d8a2011-05-25 03:47:11434
435 // The app under test acts on URLs whose host is "localhost",
436 // so the URLs we navigate to must have host "localhost".
[email protected]118d3122011-08-10 17:09:53437 GURL base_url = GetTestBaseURL("app_process");
[email protected]d292d8a2011-05-25 03:47:11438
439 // Load an app URL before loading the app.
[email protected]4c9d02082013-05-15 15:38:36440 LOG(INFO) << "Loading path1/empty.html.";
[email protected]d292d8a2011-05-25 03:47:11441 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]4c9d02082013-05-15 15:38:36442 LOG(INFO) << "Loading path1/empty.html - done.";
[email protected]e0448872013-01-11 19:35:02443 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]6f371442011-11-09 06:45:46444 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52445 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11446
[email protected]aaef4752013-03-02 10:10:51447 // Load app and re-navigate to the page.
[email protected]4c9d02082013-05-15 15:38:36448 LOG(INFO) << "Loading extension.";
[email protected]d292d8a2011-05-25 03:47:11449 const Extension* app =
450 LoadExtension(test_data_dir_.AppendASCII("app_process"));
[email protected]4c9d02082013-05-15 15:38:36451 LOG(INFO) << "Loading extension - done.";
[email protected]d292d8a2011-05-25 03:47:11452 ASSERT_TRUE(app);
[email protected]4c9d02082013-05-15 15:38:36453 LOG(INFO) << "Loading path1/empty.html.";
[email protected]d292d8a2011-05-25 03:47:11454 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]4c9d02082013-05-15 15:38:36455 LOG(INFO) << "Loading path1/empty.html - done.";
[email protected]6f371442011-11-09 06:45:46456 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52457 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11458
[email protected]aaef4752013-03-02 10:10:51459 // Disable app and re-navigate to the page.
[email protected]4c9d02082013-05-15 15:38:36460 LOG(INFO) << "Disabling extension.";
[email protected]d292d8a2011-05-25 03:47:11461 DisableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36462 LOG(INFO) << "Disabling extension - done.";
463 LOG(INFO) << "Loading path1/empty.html.";
[email protected]d292d8a2011-05-25 03:47:11464 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]4c9d02082013-05-15 15:38:36465 LOG(INFO) << "Loading path1/empty.html - done.";
[email protected]6f371442011-11-09 06:45:46466 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52467 contents->GetRenderProcessHost()->GetID()));
[email protected]aaef4752013-03-02 10:10:51468}
469
470// Ensure that reloading a URL after installing or uninstalling it as an app
471// correctly swaps the tab to the app process. (http://crbug.com/80621)
[email protected]4c9d02082013-05-15 15:38:36472//
473// Added logging to help diagnose the location of the problem.
474// http://crbug.com/238670
[email protected]aaef4752013-03-02 10:10:51475IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
[email protected]fafdc842014-01-17 18:09:08476 extensions::ProcessMap* process_map =
477 extensions::ProcessMap::Get(browser()->profile());
[email protected]aaef4752013-03-02 10:10:51478
479 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05480 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]aaef4752013-03-02 10:10:51481
482 // The app under test acts on URLs whose host is "localhost",
483 // so the URLs we navigate to must have host "localhost".
484 GURL base_url = GetTestBaseURL("app_process");
485
486 // Load app, disable it, and navigate to the page.
[email protected]4c9d02082013-05-15 15:38:36487 LOG(INFO) << "Loading extension.";
[email protected]aaef4752013-03-02 10:10:51488 const Extension* app =
489 LoadExtension(test_data_dir_.AppendASCII("app_process"));
[email protected]4c9d02082013-05-15 15:38:36490 LOG(INFO) << "Loading extension - done.";
[email protected]aaef4752013-03-02 10:10:51491 ASSERT_TRUE(app);
[email protected]4c9d02082013-05-15 15:38:36492 LOG(INFO) << "Disabling extension.";
[email protected]aaef4752013-03-02 10:10:51493 DisableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36494 LOG(INFO) << "Disabling extension - done.";
495 LOG(INFO) << "Navigate to path1/empty.html.";
[email protected]aaef4752013-03-02 10:10:51496 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]4c9d02082013-05-15 15:38:36497 LOG(INFO) << "Navigate to path1/empty.html - done.";
[email protected]aaef4752013-03-02 10:10:51498 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
499 EXPECT_FALSE(process_map->Contains(
500 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11501
[email protected]8d3132f62011-10-12 07:13:42502 // Enable app and reload the page.
[email protected]4c9d02082013-05-15 15:38:36503 LOG(INFO) << "Enabling extension.";
[email protected]8d3132f62011-10-12 07:13:42504 EnableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36505 LOG(INFO) << "Enabling extension - done.";
[email protected]a7fe9112012-07-20 02:34:45506 content::WindowedNotificationObserver reload_observer(
[email protected]8d3132f62011-10-12 07:13:42507 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50508 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02509 &browser()->tab_strip_model()->GetActiveWebContents()->
510 GetController()));
[email protected]4c9d02082013-05-15 15:38:36511 LOG(INFO) << "Reloading.";
[email protected]a37d4b02012-06-25 21:56:10512 chrome::Reload(browser(), CURRENT_TAB);
[email protected]8d3132f62011-10-12 07:13:42513 reload_observer.Wait();
[email protected]4c9d02082013-05-15 15:38:36514 LOG(INFO) << "Reloading - done.";
[email protected]6f371442011-11-09 06:45:46515 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52516 contents->GetRenderProcessHost()->GetID()));
[email protected]8d3132f62011-10-12 07:13:42517
518 // Disable app and reload the page.
[email protected]4c9d02082013-05-15 15:38:36519 LOG(INFO) << "Disabling extension.";
[email protected]8d3132f62011-10-12 07:13:42520 DisableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36521 LOG(INFO) << "Disabling extension - done.";
[email protected]a7fe9112012-07-20 02:34:45522 content::WindowedNotificationObserver reload_observer2(
[email protected]8d3132f62011-10-12 07:13:42523 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50524 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02525 &browser()->tab_strip_model()->GetActiveWebContents()->
526 GetController()));
[email protected]4c9d02082013-05-15 15:38:36527 LOG(INFO) << "Reloading.";
[email protected]a37d4b02012-06-25 21:56:10528 chrome::Reload(browser(), CURRENT_TAB);
[email protected]8d3132f62011-10-12 07:13:42529 reload_observer2.Wait();
[email protected]4c9d02082013-05-15 15:38:36530 LOG(INFO) << "Reloading - done.";
[email protected]6f371442011-11-09 06:45:46531 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52532 contents->GetRenderProcessHost()->GetID()));
[email protected]aaef4752013-03-02 10:10:51533}
534
535// Ensure that reloading a URL with JavaScript after installing or uninstalling
536// it as an app correctly swaps the process. (http://crbug.com/80621)
[email protected]4c9d02082013-05-15 15:38:36537//
538// Crashes on Windows and Mac. http://crbug.com/238670
539// Added logging to help diagnose the location of the problem.
540IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcessWithJavaScript) {
[email protected]fafdc842014-01-17 18:09:08541 extensions::ProcessMap* process_map =
542 extensions::ProcessMap::Get(browser()->profile());
[email protected]aaef4752013-03-02 10:10:51543
544 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05545 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]aaef4752013-03-02 10:10:51546
547 // The app under test acts on URLs whose host is "localhost",
548 // so the URLs we navigate to must have host "localhost".
549 GURL base_url = GetTestBaseURL("app_process");
550
551 // Load app, disable it, and navigate to the page.
[email protected]4c9d02082013-05-15 15:38:36552 LOG(INFO) << "Loading extension.";
[email protected]aaef4752013-03-02 10:10:51553 const Extension* app =
554 LoadExtension(test_data_dir_.AppendASCII("app_process"));
[email protected]4c9d02082013-05-15 15:38:36555 LOG(INFO) << "Loading extension - done.";
[email protected]aaef4752013-03-02 10:10:51556 ASSERT_TRUE(app);
[email protected]4c9d02082013-05-15 15:38:36557 LOG(INFO) << "Disabling extension.";
[email protected]aaef4752013-03-02 10:10:51558 DisableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36559 LOG(INFO) << "Disabling extension - done.";
560 LOG(INFO) << "Navigate to path1/empty.html.";
[email protected]aaef4752013-03-02 10:10:51561 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]4c9d02082013-05-15 15:38:36562 LOG(INFO) << "Navigate to path1/empty.html - done.";
[email protected]aaef4752013-03-02 10:10:51563 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
564 EXPECT_FALSE(process_map->Contains(
565 contents->GetRenderProcessHost()->GetID()));
[email protected]8d3132f62011-10-12 07:13:42566
[email protected]d292d8a2011-05-25 03:47:11567 // Enable app and reload via JavaScript.
[email protected]4c9d02082013-05-15 15:38:36568 LOG(INFO) << "Enabling extension.";
[email protected]d292d8a2011-05-25 03:47:11569 EnableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36570 LOG(INFO) << "Enabling extension - done.";
[email protected]a7fe9112012-07-20 02:34:45571 content::WindowedNotificationObserver js_reload_observer(
[email protected]8d3132f62011-10-12 07:13:42572 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50573 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02574 &browser()->tab_strip_model()->GetActiveWebContents()->
575 GetController()));
[email protected]4c9d02082013-05-15 15:38:36576 LOG(INFO) << "Executing location.reload().";
[email protected]b6987e02013-01-04 18:30:43577 ASSERT_TRUE(content::ExecuteScript(contents, "location.reload();"));
[email protected]8d3132f62011-10-12 07:13:42578 js_reload_observer.Wait();
[email protected]4c9d02082013-05-15 15:38:36579 LOG(INFO) << "Executing location.reload() - done.";
[email protected]6f371442011-11-09 06:45:46580 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52581 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11582
583 // Disable app and reload via JavaScript.
[email protected]4c9d02082013-05-15 15:38:36584 LOG(INFO) << "Disabling extension.";
[email protected]d292d8a2011-05-25 03:47:11585 DisableExtension(app->id());
[email protected]4c9d02082013-05-15 15:38:36586 LOG(INFO) << "Disabling extension - done.";
[email protected]a7fe9112012-07-20 02:34:45587 content::WindowedNotificationObserver js_reload_observer2(
[email protected]8d3132f62011-10-12 07:13:42588 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50589 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02590 &browser()->tab_strip_model()->GetActiveWebContents()->
591 GetController()));
[email protected]4c9d02082013-05-15 15:38:36592 LOG(INFO) << "Executing location = location.";
[email protected]b6987e02013-01-04 18:30:43593 ASSERT_TRUE(content::ExecuteScript(contents, "location = location;"));
[email protected]8d3132f62011-10-12 07:13:42594 js_reload_observer2.Wait();
[email protected]4c9d02082013-05-15 15:38:36595 LOG(INFO) << "Executing location = location - done.";
[email protected]6f371442011-11-09 06:45:46596 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52597 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11598}
[email protected]118d3122011-08-10 17:09:53599
[email protected]118d3122011-08-10 17:09:53600// Tests that if we have a non-app process (path3/container.html) that has an
601// iframe with a URL in the app's extent (path1/iframe.html), then opening a
602// link from that iframe to a new window to a URL in the app's extent (path1/
603// empty.html) results in the new window being in an app process. See
604// http://crbug.com/89272 for more details.
[email protected]1f4495b2012-10-12 05:51:05605IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
[email protected]988e6582013-07-22 19:32:47606#if defined(OS_WIN) && defined(USE_ASH)
607 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
[email protected]b65d4bdcc2013-07-31 00:37:33608 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
[email protected]988e6582013-07-22 19:32:47609 return;
610#endif
611
[email protected]fafdc842014-01-17 18:09:08612 extensions::ProcessMap* process_map =
613 extensions::ProcessMap::Get(browser()->profile());
[email protected]718eab62011-10-05 21:16:52614
[email protected]118d3122011-08-10 17:09:53615 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05616 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]118d3122011-08-10 17:09:53617
618 GURL base_url = GetTestBaseURL("app_process");
619
620 // Load app and start URL (not in the app).
621 const Extension* app =
622 LoadExtension(test_data_dir_.AppendASCII("app_process"));
623 ASSERT_TRUE(app);
[email protected]19da16a92012-05-23 17:11:29624
[email protected]19da16a92012-05-23 17:11:29625 ui_test_utils::NavigateToURL(browser(),
626 base_url.Resolve("path3/container.html"));
[email protected]6f371442011-11-09 06:45:46627 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02628 browser()->tab_strip_model()->GetWebContentsAt(0)->
629 GetRenderProcessHost()->GetID()));
[email protected]118d3122011-08-10 17:09:53630
[email protected]415dc61612013-10-29 04:35:27631 const BrowserList* active_browser_list =
632 BrowserList::GetInstance(chrome::GetActiveDesktop());
633 EXPECT_EQ(2U, active_browser_list->size());
634 content::WebContents* popup_contents =
635 active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents();
636 content::WaitForLoadStop(popup_contents);
637
[email protected]118d3122011-08-10 17:09:53638 // Popup window should be in the app's process.
[email protected]415dc61612013-10-29 04:35:27639 RenderViewHost* popup_host = popup_contents->GetRenderViewHost();
[email protected]19da16a92012-05-23 17:11:29640 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID()));
[email protected]118d3122011-08-10 17:09:53641}
[email protected]a09add52011-08-12 03:59:23642
[email protected]079b3cc2012-09-26 19:59:13643// Similar to the previous test, but ensure that popup blocking bypass
644// isn't granted to the iframe. See crbug.com/117446.
[email protected]1f4495b2012-10-12 05:51:05645#if defined(OS_CHROMEOS)
646// http://crbug.com/153513
647#define MAYBE_OpenAppFromIframe DISABLED_OpenAppFromIframe
648#else
649#define MAYBE_OpenAppFromIframe OpenAppFromIframe
650#endif
651IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, MAYBE_OpenAppFromIframe) {
[email protected]079b3cc2012-09-26 19:59:13652 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05653 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]079b3cc2012-09-26 19:59:13654
655 // Load app and start URL (not in the app).
656 const Extension* app =
657 LoadExtension(test_data_dir_.AppendASCII("app_process"));
658 ASSERT_TRUE(app);
659
[email protected]079b3cc2012-09-26 19:59:13660 ui_test_utils::NavigateToURL(
661 browser(), GetTestBaseURL("app_process").Resolve("path3/container.html"));
662
[email protected]e0448872013-01-11 19:35:02663 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]e0731d72013-07-25 12:39:46664 PopupBlockerTabHelper* popup_blocker_tab_helper =
665 PopupBlockerTabHelper::FromWebContents(tab);
[email protected]992e2912013-08-19 15:05:24666 if (!popup_blocker_tab_helper->GetBlockedPopupsCount()) {
[email protected]e0731d72013-07-25 12:39:46667 content::WindowedNotificationObserver observer(
668 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
669 content::NotificationService::AllSources());
670 observer.Wait();
671 }
672
[email protected]992e2912013-08-19 15:05:24673 EXPECT_EQ(1u, popup_blocker_tab_helper->GetBlockedPopupsCount());
[email protected]079b3cc2012-09-26 19:59:13674}
675
[email protected]88aae972011-12-16 01:14:18676// Tests that if an extension launches an app via chrome.tabs.create with an URL
[email protected]b0a29f22013-05-30 23:00:09677// that's not in the app's extent but that server redirects to it, we still end
678// up with an app process. See http://crbug.com/99349 for more details.
679IN_PROC_BROWSER_TEST_F(AppApiTest, ServerRedirectToAppFromExtension) {
[email protected]88aae972011-12-16 01:14:18680 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05681 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]88aae972011-12-16 01:14:18682
683 LoadExtension(test_data_dir_.AppendASCII("app_process"));
684 const Extension* launcher =
685 LoadExtension(test_data_dir_.AppendASCII("app_launcher"));
686
[email protected]6169a5772013-05-29 17:41:14687 // There should be two navigations by the time the app page is loaded.
[email protected]88aae972011-12-16 01:14:18688 // 1. The extension launcher page.
[email protected]6169a5772013-05-29 17:41:14689 // 2. The app's URL (which includes a server redirect).
690 // Note that the server redirect does not generate a navigation event.
[email protected]5b8ff1c2012-06-02 20:42:20691 content::TestNavigationObserver test_navigation_observer(
[email protected]cbb1ef592013-06-05 19:49:46692 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]6169a5772013-05-29 17:41:14693 2);
[email protected]cbb1ef592013-06-05 19:49:46694 test_navigation_observer.StartWatchingNewWebContents();
[email protected]88aae972011-12-16 01:14:18695
696 // Load the launcher extension, which should launch the app.
697 ui_test_utils::NavigateToURLWithDisposition(
698 browser(),
[email protected]b0a29f22013-05-30 23:00:09699 launcher->GetResourceURL("server_redirect.html"),
700 CURRENT_TAB,
701 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
702
703 // Wait for app tab to be created and loaded.
[email protected]91621872013-10-08 04:04:59704 test_navigation_observer.Wait();
[email protected]b0a29f22013-05-30 23:00:09705
706 // App has loaded, and chrome.app.isInstalled should be true.
707 bool is_installed = false;
708 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
709 browser()->tab_strip_model()->GetActiveWebContents(),
710 "window.domAutomationController.send(chrome.app.isInstalled)",
711 &is_installed));
712 ASSERT_TRUE(is_installed);
713}
714
715// Tests that if an extension launches an app via chrome.tabs.create with an URL
716// that's not in the app's extent but that client redirects to it, we still end
717// up with an app process.
718IN_PROC_BROWSER_TEST_F(AppApiTest, ClientRedirectToAppFromExtension) {
719 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05720 ASSERT_TRUE(StartEmbeddedTestServer());
[email protected]b0a29f22013-05-30 23:00:09721
722 LoadExtension(test_data_dir_.AppendASCII("app_process"));
723 const Extension* launcher =
724 LoadExtension(test_data_dir_.AppendASCII("app_launcher"));
725
726 // There should be three navigations by the time the app page is loaded.
727 // 1. The extension launcher page.
728 // 2. The URL that the extension launches, which client redirects.
729 // 3. The app's URL.
730 content::TestNavigationObserver test_navigation_observer(
[email protected]cbb1ef592013-06-05 19:49:46731 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]b0a29f22013-05-30 23:00:09732 3);
[email protected]cbb1ef592013-06-05 19:49:46733 test_navigation_observer.StartWatchingNewWebContents();
[email protected]b0a29f22013-05-30 23:00:09734
735 // Load the launcher extension, which should launch the app.
736 ui_test_utils::NavigateToURLWithDisposition(
737 browser(),
738 launcher->GetResourceURL("client_redirect.html"),
[email protected]88aae972011-12-16 01:14:18739 CURRENT_TAB,
740 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
741
742 // Wait for app tab to be created and loaded.
[email protected]91621872013-10-08 04:04:59743 test_navigation_observer.Wait();
[email protected]88aae972011-12-16 01:14:18744
745 // App has loaded, and chrome.app.isInstalled should be true.
746 bool is_installed = false;
[email protected]b6987e02013-01-04 18:30:43747 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]e0448872013-01-11 19:35:02748 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13749 "window.domAutomationController.send(chrome.app.isInstalled)",
[email protected]88aae972011-12-16 01:14:18750 &is_installed));
751 ASSERT_TRUE(is_installed);
752}
753
[email protected]d55c2382011-08-18 23:10:36754// Tests that if we have an app process (path1/container.html) with a non-app
755// iframe (path3/iframe.html), then opening a link from that iframe to a new
756// window to a same-origin non-app URL (path3/empty.html) should keep the window
757// in the app process.
758// This is in contrast to OpenAppFromIframe, since here the popup will not be
759// missing special permissions and should be scriptable from the iframe.
760// See http://crbug.com/92669 for more details.
[email protected]19da16a92012-05-23 17:11:29761IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) {
[email protected]fafdc842014-01-17 18:09:08762 extensions::ProcessMap* process_map =
763 extensions::ProcessMap::Get(browser()->profile());
[email protected]718eab62011-10-05 21:16:52764
[email protected]d55c2382011-08-18 23:10:36765 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05766 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]d55c2382011-08-18 23:10:36767
768 GURL base_url = GetTestBaseURL("app_process");
769
770 // Load app and start URL (in the app).
771 const Extension* app =
772 LoadExtension(test_data_dir_.AppendASCII("app_process"));
773 ASSERT_TRUE(app);
[email protected]19da16a92012-05-23 17:11:29774
[email protected]19da16a92012-05-23 17:11:29775 ui_test_utils::NavigateToURL(browser(),
776 base_url.Resolve("path1/container.html"));
[email protected]f3b1a082011-11-18 00:34:30777 content::RenderProcessHost* process =
[email protected]e0448872013-01-11 19:35:02778 browser()->tab_strip_model()->GetWebContentsAt(0)->GetRenderProcessHost();
[email protected]f3b1a082011-11-18 00:34:30779 EXPECT_TRUE(process_map->Contains(process->GetID()));
[email protected]d55c2382011-08-18 23:10:36780
[email protected]d55c2382011-08-18 23:10:36781 // Popup window should be in the app's process.
[email protected]415dc61612013-10-29 04:35:27782 const BrowserList* active_browser_list =
783 BrowserList::GetInstance(chrome::GetActiveDesktop());
784 EXPECT_EQ(2U, active_browser_list->size());
785 content::WebContents* popup_contents =
786 active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents();
787 content::WaitForLoadStop(popup_contents);
788
789 RenderViewHost* popup_host = popup_contents->GetRenderViewHost();
[email protected]19da16a92012-05-23 17:11:29790 EXPECT_EQ(process, popup_host->GetProcess());
[email protected]d55c2382011-08-18 23:10:36791}
792
[email protected]a344b762012-03-16 18:53:49793// http://crbug.com/118502
794#if defined(OS_MACOSX) || defined(OS_LINUX)
795#define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash
796#else
797#define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash
798#endif
799IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) {
[email protected]fafdc842014-01-17 18:09:08800 extensions::ProcessMap* process_map =
801 extensions::ProcessMap::Get(browser()->profile());
[email protected]6f371442011-11-09 06:45:46802
[email protected]a09add52011-08-12 03:59:23803 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]c1dffe82013-06-26 20:59:05804 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
[email protected]a09add52011-08-12 03:59:23805
806 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
807
808 GURL base_url = GetTestBaseURL("app_process");
809
810 // Load the app, chrome.app.isInstalled should be true.
811 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]e0448872013-01-11 19:35:02812 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]6f371442011-11-09 06:45:46813 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52814 contents->GetRenderProcessHost()->GetID()));
[email protected]a09add52011-08-12 03:59:23815 bool is_installed = false;
[email protected]b6987e02013-01-04 18:30:43816 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
817 contents,
[email protected]06bc5d92013-01-02 22:44:13818 "window.domAutomationController.send(chrome.app.isInstalled)",
[email protected]a09add52011-08-12 03:59:23819 &is_installed));
820 ASSERT_TRUE(is_installed);
821
822 // Crash the tab and reload it, chrome.app.isInstalled should still be true.
[email protected]e0448872013-01-11 19:35:02823 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents());
[email protected]a7fe9112012-07-20 02:34:45824 content::WindowedNotificationObserver observer(
[email protected]ae673742011-08-24 19:48:37825 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50826 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02827 &browser()->tab_strip_model()->GetActiveWebContents()->
828 GetController()));
[email protected]a37d4b02012-06-25 21:56:10829 chrome::Reload(browser(), CURRENT_TAB);
[email protected]ae673742011-08-24 19:48:37830 observer.Wait();
[email protected]b6987e02013-01-04 18:30:43831 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
832 contents,
[email protected]06bc5d92013-01-02 22:44:13833 "window.domAutomationController.send(chrome.app.isInstalled)",
[email protected]a09add52011-08-12 03:59:23834 &is_installed));
835 ASSERT_TRUE(is_installed);
836}
[email protected]2aca9a92013-12-03 05:16:07837
838// Test that a cross-process navigation away from a hosted app stays in the same
839// BrowsingInstance, so that postMessage calls to the app's other windows still
840// work.
841IN_PROC_BROWSER_TEST_F(AppApiTest, SameBrowsingInstanceAfterSwap) {
[email protected]fafdc842014-01-17 18:09:08842 extensions::ProcessMap* process_map =
843 extensions::ProcessMap::Get(browser()->profile());
[email protected]2aca9a92013-12-03 05:16:07844
845 host_resolver()->AddRule("*", "127.0.0.1");
846 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
847
848 GURL base_url = GetTestBaseURL("app_process");
849
850 // Load app and start URL (in the app).
851 const Extension* app =
852 LoadExtension(test_data_dir_.AppendASCII("app_process"));
853 ASSERT_TRUE(app);
854
855 ui_test_utils::NavigateToURL(browser(),
856 base_url.Resolve("path1/iframe.html"));
857 content::SiteInstance* app_instance =
858 browser()->tab_strip_model()->GetWebContentsAt(0)->GetSiteInstance();
859 EXPECT_TRUE(process_map->Contains(app_instance->GetProcess()->GetID()));
860
861 // Popup window should be in the app's process.
862 const BrowserList* active_browser_list =
863 BrowserList::GetInstance(chrome::GetActiveDesktop());
864 EXPECT_EQ(2U, active_browser_list->size());
865 content::WebContents* popup_contents =
866 active_browser_list->get(1)->tab_strip_model()->GetActiveWebContents();
867 content::WaitForLoadStop(popup_contents);
868
869 SiteInstance* popup_instance = popup_contents->GetSiteInstance();
870 EXPECT_EQ(app_instance, popup_instance);
871
872 // Navigate the popup to another process outside the app.
873 GURL non_app_url(base_url.Resolve("path3/empty.html"));
874 ui_test_utils::NavigateToURL(active_browser_list->get(1), non_app_url);
875 SiteInstance* new_instance = popup_contents->GetSiteInstance();
876 EXPECT_NE(app_instance, new_instance);
877
878 // It should still be in the same BrowsingInstance, allowing postMessage to
879 // work.
880 EXPECT_TRUE(app_instance->IsRelatedSiteInstance(new_instance));
881}