| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "content/public/test/browser_test_utils.h" | 44 #include "content/public/test/browser_test_utils.h" |
| 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 "net/dns/mock_host_resolver.h" | 51 #include "net/dns/mock_host_resolver.h" |
| 52 #include "net/test/embedded_test_server/embedded_test_server.h" | 52 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 53 #include "net/test/embedded_test_server/request_handler_util.h" | 53 #include "net/test/embedded_test_server/request_handler_util.h" |
| 54 #include "testing/gmock/include/gmock/gmock-matchers.h" |
| 54 | 55 |
| 55 using base::ASCIIToUTF16; | 56 using base::ASCIIToUTF16; |
| 56 | 57 |
| 57 namespace content { | 58 namespace content { |
| 58 | 59 |
| 59 namespace { | 60 namespace { |
| 60 | 61 |
| 61 const char kOpenUrlViaClickTargetFunc[] = | 62 const char kOpenUrlViaClickTargetFunc[] = |
| 62 "(function(url) {\n" | 63 "(function(url) {\n" |
| 63 " var lnk = document.createElement(\"a\");\n" | 64 " var lnk = document.createElement(\"a\");\n" |
| (...skipping 2478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2542 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2543 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2543 new_shell->web_contents(), | 2544 new_shell->web_contents(), |
| 2544 "domAutomationController.send(document.origin)", &origin)); | 2545 "domAutomationController.send(document.origin)", &origin)); |
| 2545 EXPECT_EQ("null", origin); | 2546 EXPECT_EQ("null", origin); |
| 2546 }; | 2547 }; |
| 2547 | 2548 |
| 2548 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); | 2549 click_link_and_verify_popup("clickNoOpenerTargetBlankLink()"); |
| 2549 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); | 2550 click_link_and_verify_popup("clickNoRefTargetBlankLink()"); |
| 2550 } | 2551 } |
| 2551 | 2552 |
| 2553 // When two frames are same-origin but cross-process, they should behave as if |
| 2554 // they are not same-origin and should not crash. |
| 2555 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 2556 SameOriginFramesInDifferentProcesses) { |
| 2557 StartEmbeddedServer(); |
| 2558 |
| 2559 // Load a page with links that open in a new window. |
| 2560 NavigateToURL(shell(), embedded_test_server()->GetURL( |
| 2561 "a.com", "/click-noreferrer-links.html")); |
| 2562 |
| 2563 // Get the original SiteInstance for later comparison. |
| 2564 scoped_refptr<SiteInstance> orig_site_instance( |
| 2565 shell()->web_contents()->GetSiteInstance()); |
| 2566 EXPECT_NE(nullptr, orig_site_instance.get()); |
| 2567 |
| 2568 // Test clicking a target=foo link. |
| 2569 ShellAddedObserver new_shell_observer; |
| 2570 bool success = false; |
| 2571 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2572 shell()->web_contents(), |
| 2573 "window.domAutomationController.send(clickSameSiteTargetedLink());" |
| 2574 "saveWindowReference();", |
| 2575 &success)); |
| 2576 EXPECT_TRUE(success); |
| 2577 Shell* new_shell = new_shell_observer.GetShell(); |
| 2578 |
| 2579 // Wait for the navigation in the new tab to finish, if it hasn't. |
| 2580 WaitForLoadStop(new_shell->web_contents()); |
| 2581 EXPECT_EQ("/navigate_opener.html", |
| 2582 new_shell->web_contents()->GetLastCommittedURL().path()); |
| 2583 |
| 2584 // Do a cross-site navigation that winds up same-site. The same-site |
| 2585 // navigation to a.com will commit in a different process than the original |
| 2586 // a.com window. |
| 2587 NavigateToURL(new_shell, embedded_test_server()->GetURL( |
| 2588 "b.com", "/cross-site/a.com/title1.html")); |
| 2589 if (AreAllSitesIsolatedForTesting()) { |
| 2590 // In --site-per-process mode, both windows will actually be in the same |
| 2591 // process. |
| 2592 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 2593 new_shell->web_contents()->GetSiteInstance()); |
| 2594 } else { |
| 2595 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 2596 new_shell->web_contents()->GetSiteInstance()); |
| 2597 } |
| 2598 |
| 2599 std::string result; |
| 2600 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2601 shell()->web_contents(), |
| 2602 "window.domAutomationController.send((function() {\n" |
| 2603 " try {\n" |
| 2604 " return getLastOpenedWindowLocation();\n" |
| 2605 " } catch (e) {\n" |
| 2606 " return e.toString();\n" |
| 2607 " }\n" |
| 2608 "})())", |
| 2609 &result)); |
| 2610 if (AreAllSitesIsolatedForTesting()) { |
| 2611 EXPECT_THAT(result, |
| 2612 ::testing::MatchesRegex("http://a.com:\\d+/title1.html")); |
| 2613 } else { |
| 2614 // Accessing a property with normal security checks should throw a |
| 2615 // SecurityError if the same-origin windows are in different processes. |
| 2616 EXPECT_THAT(result, |
| 2617 ::testing::MatchesRegex("SecurityError: Blocked a frame with " |
| 2618 "origin \"http://a.com:\\d+\" from " |
| 2619 "accessing a cross-origin frame.")); |
| 2620 } |
| 2621 } |
| 2622 |
| 2552 } // namespace content | 2623 } // namespace content |
| OLD | NEW |