Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 1887553002: Make sure binding security checks don't pass if the frame is remote. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments / add more comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 6 #include <stdint.h>
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "content/public/test/content_browser_test.h" 45 #include "content/public/test/content_browser_test.h"
46 #include "content/public/test/content_browser_test_utils.h" 46 #include "content/public/test/content_browser_test_utils.h"
47 #include "content/public/test/test_navigation_observer.h" 47 #include "content/public/test/test_navigation_observer.h"
48 #include "content/public/test/test_utils.h" 48 #include "content/public/test/test_utils.h"
49 #include "content/shell/browser/shell.h" 49 #include "content/shell/browser/shell.h"
50 #include "content/test/content_browser_test_utils_internal.h" 50 #include "content/test/content_browser_test_utils_internal.h"
51 #include "content/test/test_frame_navigation_observer.h" 51 #include "content/test/test_frame_navigation_observer.h"
52 #include "net/dns/mock_host_resolver.h" 52 #include "net/dns/mock_host_resolver.h"
53 #include "net/test/embedded_test_server/embedded_test_server.h" 53 #include "net/test/embedded_test_server/embedded_test_server.h"
54 #include "net/test/embedded_test_server/request_handler_util.h" 54 #include "net/test/embedded_test_server/request_handler_util.h"
55 #include "testing/gmock/include/gmock/gmock-matchers.h"
55 56
56 using base::ASCIIToUTF16; 57 using base::ASCIIToUTF16;
57 58
58 namespace content { 59 namespace content {
59 60
60 namespace { 61 namespace {
61 62
62 const char kOpenUrlViaClickTargetFunc[] = 63 const char kOpenUrlViaClickTargetFunc[] =
63 "(function(url) {\n" 64 "(function(url) {\n"
64 " var lnk = document.createElement(\"a\");\n" 65 " var lnk = document.createElement(\"a\");\n"
(...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 EXPECT_TRUE(ExecuteScriptAndExtractString( 2611 EXPECT_TRUE(ExecuteScriptAndExtractString(
2611 new_shell->web_contents(), 2612 new_shell->web_contents(),
2612 "domAutomationController.send(document.origin)", &origin)); 2613 "domAutomationController.send(document.origin)", &origin));
2613 EXPECT_EQ("null", origin); 2614 EXPECT_EQ("null", origin);
2614 }; 2615 };
2615 2616
2616 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); 2617 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()");
2617 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); 2618 click_link_and_verify_popup("clickNoRefTargetBlankLink()");
2618 } 2619 }
2619 2620
2621
2622 // When two frames are same-origin but cross-process, they should behave as if
2623 // they are not same-origin and should not crash.
2624 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
2625 SameOriginFramesInDifferentProcesses) {
2626 StartEmbeddedServer();
2627
2628 // Load a page with links that open in a new window.
2629 NavigateToURL(shell(), embedded_test_server()->GetURL(
2630 "a.com", "/click-noreferrer-links.html"));
2631
2632 // Get the original SiteInstance for later comparison.
2633 scoped_refptr<SiteInstance> orig_site_instance(
2634 shell()->web_contents()->GetSiteInstance());
2635 EXPECT_NE(nullptr, orig_site_instance.get());
2636
2637 // Test clicking a target=foo link.
2638 ShellAddedObserver new_shell_observer;
2639 bool success = false;
2640 EXPECT_TRUE(ExecuteScriptAndExtractBool(
2641 shell()->web_contents(),
2642 "window.domAutomationController.send(clickSameSiteTargetedLink());"
2643 "saveWindowReference();",
2644 &success));
2645 EXPECT_TRUE(success);
2646 Shell* new_shell = new_shell_observer.GetShell();
2647
2648 // Wait for the navigation in the new tab to finish, if it hasn't.
2649 WaitForLoadStop(new_shell->web_contents());
2650 EXPECT_EQ("/navigate_opener.html",
2651 new_shell->web_contents()->GetLastCommittedURL().path());
2652
2653 // Do a cross-site navigation that winds up same-site. The same-site
2654 // navigation to a.com will commit in a different process than the original
2655 // a.com window.
2656 NavigateToURL(new_shell, embedded_test_server()->GetURL(
2657 "b.com", "/cross-site/a.com/title1.html"));
2658 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
2659 new_shell->web_contents()->GetSiteInstance());
2660
2661 // Accessing a property with normal security checks should throw a
2662 // SecurityError.
2663 std::string result;
2664 EXPECT_TRUE(ExecuteScriptAndExtractString(
2665 shell()->web_contents(),
2666 "window.domAutomationController.send((function() {\n"
2667 " try {\n"
2668 " getLastOpenedWindowLocation();\n"
2669 " } catch (e) {\n"
2670 " return e.toString();\n"
2671 " }\n"
2672 "})())",
2673 &result));
2674 EXPECT_THAT(result,
2675 ::testing::MatchesRegex("SecurityError: Blocked a frame with "
2676 "origin \"http://a.com:\\d+\" from "
2677 "accessing a cross-origin frame."));
Charlie Reis 2016/04/13 16:45:56 Note: We won't get the security error in --site-pe
dcheng 2016/04/13 17:13:01 Done.
2678 }
2679
2620 } // namespace content 2680 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698