| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "content/public/browser/navigation_handle.h" | 44 #include "content/public/browser/navigation_handle.h" |
| 45 #include "content/public/browser/notification_observer.h" | 45 #include "content/public/browser/notification_observer.h" |
| 46 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
| 47 #include "content/public/browser/notification_types.h" | 47 #include "content/public/browser/notification_types.h" |
| 48 #include "content/public/browser/resource_dispatcher_host.h" | 48 #include "content/public/browser/resource_dispatcher_host.h" |
| 49 #include "content/public/common/browser_side_navigation_policy.h" | 49 #include "content/public/common/browser_side_navigation_policy.h" |
| 50 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
| 51 #include "content/public/common/url_constants.h" | 51 #include "content/public/common/url_constants.h" |
| 52 #include "content/public/test/browser_test_utils.h" | 52 #include "content/public/test/browser_test_utils.h" |
| 53 #include "content/public/test/content_browser_test_utils.h" | 53 #include "content/public/test/content_browser_test_utils.h" |
| 54 #include "content/public/test/test_frame_navigation_observer.h" |
| 54 #include "content/public/test/test_navigation_observer.h" | 55 #include "content/public/test/test_navigation_observer.h" |
| 55 #include "content/public/test/test_utils.h" | 56 #include "content/public/test/test_utils.h" |
| 56 #include "content/test/content_browser_test_utils_internal.h" | 57 #include "content/test/content_browser_test_utils_internal.h" |
| 57 #include "content/test/test_frame_navigation_observer.h" | |
| 58 #include "ipc/ipc.mojom.h" | 58 #include "ipc/ipc.mojom.h" |
| 59 #include "ipc/ipc_security_test_util.h" | 59 #include "ipc/ipc_security_test_util.h" |
| 60 #include "net/dns/mock_host_resolver.h" | 60 #include "net/dns/mock_host_resolver.h" |
| 61 #include "net/test/embedded_test_server/embedded_test_server.h" | 61 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 62 #include "testing/gtest/include/gtest/gtest.h" | 62 #include "testing/gtest/include/gtest/gtest.h" |
| 63 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" | 63 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" |
| 64 #include "third_party/WebKit/public/web/WebInputEvent.h" | 64 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 65 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 65 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 66 #include "ui/display/display_switches.h" | 66 #include "ui/display/display_switches.h" |
| 67 #include "ui/display/screen.h" | 67 #include "ui/display/screen.h" |
| (...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 "Where A = http://a.com/\n" | 1917 "Where A = http://a.com/\n" |
| 1918 " D = http://f00.com/", | 1918 " D = http://f00.com/", |
| 1919 DepictFrameTree(root)); | 1919 DepictFrameTree(root)); |
| 1920 | 1920 |
| 1921 // Navigate the iframe itself to about:blank using a script executing in its | 1921 // Navigate the iframe itself to about:blank using a script executing in its |
| 1922 // own context. It should stay in the same SiteInstance as before, not the | 1922 // own context. It should stay in the same SiteInstance as before, not the |
| 1923 // parent one. | 1923 // parent one. |
| 1924 std::string script( | 1924 std::string script( |
| 1925 "window.domAutomationController.send(" | 1925 "window.domAutomationController.send(" |
| 1926 "window.location.href = 'about:blank');"); | 1926 "window.location.href = 'about:blank');"); |
| 1927 TestFrameNavigationObserver frame_observer(child); | 1927 TestFrameNavigationObserver frame_observer(child->current_frame_host()); |
| 1928 EXPECT_TRUE(ExecuteScript(child, script)); | 1928 EXPECT_TRUE(ExecuteScript(child, script)); |
| 1929 frame_observer.Wait(); | 1929 frame_observer.Wait(); |
| 1930 EXPECT_EQ(about_blank_url, child->current_url()); | 1930 EXPECT_EQ(about_blank_url, child->current_url()); |
| 1931 | 1931 |
| 1932 // Ensure that we have navigated using the top level process. | 1932 // Ensure that we have navigated using the top level process. |
| 1933 EXPECT_EQ( | 1933 EXPECT_EQ( |
| 1934 " Site A ------------ proxies for D\n" | 1934 " Site A ------------ proxies for D\n" |
| 1935 " |--Site D ------- proxies for A\n" | 1935 " |--Site D ------- proxies for A\n" |
| 1936 " +--Site A ------- proxies for D\n" | 1936 " +--Site A ------- proxies for D\n" |
| 1937 " +--Site A -- proxies for D\n" | 1937 " +--Site A -- proxies for D\n" |
| (...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2887 // proxies to have been created in the frame tree, but children of the | 2887 // proxies to have been created in the frame tree, but children of the |
| 2888 // navigating frame to still be present. The reason is that we don't run the | 2888 // navigating frame to still be present. The reason is that we don't run the |
| 2889 // message loop, so no IPCs that alter the frame tree can be processed. | 2889 // message loop, so no IPCs that alter the frame tree can be processed. |
| 2890 FrameTreeNode* child = root->child_at(1); | 2890 FrameTreeNode* child = root->child_at(1); |
| 2891 SiteInstance* site = NULL; | 2891 SiteInstance* site = NULL; |
| 2892 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); | 2892 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); |
| 2893 std::string cross_site_rfh_type = | 2893 std::string cross_site_rfh_type = |
| 2894 browser_side_navigation ? "speculative" : "pending"; | 2894 browser_side_navigation ? "speculative" : "pending"; |
| 2895 { | 2895 { |
| 2896 TestNavigationObserver observer(shell()->web_contents()); | 2896 TestNavigationObserver observer(shell()->web_contents()); |
| 2897 TestFrameNavigationObserver navigation_observer(child); | 2897 TestFrameNavigationObserver navigation_observer( |
| 2898 child->current_frame_host()); |
| 2898 NavigationController::LoadURLParams params(cross_site_url); | 2899 NavigationController::LoadURLParams params(cross_site_url); |
| 2899 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 2900 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
| 2900 params.frame_tree_node_id = child->frame_tree_node_id(); | 2901 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 2901 child->navigator()->GetController()->LoadURLWithParams(params); | 2902 child->navigator()->GetController()->LoadURLWithParams(params); |
| 2902 | 2903 |
| 2903 if (browser_side_navigation) { | 2904 if (browser_side_navigation) { |
| 2904 site = child->render_manager() | 2905 site = child->render_manager() |
| 2905 ->speculative_frame_host() | 2906 ->speculative_frame_host() |
| 2906 ->GetSiteInstance(); | 2907 ->GetSiteInstance(); |
| 2907 } else { | 2908 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2940 // Load another cross-site page into the same iframe. | 2941 // Load another cross-site page into the same iframe. |
| 2941 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title3.html"); | 2942 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 2942 { | 2943 { |
| 2943 // Perform the same checks as the first cross-site navigation, since | 2944 // Perform the same checks as the first cross-site navigation, since |
| 2944 // there have been issues in subsequent cross-site navigations. Also ensure | 2945 // there have been issues in subsequent cross-site navigations. Also ensure |
| 2945 // that the SiteInstance has properly changed. | 2946 // that the SiteInstance has properly changed. |
| 2946 // TODO(nasko): Once we have proper cleanup of resources, add code to | 2947 // TODO(nasko): Once we have proper cleanup of resources, add code to |
| 2947 // verify that the intermediate SiteInstance/RenderFrameHost have been | 2948 // verify that the intermediate SiteInstance/RenderFrameHost have been |
| 2948 // properly cleaned up. | 2949 // properly cleaned up. |
| 2949 TestNavigationObserver observer(shell()->web_contents()); | 2950 TestNavigationObserver observer(shell()->web_contents()); |
| 2950 TestFrameNavigationObserver navigation_observer(child); | 2951 TestFrameNavigationObserver navigation_observer( |
| 2952 child->current_frame_host()); |
| 2951 NavigationController::LoadURLParams params(cross_site_url); | 2953 NavigationController::LoadURLParams params(cross_site_url); |
| 2952 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 2954 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
| 2953 params.frame_tree_node_id = child->frame_tree_node_id(); | 2955 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 2954 child->navigator()->GetController()->LoadURLWithParams(params); | 2956 child->navigator()->GetController()->LoadURLWithParams(params); |
| 2955 | 2957 |
| 2956 SiteInstance* site2; | 2958 SiteInstance* site2; |
| 2957 if (browser_side_navigation) { | 2959 if (browser_side_navigation) { |
| 2958 site2 = child->render_manager() | 2960 site2 = child->render_manager() |
| 2959 ->speculative_frame_host() | 2961 ->speculative_frame_host() |
| 2960 ->GetSiteInstance(); | 2962 ->GetSiteInstance(); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3614 // per blink::parseSandboxPolicy(). | 3616 // per blink::parseSandboxPolicy(). |
| 3615 blink::WebSandboxFlags expected_flags = | 3617 blink::WebSandboxFlags expected_flags = |
| 3616 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 3618 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 3617 ~blink::WebSandboxFlags::AutomaticFeatures; | 3619 ~blink::WebSandboxFlags::AutomaticFeatures; |
| 3618 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3620 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3619 EXPECT_EQ(blink::WebSandboxFlags::None, | 3621 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3620 root->child_at(0)->effective_sandbox_flags()); | 3622 root->child_at(0)->effective_sandbox_flags()); |
| 3621 | 3623 |
| 3622 // Perform a renderer-initiated same-site navigation in the first frame. The | 3624 // Perform a renderer-initiated same-site navigation in the first frame. The |
| 3623 // new sandbox flags should take effect. | 3625 // new sandbox flags should take effect. |
| 3624 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 3626 TestFrameNavigationObserver frame_observer( |
| 3627 root->child_at(0)->current_frame_host()); |
| 3625 ASSERT_TRUE( | 3628 ASSERT_TRUE( |
| 3626 ExecuteScript(root->child_at(0), "window.location.href='/title2.html'")); | 3629 ExecuteScript(root->child_at(0), "window.location.href='/title2.html'")); |
| 3627 frame_observer.Wait(); | 3630 frame_observer.Wait(); |
| 3628 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title2.html"), | 3631 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title2.html"), |
| 3629 root->child_at(0)->current_url()); | 3632 root->child_at(0)->current_url()); |
| 3630 | 3633 |
| 3631 // Confirm that the browser process has updated the frame's current sandbox | 3634 // Confirm that the browser process has updated the frame's current sandbox |
| 3632 // flags. | 3635 // flags. |
| 3633 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3636 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3634 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 3637 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3681 // the new sandboxed local frame, its child (while it's still local), and a | 3684 // the new sandboxed local frame, its child (while it's still local), and a |
| 3682 // pending RFH when starting the cross-site navigation to baz.com. | 3685 // pending RFH when starting the cross-site navigation to baz.com. |
| 3683 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); | 3686 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); |
| 3684 EXPECT_TRUE(ExecuteScript(root, | 3687 EXPECT_TRUE(ExecuteScript(root, |
| 3685 "addFrame('/frame_tree/page_with_one_frame.html'," | 3688 "addFrame('/frame_tree/page_with_one_frame.html'," |
| 3686 " 'allow-scripts allow-same-origin'))")); | 3689 " 'allow-scripts allow-same-origin'))")); |
| 3687 frame_observer.Wait(); | 3690 frame_observer.Wait(); |
| 3688 | 3691 |
| 3689 // Wait for the cross-site navigation to baz.com in the grandchild to finish. | 3692 // Wait for the cross-site navigation to baz.com in the grandchild to finish. |
| 3690 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); | 3693 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); |
| 3691 TestFrameNavigationObserver navigation_observer(bottom_child); | 3694 TestFrameNavigationObserver navigation_observer( |
| 3695 bottom_child->current_frame_host()); |
| 3692 navigation_observer.Wait(); | 3696 navigation_observer.Wait(); |
| 3693 | 3697 |
| 3694 EXPECT_EQ( | 3698 EXPECT_EQ( |
| 3695 " Site A ------------ proxies for B\n" | 3699 " Site A ------------ proxies for B\n" |
| 3696 " |--Site B ------- proxies for A\n" | 3700 " |--Site B ------- proxies for A\n" |
| 3697 " +--Site A ------- proxies for B\n" | 3701 " +--Site A ------- proxies for B\n" |
| 3698 " +--Site B -- proxies for A\n" | 3702 " +--Site B -- proxies for A\n" |
| 3699 "Where A = http://127.0.0.1/\n" | 3703 "Where A = http://127.0.0.1/\n" |
| 3700 " B = http://baz.com/", | 3704 " B = http://baz.com/", |
| 3701 DepictFrameTree(root)); | 3705 DepictFrameTree(root)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3804 " frames['updated-name'] == frames[0]);", | 3808 " frames['updated-name'] == frames[0]);", |
| 3805 &success)); | 3809 &success)); |
| 3806 EXPECT_TRUE(success); | 3810 EXPECT_TRUE(success); |
| 3807 | 3811 |
| 3808 // Issue a renderer-initiated navigation from the root frame to the child | 3812 // Issue a renderer-initiated navigation from the root frame to the child |
| 3809 // frame using the frame's name. Make sure correct frame is navigated. | 3813 // frame using the frame's name. Make sure correct frame is navigated. |
| 3810 // | 3814 // |
| 3811 // TODO(alexmos): When blink::createWindow is refactored to handle | 3815 // TODO(alexmos): When blink::createWindow is refactored to handle |
| 3812 // RemoteFrames, this should also be tested via window.open(url, frame_name) | 3816 // RemoteFrames, this should also be tested via window.open(url, frame_name) |
| 3813 // and a more complicated frame hierarchy (https://crbug.com/463742) | 3817 // and a more complicated frame hierarchy (https://crbug.com/463742) |
| 3814 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 3818 TestFrameNavigationObserver frame_observer( |
| 3819 root->child_at(0)->current_frame_host()); |
| 3815 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | 3820 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 3816 EXPECT_TRUE(ExecuteScript( | 3821 EXPECT_TRUE(ExecuteScript( |
| 3817 shell(), | 3822 shell(), |
| 3818 base::StringPrintf("frames['updated-name'].location.href = '%s';", | 3823 base::StringPrintf("frames['updated-name'].location.href = '%s';", |
| 3819 foo_url.spec().c_str()))); | 3824 foo_url.spec().c_str()))); |
| 3820 frame_observer.Wait(); | 3825 frame_observer.Wait(); |
| 3821 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); | 3826 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); |
| 3822 } | 3827 } |
| 3823 | 3828 |
| 3824 // Verify that when a frame is navigated to a new origin, the origin update | 3829 // Verify that when a frame is navigated to a new origin, the origin update |
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4822 // Install a BrowserMessageFilter to drop SwapOut ACK messages in A's | 4827 // Install a BrowserMessageFilter to drop SwapOut ACK messages in A's |
| 4823 // process. | 4828 // process. |
| 4824 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); | 4829 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); |
| 4825 rfh->GetProcess()->AddFilter(filter.get()); | 4830 rfh->GetProcess()->AddFilter(filter.get()); |
| 4826 rfh->DisableSwapOutTimerForTesting(); | 4831 rfh->DisableSwapOutTimerForTesting(); |
| 4827 | 4832 |
| 4828 // Navigate to B. This must wait for DidCommitProvisionalLoad and not | 4833 // Navigate to B. This must wait for DidCommitProvisionalLoad and not |
| 4829 // DidStopLoading, so that the SwapOut timer doesn't call OnSwappedOut and | 4834 // DidStopLoading, so that the SwapOut timer doesn't call OnSwappedOut and |
| 4830 // destroy |rfh| and |rvh| before they are checked in the test. | 4835 // destroy |rfh| and |rvh| before they are checked in the test. |
| 4831 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 4836 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 4832 TestFrameNavigationObserver commit_observer(root); | 4837 TestFrameNavigationObserver commit_observer(root->current_frame_host()); |
| 4833 shell()->LoadURL(b_url); | 4838 shell()->LoadURL(b_url); |
| 4834 commit_observer.WaitForCommit(); | 4839 commit_observer.WaitForCommit(); |
| 4835 EXPECT_FALSE(deleted_observer.deleted()); | 4840 EXPECT_FALSE(deleted_observer.deleted()); |
| 4836 | 4841 |
| 4837 // Since the SwapOut ACK for A->B is dropped, the first page's | 4842 // Since the SwapOut ACK for A->B is dropped, the first page's |
| 4838 // RenderFrameHost should be pending deletion after the last navigation. | 4843 // RenderFrameHost should be pending deletion after the last navigation. |
| 4839 EXPECT_FALSE(rfh->is_active()); | 4844 EXPECT_FALSE(rfh->is_active()); |
| 4840 | 4845 |
| 4841 // Wait for process A to exit so we can reinitialize it cleanly for the next | 4846 // Wait for process A to exit so we can reinitialize it cleanly for the next |
| 4842 // navigation. Since process A doesn't have any active views, it will | 4847 // navigation. Since process A doesn't have any active views, it will |
| (...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6441 EXPECT_EQ(blink::WebSandboxFlags::None, child->effective_sandbox_flags()); | 6446 EXPECT_EQ(blink::WebSandboxFlags::None, child->effective_sandbox_flags()); |
| 6442 | 6447 |
| 6443 // Add a new grandchild frame and navigate it cross-site. | 6448 // Add a new grandchild frame and navigate it cross-site. |
| 6444 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); | 6449 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); |
| 6445 EXPECT_TRUE(ExecuteScript( | 6450 EXPECT_TRUE(ExecuteScript( |
| 6446 child, "document.body.appendChild(document.createElement('iframe'));")); | 6451 child, "document.body.appendChild(document.createElement('iframe'));")); |
| 6447 frame_observer.Wait(); | 6452 frame_observer.Wait(); |
| 6448 | 6453 |
| 6449 FrameTreeNode* grandchild = child->child_at(0); | 6454 FrameTreeNode* grandchild = child->child_at(0); |
| 6450 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6455 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6451 TestFrameNavigationObserver navigation_observer(grandchild); | 6456 TestFrameNavigationObserver navigation_observer( |
| 6457 grandchild->current_frame_host()); |
| 6452 NavigateFrameToURL(grandchild, frame_url); | 6458 NavigateFrameToURL(grandchild, frame_url); |
| 6453 navigation_observer.Wait(); | 6459 navigation_observer.Wait(); |
| 6454 | 6460 |
| 6455 // Since the update flags haven't yet taken effect in its parent, this | 6461 // Since the update flags haven't yet taken effect in its parent, this |
| 6456 // grandchild frame should not be sandboxed. | 6462 // grandchild frame should not be sandboxed. |
| 6457 EXPECT_EQ(blink::WebSandboxFlags::None, grandchild->pending_sandbox_flags()); | 6463 EXPECT_EQ(blink::WebSandboxFlags::None, grandchild->pending_sandbox_flags()); |
| 6458 EXPECT_EQ(blink::WebSandboxFlags::None, | 6464 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 6459 grandchild->effective_sandbox_flags()); | 6465 grandchild->effective_sandbox_flags()); |
| 6460 | 6466 |
| 6461 // Check that the grandchild frame isn't sandboxed on the renderer side. If | 6467 // Check that the grandchild frame isn't sandboxed on the renderer side. If |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6484 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per | 6490 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per |
| 6485 // blink::parseSandboxPolicy(). | 6491 // blink::parseSandboxPolicy(). |
| 6486 blink::WebSandboxFlags expected_flags = | 6492 blink::WebSandboxFlags expected_flags = |
| 6487 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 6493 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 6488 ~blink::WebSandboxFlags::AutomaticFeatures & | 6494 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 6489 ~blink::WebSandboxFlags::Popups; | 6495 ~blink::WebSandboxFlags::Popups; |
| 6490 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 6496 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 6491 | 6497 |
| 6492 // Navigate child frame cross-site. The sandbox flags should take effect. | 6498 // Navigate child frame cross-site. The sandbox flags should take effect. |
| 6493 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6499 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6494 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 6500 TestFrameNavigationObserver frame_observer( |
| 6501 root->child_at(0)->current_frame_host()); |
| 6495 NavigateFrameToURL(root->child_at(0), frame_url); | 6502 NavigateFrameToURL(root->child_at(0), frame_url); |
| 6496 frame_observer.Wait(); | 6503 frame_observer.Wait(); |
| 6497 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 6504 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 6498 | 6505 |
| 6499 // Verify that they've also taken effect on the renderer side. The sandboxed | 6506 // Verify that they've also taken effect on the renderer side. The sandboxed |
| 6500 // frame's origin should be unique. | 6507 // frame's origin should be unique. |
| 6501 EXPECT_EQ("null", GetDocumentOrigin(root->child_at(0))); | 6508 EXPECT_EQ("null", GetDocumentOrigin(root->child_at(0))); |
| 6502 | 6509 |
| 6503 // Open a popup named "foo" from the sandboxed child frame. | 6510 // Open a popup named "foo" from the sandboxed child frame. |
| 6504 Shell* foo_shell = | 6511 Shell* foo_shell = |
| 6505 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), "foo"); | 6512 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), "foo"); |
| 6506 EXPECT_TRUE(foo_shell); | 6513 EXPECT_TRUE(foo_shell); |
| 6507 | 6514 |
| 6508 FrameTreeNode* foo_root = | 6515 FrameTreeNode* foo_root = |
| 6509 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 6516 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 6510 ->GetFrameTree() | 6517 ->GetFrameTree() |
| 6511 ->root(); | 6518 ->root(); |
| 6512 | 6519 |
| 6513 // Check that the sandbox flags for new popup are correct in the browser | 6520 // Check that the sandbox flags for new popup are correct in the browser |
| 6514 // process. | 6521 // process. |
| 6515 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); | 6522 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); |
| 6516 | 6523 |
| 6517 // The popup's origin should be unique, since it's sandboxed. | 6524 // The popup's origin should be unique, since it's sandboxed. |
| 6518 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); | 6525 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); |
| 6519 | 6526 |
| 6520 // Navigate the popup cross-site. This should keep the unique origin and the | 6527 // Navigate the popup cross-site. This should keep the unique origin and the |
| 6521 // inherited sandbox flags. | 6528 // inherited sandbox flags. |
| 6522 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 6529 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6523 TestFrameNavigationObserver popup_observer(foo_root); | 6530 TestFrameNavigationObserver popup_observer(foo_root->current_frame_host()); |
| 6524 EXPECT_TRUE( | 6531 EXPECT_TRUE( |
| 6525 ExecuteScript(foo_root, "location.href = '" + c_url.spec() + "';")); | 6532 ExecuteScript(foo_root, "location.href = '" + c_url.spec() + "';")); |
| 6526 popup_observer.Wait(); | 6533 popup_observer.Wait(); |
| 6527 EXPECT_EQ(c_url, foo_shell->web_contents()->GetLastCommittedURL()); | 6534 EXPECT_EQ(c_url, foo_shell->web_contents()->GetLastCommittedURL()); |
| 6528 | 6535 |
| 6529 // Confirm that the popup is still sandboxed, both on browser and renderer | 6536 // Confirm that the popup is still sandboxed, both on browser and renderer |
| 6530 // sides. | 6537 // sides. |
| 6531 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); | 6538 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); |
| 6532 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); | 6539 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); |
| 6533 } | 6540 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6556 // per blink::parseSandboxPolicy(). | 6563 // per blink::parseSandboxPolicy(). |
| 6557 blink::WebSandboxFlags expected_flags = | 6564 blink::WebSandboxFlags expected_flags = |
| 6558 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 6565 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 6559 ~blink::WebSandboxFlags::AutomaticFeatures & | 6566 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 6560 ~blink::WebSandboxFlags::Popups & | 6567 ~blink::WebSandboxFlags::Popups & |
| 6561 ~blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; | 6568 ~blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; |
| 6562 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 6569 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 6563 | 6570 |
| 6564 // Navigate child frame cross-site. The sandbox flags should take effect. | 6571 // Navigate child frame cross-site. The sandbox flags should take effect. |
| 6565 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6572 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6566 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 6573 TestFrameNavigationObserver frame_observer( |
| 6574 root->child_at(0)->current_frame_host()); |
| 6567 NavigateFrameToURL(root->child_at(0), frame_url); | 6575 NavigateFrameToURL(root->child_at(0), frame_url); |
| 6568 frame_observer.Wait(); | 6576 frame_observer.Wait(); |
| 6569 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 6577 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 6570 | 6578 |
| 6571 // Open a cross-site popup named "foo" from the child frame. | 6579 // Open a cross-site popup named "foo" from the child frame. |
| 6572 GURL b_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 6580 GURL b_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6573 Shell* foo_shell = OpenPopup(root->child_at(0), b_url, "foo"); | 6581 Shell* foo_shell = OpenPopup(root->child_at(0), b_url, "foo"); |
| 6574 EXPECT_TRUE(foo_shell); | 6582 EXPECT_TRUE(foo_shell); |
| 6575 | 6583 |
| 6576 FrameTreeNode* foo_root = | 6584 FrameTreeNode* foo_root = |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7136 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 7144 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 7137 std::string script = base::StringPrintf( | 7145 std::string script = base::StringPrintf( |
| 7138 "window.domAutomationController.send(" | 7146 "window.domAutomationController.send(" |
| 7139 "parent.location = '%s');", | 7147 "parent.location = '%s');", |
| 7140 b_url.spec().c_str()); | 7148 b_url.spec().c_str()); |
| 7141 | 7149 |
| 7142 // Ensure the child has received a user gesture, so that it has permission | 7150 // Ensure the child has received a user gesture, so that it has permission |
| 7143 // to framebust. | 7151 // to framebust. |
| 7144 SimulateMouseClick( | 7152 SimulateMouseClick( |
| 7145 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); | 7153 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
| 7146 TestFrameNavigationObserver frame_observer(root); | 7154 TestFrameNavigationObserver frame_observer(root->current_frame_host()); |
| 7147 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); | 7155 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 7148 frame_observer.Wait(); | 7156 frame_observer.Wait(); |
| 7149 EXPECT_EQ(b_url, root->current_url()); | 7157 EXPECT_EQ(b_url, root->current_url()); |
| 7150 | 7158 |
| 7151 // Verify that the same RenderViewHost is preserved and that it is no longer | 7159 // Verify that the same RenderViewHost is preserved and that it is no longer |
| 7152 // in swapped out state. | 7160 // in swapped out state. |
| 7153 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( | 7161 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( |
| 7154 root->current_frame_host()->GetSiteInstance())); | 7162 root->current_frame_host()->GetSiteInstance())); |
| 7155 EXPECT_FALSE(rvh->is_swapped_out_); | 7163 EXPECT_FALSE(rvh->is_swapped_out_); |
| 7156 } | 7164 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7303 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 7311 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 7304 NavigateFrameToURL(child, cross_site_url); | 7312 NavigateFrameToURL(child, cross_site_url); |
| 7305 EXPECT_TRUE(observer.last_navigation_succeeded()); | 7313 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 7306 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 7314 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 7307 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); | 7315 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); |
| 7308 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7316 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7309 | 7317 |
| 7310 // Go back and ensure the data: URL committed in the same SiteInstance as the | 7318 // Go back and ensure the data: URL committed in the same SiteInstance as the |
| 7311 // original navigation. | 7319 // original navigation. |
| 7312 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); | 7320 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); |
| 7313 TestFrameNavigationObserver frame_observer(child); | 7321 TestFrameNavigationObserver frame_observer(child->current_frame_host()); |
| 7314 web_contents()->GetController().GoBack(); | 7322 web_contents()->GetController().GoBack(); |
| 7315 frame_observer.WaitForCommit(); | 7323 frame_observer.WaitForCommit(); |
| 7316 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7324 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7317 } | 7325 } |
| 7318 | 7326 |
| 7319 // Ensures that navigating to about:blank URLs present in session history will | 7327 // Ensures that navigating to about:blank URLs present in session history will |
| 7320 // correctly commit the navigation in the same process as the one used for | 7328 // correctly commit the navigation in the same process as the one used for |
| 7321 // the original navigation. | 7329 // the original navigation. |
| 7322 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 7330 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 7323 NavigateSubframeToAboutBlankInSessionHistory) { | 7331 NavigateSubframeToAboutBlankInSessionHistory) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 7351 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 7359 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 7352 NavigateFrameToURL(child, cross_site_url); | 7360 NavigateFrameToURL(child, cross_site_url); |
| 7353 EXPECT_TRUE(observer.last_navigation_succeeded()); | 7361 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 7354 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 7362 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 7355 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); | 7363 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); |
| 7356 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7364 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7357 | 7365 |
| 7358 // Go back and ensure the about:blank URL committed in the same SiteInstance | 7366 // Go back and ensure the about:blank URL committed in the same SiteInstance |
| 7359 // as the original navigation. | 7367 // as the original navigation. |
| 7360 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); | 7368 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); |
| 7361 TestFrameNavigationObserver frame_observer(child); | 7369 TestFrameNavigationObserver frame_observer(child->current_frame_host()); |
| 7362 web_contents()->GetController().GoBack(); | 7370 web_contents()->GetController().GoBack(); |
| 7363 frame_observer.WaitForCommit(); | 7371 frame_observer.WaitForCommit(); |
| 7364 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7372 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7365 } | 7373 } |
| 7366 | 7374 |
| 7367 // Tests that there are no crashes if a subframe is detached in its unload | 7375 // Tests that there are no crashes if a subframe is detached in its unload |
| 7368 // handler. See https://crbug.com/590054. | 7376 // handler. See https://crbug.com/590054. |
| 7369 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DetachInUnloadHandler) { | 7377 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DetachInUnloadHandler) { |
| 7370 GURL main_url(embedded_test_server()->GetURL( | 7378 GURL main_url(embedded_test_server()->GetURL( |
| 7371 "a.com", "/cross_site_iframe_factory.html?a(b(b))")); | 7379 "a.com", "/cross_site_iframe_factory.html?a(b(b))")); |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8237 // Install a filter to drop DispatchLoad messages from b.com. | 8245 // Install a filter to drop DispatchLoad messages from b.com. |
| 8238 scoped_refptr<DispatchLoadMessageFilter> filter = | 8246 scoped_refptr<DispatchLoadMessageFilter> filter = |
| 8239 new DispatchLoadMessageFilter(); | 8247 new DispatchLoadMessageFilter(); |
| 8240 RenderProcessHost* b_process = | 8248 RenderProcessHost* b_process = |
| 8241 popup_shell->web_contents()->GetMainFrame()->GetProcess(); | 8249 popup_shell->web_contents()->GetMainFrame()->GetProcess(); |
| 8242 b_process->AddFilter(filter.get()); | 8250 b_process->AddFilter(filter.get()); |
| 8243 | 8251 |
| 8244 // Navigate subframe to b.com. Wait for commit but not full load. | 8252 // Navigate subframe to b.com. Wait for commit but not full load. |
| 8245 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 8253 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 8246 { | 8254 { |
| 8247 TestFrameNavigationObserver commit_observer(child); | 8255 TestFrameNavigationObserver commit_observer(child->current_frame_host()); |
| 8248 EXPECT_TRUE( | 8256 EXPECT_TRUE( |
| 8249 ExecuteScript(child, "location.href = '" + b_url.spec() + "';")); | 8257 ExecuteScript(child, "location.href = '" + b_url.spec() + "';")); |
| 8250 commit_observer.WaitForCommit(); | 8258 commit_observer.WaitForCommit(); |
| 8251 } | 8259 } |
| 8252 RenderFrameHostImpl* child_rfh = child->current_frame_host(); | 8260 RenderFrameHostImpl* child_rfh = child->current_frame_host(); |
| 8253 child_rfh->DisableSwapOutTimerForTesting(); | 8261 child_rfh->DisableSwapOutTimerForTesting(); |
| 8254 | 8262 |
| 8255 // At this point, the subframe should have a proxy in its parent's | 8263 // At this point, the subframe should have a proxy in its parent's |
| 8256 // SiteInstance, a.com. | 8264 // SiteInstance, a.com. |
| 8257 EXPECT_TRUE(child->render_manager()->GetProxyToParent()); | 8265 EXPECT_TRUE(child->render_manager()->GetProxyToParent()); |
| 8258 | 8266 |
| 8259 // Now, go back to a.com in the subframe and wait for commit. | 8267 // Now, go back to a.com in the subframe and wait for commit. |
| 8260 { | 8268 { |
| 8261 TestFrameNavigationObserver commit_observer(child); | 8269 TestFrameNavigationObserver commit_observer(child->current_frame_host()); |
| 8262 web_contents()->GetController().GoBack(); | 8270 web_contents()->GetController().GoBack(); |
| 8263 commit_observer.WaitForCommit(); | 8271 commit_observer.WaitForCommit(); |
| 8264 } | 8272 } |
| 8265 | 8273 |
| 8266 // At this point, the subframe's old RFH for b.com should be pending | 8274 // At this point, the subframe's old RFH for b.com should be pending |
| 8267 // deletion, and the subframe's proxy in a.com should've been cleared. | 8275 // deletion, and the subframe's proxy in a.com should've been cleared. |
| 8268 EXPECT_FALSE(child_rfh->is_active()); | 8276 EXPECT_FALSE(child_rfh->is_active()); |
| 8269 EXPECT_FALSE(child->render_manager()->GetProxyToParent()); | 8277 EXPECT_FALSE(child->render_manager()->GetProxyToParent()); |
| 8270 | 8278 |
| 8271 // Simulate that the load event is dispatched from |child_rfh| just after | 8279 // Simulate that the load event is dispatched from |child_rfh| just after |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8548 EXPECT_TRUE(NavigateToURL(shell(), b_url)); | 8556 EXPECT_TRUE(NavigateToURL(shell(), b_url)); |
| 8549 | 8557 |
| 8550 base::string16 expected_title(base::UTF8ToUTF16("foo")); | 8558 base::string16 expected_title(base::UTF8ToUTF16("foo")); |
| 8551 TitleWatcher title_watcher(popup2->web_contents(), expected_title); | 8559 TitleWatcher title_watcher(popup2->web_contents(), expected_title); |
| 8552 EXPECT_TRUE(ExecuteScript( | 8560 EXPECT_TRUE(ExecuteScript( |
| 8553 shell(), "window.open('','popup2').postMessage('foo', '*');")); | 8561 shell(), "window.open('','popup2').postMessage('foo', '*');")); |
| 8554 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 8562 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 8555 } | 8563 } |
| 8556 | 8564 |
| 8557 } // namespace content | 8565 } // namespace content |
| OLD | NEW |