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

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

Issue 1309323004: Create a NavigationEntry for the initial blank page. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GetEntryCount, more tests Created 5 years, 2 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
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 "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/frame_navigation_entry.h" 8 #include "content/browser/frame_host/frame_navigation_entry.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/navigation_controller_impl.h" 10 #include "content/browser/frame_host/navigation_controller_impl.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 } // namespace 174 } // namespace
175 175
176 // When loading a new page to replace an old page in the history list, make sure 176 // When loading a new page to replace an old page in the history list, make sure
177 // that the browser and renderer agree, and that both get it right. 177 // that the browser and renderer agree, and that both get it right.
178 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 178 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
179 CorrectLengthWithCurrentItemReplacement) { 179 CorrectLengthWithCurrentItemReplacement) {
180 NavigationController& controller = 180 NavigationController& controller =
181 shell()->web_contents()->GetController(); 181 shell()->web_contents()->GetController();
182 182
183 // Before any navigation begins, we have one entry in the NavigationController
184 // for the initial about:blank, but the renderer thinks the history is empty.
185 // TODO(creis): Fix https://crbug.com/521729 and verify RendererHistoryLength
186 // is 0 before the first navigation. (Or check in a popup.)
187 EXPECT_EQ(1, controller.GetEntryCount());
188
183 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1"))); 189 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,page1")));
184 EXPECT_EQ(1, controller.GetEntryCount()); 190 EXPECT_EQ(1, controller.GetEntryCount());
185 EXPECT_EQ(1, RendererHistoryLength(shell())); 191 EXPECT_EQ(1, RendererHistoryLength(shell()));
186 192
187 EXPECT_TRUE(NavigateToURLAndReplace(shell(), GURL("data:text/html,page1a"))); 193 EXPECT_TRUE(NavigateToURLAndReplace(shell(), GURL("data:text/html,page1a")));
188 EXPECT_EQ(1, controller.GetEntryCount()); 194 EXPECT_EQ(1, controller.GetEntryCount());
189 EXPECT_EQ(1, RendererHistoryLength(shell())); 195 EXPECT_EQ(1, RendererHistoryLength(shell()));
190 196
191 // Now create two more entries and go back, to test replacing an entry without 197 // Now create two more entries and go back, to test replacing an entry without
192 // pruning the forward history. 198 // pruning the forward history.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host, 260 void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
255 const LoadCommittedDetails& details, 261 const LoadCommittedDetails& details,
256 const FrameNavigateParams& params) override { 262 const FrameNavigateParams& params) override {
257 FAIL() << "No navigations should occur"; 263 FAIL() << "No navigations should occur";
258 } 264 }
259 }; 265 };
260 266
261 } // namespace 267 } // namespace
262 268
263 // Some pages create a popup, then write an iframe into it. This causes a 269 // Some pages create a popup, then write an iframe into it. This causes a
264 // subframe navigation without having any committed entry. Such navigations 270 // subframe navigation on the initial blank committed entry.
265 // just get thrown on the ground, but we shouldn't crash.
266 // 271 //
267 // This test actually hits NAVIGATION_TYPE_NAV_IGNORE three times. Two of them, 272 // This test actually hits RendererDidNavigate three times. Two of them,
268 // the initial window.open() and the iframe creation, don't try to create 273 // the initial window.open() and the iframe creation, don't try to create
269 // navigation entries, and the third, the new navigation, tries to. 274 // navigation entries, and the third, the new navigation, tries to.
270 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, SubframeOnEmptyPage) { 275 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, SubframeOnEmptyPage) {
271 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 276 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
272 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 277 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
273 278
274 FrameTreeNode* root = 279 FrameTreeNode* root =
275 static_cast<WebContentsImpl*>(shell()->web_contents())-> 280 static_cast<WebContentsImpl*>(shell()->web_contents())->
276 GetFrameTree()->root(); 281 GetFrameTree()->root();
277 282
278 // Pop open a new window. 283 // Pop open a new window.
279 ShellAddedObserver new_shell_observer; 284 ShellAddedObserver new_shell_observer;
280 std::string script = "window.open()"; 285 std::string script = "window.open()";
281 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 286 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
282 Shell* new_shell = new_shell_observer.GetShell(); 287 Shell* new_shell = new_shell_observer.GetShell();
283 ASSERT_NE(new_shell->web_contents(), shell()->web_contents()); 288 ASSERT_NE(new_shell->web_contents(), shell()->web_contents());
284 FrameTreeNode* new_root = 289 FrameTreeNode* new_root =
285 static_cast<WebContentsImpl*>(new_shell->web_contents())-> 290 static_cast<WebContentsImpl*>(new_shell->web_contents())->
286 GetFrameTree()->root(); 291 GetFrameTree()->root();
287 292
288 // Make a new iframe in it. 293 // Make a new iframe in it.
294 // TODO(creis): This should actually navigate.
289 NoNavigationsObserver observer(new_shell->web_contents()); 295 NoNavigationsObserver observer(new_shell->web_contents());
290 script = "var iframe = document.createElement('iframe');" 296 script = "var iframe = document.createElement('iframe');"
291 "iframe.src = 'data:text/html,<p>some page</p>';" 297 "iframe.src = 'data:text/html,<p>some page</p>';"
292 "document.body.appendChild(iframe);"; 298 "document.body.appendChild(iframe);";
293 EXPECT_TRUE(content::ExecuteScript(new_root->current_frame_host(), script)); 299 EXPECT_TRUE(content::ExecuteScript(new_root->current_frame_host(), script));
294 // The success check is of the last-committed entry, and there is none. 300 // The success check is of the last-committed entry, and there is none.
295 WaitForLoadStopWithoutSuccessCheck(new_shell->web_contents()); 301 //WaitForLoadStopWithoutSuccessCheck(new_shell->web_contents());
302 WaitForLoadStop(new_shell->web_contents());
296 303
297 ASSERT_EQ(1U, new_root->child_count()); 304 ASSERT_EQ(1U, new_root->child_count());
298 ASSERT_NE(nullptr, new_root->child_at(0)); 305 ASSERT_NE(nullptr, new_root->child_at(0));
299 306
300 // Navigate it. 307 // Navigate it.
301 GURL frame_url = embedded_test_server()->GetURL( 308 GURL frame_url = embedded_test_server()->GetURL(
302 "/navigation_controller/simple_page_2.html"); 309 "/navigation_controller/simple_page_2.html");
303 script = "location.assign('" + frame_url.spec() + "')"; 310 script = "location.assign('" + frame_url.spec() + "')";
304 EXPECT_TRUE(content::ExecuteScript( 311 EXPECT_TRUE(content::ExecuteScript(
305 new_root->child_at(0)->current_frame_host(), script)); 312 new_root->child_at(0)->current_frame_host(), script));
306 313
307 // Success is not crashing, and not navigating. 314 // TODO(creis): Should be able to go back.
308 EXPECT_EQ(nullptr, 315 // TODO(creis): This currently only works in --site-per-process. I think it's
309 new_shell->web_contents()->GetController().GetLastCommittedEntry()); 316 // because PageState might not get sent if page ID is -1?
310 } 317 }
311 318
312 namespace { 319 namespace {
313 320
314 class FrameNavigateParamsCapturer : public WebContentsObserver { 321 class FrameNavigateParamsCapturer : public WebContentsObserver {
315 public: 322 public:
316 // Observes navigation for the specified |node|. 323 // Observes navigation for the specified |node|.
317 explicit FrameNavigateParamsCapturer(FrameTreeNode* node) 324 explicit FrameNavigateParamsCapturer(FrameTreeNode* node)
318 : WebContentsObserver( 325 : WebContentsObserver(
319 node->current_frame_host()->delegate()->GetAsWebContents()), 326 node->current_frame_host()->delegate()->GetAsWebContents()),
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 EXPECT_EQ(original_url, capturer.all_params()[1].url); 2413 EXPECT_EQ(original_url, capturer.all_params()[1].url);
2407 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); 2414 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL());
2408 } 2415 }
2409 2416
2410 // Make sure the renderer is still alive. 2417 // Make sure the renderer is still alive.
2411 EXPECT_TRUE( 2418 EXPECT_TRUE(
2412 ExecuteScript(shell()->web_contents(), "console.log('Success');")); 2419 ExecuteScript(shell()->web_contents(), "console.log('Success');"));
2413 } 2420 }
2414 2421
2415 } // namespace content 2422 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698