| 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 "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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 665 // navigation entries, and the third and fourth, the new navigations, try to. | 665 // navigation entries, and the third and fourth, the new navigations, try to. | 
| 666 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, SubframeOnEmptyPage) { | 666 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, SubframeOnEmptyPage) { | 
| 667   // Navigate to a page to force the renderer process to start. | 667   // Navigate to a page to force the renderer process to start. | 
| 668   EXPECT_TRUE(NavigateToURL(shell(), GURL(url::kAboutBlankURL))); | 668   EXPECT_TRUE(NavigateToURL(shell(), GURL(url::kAboutBlankURL))); | 
| 669   FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 669   FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 
| 670                             ->GetFrameTree() | 670                             ->GetFrameTree() | 
| 671                             ->root(); | 671                             ->root(); | 
| 672 | 672 | 
| 673   // Pop open a new window with no last committed entry. | 673   // Pop open a new window with no last committed entry. | 
| 674   ShellAddedObserver new_shell_observer; | 674   ShellAddedObserver new_shell_observer; | 
| 675   { | 675   EXPECT_TRUE(ExecuteScript(root, "window.open()")); | 
| 676     std::string script = "window.open()"; |  | 
| 677     EXPECT_TRUE(ExecuteScript(root, script)); |  | 
| 678   } |  | 
| 679   Shell* new_shell = new_shell_observer.GetShell(); | 676   Shell* new_shell = new_shell_observer.GetShell(); | 
| 680   ASSERT_NE(new_shell->web_contents(), shell()->web_contents()); | 677   ASSERT_NE(new_shell->web_contents(), shell()->web_contents()); | 
| 681   FrameTreeNode* new_root = | 678   FrameTreeNode* new_root = | 
| 682       static_cast<WebContentsImpl*>(new_shell->web_contents()) | 679       static_cast<WebContentsImpl*>(new_shell->web_contents()) | 
| 683           ->GetFrameTree() | 680           ->GetFrameTree() | 
| 684           ->root(); | 681           ->root(); | 
| 685   EXPECT_FALSE( | 682   EXPECT_FALSE( | 
| 686       new_shell->web_contents()->GetController().GetLastCommittedEntry()); | 683       new_shell->web_contents()->GetController().GetLastCommittedEntry()); | 
| 687 | 684 | 
| 688   // Make a new iframe in it. | 685   // Make a new iframe in it. | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 720     std::string script = "var iframe = document.createElement('iframe');" | 717     std::string script = "var iframe = document.createElement('iframe');" | 
| 721                          "iframe.src = '" + grandchild_url.spec() + "';" | 718                          "iframe.src = '" + grandchild_url.spec() + "';" | 
| 722                          "document.body.appendChild(iframe);"; | 719                          "document.body.appendChild(iframe);"; | 
| 723     EXPECT_TRUE(ExecuteScript(new_root->child_at(0), script)); | 720     EXPECT_TRUE(ExecuteScript(new_root->child_at(0), script)); | 
| 724     capturer.Wait(); | 721     capturer.Wait(); | 
| 725   } | 722   } | 
| 726   ASSERT_EQ(1U, new_root->child_at(0)->child_count()); | 723   ASSERT_EQ(1U, new_root->child_at(0)->child_count()); | 
| 727   EXPECT_EQ(grandchild_url, new_root->child_at(0)->child_at(0)->current_url()); | 724   EXPECT_EQ(grandchild_url, new_root->child_at(0)->child_at(0)->current_url()); | 
| 728 } | 725 } | 
| 729 | 726 | 
|  | 727 // Test that the renderer is not killed after an auto subframe navigation if the | 
|  | 728 // main frame appears to change its origin due to a document.write on an | 
|  | 729 // about:blank page.  See https://crbug.com/613732. | 
|  | 730 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 
|  | 731                        OriginChangeAfterDocumentWrite) { | 
|  | 732   GURL url1 = embedded_test_server()->GetURL( | 
|  | 733       "/navigation_controller/simple_page_1.html"); | 
|  | 734   EXPECT_TRUE(NavigateToURL(shell(), url1)); | 
|  | 735   FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 
|  | 736                             ->GetFrameTree() | 
|  | 737                             ->root(); | 
|  | 738 | 
|  | 739   // Pop open a new window to about:blank. | 
|  | 740   ShellAddedObserver new_shell_observer; | 
|  | 741   EXPECT_TRUE(ExecuteScript(root, "var w = window.open('about:blank')")); | 
|  | 742   Shell* new_shell = new_shell_observer.GetShell(); | 
|  | 743   ASSERT_NE(new_shell->web_contents(), shell()->web_contents()); | 
|  | 744   FrameTreeNode* new_root = | 
|  | 745       static_cast<WebContentsImpl*>(new_shell->web_contents()) | 
|  | 746           ->GetFrameTree() | 
|  | 747           ->root(); | 
|  | 748   GURL blank_url(url::kAboutBlankURL); | 
|  | 749   EXPECT_EQ(blank_url, new_root->current_url()); | 
|  | 750 | 
|  | 751   // Make a new iframe in it using document.write from the opener. | 
|  | 752   { | 
|  | 753     LoadCommittedCapturer capturer(new_shell->web_contents()); | 
|  | 754     std::string script = "w.document.write(" | 
|  | 755                          "\"<iframe src='" + url1.spec() + "'></iframe>\");" | 
|  | 756                          "w.document.close();"; | 
|  | 757     EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | 
|  | 758     capturer.Wait(); | 
|  | 759   } | 
|  | 760   ASSERT_EQ(1U, new_root->child_count()); | 
|  | 761   EXPECT_EQ(blank_url, new_root->current_url()); | 
|  | 762   EXPECT_EQ(url1, new_root->child_at(0)->current_url()); | 
|  | 763 | 
|  | 764   // Navigate the subframe. | 
|  | 765   GURL url2 = embedded_test_server()->GetURL( | 
|  | 766       "/navigation_controller/simple_page_2.html"); | 
|  | 767   { | 
|  | 768     LoadCommittedCapturer capturer(new_root->child_at(0)); | 
|  | 769     std::string script = "location.href = '" + url2.spec() + "';"; | 
|  | 770     EXPECT_TRUE(ExecuteScript(new_root->child_at(0), script)); | 
|  | 771     capturer.Wait(); | 
|  | 772   } | 
|  | 773   EXPECT_EQ(blank_url, new_root->current_url()); | 
|  | 774   EXPECT_EQ(url2, new_root->child_at(0)->current_url()); | 
|  | 775   EXPECT_EQ(2, new_shell->web_contents()->GetController().GetEntryCount()); | 
|  | 776 | 
|  | 777   // Do a replace state in the main frame, which changes the URL from | 
|  | 778   // about:blank to the opener's origin, due to the document.write() call. | 
|  | 779   { | 
|  | 780     LoadCommittedCapturer capturer(new_root); | 
|  | 781     std::string script = "history.replaceState({}, 'foo', 'foo');"; | 
|  | 782     EXPECT_TRUE(ExecuteScript(new_root, script)); | 
|  | 783     capturer.Wait(); | 
|  | 784   } | 
|  | 785   EXPECT_EQ(embedded_test_server()->GetURL("/navigation_controller/foo"), | 
|  | 786             new_root->current_url()); | 
|  | 787   EXPECT_EQ(url2, new_root->child_at(0)->current_url()); | 
|  | 788 | 
|  | 789   // Go back in the subframe.  Note that the main frame's URL looks like a | 
|  | 790   // cross-origin change from a web URL to about:blank. | 
|  | 791   { | 
|  | 792     TestNavigationObserver observer(new_shell->web_contents(), 1); | 
|  | 793     new_shell->web_contents()->GetController().GoBack(); | 
|  | 794     observer.Wait(); | 
|  | 795   } | 
|  | 796   EXPECT_TRUE(new_root->current_frame_host()->IsRenderFrameLive()); | 
|  | 797 | 
|  | 798   // Go forward in the subframe.  Note that the main frame's URL looks like a | 
|  | 799   // cross-origin change from about:blank to a web URL. | 
|  | 800   { | 
|  | 801     TestNavigationObserver observer(new_shell->web_contents(), 1); | 
|  | 802     new_shell->web_contents()->GetController().GoForward(); | 
|  | 803     observer.Wait(); | 
|  | 804   } | 
|  | 805   EXPECT_TRUE(new_root->current_frame_host()->IsRenderFrameLive()); | 
|  | 806 } | 
|  | 807 | 
| 730 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 808 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 
| 731                        ErrorPageReplacement) { | 809                        ErrorPageReplacement) { | 
| 732   NavigationController& controller = shell()->web_contents()->GetController(); | 810   NavigationController& controller = shell()->web_contents()->GetController(); | 
| 733   GURL error_url( | 811   GURL error_url( | 
| 734       net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); | 812       net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); | 
| 735   BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 813   BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 
| 736                           base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); | 814                           base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); | 
| 737 | 815 | 
| 738   NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 816   NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 
| 739   EXPECT_EQ(1, controller.GetEntryCount()); | 817   EXPECT_EQ(1, controller.GetEntryCount()); | 
| (...skipping 3751 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4491     // TODO(clamy): Check the post id as well when PlzNavigate handles it | 4569     // TODO(clamy): Check the post id as well when PlzNavigate handles it | 
| 4492     // properly. | 4570     // properly. | 
| 4493     if (!IsBrowserSideNavigationEnabled()) | 4571     if (!IsBrowserSideNavigationEnabled()) | 
| 4494       EXPECT_NE(-1, frame_entry->post_id()); | 4572       EXPECT_NE(-1, frame_entry->post_id()); | 
| 4495     EXPECT_FALSE(entry->GetHasPostData()); | 4573     EXPECT_FALSE(entry->GetHasPostData()); | 
| 4496     EXPECT_EQ(-1, entry->GetPostID()); | 4574     EXPECT_EQ(-1, entry->GetPostID()); | 
| 4497   } | 4575   } | 
| 4498 } | 4576 } | 
| 4499 | 4577 | 
| 4500 }  // namespace content | 4578 }  // namespace content | 
| OLD | NEW | 
|---|