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

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

Issue 2032903007: Allow about:blank to be considered in-page if origin matches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests and add test Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 4147 matching lines...) Expand 10 before | Expand all | Expand 10 after
4158 // frame_url_2. Perhaps we should be going back to frame_url_1 when going 4158 // frame_url_2. Perhaps we should be going back to frame_url_1 when going
4159 // back two entries above, since it's different than the initial blank case. 4159 // back two entries above, since it's different than the initial blank case.
4160 // 4160 //
4161 // TODO(creis): This actually goes to frame_url_2 in some cases when subframe 4161 // TODO(creis): This actually goes to frame_url_2 in some cases when subframe
4162 // FrameNavigationEntries are enabled, due to a mismatch between PageState and 4162 // FrameNavigationEntries are enabled, due to a mismatch between PageState and
4163 // the entry's URL. That should be fixed in https://crbug.com/617239. 4163 // the entry's URL. That should be fixed in https://crbug.com/617239.
4164 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) 4164 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
4165 EXPECT_EQ(frame_url_1, frame->current_url()); 4165 EXPECT_EQ(frame_url_1, frame->current_url());
4166 } 4166 }
4167 4167
4168 // Test for in-page navigation kills when going back to about:blank after a
4169 // document.write. See https://crbug.com/446959.
4170 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4171 BackAfterIframeDocumentWrite) {
4172 GURL links_url(embedded_test_server()->GetURL(
4173 "/navigation_controller/page_with_links.html"));
4174 NavigateToURL(shell(), links_url);
4175 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4176
4177 NavigationController& controller = shell()->web_contents()->GetController();
4178 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4179 ->GetFrameTree()
4180 ->root();
4181
4182 EXPECT_EQ(1, controller.GetEntryCount());
4183 EXPECT_EQ(1, RendererHistoryLength(shell()));
4184
4185 // Add an iframe with no 'src'.
4186 GURL blank_url(url::kAboutBlankURL);
4187 std::string script =
4188 "var iframe = document.createElement('iframe');"
4189 "iframe.id = 'frame';"
4190 "document.body.appendChild(iframe);";
4191 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
4192 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4193 EXPECT_EQ(1, controller.GetEntryCount());
4194 EXPECT_EQ(1, RendererHistoryLength(shell()));
4195 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4196 ASSERT_EQ(1U, root->child_count());
4197 FrameTreeNode* frame = root->child_at(0);
4198 ASSERT_NE(nullptr, frame);
4199 EXPECT_EQ(blank_url, frame->current_url());
4200
4201 // Do a document.write in the subframe to create a link to click.
4202 std::string document_write_script =
4203 "var iframe = document.getElementById('frame');"
4204 "iframe.contentWindow.document.write("
4205 " \"<a id='fraglink' href='#frag'>fragment link</a>\");";
4206 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script));
4207
4208 // Click the link to do an in-page navigation. Due to the document.write, the
4209 // new URL matches the parent frame's URL.
4210 GURL frame_url_2(embedded_test_server()->GetURL(
4211 "/navigation_controller/page_with_links.html#frag"));
4212 std::string link_script = "document.getElementById('fraglink').click()";
4213 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script));
4214 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4215 EXPECT_EQ(2, controller.GetEntryCount());
4216 EXPECT_EQ(2, RendererHistoryLength(shell()));
4217 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4218 EXPECT_EQ(frame_url_2, frame->current_url());
4219
4220 // Go back.
4221 {
4222 TestNavigationObserver observer(shell()->web_contents(), 1);
4223 controller.GoBack();
4224 observer.Wait();
4225 }
4226
4227 // Verify the process is still alive by running script. We can't just call
4228 // IsRenderFrameLive after the navigation since it might not have disconnected
4229 // yet.
4230 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;"));
4231 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4232
4233 EXPECT_EQ(blank_url, frame->current_url());
4234 }
4235
4236 // Test for in-page navigation kills when going back to about:blank in an iframe
4237 // of a data URL, after a document.write. This differs from
4238 // BackAfterIframeDocumentWrite because both about:blank and the data URL are
4239 // considered unique origins. See https://crbug.com/446959.
4240 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4241 BackAfterIframeDocumentWriteInDataURL) {
4242 GURL data_url("data:text/html,Top level page");
4243 NavigateToURL(shell(), data_url);
4244 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4245
4246 NavigationController& controller = shell()->web_contents()->GetController();
4247 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4248 ->GetFrameTree()
4249 ->root();
4250
4251 EXPECT_EQ(1, controller.GetEntryCount());
4252 EXPECT_EQ(1, RendererHistoryLength(shell()));
4253
4254 // Add an iframe with no 'src'.
4255 GURL blank_url(url::kAboutBlankURL);
4256 std::string script =
4257 "var iframe = document.createElement('iframe');"
4258 "iframe.id = 'frame';"
4259 "document.body.appendChild(iframe);";
4260 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
4261 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4262 EXPECT_EQ(1, controller.GetEntryCount());
4263 EXPECT_EQ(1, RendererHistoryLength(shell()));
4264 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4265 ASSERT_EQ(1U, root->child_count());
4266 FrameTreeNode* frame = root->child_at(0);
4267 ASSERT_NE(nullptr, frame);
4268 EXPECT_EQ(blank_url, frame->current_url());
4269
4270 // Do a document.write in the subframe to create a link to click.
4271 std::string document_write_script =
4272 "var iframe = document.getElementById('frame');"
4273 "iframe.contentWindow.document.write("
4274 " \"<a id='fraglink' href='#frag'>fragment link</a>\");";
4275 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script));
4276
4277 // Click the link to do an in-page navigation. Due to the document.write, the
4278 // new URL matches the parent frame's URL.
4279 GURL frame_url_2("data:text/html,Top level page#frag");
4280 std::string link_script = "document.getElementById('fraglink').click()";
4281 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script));
4282 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4283 EXPECT_EQ(2, controller.GetEntryCount());
4284 EXPECT_EQ(2, RendererHistoryLength(shell()));
4285 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4286 EXPECT_EQ(frame_url_2, frame->current_url());
4287
4288 // Go back.
4289 {
4290 TestNavigationObserver observer(shell()->web_contents(), 1);
4291 controller.GoBack();
4292 observer.Wait();
4293 }
4294
4295 // Verify the process is still alive by running script. We can't just call
4296 // IsRenderFrameLive after the navigation since it might not have disconnected
4297 // yet.
4298 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;"));
4299 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4300
4301 EXPECT_EQ(blank_url, frame->current_url());
4302 }
4303
4168 // Ensure that we do not corrupt a NavigationEntry's PageState if a subframe 4304 // Ensure that we do not corrupt a NavigationEntry's PageState if a subframe
4169 // forward navigation commits after we've already started another forward 4305 // forward navigation commits after we've already started another forward
4170 // navigation in the main frame. See https://crbug.com/597322. 4306 // navigation in the main frame. See https://crbug.com/597322.
4171 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 4307 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4172 ForwardInSubframeWithPendingForward) { 4308 ForwardInSubframeWithPendingForward) {
4173 // Navigate to a page with an iframe. 4309 // Navigate to a page with an iframe.
4174 GURL url_a(embedded_test_server()->GetURL( 4310 GURL url_a(embedded_test_server()->GetURL(
4175 "/navigation_controller/page_with_data_iframe.html")); 4311 "/navigation_controller/page_with_data_iframe.html"));
4176 GURL frame_url_a1("data:text/html,Subframe"); 4312 GURL frame_url_a1("data:text/html,Subframe");
4177 EXPECT_TRUE(NavigateToURL(shell(), url_a)); 4313 EXPECT_TRUE(NavigateToURL(shell(), url_a));
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
4363 // TODO(clamy): Check the post id as well when PlzNavigate handles it 4499 // TODO(clamy): Check the post id as well when PlzNavigate handles it
4364 // properly. 4500 // properly.
4365 if (!IsBrowserSideNavigationEnabled()) 4501 if (!IsBrowserSideNavigationEnabled())
4366 EXPECT_NE(-1, frame_entry->post_id()); 4502 EXPECT_NE(-1, frame_entry->post_id());
4367 EXPECT_FALSE(entry->GetHasPostData()); 4503 EXPECT_FALSE(entry->GetHasPostData());
4368 EXPECT_EQ(-1, entry->GetPostID()); 4504 EXPECT_EQ(-1, entry->GetPostID());
4369 } 4505 }
4370 } 4506 }
4371 4507
4372 } // namespace content 4508 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698