| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 "/navigation_controller/simple_page_2.html"); | 302 "/navigation_controller/simple_page_2.html"); |
| 303 script = "location.assign('" + frame_url.spec() + "')"; | 303 script = "location.assign('" + frame_url.spec() + "')"; |
| 304 EXPECT_TRUE(content::ExecuteScript( | 304 EXPECT_TRUE(content::ExecuteScript( |
| 305 new_root->child_at(0)->current_frame_host(), script)); | 305 new_root->child_at(0)->current_frame_host(), script)); |
| 306 | 306 |
| 307 // Success is not crashing, and not navigating. | 307 // Success is not crashing, and not navigating. |
| 308 EXPECT_EQ(nullptr, | 308 EXPECT_EQ(nullptr, |
| 309 new_shell->web_contents()->GetController().GetLastCommittedEntry()); | 309 new_shell->web_contents()->GetController().GetLastCommittedEntry()); |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Similar to SubframeOnEmptyPage, but verifies that in-page navigations on the |
| 313 // initial about:blank document also do not create NavigationEntries. This was |
| 314 // a problem when cloning subframe FrameNavigationEntries in --site-per-process. |
| 315 // See https://crbug.com/522193. |
| 316 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, InPageOnEmptyPage) { |
| 317 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 318 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 319 |
| 320 FrameTreeNode* root = |
| 321 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 322 GetFrameTree()->root(); |
| 323 |
| 324 // Pop open a new window. |
| 325 ShellAddedObserver new_shell_observer; |
| 326 std::string script = "window.open()"; |
| 327 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 328 Shell* new_shell = new_shell_observer.GetShell(); |
| 329 ASSERT_NE(new_shell->web_contents(), shell()->web_contents()); |
| 330 FrameTreeNode* new_root = |
| 331 static_cast<WebContentsImpl*>(new_shell->web_contents())-> |
| 332 GetFrameTree()->root(); |
| 333 |
| 334 // Make a new iframe in it. |
| 335 NoNavigationsObserver observer(new_shell->web_contents()); |
| 336 script = "var iframe = document.createElement('iframe');" |
| 337 "iframe.src = 'data:text/html,<p>some page</p>';" |
| 338 "document.body.appendChild(iframe);"; |
| 339 EXPECT_TRUE(content::ExecuteScript(new_root->current_frame_host(), script)); |
| 340 // The success check is of the last-committed entry, and there is none. |
| 341 WaitForLoadStopWithoutSuccessCheck(new_shell->web_contents()); |
| 342 |
| 343 ASSERT_EQ(1U, new_root->child_count()); |
| 344 ASSERT_NE(nullptr, new_root->child_at(0)); |
| 345 |
| 346 // Navigate in-page in the main frame, which should be ignored. |
| 347 script = "location.href='#foo';"; |
| 348 EXPECT_TRUE(content::ExecuteScript(new_root->current_frame_host(), script)); |
| 349 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 350 EXPECT_EQ(nullptr, |
| 351 new_shell->web_contents()->GetController().GetLastCommittedEntry()); |
| 352 |
| 353 // Make a new nested iframe. Shouldn't crash. |
| 354 script = "var iframe = document.createElement('iframe');" |
| 355 "iframe.src = 'data:text/html,<p>nested page</p>';" |
| 356 "document.body.appendChild(iframe);"; |
| 357 EXPECT_TRUE(content::ExecuteScript( |
| 358 new_root->child_at(0)->current_frame_host(), script)); |
| 359 // The success check is of the last-committed entry, and there is none. |
| 360 WaitForLoadStopWithoutSuccessCheck(new_shell->web_contents()); |
| 361 } |
| 362 |
| 312 namespace { | 363 namespace { |
| 313 | 364 |
| 314 class FrameNavigateParamsCapturer : public WebContentsObserver { | 365 class FrameNavigateParamsCapturer : public WebContentsObserver { |
| 315 public: | 366 public: |
| 316 // Observes navigation for the specified |node|. | 367 // Observes navigation for the specified |node|. |
| 317 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) | 368 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) |
| 318 : WebContentsObserver( | 369 : WebContentsObserver( |
| 319 node->current_frame_host()->delegate()->GetAsWebContents()), | 370 node->current_frame_host()->delegate()->GetAsWebContents()), |
| 320 frame_tree_node_id_(node->frame_tree_node_id()), | 371 frame_tree_node_id_(node->frame_tree_node_id()), |
| 321 navigations_remaining_(1), | 372 navigations_remaining_(1), |
| (...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 2385 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
| 2335 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2386 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 2336 } | 2387 } |
| 2337 | 2388 |
| 2338 // Make sure the renderer is still alive. | 2389 // Make sure the renderer is still alive. |
| 2339 EXPECT_TRUE( | 2390 EXPECT_TRUE( |
| 2340 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2391 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
| 2341 } | 2392 } |
| 2342 | 2393 |
| 2343 } // namespace content | 2394 } // namespace content |
| OLD | NEW |