| OLD | NEW |
| 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 Loading... |
| 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 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2620 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2620 new_shell->web_contents(), | 2621 new_shell->web_contents(), |
| 2621 "domAutomationController.send(document.origin)", &origin)); | 2622 "domAutomationController.send(document.origin)", &origin)); |
| 2622 EXPECT_EQ("null", origin); | 2623 EXPECT_EQ("null", origin); |
| 2623 }; | 2624 }; |
| 2624 | 2625 |
| 2625 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); | 2626 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); |
| 2626 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); | 2627 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); |
| 2627 } | 2628 } |
| 2628 | 2629 |
| 2630 // When two frames are same-origin but cross-process, they should behave as if |
| 2631 // they are not same-origin and should not crash. |
| 2632 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 2633 SameOriginFramesInDifferentProcesses) { |
| 2634 StartEmbeddedServer(); |
| 2635 |
| 2636 // Load a page with links that open in a new window. |
| 2637 NavigateToURL(shell(), embedded_test_server()->GetURL( |
| 2638 "a.com", "/click-noreferrer-links.html")); |
| 2639 |
| 2640 // Get the original SiteInstance for later comparison. |
| 2641 scoped_refptr<SiteInstance> orig_site_instance( |
| 2642 shell()->web_contents()->GetSiteInstance()); |
| 2643 EXPECT_NE(nullptr, orig_site_instance.get()); |
| 2644 |
| 2645 // Test clicking a target=foo link. |
| 2646 ShellAddedObserver new_shell_observer; |
| 2647 bool success = false; |
| 2648 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2649 shell()->web_contents(), |
| 2650 "window.domAutomationController.send(clickSameSiteTargetedLink());" |
| 2651 "saveWindowReference();", |
| 2652 &success)); |
| 2653 EXPECT_TRUE(success); |
| 2654 Shell* new_shell = new_shell_observer.GetShell(); |
| 2655 |
| 2656 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 2657 WaitForLoadStop(new_shell->web_contents()); |
| 2658 EXPECT_EQ("/navigate_opener.html", |
| 2659 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 2660 |
| 2661 // Do a cross-site navigation that winds up same-site. The same-site |
| 2662 // navigation to a.com will commit in a different process than the original |
| 2663 // a.com window. |
| 2664 NavigateToURL(new_shell, embedded_test_server()->GetURL( |
| 2665 "b.com", "/cross-site/a.com/title1.html")); |
| 2666 if (AreAllSitesIsolatedForTesting()) { |
| 2667 // In --site-per-process mode, both windows will actually be in the same |
| 2668 // process. |
| 2669 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 2670 new_shell->web_contents()->GetSiteInstance()); |
| 2671 } else { |
| 2672 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 2673 new_shell->web_contents()->GetSiteInstance()); |
| 2674 } |
| 2675 |
| 2676 std::string result; |
| 2677 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2678 shell()->web_contents(), |
| 2679 "window.domAutomationController.send((function() {\n" |
| 2680 " try {\n" |
| 2681 " return getLastOpenedWindowLocation();\n" |
| 2682 " } catch (e) {\n" |
| 2683 " return e.toString();\n" |
| 2684 " }\n" |
| 2685 "})())", |
| 2686 &result)); |
| 2687 if (AreAllSitesIsolatedForTesting()) { |
| 2688 EXPECT_THAT(result, |
| 2689 ::testing::MatchesRegex("http://a.com:\\d+/title1.html")); |
| 2690 } else { |
| 2691 // Accessing a property with normal security checks should throw a |
| 2692 // SecurityError if the same-origin windows are in different processes. |
| 2693 EXPECT_THAT(result, |
| 2694 ::testing::MatchesRegex("SecurityError: Blocked a frame with " |
| 2695 "origin \"http://a.com:\\d+\" from " |
| 2696 "accessing a cross-origin frame.")); |
| 2697 } |
| 2698 } |
| 2699 |
| 2629 } // namespace content | 2700 } // namespace content |
| OLD | NEW |