blob: 70034c129b04dcdb625429503a3902dba806ccc0 [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]3a8eecb2010-04-22 23:56:305#include "chrome/browser/extensions/extension_apitest.h"
6#include "chrome/browser/extensions/extension_host.h"
[email protected]6f371442011-11-09 06:45:467#include "chrome/browser/extensions/extension_service.h"
[email protected]06bdd2b2012-11-30 18:47:138#include "chrome/browser/extensions/extension_system.h"
[email protected]6f371442011-11-09 06:45:469#include "chrome/browser/extensions/process_map.h"
[email protected]8ecad5e2010-12-02 21:18:3310#include "chrome/browser/profiles/profile.h"
[email protected]079b3cc2012-09-26 19:59:1311#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
[email protected]7b5dc002010-11-16 23:08:1012#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1013#include "chrome/browser/ui/browser_commands.h"
[email protected]d8748142012-05-16 21:13:4314#include "chrome/browser/ui/browser_finder.h"
[email protected]71b73f02011-04-06 15:57:2915#include "chrome/browser/ui/browser_list.h"
[email protected]d55c2382011-08-18 23:10:3616#include "chrome/browser/ui/browser_window.h"
[email protected]e0448872013-01-11 19:35:0217#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]884033e2012-04-16 19:38:4218#include "chrome/common/chrome_notification_types.h"
[email protected]3a8eecb2010-04-22 23:56:3019#include "chrome/common/chrome_switches.h"
[email protected]814a7bf0f2011-08-13 05:30:5920#include "chrome/common/extensions/extension.h"
[email protected]c2f36e3a2011-12-14 01:27:1921#include "chrome/common/extensions/extension_file_util.h"
[email protected]af44e7fb2011-07-29 18:32:3222#include "chrome/test/base/ui_test_utils.h"
[email protected]ad23a092011-12-28 07:02:0423#include "content/public/browser/navigation_entry.h"
[email protected]ad50def52011-10-19 23:17:0724#include "content/public/browser/notification_service.h"
[email protected]c333e792012-01-06 16:57:3925#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3326#include "content/public/browser/render_view_host.h"
[email protected]6acde6352012-01-04 16:52:2027#include "content/public/browser/web_contents.h"
[email protected]7d478cb2012-07-24 17:19:4228#include "content/public/test/browser_test_utils.h"
[email protected]5b8ff1c2012-06-02 20:42:2029#include "content/public/test/test_navigation_observer.h"
[email protected]3a8eecb2010-04-22 23:56:3030#include "net/base/mock_host_resolver.h"
[email protected]36b643212012-09-07 12:53:0031#include "sync/api/string_ordinal.h"
[email protected]3a8eecb2010-04-22 23:56:3032
[email protected]c5eed492012-01-04 17:07:5033using content::NavigationController;
[email protected]eaabba22012-03-07 15:02:1134using content::RenderViewHost;
[email protected]4ca15302012-01-03 05:53:2035using content::WebContents;
[email protected]1c321ee52012-05-21 03:02:3436using extensions::Extension;
[email protected]4ca15302012-01-03 05:53:2037
[email protected]7b54ca02012-03-02 18:06:5338class AppApiTest : public ExtensionApiTest {
39 protected:
40 // Gets the base URL for files for a specific test, making sure that it uses
41 // "localhost" as the hostname, since that is what the extent is declared
42 // as in the test apps manifests.
43 GURL GetTestBaseURL(std::string test_directory) {
44 GURL::Replacements replace_host;
45 std::string host_str("localhost"); // must stay in scope with replace_host
46 replace_host.SetHostStr(host_str);
47 GURL base_url = test_server()->GetURL(
48 "files/extensions/api_test/" + test_directory + "/");
49 return base_url.ReplaceComponents(replace_host);
50 }
51
52 // Pass flags to make testing apps easier.
[email protected]49aeab62013-02-07 02:53:1153 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]7b54ca02012-03-02 18:06:5354 ExtensionApiTest::SetUpCommandLine(command_line);
55 CommandLine::ForCurrentProcess()->AppendSwitch(
56 switches::kDisablePopupBlocking);
57 CommandLine::ForCurrentProcess()->AppendSwitch(
58 switches::kAllowHTTPBackgroundPage);
59 }
60
61 // Helper function to test that independent tabs of the named app are loaded
62 // into separate processes.
63 void TestAppInstancesHelper(std::string app_name) {
64 LOG(INFO) << "Start of test.";
65
[email protected]06bdd2b2012-11-30 18:47:1366 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
67 browser()->profile())->extension_service()->process_map();
[email protected]7b54ca02012-03-02 18:06:5368
69 host_resolver()->AddRule("*", "127.0.0.1");
70 ASSERT_TRUE(test_server()->Start());
71
72 ASSERT_TRUE(LoadExtension(
73 test_data_dir_.AppendASCII(app_name)));
74
75 // Open two tabs in the app, one outside it.
76 GURL base_url = GetTestBaseURL(app_name);
77
78 // Test both opening a URL in a new tab, and opening a tab and then
79 // navigating it. Either way, app tabs should be considered extension
80 // processes, but they have no elevated privileges and thus should not
81 // have WebUI bindings.
82 ui_test_utils::NavigateToURLWithDisposition(
83 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
84 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
85 LOG(INFO) << "Nav 1.";
86 EXPECT_TRUE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:0287 browser()->tab_strip_model()->GetWebContentsAt(1)->
88 GetRenderProcessHost()->GetID()));
89 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
[email protected]7b54ca02012-03-02 18:06:5390
[email protected]a7fe9112012-07-20 02:34:4591 content::WindowedNotificationObserver tab_added_observer(
[email protected]884033e2012-04-16 19:38:4292 chrome::NOTIFICATION_TAB_ADDED,
[email protected]7b54ca02012-03-02 18:06:5393 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:1094 chrome::NewTab(browser());
[email protected]7b54ca02012-03-02 18:06:5395 tab_added_observer.Wait();
96 LOG(INFO) << "New tab.";
97 ui_test_utils::NavigateToURL(browser(),
98 base_url.Resolve("path2/empty.html"));
99 LOG(INFO) << "Nav 2.";
100 EXPECT_TRUE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02101 browser()->tab_strip_model()->GetWebContentsAt(2)->
102 GetRenderProcessHost()->GetID()));
103 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
[email protected]7b54ca02012-03-02 18:06:53104
105 // We should have opened 2 new extension tabs. Including the original blank
106 // tab, we now have 3 tabs. The two app tabs should not be in the same
107 // process, since they do not have the background permission. (Thus, we
108 // want to separate them to improve responsiveness.)
[email protected]e0448872013-01-11 19:35:02109 ASSERT_EQ(3, browser()->tab_strip_model()->count());
110 WebContents* tab1 = browser()->tab_strip_model()->GetWebContentsAt(1);
111 WebContents* tab2 = browser()->tab_strip_model()->GetWebContentsAt(2);
[email protected]19da16a92012-05-23 17:11:29112 EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
[email protected]7b54ca02012-03-02 18:06:53113
114 // Opening tabs with window.open should keep the page in the opener's
115 // process.
[email protected]c987a242013-02-28 01:17:41116 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
117 browser()->host_desktop_type()));
[email protected]19da16a92012-05-23 17:11:29118 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL);
[email protected]7b54ca02012-03-02 18:06:53119 LOG(INFO) << "WindowOpenHelper 1.";
[email protected]19da16a92012-05-23 17:11:29120 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL);
[email protected]7b54ca02012-03-02 18:06:53121 LOG(INFO) << "End of test.";
122 }
123};
124
[email protected]079b3cc2012-09-26 19:59:13125// Omits the disable-popup-blocking flag so we can cover that case.
126class BlockedAppApiTest : public AppApiTest {
127 protected:
[email protected]49aeab62013-02-07 02:53:11128 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]079b3cc2012-09-26 19:59:13129 ExtensionApiTest::SetUpCommandLine(command_line);
130 CommandLine::ForCurrentProcess()->AppendSwitch(
131 switches::kAllowHTTPBackgroundPage);
132 }
133};
134
[email protected]7b54ca02012-03-02 18:06:53135// Tests that hosted apps with the background permission get a process-per-app
136// model, since all pages need to be able to script the background page.
[email protected]c9c206082013-01-29 00:42:56137// http://crbug.com/172750
138#if defined(OS_WIN)
139#define MAYBE_AppProcess DISABLED_AppProcess
140#else
141#define MAYBE_AppProcess AppProcess
142#endif
143IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
[email protected]87c7c292011-10-27 16:16:41144 LOG(INFO) << "Start of test.";
[email protected]9b600832011-10-26 20:31:59145
[email protected]06bdd2b2012-11-30 18:47:13146 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
147 browser()->profile())->extension_service()->process_map();
[email protected]718eab62011-10-05 21:16:52148
[email protected]3a8eecb2010-04-22 23:56:30149 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]95409e12010-08-17 20:07:11150 ASSERT_TRUE(test_server()->Start());
[email protected]3a8eecb2010-04-22 23:56:30151
[email protected]cbf4d1912010-08-12 18:24:57152 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
[email protected]3a8eecb2010-04-22 23:56:30153
[email protected]87c7c292011-10-27 16:16:41154 LOG(INFO) << "Loaded extension.";
155
[email protected]cbf4d1912010-08-12 18:24:57156 // Open two tabs in the app, one outside it.
[email protected]118d3122011-08-10 17:09:53157 GURL base_url = GetTestBaseURL("app_process");
[email protected]fe3048872010-10-18 14:58:59158
[email protected]f0e13332011-05-20 22:41:14159 // Test both opening a URL in a new tab, and opening a tab and then navigating
160 // it. Either way, app tabs should be considered extension processes, but
161 // they have no elevated privileges and thus should not have WebUI bindings.
162 ui_test_utils::NavigateToURLWithDisposition(
163 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
164 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
[email protected]6f371442011-11-09 06:45:46165 EXPECT_TRUE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02166 browser()->tab_strip_model()->GetWebContentsAt(1)->
167 GetRenderProcessHost()->GetID()));
168 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
[email protected]87c7c292011-10-27 16:16:41169 LOG(INFO) << "Nav 1.";
170
171 ui_test_utils::NavigateToURLWithDisposition(
172 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB,
173 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
[email protected]6f371442011-11-09 06:45:46174 EXPECT_TRUE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02175 browser()->tab_strip_model()->GetWebContentsAt(2)->
176 GetRenderProcessHost()->GetID()));
177 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
[email protected]87c7c292011-10-27 16:16:41178 LOG(INFO) << "Nav 2.";
179
[email protected]a7fe9112012-07-20 02:34:45180 content::WindowedNotificationObserver tab_added_observer(
[email protected]884033e2012-04-16 19:38:42181 chrome::NOTIFICATION_TAB_ADDED,
[email protected]87c7c292011-10-27 16:16:41182 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:10183 chrome::NewTab(browser());
[email protected]87c7c292011-10-27 16:16:41184 tab_added_observer.Wait();
185 LOG(INFO) << "New tab.";
[email protected]cbf4d1912010-08-12 18:24:57186 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
[email protected]87c7c292011-10-27 16:16:41187 LOG(INFO) << "Nav 3.";
[email protected]6f371442011-11-09 06:45:46188 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02189 browser()->tab_strip_model()->GetWebContentsAt(3)->
190 GetRenderProcessHost()->GetID()));
191 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(3)->GetWebUI());
[email protected]3a8eecb2010-04-22 23:56:30192
[email protected]056ad2a2011-07-12 02:13:55193 // We should have opened 3 new extension tabs. Including the original blank
194 // tab, we now have 4 tabs. Because the app_process app has the background
195 // permission, all of its instances are in the same process. Thus two tabs
196 // should be part of the extension app and grouped in the same process.
[email protected]e0448872013-01-11 19:35:02197 ASSERT_EQ(4, browser()->tab_strip_model()->count());
198 WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
[email protected]cbf4d1912010-08-12 18:24:57199
[email protected]19da16a92012-05-23 17:11:29200 EXPECT_EQ(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02201 browser()->tab_strip_model()->GetWebContentsAt(2)->
202 GetRenderProcessHost());
[email protected]19da16a92012-05-23 17:11:29203 EXPECT_NE(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02204 browser()->tab_strip_model()->GetWebContentsAt(3)->
205 GetRenderProcessHost());
[email protected]3a8eecb2010-04-22 23:56:30206
207 // Now let's do the same using window.open. The same should happen.
[email protected]c987a242013-02-28 01:17:41208 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
209 browser()->host_desktop_type()));
[email protected]19da16a92012-05-23 17:11:29210 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
[email protected]87c7c292011-10-27 16:16:41211 LOG(INFO) << "WindowOpenHelper 1.";
[email protected]19da16a92012-05-23 17:11:29212 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
[email protected]87c7c292011-10-27 16:16:41213 LOG(INFO) << "WindowOpenHelper 2.";
[email protected]361a5f1f2011-10-05 20:11:15214 // TODO(creis): This should open in a new process (i.e., false for the last
[email protected]ea7b7d82012-05-25 17:29:17215 // argument), but we temporarily avoid swapping processes away from a hosted
216 // app if it has an opener, because some OAuth providers make script calls
217 // between non-app popups and non-app iframes in the app process.
[email protected]361a5f1f2011-10-05 20:11:15218 // See crbug.com/59285.
[email protected]19da16a92012-05-23 17:11:29219 OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL);
[email protected]87c7c292011-10-27 16:16:41220 LOG(INFO) << "WindowOpenHelper 3.";
[email protected]3a8eecb2010-04-22 23:56:30221
222 // Now let's have these pages navigate, into or out of the extension web
223 // extent. They should switch processes.
[email protected]9a1e6d42010-04-26 22:29:36224 const GURL& app_url(base_url.Resolve("path1/empty.html"));
225 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
[email protected]e0448872013-01-11 19:35:02226 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
227 non_app_url);
[email protected]87c7c292011-10-27 16:16:41228 LOG(INFO) << "NavigateTabHelper 1.";
[email protected]e0448872013-01-11 19:35:02229 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(3),
230 app_url);
[email protected]87c7c292011-10-27 16:16:41231 LOG(INFO) << "NavigateTabHelper 2.";
[email protected]ea7b7d82012-05-25 17:29:17232 EXPECT_NE(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02233 browser()->tab_strip_model()->GetWebContentsAt(2)->
234 GetRenderProcessHost());
[email protected]19da16a92012-05-23 17:11:29235 EXPECT_EQ(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02236 browser()->tab_strip_model()->GetWebContentsAt(3)->
237 GetRenderProcessHost());
[email protected]08e94b82010-12-15 22:51:04238
239 // If one of the popup tabs navigates back to the app, window.opener should
240 // be valid.
[email protected]e0448872013-01-11 19:35:02241 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(6),
242 app_url);
[email protected]87c7c292011-10-27 16:16:41243 LOG(INFO) << "NavigateTabHelper 3.";
[email protected]19da16a92012-05-23 17:11:29244 EXPECT_EQ(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02245 browser()->tab_strip_model()->GetWebContentsAt(6)->
246 GetRenderProcessHost());
[email protected]08e94b82010-12-15 22:51:04247 bool windowOpenerValid = false;
[email protected]b6987e02013-01-04 18:30:43248 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]e0448872013-01-11 19:35:02249 browser()->tab_strip_model()->GetWebContentsAt(6),
[email protected]06bc5d92013-01-02 22:44:13250 "window.domAutomationController.send(window.opener != null)",
[email protected]08e94b82010-12-15 22:51:04251 &windowOpenerValid));
252 ASSERT_TRUE(windowOpenerValid);
[email protected]87c7c292011-10-27 16:16:41253
254 LOG(INFO) << "End of test.";
[email protected]3a8eecb2010-04-22 23:56:30255}
[email protected]faf407b2011-01-05 01:24:32256
[email protected]056ad2a2011-07-12 02:13:55257// Test that hosted apps without the background permission use a process per app
258// instance model, such that separate instances are in separate processes.
[email protected]19da16a92012-05-23 17:11:29259IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) {
[email protected]7b54ca02012-03-02 18:06:53260 TestAppInstancesHelper("app_process_instances");
261}
[email protected]87c7c292011-10-27 16:16:41262
[email protected]7b54ca02012-03-02 18:06:53263// Test that hosted apps with the background permission but that set
264// allow_js_access to false also use a process per app instance model.
265// Separate instances should be in separate processes.
[email protected]0d70b7d42012-12-13 01:14:20266// Flaky on XP: http://crbug.com/165834
[email protected]0cfb748b2012-12-13 01:10:11267#if defined(OS_WIN)
268#define MAYBE_AppProcessBackgroundInstances \
269 DISABLED_AppProcessBackgroundInstances
270#else
271#define MAYBE_AppProcessBackgroundInstances AppProcessBackgroundInstances
272#endif
273IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessBackgroundInstances) {
[email protected]7b54ca02012-03-02 18:06:53274 TestAppInstancesHelper("app_process_background_instances");
[email protected]056ad2a2011-07-12 02:13:55275}
276
[email protected]15877ca2011-11-18 22:40:52277// Tests that bookmark apps do not use the app process model and are treated
278// like normal web pages instead. http://crbug.com/104636.
[email protected]19da16a92012-05-23 17:11:29279IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) {
[email protected]06bdd2b2012-11-30 18:47:13280 ExtensionService* service = extensions::ExtensionSystem::Get(
281 browser()->profile())->extension_service();
[email protected]c2f36e3a2011-12-14 01:27:19282 extensions::ProcessMap* process_map = service->process_map();
[email protected]15877ca2011-11-18 22:40:52283
284 host_resolver()->AddRule("*", "127.0.0.1");
285 ASSERT_TRUE(test_server()->Start());
[email protected]15877ca2011-11-18 22:40:52286 GURL base_url = GetTestBaseURL("app_process");
287
[email protected]c2f36e3a2011-12-14 01:27:19288 // Load an app as a bookmark app.
289 std::string error;
290 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
291 test_data_dir_.AppendASCII("app_process"),
[email protected]12075d12013-02-27 05:38:05292 extensions::Manifest::UNPACKED,
[email protected]c2f36e3a2011-12-14 01:27:19293 Extension::FROM_BOOKMARK,
294 &error));
[email protected]26367b62012-10-04 23:03:32295 service->OnExtensionInstalled(extension,
[email protected]98270432012-09-11 20:51:24296 syncer::StringOrdinal::CreateInitialOrdinal(),
[email protected]0db124b02012-11-07 04:55:05297 false /* no requirement errors */,
298 false /* don't wait for idle */);
[email protected]c2f36e3a2011-12-14 01:27:19299 ASSERT_TRUE(extension.get());
300 ASSERT_TRUE(extension->from_bookmark());
301
[email protected]15877ca2011-11-18 22:40:52302 // Test both opening a URL in a new tab, and opening a tab and then navigating
303 // it. Either way, bookmark app tabs should be considered normal processes
304 // with no elevated privileges and no WebUI bindings.
305 ui_test_utils::NavigateToURLWithDisposition(
306 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
307 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
308 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02309 browser()->tab_strip_model()->GetWebContentsAt(1)->
310 GetRenderProcessHost()->GetID()));
311 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(1)->GetWebUI());
[email protected]15877ca2011-11-18 22:40:52312
[email protected]a7fe9112012-07-20 02:34:45313 content::WindowedNotificationObserver tab_added_observer(
[email protected]884033e2012-04-16 19:38:42314 chrome::NOTIFICATION_TAB_ADDED,
[email protected]15877ca2011-11-18 22:40:52315 content::NotificationService::AllSources());
[email protected]a37d4b02012-06-25 21:56:10316 chrome::NewTab(browser());
[email protected]15877ca2011-11-18 22:40:52317 tab_added_observer.Wait();
318 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
319 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02320 browser()->tab_strip_model()->GetWebContentsAt(2)->
321 GetRenderProcessHost()->GetID()));
322 EXPECT_FALSE(browser()->tab_strip_model()->GetWebContentsAt(2)->GetWebUI());
[email protected]15877ca2011-11-18 22:40:52323
324 // We should have opened 2 new bookmark app tabs. Including the original blank
325 // tab, we now have 3 tabs. Because normal pages use the
326 // process-per-site-instance model, each should be in its own process.
[email protected]e0448872013-01-11 19:35:02327 ASSERT_EQ(3, browser()->tab_strip_model()->count());
328 WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
[email protected]19da16a92012-05-23 17:11:29329 EXPECT_NE(tab->GetRenderProcessHost(),
[email protected]e0448872013-01-11 19:35:02330 browser()->tab_strip_model()->GetWebContentsAt(2)->
331 GetRenderProcessHost());
[email protected]15877ca2011-11-18 22:40:52332
333 // Now let's do the same using window.open. The same should happen.
[email protected]c987a242013-02-28 01:17:41334 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
335 browser()->host_desktop_type()));
[email protected]19da16a92012-05-23 17:11:29336 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
337 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
[email protected]15877ca2011-11-18 22:40:52338
339 // Now let's have a tab navigate out of and back into the app's web
340 // extent. Neither navigation should switch processes.
341 const GURL& app_url(base_url.Resolve("path1/empty.html"));
342 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
[email protected]52877dbc62012-06-29 22:22:03343 RenderViewHost* host2 =
[email protected]e0448872013-01-11 19:35:02344 browser()->tab_strip_model()->GetWebContentsAt(2)->GetRenderViewHost();
345 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
346 non_app_url);
[email protected]9f76c1e2012-03-05 15:15:58347 EXPECT_EQ(host2->GetProcess(),
[email protected]e0448872013-01-11 19:35:02348 browser()->tab_strip_model()->GetWebContentsAt(2)->
349 GetRenderProcessHost());
350 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(2),
351 app_url);
[email protected]9f76c1e2012-03-05 15:15:58352 EXPECT_EQ(host2->GetProcess(),
[email protected]e0448872013-01-11 19:35:02353 browser()->tab_strip_model()->GetWebContentsAt(2)->
354 GetRenderProcessHost());
[email protected]15877ca2011-11-18 22:40:52355}
356
[email protected]faf407b2011-01-05 01:24:32357// Tests that app process switching works properly in the following scenario:
358// 1. navigate to a page1 in the app
359// 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
360// 3. page2 redirects back to a page in the app
361// The final navigation should end up in the app process.
362// See http://crbug.com/61757
[email protected]ea7b7d82012-05-25 17:29:17363IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) {
[email protected]faf407b2011-01-05 01:24:32364 host_resolver()->AddRule("*", "127.0.0.1");
365 ASSERT_TRUE(test_server()->Start());
366
367 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
368
369 // Open two tabs in the app.
[email protected]118d3122011-08-10 17:09:53370 GURL base_url = GetTestBaseURL("app_process");
[email protected]faf407b2011-01-05 01:24:32371
[email protected]a37d4b02012-06-25 21:56:10372 chrome::NewTab(browser());
[email protected]faf407b2011-01-05 01:24:32373 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]a37d4b02012-06-25 21:56:10374 chrome::NewTab(browser());
[email protected]ea7b7d82012-05-25 17:29:17375 // Wait until the second tab finishes its redirect train (2 hops).
[email protected]4ad5d77d2011-12-03 02:00:48376 // 1. We navigate to redirect.html
377 // 2. Renderer navigates and finishes, counting as a load stop.
378 // 3. Renderer issues the meta refresh to navigate to server-redirect.
379 // 4. Renderer is now in a "provisional load", waiting for navigation to
380 // complete.
381 // 5. Browser sees a redirect response from server-redirect to empty.html, and
382 // transfers that to a new navigation, using RequestTransferURL.
[email protected]ea7b7d82012-05-25 17:29:17383 // 6. Renderer navigates to empty.html, and finishes loading, counting as the
384 // second load stop
[email protected]4ad5d77d2011-12-03 02:00:48385 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
[email protected]ea7b7d82012-05-25 17:29:17386 browser(), base_url.Resolve("path1/redirect.html"), 2);
[email protected]faf407b2011-01-05 01:24:32387
388 // 3 tabs, including the initial about:blank. The last 2 should be the same
389 // process.
[email protected]e0448872013-01-11 19:35:02390 ASSERT_EQ(3, browser()->tab_strip_model()->count());
[email protected]089e8c332011-01-06 21:37:29391 EXPECT_EQ("/files/extensions/api_test/app_process/path1/empty.html",
[email protected]e0448872013-01-11 19:35:02392 browser()->tab_strip_model()->GetWebContentsAt(2)->
393 GetController().GetLastCommittedEntry()->GetURL().path());
394 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1)->
395 GetRenderProcessHost(),
396 browser()->tab_strip_model()->GetWebContentsAt(2)->
397 GetRenderProcessHost());
[email protected]faf407b2011-01-05 01:24:32398}
[email protected]d292d8a2011-05-25 03:47:11399
[email protected]aaef4752013-03-02 10:10:51400// Ensure that re-navigating to a URL after installing or uninstalling it as an
401// app correctly swaps the tab to the app process. (http://crbug.com/80621)
402IN_PROC_BROWSER_TEST_F(AppApiTest, NavigateIntoAppProcess) {
[email protected]06bdd2b2012-11-30 18:47:13403 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
404 browser()->profile())->extension_service()->process_map();
[email protected]718eab62011-10-05 21:16:52405
[email protected]d292d8a2011-05-25 03:47:11406 host_resolver()->AddRule("*", "127.0.0.1");
407 ASSERT_TRUE(test_server()->Start());
408
409 // The app under test acts on URLs whose host is "localhost",
410 // so the URLs we navigate to must have host "localhost".
[email protected]118d3122011-08-10 17:09:53411 GURL base_url = GetTestBaseURL("app_process");
[email protected]d292d8a2011-05-25 03:47:11412
413 // Load an app URL before loading the app.
414 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]e0448872013-01-11 19:35:02415 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]6f371442011-11-09 06:45:46416 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52417 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11418
[email protected]aaef4752013-03-02 10:10:51419 // Load app and re-navigate to the page.
[email protected]d292d8a2011-05-25 03:47:11420 const Extension* app =
421 LoadExtension(test_data_dir_.AppendASCII("app_process"));
422 ASSERT_TRUE(app);
423 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]6f371442011-11-09 06:45:46424 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52425 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11426
[email protected]aaef4752013-03-02 10:10:51427 // Disable app and re-navigate to the page.
[email protected]d292d8a2011-05-25 03:47:11428 DisableExtension(app->id());
429 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]6f371442011-11-09 06:45:46430 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52431 contents->GetRenderProcessHost()->GetID()));
[email protected]aaef4752013-03-02 10:10:51432}
433
434// Ensure that reloading a URL after installing or uninstalling it as an app
435// correctly swaps the tab to the app process. (http://crbug.com/80621)
436IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
437 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
438 browser()->profile())->extension_service()->process_map();
439
440 host_resolver()->AddRule("*", "127.0.0.1");
441 ASSERT_TRUE(test_server()->Start());
442
443 // The app under test acts on URLs whose host is "localhost",
444 // so the URLs we navigate to must have host "localhost".
445 GURL base_url = GetTestBaseURL("app_process");
446
447 // Load app, disable it, and navigate to the page.
448 const Extension* app =
449 LoadExtension(test_data_dir_.AppendASCII("app_process"));
450 ASSERT_TRUE(app);
451 DisableExtension(app->id());
452 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
453 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
454 EXPECT_FALSE(process_map->Contains(
455 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11456
[email protected]8d3132f62011-10-12 07:13:42457 // Enable app and reload the page.
458 EnableExtension(app->id());
[email protected]a7fe9112012-07-20 02:34:45459 content::WindowedNotificationObserver reload_observer(
[email protected]8d3132f62011-10-12 07:13:42460 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50461 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02462 &browser()->tab_strip_model()->GetActiveWebContents()->
463 GetController()));
[email protected]a37d4b02012-06-25 21:56:10464 chrome::Reload(browser(), CURRENT_TAB);
[email protected]8d3132f62011-10-12 07:13:42465 reload_observer.Wait();
[email protected]6f371442011-11-09 06:45:46466 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52467 contents->GetRenderProcessHost()->GetID()));
[email protected]8d3132f62011-10-12 07:13:42468
469 // Disable app and reload the page.
470 DisableExtension(app->id());
[email protected]a7fe9112012-07-20 02:34:45471 content::WindowedNotificationObserver reload_observer2(
[email protected]8d3132f62011-10-12 07:13:42472 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50473 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02474 &browser()->tab_strip_model()->GetActiveWebContents()->
475 GetController()));
[email protected]a37d4b02012-06-25 21:56:10476 chrome::Reload(browser(), CURRENT_TAB);
[email protected]8d3132f62011-10-12 07:13:42477 reload_observer2.Wait();
[email protected]6f371442011-11-09 06:45:46478 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52479 contents->GetRenderProcessHost()->GetID()));
[email protected]aaef4752013-03-02 10:10:51480}
481
482// Ensure that reloading a URL with JavaScript after installing or uninstalling
483// it as an app correctly swaps the process. (http://crbug.com/80621)
484IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcessWithJavaScript) {
485 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
486 browser()->profile())->extension_service()->process_map();
487
488 host_resolver()->AddRule("*", "127.0.0.1");
489 ASSERT_TRUE(test_server()->Start());
490
491 // The app under test acts on URLs whose host is "localhost",
492 // so the URLs we navigate to must have host "localhost".
493 GURL base_url = GetTestBaseURL("app_process");
494
495 // Load app, disable it, and navigate to the page.
496 const Extension* app =
497 LoadExtension(test_data_dir_.AppendASCII("app_process"));
498 ASSERT_TRUE(app);
499 DisableExtension(app->id());
500 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
501 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
502 EXPECT_FALSE(process_map->Contains(
503 contents->GetRenderProcessHost()->GetID()));
[email protected]8d3132f62011-10-12 07:13:42504
[email protected]d292d8a2011-05-25 03:47:11505 // Enable app and reload via JavaScript.
506 EnableExtension(app->id());
[email protected]a7fe9112012-07-20 02:34:45507 content::WindowedNotificationObserver js_reload_observer(
[email protected]8d3132f62011-10-12 07:13:42508 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50509 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02510 &browser()->tab_strip_model()->GetActiveWebContents()->
511 GetController()));
[email protected]b6987e02013-01-04 18:30:43512 ASSERT_TRUE(content::ExecuteScript(contents, "location.reload();"));
[email protected]8d3132f62011-10-12 07:13:42513 js_reload_observer.Wait();
[email protected]6f371442011-11-09 06:45:46514 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52515 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11516
517 // Disable app and reload via JavaScript.
518 DisableExtension(app->id());
[email protected]a7fe9112012-07-20 02:34:45519 content::WindowedNotificationObserver js_reload_observer2(
[email protected]8d3132f62011-10-12 07:13:42520 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50521 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02522 &browser()->tab_strip_model()->GetActiveWebContents()->
523 GetController()));
[email protected]b6987e02013-01-04 18:30:43524 ASSERT_TRUE(content::ExecuteScript(contents, "location = location;"));
[email protected]8d3132f62011-10-12 07:13:42525 js_reload_observer2.Wait();
[email protected]6f371442011-11-09 06:45:46526 EXPECT_FALSE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52527 contents->GetRenderProcessHost()->GetID()));
[email protected]d292d8a2011-05-25 03:47:11528}
[email protected]118d3122011-08-10 17:09:53529
[email protected]118d3122011-08-10 17:09:53530// Tests that if we have a non-app process (path3/container.html) that has an
531// iframe with a URL in the app's extent (path1/iframe.html), then opening a
532// link from that iframe to a new window to a URL in the app's extent (path1/
533// empty.html) results in the new window being in an app process. See
534// http://crbug.com/89272 for more details.
[email protected]1f4495b2012-10-12 05:51:05535IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
[email protected]06bdd2b2012-11-30 18:47:13536 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
537 browser()->profile())->extension_service()->process_map();
[email protected]718eab62011-10-05 21:16:52538
[email protected]118d3122011-08-10 17:09:53539 host_resolver()->AddRule("*", "127.0.0.1");
540 ASSERT_TRUE(test_server()->Start());
541
542 GURL base_url = GetTestBaseURL("app_process");
543
544 // Load app and start URL (not in the app).
545 const Extension* app =
546 LoadExtension(test_data_dir_.AppendASCII("app_process"));
547 ASSERT_TRUE(app);
[email protected]19da16a92012-05-23 17:11:29548
[email protected]a7fe9112012-07-20 02:34:45549 content::WindowedNotificationObserver popup_observer(
[email protected]079b3cc2012-09-26 19:59:13550 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
551 content::NotificationService::AllSources());
[email protected]19da16a92012-05-23 17:11:29552 ui_test_utils::NavigateToURL(browser(),
553 base_url.Resolve("path3/container.html"));
[email protected]6f371442011-11-09 06:45:46554 EXPECT_FALSE(process_map->Contains(
[email protected]e0448872013-01-11 19:35:02555 browser()->tab_strip_model()->GetWebContentsAt(0)->
556 GetRenderProcessHost()->GetID()));
[email protected]19da16a92012-05-23 17:11:29557 popup_observer.Wait();
[email protected]118d3122011-08-10 17:09:53558
559 // Popup window should be in the app's process.
[email protected]19da16a92012-05-23 17:11:29560 RenderViewHost* popup_host =
561 content::Source<RenderViewHost>(popup_observer.source()).ptr();
562 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID()));
[email protected]118d3122011-08-10 17:09:53563}
[email protected]a09add52011-08-12 03:59:23564
[email protected]079b3cc2012-09-26 19:59:13565// Similar to the previous test, but ensure that popup blocking bypass
566// isn't granted to the iframe. See crbug.com/117446.
[email protected]1f4495b2012-10-12 05:51:05567#if defined(OS_CHROMEOS)
568// http://crbug.com/153513
569#define MAYBE_OpenAppFromIframe DISABLED_OpenAppFromIframe
570#else
571#define MAYBE_OpenAppFromIframe OpenAppFromIframe
572#endif
573IN_PROC_BROWSER_TEST_F(BlockedAppApiTest, MAYBE_OpenAppFromIframe) {
[email protected]079b3cc2012-09-26 19:59:13574 host_resolver()->AddRule("*", "127.0.0.1");
575 ASSERT_TRUE(test_server()->Start());
576
577 // Load app and start URL (not in the app).
578 const Extension* app =
579 LoadExtension(test_data_dir_.AppendASCII("app_process"));
580 ASSERT_TRUE(app);
581
582 content::WindowedNotificationObserver blocker_observer(
583 chrome::NOTIFICATION_CONTENT_BLOCKED_STATE_CHANGED,
584 content::NotificationService::AllSources());
585 ui_test_utils::NavigateToURL(
586 browser(), GetTestBaseURL("app_process").Resolve("path3/container.html"));
587
588 blocker_observer.Wait();
589
[email protected]e0448872013-01-11 19:35:02590 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]079b3cc2012-09-26 19:59:13591 BlockedContentTabHelper* blocked_content_tab_helper =
592 BlockedContentTabHelper::FromWebContents(tab);
593 std::vector<WebContents*> blocked_contents;
594 blocked_content_tab_helper->GetBlockedContents(&blocked_contents);
595 EXPECT_EQ(blocked_contents.size(), 1u);
596}
597
[email protected]88aae972011-12-16 01:14:18598// Tests that if an extension launches an app via chrome.tabs.create with an URL
599// that's not in the app's extent but that redirects to it, we still end up with
600// an app process. See http://crbug.com/99349 for more details.
601IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) {
602 host_resolver()->AddRule("*", "127.0.0.1");
603 ASSERT_TRUE(StartTestServer());
604
605 LoadExtension(test_data_dir_.AppendASCII("app_process"));
606 const Extension* launcher =
607 LoadExtension(test_data_dir_.AppendASCII("app_launcher"));
608
609 // There should be three navigations by the time the app page is loaded.
610 // 1. The extension launcher page.
611 // 2. The URL that the extension launches, which redirects.
612 // 3. The app's URL.
[email protected]5b8ff1c2012-06-02 20:42:20613 content::TestNavigationObserver test_navigation_observer(
614 content::NotificationService::AllSources(),
615 NULL,
616 3);
[email protected]88aae972011-12-16 01:14:18617
618 // Load the launcher extension, which should launch the app.
619 ui_test_utils::NavigateToURLWithDisposition(
620 browser(),
621 launcher->GetResourceURL("main.html"),
622 CURRENT_TAB,
623 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
624
625 // Wait for app tab to be created and loaded.
626 test_navigation_observer.WaitForObservation(
[email protected]729eb632012-07-26 04:45:26627 base::Bind(&content::RunMessageLoop),
[email protected]88aae972011-12-16 01:14:18628 base::Bind(&MessageLoop::Quit,
629 base::Unretained(MessageLoopForUI::current())));
630
631 // App has loaded, and chrome.app.isInstalled should be true.
632 bool is_installed = false;
[email protected]b6987e02013-01-04 18:30:43633 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
[email protected]e0448872013-01-11 19:35:02634 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13635 "window.domAutomationController.send(chrome.app.isInstalled)",
[email protected]88aae972011-12-16 01:14:18636 &is_installed));
637 ASSERT_TRUE(is_installed);
638}
639
[email protected]d55c2382011-08-18 23:10:36640// Tests that if we have an app process (path1/container.html) with a non-app
641// iframe (path3/iframe.html), then opening a link from that iframe to a new
642// window to a same-origin non-app URL (path3/empty.html) should keep the window
643// in the app process.
644// This is in contrast to OpenAppFromIframe, since here the popup will not be
645// missing special permissions and should be scriptable from the iframe.
646// See http://crbug.com/92669 for more details.
[email protected]19da16a92012-05-23 17:11:29647IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) {
[email protected]06bdd2b2012-11-30 18:47:13648 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
649 browser()->profile())->extension_service()->process_map();
[email protected]718eab62011-10-05 21:16:52650
[email protected]d55c2382011-08-18 23:10:36651 host_resolver()->AddRule("*", "127.0.0.1");
652 ASSERT_TRUE(test_server()->Start());
653
654 GURL base_url = GetTestBaseURL("app_process");
655
656 // Load app and start URL (in the app).
657 const Extension* app =
658 LoadExtension(test_data_dir_.AppendASCII("app_process"));
659 ASSERT_TRUE(app);
[email protected]19da16a92012-05-23 17:11:29660
[email protected]a7fe9112012-07-20 02:34:45661 content::WindowedNotificationObserver popup_observer(
[email protected]19da16a92012-05-23 17:11:29662 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
663 content::NotificationService::AllSources());
664 ui_test_utils::NavigateToURL(browser(),
665 base_url.Resolve("path1/container.html"));
[email protected]f3b1a082011-11-18 00:34:30666 content::RenderProcessHost* process =
[email protected]e0448872013-01-11 19:35:02667 browser()->tab_strip_model()->GetWebContentsAt(0)->GetRenderProcessHost();
[email protected]f3b1a082011-11-18 00:34:30668 EXPECT_TRUE(process_map->Contains(process->GetID()));
[email protected]d55c2382011-08-18 23:10:36669
[email protected]19da16a92012-05-23 17:11:29670 // Wait for popup window to appear.
671 popup_observer.Wait();
[email protected]d55c2382011-08-18 23:10:36672
673 // Popup window should be in the app's process.
[email protected]19da16a92012-05-23 17:11:29674 RenderViewHost* popup_host =
675 content::Source<RenderViewHost>(popup_observer.source()).ptr();
676 EXPECT_EQ(process, popup_host->GetProcess());
[email protected]d55c2382011-08-18 23:10:36677}
678
[email protected]a344b762012-03-16 18:53:49679// http://crbug.com/118502
680#if defined(OS_MACOSX) || defined(OS_LINUX)
681#define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash
682#else
683#define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash
684#endif
685IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) {
[email protected]06bdd2b2012-11-30 18:47:13686 extensions::ProcessMap* process_map = extensions::ExtensionSystem::Get(
687 browser()->profile())->extension_service()->process_map();
[email protected]6f371442011-11-09 06:45:46688
[email protected]a09add52011-08-12 03:59:23689 host_resolver()->AddRule("*", "127.0.0.1");
690 ASSERT_TRUE(test_server()->Start());
691
692 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
693
694 GURL base_url = GetTestBaseURL("app_process");
695
696 // Load the app, chrome.app.isInstalled should be true.
697 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
[email protected]e0448872013-01-11 19:35:02698 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]6f371442011-11-09 06:45:46699 EXPECT_TRUE(process_map->Contains(
[email protected]151a63d2011-12-20 22:32:52700 contents->GetRenderProcessHost()->GetID()));
[email protected]a09add52011-08-12 03:59:23701 bool is_installed = false;
[email protected]b6987e02013-01-04 18:30:43702 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
703 contents,
[email protected]06bc5d92013-01-02 22:44:13704 "window.domAutomationController.send(chrome.app.isInstalled)",
[email protected]a09add52011-08-12 03:59:23705 &is_installed));
706 ASSERT_TRUE(is_installed);
707
708 // Crash the tab and reload it, chrome.app.isInstalled should still be true.
[email protected]e0448872013-01-11 19:35:02709 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents());
[email protected]a7fe9112012-07-20 02:34:45710 content::WindowedNotificationObserver observer(
[email protected]ae673742011-08-24 19:48:37711 content::NOTIFICATION_LOAD_STOP,
[email protected]c5eed492012-01-04 17:07:50712 content::Source<NavigationController>(
[email protected]e0448872013-01-11 19:35:02713 &browser()->tab_strip_model()->GetActiveWebContents()->
714 GetController()));
[email protected]a37d4b02012-06-25 21:56:10715 chrome::Reload(browser(), CURRENT_TAB);
[email protected]ae673742011-08-24 19:48:37716 observer.Wait();
[email protected]b6987e02013-01-04 18:30:43717 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
718 contents,
[email protected]06bc5d92013-01-02 22:44:13719 "window.domAutomationController.send(chrome.app.isInstalled)",
[email protected]a09add52011-08-12 03:59:23720 &is_installed));
721 ASSERT_TRUE(is_installed);
722}