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

Side by Side Diff: content/browser/tab_contents/navigation_controller_unittest.cc

Issue 6993037: Ensure address bar is reset after a redirect turns into a download. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments. Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/tab_contents/tab_contents.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 // This should clear the pending entry and notify of a navigation state 407 // This should clear the pending entry and notify of a navigation state
408 // change, so that we do not keep displaying kNewURL. 408 // change, so that we do not keep displaying kNewURL.
409 EXPECT_EQ(-1, controller().pending_entry_index()); 409 EXPECT_EQ(-1, controller().pending_entry_index());
410 EXPECT_FALSE(controller().pending_entry()); 410 EXPECT_FALSE(controller().pending_entry());
411 EXPECT_EQ(-1, controller().last_committed_entry_index()); 411 EXPECT_EQ(-1, controller().last_committed_entry_index());
412 EXPECT_EQ(2, delegate->navigation_state_change_count()); 412 EXPECT_EQ(2, delegate->navigation_state_change_count());
413 413
414 contents()->set_delegate(NULL); 414 contents()->set_delegate(NULL);
415 } 415 }
416 416
417 // Tests that the pending entry state is correct after an abort.
418 TEST_F(NavigationControllerTest, LoadURL_AbortCancelsPending) {
419 TestNotificationTracker notifications;
420 RegisterForAllNavNotifications(&notifications, &controller());
421
422 // Set a TabContentsDelegate to listen for state changes.
423 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate());
424 EXPECT_FALSE(contents()->delegate());
425 contents()->set_delegate(delegate.get());
426
427 // Without any navigations, the renderer starts at about:blank.
428 const GURL kExistingURL("about:blank");
429
430 // Now make a pending new navigation.
431 const GURL kNewURL("http://eh");
432 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED);
433 EXPECT_EQ(0U, notifications.size());
434 EXPECT_EQ(-1, controller().pending_entry_index());
435 EXPECT_TRUE(controller().pending_entry());
436 EXPECT_EQ(-1, controller().last_committed_entry_index());
437 EXPECT_EQ(1, delegate->navigation_state_change_count());
438
439 // It may abort before committing, if it's a download or due to a stop or
440 // a new navigation from the user.
441 rvh()->TestOnMessageReceived(
442 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
443 1, // frame_id
444 true, // is_main_frame
445 net::ERR_ABORTED, // error
446 kNewURL, // url
447 false)); // repost
448
449 // This should clear the pending entry and notify of a navigation state
450 // change, so that we do not keep displaying kNewURL.
451 EXPECT_EQ(-1, controller().pending_entry_index());
452 EXPECT_FALSE(controller().pending_entry());
453 EXPECT_EQ(-1, controller().last_committed_entry_index());
454 EXPECT_EQ(2, delegate->navigation_state_change_count());
455
456 contents()->set_delegate(NULL);
457 }
458
459 // Tests that the pending entry state is correct after a redirect and abort.
460 // http://crbug.com/83031.
461 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortCancelsPending) {
462 TestNotificationTracker notifications;
463 RegisterForAllNavNotifications(&notifications, &controller());
464
465 // Set a TabContentsDelegate to listen for state changes.
466 scoped_ptr<TestTabContentsDelegate> delegate(new TestTabContentsDelegate());
467 EXPECT_FALSE(contents()->delegate());
468 contents()->set_delegate(delegate.get());
469
470 // Without any navigations, the renderer starts at about:blank.
471 const GURL kExistingURL("about:blank");
472
473 // Now make a pending new navigation.
474 const GURL kNewURL("http://eh");
475 controller().LoadURL(kNewURL, GURL(), PageTransition::TYPED);
476 EXPECT_EQ(0U, notifications.size());
477 EXPECT_EQ(-1, controller().pending_entry_index());
478 EXPECT_TRUE(controller().pending_entry());
479 EXPECT_EQ(-1, controller().last_committed_entry_index());
480 EXPECT_EQ(1, delegate->navigation_state_change_count());
481
482 // Now the navigation redirects.
483 const GURL kRedirectURL("http://bee");
484 rvh()->TestOnMessageReceived(
485 ViewHostMsg_DidRedirectProvisionalLoad(0, // routing_id
486 -1, // pending page_id
487 false, // opener
488 kNewURL, // old url
489 kRedirectURL)); // new url
490
491 // We don't want to change the NavigationEntry's url, in case it cancels.
492 // Prevents regression of http://crbug.com/77786.
493 EXPECT_EQ(kNewURL, controller().pending_entry()->url());
494
495 // It may abort before committing, if it's a download or due to a stop or
496 // a new navigation from the user.
497 rvh()->TestOnMessageReceived(
498 ViewHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
499 1, // frame_id
500 true, // is_main_frame
501 net::ERR_ABORTED, // error
502 kRedirectURL, // url
503 false)); // repost
504
505 // This should clear the pending entry and notify of a navigation state
506 // change, so that we do not keep displaying kNewURL.
507 EXPECT_EQ(-1, controller().pending_entry_index());
508 EXPECT_FALSE(controller().pending_entry());
509 EXPECT_EQ(-1, controller().last_committed_entry_index());
510 EXPECT_EQ(2, delegate->navigation_state_change_count());
511
512 contents()->set_delegate(NULL);
513 }
514
417 TEST_F(NavigationControllerTest, Reload) { 515 TEST_F(NavigationControllerTest, Reload) {
418 TestNotificationTracker notifications; 516 TestNotificationTracker notifications;
419 RegisterForAllNavNotifications(&notifications, &controller()); 517 RegisterForAllNavNotifications(&notifications, &controller());
420 518
421 const GURL url1("http://foo1"); 519 const GURL url1("http://foo1");
422 520
423 controller().LoadURL(url1, GURL(), PageTransition::TYPED); 521 controller().LoadURL(url1, GURL(), PageTransition::TYPED);
424 EXPECT_EQ(0U, notifications.size()); 522 EXPECT_EQ(0U, notifications.size());
425 rvh()->SendNavigate(0, url1); 523 rvh()->SendNavigate(0, url1);
426 EXPECT_TRUE(notifications.Check1AndReset( 524 EXPECT_TRUE(notifications.Check1AndReset(
(...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 TabNavigation nav(0, url0, GURL(), string16(), 2343 TabNavigation nav(0, url0, GURL(), string16(),
2246 webkit_glue::CreateHistoryStateForURL(url0), 2344 webkit_glue::CreateHistoryStateForURL(url0),
2247 PageTransition::LINK); 2345 PageTransition::LINK);
2248 session_helper_.AssertNavigationEquals(nav, 2346 session_helper_.AssertNavigationEquals(nav,
2249 windows_[0]->tabs[0]->navigations[0]); 2347 windows_[0]->tabs[0]->navigations[0]);
2250 nav.set_url(url2); 2348 nav.set_url(url2);
2251 session_helper_.AssertNavigationEquals(nav, 2349 session_helper_.AssertNavigationEquals(nav,
2252 windows_[0]->tabs[0]->navigations[1]); 2350 windows_[0]->tabs[0]->navigations[1]);
2253 } 2351 }
2254 */ 2352 */
OLDNEW
« no previous file with comments | « no previous file | content/browser/tab_contents/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698