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

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: Add document.close() to tests. 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 "iframe.contentWindow.document.close();";
4207 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script));
4208
4209 // Click the link to do an in-page navigation. Due to the document.write, the
4210 // new URL matches the parent frame's URL.
4211 GURL frame_url_2(embedded_test_server()->GetURL(
4212 "/navigation_controller/page_with_links.html#frag"));
4213 std::string link_script = "document.getElementById('fraglink').click()";
4214 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script));
4215 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4216 EXPECT_EQ(2, controller.GetEntryCount());
4217 EXPECT_EQ(2, RendererHistoryLength(shell()));
4218 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4219 EXPECT_EQ(frame_url_2, frame->current_url());
4220
4221 // Go back.
4222 {
4223 TestNavigationObserver observer(shell()->web_contents(), 1);
4224 controller.GoBack();
4225 observer.Wait();
4226 }
4227
4228 // Verify the process is still alive by running script. We can't just call
4229 // IsRenderFrameLive after the navigation since it might not have disconnected
4230 // yet.
4231 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;"));
4232 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4233
4234 EXPECT_EQ(blank_url, frame->current_url());
4235 }
4236
4237 // Test for in-page navigation kills when going back to about:blank in an iframe
4238 // of a data URL, after a document.write. This differs from
4239 // BackAfterIframeDocumentWrite because both about:blank and the data URL are
4240 // considered unique origins. See https://crbug.com/446959.
4241 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4242 BackAfterIframeDocumentWriteInDataURL) {
4243 GURL data_url("data:text/html,Top level page");
4244 NavigateToURL(shell(), data_url);
4245 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4246
4247 NavigationController& controller = shell()->web_contents()->GetController();
4248 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4249 ->GetFrameTree()
4250 ->root();
4251
4252 EXPECT_EQ(1, controller.GetEntryCount());
4253 EXPECT_EQ(1, RendererHistoryLength(shell()));
4254
4255 // Add an iframe with no 'src'.
4256 GURL blank_url(url::kAboutBlankURL);
4257 std::string script =
4258 "var iframe = document.createElement('iframe');"
4259 "iframe.id = 'frame';"
4260 "document.body.appendChild(iframe);";
4261 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script));
4262 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4263 EXPECT_EQ(1, controller.GetEntryCount());
4264 EXPECT_EQ(1, RendererHistoryLength(shell()));
4265 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4266 ASSERT_EQ(1U, root->child_count());
4267 FrameTreeNode* frame = root->child_at(0);
4268 ASSERT_NE(nullptr, frame);
4269 EXPECT_EQ(blank_url, frame->current_url());
4270
4271 // Do a document.write in the subframe to create a link to click.
4272 std::string document_write_script =
4273 "var iframe = document.getElementById('frame');"
4274 "iframe.contentWindow.document.write("
4275 " \"<a id='fraglink' href='#frag'>fragment link</a>\");"
4276 "iframe.contentWindow.document.close();";
4277 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script));
4278
4279 // Click the link to do an in-page navigation. Due to the document.write, the
4280 // new URL matches the parent frame's URL.
4281 GURL frame_url_2("data:text/html,Top level page#frag");
4282 std::string link_script = "document.getElementById('fraglink').click()";
4283 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script));
4284 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4285 EXPECT_EQ(2, controller.GetEntryCount());
4286 EXPECT_EQ(2, RendererHistoryLength(shell()));
4287 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4288 EXPECT_EQ(frame_url_2, frame->current_url());
4289
4290 // Go back.
4291 {
4292 TestNavigationObserver observer(shell()->web_contents(), 1);
4293 controller.GoBack();
4294 observer.Wait();
4295 }
4296
4297 // Verify the process is still alive by running script. We can't just call
4298 // IsRenderFrameLive after the navigation since it might not have disconnected
4299 // yet.
4300 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;"));
4301 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4302
4303 EXPECT_EQ(blank_url, frame->current_url());
4304 }
4305
4168 // Ensure that we do not corrupt a NavigationEntry's PageState if a subframe 4306 // Ensure that we do not corrupt a NavigationEntry's PageState if a subframe
4169 // forward navigation commits after we've already started another forward 4307 // forward navigation commits after we've already started another forward
4170 // navigation in the main frame. See https://crbug.com/597322. 4308 // navigation in the main frame. See https://crbug.com/597322.
4171 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 4309 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4172 ForwardInSubframeWithPendingForward) { 4310 ForwardInSubframeWithPendingForward) {
4173 // Navigate to a page with an iframe. 4311 // Navigate to a page with an iframe.
4174 GURL url_a(embedded_test_server()->GetURL( 4312 GURL url_a(embedded_test_server()->GetURL(
4175 "/navigation_controller/page_with_data_iframe.html")); 4313 "/navigation_controller/page_with_data_iframe.html"));
4176 GURL frame_url_a1("data:text/html,Subframe"); 4314 GURL frame_url_a1("data:text/html,Subframe");
4177 EXPECT_TRUE(NavigateToURL(shell(), url_a)); 4315 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 4501 // TODO(clamy): Check the post id as well when PlzNavigate handles it
4364 // properly. 4502 // properly.
4365 if (!IsBrowserSideNavigationEnabled()) 4503 if (!IsBrowserSideNavigationEnabled())
4366 EXPECT_NE(-1, frame_entry->post_id()); 4504 EXPECT_NE(-1, frame_entry->post_id());
4367 EXPECT_FALSE(entry->GetHasPostData()); 4505 EXPECT_FALSE(entry->GetHasPostData());
4368 EXPECT_EQ(-1, entry->GetPostID()); 4506 EXPECT_EQ(-1, entry->GetPostID());
4369 } 4507 }
4370 } 4508 }
4371 4509
4372 } // namespace content 4510 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698