Chromium Code Reviews| 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 EXPECT_TRUE(success); | 52 EXPECT_TRUE(success); |
| 53 | 53 |
| 54 content::DOMMessageQueue msg_queue; | 54 content::DOMMessageQueue msg_queue; |
| 55 std::string status; | 55 std::string status; |
| 56 while (msg_queue.WaitForMessage(&status)) { | 56 while (msg_queue.WaitForMessage(&status)) { |
| 57 if (status == reply_status) | 57 if (status == reply_status) |
| 58 break; | 58 break; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // anonymous namespace | |
| 63 | |
| 64 class RedirectNotificationObserver : public NotificationObserver { | 62 class RedirectNotificationObserver : public NotificationObserver { |
| 65 public: | 63 public: |
| 66 // Register to listen for notifications of the given type from either a | 64 // Register to listen for notifications of the given type from either a |
| 67 // specific source, or from all sources if |source| is | 65 // specific source, or from all sources if |source| is |
| 68 // NotificationService::AllSources(). | 66 // NotificationService::AllSources(). |
| 69 RedirectNotificationObserver(int notification_type, | 67 RedirectNotificationObserver(int notification_type, |
| 70 const NotificationSource& source); | 68 const NotificationSource& source); |
| 71 ~RedirectNotificationObserver() override; | 69 ~RedirectNotificationObserver() override; |
| 72 | 70 |
| 73 // Wait until the specified notification occurs. If the notification was | 71 // Wait until the specified notification occurs. If the notification was |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 DCHECK(source == web_contents_); | 231 DCHECK(source == web_contents_); |
| 234 | 232 |
| 235 std::string ascii_message = base::UTF16ToASCII(message); | 233 std::string ascii_message = base::UTF16ToASCII(message); |
| 236 if (MatchPattern(ascii_message, filter_)) { | 234 if (MatchPattern(ascii_message, filter_)) { |
| 237 message_ = ascii_message; | 235 message_ = ascii_message; |
| 238 message_loop_runner_->Quit(); | 236 message_loop_runner_->Quit(); |
| 239 } | 237 } |
| 240 return false; | 238 return false; |
| 241 } | 239 } |
| 242 | 240 |
| 241 std::string GetCookieFromJS(RenderFrameHost* frame) { | |
| 242 std::string cookie; | |
| 243 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 244 frame, "window.domAutomationController.send(document.cookie);", &cookie)); | |
| 245 return cookie; | |
| 246 } | |
| 247 | |
| 248 } // namespace | |
| 249 | |
| 243 // | 250 // |
| 244 // SitePerProcessBrowserTest | 251 // SitePerProcessBrowserTest |
| 245 // | 252 // |
| 246 | 253 |
| 247 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 254 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
| 248 }; | 255 }; |
| 249 | 256 |
| 250 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 257 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| 251 return visualizer_.DepictFrameTree(node); | 258 return visualizer_.DepictFrameTree(node); |
| 252 } | 259 } |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 | 1061 |
| 1055 // Crash a subframe and ensures its children are cleared from the FrameTree. | 1062 // Crash a subframe and ensures its children are cleared from the FrameTree. |
| 1056 // See http://crbug.com/338508. | 1063 // See http://crbug.com/338508. |
| 1057 // TODO(creis): Disabled for flakiness; see http://crbug.com/405582. | 1064 // TODO(creis): Disabled for flakiness; see http://crbug.com/405582. |
| 1058 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) { | 1065 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) { |
| 1059 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1066 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 1060 NavigateToURL(shell(), main_url); | 1067 NavigateToURL(shell(), main_url); |
| 1061 | 1068 |
| 1062 StartFrameAtDataURL(); | 1069 StartFrameAtDataURL(); |
| 1063 | 1070 |
| 1064 // These must stay in scope with replace_host. | |
| 1065 GURL::Replacements replace_host; | |
| 1066 std::string foo_com("foo.com"); | |
| 1067 | |
| 1068 // Load cross-site page into iframe. | 1071 // Load cross-site page into iframe. |
| 1069 EXPECT_TRUE(NavigateIframeToURL( | 1072 EXPECT_TRUE(NavigateIframeToURL( |
| 1070 shell()->web_contents(), "test", | 1073 shell()->web_contents(), "test", |
| 1071 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"))); | 1074 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"))); |
| 1072 | 1075 |
| 1073 // Check the subframe process. | 1076 // Check the subframe process. |
| 1074 FrameTreeNode* root = | 1077 FrameTreeNode* root = |
| 1075 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1078 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1076 GetFrameTree()->root(); | 1079 GetFrameTree()->root(); |
| 1077 ASSERT_EQ(2U, root->child_count()); | 1080 ASSERT_EQ(2U, root->child_count()); |
| (...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2459 " Site A\n" | 2462 " Site A\n" |
| 2460 " |--Site A\n" | 2463 " |--Site A\n" |
| 2461 " +--Site A\n" | 2464 " +--Site A\n" |
| 2462 " |--Site A\n" | 2465 " |--Site A\n" |
| 2463 " +--Site A\n" | 2466 " +--Site A\n" |
| 2464 " +--Site A\n" | 2467 " +--Site A\n" |
| 2465 "Where A = http://127.0.0.1/", | 2468 "Where A = http://127.0.0.1/", |
| 2466 DepictFrameTree(root)); | 2469 DepictFrameTree(root)); |
| 2467 } | 2470 } |
| 2468 | 2471 |
| 2472 // Exercises | |
|
James Cook
2015/05/22 18:13:10
Exercises?
Also, is this meant to be part of a di
ncarter (slow)
2015/05/22 18:41:52
Oh gosh yes, this doesn't belong here at all. Stal
| |
| 2473 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CookieAccessRestrictions) { | |
| 2474 net::SpawnedTestServer https_server( | |
| 2475 net::SpawnedTestServer::TYPE_HTTPS, net::SpawnedTestServer::kLocalhost, | |
| 2476 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | |
| 2477 ASSERT_TRUE(https_server.Start()); | |
| 2478 | |
| 2479 // The server sends a HttpOnly cookie which should never be seen by any | |
| 2480 // renderer. | |
| 2481 GURL https_url = https_server.GetURL("set-cookie?notforjs=1;HttpOnly"); | |
| 2482 GURL http_url = embedded_test_server()->GetURL("/frame_with_load_event.html"); | |
| 2483 | |
| 2484 Shell* shell2 = CreateBrowser(); | |
| 2485 NavigateToURL(shell(), http_url); | |
| 2486 NavigateToURL(shell2, https_url); | |
| 2487 | |
| 2488 WebContentsImpl* secure_web_contents = | |
| 2489 static_cast<WebContentsImpl*>(shell2->web_contents()); | |
| 2490 WebContentsImpl* insecure_web_contents = | |
| 2491 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 2492 | |
| 2493 EXPECT_EQ("http://127.0.0.1/", | |
| 2494 insecure_web_contents->GetSiteInstance()->GetSiteURL().spec()); | |
| 2495 EXPECT_EQ("https://127.0.0.1/", | |
| 2496 secure_web_contents->GetSiteInstance()->GetSiteURL().spec()); | |
| 2497 | |
| 2498 EXPECT_NE(insecure_web_contents->GetSiteInstance()->GetProcess(), | |
| 2499 secure_web_contents->GetSiteInstance()->GetProcess()); | |
| 2500 | |
| 2501 EXPECT_EQ("", GetCookieFromJS(secure_web_contents->GetMainFrame())); | |
| 2502 EXPECT_EQ("", GetCookieFromJS(insecure_web_contents->GetMainFrame())); | |
| 2503 | |
| 2504 // HTTP page writes secure cookie. | |
| 2505 EXPECT_TRUE(ExecuteScript(insecure_web_contents->GetMainFrame(), | |
| 2506 "document.cookie = 'A=1; secure;';")); | |
| 2507 EXPECT_EQ("A=1", GetCookieFromJS(secure_web_contents->GetMainFrame())); | |
| 2508 EXPECT_EQ("", GetCookieFromJS(insecure_web_contents->GetMainFrame())); | |
| 2509 | |
| 2510 // TLS page writes not-secure cookie. | |
| 2511 EXPECT_TRUE(ExecuteScript(insecure_web_contents->GetMainFrame(), | |
| 2512 "document.cookie = 'B=2';")); | |
| 2513 EXPECT_EQ("A=1; B=2", GetCookieFromJS(secure_web_contents->GetMainFrame())); | |
| 2514 EXPECT_EQ("B=2", GetCookieFromJS(insecure_web_contents->GetMainFrame())); | |
| 2515 | |
| 2516 // HTTP page writes secure cookie. | |
| 2517 EXPECT_TRUE(ExecuteScript(secure_web_contents->GetMainFrame(), | |
| 2518 "document.cookie = 'C=3;secure;';")); | |
| 2519 EXPECT_EQ("A=1; B=2; C=3", | |
| 2520 GetCookieFromJS(secure_web_contents->GetMainFrame())); | |
| 2521 EXPECT_EQ("B=2", GetCookieFromJS(insecure_web_contents->GetMainFrame())); | |
| 2522 | |
| 2523 // TLS doc writes not-secure cookie. | |
| 2524 EXPECT_TRUE(ExecuteScript(secure_web_contents->GetMainFrame(), | |
| 2525 "document.cookie = 'D=4';")); | |
| 2526 EXPECT_EQ("A=1; B=2; C=3; D=4", | |
| 2527 GetCookieFromJS(secure_web_contents->GetMainFrame())); | |
| 2528 EXPECT_EQ("B=2; D=4", GetCookieFromJS(insecure_web_contents->GetMainFrame())); | |
| 2529 | |
| 2530 // The iframe on the http page should get its own process. | |
| 2531 EXPECT_EQ( | |
| 2532 " Site A ------------ proxies for B\n" | |
| 2533 " +--Site B ------- proxies for A\n" | |
| 2534 "Where A = http://127.0.0.1/\n" | |
| 2535 " B = http://baz.com/", | |
| 2536 DepictFrameTree(insecure_web_contents->GetFrameTree()->root())); | |
| 2537 | |
| 2538 RenderFrameHost* evil_iframe = insecure_web_contents->GetFrameTree() | |
| 2539 ->root() | |
| 2540 ->child_at(0) | |
| 2541 ->current_frame_host(); | |
| 2542 | |
| 2543 EXPECT_NE(evil_iframe->GetProcess(), | |
| 2544 insecure_web_contents->GetMainFrame()->GetProcess()); | |
| 2545 EXPECT_NE(evil_iframe->GetProcess(), | |
| 2546 secure_web_contents->GetMainFrame()->GetProcess()); | |
| 2547 | |
| 2548 // Try to get cross-site cookies from the subframe's process and wait for it | |
| 2549 // to be killed. | |
| 2550 std::string response; | |
| 2551 FrameHostMsg_GetCookies illegal_get_cookies( | |
| 2552 evil_iframe->GetRoutingID(), GURL("https://127.0.0.1/"), | |
| 2553 GURL("https://127.0.0.1/"), &response); | |
| 2554 | |
| 2555 RenderProcessHostWatcher baz_killed( | |
| 2556 evil_iframe->GetProcess(), | |
| 2557 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
| 2558 | |
| 2559 IPC::IpcSecurityTestUtil::PwnMessageReceived( | |
| 2560 evil_iframe->GetProcess()->GetChannel(), illegal_get_cookies); | |
| 2561 | |
| 2562 baz_killed.Wait(); | |
| 2563 | |
| 2564 EXPECT_EQ( | |
| 2565 " Site A ------------ proxies for B\n" | |
| 2566 " +--Site B ------- proxies for A\n" | |
| 2567 "Where A = http://127.0.0.1/\n" | |
| 2568 " B = http://baz.com/ (no process)", | |
| 2569 DepictFrameTree(insecure_web_contents->GetFrameTree()->root())); | |
| 2570 | |
| 2571 EXPECT_EQ( | |
| 2572 " Site C\n" | |
| 2573 "Where C = https://127.0.0.1/", | |
| 2574 DepictFrameTree(secure_web_contents->GetFrameTree()->root())); | |
| 2575 | |
| 2576 // Now set a cross-site cookie from the main frame's process and wait for it | |
| 2577 // to be killed. | |
| 2578 RenderProcessHostWatcher secure_localhost_killed( | |
| 2579 insecure_web_contents->GetMainFrame()->GetProcess(), | |
| 2580 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
| 2581 FrameHostMsg_SetCookie illegal_set_cookie( | |
| 2582 insecure_web_contents->GetMainFrame()->GetRoutingID(), | |
| 2583 GURL("https://baz.com/"), GURL("https://baz.com/"), "pwn=ed"); | |
| 2584 IPC::IpcSecurityTestUtil::PwnMessageReceived( | |
| 2585 secure_web_contents->GetMainFrame()->GetProcess()->GetChannel(), | |
| 2586 illegal_set_cookie); | |
| 2587 | |
| 2588 secure_localhost_killed.Wait(); | |
| 2589 | |
| 2590 EXPECT_EQ( | |
| 2591 " Site C\n" | |
| 2592 "Where C = https://127.0.0.1/ (no process)", | |
| 2593 DepictFrameTree(secure_web_contents->GetFrameTree()->root())); | |
| 2594 | |
| 2595 // Now try to . | |
| 2596 | |
| 2597 EXPECT_EQ( | |
| 2598 " Site A\n" | |
| 2599 "Where A = http://127.0.0.1/ (no process)", | |
| 2600 DepictFrameTree(insecure_web_contents->GetFrameTree()->root())); | |
| 2601 } | |
| 2602 | |
| 2469 } // namespace content | 2603 } // namespace content |
| OLD | NEW |