OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/automation/automation_util.h" | 6 #include "chrome/browser/automation/automation_util.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 EXPECT_NE(process_id_0, | 292 EXPECT_NE(process_id_0, |
293 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI
D()); | 293 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetI
D()); |
294 | 294 |
295 // Navigating the second tab out of the app should cause a process swap. | 295 // Navigating the second tab out of the app should cause a process swap. |
296 const GURL& non_app_url(base_url.Resolve("non_app/main.html")); | 296 const GURL& non_app_url(base_url.Resolve("non_app/main.html")); |
297 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url); | 297 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 1), non_app_url); |
298 EXPECT_NE(process_id_1, | 298 EXPECT_NE(process_id_1, |
299 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI
D()); | 299 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetI
D()); |
300 } | 300 } |
301 | 301 |
302 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, SessionStorage) { | 302 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, PRE_SessionStorage) { |
303 host_resolver()->AddRule("*", "127.0.0.1"); | 303 host_resolver()->AddRule("*", "127.0.0.1"); |
304 ASSERT_TRUE(test_server()->Start()); | 304 ASSERT_TRUE(test_server()->Start()); |
305 | 305 |
306 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 306 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
307 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 307 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
308 | 308 |
309 // The app under test acts on URLs whose host is "localhost", | 309 // The app under test acts on URLs whose host is "localhost", |
310 // so the URLs we navigate to must have host "localhost". | 310 // so the URLs we navigate to must have host "localhost". |
311 GURL base_url = test_server()->GetURL( | 311 GURL base_url = test_server()->GetURL( |
312 "files/extensions/isolated_apps/"); | 312 "files/extensions/isolated_apps/"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 EXPECT_EQ("ss_app2", result); | 364 EXPECT_EQ("ss_app2", result); |
365 | 365 |
366 ui_test_utils::NavigateToURLWithDisposition( | 366 ui_test_utils::NavigateToURLWithDisposition( |
367 browser(), base_url.Resolve("non_app/main.html"), | 367 browser(), base_url.Resolve("non_app/main.html"), |
368 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 368 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
369 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | 369 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
370 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | 370 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
371 L"", kRetrieveSessionStorage.c_str(), &result)); | 371 L"", kRetrieveSessionStorage.c_str(), &result)); |
372 EXPECT_EQ("ss_normal", result); | 372 EXPECT_EQ("ss_normal", result); |
373 } | 373 } |
| 374 |
| 375 // Okay, let's whack the brwoser, restore it, and see if we keep our |
| 376 // sessionStorage. |
| 377 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, SessionStorage) { |
| 378 host_resolver()->AddRule("*", "127.0.0.1"); |
| 379 ASSERT_TRUE(test_server()->Start()); |
| 380 |
| 381 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 382 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
| 383 |
| 384 // The app under test acts on URLs whose host is "localhost", |
| 385 // so the URLs we navigate to must have host "localhost". |
| 386 GURL base_url = test_server()->GetURL( |
| 387 "files/extensions/isolated_apps/"); |
| 388 GURL::Replacements replace_host; |
| 389 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 390 replace_host.SetHostStr(host_str); |
| 391 base_url = base_url.ReplaceComponents(replace_host); |
| 392 |
| 393 const std::wstring& kRetrieveSessionStorage = |
| 394 WrapForJavascriptAndExtract( |
| 395 L"window.sessionStorage.getItem('testdata')"); |
| 396 std::string result; |
| 397 Browser* new_browser = ui_test_utils::QuitBrowserAndRestore(browser(), 1); |
| 398 ui_test_utils::NavigateToURLWithDisposition( |
| 399 new_browser, base_url.Resolve("app1/main.html"), |
| 400 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 401 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 402 chrome::GetWebContentsAt(new_browser, 0)->GetRenderViewHost(), |
| 403 L"", kRetrieveSessionStorage.c_str(), &result)); |
| 404 EXPECT_EQ("ss_app1", result); |
| 405 |
| 406 ui_test_utils::NavigateToURLWithDisposition( |
| 407 new_browser, base_url.Resolve("app2/main.html"), |
| 408 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 409 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 410 chrome::GetWebContentsAt(new_browser, 0)->GetRenderViewHost(), |
| 411 L"", kRetrieveSessionStorage.c_str(), &result)); |
| 412 EXPECT_EQ("ss_app2", result); |
| 413 |
| 414 ui_test_utils::NavigateToURLWithDisposition( |
| 415 new_browser, base_url.Resolve("non_app/main.html"), |
| 416 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 417 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 418 chrome::GetWebContentsAt(new_browser, 0)->GetRenderViewHost(), |
| 419 L"", kRetrieveSessionStorage.c_str(), &result)); |
| 420 EXPECT_EQ("ss_normal", result); |
| 421 } |
OLD | NEW |