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 <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 6891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6902 | 6902 |
6903 // Verify that the extra header was NOT present for the subresource. | 6903 // Verify that the extra header was NOT present for the subresource. |
6904 const net::test_server::HttpRequest* image_request = | 6904 const net::test_server::HttpRequest* image_request = |
6905 FindAccumulatedRequest(image_url); | 6905 FindAccumulatedRequest(image_url); |
6906 ASSERT_TRUE(image_request); | 6906 ASSERT_TRUE(image_request); |
6907 EXPECT_THAT(image_request->headers, | 6907 EXPECT_THAT(image_request->headers, |
6908 testing::Not(testing::Contains( | 6908 testing::Not(testing::Contains( |
6909 testing::Key("X-ExtraHeadersVsSubresources")))); | 6909 testing::Key("X-ExtraHeadersVsSubresources")))); |
6910 } | 6910 } |
6911 | 6911 |
| 6912 // Test that a same-page navigation does not lead to the deletion of the |
| 6913 // NavigationHandle for an ongoing different page navigation. |
| 6914 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 6915 SamePageNavigationDoesntDeleteNavigationHandle) { |
| 6916 const GURL kURL1 = embedded_test_server()->GetURL("/title1.html"); |
| 6917 const GURL kPushStateURL = |
| 6918 embedded_test_server()->GetURL("/title1.html#fragment"); |
| 6919 const GURL kURL2 = embedded_test_server()->GetURL("/title2.html"); |
| 6920 |
| 6921 // Navigate to the initial page. |
| 6922 EXPECT_TRUE(NavigateToURL(shell(), kURL1)); |
| 6923 RenderFrameHostImpl* main_frame = |
| 6924 static_cast<WebContentsImpl*>(shell()->web_contents())->GetMainFrame(); |
| 6925 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 6926 ->GetFrameTree() |
| 6927 ->root(); |
| 6928 EXPECT_FALSE(main_frame->navigation_handle()); |
| 6929 EXPECT_FALSE(root->navigation_request()); |
| 6930 |
| 6931 // Start navigating to the second page. |
| 6932 TestNavigationManager manager(shell()->web_contents(), kURL2); |
| 6933 shell()->web_contents()->GetController().LoadURL( |
| 6934 kURL2, Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 6935 EXPECT_TRUE(manager.WaitForRequestStart()); |
| 6936 |
| 6937 // This should create a NavigationHandle. |
| 6938 if (IsBrowserSideNavigationEnabled()) { |
| 6939 EXPECT_TRUE(root->navigation_request()); |
| 6940 } else { |
| 6941 EXPECT_TRUE(main_frame->navigation_handle()); |
| 6942 } |
| 6943 |
| 6944 // The current page does a PushState. |
| 6945 std::string push_state = |
| 6946 "var stateObj = {}; history.pushState(stateObj, \"title 1\", \"" + |
| 6947 kPushStateURL.spec() + "\");"; |
| 6948 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), push_state)); |
| 6949 NavigationEntry* last_committed = |
| 6950 shell()->web_contents()->GetController().GetLastCommittedEntry(); |
| 6951 ASSERT_TRUE(last_committed); |
| 6952 EXPECT_EQ(kPushStateURL, last_committed->GetURL()); |
| 6953 |
| 6954 // This shouldn't affect the ongoing navigation. |
| 6955 if (IsBrowserSideNavigationEnabled()) { |
| 6956 EXPECT_TRUE(root->navigation_request()); |
| 6957 } else { |
| 6958 EXPECT_TRUE(main_frame->navigation_handle()); |
| 6959 } |
| 6960 |
| 6961 // Let the navigation finish. It should commit successfully. |
| 6962 manager.WaitForNavigationFinished(); |
| 6963 last_committed = |
| 6964 shell()->web_contents()->GetController().GetLastCommittedEntry(); |
| 6965 ASSERT_TRUE(last_committed); |
| 6966 EXPECT_EQ(kURL2, last_committed->GetURL()); |
| 6967 } |
| 6968 |
| 6969 class NavigationHandleCommitObserver : public WebContentsObserver { |
| 6970 public: |
| 6971 NavigationHandleCommitObserver(WebContents* web_contents, const GURL& url) |
| 6972 : WebContentsObserver(web_contents), |
| 6973 url_(url), |
| 6974 has_committed_(false), |
| 6975 was_same_page_(false), |
| 6976 was_renderer_initiated_(false) {} |
| 6977 |
| 6978 bool has_committed() const { return has_committed_; } |
| 6979 bool was_same_page() const { return was_same_page_; } |
| 6980 bool was_renderer_initiated() const { return was_renderer_initiated_; } |
| 6981 |
| 6982 private: |
| 6983 void DidFinishNavigation(NavigationHandle* handle) override { |
| 6984 if (handle->GetURL() != url_) |
| 6985 return; |
| 6986 has_committed_ = true; |
| 6987 was_same_page_ = handle->IsSamePage(); |
| 6988 was_renderer_initiated_ = handle->IsRendererInitiated(); |
| 6989 } |
| 6990 |
| 6991 const GURL url_; |
| 6992 bool has_committed_; |
| 6993 bool was_same_page_; |
| 6994 bool was_renderer_initiated_; |
| 6995 }; |
| 6996 |
| 6997 // Tests that a same-page browser-initiated navigation is properly rported by |
| 6998 // the NavigationHandle. |
| 6999 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 7000 SamePageBrowserInitiated) { |
| 7001 const GURL kURL = embedded_test_server()->GetURL("/title1.html"); |
| 7002 const GURL kFragmentURL = |
| 7003 embedded_test_server()->GetURL("/title1.html#fragment"); |
| 7004 |
| 7005 // Navigate to the initial page. |
| 7006 EXPECT_TRUE(NavigateToURL(shell(), kURL)); |
| 7007 |
| 7008 // Do a browser-initiated fragment navigation. |
| 7009 NavigationHandleCommitObserver handle_observer(shell()->web_contents(), |
| 7010 kFragmentURL); |
| 7011 EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); |
| 7012 |
| 7013 EXPECT_TRUE(handle_observer.has_committed()); |
| 7014 EXPECT_TRUE(handle_observer.was_same_page()); |
| 7015 EXPECT_FALSE(handle_observer.was_renderer_initiated()); |
| 7016 } |
| 7017 |
6912 } // namespace content | 7018 } // namespace content |
OLD | NEW |