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

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

Issue 902083002: Only increment the history list offset if we are not replacing the current item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: with test Created 5 years, 10 months 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
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "content/browser/frame_host/frame_tree.h" 7 #include "content/browser/frame_host/frame_tree.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 15 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
18 #include "content/test/content_browser_test_utils_internal.h" 19 #include "content/test/content_browser_test_utils_internal.h"
19 #include "net/dns/mock_host_resolver.h" 20 #include "net/dns/mock_host_resolver.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 class NavigationControllerBrowserTest : public ContentBrowserTest { 25 class NavigationControllerBrowserTest : public ContentBrowserTest {
25 protected: 26 protected:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // Now try to go back. This should not hang. 82 // Now try to go back. This should not hang.
82 ASSERT_TRUE(controller.CanGoBack()); 83 ASSERT_TRUE(controller.CanGoBack());
83 controller.GoBack(); 84 controller.GoBack();
84 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 85 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
85 86
86 // This should have successfully gone back. 87 // This should have successfully gone back.
87 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)), 88 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)),
88 controller.GetLastCommittedEntry()->GetURL()); 89 controller.GetLastCommittedEntry()->GetURL());
89 } 90 }
90 91
92 namespace {
93
94 int RendererHistoryLength(Shell* shell) {
95 int value = 0;
96 EXPECT_TRUE(ExecuteScriptAndExtractInt(
97 shell->web_contents(),
98 "domAutomationController.send(history.length)",
99 &value));
100 return value;
101 }
102
103 // Similar to the ones from content_browser_test_utils.
104 bool NavigateToURLAndReplace(Shell* shell, const GURL& url) {
105 WebContents* web_contents = shell->web_contents();
106 WaitForLoadStop(web_contents);
107 TestNavigationObserver same_tab_observer(web_contents, 1);
108 NavigationController::LoadURLParams params(url);
109 params.should_replace_current_entry = true;
110 web_contents->GetController().LoadURLWithParams(params);
111 web_contents->Focus();
Charlie Reis 2015/02/06 17:29:35 Is this line needed? I don't see why the focus wo
Avi (use Gerrit) 2015/02/06 17:43:14 In content_browser_test_utils, NavigateToURLBlockU
112 same_tab_observer.Wait();
113 if (!IsLastCommittedEntryOfPageType(web_contents, PAGE_TYPE_NORMAL))
114 return false;
115 return web_contents->GetLastCommittedURL() == url;
116 }
117
118 } // namespace
119
120 // When loading a new page to replace an old page in the history list, make sure
121 // that the browser and renderer agree, and that both get it right.
122 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
123 CorrectLengthWithCurrentItemReplacement) {
124 NavigationController& controller =
125 shell()->web_contents()->GetController();
126
127 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1")));
128 EXPECT_EQ(1, controller.GetEntryCount());
129 EXPECT_EQ(1, RendererHistoryLength(shell()));
130
131 EXPECT_TRUE(NavigateToURLAndReplace(shell(), GURL("data:text/html,page2")));
132 EXPECT_EQ(1, controller.GetEntryCount());
133 EXPECT_EQ(1, RendererHistoryLength(shell()));
134
135 // Note that there's no way to access the renderer's notion of the history
136 // offset via JavaScript. Checking just the history length, though, is enough;
137 // if the replacement failed, there would be a new history entry and thus an
138 // incorrect length.
139 }
140
141 namespace {
142
91 struct FrameNavigateParamsCapturer : public WebContentsObserver { 143 struct FrameNavigateParamsCapturer : public WebContentsObserver {
92 public: 144 public:
93 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) 145 explicit FrameNavigateParamsCapturer(FrameTreeNode* node)
94 : WebContentsObserver( 146 : WebContentsObserver(
95 node->current_frame_host()->delegate()->GetAsWebContents()), 147 node->current_frame_host()->delegate()->GetAsWebContents()),
96 frame_tree_node_id_(node->frame_tree_node_id()), 148 frame_tree_node_id_(node->frame_tree_node_id()),
97 message_loop_runner_(new MessageLoopRunner) {} 149 message_loop_runner_(new MessageLoopRunner) {}
98 150
99 void Wait() { 151 void Wait() {
100 message_loop_runner_->Run(); 152 message_loop_runner_->Run();
(...skipping 27 matching lines...) Expand all
128 // The params of the last navigation. 180 // The params of the last navigation.
129 FrameNavigateParams params_; 181 FrameNavigateParams params_;
130 182
131 // The details of the last navigation. 183 // The details of the last navigation.
132 LoadCommittedDetails details_; 184 LoadCommittedDetails details_;
133 185
134 // The MessageLoopRunner used to spin the message loop. 186 // The MessageLoopRunner used to spin the message loop.
135 scoped_refptr<MessageLoopRunner> message_loop_runner_; 187 scoped_refptr<MessageLoopRunner> message_loop_runner_;
136 }; 188 };
137 189
190 } // namespace
191
138 // Verify that the distinction between manual and auto subframes is properly set 192 // Verify that the distinction between manual and auto subframes is properly set
139 // for subframe navigations. TODO(avi): It's rather bogus that the same info is 193 // for subframe navigations. TODO(avi): It's rather bogus that the same info is
140 // in two different enums; http://crbug.com/453555. 194 // in two different enums; http://crbug.com/453555.
141 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 195 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
142 ManualAndAutoSubframeNavigationClassification) { 196 ManualAndAutoSubframeNavigationClassification) {
143 GURL main_url( 197 GURL main_url(
144 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); 198 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html"));
145 NavigateToURL(shell(), main_url); 199 NavigateToURL(shell(), main_url);
146 200
147 // It is safe to obtain the root frame tree node here, as it doesn't change. 201 // It is safe to obtain the root frame tree node here, as it doesn't change.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 embedded_test_server()->GetURL("/frame_tree/2-3.html")); 243 embedded_test_server()->GetURL("/frame_tree/2-3.html"));
190 NavigateFrameToURL(root->child_at(0), frame_url); 244 NavigateFrameToURL(root->child_at(0), frame_url);
191 capturer.Wait(); 245 capturer.Wait();
192 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 246 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
193 capturer.params().transition); 247 capturer.params().transition);
194 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 248 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
195 } 249 }
196 } 250 }
197 251
198 } // namespace content 252 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698