| 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 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 "Where A = http://a.com/\n" | 1923 "Where A = http://a.com/\n" |
| 1924 " D = http://f00.com/", | 1924 " D = http://f00.com/", |
| 1925 DepictFrameTree(root)); | 1925 DepictFrameTree(root)); |
| 1926 | 1926 |
| 1927 // Navigate the iframe itself to about:blank using a script executing in its | 1927 // Navigate the iframe itself to about:blank using a script executing in its |
| 1928 // own context. It should stay in the same SiteInstance as before, not the | 1928 // own context. It should stay in the same SiteInstance as before, not the |
| 1929 // parent one. | 1929 // parent one. |
| 1930 std::string script( | 1930 std::string script( |
| 1931 "window.domAutomationController.send(" | 1931 "window.domAutomationController.send(" |
| 1932 "window.location.href = 'about:blank');"); | 1932 "window.location.href = 'about:blank');"); |
| 1933 TestFrameNavigationObserver frame_observer(child); | 1933 TestFrameNavigationObserver frame_observer(child->current_frame_host()); |
| 1934 EXPECT_TRUE(ExecuteScript(child, script)); | 1934 EXPECT_TRUE(ExecuteScript(child, script)); |
| 1935 frame_observer.Wait(); | 1935 frame_observer.Wait(); |
| 1936 EXPECT_EQ(about_blank_url, child->current_url()); | 1936 EXPECT_EQ(about_blank_url, child->current_url()); |
| 1937 | 1937 |
| 1938 // Ensure that we have navigated using the top level process. | 1938 // Ensure that we have navigated using the top level process. |
| 1939 EXPECT_EQ( | 1939 EXPECT_EQ( |
| 1940 " Site A ------------ proxies for D\n" | 1940 " Site A ------------ proxies for D\n" |
| 1941 " |--Site D ------- proxies for A\n" | 1941 " |--Site D ------- proxies for A\n" |
| 1942 " +--Site A ------- proxies for D\n" | 1942 " +--Site A ------- proxies for D\n" |
| 1943 " +--Site A -- proxies for D\n" | 1943 " +--Site A -- proxies for D\n" |
| (...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2893 // proxies to have been created in the frame tree, but children of the | 2893 // proxies to have been created in the frame tree, but children of the |
| 2894 // navigating frame to still be present. The reason is that we don't run the | 2894 // navigating frame to still be present. The reason is that we don't run the |
| 2895 // message loop, so no IPCs that alter the frame tree can be processed. | 2895 // message loop, so no IPCs that alter the frame tree can be processed. |
| 2896 FrameTreeNode* child = root->child_at(1); | 2896 FrameTreeNode* child = root->child_at(1); |
| 2897 SiteInstance* site = NULL; | 2897 SiteInstance* site = NULL; |
| 2898 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); | 2898 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); |
| 2899 std::string cross_site_rfh_type = | 2899 std::string cross_site_rfh_type = |
| 2900 browser_side_navigation ? "speculative" : "pending"; | 2900 browser_side_navigation ? "speculative" : "pending"; |
| 2901 { | 2901 { |
| 2902 TestNavigationObserver observer(shell()->web_contents()); | 2902 TestNavigationObserver observer(shell()->web_contents()); |
| 2903 TestFrameNavigationObserver navigation_observer(child); | 2903 TestFrameNavigationObserver navigation_observer( |
| 2904 child->current_frame_host()); |
| 2904 NavigationController::LoadURLParams params(cross_site_url); | 2905 NavigationController::LoadURLParams params(cross_site_url); |
| 2905 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 2906 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
| 2906 params.frame_tree_node_id = child->frame_tree_node_id(); | 2907 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 2907 child->navigator()->GetController()->LoadURLWithParams(params); | 2908 child->navigator()->GetController()->LoadURLWithParams(params); |
| 2908 | 2909 |
| 2909 if (browser_side_navigation) { | 2910 if (browser_side_navigation) { |
| 2910 site = child->render_manager() | 2911 site = child->render_manager() |
| 2911 ->speculative_frame_host() | 2912 ->speculative_frame_host() |
| 2912 ->GetSiteInstance(); | 2913 ->GetSiteInstance(); |
| 2913 } else { | 2914 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2946 // Load another cross-site page into the same iframe. | 2947 // Load another cross-site page into the same iframe. |
| 2947 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title3.html"); | 2948 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 2948 { | 2949 { |
| 2949 // Perform the same checks as the first cross-site navigation, since | 2950 // Perform the same checks as the first cross-site navigation, since |
| 2950 // there have been issues in subsequent cross-site navigations. Also ensure | 2951 // there have been issues in subsequent cross-site navigations. Also ensure |
| 2951 // that the SiteInstance has properly changed. | 2952 // that the SiteInstance has properly changed. |
| 2952 // TODO(nasko): Once we have proper cleanup of resources, add code to | 2953 // TODO(nasko): Once we have proper cleanup of resources, add code to |
| 2953 // verify that the intermediate SiteInstance/RenderFrameHost have been | 2954 // verify that the intermediate SiteInstance/RenderFrameHost have been |
| 2954 // properly cleaned up. | 2955 // properly cleaned up. |
| 2955 TestNavigationObserver observer(shell()->web_contents()); | 2956 TestNavigationObserver observer(shell()->web_contents()); |
| 2956 TestFrameNavigationObserver navigation_observer(child); | 2957 TestFrameNavigationObserver navigation_observer( |
| 2958 child->current_frame_host()); |
| 2957 NavigationController::LoadURLParams params(cross_site_url); | 2959 NavigationController::LoadURLParams params(cross_site_url); |
| 2958 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); | 2960 params.transition_type = PageTransitionFromInt(ui::PAGE_TRANSITION_LINK); |
| 2959 params.frame_tree_node_id = child->frame_tree_node_id(); | 2961 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 2960 child->navigator()->GetController()->LoadURLWithParams(params); | 2962 child->navigator()->GetController()->LoadURLWithParams(params); |
| 2961 | 2963 |
| 2962 SiteInstance* site2; | 2964 SiteInstance* site2; |
| 2963 if (browser_side_navigation) { | 2965 if (browser_side_navigation) { |
| 2964 site2 = child->render_manager() | 2966 site2 = child->render_manager() |
| 2965 ->speculative_frame_host() | 2967 ->speculative_frame_host() |
| 2966 ->GetSiteInstance(); | 2968 ->GetSiteInstance(); |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3622 // per blink::parseSandboxPolicy(). | 3624 // per blink::parseSandboxPolicy(). |
| 3623 blink::WebSandboxFlags expected_flags = | 3625 blink::WebSandboxFlags expected_flags = |
| 3624 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 3626 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 3625 ~blink::WebSandboxFlags::AutomaticFeatures; | 3627 ~blink::WebSandboxFlags::AutomaticFeatures; |
| 3626 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3628 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3627 EXPECT_EQ(blink::WebSandboxFlags::None, | 3629 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3628 root->child_at(0)->effective_sandbox_flags()); | 3630 root->child_at(0)->effective_sandbox_flags()); |
| 3629 | 3631 |
| 3630 // Perform a renderer-initiated same-site navigation in the first frame. The | 3632 // Perform a renderer-initiated same-site navigation in the first frame. The |
| 3631 // new sandbox flags should take effect. | 3633 // new sandbox flags should take effect. |
| 3632 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 3634 TestFrameNavigationObserver frame_observer( |
| 3635 root->child_at(0)->current_frame_host()); |
| 3633 ASSERT_TRUE( | 3636 ASSERT_TRUE( |
| 3634 ExecuteScript(root->child_at(0), "window.location.href='/title2.html'")); | 3637 ExecuteScript(root->child_at(0), "window.location.href='/title2.html'")); |
| 3635 frame_observer.Wait(); | 3638 frame_observer.Wait(); |
| 3636 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title2.html"), | 3639 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title2.html"), |
| 3637 root->child_at(0)->current_url()); | 3640 root->child_at(0)->current_url()); |
| 3638 | 3641 |
| 3639 // Confirm that the browser process has updated the frame's current sandbox | 3642 // Confirm that the browser process has updated the frame's current sandbox |
| 3640 // flags. | 3643 // flags. |
| 3641 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3644 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3642 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 3645 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3689 // the new sandboxed local frame, its child (while it's still local), and a | 3692 // the new sandboxed local frame, its child (while it's still local), and a |
| 3690 // pending RFH when starting the cross-site navigation to baz.com. | 3693 // pending RFH when starting the cross-site navigation to baz.com. |
| 3691 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); | 3694 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); |
| 3692 EXPECT_TRUE(ExecuteScript(root, | 3695 EXPECT_TRUE(ExecuteScript(root, |
| 3693 "addFrame('/frame_tree/page_with_one_frame.html'," | 3696 "addFrame('/frame_tree/page_with_one_frame.html'," |
| 3694 " 'allow-scripts allow-same-origin'))")); | 3697 " 'allow-scripts allow-same-origin'))")); |
| 3695 frame_observer.Wait(); | 3698 frame_observer.Wait(); |
| 3696 | 3699 |
| 3697 // Wait for the cross-site navigation to baz.com in the grandchild to finish. | 3700 // Wait for the cross-site navigation to baz.com in the grandchild to finish. |
| 3698 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); | 3701 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); |
| 3699 TestFrameNavigationObserver navigation_observer(bottom_child); | 3702 TestFrameNavigationObserver navigation_observer( |
| 3703 bottom_child->current_frame_host()); |
| 3700 navigation_observer.Wait(); | 3704 navigation_observer.Wait(); |
| 3701 | 3705 |
| 3702 EXPECT_EQ( | 3706 EXPECT_EQ( |
| 3703 " Site A ------------ proxies for B\n" | 3707 " Site A ------------ proxies for B\n" |
| 3704 " |--Site B ------- proxies for A\n" | 3708 " |--Site B ------- proxies for A\n" |
| 3705 " +--Site A ------- proxies for B\n" | 3709 " +--Site A ------- proxies for B\n" |
| 3706 " +--Site B -- proxies for A\n" | 3710 " +--Site B -- proxies for A\n" |
| 3707 "Where A = http://127.0.0.1/\n" | 3711 "Where A = http://127.0.0.1/\n" |
| 3708 " B = http://baz.com/", | 3712 " B = http://baz.com/", |
| 3709 DepictFrameTree(root)); | 3713 DepictFrameTree(root)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3812 " frames['updated-name'] == frames[0]);", | 3816 " frames['updated-name'] == frames[0]);", |
| 3813 &success)); | 3817 &success)); |
| 3814 EXPECT_TRUE(success); | 3818 EXPECT_TRUE(success); |
| 3815 | 3819 |
| 3816 // Issue a renderer-initiated navigation from the root frame to the child | 3820 // Issue a renderer-initiated navigation from the root frame to the child |
| 3817 // frame using the frame's name. Make sure correct frame is navigated. | 3821 // frame using the frame's name. Make sure correct frame is navigated. |
| 3818 // | 3822 // |
| 3819 // TODO(alexmos): When blink::createWindow is refactored to handle | 3823 // TODO(alexmos): When blink::createWindow is refactored to handle |
| 3820 // RemoteFrames, this should also be tested via window.open(url, frame_name) | 3824 // RemoteFrames, this should also be tested via window.open(url, frame_name) |
| 3821 // and a more complicated frame hierarchy (https://crbug.com/463742) | 3825 // and a more complicated frame hierarchy (https://crbug.com/463742) |
| 3822 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 3826 TestFrameNavigationObserver frame_observer( |
| 3827 root->child_at(0)->current_frame_host()); |
| 3823 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | 3828 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 3824 EXPECT_TRUE(ExecuteScript( | 3829 EXPECT_TRUE(ExecuteScript( |
| 3825 shell(), | 3830 shell(), |
| 3826 base::StringPrintf("frames['updated-name'].location.href = '%s';", | 3831 base::StringPrintf("frames['updated-name'].location.href = '%s';", |
| 3827 foo_url.spec().c_str()))); | 3832 foo_url.spec().c_str()))); |
| 3828 frame_observer.Wait(); | 3833 frame_observer.Wait(); |
| 3829 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); | 3834 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); |
| 3830 } | 3835 } |
| 3831 | 3836 |
| 3832 // Verify that when a frame is navigated to a new origin, the origin update | 3837 // 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... |
| 4830 // Install a BrowserMessageFilter to drop SwapOut ACK messages in A's | 4835 // Install a BrowserMessageFilter to drop SwapOut ACK messages in A's |
| 4831 // process. | 4836 // process. |
| 4832 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); | 4837 scoped_refptr<SwapoutACKMessageFilter> filter = new SwapoutACKMessageFilter(); |
| 4833 rfh->GetProcess()->AddFilter(filter.get()); | 4838 rfh->GetProcess()->AddFilter(filter.get()); |
| 4834 rfh->DisableSwapOutTimerForTesting(); | 4839 rfh->DisableSwapOutTimerForTesting(); |
| 4835 | 4840 |
| 4836 // Navigate to B. This must wait for DidCommitProvisionalLoad and not | 4841 // Navigate to B. This must wait for DidCommitProvisionalLoad and not |
| 4837 // DidStopLoading, so that the SwapOut timer doesn't call OnSwappedOut and | 4842 // DidStopLoading, so that the SwapOut timer doesn't call OnSwappedOut and |
| 4838 // destroy |rfh| and |rvh| before they are checked in the test. | 4843 // destroy |rfh| and |rvh| before they are checked in the test. |
| 4839 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 4844 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 4840 TestFrameNavigationObserver commit_observer(root); | 4845 TestFrameNavigationObserver commit_observer(root->current_frame_host()); |
| 4841 shell()->LoadURL(b_url); | 4846 shell()->LoadURL(b_url); |
| 4842 commit_observer.WaitForCommit(); | 4847 commit_observer.WaitForCommit(); |
| 4843 EXPECT_FALSE(deleted_observer.deleted()); | 4848 EXPECT_FALSE(deleted_observer.deleted()); |
| 4844 | 4849 |
| 4845 // Since the SwapOut ACK for A->B is dropped, the first page's | 4850 // Since the SwapOut ACK for A->B is dropped, the first page's |
| 4846 // RenderFrameHost should be pending deletion after the last navigation. | 4851 // RenderFrameHost should be pending deletion after the last navigation. |
| 4847 EXPECT_FALSE(rfh->is_active()); | 4852 EXPECT_FALSE(rfh->is_active()); |
| 4848 | 4853 |
| 4849 // Wait for process A to exit so we can reinitialize it cleanly for the next | 4854 // Wait for process A to exit so we can reinitialize it cleanly for the next |
| 4850 // navigation. Since process A doesn't have any active views, it will | 4855 // 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... |
| 6449 EXPECT_EQ(blink::WebSandboxFlags::None, child->effective_sandbox_flags()); | 6454 EXPECT_EQ(blink::WebSandboxFlags::None, child->effective_sandbox_flags()); |
| 6450 | 6455 |
| 6451 // Add a new grandchild frame and navigate it cross-site. | 6456 // Add a new grandchild frame and navigate it cross-site. |
| 6452 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); | 6457 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); |
| 6453 EXPECT_TRUE(ExecuteScript( | 6458 EXPECT_TRUE(ExecuteScript( |
| 6454 child, "document.body.appendChild(document.createElement('iframe'));")); | 6459 child, "document.body.appendChild(document.createElement('iframe'));")); |
| 6455 frame_observer.Wait(); | 6460 frame_observer.Wait(); |
| 6456 | 6461 |
| 6457 FrameTreeNode* grandchild = child->child_at(0); | 6462 FrameTreeNode* grandchild = child->child_at(0); |
| 6458 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6463 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6459 TestFrameNavigationObserver navigation_observer(grandchild); | 6464 TestFrameNavigationObserver navigation_observer( |
| 6465 grandchild->current_frame_host()); |
| 6460 NavigateFrameToURL(grandchild, frame_url); | 6466 NavigateFrameToURL(grandchild, frame_url); |
| 6461 navigation_observer.Wait(); | 6467 navigation_observer.Wait(); |
| 6462 | 6468 |
| 6463 // Since the update flags haven't yet taken effect in its parent, this | 6469 // Since the update flags haven't yet taken effect in its parent, this |
| 6464 // grandchild frame should not be sandboxed. | 6470 // grandchild frame should not be sandboxed. |
| 6465 EXPECT_EQ(blink::WebSandboxFlags::None, grandchild->pending_sandbox_flags()); | 6471 EXPECT_EQ(blink::WebSandboxFlags::None, grandchild->pending_sandbox_flags()); |
| 6466 EXPECT_EQ(blink::WebSandboxFlags::None, | 6472 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 6467 grandchild->effective_sandbox_flags()); | 6473 grandchild->effective_sandbox_flags()); |
| 6468 | 6474 |
| 6469 // Check that the grandchild frame isn't sandboxed on the renderer side. If | 6475 // Check that the grandchild frame isn't sandboxed on the renderer side. If |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6492 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per | 6498 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per |
| 6493 // blink::parseSandboxPolicy(). | 6499 // blink::parseSandboxPolicy(). |
| 6494 blink::WebSandboxFlags expected_flags = | 6500 blink::WebSandboxFlags expected_flags = |
| 6495 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 6501 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 6496 ~blink::WebSandboxFlags::AutomaticFeatures & | 6502 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 6497 ~blink::WebSandboxFlags::Popups; | 6503 ~blink::WebSandboxFlags::Popups; |
| 6498 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 6504 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 6499 | 6505 |
| 6500 // Navigate child frame cross-site. The sandbox flags should take effect. | 6506 // Navigate child frame cross-site. The sandbox flags should take effect. |
| 6501 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6507 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6502 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 6508 TestFrameNavigationObserver frame_observer( |
| 6509 root->child_at(0)->current_frame_host()); |
| 6503 NavigateFrameToURL(root->child_at(0), frame_url); | 6510 NavigateFrameToURL(root->child_at(0), frame_url); |
| 6504 frame_observer.Wait(); | 6511 frame_observer.Wait(); |
| 6505 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 6512 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 6506 | 6513 |
| 6507 // Verify that they've also taken effect on the renderer side. The sandboxed | 6514 // Verify that they've also taken effect on the renderer side. The sandboxed |
| 6508 // frame's origin should be unique. | 6515 // frame's origin should be unique. |
| 6509 EXPECT_EQ("null", GetDocumentOrigin(root->child_at(0))); | 6516 EXPECT_EQ("null", GetDocumentOrigin(root->child_at(0))); |
| 6510 | 6517 |
| 6511 // Open a popup named "foo" from the sandboxed child frame. | 6518 // Open a popup named "foo" from the sandboxed child frame. |
| 6512 Shell* foo_shell = | 6519 Shell* foo_shell = |
| 6513 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), "foo"); | 6520 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), "foo"); |
| 6514 EXPECT_TRUE(foo_shell); | 6521 EXPECT_TRUE(foo_shell); |
| 6515 | 6522 |
| 6516 FrameTreeNode* foo_root = | 6523 FrameTreeNode* foo_root = |
| 6517 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 6524 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 6518 ->GetFrameTree() | 6525 ->GetFrameTree() |
| 6519 ->root(); | 6526 ->root(); |
| 6520 | 6527 |
| 6521 // Check that the sandbox flags for new popup are correct in the browser | 6528 // Check that the sandbox flags for new popup are correct in the browser |
| 6522 // process. | 6529 // process. |
| 6523 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); | 6530 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); |
| 6524 | 6531 |
| 6525 // The popup's origin should be unique, since it's sandboxed. | 6532 // The popup's origin should be unique, since it's sandboxed. |
| 6526 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); | 6533 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); |
| 6527 | 6534 |
| 6528 // Navigate the popup cross-site. This should keep the unique origin and the | 6535 // Navigate the popup cross-site. This should keep the unique origin and the |
| 6529 // inherited sandbox flags. | 6536 // inherited sandbox flags. |
| 6530 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 6537 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6531 TestFrameNavigationObserver popup_observer(foo_root); | 6538 TestFrameNavigationObserver popup_observer(foo_root->current_frame_host()); |
| 6532 EXPECT_TRUE( | 6539 EXPECT_TRUE( |
| 6533 ExecuteScript(foo_root, "location.href = '" + c_url.spec() + "';")); | 6540 ExecuteScript(foo_root, "location.href = '" + c_url.spec() + "';")); |
| 6534 popup_observer.Wait(); | 6541 popup_observer.Wait(); |
| 6535 EXPECT_EQ(c_url, foo_shell->web_contents()->GetLastCommittedURL()); | 6542 EXPECT_EQ(c_url, foo_shell->web_contents()->GetLastCommittedURL()); |
| 6536 | 6543 |
| 6537 // Confirm that the popup is still sandboxed, both on browser and renderer | 6544 // Confirm that the popup is still sandboxed, both on browser and renderer |
| 6538 // sides. | 6545 // sides. |
| 6539 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); | 6546 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); |
| 6540 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); | 6547 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); |
| 6541 } | 6548 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6564 // per blink::parseSandboxPolicy(). | 6571 // per blink::parseSandboxPolicy(). |
| 6565 blink::WebSandboxFlags expected_flags = | 6572 blink::WebSandboxFlags expected_flags = |
| 6566 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 6573 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 6567 ~blink::WebSandboxFlags::AutomaticFeatures & | 6574 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 6568 ~blink::WebSandboxFlags::Popups & | 6575 ~blink::WebSandboxFlags::Popups & |
| 6569 ~blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; | 6576 ~blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; |
| 6570 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 6577 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 6571 | 6578 |
| 6572 // Navigate child frame cross-site. The sandbox flags should take effect. | 6579 // Navigate child frame cross-site. The sandbox flags should take effect. |
| 6573 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6580 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6574 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 6581 TestFrameNavigationObserver frame_observer( |
| 6582 root->child_at(0)->current_frame_host()); |
| 6575 NavigateFrameToURL(root->child_at(0), frame_url); | 6583 NavigateFrameToURL(root->child_at(0), frame_url); |
| 6576 frame_observer.Wait(); | 6584 frame_observer.Wait(); |
| 6577 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 6585 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 6578 | 6586 |
| 6579 // Open a cross-site popup named "foo" from the child frame. | 6587 // Open a cross-site popup named "foo" from the child frame. |
| 6580 GURL b_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 6588 GURL b_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6581 Shell* foo_shell = OpenPopup(root->child_at(0), b_url, "foo"); | 6589 Shell* foo_shell = OpenPopup(root->child_at(0), b_url, "foo"); |
| 6582 EXPECT_TRUE(foo_shell); | 6590 EXPECT_TRUE(foo_shell); |
| 6583 | 6591 |
| 6584 FrameTreeNode* foo_root = | 6592 FrameTreeNode* foo_root = |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7144 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 7152 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 7145 std::string script = base::StringPrintf( | 7153 std::string script = base::StringPrintf( |
| 7146 "window.domAutomationController.send(" | 7154 "window.domAutomationController.send(" |
| 7147 "parent.location = '%s');", | 7155 "parent.location = '%s');", |
| 7148 b_url.spec().c_str()); | 7156 b_url.spec().c_str()); |
| 7149 | 7157 |
| 7150 // Ensure the child has received a user gesture, so that it has permission | 7158 // Ensure the child has received a user gesture, so that it has permission |
| 7151 // to framebust. | 7159 // to framebust. |
| 7152 SimulateMouseClick( | 7160 SimulateMouseClick( |
| 7153 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); | 7161 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
| 7154 TestFrameNavigationObserver frame_observer(root); | 7162 TestFrameNavigationObserver frame_observer(root->current_frame_host()); |
| 7155 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); | 7163 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 7156 frame_observer.Wait(); | 7164 frame_observer.Wait(); |
| 7157 EXPECT_EQ(b_url, root->current_url()); | 7165 EXPECT_EQ(b_url, root->current_url()); |
| 7158 | 7166 |
| 7159 // Verify that the same RenderViewHost is preserved and that it is no longer | 7167 // Verify that the same RenderViewHost is preserved and that it is no longer |
| 7160 // in swapped out state. | 7168 // in swapped out state. |
| 7161 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( | 7169 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( |
| 7162 root->current_frame_host()->GetSiteInstance())); | 7170 root->current_frame_host()->GetSiteInstance())); |
| 7163 EXPECT_FALSE(rvh->is_swapped_out_); | 7171 EXPECT_FALSE(rvh->is_swapped_out_); |
| 7164 } | 7172 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7311 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 7319 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 7312 NavigateFrameToURL(child, cross_site_url); | 7320 NavigateFrameToURL(child, cross_site_url); |
| 7313 EXPECT_TRUE(observer.last_navigation_succeeded()); | 7321 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 7314 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 7322 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 7315 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); | 7323 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); |
| 7316 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7324 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7317 | 7325 |
| 7318 // Go back and ensure the data: URL committed in the same SiteInstance as the | 7326 // Go back and ensure the data: URL committed in the same SiteInstance as the |
| 7319 // original navigation. | 7327 // original navigation. |
| 7320 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); | 7328 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); |
| 7321 TestFrameNavigationObserver frame_observer(child); | 7329 TestFrameNavigationObserver frame_observer(child->current_frame_host()); |
| 7322 web_contents()->GetController().GoBack(); | 7330 web_contents()->GetController().GoBack(); |
| 7323 frame_observer.WaitForCommit(); | 7331 frame_observer.WaitForCommit(); |
| 7324 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7332 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7325 } | 7333 } |
| 7326 | 7334 |
| 7327 // Ensures that navigating to about:blank URLs present in session history will | 7335 // Ensures that navigating to about:blank URLs present in session history will |
| 7328 // correctly commit the navigation in the same process as the one used for | 7336 // correctly commit the navigation in the same process as the one used for |
| 7329 // the original navigation. | 7337 // the original navigation. |
| 7330 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 7338 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 7331 NavigateSubframeToAboutBlankInSessionHistory) { | 7339 NavigateSubframeToAboutBlankInSessionHistory) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 7359 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 7367 GURL cross_site_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 7360 NavigateFrameToURL(child, cross_site_url); | 7368 NavigateFrameToURL(child, cross_site_url); |
| 7361 EXPECT_TRUE(observer.last_navigation_succeeded()); | 7369 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 7362 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 7370 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 7363 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); | 7371 EXPECT_EQ(3, web_contents()->GetController().GetEntryCount()); |
| 7364 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7372 EXPECT_NE(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7365 | 7373 |
| 7366 // Go back and ensure the about:blank URL committed in the same SiteInstance | 7374 // Go back and ensure the about:blank URL committed in the same SiteInstance |
| 7367 // as the original navigation. | 7375 // as the original navigation. |
| 7368 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); | 7376 EXPECT_TRUE(web_contents()->GetController().CanGoBack()); |
| 7369 TestFrameNavigationObserver frame_observer(child); | 7377 TestFrameNavigationObserver frame_observer(child->current_frame_host()); |
| 7370 web_contents()->GetController().GoBack(); | 7378 web_contents()->GetController().GoBack(); |
| 7371 frame_observer.WaitForCommit(); | 7379 frame_observer.WaitForCommit(); |
| 7372 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); | 7380 EXPECT_EQ(orig_site_instance, child->current_frame_host()->GetSiteInstance()); |
| 7373 } | 7381 } |
| 7374 | 7382 |
| 7375 // Tests that there are no crashes if a subframe is detached in its unload | 7383 // Tests that there are no crashes if a subframe is detached in its unload |
| 7376 // handler. See https://crbug.com/590054. | 7384 // handler. See https://crbug.com/590054. |
| 7377 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DetachInUnloadHandler) { | 7385 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DetachInUnloadHandler) { |
| 7378 GURL main_url(embedded_test_server()->GetURL( | 7386 GURL main_url(embedded_test_server()->GetURL( |
| 7379 "a.com", "/cross_site_iframe_factory.html?a(b(b))")); | 7387 "a.com", "/cross_site_iframe_factory.html?a(b(b))")); |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8245 // Install a filter to drop DispatchLoad messages from b.com. | 8253 // Install a filter to drop DispatchLoad messages from b.com. |
| 8246 scoped_refptr<DispatchLoadMessageFilter> filter = | 8254 scoped_refptr<DispatchLoadMessageFilter> filter = |
| 8247 new DispatchLoadMessageFilter(); | 8255 new DispatchLoadMessageFilter(); |
| 8248 RenderProcessHost* b_process = | 8256 RenderProcessHost* b_process = |
| 8249 popup_shell->web_contents()->GetMainFrame()->GetProcess(); | 8257 popup_shell->web_contents()->GetMainFrame()->GetProcess(); |
| 8250 b_process->AddFilter(filter.get()); | 8258 b_process->AddFilter(filter.get()); |
| 8251 | 8259 |
| 8252 // Navigate subframe to b.com. Wait for commit but not full load. | 8260 // Navigate subframe to b.com. Wait for commit but not full load. |
| 8253 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 8261 GURL b_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 8254 { | 8262 { |
| 8255 TestFrameNavigationObserver commit_observer(child); | 8263 TestFrameNavigationObserver commit_observer(child->current_frame_host()); |
| 8256 EXPECT_TRUE( | 8264 EXPECT_TRUE( |
| 8257 ExecuteScript(child, "location.href = '" + b_url.spec() + "';")); | 8265 ExecuteScript(child, "location.href = '" + b_url.spec() + "';")); |
| 8258 commit_observer.WaitForCommit(); | 8266 commit_observer.WaitForCommit(); |
| 8259 } | 8267 } |
| 8260 RenderFrameHostImpl* child_rfh = child->current_frame_host(); | 8268 RenderFrameHostImpl* child_rfh = child->current_frame_host(); |
| 8261 child_rfh->DisableSwapOutTimerForTesting(); | 8269 child_rfh->DisableSwapOutTimerForTesting(); |
| 8262 | 8270 |
| 8263 // At this point, the subframe should have a proxy in its parent's | 8271 // At this point, the subframe should have a proxy in its parent's |
| 8264 // SiteInstance, a.com. | 8272 // SiteInstance, a.com. |
| 8265 EXPECT_TRUE(child->render_manager()->GetProxyToParent()); | 8273 EXPECT_TRUE(child->render_manager()->GetProxyToParent()); |
| 8266 | 8274 |
| 8267 // Now, go back to a.com in the subframe and wait for commit. | 8275 // Now, go back to a.com in the subframe and wait for commit. |
| 8268 { | 8276 { |
| 8269 TestFrameNavigationObserver commit_observer(child); | 8277 TestFrameNavigationObserver commit_observer(child->current_frame_host()); |
| 8270 web_contents()->GetController().GoBack(); | 8278 web_contents()->GetController().GoBack(); |
| 8271 commit_observer.WaitForCommit(); | 8279 commit_observer.WaitForCommit(); |
| 8272 } | 8280 } |
| 8273 | 8281 |
| 8274 // At this point, the subframe's old RFH for b.com should be pending | 8282 // At this point, the subframe's old RFH for b.com should be pending |
| 8275 // deletion, and the subframe's proxy in a.com should've been cleared. | 8283 // deletion, and the subframe's proxy in a.com should've been cleared. |
| 8276 EXPECT_FALSE(child_rfh->is_active()); | 8284 EXPECT_FALSE(child_rfh->is_active()); |
| 8277 EXPECT_FALSE(child->render_manager()->GetProxyToParent()); | 8285 EXPECT_FALSE(child->render_manager()->GetProxyToParent()); |
| 8278 | 8286 |
| 8279 // Simulate that the load event is dispatched from |child_rfh| just after | 8287 // 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... |
| 8556 EXPECT_TRUE(NavigateToURL(shell(), b_url)); | 8564 EXPECT_TRUE(NavigateToURL(shell(), b_url)); |
| 8557 | 8565 |
| 8558 base::string16 expected_title(base::UTF8ToUTF16("foo")); | 8566 base::string16 expected_title(base::UTF8ToUTF16("foo")); |
| 8559 TitleWatcher title_watcher(popup2->web_contents(), expected_title); | 8567 TitleWatcher title_watcher(popup2->web_contents(), expected_title); |
| 8560 EXPECT_TRUE(ExecuteScript( | 8568 EXPECT_TRUE(ExecuteScript( |
| 8561 shell(), "window.open('','popup2').postMessage('foo', '*');")); | 8569 shell(), "window.open('','popup2').postMessage('foo', '*');")); |
| 8562 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 8570 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 8563 } | 8571 } |
| 8564 | 8572 |
| 8565 } // namespace content | 8573 } // namespace content |
| OLD | NEW |