Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_browsertest.cc

Issue 2528813002: Fix Self-Referencing OOPIF Infinite Loop (Closed)
Patch Set: refactor allowedToLoadFrame conditional Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2936 matching lines...) Expand 10 before | Expand all | Expand 10 after
2947 // the sad tab. Ensure this is not the case. 2947 // the sad tab. Ensure this is not the case.
2948 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, 2948 EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
2949 popup->web_contents()->GetCrashedStatus()); 2949 popup->web_contents()->GetCrashedStatus());
2950 EXPECT_TRUE(popup->web_contents()->GetMainFrame()->IsRenderFrameLive()); 2950 EXPECT_TRUE(popup->web_contents()->GetMainFrame()->IsRenderFrameLive());
2951 EXPECT_EQ(popup->web_contents()->GetMainFrame()->GetSiteInstance(), 2951 EXPECT_EQ(popup->web_contents()->GetMainFrame()->GetSiteInstance(),
2952 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); 2952 shell()->web_contents()->GetMainFrame()->GetSiteInstance());
2953 } 2953 }
2954 2954
2955 // Verify that GetLastCommittedOrigin() is correct for the full lifetime of a 2955 // Verify that GetLastCommittedOrigin() is correct for the full lifetime of a
2956 // RenderFrameHost, including when it's pending, current, and pending deletion. 2956 // RenderFrameHost, including when it's pending, current, and pending deletion.
2957 // This is checked both for main frames and subframes. See 2957 // This is checked both for main frames and subframes.
2958 // https://crbug.com/590035. 2958 // See https://crbug.com/590035.
2959 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, LastCommittedOrigin) { 2959 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, LastCommittedOrigin) {
2960 StartEmbeddedServer(); 2960 StartEmbeddedServer();
2961 GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html")); 2961 GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html"));
2962 EXPECT_TRUE(NavigateToURL(shell(), url_a)); 2962 EXPECT_TRUE(NavigateToURL(shell(), url_a));
2963 2963
2964 WebContentsImpl* web_contents = 2964 WebContentsImpl* web_contents =
2965 static_cast<WebContentsImpl*>(shell()->web_contents()); 2965 static_cast<WebContentsImpl*>(shell()->web_contents());
2966 FrameTreeNode* root = web_contents->GetFrameTree()->root(); 2966 FrameTreeNode* root = web_contents->GetFrameTree()->root();
2967 RenderFrameHostImpl* rfh_a = root->current_frame_host(); 2967 RenderFrameHostImpl* rfh_a = root->current_frame_host();
2968 rfh_a->DisableSwapOutTimerForTesting(); 2968 rfh_a->DisableSwapOutTimerForTesting();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3099 // different SiteInstance from the parent frame. 3099 // different SiteInstance from the parent frame.
3100 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 3100 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
3101 ASSERT_EQ(2U, entry->root_node()->children.size()); 3101 ASSERT_EQ(2U, entry->root_node()->children.size());
3102 EXPECT_EQ(regular_web_url, 3102 EXPECT_EQ(regular_web_url,
3103 entry->root_node()->children[1]->frame_entry->url()); 3103 entry->root_node()->children[1]->frame_entry->url());
3104 EXPECT_NE(root->current_frame_host()->GetSiteInstance(), 3104 EXPECT_NE(root->current_frame_host()->GetSiteInstance(),
3105 root->child_at(1)->current_frame_host()->GetSiteInstance()); 3105 root->child_at(1)->current_frame_host()->GetSiteInstance());
3106 } 3106 }
3107 } 3107 }
3108 3108
3109 // Ensure that loading a page with cross-site coreferencing iframes does not
3110 // cause an infinite number of nested iframes to be created.
3111 // See https://crbug.com/650332.
3112 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, CoReferencingFrames) {
3113 // Load a page with a cross-site coreferencing iframe. "Coreferencing" here
3114 // refers to two separate pages that contain subframes with URLs to each
3115 // other.
3116 StartEmbeddedServer();
3117 GURL url_1(
3118 embedded_test_server()->GetURL("a.com", "/coreferencingframe_1.html"));
3119 EXPECT_TRUE(NavigateToURL(shell(), url_1));
3120
3121 WebContentsImpl* web_contents =
3122 static_cast<WebContentsImpl*>(shell()->web_contents());
3123
3124 FrameTreeNode* root = web_contents->GetFrameTree()->root();
3125
3126 // The FrameTree contains two successful instances of each site plus an
3127 // unsuccessfully-navigated third instance of B with a blank URL. When not in
3128 // site-per-process mode, the FrameTreeVisualizer depicts all nodes as
3129 // referencing Site A because iframes are identified with their root site.
3130 if (AreAllSitesIsolatedForTesting()) {
3131 EXPECT_EQ(
3132 " Site A ------------ proxies for B\n"
3133 " +--Site B ------- proxies for A\n"
3134 " +--Site A -- proxies for B\n"
3135 " +--Site B -- proxies for A\n"
3136 " +--Site B -- proxies for A\n"
3137 "Where A = http://a.com/\n"
3138 " B = http://b.com/",
3139 FrameTreeVisualizer().DepictFrameTree(root));
3140 } else {
3141 EXPECT_EQ(
3142 " Site A\n"
3143 " +--Site A\n"
3144 " +--Site A\n"
3145 " +--Site A\n"
3146 " +--Site A\n"
3147 "Where A = http://a.com/",
3148 FrameTreeVisualizer().DepictFrameTree(root));
3149 }
3150 FrameTreeNode* bottom_child =
3151 root->child_at(0)->child_at(0)->child_at(0)->child_at(0);
3152 EXPECT_TRUE(bottom_child->current_url().is_empty());
3153 EXPECT_FALSE(bottom_child->has_committed_real_load());
3154 }
3155
3156 // Ensures that nested subframes with the same URL but different fragments can
3157 // only be nested once. See https://crbug.com/650332.
3158 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
3159 SelfReferencingFragmentFrames) {
3160 StartEmbeddedServer();
3161 GURL url(
3162 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html#123"));
3163 EXPECT_TRUE(NavigateToURL(shell(), url));
3164
3165 WebContentsImpl* web_contents =
3166 static_cast<WebContentsImpl*>(shell()->web_contents());
3167
3168 FrameTreeNode* root = web_contents->GetFrameTree()->root();
3169 FrameTreeNode* child = root->child_at(0);
3170
3171 // ExecuteScript is used here and once more below because it is important to
3172 // use renderer-initiated navigations since browser-initiated navigations are
3173 // bypassed in the self-referencing navigation check.
3174 TestFrameNavigationObserver observer1(child);
3175 EXPECT_TRUE(
3176 ExecuteScript(child, "location.href = '" + url.spec() + "456" + "';"));
3177 observer1.Wait();
3178
3179 FrameTreeNode* grandchild = child->child_at(0);
3180 GURL expected_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
3181 EXPECT_EQ(expected_url, grandchild->current_url());
3182
3183 // This navigation should be blocked.
3184 GURL blocked_url(embedded_test_server()->GetURL(
3185 "a.com", "/page_with_iframe.html#123456789"));
3186 TestNavigationManager manager(web_contents, blocked_url);
3187 EXPECT_TRUE(ExecuteScript(grandchild,
3188 "location.href = '" + blocked_url.spec() + "';"));
3189 // Wait for WillStartRequest and verify that the request is aborted before
3190 // starting it.
3191 EXPECT_FALSE(manager.WaitForRequestStart());
3192 WaitForLoadStop(web_contents);
3193
3194 // The FrameTree contains two successful instances of the url plus an
3195 // unsuccessfully-navigated third instance with a blank URL.
3196 EXPECT_EQ(
3197 " Site A\n"
3198 " +--Site A\n"
3199 " +--Site A\n"
3200 "Where A = http://a.com/",
3201 FrameTreeVisualizer().DepictFrameTree(root));
3202
3203 // The URL of the grandchild has not changed.
3204 EXPECT_EQ(expected_url, grandchild->current_url());
3205 }
3206
3207 // Ensure that loading a page with a meta refresh iframe does not cause an
3208 // infinite number of nested iframes to be created. This test loads a page with
3209 // an about:blank iframe where the page injects html containing a meta refresh
3210 // into the iframe. This test then checks that this does not cause infinite
3211 // nested iframes to be created. See https://crbug.com/527367.
3212 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
3213 SelfReferencingMetaRefreshFrames) {
3214 // Load a page with a blank iframe.
3215 StartEmbeddedServer();
3216 GURL url(embedded_test_server()->GetURL(
3217 "a.com", "/page_with_meta_refresh_frame.html"));
3218 NavigateToURLBlockUntilNavigationsComplete(shell(), url, 3);
3219
3220 WebContentsImpl* web_contents =
3221 static_cast<WebContentsImpl*>(shell()->web_contents());
3222
3223 FrameTreeNode* root = web_contents->GetFrameTree()->root();
3224
3225 // The third navigation should fail and be cancelled, leaving a FrameTree with
3226 // a height of 2.
3227 EXPECT_EQ(
3228 " Site A\n"
3229 " +--Site A\n"
3230 " +--Site A\n"
3231 "Where A = http://a.com/",
3232 FrameTreeVisualizer().DepictFrameTree(root));
3233
3234 EXPECT_EQ(GURL(url::kAboutBlankURL),
3235 root->child_at(0)->child_at(0)->current_url());
3236
3237 EXPECT_FALSE(root->child_at(0)->child_at(0)->has_committed_real_load());
3238 }
3239
3240 // Ensure that navigating a subframe to the same URL as its parent twice in a
3241 // row is not blocked by the self-reference check.
3242 // See https://crbug.com/650332.
3243 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest,
3244 SelfReferencingSameURLRenavigation) {
3245 StartEmbeddedServer();
3246 GURL first_url(
3247 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html"));
3248 GURL second_url(first_url.spec() + "#123");
3249 EXPECT_TRUE(NavigateToURL(shell(), first_url));
3250
3251 WebContentsImpl* web_contents =
3252 static_cast<WebContentsImpl*>(shell()->web_contents());
3253
3254 FrameTreeNode* root = web_contents->GetFrameTree()->root();
3255 FrameTreeNode* child = root->child_at(0);
3256
3257 TestFrameNavigationObserver observer1(child);
3258 EXPECT_TRUE(
3259 ExecuteScript(child, "location.href = '" + second_url.spec() + "';"));
3260 observer1.Wait();
3261
3262 EXPECT_EQ(child->current_url(), second_url);
3263
3264 TestFrameNavigationObserver observer2(child);
3265 // This navigation shouldn't be blocked. Blocking should only occur when more
3266 // than one ancestor has the same URL (excluding fragments), and the
3267 // navigating frame's current URL shouldn't count toward that.
3268 EXPECT_TRUE(
3269 ExecuteScript(child, "location.href = '" + first_url.spec() + "';"));
3270 observer2.Wait();
3271
3272 EXPECT_EQ(child->current_url(), first_url);
3273 }
3274
3109 } // namespace content 3275 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.cc ('k') | content/test/data/coreferencingframe_1.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698