| 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 4910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4921 // the body of the page. | 4921 // the body of the page. |
| 4922 std::string body; | 4922 std::string body; |
| 4923 EXPECT_TRUE(ExecuteScriptAndExtractString( | 4923 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 4924 shell()->web_contents(), | 4924 shell()->web_contents(), |
| 4925 "window.domAutomationController.send(" | 4925 "window.domAutomationController.send(" |
| 4926 "document.getElementsByTagName('pre')[0].innerText);", | 4926 "document.getElementsByTagName('pre')[0].innerText);", |
| 4927 &body)); | 4927 &body)); |
| 4928 EXPECT_EQ("text=value\n", body); | 4928 EXPECT_EQ("text=value\n", body); |
| 4929 } | 4929 } |
| 4930 | 4930 |
| 4931 // Test that navigations classified as SAME_PAGE properly update all the |
| 4932 // members of FrameNavigationEntry. If not, it is possible to get a mismatch |
| 4933 // between the origin and URL of a document as seen in |
| 4934 // https://crbug.com/630103. |
| 4935 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 4936 EnsureSamePageNavigationUpdatesFrameNavigationEntry) { |
| 4937 WebContentsImpl* web_contents = |
| 4938 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 4939 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 4940 |
| 4941 // Navigate to a simple page and then perform an in-page navigation. |
| 4942 GURL start_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 4943 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 4944 |
| 4945 GURL same_page_url( |
| 4946 embedded_test_server()->GetURL("a.com", "/title1.html#foo")); |
| 4947 EXPECT_TRUE(NavigateToURL(shell(), same_page_url)); |
| 4948 EXPECT_EQ(2, web_contents->GetController().GetEntryCount()); |
| 4949 |
| 4950 // Replace the URL of the current NavigationEntry with one that will cause |
| 4951 // a server redirect when loaded. |
| 4952 { |
| 4953 GURL redirect_dest_url( |
| 4954 embedded_test_server()->GetURL("sub.a.com", "/simple_page.html")); |
| 4955 TestNavigationObserver observer(web_contents); |
| 4956 std::string script = "history.replaceState({}, '', '/server-redirect?" + |
| 4957 redirect_dest_url.spec() + "')"; |
| 4958 EXPECT_TRUE(ExecuteScript(root, script)); |
| 4959 observer.Wait(); |
| 4960 } |
| 4961 |
| 4962 // Simulate the user hitting Enter in the omnibox without changing the URL. |
| 4963 { |
| 4964 TestNavigationObserver observer(web_contents); |
| 4965 web_contents->GetController().LoadURL(web_contents->GetLastCommittedURL(), |
| 4966 Referrer(), ui::PAGE_TRANSITION_LINK, |
| 4967 std::string()); |
| 4968 observer.Wait(); |
| 4969 } |
| 4970 |
| 4971 // Prior to fixing the issue, the above omnibox navigation (which is |
| 4972 // classified as SAME_PAGE) was leaving the FrameNavigationEntry with the |
| 4973 // same document sequence number as the previous entry but updates the URL. |
| 4974 // Doing a back session history navigation now will cause the browser to |
| 4975 // consider it as in-page because of this matching document sequence number |
| 4976 // and lead to a mismatch of origin and URL in the renderer process. |
| 4977 { |
| 4978 TestNavigationObserver observer(web_contents); |
| 4979 web_contents->GetController().GoBack(); |
| 4980 observer.Wait(); |
| 4981 } |
| 4982 |
| 4983 // Verify the expected origin through JavaScript. It also has the additional |
| 4984 // verification of the process also being still alive. |
| 4985 std::string origin; |
| 4986 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 4987 web_contents, "domAutomationController.send(document.origin)", &origin)); |
| 4988 EXPECT_EQ(start_url.GetOrigin().spec(), origin + "/"); |
| 4989 } |
| 4990 |
| 4931 } // namespace content | 4991 } // namespace content |
| OLD | NEW |