| 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 <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 2932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2943 // the sad tab. Ensure this is not the case. | 2943 // the sad tab. Ensure this is not the case. |
| 2944 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, | 2944 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, |
| 2945 popup->web_contents()->GetCrashedStatus()); | 2945 popup->web_contents()->GetCrashedStatus()); |
| 2946 EXPECT_TRUE(popup->web_contents()->GetMainFrame()->IsRenderFrameLive()); | 2946 EXPECT_TRUE(popup->web_contents()->GetMainFrame()->IsRenderFrameLive()); |
| 2947 EXPECT_EQ(popup->web_contents()->GetMainFrame()->GetSiteInstance(), | 2947 EXPECT_EQ(popup->web_contents()->GetMainFrame()->GetSiteInstance(), |
| 2948 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); | 2948 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); |
| 2949 } | 2949 } |
| 2950 | 2950 |
| 2951 // Verify that GetLastCommittedOrigin() is correct for the full lifetime of a | 2951 // Verify that GetLastCommittedOrigin() is correct for the full lifetime of a |
| 2952 // RenderFrameHost, including when it's pending, current, and pending deletion. | 2952 // RenderFrameHost, including when it's pending, current, and pending deletion. |
| 2953 // This is checked both for main frames and subframes. See | 2953 // This is checked both for main frames and subframes. |
| 2954 // https://crbug.com/590035. | 2954 // See https://crbug.com/590035. |
| 2955 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, LastCommittedOrigin) { | 2955 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, LastCommittedOrigin) { |
| 2956 StartEmbeddedServer(); | 2956 StartEmbeddedServer(); |
| 2957 GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html")); | 2957 GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 2958 EXPECT_TRUE(NavigateToURL(shell(), url_a)); | 2958 EXPECT_TRUE(NavigateToURL(shell(), url_a)); |
| 2959 | 2959 |
| 2960 WebContentsImpl* web_contents = | 2960 WebContentsImpl* web_contents = |
| 2961 static_cast<WebContentsImpl*>(shell()->web_contents()); | 2961 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 2962 FrameTreeNode* root = web_contents->GetFrameTree()->root(); | 2962 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 2963 RenderFrameHostImpl* rfh_a = root->current_frame_host(); | 2963 RenderFrameHostImpl* rfh_a = root->current_frame_host(); |
| 2964 rfh_a->DisableSwapOutTimerForTesting(); | 2964 rfh_a->DisableSwapOutTimerForTesting(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3024 // With OOPIFs, this navigation used a cross-process transfer. Ensure that | 3024 // With OOPIFs, this navigation used a cross-process transfer. Ensure that |
| 3025 // the iframe's old RFH still has correct origin, even though it's pending | 3025 // the iframe's old RFH still has correct origin, even though it's pending |
| 3026 // deletion. | 3026 // deletion. |
| 3027 if (AreAllSitesIsolatedForTesting()) { | 3027 if (AreAllSitesIsolatedForTesting()) { |
| 3028 EXPECT_FALSE(child_rfh_b->is_active()); | 3028 EXPECT_FALSE(child_rfh_b->is_active()); |
| 3029 EXPECT_NE(child_rfh_b, child->current_frame_host()); | 3029 EXPECT_NE(child_rfh_b, child->current_frame_host()); |
| 3030 EXPECT_EQ(url::Origin(url_b), child_rfh_b->GetLastCommittedOrigin()); | 3030 EXPECT_EQ(url::Origin(url_b), child_rfh_b->GetLastCommittedOrigin()); |
| 3031 } | 3031 } |
| 3032 } | 3032 } |
| 3033 | 3033 |
| 3034 // Ensure that loading a page with cross-site coreferencing iframes does not |
| 3035 // cause an infinite number of nested iframes to be created. |
| 3036 // See https://crbug.com/650332. |
| 3037 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, CoReferencingFrames) { |
| 3038 // Load a page with a cross-site coreferencing iframe. "Coreferencing" here |
| 3039 // refers to two separate pages that contain subframes with URLs to each |
| 3040 // other. |
| 3041 StartEmbeddedServer(); |
| 3042 GURL url_1( |
| 3043 embedded_test_server()->GetURL("a.com", "/coreferencingframe_1.html")); |
| 3044 EXPECT_TRUE(NavigateToURL(shell(), url_1)); |
| 3045 |
| 3046 WebContentsImpl* web_contents = |
| 3047 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 3048 |
| 3049 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 3050 |
| 3051 // The FrameTree contains two successful instances of each site plus an |
| 3052 // unsuccessfully-navigated third instance of B with a blank URL. When not in |
| 3053 // site-per-process mode, the FrameTreeVisualizer depicts all nodes as |
| 3054 // referencing Site A because iframes are identified with their root site. |
| 3055 if (AreAllSitesIsolatedForTesting()) { |
| 3056 EXPECT_EQ( |
| 3057 " Site A ------------ proxies for B\n" |
| 3058 " +--Site B ------- proxies for A\n" |
| 3059 " +--Site A -- proxies for B\n" |
| 3060 " +--Site B -- proxies for A\n" |
| 3061 " +--Site B -- proxies for A\n" |
| 3062 "Where A = http://a.com/\n" |
| 3063 " B = http://b.com/", |
| 3064 FrameTreeVisualizer().DepictFrameTree(root)); |
| 3065 } else { |
| 3066 EXPECT_EQ( |
| 3067 " Site A\n" |
| 3068 " +--Site A\n" |
| 3069 " +--Site A\n" |
| 3070 " +--Site A\n" |
| 3071 " +--Site A\n" |
| 3072 "Where A = http://a.com/", |
| 3073 FrameTreeVisualizer().DepictFrameTree(root)); |
| 3074 } |
| 3075 FrameTreeNode* bottom_child = |
| 3076 root->child_at(0)->child_at(0)->child_at(0)->child_at(0); |
| 3077 EXPECT_TRUE(bottom_child->current_url().is_empty()); |
| 3078 EXPECT_FALSE(bottom_child->has_committed_real_load()); |
| 3079 } |
| 3080 |
| 3081 // Ensures that nested subframes with the same URL but different fragments can |
| 3082 // only be nested once. See https://crbug.com/650332. |
| 3083 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 3084 SelfReferencingFragmentFrames) { |
| 3085 StartEmbeddedServer(); |
| 3086 GURL url( |
| 3087 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html#123")); |
| 3088 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 3089 |
| 3090 WebContentsImpl* web_contents = |
| 3091 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 3092 |
| 3093 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 3094 FrameTreeNode* child = root->child_at(0); |
| 3095 |
| 3096 // ExecuteScript is used here and once more below because it is important to |
| 3097 // use renderer-initiated navigations since browser-initiated navigations are |
| 3098 // bypassed in the self-referencing navigation check. |
| 3099 TestFrameNavigationObserver observer1(child); |
| 3100 EXPECT_TRUE( |
| 3101 ExecuteScript(child, "location.href = '" + url.spec() + "456" + "';")); |
| 3102 observer1.Wait(); |
| 3103 |
| 3104 FrameTreeNode* grandchild = child->child_at(0); |
| 3105 GURL expected_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 3106 EXPECT_EQ(expected_url, grandchild->current_url()); |
| 3107 |
| 3108 // This navigation should be blocked. |
| 3109 GURL blocked_url(embedded_test_server()->GetURL( |
| 3110 "a.com", "/page_with_iframe.html#123456789")); |
| 3111 TestNavigationManager manager(web_contents, blocked_url); |
| 3112 EXPECT_TRUE(ExecuteScript(grandchild, |
| 3113 "location.href = '" + blocked_url.spec() + "';")); |
| 3114 // Wait for WillStartRequest and verify that the request is aborted before |
| 3115 // starting it. |
| 3116 EXPECT_FALSE(manager.WaitForRequestStart()); |
| 3117 WaitForLoadStop(web_contents); |
| 3118 |
| 3119 // The FrameTree contains two successful instances of the url plus an |
| 3120 // unsuccessfully-navigated third instance with a blank URL. |
| 3121 EXPECT_EQ( |
| 3122 " Site A\n" |
| 3123 " +--Site A\n" |
| 3124 " +--Site A\n" |
| 3125 "Where A = http://a.com/", |
| 3126 FrameTreeVisualizer().DepictFrameTree(root)); |
| 3127 |
| 3128 // The URL of the grandchild has not changed. |
| 3129 EXPECT_EQ(expected_url, grandchild->current_url()); |
| 3130 } |
| 3131 |
| 3132 // Ensure that loading a page with a meta refresh iframe does not cause an |
| 3133 // infinite number of nested iframes to be created. This test loads a page with |
| 3134 // an about:blank iframe where the page injects html containing a meta refresh |
| 3135 // into the iframe. This test then checks that this does not cause infinite |
| 3136 // nested iframes to be created. See https://crbug.com/527367. |
| 3137 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 3138 SelfReferencingMetaRefreshFrames) { |
| 3139 // Load a page with a blank iframe. |
| 3140 StartEmbeddedServer(); |
| 3141 GURL url(embedded_test_server()->GetURL( |
| 3142 "a.com", "/page_with_meta_refresh_frame.html")); |
| 3143 NavigateToURLBlockUntilNavigationsComplete(shell(), url, 3); |
| 3144 |
| 3145 WebContentsImpl* web_contents = |
| 3146 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 3147 |
| 3148 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 3149 |
| 3150 // The third navigation should fail and be cancelled, leaving a FrameTree with |
| 3151 // a height of 2. |
| 3152 EXPECT_EQ( |
| 3153 " Site A\n" |
| 3154 " +--Site A\n" |
| 3155 " +--Site A\n" |
| 3156 "Where A = http://a.com/", |
| 3157 FrameTreeVisualizer().DepictFrameTree(root)); |
| 3158 |
| 3159 EXPECT_EQ(GURL(url::kAboutBlankURL), |
| 3160 root->child_at(0)->child_at(0)->current_url()); |
| 3161 |
| 3162 EXPECT_FALSE(root->child_at(0)->child_at(0)->has_committed_real_load()); |
| 3163 } |
| 3164 |
| 3165 // Ensure that navigating a subframe to the same URL as its parent twice in a |
| 3166 // row is not blocked by the self-reference check. |
| 3167 // See https://crbug.com/650332. |
| 3168 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 3169 SelfReferencingSameURLRenavigation) { |
| 3170 StartEmbeddedServer(); |
| 3171 GURL first_url( |
| 3172 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html")); |
| 3173 GURL second_url(first_url.spec() + "#123"); |
| 3174 EXPECT_TRUE(NavigateToURL(shell(), first_url)); |
| 3175 |
| 3176 WebContentsImpl* web_contents = |
| 3177 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 3178 |
| 3179 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 3180 FrameTreeNode* child = root->child_at(0); |
| 3181 |
| 3182 TestFrameNavigationObserver observer1(child); |
| 3183 EXPECT_TRUE( |
| 3184 ExecuteScript(child, "location.href = '" + second_url.spec() + "';")); |
| 3185 observer1.Wait(); |
| 3186 |
| 3187 EXPECT_EQ(child->current_url(), second_url); |
| 3188 |
| 3189 TestFrameNavigationObserver observer2(child); |
| 3190 // This navigation shouldn't be blocked. Blocking should only occur when more |
| 3191 // than one ancestor has the same URL (excluding fragments), and the |
| 3192 // navigating frame's current URL shouldn't count toward that. |
| 3193 EXPECT_TRUE( |
| 3194 ExecuteScript(child, "location.href = '" + first_url.spec() + "';")); |
| 3195 observer2.Wait(); |
| 3196 |
| 3197 EXPECT_EQ(child->current_url(), first_url); |
| 3198 } |
| 3199 |
| 3034 } // namespace content | 3200 } // namespace content |
| OLD | NEW |