| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 if (expectations_satisfied) { | 97 if (expectations_satisfied) { |
| 98 for (size_t i = 0; i < cookies_to_set.size(); i++) | 98 for (size_t i = 0; i < cookies_to_set.size(); i++) |
| 99 http_response->AddCustomHeader("Set-Cookie", cookies_to_set[i]); | 99 http_response->AddCustomHeader("Set-Cookie", cookies_to_set[i]); |
| 100 } | 100 } |
| 101 | 101 |
| 102 return std::move(http_response); | 102 return std::move(http_response); |
| 103 } | 103 } |
| 104 | 104 |
| 105 class IsolatedAppTest : public ExtensionBrowserTest { | 105 class IsolatedAppTest : public ExtensionBrowserTest { |
| 106 public: | 106 public: |
| 107 void SetUpOnMainThread() override { |
| 108 ExtensionBrowserTest::SetUpOnMainThread(); |
| 109 host_resolver()->AddRule("*", "127.0.0.1"); |
| 110 } |
| 111 |
| 107 // Returns whether the given tab's current URL has the given cookie. | 112 // Returns whether the given tab's current URL has the given cookie. |
| 108 bool WARN_UNUSED_RESULT HasCookie(WebContents* contents, | 113 bool WARN_UNUSED_RESULT HasCookie(WebContents* contents, |
| 109 const std::string& cookie) { | 114 const std::string& cookie) { |
| 110 int value_size; | 115 int value_size; |
| 111 std::string actual_cookie; | 116 std::string actual_cookie; |
| 112 ui_test_utils::GetCookies(contents->GetURL(), contents, &value_size, | 117 ui_test_utils::GetCookies(contents->GetURL(), contents, &value_size, |
| 113 &actual_cookie); | 118 &actual_cookie); |
| 114 return actual_cookie.find(cookie) != std::string::npos; | 119 return actual_cookie.find(cookie) != std::string::npos; |
| 115 } | 120 } |
| 116 | 121 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 132 } | 137 } |
| 133 | 138 |
| 134 private: | 139 private: |
| 135 void SetUpCommandLine(base::CommandLine* command_line) override { | 140 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 136 ExtensionBrowserTest::SetUpCommandLine(command_line); | 141 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 137 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 142 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 138 } | 143 } |
| 139 }; | 144 }; |
| 140 | 145 |
| 141 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossProcessClientRedirect) { | 146 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossProcessClientRedirect) { |
| 142 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 143 ASSERT_TRUE(embedded_test_server()->Start()); | 147 ASSERT_TRUE(embedded_test_server()->Start()); |
| 144 | 148 |
| 145 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 149 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 146 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 150 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
| 147 | 151 |
| 148 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 152 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
| 149 GURL::Replacements replace_host; | 153 GURL::Replacements replace_host; |
| 150 replace_host.SetHostStr("localhost"); | 154 replace_host.SetHostStr("localhost"); |
| 151 base_url = base_url.ReplaceComponents(replace_host); | 155 base_url = base_url.ReplaceComponents(replace_host); |
| 152 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); | 156 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 EXPECT_FALSE(chrome::CanGoBack(browser())); | 199 EXPECT_FALSE(chrome::CanGoBack(browser())); |
| 196 } | 200 } |
| 197 | 201 |
| 198 // Tests that cookies set within an isolated app are not visible to normal | 202 // Tests that cookies set within an isolated app are not visible to normal |
| 199 // pages or other apps. | 203 // pages or other apps. |
| 200 // | 204 // |
| 201 // TODO(ajwong): Also test what happens if an app spans multiple sites in its | 205 // TODO(ajwong): Also test what happens if an app spans multiple sites in its |
| 202 // extent. These origins should also be isolated, but still have origin-based | 206 // extent. These origins should also be isolated, but still have origin-based |
| 203 // separation as you would expect. | 207 // separation as you would expect. |
| 204 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { | 208 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { |
| 205 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 206 ASSERT_TRUE(embedded_test_server()->Start()); | 209 ASSERT_TRUE(embedded_test_server()->Start()); |
| 207 | 210 |
| 208 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 211 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 209 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 212 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
| 210 | 213 |
| 211 // The app under test acts on URLs whose host is "localhost", | 214 // The app under test acts on URLs whose host is "localhost", |
| 212 // so the URLs we navigate to must have host "localhost". | 215 // so the URLs we navigate to must have host "localhost". |
| 213 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 216 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
| 214 GURL::Replacements replace_host; | 217 GURL::Replacements replace_host; |
| 215 replace_host.SetHostStr("localhost"); | 218 replace_host.SetHostStr("localhost"); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 295 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 293 observer.Wait(); | 296 observer.Wait(); |
| 294 EXPECT_TRUE(HasCookie(tab0, "app1=3")); | 297 EXPECT_TRUE(HasCookie(tab0, "app1=3")); |
| 295 EXPECT_FALSE(HasCookie(tab0, "app2")); | 298 EXPECT_FALSE(HasCookie(tab0, "app2")); |
| 296 EXPECT_FALSE(HasCookie(tab0, "normalPage")); | 299 EXPECT_FALSE(HasCookie(tab0, "normalPage")); |
| 297 } | 300 } |
| 298 | 301 |
| 299 // This test is disabled due to being flaky. http://crbug.com/145588 | 302 // This test is disabled due to being flaky. http://crbug.com/145588 |
| 300 // Ensure that cookies are not isolated if the isolated apps are not installed. | 303 // Ensure that cookies are not isolated if the isolated apps are not installed. |
| 301 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_NoCookieIsolationWithoutApp) { | 304 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_NoCookieIsolationWithoutApp) { |
| 302 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 303 ASSERT_TRUE(embedded_test_server()->Start()); | 305 ASSERT_TRUE(embedded_test_server()->Start()); |
| 304 | 306 |
| 305 // The app under test acts on URLs whose host is "localhost", | 307 // The app under test acts on URLs whose host is "localhost", |
| 306 // so the URLs we navigate to must have host "localhost". | 308 // so the URLs we navigate to must have host "localhost". |
| 307 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 309 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
| 308 GURL::Replacements replace_host; | 310 GURL::Replacements replace_host; |
| 309 replace_host.SetHostStr("localhost"); | 311 replace_host.SetHostStr("localhost"); |
| 310 base_url = base_url.ReplaceComponents(replace_host); | 312 base_url = base_url.ReplaceComponents(replace_host); |
| 311 | 313 |
| 312 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); | 314 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 #else | 375 #else |
| 374 #define MAYBE_SubresourceCookieIsolation SubresourceCookieIsolation | 376 #define MAYBE_SubresourceCookieIsolation SubresourceCookieIsolation |
| 375 #endif // (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) | 377 #endif // (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) |
| 376 | 378 |
| 377 // Tests that subresource and media requests use the app's cookie store. | 379 // Tests that subresource and media requests use the app's cookie store. |
| 378 // See http://crbug.com/141172. | 380 // See http://crbug.com/141172. |
| 379 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_SubresourceCookieIsolation) { | 381 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_SubresourceCookieIsolation) { |
| 380 embedded_test_server()->RegisterRequestHandler( | 382 embedded_test_server()->RegisterRequestHandler( |
| 381 base::Bind(&HandleExpectAndSetCookieRequest, embedded_test_server())); | 383 base::Bind(&HandleExpectAndSetCookieRequest, embedded_test_server())); |
| 382 | 384 |
| 383 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 384 ASSERT_TRUE(embedded_test_server()->Start()); | 385 ASSERT_TRUE(embedded_test_server()->Start()); |
| 385 | 386 |
| 386 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 387 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 387 | 388 |
| 388 // The app under test acts on URLs whose host is "localhost", | 389 // The app under test acts on URLs whose host is "localhost", |
| 389 // so the URLs we navigate to must have host "localhost". | 390 // so the URLs we navigate to must have host "localhost". |
| 390 GURL root_url = embedded_test_server()->GetURL("/"); | 391 GURL root_url = embedded_test_server()->GetURL("/"); |
| 391 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 392 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
| 392 GURL::Replacements replace_host; | 393 GURL::Replacements replace_host; |
| 393 replace_host.SetHostStr("localhost"); | 394 replace_host.SetHostStr("localhost"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 #if defined(OS_WIN) | 447 #if defined(OS_WIN) |
| 447 #define MAYBE_IsolatedAppProcessModel DISABLED_IsolatedAppProcessModel | 448 #define MAYBE_IsolatedAppProcessModel DISABLED_IsolatedAppProcessModel |
| 448 #else | 449 #else |
| 449 #define MAYBE_IsolatedAppProcessModel IsolatedAppProcessModel | 450 #define MAYBE_IsolatedAppProcessModel IsolatedAppProcessModel |
| 450 #endif // defined(OS_WIN) | 451 #endif // defined(OS_WIN) |
| 451 | 452 |
| 452 // Tests that isolated apps processes do not render top-level non-app pages. | 453 // Tests that isolated apps processes do not render top-level non-app pages. |
| 453 // This is true even in the case of the OAuth workaround for hosted apps, | 454 // This is true even in the case of the OAuth workaround for hosted apps, |
| 454 // where non-app popups may be kept in the hosted app process. | 455 // where non-app popups may be kept in the hosted app process. |
| 455 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_IsolatedAppProcessModel) { | 456 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_IsolatedAppProcessModel) { |
| 456 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 457 ASSERT_TRUE(embedded_test_server()->Start()); | 457 ASSERT_TRUE(embedded_test_server()->Start()); |
| 458 | 458 |
| 459 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 459 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 460 | 460 |
| 461 // The app under test acts on URLs whose host is "localhost", | 461 // The app under test acts on URLs whose host is "localhost", |
| 462 // so the URLs we navigate to must have host "localhost". | 462 // so the URLs we navigate to must have host "localhost". |
| 463 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 463 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
| 464 GURL::Replacements replace_host; | 464 GURL::Replacements replace_host; |
| 465 replace_host.SetHostStr("localhost"); | 465 replace_host.SetHostStr("localhost"); |
| 466 base_url = base_url.ReplaceComponents(replace_host); | 466 base_url = base_url.ReplaceComponents(replace_host); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 browser()->tab_strip_model()->GetWebContentsAt(1)-> | 504 browser()->tab_strip_model()->GetWebContentsAt(1)-> |
| 505 GetRenderProcessHost()->GetID()); | 505 GetRenderProcessHost()->GetID()); |
| 506 } | 506 } |
| 507 | 507 |
| 508 // This test no longer passes, since we don't properly isolate sessionStorage | 508 // This test no longer passes, since we don't properly isolate sessionStorage |
| 509 // for isolated apps. This was broken as part of the changes for storage | 509 // for isolated apps. This was broken as part of the changes for storage |
| 510 // partition support for webview tags. | 510 // partition support for webview tags. |
| 511 // TODO(nasko): If isolated apps is no longer developed, this test should be | 511 // TODO(nasko): If isolated apps is no longer developed, this test should be |
| 512 // removed. http://crbug.com/159932 | 512 // removed. http://crbug.com/159932 |
| 513 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_SessionStorage) { | 513 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_SessionStorage) { |
| 514 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 515 ASSERT_TRUE(embedded_test_server()->Start()); | 514 ASSERT_TRUE(embedded_test_server()->Start()); |
| 516 | 515 |
| 517 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 516 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 518 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 517 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
| 519 | 518 |
| 520 // The app under test acts on URLs whose host is "localhost", | 519 // The app under test acts on URLs whose host is "localhost", |
| 521 // so the URLs we navigate to must have host "localhost". | 520 // so the URLs we navigate to must have host "localhost". |
| 522 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 521 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
| 523 GURL::Replacements replace_host; | 522 GURL::Replacements replace_host; |
| 524 replace_host.SetHostStr("localhost"); | 523 replace_host.SetHostStr("localhost"); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 browser(), base_url.Resolve("non_app/main.html")); | 563 browser(), base_url.Resolve("non_app/main.html")); |
| 565 ASSERT_TRUE(ExecuteScriptAndExtractString( | 564 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 566 browser()->tab_strip_model()->GetWebContentsAt(0), | 565 browser()->tab_strip_model()->GetWebContentsAt(0), |
| 567 kRetrieveSessionStorage.c_str(), &result)); | 566 kRetrieveSessionStorage.c_str(), &result)); |
| 568 EXPECT_EQ("ss_normal", result); | 567 EXPECT_EQ("ss_normal", result); |
| 569 } | 568 } |
| 570 | 569 |
| 571 } // namespace | 570 } // namespace |
| 572 | 571 |
| 573 } // namespace extensions | 572 } // namespace extensions |
| OLD | NEW |