app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / isolated_app_browsertest.cc
blob38ee2bd3bc555a3443602a9ba812f3cd93158ac4
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/stringprintf.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/site_instance.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/browser_test_utils.h"
18 #include "extensions/browser/extension_host.h"
19 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/process_map.h"
21 #include "extensions/common/switches.h"
22 #include "net/dns/mock_host_resolver.h"
23 #include "net/test/embedded_test_server/embedded_test_server.h"
24 #include "net/test/embedded_test_server/http_request.h"
25 #include "net/test/embedded_test_server/http_response.h"
27 using content::ExecuteScript;
28 using content::ExecuteScriptAndExtractString;
29 using content::NavigationController;
30 using content::RenderViewHost;
31 using content::WebContents;
33 namespace extensions {
35 namespace {
37 std::string WrapForJavascriptAndExtract(const char* javascript_expression) {
38 return std::string("window.domAutomationController.send(") +
39 javascript_expression + ")";
42 scoped_ptr<net::test_server::HttpResponse> HandleExpectAndSetCookieRequest(
43 const net::test_server::EmbeddedTestServer* test_server,
44 const net::test_server::HttpRequest& request) {
45 if (!StartsWithASCII(request.relative_url, "/expect-and-set-cookie?", true))
46 return scoped_ptr<net::test_server::HttpResponse>();
48 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
49 new net::test_server::BasicHttpResponse);
50 http_response->set_code(net::HTTP_OK);
52 std::string request_cookies;
53 std::map<std::string, std::string>::const_iterator it =
54 request.headers.find("Cookie");
55 if (it != request.headers.end())
56 request_cookies = it->second;
58 size_t query_string_pos = request.relative_url.find('?');
59 std::string query_string =
60 request.relative_url.substr(query_string_pos + 1);
61 url::Component query(0, query_string.length()), key_pos, value_pos;
62 bool expectations_satisfied = true;
63 std::vector<std::string> cookies_to_set;
64 while (url::ExtractQueryKeyValue(query_string.c_str(), &query, &key_pos,
65 &value_pos)) {
66 std::string escaped_key(query_string.substr(key_pos.begin, key_pos.len));
67 std::string escaped_value(
68 query_string.substr(value_pos.begin, value_pos.len));
70 std::string key =
71 net::UnescapeURLComponent(escaped_key,
72 net::UnescapeRule::NORMAL |
73 net::UnescapeRule::SPACES |
74 net::UnescapeRule::URL_SPECIAL_CHARS);
76 std::string value =
77 net::UnescapeURLComponent(escaped_value,
78 net::UnescapeRule::NORMAL |
79 net::UnescapeRule::SPACES |
80 net::UnescapeRule::URL_SPECIAL_CHARS);
82 if (key == "expect") {
83 if (request_cookies.find(value) == std::string::npos)
84 expectations_satisfied = false;
85 } else if (key == "set") {
86 cookies_to_set.push_back(value);
87 } else {
88 return nullptr;
92 if (expectations_satisfied) {
93 for (size_t i = 0; i < cookies_to_set.size(); i++)
94 http_response->AddCustomHeader("Set-Cookie", cookies_to_set[i]);
97 return http_response.Pass();
100 class IsolatedAppTest : public ExtensionBrowserTest {
101 public:
102 // Returns whether the given tab's current URL has the given cookie.
103 bool WARN_UNUSED_RESULT HasCookie(WebContents* contents, std::string cookie) {
104 int value_size;
105 std::string actual_cookie;
106 ui_test_utils::GetCookies(contents->GetURL(), contents, &value_size,
107 &actual_cookie);
108 return actual_cookie.find(cookie) != std::string::npos;
111 const Extension* GetInstalledApp(WebContents* contents) {
112 content::BrowserContext* browser_context = contents->GetBrowserContext();
113 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context);
114 std::set<std::string> extension_ids =
115 ProcessMap::Get(browser_context)->GetExtensionsInProcess(
116 contents->GetRenderViewHost()->GetProcess()->GetID());
117 for (std::set<std::string>::iterator iter = extension_ids.begin();
118 iter != extension_ids.end(); ++iter) {
119 const Extension* installed_app =
120 registry->enabled_extensions().GetByID(*iter);
121 if (installed_app && installed_app->is_app())
122 return installed_app;
124 return NULL;
127 private:
128 void SetUpCommandLine(base::CommandLine* command_line) override {
129 ExtensionBrowserTest::SetUpCommandLine(command_line);
130 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
134 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossProcessClientRedirect) {
135 host_resolver()->AddRule("*", "127.0.0.1");
136 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
138 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
139 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
141 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/");
142 GURL::Replacements replace_host;
143 std::string host_str("localhost"); // Must stay in scope with replace_host.
144 replace_host.SetHostStr(host_str);
145 base_url = base_url.ReplaceComponents(replace_host);
146 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
148 // Redirect to app2.
149 GURL redirect_url(embedded_test_server()->GetURL(
150 "/extensions/isolated_apps/app2/redirect.html"));
151 ui_test_utils::NavigateToURL(browser(), redirect_url);
153 // Go back twice.
154 // If bug fixed, we cannot go back anymore.
155 // If not fixed, we will redirect back to app2 and can go back again.
156 EXPECT_TRUE(chrome::CanGoBack(browser()));
157 chrome::GoBack(browser(), CURRENT_TAB);
158 EXPECT_TRUE(chrome::CanGoBack(browser()));
159 chrome::GoBack(browser(), CURRENT_TAB);
160 EXPECT_FALSE(chrome::CanGoBack(browser()));
162 // We also need to test script-initialized navigation (document.location.href)
163 // happened after page finishes loading. This one will also triggered the
164 // willPerformClientRedirect hook in RenderViewImpl but should not replace
165 // the previous history entry.
166 ui_test_utils::NavigateToURLWithDisposition(
167 browser(), base_url.Resolve("non_app/main.html"),
168 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
170 WebContents* tab0 = browser()->tab_strip_model()->GetWebContentsAt(1);
172 // Using JavaScript to navigate to app2 page,
173 // after the non_app page has finished loading.
174 content::WindowedNotificationObserver observer1(
175 content::NOTIFICATION_LOAD_STOP,
176 content::Source<NavigationController>(
177 &browser()->tab_strip_model()->GetActiveWebContents()->
178 GetController()));
179 std::string script = base::StringPrintf(
180 "document.location.href=\"%s\";",
181 base_url.Resolve("app2/main.html").spec().c_str());
182 EXPECT_TRUE(ExecuteScript(tab0, script));
183 observer1.Wait();
185 // This kind of navigation should not replace previous navigation entry.
186 EXPECT_TRUE(chrome::CanGoBack(browser()));
187 chrome::GoBack(browser(), CURRENT_TAB);
188 EXPECT_FALSE(chrome::CanGoBack(browser()));
191 // Tests that cookies set within an isolated app are not visible to normal
192 // pages or other apps.
194 // TODO(ajwong): Also test what happens if an app spans multiple sites in its
195 // extent. These origins should also be isolated, but still have origin-based
196 // separation as you would expect.
198 // This test is disabled due to being flaky. http://crbug.com/86562
199 #if defined(OS_WIN)
200 #define MAYBE_CookieIsolation DISABLED_CookieIsolation
201 #else
202 #define MAYBE_CookieIsolation CookieIsolation
203 #endif
204 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_CookieIsolation) {
205 host_resolver()->AddRule("*", "127.0.0.1");
206 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
208 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
209 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
211 // The app under test acts on URLs whose host is "localhost",
212 // so the URLs we navigate to must have host "localhost".
213 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/");
214 GURL::Replacements replace_host;
215 std::string host_str("localhost"); // Must stay in scope with replace_host.
216 replace_host.SetHostStr(host_str);
217 base_url = base_url.ReplaceComponents(replace_host);
219 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
220 ui_test_utils::NavigateToURLWithDisposition(
221 browser(), base_url.Resolve("app2/main.html"),
222 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
223 ui_test_utils::NavigateToURLWithDisposition(
224 browser(), base_url.Resolve("non_app/main.html"),
225 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
227 ASSERT_EQ(3, browser()->tab_strip_model()->count());
229 // Ensure first two tabs have installed apps.
230 WebContents* tab0 = browser()->tab_strip_model()->GetWebContentsAt(0);
231 WebContents* tab1 = browser()->tab_strip_model()->GetWebContentsAt(1);
232 WebContents* tab2 = browser()->tab_strip_model()->GetWebContentsAt(2);
233 ASSERT_TRUE(GetInstalledApp(tab0));
234 ASSERT_TRUE(GetInstalledApp(tab1));
235 ASSERT_TRUE(!GetInstalledApp(tab2));
237 // Check that tabs see cannot each other's localStorage even though they are
238 // in the same origin.
239 ASSERT_TRUE(ExecuteScript(
240 tab0, "window.localStorage.setItem('testdata', 'ls_app1');"));
241 ASSERT_TRUE(ExecuteScript(
242 tab1, "window.localStorage.setItem('testdata', 'ls_app2');"));
243 ASSERT_TRUE(ExecuteScript(
244 tab2, "window.localStorage.setItem('testdata', 'ls_normal');"));
246 const std::string& kRetrieveLocalStorage =
247 WrapForJavascriptAndExtract(
248 "window.localStorage.getItem('testdata') || 'badval'");
249 std::string result;
250 ASSERT_TRUE(ExecuteScriptAndExtractString(
251 tab0, kRetrieveLocalStorage.c_str(), &result));
252 EXPECT_EQ("ls_app1", result);
253 ASSERT_TRUE(ExecuteScriptAndExtractString(
254 tab1, kRetrieveLocalStorage.c_str(), &result));
255 EXPECT_EQ("ls_app2", result);
256 ASSERT_TRUE(ExecuteScriptAndExtractString(
257 tab2, kRetrieveLocalStorage.c_str(), &result));
258 EXPECT_EQ("ls_normal", result);
260 // Check that each tab sees its own cookie.
261 EXPECT_TRUE(HasCookie(tab0, "app1=3"));
262 EXPECT_TRUE(HasCookie(tab1, "app2=4"));
263 EXPECT_TRUE(HasCookie(tab2, "normalPage=5"));
265 // Check that app1 tab cannot see the other cookies.
266 EXPECT_FALSE(HasCookie(tab0, "app2"));
267 EXPECT_FALSE(HasCookie(tab0, "normalPage"));
269 // Check that app2 tab cannot see the other cookies.
270 EXPECT_FALSE(HasCookie(tab1, "app1"));
271 EXPECT_FALSE(HasCookie(tab1, "normalPage"));
273 // Check that normal tab cannot see the other cookies.
274 EXPECT_FALSE(HasCookie(tab2, "app1"));
275 EXPECT_FALSE(HasCookie(tab2, "app2"));
277 // Check that the non_app iframe cookie is associated with app1 and not the
278 // normal tab. (For now, iframes are always rendered in their parent
279 // process, even if they aren't in the app manifest.)
280 EXPECT_TRUE(HasCookie(tab0, "nonAppFrame=6"));
281 EXPECT_FALSE(HasCookie(tab2, "nonAppFrame"));
283 // Check that isolation persists even if the tab crashes and is reloaded.
284 chrome::SelectNumberedTab(browser(), 0);
285 content::CrashTab(tab0);
286 content::WindowedNotificationObserver observer(
287 content::NOTIFICATION_LOAD_STOP,
288 content::Source<NavigationController>(
289 &browser()->tab_strip_model()->GetActiveWebContents()->
290 GetController()));
291 chrome::Reload(browser(), CURRENT_TAB);
292 observer.Wait();
293 EXPECT_TRUE(HasCookie(tab0, "app1=3"));
294 EXPECT_FALSE(HasCookie(tab0, "app2"));
295 EXPECT_FALSE(HasCookie(tab0, "normalPage"));
298 // This test is disabled due to being flaky. http://crbug.com/145588
299 // Ensure that cookies are not isolated if the isolated apps are not installed.
300 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_NoCookieIsolationWithoutApp) {
301 host_resolver()->AddRule("*", "127.0.0.1");
302 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
304 // The app under test acts on URLs whose host is "localhost",
305 // so the URLs we navigate to must have host "localhost".
306 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/");
307 GURL::Replacements replace_host;
308 std::string host_str("localhost"); // Must stay in scope with replace_host.
309 replace_host.SetHostStr(host_str);
310 base_url = base_url.ReplaceComponents(replace_host);
312 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
313 ui_test_utils::NavigateToURLWithDisposition(
314 browser(), base_url.Resolve("app2/main.html"),
315 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
316 ui_test_utils::NavigateToURLWithDisposition(
317 browser(), base_url.Resolve("non_app/main.html"),
318 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
320 ASSERT_EQ(3, browser()->tab_strip_model()->count());
322 // Check that tabs see each other's cookies.
323 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(0),
324 "app2=4"));
325 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(0),
326 "normalPage=5"));
327 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(0),
328 "nonAppFrame=6"));
329 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(1),
330 "app1=3"));
331 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(1),
332 "normalPage=5"));
333 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(1),
334 "nonAppFrame=6"));
335 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(2),
336 "app1=3"));
337 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(2),
338 "app2=4"));
339 EXPECT_TRUE(HasCookie(browser()->tab_strip_model()->GetWebContentsAt(2),
340 "nonAppFrame=6"));
342 // Check that all tabs share the same localStorage if they have the same
343 // origin.
344 WebContents* app1_wc = browser()->tab_strip_model()->GetWebContentsAt(0);
345 WebContents* app2_wc = browser()->tab_strip_model()->GetWebContentsAt(1);
346 WebContents* non_app_wc = browser()->tab_strip_model()->GetWebContentsAt(2);
347 ASSERT_TRUE(ExecuteScript(
348 app1_wc, "window.localStorage.setItem('testdata', 'ls_app1');"));
349 ASSERT_TRUE(ExecuteScript(
350 app2_wc, "window.localStorage.setItem('testdata', 'ls_app2');"));
351 ASSERT_TRUE(ExecuteScript(
352 non_app_wc, "window.localStorage.setItem('testdata', 'ls_normal');"));
354 const std::string& kRetrieveLocalStorage =
355 WrapForJavascriptAndExtract("window.localStorage.getItem('testdata')");
356 std::string result;
357 ASSERT_TRUE(ExecuteScriptAndExtractString(
358 app1_wc, kRetrieveLocalStorage.c_str(), &result));
359 EXPECT_EQ("ls_normal", result);
360 ASSERT_TRUE(ExecuteScriptAndExtractString(
361 app2_wc, kRetrieveLocalStorage.c_str(), &result));
362 EXPECT_EQ("ls_normal", result);
363 ASSERT_TRUE(ExecuteScriptAndExtractString(
364 non_app_wc, kRetrieveLocalStorage.c_str(), &result));
365 EXPECT_EQ("ls_normal", result);
368 // http://crbug.com/174926
369 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX)
370 #define MAYBE_SubresourceCookieIsolation DISABLED_SubresourceCookieIsolation
371 #else
372 #define MAYBE_SubresourceCookieIsolation SubresourceCookieIsolation
373 #endif // (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX)
375 // Tests that subresource and media requests use the app's cookie store.
376 // See http://crbug.com/141172.
377 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_SubresourceCookieIsolation) {
378 embedded_test_server()->RegisterRequestHandler(
379 base::Bind(&HandleExpectAndSetCookieRequest, embedded_test_server()));
381 host_resolver()->AddRule("*", "127.0.0.1");
382 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
384 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
386 // The app under test acts on URLs whose host is "localhost",
387 // so the URLs we navigate to must have host "localhost".
388 GURL root_url = embedded_test_server()->GetURL("/");
389 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/");
390 GURL::Replacements replace_host;
391 std::string host_str("localhost"); // Must stay in scope with replace_host.
392 replace_host.SetHostStr(host_str);
393 root_url = root_url.ReplaceComponents(replace_host);
394 base_url = base_url.ReplaceComponents(replace_host);
396 // First set cookies inside and outside the app.
397 ui_test_utils::NavigateToURL(
398 browser(), root_url.Resolve("expect-and-set-cookie?set=nonApp%3d1"));
399 WebContents* tab0 = browser()->tab_strip_model()->GetWebContentsAt(0);
400 ASSERT_FALSE(GetInstalledApp(tab0));
401 ui_test_utils::NavigateToURLWithDisposition(
402 browser(), base_url.Resolve("app1/main.html"),
403 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
404 WebContents* tab1 = browser()->tab_strip_model()->GetWebContentsAt(1);
405 ASSERT_TRUE(GetInstalledApp(tab1));
407 // Check that each tab sees its own cookie.
408 EXPECT_TRUE(HasCookie(tab0, "nonApp=1"));
409 EXPECT_FALSE(HasCookie(tab0, "app1=3"));
410 EXPECT_FALSE(HasCookie(tab1, "nonApp=1"));
411 EXPECT_TRUE(HasCookie(tab1, "app1=3"));
413 // Now visit an app page that loads subresources located outside the app.
414 // For both images and video tags, it loads two URLs:
415 // - One will set nonApp{Media,Image}=1 cookies if nonApp=1 is set.
416 // - One will set app1{Media,Image}=1 cookies if app1=3 is set.
417 // We expect only the app's cookies to be present.
418 // We must wait for the onload event, to allow the subresources to finish.
419 content::WindowedNotificationObserver observer(
420 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
421 content::Source<WebContents>(
422 browser()->tab_strip_model()->GetActiveWebContents()));
423 ui_test_utils::NavigateToURL(
424 browser(), base_url.Resolve("app1/app_subresources.html"));
425 observer.Wait();
426 EXPECT_FALSE(HasCookie(tab1, "nonAppMedia=1"));
427 EXPECT_TRUE(HasCookie(tab1, "app1Media=1"));
428 EXPECT_FALSE(HasCookie(tab1, "nonAppImage=1"));
429 EXPECT_TRUE(HasCookie(tab1, "app1Image=1"));
431 // Also create a non-app tab to ensure no new cookies were set in that jar.
432 ui_test_utils::NavigateToURLWithDisposition(
433 browser(), root_url,
434 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
435 WebContents* tab2 = browser()->tab_strip_model()->GetWebContentsAt(2);
436 EXPECT_FALSE(HasCookie(tab2, "nonAppMedia=1"));
437 EXPECT_FALSE(HasCookie(tab2, "app1Media=1"));
438 EXPECT_FALSE(HasCookie(tab2, "nonAppImage=1"));
439 EXPECT_FALSE(HasCookie(tab2, "app1Image=1"));
442 // Test is flaky on Windows.
443 // http://crbug.com/247667
444 #if defined(OS_WIN)
445 #define MAYBE_IsolatedAppProcessModel DISABLED_IsolatedAppProcessModel
446 #else
447 #define MAYBE_IsolatedAppProcessModel IsolatedAppProcessModel
448 #endif // defined(OS_WIN)
450 // Tests that isolated apps processes do not render top-level non-app pages.
451 // This is true even in the case of the OAuth workaround for hosted apps,
452 // where non-app popups may be kept in the hosted app process.
453 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_IsolatedAppProcessModel) {
454 host_resolver()->AddRule("*", "127.0.0.1");
455 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
457 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
459 // The app under test acts on URLs whose host is "localhost",
460 // so the URLs we navigate to must have host "localhost".
461 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/");
462 GURL::Replacements replace_host;
463 std::string host_str("localhost"); // Must stay in scope with replace_host.
464 replace_host.SetHostStr(host_str);
465 base_url = base_url.ReplaceComponents(replace_host);
467 // Create three tabs in the isolated app in different ways.
468 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
469 ui_test_utils::NavigateToURLWithDisposition(
470 browser(), base_url.Resolve("app1/main.html"),
471 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
472 // For the third tab, use window.open to keep it in process with an opener.
473 OpenWindow(browser()->tab_strip_model()->GetWebContentsAt(0),
474 base_url.Resolve("app1/main.html"), true, NULL);
476 // In a fourth tab, use window.open to a non-app URL. It should open in a
477 // separate process, even though this would trigger the OAuth workaround
478 // for hosted apps (from http://crbug.com/59285).
479 OpenWindow(browser()->tab_strip_model()->GetWebContentsAt(0),
480 base_url.Resolve("non_app/main.html"), false, NULL);
482 // We should now have four tabs, the first and third sharing a process.
483 // The second one is an independent instance in a separate process.
484 ASSERT_EQ(4, browser()->tab_strip_model()->count());
485 int process_id_0 = browser()->tab_strip_model()->GetWebContentsAt(0)->
486 GetRenderProcessHost()->GetID();
487 int process_id_1 = browser()->tab_strip_model()->GetWebContentsAt(1)->
488 GetRenderProcessHost()->GetID();
489 EXPECT_NE(process_id_0, process_id_1);
490 EXPECT_EQ(process_id_0,
491 browser()->tab_strip_model()->GetWebContentsAt(2)->
492 GetRenderProcessHost()->GetID());
493 EXPECT_NE(process_id_0,
494 browser()->tab_strip_model()->GetWebContentsAt(3)->
495 GetRenderProcessHost()->GetID());
497 // Navigating the second tab out of the app should cause a process swap.
498 const GURL& non_app_url(base_url.Resolve("non_app/main.html"));
499 NavigateInRenderer(browser()->tab_strip_model()->GetWebContentsAt(1),
500 non_app_url);
501 EXPECT_NE(process_id_1,
502 browser()->tab_strip_model()->GetWebContentsAt(1)->
503 GetRenderProcessHost()->GetID());
506 // This test no longer passes, since we don't properly isolate sessionStorage
507 // for isolated apps. This was broken as part of the changes for storage
508 // partition support for webview tags.
509 // TODO(nasko): If isolated apps is no longer developed, this test should be
510 // removed. http://crbug.com/159932
511 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_SessionStorage) {
512 host_resolver()->AddRule("*", "127.0.0.1");
513 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
515 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
516 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2")));
518 // The app under test acts on URLs whose host is "localhost",
519 // so the URLs we navigate to must have host "localhost".
520 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/");
521 GURL::Replacements replace_host;
522 std::string host_str("localhost"); // Must stay in scope with replace_host.
523 replace_host.SetHostStr(host_str);
524 base_url = base_url.ReplaceComponents(replace_host);
526 // Enter some state into sessionStorage three times on the same origin, but
527 // for three URLs that correspond to app1, app2, and a non-isolated site.
528 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
529 ASSERT_TRUE(ExecuteScript(
530 browser()->tab_strip_model()->GetWebContentsAt(0),
531 "window.sessionStorage.setItem('testdata', 'ss_app1');"));
533 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app2/main.html"));
534 ASSERT_TRUE(ExecuteScript(
535 browser()->tab_strip_model()->GetWebContentsAt(0),
536 "window.sessionStorage.setItem('testdata', 'ss_app2');"));
538 ui_test_utils::NavigateToURL(
539 browser(), base_url.Resolve("non_app/main.html"));
540 ASSERT_TRUE(ExecuteScript(
541 browser()->tab_strip_model()->GetWebContentsAt(0),
542 "window.sessionStorage.setItem('testdata', 'ss_normal');"));
544 // Now, ensure that the sessionStorage is correctly partitioned, and persists
545 // when we navigate around all over the dang place.
546 const std::string& kRetrieveSessionStorage =
547 WrapForJavascriptAndExtract(
548 "window.sessionStorage.getItem('testdata') || 'badval'");
549 std::string result;
550 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html"));
551 ASSERT_TRUE(ExecuteScriptAndExtractString(
552 browser()->tab_strip_model()->GetWebContentsAt(0),
553 kRetrieveSessionStorage.c_str(), &result));
554 EXPECT_EQ("ss_app1", result);
556 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app2/main.html"));
557 ASSERT_TRUE(ExecuteScriptAndExtractString(
558 browser()->tab_strip_model()->GetWebContentsAt(0),
559 kRetrieveSessionStorage.c_str(), &result));
560 EXPECT_EQ("ss_app2", result);
562 ui_test_utils::NavigateToURL(
563 browser(), base_url.Resolve("non_app/main.html"));
564 ASSERT_TRUE(ExecuteScriptAndExtractString(
565 browser()->tab_strip_model()->GetWebContentsAt(0),
566 kRetrieveSessionStorage.c_str(), &result));
567 EXPECT_EQ("ss_normal", result);
570 } // namespace
572 } // namespace extensions