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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698