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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 namespace extensions { | 34 namespace extensions { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 std::string WrapForJavascriptAndExtract(const char* javascript_expression) { | 38 std::string WrapForJavascriptAndExtract(const char* javascript_expression) { |
39 return std::string("window.domAutomationController.send(") + | 39 return std::string("window.domAutomationController.send(") + |
40 javascript_expression + ")"; | 40 javascript_expression + ")"; |
41 } | 41 } |
42 | 42 |
43 scoped_ptr<net::test_server::HttpResponse> HandleExpectAndSetCookieRequest( | 43 scoped_ptr<net::test_server::HttpResponse> HandleExpectAndSetCookieRequest( |
44 const net::test_server::EmbeddedTestServer* test_server, | 44 const net::EmbeddedTestServer* test_server, |
45 const net::test_server::HttpRequest& request) { | 45 const net::test_server::HttpRequest& request) { |
46 if (!base::StartsWith(request.relative_url, "/expect-and-set-cookie?", | 46 if (!base::StartsWith(request.relative_url, "/expect-and-set-cookie?", |
47 base::CompareCase::SENSITIVE)) | 47 base::CompareCase::SENSITIVE)) |
48 return scoped_ptr<net::test_server::HttpResponse>(); | 48 return scoped_ptr<net::test_server::HttpResponse>(); |
49 | 49 |
50 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 50 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
51 new net::test_server::BasicHttpResponse); | 51 new net::test_server::BasicHttpResponse); |
52 http_response->set_code(net::HTTP_OK); | 52 http_response->set_code(net::HTTP_OK); |
53 | 53 |
54 std::string request_cookies; | 54 std::string request_cookies; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 private: | 130 private: |
131 void SetUpCommandLine(base::CommandLine* command_line) override { | 131 void SetUpCommandLine(base::CommandLine* command_line) override { |
132 ExtensionBrowserTest::SetUpCommandLine(command_line); | 132 ExtensionBrowserTest::SetUpCommandLine(command_line); |
133 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 133 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
134 } | 134 } |
135 }; | 135 }; |
136 | 136 |
137 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossProcessClientRedirect) { | 137 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossProcessClientRedirect) { |
138 host_resolver()->AddRule("*", "127.0.0.1"); | 138 host_resolver()->AddRule("*", "127.0.0.1"); |
139 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 139 ASSERT_TRUE(embedded_test_server()->Start()); |
140 | 140 |
141 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 141 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
142 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 142 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
143 | 143 |
144 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 144 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
145 GURL::Replacements replace_host; | 145 GURL::Replacements replace_host; |
146 replace_host.SetHostStr("localhost"); | 146 replace_host.SetHostStr("localhost"); |
147 base_url = base_url.ReplaceComponents(replace_host); | 147 base_url = base_url.ReplaceComponents(replace_host); |
148 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); | 148 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); |
149 | 149 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // separation as you would expect. | 198 // separation as you would expect. |
199 // | 199 // |
200 // This test is disabled due to being flaky. http://crbug.com/86562 | 200 // This test is disabled due to being flaky. http://crbug.com/86562 |
201 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
202 #define MAYBE_CookieIsolation DISABLED_CookieIsolation | 202 #define MAYBE_CookieIsolation DISABLED_CookieIsolation |
203 #else | 203 #else |
204 #define MAYBE_CookieIsolation CookieIsolation | 204 #define MAYBE_CookieIsolation CookieIsolation |
205 #endif | 205 #endif |
206 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_CookieIsolation) { | 206 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_CookieIsolation) { |
207 host_resolver()->AddRule("*", "127.0.0.1"); | 207 host_resolver()->AddRule("*", "127.0.0.1"); |
208 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 208 ASSERT_TRUE(embedded_test_server()->Start()); |
209 | 209 |
210 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 210 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
211 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 211 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
212 | 212 |
213 // The app under test acts on URLs whose host is "localhost", | 213 // The app under test acts on URLs whose host is "localhost", |
214 // so the URLs we navigate to must have host "localhost". | 214 // so the URLs we navigate to must have host "localhost". |
215 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 215 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
216 GURL::Replacements replace_host; | 216 GURL::Replacements replace_host; |
217 replace_host.SetHostStr("localhost"); | 217 replace_host.SetHostStr("localhost"); |
218 base_url = base_url.ReplaceComponents(replace_host); | 218 base_url = base_url.ReplaceComponents(replace_host); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 observer.Wait(); | 293 observer.Wait(); |
294 EXPECT_TRUE(HasCookie(tab0, "app1=3")); | 294 EXPECT_TRUE(HasCookie(tab0, "app1=3")); |
295 EXPECT_FALSE(HasCookie(tab0, "app2")); | 295 EXPECT_FALSE(HasCookie(tab0, "app2")); |
296 EXPECT_FALSE(HasCookie(tab0, "normalPage")); | 296 EXPECT_FALSE(HasCookie(tab0, "normalPage")); |
297 } | 297 } |
298 | 298 |
299 // This test is disabled due to being flaky. http://crbug.com/145588 | 299 // 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. | 300 // Ensure that cookies are not isolated if the isolated apps are not installed. |
301 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_NoCookieIsolationWithoutApp) { | 301 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_NoCookieIsolationWithoutApp) { |
302 host_resolver()->AddRule("*", "127.0.0.1"); | 302 host_resolver()->AddRule("*", "127.0.0.1"); |
303 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 303 ASSERT_TRUE(embedded_test_server()->Start()); |
304 | 304 |
305 // The app under test acts on URLs whose host is "localhost", | 305 // The app under test acts on URLs whose host is "localhost", |
306 // so the URLs we navigate to must have host "localhost". | 306 // so the URLs we navigate to must have host "localhost". |
307 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 307 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
308 GURL::Replacements replace_host; | 308 GURL::Replacements replace_host; |
309 replace_host.SetHostStr("localhost"); | 309 replace_host.SetHostStr("localhost"); |
310 base_url = base_url.ReplaceComponents(replace_host); | 310 base_url = base_url.ReplaceComponents(replace_host); |
311 | 311 |
312 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); | 312 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("app1/main.html")); |
313 ui_test_utils::NavigateToURLWithDisposition( | 313 ui_test_utils::NavigateToURLWithDisposition( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 #define MAYBE_SubresourceCookieIsolation SubresourceCookieIsolation | 372 #define MAYBE_SubresourceCookieIsolation SubresourceCookieIsolation |
373 #endif // (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) | 373 #endif // (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) |
374 | 374 |
375 // Tests that subresource and media requests use the app's cookie store. | 375 // Tests that subresource and media requests use the app's cookie store. |
376 // See http://crbug.com/141172. | 376 // See http://crbug.com/141172. |
377 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_SubresourceCookieIsolation) { | 377 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_SubresourceCookieIsolation) { |
378 embedded_test_server()->RegisterRequestHandler( | 378 embedded_test_server()->RegisterRequestHandler( |
379 base::Bind(&HandleExpectAndSetCookieRequest, embedded_test_server())); | 379 base::Bind(&HandleExpectAndSetCookieRequest, embedded_test_server())); |
380 | 380 |
381 host_resolver()->AddRule("*", "127.0.0.1"); | 381 host_resolver()->AddRule("*", "127.0.0.1"); |
382 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 382 ASSERT_TRUE(embedded_test_server()->Start()); |
383 | 383 |
384 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 384 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
385 | 385 |
386 // The app under test acts on URLs whose host is "localhost", | 386 // The app under test acts on URLs whose host is "localhost", |
387 // so the URLs we navigate to must have host "localhost". | 387 // so the URLs we navigate to must have host "localhost". |
388 GURL root_url = embedded_test_server()->GetURL("/"); | 388 GURL root_url = embedded_test_server()->GetURL("/"); |
389 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 389 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
390 GURL::Replacements replace_host; | 390 GURL::Replacements replace_host; |
391 replace_host.SetHostStr("localhost"); | 391 replace_host.SetHostStr("localhost"); |
392 root_url = root_url.ReplaceComponents(replace_host); | 392 root_url = root_url.ReplaceComponents(replace_host); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 #define MAYBE_IsolatedAppProcessModel DISABLED_IsolatedAppProcessModel | 444 #define MAYBE_IsolatedAppProcessModel DISABLED_IsolatedAppProcessModel |
445 #else | 445 #else |
446 #define MAYBE_IsolatedAppProcessModel IsolatedAppProcessModel | 446 #define MAYBE_IsolatedAppProcessModel IsolatedAppProcessModel |
447 #endif // defined(OS_WIN) | 447 #endif // defined(OS_WIN) |
448 | 448 |
449 // Tests that isolated apps processes do not render top-level non-app pages. | 449 // Tests that isolated apps processes do not render top-level non-app pages. |
450 // This is true even in the case of the OAuth workaround for hosted apps, | 450 // This is true even in the case of the OAuth workaround for hosted apps, |
451 // where non-app popups may be kept in the hosted app process. | 451 // where non-app popups may be kept in the hosted app process. |
452 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_IsolatedAppProcessModel) { | 452 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, MAYBE_IsolatedAppProcessModel) { |
453 host_resolver()->AddRule("*", "127.0.0.1"); | 453 host_resolver()->AddRule("*", "127.0.0.1"); |
454 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 454 ASSERT_TRUE(embedded_test_server()->Start()); |
455 | 455 |
456 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 456 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
457 | 457 |
458 // The app under test acts on URLs whose host is "localhost", | 458 // The app under test acts on URLs whose host is "localhost", |
459 // so the URLs we navigate to must have host "localhost". | 459 // so the URLs we navigate to must have host "localhost". |
460 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 460 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
461 GURL::Replacements replace_host; | 461 GURL::Replacements replace_host; |
462 replace_host.SetHostStr("localhost"); | 462 replace_host.SetHostStr("localhost"); |
463 base_url = base_url.ReplaceComponents(replace_host); | 463 base_url = base_url.ReplaceComponents(replace_host); |
464 | 464 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 GetRenderProcessHost()->GetID()); | 501 GetRenderProcessHost()->GetID()); |
502 } | 502 } |
503 | 503 |
504 // This test no longer passes, since we don't properly isolate sessionStorage | 504 // This test no longer passes, since we don't properly isolate sessionStorage |
505 // for isolated apps. This was broken as part of the changes for storage | 505 // for isolated apps. This was broken as part of the changes for storage |
506 // partition support for webview tags. | 506 // partition support for webview tags. |
507 // TODO(nasko): If isolated apps is no longer developed, this test should be | 507 // TODO(nasko): If isolated apps is no longer developed, this test should be |
508 // removed. http://crbug.com/159932 | 508 // removed. http://crbug.com/159932 |
509 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_SessionStorage) { | 509 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, DISABLED_SessionStorage) { |
510 host_resolver()->AddRule("*", "127.0.0.1"); | 510 host_resolver()->AddRule("*", "127.0.0.1"); |
511 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 511 ASSERT_TRUE(embedded_test_server()->Start()); |
512 | 512 |
513 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 513 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
514 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 514 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
515 | 515 |
516 // The app under test acts on URLs whose host is "localhost", | 516 // The app under test acts on URLs whose host is "localhost", |
517 // so the URLs we navigate to must have host "localhost". | 517 // so the URLs we navigate to must have host "localhost". |
518 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); | 518 GURL base_url = embedded_test_server()->GetURL("/extensions/isolated_apps/"); |
519 GURL::Replacements replace_host; | 519 GURL::Replacements replace_host; |
520 replace_host.SetHostStr("localhost"); | 520 replace_host.SetHostStr("localhost"); |
521 base_url = base_url.ReplaceComponents(replace_host); | 521 base_url = base_url.ReplaceComponents(replace_host); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 browser(), base_url.Resolve("non_app/main.html")); | 560 browser(), base_url.Resolve("non_app/main.html")); |
561 ASSERT_TRUE(ExecuteScriptAndExtractString( | 561 ASSERT_TRUE(ExecuteScriptAndExtractString( |
562 browser()->tab_strip_model()->GetWebContentsAt(0), | 562 browser()->tab_strip_model()->GetWebContentsAt(0), |
563 kRetrieveSessionStorage.c_str(), &result)); | 563 kRetrieveSessionStorage.c_str(), &result)); |
564 EXPECT_EQ("ss_normal", result); | 564 EXPECT_EQ("ss_normal", result); |
565 } | 565 } |
566 | 566 |
567 } // namespace | 567 } // namespace |
568 | 568 |
569 } // namespace extensions | 569 } // namespace extensions |
OLD | NEW |