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

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

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unit tests Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 RegisterForAllNavNotifications(&notifications, &controller); 312 RegisterForAllNavNotifications(&notifications, &controller);
313 313
314 const int kNumUrls = 5; 314 const int kNumUrls = 5;
315 std::vector<GURL> urls(kNumUrls); 315 std::vector<GURL> urls(kNumUrls);
316 for (int i = 0; i < kNumUrls; ++i) { 316 for (int i = 0; i < kNumUrls; ++i) {
317 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); 317 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i));
318 } 318 }
319 319
320 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); 320 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true);
321 main_test_rfh()->PrepareForCommit(); 321 main_test_rfh()->PrepareForCommit();
322 main_test_rfh()->SendNavigate(0, urls[0]); 322 main_test_rfh()->SendNavigate(0, 0, true, urls[0]);
323 EXPECT_EQ(1U, navigation_entry_committed_counter_); 323 EXPECT_EQ(1U, navigation_entry_committed_counter_);
324 navigation_entry_committed_counter_ = 0; 324 navigation_entry_committed_counter_ = 0;
325 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); 325 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL());
326 EXPECT_FALSE(controller.CanGoBack()); 326 EXPECT_FALSE(controller.CanGoBack());
327 EXPECT_FALSE(controller.CanGoForward()); 327 EXPECT_FALSE(controller.CanGoForward());
328 EXPECT_FALSE(controller.CanGoToOffset(1)); 328 EXPECT_FALSE(controller.CanGoToOffset(1));
329 329
330 for (int i = 1; i <= 4; ++i) { 330 for (int i = 1; i <= 4; ++i) {
331 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); 331 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true);
332 main_test_rfh()->PrepareForCommit(); 332 main_test_rfh()->PrepareForCommit();
333 main_test_rfh()->SendNavigate(i, urls[i]); 333 main_test_rfh()->SendNavigate(i, 0, true, urls[i]);
334 EXPECT_EQ(1U, navigation_entry_committed_counter_); 334 EXPECT_EQ(1U, navigation_entry_committed_counter_);
335 navigation_entry_committed_counter_ = 0; 335 navigation_entry_committed_counter_ = 0;
336 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); 336 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL());
337 EXPECT_TRUE(controller.CanGoToOffset(-i)); 337 EXPECT_TRUE(controller.CanGoToOffset(-i));
338 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); 338 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1)));
339 EXPECT_FALSE(controller.CanGoToOffset(1)); 339 EXPECT_FALSE(controller.CanGoToOffset(1));
340 } 340 }
341 341
342 // We have loaded 5 pages, and are currently at the last-loaded page. 342 // We have loaded 5 pages, and are currently at the last-loaded page.
343 int url_index = 4; 343 int url_index = 4;
(...skipping 11 matching lines...) Expand all
355 GO_TO_MIDDLE_PAGE, 355 GO_TO_MIDDLE_PAGE,
356 GO_FORWARDS, 356 GO_FORWARDS,
357 GO_BACKWARDS, 357 GO_BACKWARDS,
358 GO_TO_BEGINNING, 358 GO_TO_BEGINNING,
359 GO_TO_END 359 GO_TO_END
360 }; 360 };
361 361
362 for (int test = 0; test < NUM_TESTS; ++test) { 362 for (int test = 0; test < NUM_TESTS; ++test) {
363 int offset = test_offsets[test]; 363 int offset = test_offsets[test];
364 controller.GoToOffset(offset); 364 controller.GoToOffset(offset);
365 NavigationEntry* entry = controller.GetPendingEntry();
365 url_index += offset; 366 url_index += offset;
366 // Check that the GoToOffset will land on the expected page. 367 // Check that the GoToOffset will land on the expected page.
367 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); 368 EXPECT_EQ(urls[url_index], entry->GetVirtualURL());
368 main_test_rfh()->PrepareForCommit(); 369 main_test_rfh()->PrepareForCommit();
369 main_test_rfh()->SendNavigate(url_index, urls[url_index]); 370 main_test_rfh()->SendNavigate(
371 url_index, entry->GetUniqueID(), false, urls[url_index]);
370 EXPECT_EQ(1U, navigation_entry_committed_counter_); 372 EXPECT_EQ(1U, navigation_entry_committed_counter_);
371 navigation_entry_committed_counter_ = 0; 373 navigation_entry_committed_counter_ = 0;
372 // Check that we can go to any valid offset into the history. 374 // Check that we can go to any valid offset into the history.
373 for (size_t j = 0; j < urls.size(); ++j) 375 for (size_t j = 0; j < urls.size(); ++j)
374 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); 376 EXPECT_TRUE(controller.CanGoToOffset(j - url_index));
375 // Check that we can't go beyond the beginning or end of the history. 377 // Check that we can't go beyond the beginning or end of the history.
376 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); 378 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1)));
377 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); 379 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index));
378 } 380 }
379 } 381 }
(...skipping 24 matching lines...) Expand all
404 EXPECT_EQ(contents()->GetMaxPageID(), -1); 406 EXPECT_EQ(contents()->GetMaxPageID(), -1);
405 407
406 // Neither the timestamp nor the status code should have been set yet. 408 // Neither the timestamp nor the status code should have been set yet.
407 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 409 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
408 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); 410 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode());
409 411
410 // We should have gotten no notifications from the preceeding checks. 412 // We should have gotten no notifications from the preceeding checks.
411 EXPECT_EQ(0U, notifications.size()); 413 EXPECT_EQ(0U, notifications.size());
412 414
413 main_test_rfh()->PrepareForCommit(); 415 main_test_rfh()->PrepareForCommit();
414 main_test_rfh()->SendNavigate(0, url1); 416 main_test_rfh()->SendNavigate(
417 0, controller.GetPendingEntry()->GetUniqueID(), true, url1);
415 EXPECT_EQ(1U, navigation_entry_committed_counter_); 418 EXPECT_EQ(1U, navigation_entry_committed_counter_);
416 navigation_entry_committed_counter_ = 0; 419 navigation_entry_committed_counter_ = 0;
417 420
418 // The load should now be committed. 421 // The load should now be committed.
419 EXPECT_EQ(controller.GetEntryCount(), 1); 422 EXPECT_EQ(controller.GetEntryCount(), 1);
420 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 423 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
421 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 424 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
422 EXPECT_TRUE(controller.GetLastCommittedEntry()); 425 EXPECT_TRUE(controller.GetLastCommittedEntry());
423 EXPECT_FALSE(controller.GetPendingEntry()); 426 EXPECT_FALSE(controller.GetPendingEntry());
424 ASSERT_TRUE(controller.GetVisibleEntry()); 427 ASSERT_TRUE(controller.GetVisibleEntry());
(...skipping 19 matching lines...) Expand all
444 // TODO(darin): maybe this should really be true? 447 // TODO(darin): maybe this should really be true?
445 EXPECT_FALSE(controller.CanGoBack()); 448 EXPECT_FALSE(controller.CanGoBack());
446 EXPECT_FALSE(controller.CanGoForward()); 449 EXPECT_FALSE(controller.CanGoForward());
447 EXPECT_EQ(contents()->GetMaxPageID(), 0); 450 EXPECT_EQ(contents()->GetMaxPageID(), 0);
448 451
449 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); 452 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null());
450 453
451 // Simulate the beforeunload ack for the cross-site transition, and then the 454 // Simulate the beforeunload ack for the cross-site transition, and then the
452 // commit. 455 // commit.
453 main_test_rfh()->PrepareForCommit(); 456 main_test_rfh()->PrepareForCommit();
454 contents()->GetPendingMainFrame()->SendNavigate(1, url2); 457 contents()->GetPendingMainFrame()->SendNavigate(
458 1, controller.GetPendingEntry()->GetUniqueID(), true, url2);
455 EXPECT_EQ(1U, navigation_entry_committed_counter_); 459 EXPECT_EQ(1U, navigation_entry_committed_counter_);
456 navigation_entry_committed_counter_ = 0; 460 navigation_entry_committed_counter_ = 0;
457 461
458 // The load should now be committed. 462 // The load should now be committed.
459 EXPECT_EQ(controller.GetEntryCount(), 2); 463 EXPECT_EQ(controller.GetEntryCount(), 2);
460 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 464 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
461 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 465 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
462 EXPECT_TRUE(controller.GetLastCommittedEntry()); 466 EXPECT_TRUE(controller.GetLastCommittedEntry());
463 EXPECT_FALSE(controller.GetPendingEntry()); 467 EXPECT_FALSE(controller.GetPendingEntry());
464 ASSERT_TRUE(controller.GetVisibleEntry()); 468 ASSERT_TRUE(controller.GetVisibleEntry());
(...skipping 19 matching lines...) Expand all
484 488
485 // Set the clock to always return a timestamp of 1. 489 // Set the clock to always return a timestamp of 1.
486 controller.SetGetTimestampCallbackForTest( 490 controller.SetGetTimestampCallbackForTest(
487 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); 491 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1)));
488 492
489 const GURL url1("http://foo1"); 493 const GURL url1("http://foo1");
490 const GURL url2("http://foo2"); 494 const GURL url2("http://foo2");
491 495
492 controller.LoadURL( 496 controller.LoadURL(
493 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 497 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
498 NavigationEntry* entry = controller.GetPendingEntry();
494 499
495 main_test_rfh()->PrepareForCommit(); 500 main_test_rfh()->PrepareForCommit();
496 main_test_rfh()->SendNavigate(0, url1); 501 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
497 EXPECT_EQ(1U, navigation_entry_committed_counter_); 502 EXPECT_EQ(1U, navigation_entry_committed_counter_);
498 navigation_entry_committed_counter_ = 0; 503 navigation_entry_committed_counter_ = 0;
499 504
500 // Load another... 505 // Load another...
501 controller.LoadURL( 506 controller.LoadURL(
502 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 507 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
508 entry = controller.GetPendingEntry();
503 509
504 // Simulate the beforeunload ack for the cross-site transition, and then the 510 // Simulate the beforeunload ack for the cross-site transition, and then the
505 // commit. 511 // commit.
506 main_test_rfh()->PrepareForCommit(); 512 main_test_rfh()->PrepareForCommit();
507 contents()->GetPendingMainFrame()->SendNavigate(1, url2); 513 contents()->GetPendingMainFrame()->SendNavigate(
514 1, entry->GetUniqueID(), true, url2);
508 EXPECT_EQ(1U, navigation_entry_committed_counter_); 515 EXPECT_EQ(1U, navigation_entry_committed_counter_);
509 navigation_entry_committed_counter_ = 0; 516 navigation_entry_committed_counter_ = 0;
510 517
511 // The two loads should now be committed. 518 // The two loads should now be committed.
512 ASSERT_EQ(controller.GetEntryCount(), 2); 519 ASSERT_EQ(controller.GetEntryCount(), 2);
513 520
514 // Timestamps should be distinct despite the clock returning the 521 // Timestamps should be distinct despite the clock returning the
515 // same value. 522 // same value.
516 EXPECT_EQ(1u, 523 EXPECT_EQ(1u,
517 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); 524 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 // the load commits (because WebCore didn't actually make a new entry). 621 // the load commits (because WebCore didn't actually make a new entry).
615 TEST_F(NavigationControllerTest, LoadURL_SamePage) { 622 TEST_F(NavigationControllerTest, LoadURL_SamePage) {
616 NavigationControllerImpl& controller = controller_impl(); 623 NavigationControllerImpl& controller = controller_impl();
617 TestNotificationTracker notifications; 624 TestNotificationTracker notifications;
618 RegisterForAllNavNotifications(&notifications, &controller); 625 RegisterForAllNavNotifications(&notifications, &controller);
619 626
620 const GURL url1("http://foo1"); 627 const GURL url1("http://foo1");
621 628
622 controller.LoadURL( 629 controller.LoadURL(
623 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 630 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
631 NavigationEntry* entry = controller.GetPendingEntry();
624 EXPECT_EQ(0U, notifications.size()); 632 EXPECT_EQ(0U, notifications.size());
625 main_test_rfh()->PrepareForCommit(); 633 main_test_rfh()->PrepareForCommit();
626 main_test_rfh()->SendNavigate(0, url1); 634 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
627 EXPECT_EQ(1U, navigation_entry_committed_counter_); 635 EXPECT_EQ(1U, navigation_entry_committed_counter_);
628 navigation_entry_committed_counter_ = 0; 636 navigation_entry_committed_counter_ = 0;
629 637
630 ASSERT_TRUE(controller.GetVisibleEntry()); 638 ASSERT_TRUE(controller.GetVisibleEntry());
631 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); 639 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
632 EXPECT_FALSE(timestamp.is_null()); 640 EXPECT_FALSE(timestamp.is_null());
633 641
634 controller.LoadURL( 642 controller.LoadURL(
635 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 643 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
644 entry = controller.GetPendingEntry();
636 EXPECT_EQ(0U, notifications.size()); 645 EXPECT_EQ(0U, notifications.size());
637 main_test_rfh()->PrepareForCommit(); 646 main_test_rfh()->PrepareForCommit();
638 main_test_rfh()->SendNavigate(0, url1); 647 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), false, url1);
639 EXPECT_EQ(1U, navigation_entry_committed_counter_); 648 EXPECT_EQ(1U, navigation_entry_committed_counter_);
640 navigation_entry_committed_counter_ = 0; 649 navigation_entry_committed_counter_ = 0;
641 650
642 // We should not have produced a new session history entry. 651 // We should not have produced a new session history entry.
643 EXPECT_EQ(controller.GetEntryCount(), 1); 652 EXPECT_EQ(controller.GetEntryCount(), 1);
644 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 653 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
645 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 654 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
646 EXPECT_TRUE(controller.GetLastCommittedEntry()); 655 EXPECT_TRUE(controller.GetLastCommittedEntry());
647 EXPECT_FALSE(controller.GetPendingEntry()); 656 EXPECT_FALSE(controller.GetPendingEntry());
648 ASSERT_TRUE(controller.GetVisibleEntry()); 657 ASSERT_TRUE(controller.GetVisibleEntry());
(...skipping 11 matching lines...) Expand all
660 // We should update the post state on the NavigationEntry. 669 // We should update the post state on the NavigationEntry.
661 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) { 670 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) {
662 NavigationControllerImpl& controller = controller_impl(); 671 NavigationControllerImpl& controller = controller_impl();
663 TestNotificationTracker notifications; 672 TestNotificationTracker notifications;
664 RegisterForAllNavNotifications(&notifications, &controller); 673 RegisterForAllNavNotifications(&notifications, &controller);
665 674
666 const GURL url1("http://foo1"); 675 const GURL url1("http://foo1");
667 676
668 controller.LoadURL( 677 controller.LoadURL(
669 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 678 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
679 NavigationEntry* entry = controller.GetPendingEntry();
670 FrameHostMsg_DidCommitProvisionalLoad_Params params; 680 FrameHostMsg_DidCommitProvisionalLoad_Params params;
671 params.page_id = 0; 681 params.page_id = 0;
682 params.nav_entry_id = entry->GetUniqueID();
683 params.did_create_new_entry = true;
672 params.url = url1; 684 params.url = url1;
673 params.transition = ui::PAGE_TRANSITION_TYPED; 685 params.transition = ui::PAGE_TRANSITION_TYPED;
674 params.is_post = true; 686 params.is_post = true;
675 params.post_id = 123; 687 params.post_id = 123;
676 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); 688 params.page_state = PageState::CreateForTesting(url1, false, 0, 0);
677 main_test_rfh()->PrepareForCommit(); 689 main_test_rfh()->PrepareForCommit();
678 main_test_rfh()->SendNavigateWithParams(&params); 690 main_test_rfh()->SendNavigateWithParams(&params);
679 691
680 // The post data should be visible. 692 // The post data should be visible.
681 NavigationEntry* entry = controller.GetVisibleEntry(); 693 entry = controller.GetVisibleEntry();
682 ASSERT_TRUE(entry); 694 ASSERT_TRUE(entry);
683 EXPECT_TRUE(entry->GetHasPostData()); 695 EXPECT_TRUE(entry->GetHasPostData());
684 EXPECT_EQ(entry->GetPostID(), 123); 696 EXPECT_EQ(entry->GetPostID(), 123);
685 697
686 controller.LoadURL( 698 controller.LoadURL(
687 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 699 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
700 entry = controller.GetPendingEntry();
688 main_test_rfh()->PrepareForCommit(); 701 main_test_rfh()->PrepareForCommit();
689 main_test_rfh()->SendNavigate(0, url1); 702 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), false, url1);
690 703
691 // We should not have produced a new session history entry. 704 // We should not have produced a new session history entry.
692 ASSERT_EQ(controller.GetVisibleEntry(), entry); 705 ASSERT_EQ(controller.GetVisibleEntry(), entry);
693 706
694 // The post data should have been cleared due to the GET. 707 // The post data should have been cleared due to the GET.
695 EXPECT_FALSE(entry->GetHasPostData()); 708 EXPECT_FALSE(entry->GetHasPostData());
696 EXPECT_EQ(entry->GetPostID(), 0); 709 EXPECT_EQ(entry->GetPostID(), 0);
697 } 710 }
698 711
699 // Tests loading a URL but discarding it before the load commits. 712 // Tests loading a URL but discarding it before the load commits.
700 TEST_F(NavigationControllerTest, LoadURL_Discarded) { 713 TEST_F(NavigationControllerTest, LoadURL_Discarded) {
701 NavigationControllerImpl& controller = controller_impl(); 714 NavigationControllerImpl& controller = controller_impl();
702 TestNotificationTracker notifications; 715 TestNotificationTracker notifications;
703 RegisterForAllNavNotifications(&notifications, &controller); 716 RegisterForAllNavNotifications(&notifications, &controller);
704 717
705 const GURL url1("http://foo1"); 718 const GURL url1("http://foo1");
706 const GURL url2("http://foo2"); 719 const GURL url2("http://foo2");
707 720
708 controller.LoadURL( 721 controller.LoadURL(
709 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 722 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
723 NavigationEntry* entry = controller.GetPendingEntry();
710 EXPECT_EQ(0U, notifications.size()); 724 EXPECT_EQ(0U, notifications.size());
711 main_test_rfh()->SendNavigate(0, url1); 725 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
712 EXPECT_EQ(1U, navigation_entry_committed_counter_); 726 EXPECT_EQ(1U, navigation_entry_committed_counter_);
713 navigation_entry_committed_counter_ = 0; 727 navigation_entry_committed_counter_ = 0;
714 728
715 ASSERT_TRUE(controller.GetVisibleEntry()); 729 ASSERT_TRUE(controller.GetVisibleEntry());
716 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); 730 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
717 EXPECT_FALSE(timestamp.is_null()); 731 EXPECT_FALSE(timestamp.is_null());
718 732
719 controller.LoadURL( 733 controller.LoadURL(
720 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 734 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
721 controller.DiscardNonCommittedEntries(); 735 controller.DiscardNonCommittedEntries();
(...skipping 17 matching lines...) Expand all
739 // navigates from the web page, and here we test that there is no pending entry. 753 // navigates from the web page, and here we test that there is no pending entry.
740 TEST_F(NavigationControllerTest, LoadURL_NoPending) { 754 TEST_F(NavigationControllerTest, LoadURL_NoPending) {
741 NavigationControllerImpl& controller = controller_impl(); 755 NavigationControllerImpl& controller = controller_impl();
742 TestNotificationTracker notifications; 756 TestNotificationTracker notifications;
743 RegisterForAllNavNotifications(&notifications, &controller); 757 RegisterForAllNavNotifications(&notifications, &controller);
744 758
745 // First make an existing committed entry. 759 // First make an existing committed entry.
746 const GURL kExistingURL1("http://eh"); 760 const GURL kExistingURL1("http://eh");
747 controller.LoadURL( 761 controller.LoadURL(
748 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 762 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
749 main_test_rfh()->SendNavigate(0, kExistingURL1); 763 NavigationEntry* entry = controller.GetPendingEntry();
764 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, kExistingURL1);
750 EXPECT_EQ(1U, navigation_entry_committed_counter_); 765 EXPECT_EQ(1U, navigation_entry_committed_counter_);
751 navigation_entry_committed_counter_ = 0; 766 navigation_entry_committed_counter_ = 0;
752 767
753 // Do a new navigation without making a pending one. 768 // Do a new navigation without making a pending one.
754 const GURL kNewURL("http://see"); 769 const GURL kNewURL("http://see");
755 main_test_rfh()->SendNavigate(99, kNewURL); 770 main_test_rfh()->SendNavigate(99, 0, true, kNewURL);
756 771
757 // There should no longer be any pending entry, and the third navigation we 772 // There should no longer be any pending entry, and the second navigation we
758 // just made should be committed. 773 // just made should be committed.
759 EXPECT_EQ(1U, navigation_entry_committed_counter_); 774 EXPECT_EQ(1U, navigation_entry_committed_counter_);
760 navigation_entry_committed_counter_ = 0; 775 navigation_entry_committed_counter_ = 0;
761 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 776 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
762 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 777 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
763 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 778 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
764 } 779 }
765 780
766 // Tests navigating to a new URL when there is a new pending navigation that is 781 // Tests navigating to a new URL when there is a new pending navigation that is
767 // not the one that just loaded. This will happen if the user types in a URL to 782 // not the one that just loaded. This will happen if the user types in a URL to
768 // somewhere slow, and then navigates the current page before the typed URL 783 // somewhere slow, and then navigates the current page before the typed URL
769 // commits. 784 // commits.
770 TEST_F(NavigationControllerTest, LoadURL_NewPending) { 785 TEST_F(NavigationControllerTest, LoadURL_NewPending) {
771 NavigationControllerImpl& controller = controller_impl(); 786 NavigationControllerImpl& controller = controller_impl();
772 TestNotificationTracker notifications; 787 TestNotificationTracker notifications;
773 RegisterForAllNavNotifications(&notifications, &controller); 788 RegisterForAllNavNotifications(&notifications, &controller);
774 789
775 // First make an existing committed entry. 790 // First make an existing committed entry.
776 const GURL kExistingURL1("http://eh"); 791 const GURL kExistingURL1("http://eh");
777 controller.LoadURL( 792 controller.LoadURL(
778 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 793 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
794 NavigationEntry* entry = controller.GetPendingEntry();
779 main_test_rfh()->PrepareForCommit(); 795 main_test_rfh()->PrepareForCommit();
780 main_test_rfh()->SendNavigate(0, kExistingURL1); 796 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, kExistingURL1);
781 EXPECT_EQ(1U, navigation_entry_committed_counter_); 797 EXPECT_EQ(1U, navigation_entry_committed_counter_);
782 navigation_entry_committed_counter_ = 0; 798 navigation_entry_committed_counter_ = 0;
783 799
784 // Make a pending entry to somewhere new. 800 // Make a pending entry to somewhere new.
785 const GURL kExistingURL2("http://bee"); 801 const GURL kExistingURL2("http://bee");
786 controller.LoadURL( 802 controller.LoadURL(
787 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 803 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
788 EXPECT_EQ(0U, notifications.size()); 804 EXPECT_EQ(0U, notifications.size());
789 805
790 // After the beforeunload but before it commits, do a new navigation. 806 // After the beforeunload but before it commits, do a new navigation.
791 main_test_rfh()->PrepareForCommit(); 807 main_test_rfh()->PrepareForCommit();
792 const GURL kNewURL("http://see"); 808 const GURL kNewURL("http://see");
793 main_test_rfh()->PrepareForCommit(); 809 main_test_rfh()->PrepareForCommit();
794 contents()->GetMainFrame()->SendNavigate(3, kNewURL); 810 contents()->GetMainFrame()->SendNavigate(3, 0, true, kNewURL);
795 811
796 // There should no longer be any pending entry, and the third navigation we 812 // There should no longer be any pending entry, and the third navigation we
797 // just made should be committed. 813 // just made should be committed.
798 EXPECT_EQ(1U, navigation_entry_committed_counter_); 814 EXPECT_EQ(1U, navigation_entry_committed_counter_);
799 navigation_entry_committed_counter_ = 0; 815 navigation_entry_committed_counter_ = 0;
800 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 816 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
801 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 817 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
802 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 818 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
803 } 819 }
804 820
805 // Tests navigating to a new URL when there is a pending back/forward 821 // Tests navigating to a new URL when there is a pending back/forward
806 // navigation. This will happen if the user hits back, but before that commits, 822 // navigation. This will happen if the user hits back, but before that commits,
807 // they navigate somewhere new. 823 // they navigate somewhere new.
808 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { 824 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) {
809 NavigationControllerImpl& controller = controller_impl(); 825 NavigationControllerImpl& controller = controller_impl();
810 TestNotificationTracker notifications; 826 TestNotificationTracker notifications;
811 RegisterForAllNavNotifications(&notifications, &controller); 827 RegisterForAllNavNotifications(&notifications, &controller);
812 828
813 // First make some history. 829 // First make some history.
814 const GURL kExistingURL1("http://foo/eh"); 830 const GURL kExistingURL1("http://foo/eh");
815 controller.LoadURL( 831 controller.LoadURL(
816 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 832 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
833 NavigationEntry* entry = controller.GetPendingEntry();
817 main_test_rfh()->PrepareForCommit(); 834 main_test_rfh()->PrepareForCommit();
818 main_test_rfh()->SendNavigate(0, kExistingURL1); 835 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, kExistingURL1);
819 EXPECT_EQ(1U, navigation_entry_committed_counter_); 836 EXPECT_EQ(1U, navigation_entry_committed_counter_);
820 navigation_entry_committed_counter_ = 0; 837 navigation_entry_committed_counter_ = 0;
821 838
822 const GURL kExistingURL2("http://foo/bee"); 839 const GURL kExistingURL2("http://foo/bee");
823 controller.LoadURL( 840 controller.LoadURL(
824 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 841 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
842 entry = controller.GetPendingEntry();
825 main_test_rfh()->PrepareForCommit(); 843 main_test_rfh()->PrepareForCommit();
826 main_test_rfh()->SendNavigate(1, kExistingURL2); 844 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, kExistingURL2);
827 EXPECT_EQ(1U, navigation_entry_committed_counter_); 845 EXPECT_EQ(1U, navigation_entry_committed_counter_);
828 navigation_entry_committed_counter_ = 0; 846 navigation_entry_committed_counter_ = 0;
829 847
830 // Now make a pending back/forward navigation. The zeroth entry should be 848 // Now make a pending back/forward navigation. The zeroth entry should be
831 // pending. 849 // pending.
832 controller.GoBack(); 850 controller.GoBack();
833 EXPECT_EQ(0U, notifications.size()); 851 EXPECT_EQ(0U, notifications.size());
834 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 852 EXPECT_EQ(0, controller.GetPendingEntryIndex());
835 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 853 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
836 854
837 // Before that commits, do a new navigation. 855 // Before that commits, do a new navigation.
838 const GURL kNewURL("http://foo/see"); 856 const GURL kNewURL("http://foo/see");
839 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); 857 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true);
840 main_test_rfh()->PrepareForCommit(); 858 main_test_rfh()->PrepareForCommit();
841 main_test_rfh()->SendNavigate(3, kNewURL); 859 main_test_rfh()->SendNavigate(3, 0, true, kNewURL);
842 860
843 // There should no longer be any pending entry, and the third navigation we 861 // There should no longer be any pending entry, and the new navigation we
844 // just made should be committed. 862 // just made should be committed.
845 EXPECT_EQ(1U, navigation_entry_committed_counter_); 863 EXPECT_EQ(1U, navigation_entry_committed_counter_);
846 navigation_entry_committed_counter_ = 0; 864 navigation_entry_committed_counter_ = 0;
847 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 865 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
848 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 866 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
849 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 867 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
850 } 868 }
851 869
852 // Tests navigating to a new URL when there is a pending back/forward 870 // Tests navigating to a new URL when there is a pending back/forward
853 // navigation to a cross-process, privileged URL. This will happen if the user 871 // navigation to a cross-process, privileged URL. This will happen if the user
854 // hits back, but before that commits, they navigate somewhere new. 872 // hits back, but before that commits, they navigate somewhere new.
855 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { 873 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) {
856 NavigationControllerImpl& controller = controller_impl(); 874 NavigationControllerImpl& controller = controller_impl();
857 TestNotificationTracker notifications; 875 TestNotificationTracker notifications;
858 RegisterForAllNavNotifications(&notifications, &controller); 876 RegisterForAllNavNotifications(&notifications, &controller);
859 877
860 // First make some history, starting with a privileged URL. 878 // First make some history, starting with a privileged URL.
861 const GURL kExistingURL1("http://privileged"); 879 const GURL kExistingURL1("http://privileged");
862 controller.LoadURL( 880 controller.LoadURL(
863 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 881 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
882 NavigationEntry* entry = controller.GetPendingEntry();
864 // Pretend it has bindings so we can tell if we incorrectly copy it. 883 // Pretend it has bindings so we can tell if we incorrectly copy it.
865 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); 884 main_test_rfh()->GetRenderViewHost()->AllowBindings(2);
866 main_test_rfh()->PrepareForCommit(); 885 main_test_rfh()->PrepareForCommit();
867 main_test_rfh()->SendNavigate(0, kExistingURL1); 886 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, kExistingURL1);
868 EXPECT_EQ(1U, navigation_entry_committed_counter_); 887 EXPECT_EQ(1U, navigation_entry_committed_counter_);
869 navigation_entry_committed_counter_ = 0; 888 navigation_entry_committed_counter_ = 0;
870 889
871 // Navigate cross-process to a second URL. 890 // Navigate cross-process to a second URL.
872 const GURL kExistingURL2("http://foo/eh"); 891 const GURL kExistingURL2("http://foo/eh");
873 controller.LoadURL( 892 controller.LoadURL(
874 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 893 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
894 entry = controller.GetPendingEntry();
875 main_test_rfh()->PrepareForCommit(); 895 main_test_rfh()->PrepareForCommit();
876 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); 896 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame();
877 foo_rfh->SendNavigate(1, kExistingURL2); 897 foo_rfh->SendNavigate(1, entry->GetUniqueID(), true, kExistingURL2);
878 EXPECT_EQ(1U, navigation_entry_committed_counter_); 898 EXPECT_EQ(1U, navigation_entry_committed_counter_);
879 navigation_entry_committed_counter_ = 0; 899 navigation_entry_committed_counter_ = 0;
880 900
881 // Now make a pending back/forward navigation to a privileged entry. 901 // Now make a pending back/forward navigation to a privileged entry.
882 // The zeroth entry should be pending. 902 // The zeroth entry should be pending.
883 controller.GoBack(); 903 controller.GoBack();
884 foo_rfh->SendBeforeUnloadACK(true); 904 foo_rfh->SendBeforeUnloadACK(true);
885 EXPECT_EQ(0U, notifications.size()); 905 EXPECT_EQ(0U, notifications.size());
886 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 906 EXPECT_EQ(0, controller.GetPendingEntryIndex());
887 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 907 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
888 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); 908 EXPECT_EQ(2, controller.GetPendingEntry()->bindings());
889 909
890 // Before that commits, do a new navigation. 910 // Before that commits, do a new navigation.
891 const GURL kNewURL("http://foo/bee"); 911 const GURL kNewURL("http://foo/bee");
892 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); 912 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true);
893 foo_rfh->PrepareForCommit(); 913 foo_rfh->PrepareForCommit();
894 foo_rfh->SendNavigate(3, kNewURL); 914 foo_rfh->SendNavigate(3, 0, true, kNewURL);
895 915
896 // There should no longer be any pending entry, and the third navigation we 916 // There should no longer be any pending entry, and the new navigation we
897 // just made should be committed. 917 // just made should be committed.
898 EXPECT_EQ(1U, navigation_entry_committed_counter_); 918 EXPECT_EQ(1U, navigation_entry_committed_counter_);
899 navigation_entry_committed_counter_ = 0; 919 navigation_entry_committed_counter_ = 0;
900 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 920 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
901 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 921 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
902 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); 922 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL());
903 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); 923 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings());
904 } 924 }
905 925
906 // Tests navigating to an existing URL when there is a pending new navigation. 926 // This VVVVVVV should be impossible. All history navigations should be routed
907 // This will happen if the user enters a URL, but before that commits, the 927 // through the browser process, so there should be no surprise history
908 // current page fires history.back(). 928 // navigations from the renderer.
909 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) {
910 NavigationControllerImpl& controller = controller_impl();
911 TestNotificationTracker notifications;
912 RegisterForAllNavNotifications(&notifications, &controller);
913 929
914 // First make some history. 930 // // Tests navigating to an existing URL when there is a pending new navigation .
915 const GURL kExistingURL1("http://foo/eh"); 931 // // This will happen if the user enters a URL, but before that commits, the
916 controller.LoadURL( 932 // // current page fires history.back().
917 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 933 // TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) {
918 main_test_rfh()->PrepareForCommit(); 934 // NavigationControllerImpl& controller = controller_impl();
919 main_test_rfh()->SendNavigate(0, kExistingURL1); 935 // TestNotificationTracker notifications;
920 EXPECT_EQ(1U, navigation_entry_committed_counter_); 936 // RegisterForAllNavNotifications(&notifications, &controller);
921 navigation_entry_committed_counter_ = 0;
922 937
923 const GURL kExistingURL2("http://foo/bee"); 938 // // First make some history.
924 controller.LoadURL( 939 // const GURL kExistingURL1("http://foo/eh");
925 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 940 // controller.LoadURL(
926 main_test_rfh()->PrepareForCommit(); 941 // kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
927 main_test_rfh()->SendNavigate(1, kExistingURL2); 942 // main_test_rfh()->PrepareForCommit();
928 EXPECT_EQ(1U, navigation_entry_committed_counter_); 943 // main_test_rfh()->SendNavigate(0, kExistingURL1);
929 navigation_entry_committed_counter_ = 0; 944 // EXPECT_EQ(1U, navigation_entry_committed_counter_);
945 // navigation_entry_committed_counter_ = 0;
930 946
931 // Now make a pending new navigation. 947 // const GURL kExistingURL2("http://foo/bee");
932 const GURL kNewURL("http://foo/see"); 948 // controller.LoadURL(
933 controller.LoadURL( 949 // kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
934 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 950 // main_test_rfh()->PrepareForCommit();
935 EXPECT_EQ(0U, notifications.size()); 951 // main_test_rfh()->SendNavigate(1, kExistingURL2);
936 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 952 // EXPECT_EQ(1U, navigation_entry_committed_counter_);
937 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 953 // navigation_entry_committed_counter_ = 0;
938 954
939 // Before that commits, a back navigation from the renderer commits. 955 // // Now make a pending new navigation.
940 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL1, true); 956 // const GURL kNewURL("http://foo/see");
941 main_test_rfh()->PrepareForCommit(); 957 // controller.LoadURL(
942 main_test_rfh()->SendNavigate(0, kExistingURL1); 958 // kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
959 // EXPECT_EQ(0U, notifications.size());
960 // EXPECT_EQ(-1, controller.GetPendingEntryIndex());
961 // EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
943 962
944 // There should no longer be any pending entry, and the back navigation we 963 // // Before that commits, a back navigation from the renderer commits.
945 // just made should be committed. 964 // main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL1, true );
946 EXPECT_EQ(1U, navigation_entry_committed_counter_); 965 // main_test_rfh()->PrepareForCommit();
947 navigation_entry_committed_counter_ = 0; 966 // main_test_rfh()->SendNavigate(0, kExistingURL1);
948 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 967
949 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 968 // // There should no longer be any pending entry, and the back navigation we
950 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); 969 // // just made should be committed.
951 } 970 // EXPECT_EQ(1U, navigation_entry_committed_counter_);
971 // navigation_entry_committed_counter_ = 0;
972 // EXPECT_EQ(-1, controller.GetPendingEntryIndex());
973 // EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
974 // EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL());
975 // }
952 976
953 // Tests an ignored navigation when there is a pending new navigation. 977 // Tests an ignored navigation when there is a pending new navigation.
954 // This will happen if the user enters a URL, but before that commits, the 978 // This will happen if the user enters a URL, but before that commits, the
955 // current blank page reloads. See http://crbug.com/77507. 979 // current blank page reloads. See http://crbug.com/77507.
956 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { 980 TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) {
957 NavigationControllerImpl& controller = controller_impl(); 981 NavigationControllerImpl& controller = controller_impl();
958 TestNotificationTracker notifications; 982 TestNotificationTracker notifications;
959 RegisterForAllNavNotifications(&notifications, &controller); 983 RegisterForAllNavNotifications(&notifications, &controller);
960 984
961 // Set a WebContentsDelegate to listen for state changes. 985 // Set a WebContentsDelegate to listen for state changes.
962 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 986 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
963 EXPECT_FALSE(contents()->GetDelegate()); 987 EXPECT_FALSE(contents()->GetDelegate());
964 contents()->SetDelegate(delegate.get()); 988 contents()->SetDelegate(delegate.get());
965 989
966 // Without any navigations, the renderer starts at about:blank. 990 // Without any navigations, the renderer starts at about:blank.
967 const GURL kExistingURL(url::kAboutBlankURL); 991 const GURL kExistingURL(url::kAboutBlankURL);
968 992
969 // Now make a pending new navigation. 993 // Now make a pending new navigation.
970 const GURL kNewURL("http://eh"); 994 const GURL kNewURL("http://eh");
971 controller.LoadURL( 995 controller.LoadURL(
972 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 996 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
973 EXPECT_EQ(0U, notifications.size()); 997 EXPECT_EQ(0U, notifications.size());
974 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 998 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
975 EXPECT_TRUE(controller.GetPendingEntry()); 999 EXPECT_TRUE(controller.GetPendingEntry());
976 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 1000 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
977 EXPECT_EQ(1, delegate->navigation_state_change_count()); 1001 EXPECT_EQ(1, delegate->navigation_state_change_count());
978 1002
979 // Before that commits, a document.write and location.reload can cause the 1003 // Before that commits, a document.write and location.reload can cause the
980 // renderer to send a FrameNavigate with page_id -1. 1004 // renderer to send a FrameNavigate with page_id -1 and nav_entry_id 0.
981 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); 1005 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true);
982 main_test_rfh()->PrepareForCommit(); 1006 main_test_rfh()->PrepareForCommit();
983 main_test_rfh()->SendNavigate(-1, kExistingURL); 1007 main_test_rfh()->SendNavigate(-1, 0, false, kExistingURL);
984 1008
985 // This should clear the pending entry and notify of a navigation state 1009 // This should clear the pending entry and notify of a navigation state
986 // change, so that we do not keep displaying kNewURL. 1010 // change, so that we do not keep displaying kNewURL.
987 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1011 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
988 EXPECT_FALSE(controller.GetPendingEntry()); 1012 EXPECT_FALSE(controller.GetPendingEntry());
989 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); 1013 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex());
990 EXPECT_EQ(2, delegate->navigation_state_change_count()); 1014 EXPECT_EQ(2, delegate->navigation_state_change_count());
991 1015
992 contents()->SetDelegate(NULL); 1016 contents()->SetDelegate(NULL);
993 } 1017 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 // redirect and abort. See http://crbug.com/83031. 1072 // redirect and abort. See http://crbug.com/83031.
1049 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { 1073 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
1050 NavigationControllerImpl& controller = controller_impl(); 1074 NavigationControllerImpl& controller = controller_impl();
1051 TestNotificationTracker notifications; 1075 TestNotificationTracker notifications;
1052 RegisterForAllNavNotifications(&notifications, &controller); 1076 RegisterForAllNavNotifications(&notifications, &controller);
1053 1077
1054 // First make an existing committed entry. 1078 // First make an existing committed entry.
1055 const GURL kExistingURL("http://foo/eh"); 1079 const GURL kExistingURL("http://foo/eh");
1056 controller.LoadURL(kExistingURL, content::Referrer(), 1080 controller.LoadURL(kExistingURL, content::Referrer(),
1057 ui::PAGE_TRANSITION_TYPED, std::string()); 1081 ui::PAGE_TRANSITION_TYPED, std::string());
1058 main_test_rfh()->SendNavigate(1, kExistingURL); 1082 NavigationEntry* entry = controller.GetPendingEntry();
1083 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, kExistingURL);
1059 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1084 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1060 navigation_entry_committed_counter_ = 0; 1085 navigation_entry_committed_counter_ = 0;
1061 1086
1062 // Set a WebContentsDelegate to listen for state changes. 1087 // Set a WebContentsDelegate to listen for state changes.
1063 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 1088 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
1064 EXPECT_FALSE(contents()->GetDelegate()); 1089 EXPECT_FALSE(contents()->GetDelegate());
1065 contents()->SetDelegate(delegate.get()); 1090 contents()->SetDelegate(delegate.get());
1066 1091
1067 // Now make a pending new navigation, initiated by the renderer. 1092 // Now make a pending new navigation, initiated by the renderer.
1068 const GURL kNewURL("http://foo/bee"); 1093 const GURL kNewURL("http://foo/bee");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 std::vector<GURL> url_chain; 1145 std::vector<GURL> url_chain;
1121 1146
1122 const GURL url1("http://foo1"); 1147 const GURL url1("http://foo1");
1123 const GURL url2("http://foo2"); 1148 const GURL url2("http://foo2");
1124 1149
1125 // Navigate to a first, unprivileged URL. 1150 // Navigate to a first, unprivileged URL.
1126 controller.LoadURL( 1151 controller.LoadURL(
1127 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1152 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1128 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, 1153 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings,
1129 controller.GetPendingEntry()->bindings()); 1154 controller.GetPendingEntry()->bindings());
1155 NavigationEntry* entry1 = controller.GetPendingEntry();
1130 1156
1131 // Commit. 1157 // Commit.
1132 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); 1158 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame();
1133 orig_rfh->PrepareForCommit(); 1159 orig_rfh->PrepareForCommit();
1134 orig_rfh->SendNavigate(0, url1); 1160 orig_rfh->SendNavigate(0, entry1->GetUniqueID(), true, url1);
1135 EXPECT_EQ(controller.GetEntryCount(), 1); 1161 EXPECT_EQ(controller.GetEntryCount(), 1);
1136 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1162 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1137 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); 1163 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings());
1138 1164
1139 // Manually increase the number of active frames in the SiteInstance 1165 // Manually increase the number of active frames in the SiteInstance
1140 // that orig_rfh belongs to, to prevent it from being destroyed when 1166 // that orig_rfh belongs to, to prevent it from being destroyed when
1141 // it gets swapped out, so that we can reuse orig_rfh when the 1167 // it gets swapped out, so that we can reuse orig_rfh when the
1142 // controller goes back. 1168 // controller goes back.
1143 orig_rfh->GetSiteInstance()->increment_active_frame_count(); 1169 orig_rfh->GetSiteInstance()->increment_active_frame_count();
1144 1170
1145 // Navigate to a second URL, simulate the beforeunload ack for the cross-site 1171 // Navigate to a second URL, simulate the beforeunload ack for the cross-site
1146 // transition, and set bindings on the pending RenderViewHost to simulate a 1172 // transition, and set bindings on the pending RenderViewHost to simulate a
1147 // privileged url. 1173 // privileged url.
1148 controller.LoadURL( 1174 controller.LoadURL(
1149 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1175 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1176 NavigationEntry* entry2 = controller.GetPendingEntry();
1150 orig_rfh->PrepareForCommit(); 1177 orig_rfh->PrepareForCommit();
1151 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); 1178 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame();
1152 new_rfh->GetRenderViewHost()->AllowBindings(1); 1179 new_rfh->GetRenderViewHost()->AllowBindings(1);
1153 new_rfh->SendNavigate(1, url2); 1180 new_rfh->SendNavigate(1, entry2->GetUniqueID(), true, url2);
1154 1181
1155 // The second load should be committed, and bindings should be remembered. 1182 // The second load should be committed, and bindings should be remembered.
1156 EXPECT_EQ(controller.GetEntryCount(), 2); 1183 EXPECT_EQ(controller.GetEntryCount(), 2);
1157 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1184 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1158 EXPECT_TRUE(controller.CanGoBack()); 1185 EXPECT_TRUE(controller.CanGoBack());
1159 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); 1186 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings());
1160 1187
1161 // Going back, the first entry should still appear unprivileged. 1188 // Going back, the first entry should still appear unprivileged.
1162 controller.GoBack(); 1189 controller.GoBack();
1163 new_rfh->PrepareForCommit(); 1190 new_rfh->PrepareForCommit();
1164 orig_rfh->SendNavigate(0, url1); 1191 orig_rfh->SendNavigate(0, entry1->GetUniqueID(), false, url1);
1165 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1192 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1166 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); 1193 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings());
1167 } 1194 }
1168 1195
1169 TEST_F(NavigationControllerTest, Reload) { 1196 TEST_F(NavigationControllerTest, Reload) {
1170 NavigationControllerImpl& controller = controller_impl(); 1197 NavigationControllerImpl& controller = controller_impl();
1171 TestNotificationTracker notifications; 1198 TestNotificationTracker notifications;
1172 RegisterForAllNavNotifications(&notifications, &controller); 1199 RegisterForAllNavNotifications(&notifications, &controller);
1173 1200
1174 const GURL url1("http://foo1"); 1201 const GURL url1("http://foo1");
1175 1202
1176 controller.LoadURL( 1203 controller.LoadURL(
1177 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1204 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1205 NavigationEntry* entry = controller.GetPendingEntry();
1178 EXPECT_EQ(0U, notifications.size()); 1206 EXPECT_EQ(0U, notifications.size());
1179 main_test_rfh()->PrepareForCommit(); 1207 main_test_rfh()->PrepareForCommit();
1180 main_test_rfh()->SendNavigate(0, url1); 1208 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
1181 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1209 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1182 navigation_entry_committed_counter_ = 0; 1210 navigation_entry_committed_counter_ = 0;
1183 ASSERT_TRUE(controller.GetVisibleEntry()); 1211 ASSERT_TRUE(controller.GetVisibleEntry());
1184 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); 1212 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title"));
1213
1185 controller.Reload(true); 1214 controller.Reload(true);
1186 EXPECT_EQ(0U, notifications.size()); 1215 EXPECT_EQ(0U, notifications.size());
1187 1216
1188 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); 1217 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp();
1189 EXPECT_FALSE(timestamp.is_null()); 1218 EXPECT_FALSE(timestamp.is_null());
1190 1219
1191 // The reload is pending. 1220 // The reload is pending.
1192 EXPECT_EQ(controller.GetEntryCount(), 1); 1221 EXPECT_EQ(controller.GetEntryCount(), 1);
1193 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1222 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1194 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1223 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1195 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1224 EXPECT_TRUE(controller.GetLastCommittedEntry());
1196 EXPECT_TRUE(controller.GetPendingEntry()); 1225 EXPECT_TRUE(controller.GetPendingEntry());
1197 EXPECT_FALSE(controller.CanGoBack()); 1226 EXPECT_FALSE(controller.CanGoBack());
1198 EXPECT_FALSE(controller.CanGoForward()); 1227 EXPECT_FALSE(controller.CanGoForward());
1199 // Make sure the title has been cleared (will be redrawn just after reload). 1228 // Make sure the title has been cleared (will be redrawn just after reload).
1200 // Avoids a stale cached title when the new page being reloaded has no title. 1229 // Avoids a stale cached title when the new page being reloaded has no title.
1201 // See http://crbug.com/96041. 1230 // See http://crbug.com/96041.
1202 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); 1231 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty());
1203 1232
1204 main_test_rfh()->PrepareForCommit(); 1233 main_test_rfh()->PrepareForCommit();
1205 main_test_rfh()->SendNavigate(0, url1); 1234 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), false, url1);
1206 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1235 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1207 navigation_entry_committed_counter_ = 0; 1236 navigation_entry_committed_counter_ = 0;
1208 1237
1209 // Now the reload is committed. 1238 // Now the reload is committed.
1210 EXPECT_EQ(controller.GetEntryCount(), 1); 1239 EXPECT_EQ(controller.GetEntryCount(), 1);
1211 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1240 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1212 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1241 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1213 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1242 EXPECT_TRUE(controller.GetLastCommittedEntry());
1214 EXPECT_FALSE(controller.GetPendingEntry()); 1243 EXPECT_FALSE(controller.GetPendingEntry());
1215 EXPECT_FALSE(controller.CanGoBack()); 1244 EXPECT_FALSE(controller.CanGoBack());
1216 EXPECT_FALSE(controller.CanGoForward()); 1245 EXPECT_FALSE(controller.CanGoForward());
1217 1246
1218 // The timestamp should have been updated. 1247 // The timestamp should have been updated.
1219 ASSERT_TRUE(controller.GetVisibleEntry()); 1248 ASSERT_TRUE(controller.GetVisibleEntry());
1220 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); 1249 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp);
1221 } 1250 }
1222 1251
1223 // Tests what happens when a reload navigation produces a new page. 1252 // Tests what happens when a reload navigation produces a new page.
1224 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { 1253 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) {
1225 NavigationControllerImpl& controller = controller_impl(); 1254 NavigationControllerImpl& controller = controller_impl();
1226 TestNotificationTracker notifications; 1255 TestNotificationTracker notifications;
1227 RegisterForAllNavNotifications(&notifications, &controller); 1256 RegisterForAllNavNotifications(&notifications, &controller);
1228 1257
1229 const GURL url1("http://foo1"); 1258 const GURL url1("http://foo1");
1230 const GURL url2("http://foo2"); 1259 const GURL url2("http://foo2");
1231 1260
1232 controller.LoadURL( 1261 controller.LoadURL(
1233 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1262 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1263 NavigationEntry* entry = controller.GetPendingEntry();
1234 main_test_rfh()->PrepareForCommit(); 1264 main_test_rfh()->PrepareForCommit();
1235 main_test_rfh()->SendNavigate(0, url1); 1265 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
1236 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1266 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1237 navigation_entry_committed_counter_ = 0; 1267 navigation_entry_committed_counter_ = 0;
1238 1268
1239 controller.Reload(true); 1269 controller.Reload(true);
1240 EXPECT_EQ(0U, notifications.size()); 1270 EXPECT_EQ(0U, notifications.size());
1241 1271
1242 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); 1272 main_test_rfh()->PrepareForCommitWithServerRedirect(url2);
1243 main_test_rfh()->SendNavigate(1, url2); 1273 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url2);
1244 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1274 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1245 navigation_entry_committed_counter_ = 0; 1275 navigation_entry_committed_counter_ = 0;
1246 1276
1247 // Now the reload is committed. 1277 // Now the reload is committed.
1248 EXPECT_EQ(controller.GetEntryCount(), 2); 1278 EXPECT_EQ(controller.GetEntryCount(), 2);
1249 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1279 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1250 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1280 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1251 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1281 EXPECT_TRUE(controller.GetLastCommittedEntry());
1252 EXPECT_FALSE(controller.GetPendingEntry()); 1282 EXPECT_FALSE(controller.GetPendingEntry());
1253 EXPECT_TRUE(controller.CanGoBack()); 1283 EXPECT_TRUE(controller.CanGoBack());
1254 EXPECT_FALSE(controller.CanGoForward()); 1284 EXPECT_FALSE(controller.CanGoForward());
1255 } 1285 }
1256 1286
1257 // This test ensures that when a guest renderer reloads, the reload goes through 1287 // This test ensures that when a guest renderer reloads, the reload goes through
1258 // without ending up in the "we have a wrong process for the URL" branch in 1288 // without ending up in the "we have a wrong process for the URL" branch in
1259 // NavigationControllerImpl::ReloadInternal. 1289 // NavigationControllerImpl::ReloadInternal.
1260 TEST_F(NavigationControllerTest, ReloadWithGuest) { 1290 TEST_F(NavigationControllerTest, ReloadWithGuest) {
1261 NavigationControllerImpl& controller = controller_impl(); 1291 NavigationControllerImpl& controller = controller_impl();
1262 1292
1263 const GURL url1("http://foo1"); 1293 const GURL url1("http://foo1");
1264 controller.LoadURL( 1294 controller.LoadURL(
1265 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1295 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1266 main_test_rfh()->SendNavigate(0, url1); 1296 NavigationEntry* entry = controller.GetPendingEntry();
1297 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
1267 ASSERT_TRUE(controller.GetVisibleEntry()); 1298 ASSERT_TRUE(controller.GetVisibleEntry());
1268 1299
1269 // Make the entry believe its RenderProcessHost is a guest. 1300 // Make the entry believe its RenderProcessHost is a guest.
1270 NavigationEntryImpl* entry1 = controller.GetVisibleEntry(); 1301 NavigationEntryImpl* entry1 = controller.GetVisibleEntry();
1271 reinterpret_cast<MockRenderProcessHost*>( 1302 reinterpret_cast<MockRenderProcessHost*>(
1272 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true); 1303 entry1->site_instance()->GetProcess())->set_is_isolated_guest(true);
1273 1304
1274 // And reload. 1305 // And reload.
1275 controller.Reload(true); 1306 controller.Reload(true);
1276 1307
(...skipping 12 matching lines...) Expand all
1289 NavigationControllerImpl& controller = controller_impl(); 1320 NavigationControllerImpl& controller = controller_impl();
1290 TestNotificationTracker notifications; 1321 TestNotificationTracker notifications;
1291 RegisterForAllNavNotifications(&notifications, &controller); 1322 RegisterForAllNavNotifications(&notifications, &controller);
1292 1323
1293 const GURL original_url("http://foo1"); 1324 const GURL original_url("http://foo1");
1294 const GURL final_url("http://foo2"); 1325 const GURL final_url("http://foo2");
1295 1326
1296 // Load up the original URL, but get redirected. 1327 // Load up the original URL, but get redirected.
1297 controller.LoadURL( 1328 controller.LoadURL(
1298 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1329 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1330 NavigationEntry* entry = controller.GetPendingEntry();
1299 EXPECT_EQ(0U, notifications.size()); 1331 EXPECT_EQ(0U, notifications.size());
1300 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); 1332 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url);
1301 main_test_rfh()->SendNavigateWithOriginalRequestURL( 1333 main_test_rfh()->SendNavigateWithOriginalRequestURL(
1302 0, final_url, original_url); 1334 0, entry->GetUniqueID(), true, final_url, original_url);
1303 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1335 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1304 navigation_entry_committed_counter_ = 0; 1336 navigation_entry_committed_counter_ = 0;
1305 1337
1306 // The NavigationEntry should save both the original URL and the final 1338 // The NavigationEntry should save both the original URL and the final
1307 // redirected URL. 1339 // redirected URL.
1308 EXPECT_EQ( 1340 EXPECT_EQ(
1309 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); 1341 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL());
1310 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); 1342 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL());
1311 1343
1312 // Reload using the original URL. 1344 // Reload using the original URL.
(...skipping 11 matching lines...) Expand all
1324 EXPECT_FALSE(controller.CanGoBack()); 1356 EXPECT_FALSE(controller.CanGoBack());
1325 EXPECT_FALSE(controller.CanGoForward()); 1357 EXPECT_FALSE(controller.CanGoForward());
1326 1358
1327 // Make sure the title has been cleared (will be redrawn just after reload). 1359 // Make sure the title has been cleared (will be redrawn just after reload).
1328 // Avoids a stale cached title when the new page being reloaded has no title. 1360 // Avoids a stale cached title when the new page being reloaded has no title.
1329 // See http://crbug.com/96041. 1361 // See http://crbug.com/96041.
1330 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); 1362 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty());
1331 1363
1332 // Send that the navigation has proceeded; say it got redirected again. 1364 // Send that the navigation has proceeded; say it got redirected again.
1333 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); 1365 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url);
1334 main_test_rfh()->SendNavigate(0, final_url); 1366 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), false, final_url);
1335 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1367 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1336 navigation_entry_committed_counter_ = 0; 1368 navigation_entry_committed_counter_ = 0;
1337 1369
1338 // Now the reload is committed. 1370 // Now the reload is committed.
1339 EXPECT_EQ(controller.GetEntryCount(), 1); 1371 EXPECT_EQ(controller.GetEntryCount(), 1);
1340 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1372 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1341 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1373 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1342 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1374 EXPECT_TRUE(controller.GetLastCommittedEntry());
1343 EXPECT_FALSE(controller.GetPendingEntry()); 1375 EXPECT_FALSE(controller.GetPendingEntry());
1344 EXPECT_FALSE(controller.CanGoBack()); 1376 EXPECT_FALSE(controller.CanGoBack());
1345 EXPECT_FALSE(controller.CanGoForward()); 1377 EXPECT_FALSE(controller.CanGoForward());
1346 } 1378 }
1347 1379
1348 #endif // !defined(OS_ANDROID) 1380 #endif // !defined(OS_ANDROID)
1349 1381
1350 // Test that certain non-persisted NavigationEntryImpl values get reset after 1382 // Test that certain non-persisted NavigationEntryImpl values get reset after
1351 // commit. 1383 // commit.
1352 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { 1384 TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) {
1353 NavigationControllerImpl& controller = controller_impl(); 1385 NavigationControllerImpl& controller = controller_impl();
1354 1386
1355 // The value of "should replace entry" will be tested, but it's an error to 1387 // The value of "should replace entry" will be tested, but it's an error to
1356 // specify it when there are no entries. Create a simple entry to be replaced. 1388 // specify it when there are no entries. Create a simple entry to be replaced.
1357 const GURL url0("http://foo/0"); 1389 const GURL url0("http://foo/0");
1358 controller.LoadURL( 1390 controller.LoadURL(
1359 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1391 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1360 main_test_rfh()->SendNavigate(0, url0); 1392 NavigationEntry* entry = controller.GetPendingEntry();
1393 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url0);
1361 1394
1362 // Set up the pending entry. 1395 // Set up the pending entry.
1363 const GURL url1("http://foo/1"); 1396 const GURL url1("http://foo/1");
1364 controller.LoadURL( 1397 controller.LoadURL(
1365 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1398 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1399 entry = controller.GetPendingEntry();
1366 1400
1367 // Set up some sample values. 1401 // Set up some sample values.
1368 const unsigned char* raw_data = 1402 const unsigned char* raw_data =
1369 reinterpret_cast<const unsigned char*>("post\n\n\0data"); 1403 reinterpret_cast<const unsigned char*>("post\n\n\0data");
1370 const int length = 11; 1404 const int length = 11;
1371 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); 1405 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length);
1372 scoped_refptr<base::RefCountedBytes> post_data = 1406 scoped_refptr<base::RefCountedBytes> post_data =
1373 base::RefCountedBytes::TakeVector(&post_data_vector); 1407 base::RefCountedBytes::TakeVector(&post_data_vector);
1374 GlobalRequestID transfer_id(3, 4); 1408 GlobalRequestID transfer_id(3, 4);
1375 1409
1376 // Set non-persisted values on the pending entry. 1410 // Set non-persisted values on the pending entry.
1377 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); 1411 NavigationEntryImpl* pending_entry = controller.GetPendingEntry();
1378 pending_entry->SetBrowserInitiatedPostData(post_data.get()); 1412 pending_entry->SetBrowserInitiatedPostData(post_data.get());
1379 pending_entry->set_is_renderer_initiated(true); 1413 pending_entry->set_is_renderer_initiated(true);
1380 pending_entry->set_transferred_global_request_id(transfer_id); 1414 pending_entry->set_transferred_global_request_id(transfer_id);
1381 pending_entry->set_should_replace_entry(true); 1415 pending_entry->set_should_replace_entry(true);
1382 pending_entry->set_should_clear_history_list(true); 1416 pending_entry->set_should_clear_history_list(true);
1383 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); 1417 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData());
1384 EXPECT_TRUE(pending_entry->is_renderer_initiated()); 1418 EXPECT_TRUE(pending_entry->is_renderer_initiated());
1385 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); 1419 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id());
1386 EXPECT_TRUE(pending_entry->should_replace_entry()); 1420 EXPECT_TRUE(pending_entry->should_replace_entry());
1387 EXPECT_TRUE(pending_entry->should_clear_history_list()); 1421 EXPECT_TRUE(pending_entry->should_clear_history_list());
1388 1422
1389 // Fake a commit response. 1423 // Fake a commit response.
1390 main_test_rfh()->SendNavigate(1, url1); 1424 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url1);
1391 1425
1392 // Certain values that are only used for pending entries get reset after 1426 // Certain values that are only used for pending entries get reset after
1393 // commit. 1427 // commit.
1394 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); 1428 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry();
1395 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); 1429 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData());
1396 EXPECT_FALSE(committed_entry->is_renderer_initiated()); 1430 EXPECT_FALSE(committed_entry->is_renderer_initiated());
1397 EXPECT_EQ(GlobalRequestID(-1, -1), 1431 EXPECT_EQ(GlobalRequestID(-1, -1),
1398 committed_entry->transferred_global_request_id()); 1432 committed_entry->transferred_global_request_id());
1399 EXPECT_FALSE(committed_entry->should_replace_entry()); 1433 EXPECT_FALSE(committed_entry->should_replace_entry());
1400 EXPECT_FALSE(committed_entry->should_clear_history_list()); 1434 EXPECT_FALSE(committed_entry->should_clear_history_list());
1401 } 1435 }
1402 1436
1403 // Test that Redirects are preserved after a commit. 1437 // Test that Redirects are preserved after a commit.
1404 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { 1438 TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) {
1405 NavigationControllerImpl& controller = controller_impl(); 1439 NavigationControllerImpl& controller = controller_impl();
1406 const GURL url1("http://foo1"); 1440 const GURL url1("http://foo1");
1407 controller.LoadURL( 1441 controller.LoadURL(
1408 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1442 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1443 NavigationEntry* entry = controller.GetPendingEntry();
1409 1444
1410 // Set up some redirect values. 1445 // Set up some redirect values.
1411 std::vector<GURL> redirects; 1446 std::vector<GURL> redirects;
1412 redirects.push_back(GURL("http://foo2")); 1447 redirects.push_back(GURL("http://foo2"));
1413 1448
1414 // Set redirects on the pending entry. 1449 // Set redirects on the pending entry.
1415 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); 1450 NavigationEntryImpl* pending_entry = controller.GetPendingEntry();
1416 pending_entry->SetRedirectChain(redirects); 1451 pending_entry->SetRedirectChain(redirects);
1417 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size()); 1452 EXPECT_EQ(1U, pending_entry->GetRedirectChain().size());
1418 EXPECT_EQ(GURL("http://foo2"), pending_entry->GetRedirectChain()[0]); 1453 EXPECT_EQ(GURL("http://foo2"), pending_entry->GetRedirectChain()[0]);
1419 1454
1420 // Normal navigation will preserve redirects in the committed entry. 1455 // Normal navigation will preserve redirects in the committed entry.
1421 main_test_rfh()->SendNavigateWithRedirects(0, url1, redirects); 1456 main_test_rfh()->SendNavigateWithRedirects(
1457 0, entry->GetUniqueID(), true, url1, redirects);
1422 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); 1458 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry();
1423 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size()); 1459 ASSERT_EQ(1U, committed_entry->GetRedirectChain().size());
1424 EXPECT_EQ(GURL("http://foo2"), committed_entry->GetRedirectChain()[0]); 1460 EXPECT_EQ(GURL("http://foo2"), committed_entry->GetRedirectChain()[0]);
1425 } 1461 }
1426 1462
1427 // Tests what happens when we navigate back successfully 1463 // Tests what happens when we navigate back successfully
1428 TEST_F(NavigationControllerTest, Back) { 1464 TEST_F(NavigationControllerTest, Back) {
1429 NavigationControllerImpl& controller = controller_impl(); 1465 NavigationControllerImpl& controller = controller_impl();
1430 TestNotificationTracker notifications; 1466 TestNotificationTracker notifications;
1431 RegisterForAllNavNotifications(&notifications, &controller); 1467 RegisterForAllNavNotifications(&notifications, &controller);
1432 1468
1433 const GURL url1("http://foo1"); 1469 const GURL url1("http://foo1");
1434 main_test_rfh()->SendNavigate(0, url1); 1470 main_test_rfh()->SendNavigate(0, 0, true, url1);
1471 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1472 NavigationEntry* entry = controller.GetPendingEntry();
1473 navigation_entry_committed_counter_ = 0;
1474
1475 const GURL url2("http://foo2");
1476 main_test_rfh()->SendNavigate(1, 0, true, url2);
1435 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1477 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1436 navigation_entry_committed_counter_ = 0; 1478 navigation_entry_committed_counter_ = 0;
1437 1479
1438 const GURL url2("http://foo2");
1439 main_test_rfh()->SendNavigate(1, url2);
1440 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1441 navigation_entry_committed_counter_ = 0;
1442
1443 controller.GoBack(); 1480 controller.GoBack();
1444 EXPECT_EQ(0U, notifications.size()); 1481 EXPECT_EQ(0U, notifications.size());
1445 1482
1446 // We should now have a pending navigation to go back. 1483 // We should now have a pending navigation to go back.
1447 EXPECT_EQ(controller.GetEntryCount(), 2); 1484 EXPECT_EQ(controller.GetEntryCount(), 2);
1448 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1485 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1449 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1486 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1450 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1487 EXPECT_TRUE(controller.GetLastCommittedEntry());
1451 EXPECT_TRUE(controller.GetPendingEntry()); 1488 EXPECT_TRUE(controller.GetPendingEntry());
1452 EXPECT_FALSE(controller.CanGoBack()); 1489 EXPECT_FALSE(controller.CanGoBack());
1453 EXPECT_FALSE(controller.CanGoToOffset(-1)); 1490 EXPECT_FALSE(controller.CanGoToOffset(-1));
1454 EXPECT_TRUE(controller.CanGoForward()); 1491 EXPECT_TRUE(controller.CanGoForward());
1455 EXPECT_TRUE(controller.CanGoToOffset(1)); 1492 EXPECT_TRUE(controller.CanGoToOffset(1));
1456 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps. 1493 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps.
1457 1494
1458 // Timestamp for entry 1 should be on or after that of entry 0. 1495 // Timestamp for entry 1 should be on or after that of entry 0.
1459 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); 1496 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null());
1460 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), 1497 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(),
1461 controller.GetEntryAtIndex(0)->GetTimestamp()); 1498 controller.GetEntryAtIndex(0)->GetTimestamp());
1462 1499
1463 main_test_rfh()->SendNavigate(0, url2); 1500 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), false, url1);
1464 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1501 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1465 navigation_entry_committed_counter_ = 0; 1502 navigation_entry_committed_counter_ = 0;
1466 1503
1467 // The back navigation completed successfully. 1504 // The back navigation completed successfully.
1468 EXPECT_EQ(controller.GetEntryCount(), 2); 1505 EXPECT_EQ(controller.GetEntryCount(), 2);
1469 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1506 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1470 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1507 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1471 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1508 EXPECT_TRUE(controller.GetLastCommittedEntry());
1472 EXPECT_FALSE(controller.GetPendingEntry()); 1509 EXPECT_FALSE(controller.GetPendingEntry());
1473 EXPECT_FALSE(controller.CanGoBack()); 1510 EXPECT_FALSE(controller.CanGoBack());
(...skipping 13 matching lines...) Expand all
1487 NavigationControllerImpl& controller = controller_impl(); 1524 NavigationControllerImpl& controller = controller_impl();
1488 TestNotificationTracker notifications; 1525 TestNotificationTracker notifications;
1489 RegisterForAllNavNotifications(&notifications, &controller); 1526 RegisterForAllNavNotifications(&notifications, &controller);
1490 1527
1491 const GURL url1("http://foo/1"); 1528 const GURL url1("http://foo/1");
1492 const GURL url2("http://foo/2"); 1529 const GURL url2("http://foo/2");
1493 const GURL url3("http://foo/3"); 1530 const GURL url3("http://foo/3");
1494 1531
1495 controller.LoadURL( 1532 controller.LoadURL(
1496 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1533 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1534 NavigationEntry* entry1 = controller.GetPendingEntry();
1497 main_test_rfh()->PrepareForCommit(); 1535 main_test_rfh()->PrepareForCommit();
1498 main_test_rfh()->SendNavigate(0, url1); 1536 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), true, url1);
1499 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1537 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1500 navigation_entry_committed_counter_ = 0; 1538 navigation_entry_committed_counter_ = 0;
1501 1539
1502 controller.LoadURL( 1540 controller.LoadURL(
1503 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1541 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1542 NavigationEntry* entry2 = controller.GetPendingEntry();
1504 main_test_rfh()->PrepareForCommit(); 1543 main_test_rfh()->PrepareForCommit();
1505 main_test_rfh()->SendNavigate(1, url2); 1544 main_test_rfh()->SendNavigate(1, entry2->GetUniqueID(), true, url2);
1506 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1545 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1507 navigation_entry_committed_counter_ = 0; 1546 navigation_entry_committed_counter_ = 0;
1508 1547
1509 controller.GoBack(); 1548 controller.GoBack();
1510 EXPECT_EQ(0U, notifications.size()); 1549 EXPECT_EQ(0U, notifications.size());
1511 1550
1512 // We should now have a pending navigation to go back. 1551 // We should now have a pending navigation to go back.
1513 EXPECT_EQ(controller.GetEntryCount(), 2); 1552 EXPECT_EQ(controller.GetEntryCount(), 2);
1514 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1553 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1515 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); 1554 EXPECT_EQ(controller.GetPendingEntryIndex(), 0);
1516 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1555 EXPECT_TRUE(controller.GetLastCommittedEntry());
1517 EXPECT_TRUE(controller.GetPendingEntry()); 1556 EXPECT_TRUE(controller.GetPendingEntry());
1518 EXPECT_FALSE(controller.CanGoBack()); 1557 EXPECT_FALSE(controller.CanGoBack());
1519 EXPECT_TRUE(controller.CanGoForward()); 1558 EXPECT_TRUE(controller.CanGoForward());
1520 1559
1521 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); 1560 main_test_rfh()->PrepareForCommitWithServerRedirect(url3);
1522 main_test_rfh()->SendNavigate(2, url3); 1561 main_test_rfh()->SendNavigate(2, entry1->GetUniqueID(), true, url3);
1523 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1562 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1524 navigation_entry_committed_counter_ = 0; 1563 navigation_entry_committed_counter_ = 0;
1525 1564
1526 // The back navigation resulted in a completely new navigation. 1565 // The back navigation resulted in a completely new navigation.
1527 // TODO(darin): perhaps this behavior will be confusing to users? 1566 // TODO(darin): perhaps this behavior will be confusing to users?
1528 EXPECT_EQ(controller.GetEntryCount(), 3); 1567 EXPECT_EQ(controller.GetEntryCount(), 3);
1529 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); 1568 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2);
1530 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1569 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1531 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1570 EXPECT_TRUE(controller.GetLastCommittedEntry());
1532 EXPECT_FALSE(controller.GetPendingEntry()); 1571 EXPECT_FALSE(controller.GetPendingEntry());
1533 EXPECT_TRUE(controller.CanGoBack()); 1572 EXPECT_TRUE(controller.CanGoBack());
1534 EXPECT_FALSE(controller.CanGoForward()); 1573 EXPECT_FALSE(controller.CanGoForward());
1535 } 1574 }
1536 1575
1537 // Receives a back message when there is a new pending navigation entry. 1576 // Receives a back message when there is a new pending navigation entry.
1538 TEST_F(NavigationControllerTest, Back_NewPending) { 1577 TEST_F(NavigationControllerTest, Back_NewPending) {
1539 NavigationControllerImpl& controller = controller_impl(); 1578 NavigationControllerImpl& controller = controller_impl();
1540 TestNotificationTracker notifications; 1579 TestNotificationTracker notifications;
1541 RegisterForAllNavNotifications(&notifications, &controller); 1580 RegisterForAllNavNotifications(&notifications, &controller);
1542 1581
1543 const GURL kUrl1("http://foo1"); 1582 const GURL kUrl1("http://foo1");
1544 const GURL kUrl2("http://foo2"); 1583 const GURL kUrl2("http://foo2");
1545 const GURL kUrl3("http://foo3"); 1584 const GURL kUrl3("http://foo3");
1546 1585
1547 // First navigate two places so we have some back history. 1586 // First navigate two places so we have some back history.
1548 main_test_rfh()->SendNavigate(0, kUrl1); 1587 main_test_rfh()->SendNavigate(0, 0, true, kUrl1);
1549 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1588 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1550 navigation_entry_committed_counter_ = 0; 1589 navigation_entry_committed_counter_ = 0;
1551 1590
1552 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED); 1591 // controller.LoadURL(kUrl2, ui::PAGE_TRANSITION_TYPED);
1553 main_test_rfh()->SendNavigate(1, kUrl2); 1592 main_test_rfh()->SendNavigate(1, 0, true, kUrl2);
1554 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1593 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1555 navigation_entry_committed_counter_ = 0; 1594 navigation_entry_committed_counter_ = 0;
1556 1595
1557 // Now start a new pending navigation and go back before it commits. 1596 // Now start a new pending navigation and go back before it commits.
1558 controller.LoadURL( 1597 controller.LoadURL(
1559 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1598 kUrl3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1560 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1599 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1561 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); 1600 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL());
1562 controller.GoBack(); 1601 controller.GoBack();
1563 1602
1564 // The pending navigation should now be the "back" item and the new one 1603 // The pending navigation should now be the "back" item and the new one
1565 // should be gone. 1604 // should be gone.
1566 EXPECT_EQ(0, controller.GetPendingEntryIndex()); 1605 EXPECT_EQ(0, controller.GetPendingEntryIndex());
1567 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); 1606 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL());
1568 } 1607 }
1569 1608
1570 // Receives a back message when there is a different renavigation already 1609 // Again, this VVVV seems impossible: particularly the unsolicited renderer
1571 // pending. 1610 // history navigation backwards to kUrl2.
1572 TEST_F(NavigationControllerTest, Back_OtherBackPending) {
1573 NavigationControllerImpl& controller = controller_impl();
1574 const GURL kUrl1("http://foo/1");
1575 const GURL kUrl2("http://foo/2");
1576 const GURL kUrl3("http://foo/3");
1577 1611
1578 // First navigate three places so we have some back history. 1612 // // Receives a back message when there is a different renavigation already
1579 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); 1613 // // pending.
1580 main_test_rfh()->PrepareForCommit(); 1614 // TEST_F(NavigationControllerTest, Back_OtherBackPending) {
1581 main_test_rfh()->SendNavigate(0, kUrl1); 1615 // NavigationControllerImpl& controller = controller_impl();
1582 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); 1616 // const GURL kUrl1("http://foo/1");
1583 main_test_rfh()->PrepareForCommit(); 1617 // const GURL kUrl2("http://foo/2");
1584 main_test_rfh()->SendNavigate(1, kUrl2); 1618 // const GURL kUrl3("http://foo/3");
1585 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true);
1586 main_test_rfh()->PrepareForCommit();
1587 main_test_rfh()->SendNavigate(2, kUrl3);
1588 1619
1589 // With nothing pending, say we get a navigation to the second entry. 1620 // // First navigate three places so we have some back history.
1590 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); 1621 // main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true);
1591 main_test_rfh()->PrepareForCommit(); 1622 // main_test_rfh()->PrepareForCommit();
1592 main_test_rfh()->SendNavigate(1, kUrl2); 1623 // main_test_rfh()->SendNavigate(0, 0, true, kUrl1);
1624 // main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true);
1625 // main_test_rfh()->PrepareForCommit();
1626 // main_test_rfh()->SendNavigate(1, 0, true, kUrl2);
1627 // main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true);
1628 // main_test_rfh()->PrepareForCommit();
1629 // main_test_rfh()->SendNavigate(2, 0, true, kUrl3);
1593 1630
1594 // We know all the entries have the same site instance, so we can just grab 1631 // // With nothing pending, say we get a navigation to the second entry.
1595 // a random one for looking up other entries. 1632 // main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true);
1596 SiteInstance* site_instance = 1633 // main_test_rfh()->PrepareForCommit();
1597 controller.GetLastCommittedEntry()->site_instance(); 1634 // main_test_rfh()->SendNavigate(1, kUrl2);
1598 1635
1599 // That second URL should be the last committed and it should have gotten the 1636 // // We know all the entries have the same site instance, so we can just grab
1600 // new title. 1637 // // a random one for looking up other entries.
1601 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); 1638 // SiteInstance* site_instance =
1602 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 1639 // controller.GetLastCommittedEntry()->site_instance();
1603 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1604 1640
1605 // Now go forward to the last item again and say it was committed. 1641 // // That second URL should be the last committed and it should have gotten t he
1606 controller.GoForward(); 1642 // // new title.
1607 main_test_rfh()->PrepareForCommit(); 1643 // EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()) ;
1608 main_test_rfh()->SendNavigate(2, kUrl3); 1644 // EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1645 // EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1609 1646
1610 // Now start going back one to the second page. It will be pending. 1647 // // Now go forward to the last item again and say it was committed.
1611 controller.GoBack(); 1648 // controller.GoForward();
1612 EXPECT_EQ(1, controller.GetPendingEntryIndex()); 1649 // main_test_rfh()->PrepareForCommit();
1613 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 1650 // main_test_rfh()->SendNavigate(2, kUrl3);
1614 1651
1615 // Now synthesize a totally new back event to the first page. This will not 1652 // // Now start going back one to the second page. It will be pending.
1616 // match the pending one. 1653 // controller.GoBack();
1617 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); 1654 // EXPECT_EQ(1, controller.GetPendingEntryIndex());
1618 main_test_rfh()->PrepareForCommit(); 1655 // EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
1619 main_test_rfh()->SendNavigate(0, kUrl1);
1620 1656
1621 // The committed navigation should clear the pending entry. 1657 // // Now synthesize a totally new back event to the first page. This will not
1622 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 1658 // // match the pending one.
1659 // main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true);
1660 // main_test_rfh()->PrepareForCommit();
1661 // main_test_rfh()->SendNavigate(0, kUrl1);
1623 1662
1624 // But the navigated entry should be the last committed. 1663 // // The committed navigation should clear the pending entry.
1625 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 1664 // EXPECT_EQ(-1, controller.GetPendingEntryIndex());
1626 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); 1665
1627 } 1666 // // But the navigated entry should be the last committed.
1667 // EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
1668 // EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL());
1669 // }
1628 1670
1629 // Tests what happens when we navigate forward successfully. 1671 // Tests what happens when we navigate forward successfully.
1630 TEST_F(NavigationControllerTest, Forward) { 1672 TEST_F(NavigationControllerTest, Forward) {
1631 NavigationControllerImpl& controller = controller_impl(); 1673 NavigationControllerImpl& controller = controller_impl();
1632 TestNotificationTracker notifications; 1674 TestNotificationTracker notifications;
1633 RegisterForAllNavNotifications(&notifications, &controller); 1675 RegisterForAllNavNotifications(&notifications, &controller);
1634 1676
1635 const GURL url1("http://foo1"); 1677 const GURL url1("http://foo1");
1636 const GURL url2("http://foo2"); 1678 const GURL url2("http://foo2");
1637 1679
1638 main_test_rfh()->PrepareForCommit(); 1680 main_test_rfh()->PrepareForCommit();
1639 main_test_rfh()->SendNavigate(0, url1); 1681 main_test_rfh()->SendNavigate(0, 0, true, url1);
1682 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
1640 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1683 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1641 navigation_entry_committed_counter_ = 0; 1684 navigation_entry_committed_counter_ = 0;
1642 1685
1643 main_test_rfh()->PrepareForCommit(); 1686 main_test_rfh()->PrepareForCommit();
1644 main_test_rfh()->SendNavigate(1, url2); 1687 main_test_rfh()->SendNavigate(1, 0, true, url2);
1688 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
1645 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1689 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1646 navigation_entry_committed_counter_ = 0; 1690 navigation_entry_committed_counter_ = 0;
1647 1691
1648 controller.GoBack(); 1692 controller.GoBack();
1649 main_test_rfh()->PrepareForCommit(); 1693 main_test_rfh()->PrepareForCommit();
1650 main_test_rfh()->SendNavigate(0, url1); 1694 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), false, url1);
1651 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1695 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1652 navigation_entry_committed_counter_ = 0; 1696 navigation_entry_committed_counter_ = 0;
1653 1697
1654 controller.GoForward(); 1698 controller.GoForward();
1655 1699
1656 // We should now have a pending navigation to go forward. 1700 // We should now have a pending navigation to go forward.
1657 EXPECT_EQ(controller.GetEntryCount(), 2); 1701 EXPECT_EQ(controller.GetEntryCount(), 2);
1658 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1702 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1659 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); 1703 EXPECT_EQ(controller.GetPendingEntryIndex(), 1);
1660 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1704 EXPECT_TRUE(controller.GetLastCommittedEntry());
1661 EXPECT_TRUE(controller.GetPendingEntry()); 1705 EXPECT_TRUE(controller.GetPendingEntry());
1662 EXPECT_TRUE(controller.CanGoBack()); 1706 EXPECT_TRUE(controller.CanGoBack());
1663 EXPECT_TRUE(controller.CanGoToOffset(-1)); 1707 EXPECT_TRUE(controller.CanGoToOffset(-1));
1664 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. 1708 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps.
1665 EXPECT_FALSE(controller.CanGoForward()); 1709 EXPECT_FALSE(controller.CanGoForward());
1666 EXPECT_FALSE(controller.CanGoToOffset(1)); 1710 EXPECT_FALSE(controller.CanGoToOffset(1));
1667 1711
1668 // Timestamp for entry 0 should be on or after that of entry 1 1712 // Timestamp for entry 0 should be on or after that of entry 1
1669 // (since we went back to it). 1713 // (since we went back to it).
1670 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); 1714 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null());
1671 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), 1715 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(),
1672 controller.GetEntryAtIndex(1)->GetTimestamp()); 1716 controller.GetEntryAtIndex(1)->GetTimestamp());
1673 1717
1674 main_test_rfh()->PrepareForCommit(); 1718 main_test_rfh()->PrepareForCommit();
1675 main_test_rfh()->SendNavigate(1, url2); 1719 main_test_rfh()->SendNavigate(1, entry2->GetUniqueID(), false, url2);
1676 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1720 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1677 navigation_entry_committed_counter_ = 0; 1721 navigation_entry_committed_counter_ = 0;
1678 1722
1679 // The forward navigation completed successfully. 1723 // The forward navigation completed successfully.
1680 EXPECT_EQ(controller.GetEntryCount(), 2); 1724 EXPECT_EQ(controller.GetEntryCount(), 2);
1681 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1725 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1682 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1726 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1683 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1727 EXPECT_TRUE(controller.GetLastCommittedEntry());
1684 EXPECT_FALSE(controller.GetPendingEntry()); 1728 EXPECT_FALSE(controller.GetPendingEntry());
1685 EXPECT_TRUE(controller.CanGoBack()); 1729 EXPECT_TRUE(controller.CanGoBack());
(...skipping 12 matching lines...) Expand all
1698 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { 1742 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) {
1699 NavigationControllerImpl& controller = controller_impl(); 1743 NavigationControllerImpl& controller = controller_impl();
1700 TestNotificationTracker notifications; 1744 TestNotificationTracker notifications;
1701 RegisterForAllNavNotifications(&notifications, &controller); 1745 RegisterForAllNavNotifications(&notifications, &controller);
1702 1746
1703 const GURL url1("http://foo1"); 1747 const GURL url1("http://foo1");
1704 const GURL url2("http://foo2"); 1748 const GURL url2("http://foo2");
1705 const GURL url3("http://foo3"); 1749 const GURL url3("http://foo3");
1706 1750
1707 main_test_rfh()->PrepareForCommit(); 1751 main_test_rfh()->PrepareForCommit();
1708 main_test_rfh()->SendNavigate(0, url1); 1752 main_test_rfh()->SendNavigate(0, 0, true, url1);
1709 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1753 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1754 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
1710 navigation_entry_committed_counter_ = 0; 1755 navigation_entry_committed_counter_ = 0;
1756
1711 main_test_rfh()->PrepareForCommit(); 1757 main_test_rfh()->PrepareForCommit();
1712 main_test_rfh()->SendNavigate(1, url2); 1758 main_test_rfh()->SendNavigate(1, 0, true, url2);
1713 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1759 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1760 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
1714 navigation_entry_committed_counter_ = 0; 1761 navigation_entry_committed_counter_ = 0;
1715 1762
1716 controller.GoBack(); 1763 controller.GoBack();
1717 main_test_rfh()->PrepareForCommit(); 1764 main_test_rfh()->PrepareForCommit();
1718 main_test_rfh()->SendNavigate(0, url1); 1765 main_test_rfh()->SendNavigate(0, entry1->GetUniqueID(), false, url1);
1719 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1766 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1720 navigation_entry_committed_counter_ = 0; 1767 navigation_entry_committed_counter_ = 0;
1721 1768
1722 controller.GoForward(); 1769 controller.GoForward();
1723 EXPECT_EQ(0U, notifications.size()); 1770 EXPECT_EQ(0U, notifications.size());
1724 1771
1725 // Should now have a pending navigation to go forward. 1772 // Should now have a pending navigation to go forward.
1726 EXPECT_EQ(controller.GetEntryCount(), 2); 1773 EXPECT_EQ(controller.GetEntryCount(), 2);
1727 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 1774 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
1728 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); 1775 EXPECT_EQ(controller.GetPendingEntryIndex(), 1);
1729 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1776 EXPECT_TRUE(controller.GetLastCommittedEntry());
1730 EXPECT_TRUE(controller.GetPendingEntry()); 1777 EXPECT_TRUE(controller.GetPendingEntry());
1731 EXPECT_TRUE(controller.CanGoBack()); 1778 EXPECT_TRUE(controller.CanGoBack());
1732 EXPECT_FALSE(controller.CanGoForward()); 1779 EXPECT_FALSE(controller.CanGoForward());
1733 1780
1734 main_test_rfh()->PrepareForCommit(); 1781 main_test_rfh()->PrepareForCommit();
1735 main_test_rfh()->SendNavigate(2, url3); 1782 main_test_rfh()->SendNavigate(2, entry2->GetUniqueID(), true, url3);
1736 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1783 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1737 navigation_entry_committed_counter_ = 0; 1784 navigation_entry_committed_counter_ = 0;
1738 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); 1785 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED));
1739 1786
1740 EXPECT_EQ(controller.GetEntryCount(), 2); 1787 EXPECT_EQ(controller.GetEntryCount(), 2);
1741 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 1788 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
1742 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1789 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1743 EXPECT_TRUE(controller.GetLastCommittedEntry()); 1790 EXPECT_TRUE(controller.GetLastCommittedEntry());
1744 EXPECT_FALSE(controller.GetPendingEntry()); 1791 EXPECT_FALSE(controller.GetPendingEntry());
1745 EXPECT_TRUE(controller.CanGoBack()); 1792 EXPECT_TRUE(controller.CanGoBack());
1746 EXPECT_FALSE(controller.CanGoForward()); 1793 EXPECT_FALSE(controller.CanGoForward());
1747 } 1794 }
1748 1795
1749 // Two consequent navigation for the same URL entered in should be considered 1796 // Two consecutive navigations for the same URL entered in should be considered
1750 // as SAME_PAGE navigation even when we are redirected to some other page. 1797 // as SAME_PAGE navigation even when we are redirected to some other page.
1751 TEST_F(NavigationControllerTest, Redirect) { 1798 TEST_F(NavigationControllerTest, Redirect) {
1752 NavigationControllerImpl& controller = controller_impl(); 1799 NavigationControllerImpl& controller = controller_impl();
1753 TestNotificationTracker notifications; 1800 TestNotificationTracker notifications;
1754 RegisterForAllNavNotifications(&notifications, &controller); 1801 RegisterForAllNavNotifications(&notifications, &controller);
1755 1802
1756 const GURL url1("http://foo1"); 1803 const GURL url1("http://foo1");
1757 const GURL url2("http://foo2"); // Redirection target 1804 const GURL url2("http://foo2"); // Redirection target
1758 1805
1759 // First request 1806 // First request
1760 controller.LoadURL( 1807 controller.LoadURL(
1761 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1808 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1809 NavigationEntry* entry = controller.GetPendingEntry();
1762 1810
1763 EXPECT_EQ(0U, notifications.size()); 1811 EXPECT_EQ(0U, notifications.size());
1764 main_test_rfh()->SendNavigate(0, url2); 1812 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url2);
1765 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1813 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1766 navigation_entry_committed_counter_ = 0; 1814 navigation_entry_committed_counter_ = 0;
1767 1815
1768 // Second request 1816 // Second request
1769 controller.LoadURL( 1817 controller.LoadURL(
1770 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1818 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1819 entry = controller.GetPendingEntry();
1771 1820
1772 EXPECT_TRUE(controller.GetPendingEntry()); 1821 EXPECT_TRUE(controller.GetPendingEntry());
1773 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1822 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1774 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1823 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1775 1824
1776 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1825 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1777 params.page_id = 0; 1826 params.page_id = 0;
1827 params.nav_entry_id = entry->GetUniqueID();
1828 params.did_create_new_entry = false;
1778 params.url = url2; 1829 params.url = url2;
1779 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1830 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1780 params.redirects.push_back(GURL("http://foo1")); 1831 params.redirects.push_back(GURL("http://foo1"));
1781 params.redirects.push_back(GURL("http://foo2")); 1832 params.redirects.push_back(GURL("http://foo2"));
1782 params.should_update_history = false; 1833 params.should_update_history = false;
1783 params.gesture = NavigationGestureAuto; 1834 params.gesture = NavigationGestureAuto;
1784 params.is_post = false; 1835 params.is_post = false;
1785 params.page_state = PageState::CreateFromURL(url2); 1836 params.page_state = PageState::CreateFromURL(url2);
1786 1837
1787 LoadCommittedDetails details; 1838 LoadCommittedDetails details;
(...skipping 23 matching lines...) Expand all
1811 NavigationControllerImpl& controller = controller_impl(); 1862 NavigationControllerImpl& controller = controller_impl();
1812 TestNotificationTracker notifications; 1863 TestNotificationTracker notifications;
1813 RegisterForAllNavNotifications(&notifications, &controller); 1864 RegisterForAllNavNotifications(&notifications, &controller);
1814 1865
1815 const GURL url1("http://foo1"); 1866 const GURL url1("http://foo1");
1816 const GURL url2("http://foo2"); // Redirection target 1867 const GURL url2("http://foo2"); // Redirection target
1817 1868
1818 // First request as POST 1869 // First request as POST
1819 controller.LoadURL( 1870 controller.LoadURL(
1820 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1871 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1872 NavigationEntry* entry = controller.GetPendingEntry();
1821 controller.GetVisibleEntry()->SetHasPostData(true); 1873 controller.GetVisibleEntry()->SetHasPostData(true);
1822 1874
1823 EXPECT_EQ(0U, notifications.size()); 1875 EXPECT_EQ(0U, notifications.size());
1824 main_test_rfh()->SendNavigate(0, url2); 1876 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url2);
1825 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1877 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1826 navigation_entry_committed_counter_ = 0; 1878 navigation_entry_committed_counter_ = 0;
1827 1879
1828 // Second request 1880 // Second request
1829 controller.LoadURL( 1881 controller.LoadURL(
1830 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 1882 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
1883 entry = controller.GetPendingEntry();
1831 1884
1832 EXPECT_TRUE(controller.GetPendingEntry()); 1885 EXPECT_TRUE(controller.GetPendingEntry());
1833 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 1886 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
1834 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 1887 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
1835 1888
1836 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1889 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1837 params.page_id = 0; 1890 params.page_id = 0;
1891 params.nav_entry_id = entry->GetUniqueID();
1892 params.did_create_new_entry = false;
1838 params.url = url2; 1893 params.url = url2;
1839 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT; 1894 params.transition = ui::PAGE_TRANSITION_SERVER_REDIRECT;
1840 params.redirects.push_back(GURL("http://foo1")); 1895 params.redirects.push_back(GURL("http://foo1"));
1841 params.redirects.push_back(GURL("http://foo2")); 1896 params.redirects.push_back(GURL("http://foo2"));
1842 params.should_update_history = false; 1897 params.should_update_history = false;
1843 params.gesture = NavigationGestureAuto; 1898 params.gesture = NavigationGestureAuto;
1844 params.is_post = false; 1899 params.is_post = false;
1845 params.page_state = PageState::CreateFromURL(url2); 1900 params.page_state = PageState::CreateFromURL(url2);
1846 1901
1847 LoadCommittedDetails details; 1902 LoadCommittedDetails details;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 } 1969 }
1915 1970
1916 // Tests navigation via link click within a subframe. A new navigation entry 1971 // Tests navigation via link click within a subframe. A new navigation entry
1917 // should be created. 1972 // should be created.
1918 TEST_F(NavigationControllerTest, NewSubframe) { 1973 TEST_F(NavigationControllerTest, NewSubframe) {
1919 NavigationControllerImpl& controller = controller_impl(); 1974 NavigationControllerImpl& controller = controller_impl();
1920 TestNotificationTracker notifications; 1975 TestNotificationTracker notifications;
1921 RegisterForAllNavNotifications(&notifications, &controller); 1976 RegisterForAllNavNotifications(&notifications, &controller);
1922 1977
1923 const GURL url1("http://foo1"); 1978 const GURL url1("http://foo1");
1924 main_test_rfh()->SendNavigate(0, url1); 1979 main_test_rfh()->SendNavigate(0, 0, true, url1);
1925 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1980 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1926 navigation_entry_committed_counter_ = 0; 1981 navigation_entry_committed_counter_ = 0;
1927 1982
1928 const GURL url2("http://foo2"); 1983 const GURL url2("http://foo2");
1929 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1984 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1930 params.page_id = 1; 1985 params.page_id = 1;
1986 params.nav_entry_id = 0;
1987 params.did_create_new_entry = true;
1931 params.url = url2; 1988 params.url = url2;
1932 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 1989 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
1933 params.should_update_history = false; 1990 params.should_update_history = false;
1934 params.gesture = NavigationGestureUser; 1991 params.gesture = NavigationGestureUser;
1935 params.is_post = false; 1992 params.is_post = false;
1936 params.page_state = PageState::CreateFromURL(url2); 1993 params.page_state = PageState::CreateFromURL(url2);
1937 1994
1938 LoadCommittedDetails details; 1995 LoadCommittedDetails details;
1939 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 1996 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
1940 &details)); 1997 &details));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 } 2036 }
1980 2037
1981 // Auto subframes are ones the page loads automatically like ads. They should 2038 // Auto subframes are ones the page loads automatically like ads. They should
1982 // not create new navigation entries. 2039 // not create new navigation entries.
1983 TEST_F(NavigationControllerTest, AutoSubframe) { 2040 TEST_F(NavigationControllerTest, AutoSubframe) {
1984 NavigationControllerImpl& controller = controller_impl(); 2041 NavigationControllerImpl& controller = controller_impl();
1985 TestNotificationTracker notifications; 2042 TestNotificationTracker notifications;
1986 RegisterForAllNavNotifications(&notifications, &controller); 2043 RegisterForAllNavNotifications(&notifications, &controller);
1987 2044
1988 const GURL url1("http://foo1"); 2045 const GURL url1("http://foo1");
1989 main_test_rfh()->SendNavigate(0, url1); 2046 main_test_rfh()->SendNavigate(0, 0, true, url1);
1990 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2047 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1991 navigation_entry_committed_counter_ = 0; 2048 navigation_entry_committed_counter_ = 0;
1992 2049
1993 const GURL url2("http://foo2"); 2050 const GURL url2("http://foo2");
1994 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2051 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1995 params.page_id = 0; 2052 params.page_id = 0;
2053 params.nav_entry_id = 0;
2054 params.did_create_new_entry = false;
1996 params.url = url2; 2055 params.url = url2;
1997 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2056 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
1998 params.should_update_history = false; 2057 params.should_update_history = false;
1999 params.gesture = NavigationGestureUser; 2058 params.gesture = NavigationGestureUser;
2000 params.is_post = false; 2059 params.is_post = false;
2001 params.page_state = PageState::CreateFromURL(url2); 2060 params.page_state = PageState::CreateFromURL(url2);
2002 2061
2003 // Navigating should do nothing. 2062 // Navigating should do nothing.
2004 LoadCommittedDetails details; 2063 LoadCommittedDetails details;
2005 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 2064 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params,
2006 &details)); 2065 &details));
2007 EXPECT_EQ(0U, notifications.size()); 2066 EXPECT_EQ(0U, notifications.size());
2008 2067
2009 // There should still be only one entry. 2068 // There should still be only one entry.
2010 EXPECT_EQ(1, controller.GetEntryCount()); 2069 EXPECT_EQ(1, controller.GetEntryCount());
2011 } 2070 }
2012 2071
2013 // Tests navigation and then going back to a subframe navigation. 2072 // Tests navigation and then going back to a subframe navigation.
2014 TEST_F(NavigationControllerTest, BackSubframe) { 2073 TEST_F(NavigationControllerTest, BackSubframe) {
2015 NavigationControllerImpl& controller = controller_impl(); 2074 NavigationControllerImpl& controller = controller_impl();
2016 TestNotificationTracker notifications; 2075 TestNotificationTracker notifications;
2017 RegisterForAllNavNotifications(&notifications, &controller); 2076 RegisterForAllNavNotifications(&notifications, &controller);
2018 2077
2019 // Main page. 2078 // Main page.
2020 const GURL url1("http://foo1"); 2079 const GURL url1("http://foo1");
2021 main_test_rfh()->SendNavigate(0, url1); 2080 main_test_rfh()->SendNavigate(0, 0, true, url1);
2022 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2081 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2082 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2023 navigation_entry_committed_counter_ = 0; 2083 navigation_entry_committed_counter_ = 0;
2024 2084
2025 // First manual subframe navigation. 2085 // First manual subframe navigation.
2026 const GURL url2("http://foo2"); 2086 const GURL url2("http://foo2");
2027 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2087 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2028 params.page_id = 1; 2088 params.page_id = 1;
2089 params.nav_entry_id = 0;
2090 params.did_create_new_entry = true;
2029 params.url = url2; 2091 params.url = url2;
2030 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2092 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2031 params.should_update_history = false; 2093 params.should_update_history = false;
2032 params.gesture = NavigationGestureUser; 2094 params.gesture = NavigationGestureUser;
2033 params.is_post = false; 2095 params.is_post = false;
2034 params.page_state = PageState::CreateFromURL(url2); 2096 params.page_state = PageState::CreateFromURL(url2);
2035 2097
2036 // This should generate a new entry. 2098 // This should generate a new entry.
2037 LoadCommittedDetails details; 2099 LoadCommittedDetails details;
2038 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2100 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2039 &details)); 2101 &details));
2102 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
2040 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2103 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2041 navigation_entry_committed_counter_ = 0; 2104 navigation_entry_committed_counter_ = 0;
2042 EXPECT_EQ(2, controller.GetEntryCount()); 2105 EXPECT_EQ(2, controller.GetEntryCount());
2043 2106
2044 // Second manual subframe navigation should also make a new entry. 2107 // Second manual subframe navigation should also make a new entry.
2045 const GURL url3("http://foo3"); 2108 const GURL url3("http://foo3");
2046 params.page_id = 2; 2109 params.page_id = 2;
2110 params.nav_entry_id = 0;
2111 params.did_create_new_entry = true;
2047 params.url = url3; 2112 params.url = url3;
2048 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2113 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2049 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2114 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2050 &details)); 2115 &details));
2051 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2116 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2052 navigation_entry_committed_counter_ = 0; 2117 navigation_entry_committed_counter_ = 0;
2053 EXPECT_EQ(3, controller.GetEntryCount()); 2118 EXPECT_EQ(3, controller.GetEntryCount());
2054 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2119 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2055 2120
2056 // Go back one. 2121 // Go back one.
2057 controller.GoBack(); 2122 controller.GoBack();
2058 params.page_id = 1; 2123 params.page_id = 1;
2124 params.nav_entry_id = entry2->GetUniqueID();
2125 params.did_create_new_entry = false;
2059 params.url = url2; 2126 params.url = url2;
2060 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2127 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2061 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2128 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2062 &details)); 2129 &details));
2063 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2130 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2064 navigation_entry_committed_counter_ = 0; 2131 navigation_entry_committed_counter_ = 0;
2065 EXPECT_EQ(3, controller.GetEntryCount()); 2132 EXPECT_EQ(3, controller.GetEntryCount());
2066 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2133 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2067 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2134 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2068 EXPECT_FALSE(controller.GetPendingEntry()); 2135 EXPECT_FALSE(controller.GetPendingEntry());
2069 2136
2070 // Go back one more. 2137 // Go back one more.
2071 controller.GoBack(); 2138 controller.GoBack();
2072 params.page_id = 0; 2139 params.page_id = 0;
2140 params.nav_entry_id = entry1->GetUniqueID();
2141 params.did_create_new_entry = false;
2073 params.url = url1; 2142 params.url = url1;
2074 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2143 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2075 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2144 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2076 &details)); 2145 &details));
2077 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2146 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2078 navigation_entry_committed_counter_ = 0; 2147 navigation_entry_committed_counter_ = 0;
2079 EXPECT_EQ(3, controller.GetEntryCount()); 2148 EXPECT_EQ(3, controller.GetEntryCount());
2080 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2149 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2081 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2150 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2082 EXPECT_FALSE(controller.GetPendingEntry()); 2151 EXPECT_FALSE(controller.GetPendingEntry());
2083 } 2152 }
2084 2153
2085 TEST_F(NavigationControllerTest, LinkClick) { 2154 TEST_F(NavigationControllerTest, LinkClick) {
2086 NavigationControllerImpl& controller = controller_impl(); 2155 NavigationControllerImpl& controller = controller_impl();
2087 TestNotificationTracker notifications; 2156 TestNotificationTracker notifications;
2088 RegisterForAllNavNotifications(&notifications, &controller); 2157 RegisterForAllNavNotifications(&notifications, &controller);
2089 2158
2090 const GURL url1("http://foo1"); 2159 const GURL url1("http://foo1");
2091 const GURL url2("http://foo2"); 2160 const GURL url2("http://foo2");
2092 2161
2093 main_test_rfh()->SendNavigate(0, url1); 2162 main_test_rfh()->SendNavigate(0, 0, true, url1);
2094 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2163 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2095 navigation_entry_committed_counter_ = 0; 2164 navigation_entry_committed_counter_ = 0;
2096 2165
2097 main_test_rfh()->SendNavigate(1, url2); 2166 main_test_rfh()->SendNavigate(1, 0, true, url2);
2098 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2167 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2099 navigation_entry_committed_counter_ = 0; 2168 navigation_entry_committed_counter_ = 0;
2100 2169
2101 // Should not have produced a new session history entry. 2170 // Should have produced a new session history entry.
2102 EXPECT_EQ(controller.GetEntryCount(), 2); 2171 EXPECT_EQ(controller.GetEntryCount(), 2);
2103 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 2172 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
2104 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2173 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2105 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2174 EXPECT_TRUE(controller.GetLastCommittedEntry());
2106 EXPECT_FALSE(controller.GetPendingEntry()); 2175 EXPECT_FALSE(controller.GetPendingEntry());
2107 EXPECT_TRUE(controller.CanGoBack()); 2176 EXPECT_TRUE(controller.CanGoBack());
2108 EXPECT_FALSE(controller.CanGoForward()); 2177 EXPECT_FALSE(controller.CanGoForward());
2109 } 2178 }
2110 2179
2111 TEST_F(NavigationControllerTest, InPage) { 2180 TEST_F(NavigationControllerTest, InPage) {
2112 NavigationControllerImpl& controller = controller_impl(); 2181 NavigationControllerImpl& controller = controller_impl();
2113 TestNotificationTracker notifications; 2182 TestNotificationTracker notifications;
2114 RegisterForAllNavNotifications(&notifications, &controller); 2183 RegisterForAllNavNotifications(&notifications, &controller);
2115 2184
2116 // Main page. 2185 // Main page.
2117 const GURL url1("http://foo"); 2186 const GURL url1("http://foo");
2118 main_test_rfh()->SendNavigate(0, url1); 2187 main_test_rfh()->SendNavigate(0, 0, true, url1);
2119 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2188 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2120 navigation_entry_committed_counter_ = 0; 2189 navigation_entry_committed_counter_ = 0;
2121 2190
2122 // Ensure main page navigation to same url respects the was_within_same_page 2191 // Ensure main page navigation to same url respects the was_within_same_page
2123 // hint provided in the params. 2192 // hint provided in the params.
2124 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; 2193 FrameHostMsg_DidCommitProvisionalLoad_Params self_params;
2125 self_params.page_id = 0; 2194 self_params.page_id = 0;
2195 self_params.nav_entry_id = 0;
2196 self_params.did_create_new_entry = false;
2126 self_params.url = url1; 2197 self_params.url = url1;
2127 self_params.transition = ui::PAGE_TRANSITION_LINK; 2198 self_params.transition = ui::PAGE_TRANSITION_LINK;
2128 self_params.should_update_history = false; 2199 self_params.should_update_history = false;
2129 self_params.gesture = NavigationGestureUser; 2200 self_params.gesture = NavigationGestureUser;
2130 self_params.is_post = false; 2201 self_params.is_post = false;
2131 self_params.page_state = PageState::CreateFromURL(url1); 2202 self_params.page_state = PageState::CreateFromURL(url1);
2132 self_params.was_within_same_page = true; 2203 self_params.was_within_same_page = true;
2133 2204
2134 LoadCommittedDetails details; 2205 LoadCommittedDetails details;
2135 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params, 2206 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), self_params,
2136 &details)); 2207 &details));
2208 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2137 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2209 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2138 navigation_entry_committed_counter_ = 0; 2210 navigation_entry_committed_counter_ = 0;
2139 EXPECT_TRUE(details.is_in_page); 2211 EXPECT_TRUE(details.is_in_page);
2140 EXPECT_TRUE(details.did_replace_entry); 2212 EXPECT_TRUE(details.did_replace_entry);
2141 EXPECT_EQ(1, controller.GetEntryCount()); 2213 EXPECT_EQ(1, controller.GetEntryCount());
2142 2214
2143 // Fragment navigation to a new page_id. 2215 // Fragment navigation to a new page_id.
2144 const GURL url2("http://foo#a"); 2216 const GURL url2("http://foo#a");
2145 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2217 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2146 params.page_id = 1; 2218 params.page_id = 1;
2219 params.nav_entry_id = 0;
2220 params.did_create_new_entry = true;
2147 params.url = url2; 2221 params.url = url2;
2148 params.transition = ui::PAGE_TRANSITION_LINK; 2222 params.transition = ui::PAGE_TRANSITION_LINK;
2149 params.should_update_history = false; 2223 params.should_update_history = false;
2150 params.gesture = NavigationGestureUser; 2224 params.gesture = NavigationGestureUser;
2151 params.is_post = false; 2225 params.is_post = false;
2152 params.page_state = PageState::CreateFromURL(url2); 2226 params.page_state = PageState::CreateFromURL(url2);
2153 params.was_within_same_page = true; 2227 params.was_within_same_page = true;
2154 2228
2155 // This should generate a new entry. 2229 // This should generate a new entry.
2156 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2230 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2157 &details)); 2231 &details));
2232 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
2158 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2233 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2159 navigation_entry_committed_counter_ = 0; 2234 navigation_entry_committed_counter_ = 0;
2160 EXPECT_TRUE(details.is_in_page); 2235 EXPECT_TRUE(details.is_in_page);
2161 EXPECT_FALSE(details.did_replace_entry); 2236 EXPECT_FALSE(details.did_replace_entry);
2162 EXPECT_EQ(2, controller.GetEntryCount()); 2237 EXPECT_EQ(2, controller.GetEntryCount());
2163 2238
2164 // Go back one. 2239 // Go back one.
2165 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); 2240 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params);
2166 controller.GoBack(); 2241 controller.GoBack();
2167 back_params.url = url1; 2242 back_params.url = url1;
2168 back_params.page_id = 0; 2243 back_params.page_id = 0;
2244 back_params.nav_entry_id = entry1->GetUniqueID();
2245 back_params.did_create_new_entry = false;
2169 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, 2246 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params,
2170 &details)); 2247 &details));
2171 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2248 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2172 navigation_entry_committed_counter_ = 0; 2249 navigation_entry_committed_counter_ = 0;
2173 EXPECT_TRUE(details.is_in_page); 2250 EXPECT_TRUE(details.is_in_page);
2174 EXPECT_EQ(2, controller.GetEntryCount()); 2251 EXPECT_EQ(2, controller.GetEntryCount());
2175 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2252 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2176 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); 2253 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL());
2177 2254
2178 // Go forward 2255 // Go forward.
2179 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); 2256 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params);
2180 controller.GoForward(); 2257 controller.GoForward();
2181 forward_params.url = url2; 2258 forward_params.url = url2;
2182 forward_params.page_id = 1; 2259 forward_params.page_id = 1;
2260 forward_params.nav_entry_id = entry2->GetUniqueID();
2261 forward_params.did_create_new_entry = false;
2183 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, 2262 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params,
2184 &details)); 2263 &details));
2185 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2264 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2186 navigation_entry_committed_counter_ = 0; 2265 navigation_entry_committed_counter_ = 0;
2187 EXPECT_TRUE(details.is_in_page); 2266 EXPECT_TRUE(details.is_in_page);
2188 EXPECT_EQ(2, controller.GetEntryCount()); 2267 EXPECT_EQ(2, controller.GetEntryCount());
2189 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2268 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2190 EXPECT_EQ(forward_params.url, 2269 EXPECT_EQ(forward_params.url,
2191 controller.GetVisibleEntry()->GetURL()); 2270 controller.GetVisibleEntry()->GetURL());
2192 2271
2193 // Now go back and forward again. This is to work around a bug where we would 2272 // Now go back and forward again. This is to work around a bug where we would
2194 // compare the incoming URL with the last committed entry rather than the 2273 // compare the incoming URL with the last committed entry rather than the
2195 // one identified by an existing page ID. This would result in the second URL 2274 // one identified by an existing page ID. This would result in the second URL
2196 // losing the reference fragment when you navigate away from it and then back. 2275 // losing the reference fragment when you navigate away from it and then back.
2197 controller.GoBack(); 2276 controller.GoBack();
2198 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params, 2277 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), back_params,
2199 &details)); 2278 &details));
2200 controller.GoForward(); 2279 controller.GoForward();
2201 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params, 2280 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), forward_params,
2202 &details)); 2281 &details));
2203 EXPECT_EQ(forward_params.url, 2282 EXPECT_EQ(forward_params.url,
2204 controller.GetVisibleEntry()->GetURL()); 2283 controller.GetVisibleEntry()->GetURL());
2205 2284
2206 // Finally, navigate to an unrelated URL to make sure in_page is not sticky. 2285 // Finally, navigate to an unrelated URL to make sure in_page is not sticky.
2207 const GURL url3("http://bar"); 2286 const GURL url3("http://bar");
2208 params.page_id = 2; 2287 params.page_id = 2;
2288 params.nav_entry_id = 0;
2289 params.did_create_new_entry = true;
2209 params.url = url3; 2290 params.url = url3;
2210 navigation_entry_committed_counter_ = 0; 2291 navigation_entry_committed_counter_ = 0;
2211 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2292 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2212 &details)); 2293 &details));
2213 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2294 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2214 navigation_entry_committed_counter_ = 0; 2295 navigation_entry_committed_counter_ = 0;
2215 EXPECT_FALSE(details.is_in_page); 2296 EXPECT_FALSE(details.is_in_page);
2216 EXPECT_EQ(3, controller.GetEntryCount()); 2297 EXPECT_EQ(3, controller.GetEntryCount());
2217 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2298 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2218 } 2299 }
2219 2300
2220 TEST_F(NavigationControllerTest, InPage_Replace) { 2301 TEST_F(NavigationControllerTest, InPage_Replace) {
2221 NavigationControllerImpl& controller = controller_impl(); 2302 NavigationControllerImpl& controller = controller_impl();
2222 TestNotificationTracker notifications; 2303 TestNotificationTracker notifications;
2223 RegisterForAllNavNotifications(&notifications, &controller); 2304 RegisterForAllNavNotifications(&notifications, &controller);
2224 2305
2225 // Main page. 2306 // Main page.
2226 const GURL url1("http://foo"); 2307 const GURL url1("http://foo");
2227 main_test_rfh()->SendNavigate(0, url1); 2308 main_test_rfh()->SendNavigate(0, 0, true, url1);
2228 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2309 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2229 navigation_entry_committed_counter_ = 0; 2310 navigation_entry_committed_counter_ = 0;
2230 2311
2231 // First navigation. 2312 // First navigation.
2232 const GURL url2("http://foo#a"); 2313 const GURL url2("http://foo#a");
2233 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2314 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2234 params.page_id = 0; // Same page_id 2315 params.page_id = 0; // Same page_id
2316 params.nav_entry_id = 0;
2317 params.did_create_new_entry = false;
2235 params.url = url2; 2318 params.url = url2;
2236 params.transition = ui::PAGE_TRANSITION_LINK; 2319 params.transition = ui::PAGE_TRANSITION_LINK;
2237 params.should_update_history = false; 2320 params.should_update_history = false;
2238 params.gesture = NavigationGestureUser; 2321 params.gesture = NavigationGestureUser;
2239 params.is_post = false; 2322 params.is_post = false;
2240 params.page_state = PageState::CreateFromURL(url2); 2323 params.page_state = PageState::CreateFromURL(url2);
2241 params.was_within_same_page = true; 2324 params.was_within_same_page = true;
2242 2325
2243 // This should NOT generate a new entry, nor prune the list. 2326 // This should NOT generate a new entry, nor prune the list.
2244 LoadCommittedDetails details; 2327 LoadCommittedDetails details;
(...skipping 13 matching lines...) Expand all
2258 // window.location='http://foo3/'; 2341 // window.location='http://foo3/';
2259 // </script> 2342 // </script>
2260 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { 2343 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) {
2261 NavigationControllerImpl& controller = controller_impl(); 2344 NavigationControllerImpl& controller = controller_impl();
2262 TestNotificationTracker notifications; 2345 TestNotificationTracker notifications;
2263 RegisterForAllNavNotifications(&notifications, &controller); 2346 RegisterForAllNavNotifications(&notifications, &controller);
2264 2347
2265 // Load an initial page. 2348 // Load an initial page.
2266 { 2349 {
2267 const GURL url("http://foo/"); 2350 const GURL url("http://foo/");
2268 main_test_rfh()->SendNavigate(0, url); 2351 main_test_rfh()->SendNavigate(0, 0, true, url);
2269 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2352 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2270 navigation_entry_committed_counter_ = 0; 2353 navigation_entry_committed_counter_ = 0;
2271 } 2354 }
2272 2355
2273 // Navigate to a new page. 2356 // Navigate to a new page.
2274 { 2357 {
2275 const GURL url("http://foo2/"); 2358 const GURL url("http://foo2/");
2276 main_test_rfh()->SendNavigate(1, url); 2359 main_test_rfh()->SendNavigate(1, 0, true, url);
2277 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2360 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2278 navigation_entry_committed_counter_ = 0; 2361 navigation_entry_committed_counter_ = 0;
2279 } 2362 }
2280 2363
2281 // Navigate within the page. 2364 // Navigate within the page.
2282 { 2365 {
2283 const GURL url("http://foo2/#a"); 2366 const GURL url("http://foo2/#a");
2284 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2367 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2285 params.page_id = 1; // Same page_id 2368 params.page_id = 1; // Same page_id
2369 params.nav_entry_id = 0;
2370 params.did_create_new_entry = false;
2286 params.url = url; 2371 params.url = url;
2287 params.transition = ui::PAGE_TRANSITION_LINK; 2372 params.transition = ui::PAGE_TRANSITION_LINK;
2288 params.redirects.push_back(url); 2373 params.redirects.push_back(url);
2289 params.should_update_history = true; 2374 params.should_update_history = true;
2290 params.gesture = NavigationGestureUnknown; 2375 params.gesture = NavigationGestureUnknown;
2291 params.is_post = false; 2376 params.is_post = false;
2292 params.page_state = PageState::CreateFromURL(url); 2377 params.page_state = PageState::CreateFromURL(url);
2293 params.was_within_same_page = true; 2378 params.was_within_same_page = true;
2294 2379
2295 // This should NOT generate a new entry, nor prune the list. 2380 // This should NOT generate a new entry, nor prune the list.
2296 LoadCommittedDetails details; 2381 LoadCommittedDetails details;
2297 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2382 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2298 &details)); 2383 &details));
2299 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2384 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2300 navigation_entry_committed_counter_ = 0; 2385 navigation_entry_committed_counter_ = 0;
2301 EXPECT_TRUE(details.is_in_page); 2386 EXPECT_TRUE(details.is_in_page);
2302 EXPECT_TRUE(details.did_replace_entry); 2387 EXPECT_TRUE(details.did_replace_entry);
2303 EXPECT_EQ(2, controller.GetEntryCount()); 2388 EXPECT_EQ(2, controller.GetEntryCount());
2304 } 2389 }
2305 2390
2306 // Perform a client redirect to a new page. 2391 // Perform a client redirect to a new page.
2307 { 2392 {
2308 const GURL url("http://foo3/"); 2393 const GURL url("http://foo3/");
2309 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2394 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2310 params.page_id = 2; // New page_id 2395 params.page_id = 2; // New page_id
2396 params.nav_entry_id = 0;
2397 params.did_create_new_entry = true;
2311 params.url = url; 2398 params.url = url;
2312 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT; 2399 params.transition = ui::PAGE_TRANSITION_CLIENT_REDIRECT;
2313 params.redirects.push_back(GURL("http://foo2/#a")); 2400 params.redirects.push_back(GURL("http://foo2/#a"));
2314 params.redirects.push_back(url); 2401 params.redirects.push_back(url);
2315 params.should_update_history = true; 2402 params.should_update_history = true;
2316 params.gesture = NavigationGestureUnknown; 2403 params.gesture = NavigationGestureUnknown;
2317 params.is_post = false; 2404 params.is_post = false;
2318 params.page_state = PageState::CreateFromURL(url); 2405 params.page_state = PageState::CreateFromURL(url);
2319 2406
2320 // This SHOULD generate a new entry. 2407 // This SHOULD generate a new entry.
2321 LoadCommittedDetails details; 2408 LoadCommittedDetails details;
2322 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2409 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params,
2323 &details)); 2410 &details));
2324 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2411 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2325 navigation_entry_committed_counter_ = 0; 2412 navigation_entry_committed_counter_ = 0;
2326 EXPECT_FALSE(details.is_in_page); 2413 EXPECT_FALSE(details.is_in_page);
2327 EXPECT_EQ(3, controller.GetEntryCount()); 2414 EXPECT_EQ(3, controller.GetEntryCount());
2328 } 2415 }
2329 2416
2330 // Verify that BACK brings us back to http://foo2/. 2417 // Verify that BACK brings us back to http://foo2/.
2331 { 2418 {
2332 const GURL url("http://foo2/"); 2419 const GURL url("http://foo2/");
2333 controller.GoBack(); 2420 controller.GoBack();
2334 main_test_rfh()->SendNavigate(1, url); 2421 NavigationEntry* entry = controller.GetPendingEntry();
2422 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), false, url);
2335 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2423 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2336 navigation_entry_committed_counter_ = 0; 2424 navigation_entry_committed_counter_ = 0;
2337 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); 2425 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL());
2338 } 2426 }
2339 } 2427 }
2340 2428
2341 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry) 2429 TEST_F(NavigationControllerTest, PushStateWithoutPreviousEntry)
2342 { 2430 {
2343 ASSERT_FALSE(controller_impl().GetLastCommittedEntry()); 2431 ASSERT_FALSE(controller_impl().GetLastCommittedEntry());
2344 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2432 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2345 GURL url("http://foo"); 2433 GURL url("http://foo");
2346 params.page_id = 1; 2434 params.page_id = 1;
2435 params.nav_entry_id = 0;
2436 params.did_create_new_entry = true;
2347 params.url = url; 2437 params.url = url;
2348 params.page_state = PageState::CreateFromURL(url); 2438 params.page_state = PageState::CreateFromURL(url);
2349 params.was_within_same_page = true; 2439 params.was_within_same_page = true;
2350 contents()->GetMainFrame()->SendNavigateWithParams(&params); 2440 contents()->GetMainFrame()->SendNavigateWithParams(&params);
2351 // We pass if we don't crash. 2441 // We pass if we don't crash.
2352 } 2442 }
2353 2443
2354 // NotificationObserver implementation used in verifying we've received the 2444 // NotificationObserver implementation used in verifying we've received the
2355 // NOTIFICATION_NAV_LIST_PRUNED method. 2445 // NOTIFICATION_NAV_LIST_PRUNED method.
2356 class PrunedListener : public NotificationObserver { 2446 class PrunedListener : public NotificationObserver {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 const int kMaxEntryCount = 5; 2479 const int kMaxEntryCount = 5;
2390 2480
2391 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); 2481 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount);
2392 2482
2393 int url_index; 2483 int url_index;
2394 // Load up to the max count, all entries should be there. 2484 // Load up to the max count, all entries should be there.
2395 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { 2485 for (url_index = 0; url_index < kMaxEntryCount; url_index++) {
2396 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); 2486 GURL url(base::StringPrintf("http://www.a.com/%d", url_index));
2397 controller.LoadURL( 2487 controller.LoadURL(
2398 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2488 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2489 NavigationEntry* entry = controller.GetPendingEntry();
2399 main_test_rfh()->PrepareForCommit(); 2490 main_test_rfh()->PrepareForCommit();
2400 main_test_rfh()->SendNavigate(url_index, url); 2491 main_test_rfh()->SendNavigate(url_index, entry->GetUniqueID(), true, url);
2401 } 2492 }
2402 2493
2403 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); 2494 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount);
2404 2495
2405 // Created a PrunedListener to observe prune notifications. 2496 // Created a PrunedListener to observe prune notifications.
2406 PrunedListener listener(&controller); 2497 PrunedListener listener(&controller);
2407 2498
2408 // Navigate some more. 2499 // Navigate some more.
2409 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); 2500 GURL url(base::StringPrintf("http://www.a.com/%d", url_index));
2410 controller.LoadURL( 2501 controller.LoadURL(
2411 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2502 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2503 NavigationEntry* entry = controller.GetPendingEntry();
2412 main_test_rfh()->PrepareForCommit(); 2504 main_test_rfh()->PrepareForCommit();
2413 main_test_rfh()->SendNavigate(url_index, url); 2505 main_test_rfh()->SendNavigate(url_index, entry->GetUniqueID(), true, url);
2414 url_index++; 2506 url_index++;
2415 2507
2416 // We should have got a pruned navigation. 2508 // We should have got a pruned navigation.
2417 EXPECT_EQ(1, listener.notification_count_); 2509 EXPECT_EQ(1, listener.notification_count_);
2418 EXPECT_TRUE(listener.details_.from_front); 2510 EXPECT_TRUE(listener.details_.from_front);
2419 EXPECT_EQ(1, listener.details_.count); 2511 EXPECT_EQ(1, listener.details_.count);
2420 2512
2421 // We expect http://www.a.com/0 to be gone. 2513 // We expect http://www.a.com/0 to be gone.
2422 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); 2514 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount);
2423 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), 2515 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(),
2424 GURL("http:////www.a.com/1")); 2516 GURL("http://www.a.com/1"));
2425 2517
2426 // More navigations. 2518 // More navigations.
2427 for (int i = 0; i < 3; i++) { 2519 for (int i = 0; i < 3; i++) {
2428 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); 2520 url = GURL(base::StringPrintf("http://www.a.com/%d", url_index));
2429 controller.LoadURL( 2521 controller.LoadURL(
2430 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2522 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2523 entry = controller.GetPendingEntry();
2431 main_test_rfh()->PrepareForCommit(); 2524 main_test_rfh()->PrepareForCommit();
2432 main_test_rfh()->SendNavigate(url_index, url); 2525 main_test_rfh()->SendNavigate(url_index, entry->GetUniqueID(), true, url);
2433 url_index++; 2526 url_index++;
2434 } 2527 }
2435 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); 2528 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount);
2436 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), 2529 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(),
2437 GURL("http:////www.a.com/4")); 2530 GURL("http://www.a.com/4"));
2438 2531
2439 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); 2532 NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
2440 } 2533 }
2441 2534
2442 // Tests that we can do a restore and navigate to the restored entries and 2535 // Tests that we can do a restore and navigate to the restored entries and
2443 // everything is updated properly. This can be tricky since there is no 2536 // everything is updated properly. This can be tricky since there is no
2444 // SiteInstance for the entries created initially. 2537 // SiteInstance for the entries created initially.
2445 TEST_F(NavigationControllerTest, RestoreNavigate) { 2538 TEST_F(NavigationControllerTest, RestoreNavigate) {
2446 // Create a NavigationController with a restored set of tabs. 2539 // Create a NavigationController with a restored set of tabs.
2447 GURL url("http://foo"); 2540 GURL url("http://foo");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, 2574 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE,
2482 our_controller.GetEntryAtIndex(0)->restore_type()); 2575 our_controller.GetEntryAtIndex(0)->restore_type());
2483 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); 2576 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance());
2484 2577
2485 // Timestamp should remain the same before the navigation finishes. 2578 // Timestamp should remain the same before the navigation finishes.
2486 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); 2579 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp());
2487 2580
2488 // Say we navigated to that entry. 2581 // Say we navigated to that entry.
2489 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2582 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2490 params.page_id = 0; 2583 params.page_id = 0;
2584 params.nav_entry_id = our_controller.GetPendingEntry()->GetUniqueID();
2585 params.did_create_new_entry = false;
2491 params.url = url; 2586 params.url = url;
2492 params.transition = ui::PAGE_TRANSITION_LINK; 2587 params.transition = ui::PAGE_TRANSITION_LINK;
2493 params.should_update_history = false; 2588 params.should_update_history = false;
2494 params.gesture = NavigationGestureUser; 2589 params.gesture = NavigationGestureUser;
2495 params.is_post = false; 2590 params.is_post = false;
2496 params.page_state = PageState::CreateFromURL(url); 2591 params.page_state = PageState::CreateFromURL(url);
2497 LoadCommittedDetails details; 2592 LoadCommittedDetails details;
2498 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2593 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params,
2499 &details); 2594 &details);
2500 2595
(...skipping 28 matching lines...) Expand all
2529 entries.push_back(entry); 2624 entries.push_back(entry);
2530 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( 2625 scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>(
2531 WebContents::Create(WebContents::CreateParams(browser_context())))); 2626 WebContents::Create(WebContents::CreateParams(browser_context()))));
2532 NavigationControllerImpl& our_controller = our_contents->GetController(); 2627 NavigationControllerImpl& our_controller = our_contents->GetController();
2533 our_controller.Restore( 2628 our_controller.Restore(
2534 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); 2629 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries);
2535 ASSERT_EQ(0u, entries.size()); 2630 ASSERT_EQ(0u, entries.size());
2536 2631
2537 // Before navigating to the restored entry, it should have a restore_type 2632 // Before navigating to the restored entry, it should have a restore_type
2538 // and no SiteInstance. 2633 // and no SiteInstance.
2634 entry = our_controller.GetEntryAtIndex(0);
2539 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, 2635 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY,
2540 our_controller.GetEntryAtIndex(0)->restore_type()); 2636 our_controller.GetEntryAtIndex(0)->restore_type());
2541 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); 2637 EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance());
2542 2638
2543 // After navigating, we should have one entry, and it should be "pending". 2639 // After navigating, we should have one entry, and it should be "pending".
2544 // It should now have a SiteInstance and no restore_type. 2640 // It should now have a SiteInstance and no restore_type.
2545 our_controller.GoToIndex(0); 2641 our_controller.GoToIndex(0);
2546 EXPECT_EQ(1, our_controller.GetEntryCount()); 2642 EXPECT_EQ(1, our_controller.GetEntryCount());
2547 EXPECT_EQ(our_controller.GetEntryAtIndex(0), 2643 EXPECT_EQ(our_controller.GetEntryAtIndex(0),
2548 our_controller.GetPendingEntry()); 2644 our_controller.GetPendingEntry());
2549 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID()); 2645 EXPECT_EQ(0, our_controller.GetEntryAtIndex(0)->GetPageID());
2550 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, 2646 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE,
2551 our_controller.GetEntryAtIndex(0)->restore_type()); 2647 our_controller.GetEntryAtIndex(0)->restore_type());
2552 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance()); 2648 EXPECT_TRUE(our_controller.GetEntryAtIndex(0)->site_instance());
2553 2649
2554 // This pending navigation may have caused a different navigation to fail, 2650 // This pending navigation may have caused a different navigation to fail,
2555 // which causes the pending entry to be cleared. 2651 // which causes the pending entry to be cleared.
2556 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params; 2652 FrameHostMsg_DidFailProvisionalLoadWithError_Params fail_load_params;
2557 fail_load_params.error_code = net::ERR_ABORTED; 2653 fail_load_params.error_code = net::ERR_ABORTED;
2558 fail_load_params.error_description = base::string16(); 2654 fail_load_params.error_description = base::string16();
2559 fail_load_params.url = url; 2655 fail_load_params.url = url;
2560 fail_load_params.showing_repost_interstitial = false; 2656 fail_load_params.showing_repost_interstitial = false;
2561 main_test_rfh()->OnMessageReceived( 2657 main_test_rfh()->OnMessageReceived(
2562 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id 2658 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id
2563 fail_load_params)); 2659 fail_load_params));
2564 2660
2565 // Now the pending restored entry commits. 2661 // Now the pending restored entry commits.
2566 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2662 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2567 params.page_id = 0; 2663 params.page_id = 0;
2664 params.nav_entry_id = entry->GetUniqueID();
2665 params.did_create_new_entry = false;
2568 params.url = url; 2666 params.url = url;
2569 params.transition = ui::PAGE_TRANSITION_LINK; 2667 params.transition = ui::PAGE_TRANSITION_LINK;
2570 params.should_update_history = false; 2668 params.should_update_history = false;
2571 params.gesture = NavigationGestureUser; 2669 params.gesture = NavigationGestureUser;
2572 params.is_post = false; 2670 params.is_post = false;
2573 params.page_state = PageState::CreateFromURL(url); 2671 params.page_state = PageState::CreateFromURL(url);
2574 LoadCommittedDetails details; 2672 LoadCommittedDetails details;
2575 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params, 2673 our_controller.RendererDidNavigate(our_contents->GetMainFrame(), params,
2576 &details); 2674 &details);
2577 2675
2578 // There should be no pending entry and one committed one. 2676 // There should be no pending entry and one committed one.
2579 EXPECT_EQ(1, our_controller.GetEntryCount()); 2677 EXPECT_EQ(1, our_controller.GetEntryCount());
2580 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex()); 2678 EXPECT_EQ(0, our_controller.GetLastCommittedEntryIndex());
2581 EXPECT_FALSE(our_controller.GetPendingEntry()); 2679 EXPECT_FALSE(our_controller.GetPendingEntry());
2582 EXPECT_EQ( 2680 EXPECT_EQ(
2583 url, 2681 url,
2584 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL()); 2682 our_controller.GetLastCommittedEntry()->site_instance()->GetSiteURL());
2585 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, 2683 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE,
2586 our_controller.GetEntryAtIndex(0)->restore_type()); 2684 our_controller.GetEntryAtIndex(0)->restore_type());
2587 } 2685 }
2588 2686
2589 // Make sure that the page type and stuff is correct after an interstitial. 2687 // Make sure that the page type and stuff is correct after an interstitial.
2590 TEST_F(NavigationControllerTest, Interstitial) { 2688 TEST_F(NavigationControllerTest, Interstitial) {
2591 NavigationControllerImpl& controller = controller_impl(); 2689 NavigationControllerImpl& controller = controller_impl();
2592 // First navigate somewhere normal. 2690 // First navigate somewhere normal.
2593 const GURL url1("http://foo"); 2691 const GURL url1("http://foo");
2594 controller.LoadURL( 2692 controller.LoadURL(
2595 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2693 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2694 NavigationEntry* entry = controller.GetPendingEntry();
2596 main_test_rfh()->PrepareForCommit(); 2695 main_test_rfh()->PrepareForCommit();
2597 main_test_rfh()->SendNavigate(0, url1); 2696 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
2598 2697
2599 // Now navigate somewhere with an interstitial. 2698 // Now navigate somewhere with an interstitial.
2600 const GURL url2("http://bar"); 2699 const GURL url2("http://bar");
2601 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, 2700 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED,
2602 std::string()); 2701 std::string());
2702 entry = controller.GetPendingEntry();
2603 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); 2703 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL);
2604 2704
2605 // At this point the interstitial will be displayed and the load will still 2705 // At this point the interstitial will be displayed and the load will still
2606 // be pending. If the user continues, the load will commit. 2706 // be pending. If the user continues, the load will commit.
2607 main_test_rfh()->PrepareForCommit(); 2707 main_test_rfh()->PrepareForCommit();
2608 main_test_rfh()->SendNavigate(1, url2); 2708 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url2);
2609 2709
2610 // The page should be a normal page again. 2710 // The page should be a normal page again.
2611 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 2711 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
2612 EXPECT_EQ(PAGE_TYPE_NORMAL, 2712 EXPECT_EQ(PAGE_TYPE_NORMAL,
2613 controller.GetLastCommittedEntry()->GetPageType()); 2713 controller.GetLastCommittedEntry()->GetPageType());
2614 } 2714 }
2615 2715
2616 TEST_F(NavigationControllerTest, RemoveEntry) { 2716 TEST_F(NavigationControllerTest, RemoveEntry) {
2617 NavigationControllerImpl& controller = controller_impl(); 2717 NavigationControllerImpl& controller = controller_impl();
2618 const GURL url1("http://foo/1"); 2718 const GURL url1("http://foo/1");
2619 const GURL url2("http://foo/2"); 2719 const GURL url2("http://foo/2");
2620 const GURL url3("http://foo/3"); 2720 const GURL url3("http://foo/3");
2621 const GURL url4("http://foo/4"); 2721 const GURL url4("http://foo/4");
2622 const GURL url5("http://foo/5"); 2722 const GURL url5("http://foo/5");
2623 const GURL pending_url("http://foo/pending"); 2723 const GURL pending_url("http://foo/pending");
2624 const GURL default_url("http://foo/default"); 2724 const GURL default_url("http://foo/default");
2625 2725
2626 controller.LoadURL( 2726 controller.LoadURL(
2627 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2727 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2728 NavigationEntry* entry = controller.GetPendingEntry();
2628 main_test_rfh()->PrepareForCommit(); 2729 main_test_rfh()->PrepareForCommit();
2629 main_test_rfh()->SendNavigate(0, url1); 2730 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
2630 controller.LoadURL( 2731 controller.LoadURL(
2631 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2732 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2733 entry = controller.GetPendingEntry();
2632 main_test_rfh()->PrepareForCommit(); 2734 main_test_rfh()->PrepareForCommit();
2633 main_test_rfh()->SendNavigate(1, url2); 2735 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url2);
2634 controller.LoadURL( 2736 controller.LoadURL(
2635 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2737 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2738 entry = controller.GetPendingEntry();
2636 main_test_rfh()->PrepareForCommit(); 2739 main_test_rfh()->PrepareForCommit();
2637 main_test_rfh()->SendNavigate(2, url3); 2740 main_test_rfh()->SendNavigate(2, entry->GetUniqueID(), true, url3);
2638 controller.LoadURL( 2741 controller.LoadURL(
2639 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2742 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2743 entry = controller.GetPendingEntry();
2640 main_test_rfh()->PrepareForCommit(); 2744 main_test_rfh()->PrepareForCommit();
2641 main_test_rfh()->SendNavigate(3, url4); 2745 main_test_rfh()->SendNavigate(3, entry->GetUniqueID(), true, url4);
2642 controller.LoadURL( 2746 controller.LoadURL(
2643 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2747 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2748 entry = controller.GetPendingEntry();
2644 main_test_rfh()->PrepareForCommit(); 2749 main_test_rfh()->PrepareForCommit();
2645 main_test_rfh()->SendNavigate(4, url5); 2750 main_test_rfh()->SendNavigate(4, entry->GetUniqueID(), true, url5);
2646 2751
2647 // Try to remove the last entry. Will fail because it is the current entry. 2752 // Try to remove the last entry. Will fail because it is the current entry.
2648 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); 2753 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1));
2649 EXPECT_EQ(5, controller.GetEntryCount()); 2754 EXPECT_EQ(5, controller.GetEntryCount());
2650 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); 2755 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex());
2651 2756
2652 // Go back, but don't commit yet. Check that we can't delete the current 2757 // Go back, but don't commit yet. Check that we can't delete the current
2653 // and pending entries. 2758 // and pending entries.
2654 controller.GoBack(); 2759 controller.GoBack();
2760 entry = controller.GetPendingEntry();
2655 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); 2761 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1));
2656 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); 2762 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2));
2657 2763
2658 // Now commit and delete the last entry. 2764 // Now commit and delete the last entry.
2659 main_test_rfh()->PrepareForCommit(); 2765 main_test_rfh()->PrepareForCommit();
2660 main_test_rfh()->SendNavigate(3, url4); 2766 main_test_rfh()->SendNavigate(3, entry->GetUniqueID(), false, url4);
2661 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); 2767 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1));
2662 EXPECT_EQ(4, controller.GetEntryCount()); 2768 EXPECT_EQ(4, controller.GetEntryCount());
2663 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); 2769 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex());
2664 EXPECT_FALSE(controller.GetPendingEntry()); 2770 EXPECT_FALSE(controller.GetPendingEntry());
2665 2771
2666 // Remove an entry which is not the last committed one. 2772 // Remove an entry which is not the last committed one.
2667 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); 2773 EXPECT_TRUE(controller.RemoveEntryAtIndex(0));
2668 EXPECT_EQ(3, controller.GetEntryCount()); 2774 EXPECT_EQ(3, controller.GetEntryCount());
2669 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); 2775 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
2670 EXPECT_FALSE(controller.GetPendingEntry()); 2776 EXPECT_FALSE(controller.GetPendingEntry());
2671 2777
2672 // Remove the 2 remaining entries. 2778 // Remove the 2 remaining entries.
2673 controller.RemoveEntryAtIndex(1); 2779 controller.RemoveEntryAtIndex(1);
2674 controller.RemoveEntryAtIndex(0); 2780 controller.RemoveEntryAtIndex(0);
2675 2781
2676 // This should leave us with only the last committed entry. 2782 // This should leave us with only the last committed entry.
2677 EXPECT_EQ(1, controller.GetEntryCount()); 2783 EXPECT_EQ(1, controller.GetEntryCount());
2678 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 2784 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
2679 } 2785 }
2680 2786
2681 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { 2787 TEST_F(NavigationControllerTest, RemoveEntryWithPending) {
2682 NavigationControllerImpl& controller = controller_impl(); 2788 NavigationControllerImpl& controller = controller_impl();
2683 const GURL url1("http://foo/1"); 2789 const GURL url1("http://foo/1");
2684 const GURL url2("http://foo/2"); 2790 const GURL url2("http://foo/2");
2685 const GURL url3("http://foo/3"); 2791 const GURL url3("http://foo/3");
2686 const GURL default_url("http://foo/default"); 2792 const GURL default_url("http://foo/default");
2687 2793
2688 controller.LoadURL( 2794 controller.LoadURL(
2689 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2795 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2796 NavigationEntry* entry = controller.GetPendingEntry();
2690 main_test_rfh()->PrepareForCommit(); 2797 main_test_rfh()->PrepareForCommit();
2691 main_test_rfh()->SendNavigate(0, url1); 2798 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
2692 controller.LoadURL( 2799 controller.LoadURL(
2693 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2800 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2801 entry = controller.GetPendingEntry();
2694 main_test_rfh()->PrepareForCommit(); 2802 main_test_rfh()->PrepareForCommit();
2695 main_test_rfh()->SendNavigate(1, url2); 2803 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url2);
2696 controller.LoadURL( 2804 controller.LoadURL(
2697 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2805 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2806 entry = controller.GetPendingEntry();
2698 main_test_rfh()->PrepareForCommit(); 2807 main_test_rfh()->PrepareForCommit();
2699 main_test_rfh()->SendNavigate(2, url3); 2808 main_test_rfh()->SendNavigate(2, entry->GetUniqueID(), true, url3);
2700 2809
2701 // Go back, but don't commit yet. Check that we can't delete the current 2810 // Go back, but don't commit yet. Check that we can't delete the current
2702 // and pending entries. 2811 // and pending entries.
2703 controller.GoBack(); 2812 controller.GoBack();
2813 entry = controller.GetPendingEntry();
2704 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); 2814 EXPECT_FALSE(controller.RemoveEntryAtIndex(2));
2705 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); 2815 EXPECT_FALSE(controller.RemoveEntryAtIndex(1));
2706 2816
2707 // Remove the first entry, while there is a pending entry. This is expected 2817 // Remove the first entry, while there is a pending entry. This is expected
2708 // to discard the pending entry. 2818 // to discard the pending entry.
2709 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); 2819 EXPECT_TRUE(controller.RemoveEntryAtIndex(0));
2710 EXPECT_FALSE(controller.GetPendingEntry()); 2820 EXPECT_FALSE(controller.GetPendingEntry());
2711 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2821 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2712 2822
2713 // We should update the last committed entry index. 2823 // We should update the last committed entry index.
2714 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 2824 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
2715 2825
2716 // Now commit and ensure we land on the right entry. 2826 // Now commit and ensure we land on the right entry.
2717 main_test_rfh()->PrepareForCommit(); 2827 main_test_rfh()->PrepareForCommit();
2718 main_test_rfh()->SendNavigate(1, url2); 2828 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), false, url2);
2719 EXPECT_EQ(2, controller.GetEntryCount()); 2829 EXPECT_EQ(2, controller.GetEntryCount());
2720 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 2830 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
2721 EXPECT_FALSE(controller.GetPendingEntry()); 2831 EXPECT_FALSE(controller.GetPendingEntry());
2722 } 2832 }
2723 2833
2724 // Tests the transient entry, making sure it goes away with all navigations. 2834 // Tests the transient entry, making sure it goes away with all navigations.
2725 TEST_F(NavigationControllerTest, TransientEntry) { 2835 TEST_F(NavigationControllerTest, TransientEntry) {
2726 NavigationControllerImpl& controller = controller_impl(); 2836 NavigationControllerImpl& controller = controller_impl();
2727 TestNotificationTracker notifications; 2837 TestNotificationTracker notifications;
2728 RegisterForAllNavNotifications(&notifications, &controller); 2838 RegisterForAllNavNotifications(&notifications, &controller);
2729 2839
2730 const GURL url0("http://foo/0"); 2840 const GURL url0("http://foo/0");
2731 const GURL url1("http://foo/1"); 2841 const GURL url1("http://foo/1");
2732 const GURL url2("http://foo/2"); 2842 const GURL url2("http://foo/2");
2733 const GURL url3("http://foo/3"); 2843 const GURL url3("http://foo/3");
2734 const GURL url3_ref("http://foo/3#bar"); 2844 const GURL url3_ref("http://foo/3#bar");
2735 const GURL url4("http://foo/4"); 2845 const GURL url4("http://foo/4");
2736 const GURL transient_url("http://foo/transient"); 2846 const GURL transient_url("http://foo/transient");
2737 2847
2738 controller.LoadURL( 2848 controller.LoadURL(
2739 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2849 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2850 NavigationEntry* entry = controller.GetPendingEntry();
2740 main_test_rfh()->PrepareForCommit(); 2851 main_test_rfh()->PrepareForCommit();
2741 main_test_rfh()->SendNavigate(0, url0); 2852 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url0);
2742 controller.LoadURL( 2853 controller.LoadURL(
2743 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2854 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2855 entry = controller.GetPendingEntry();
2744 main_test_rfh()->PrepareForCommit(); 2856 main_test_rfh()->PrepareForCommit();
2745 main_test_rfh()->SendNavigate(1, url1); 2857 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url1);
2746 2858
2747 notifications.Reset(); 2859 notifications.Reset();
2748 2860
2749 // Adding a transient with no pending entry. 2861 // Adding a transient with no pending entry.
2750 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; 2862 NavigationEntryImpl* transient_entry = new NavigationEntryImpl;
2751 transient_entry->SetURL(transient_url); 2863 transient_entry->SetURL(transient_url);
2752 controller.SetTransientEntry(transient_entry); 2864 controller.SetTransientEntry(transient_entry);
2753 2865
2754 // We should not have received any notifications. 2866 // We should not have received any notifications.
2755 EXPECT_EQ(0U, notifications.size()); 2867 EXPECT_EQ(0U, notifications.size());
2756 2868
2757 // Check our state. 2869 // Check our state.
2758 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2870 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2759 EXPECT_EQ(controller.GetEntryCount(), 3); 2871 EXPECT_EQ(controller.GetEntryCount(), 3);
2760 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); 2872 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1);
2761 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); 2873 EXPECT_EQ(controller.GetPendingEntryIndex(), -1);
2762 EXPECT_TRUE(controller.GetLastCommittedEntry()); 2874 EXPECT_TRUE(controller.GetLastCommittedEntry());
2763 EXPECT_FALSE(controller.GetPendingEntry()); 2875 EXPECT_FALSE(controller.GetPendingEntry());
2764 EXPECT_TRUE(controller.CanGoBack()); 2876 EXPECT_TRUE(controller.CanGoBack());
2765 EXPECT_FALSE(controller.CanGoForward()); 2877 EXPECT_FALSE(controller.CanGoForward());
2766 EXPECT_EQ(contents()->GetMaxPageID(), 1); 2878 EXPECT_EQ(contents()->GetMaxPageID(), 1);
2767 2879
2768 // Navigate. 2880 // Navigate.
2769 controller.LoadURL( 2881 controller.LoadURL(
2770 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2882 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2883 entry = controller.GetPendingEntry();
2771 main_test_rfh()->PrepareForCommit(); 2884 main_test_rfh()->PrepareForCommit();
2772 main_test_rfh()->SendNavigate(2, url2); 2885 main_test_rfh()->SendNavigate(2, entry->GetUniqueID(), true, url2);
2773 2886
2774 // We should have navigated, transient entry should be gone. 2887 // We should have navigated, transient entry should be gone.
2775 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2888 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2776 EXPECT_EQ(controller.GetEntryCount(), 3); 2889 EXPECT_EQ(controller.GetEntryCount(), 3);
2777 2890
2778 // Add a transient again, then navigate with no pending entry this time. 2891 // Add a transient again, then navigate with no pending entry this time.
2779 transient_entry = new NavigationEntryImpl; 2892 transient_entry = new NavigationEntryImpl;
2780 transient_entry->SetURL(transient_url); 2893 transient_entry->SetURL(transient_url);
2781 controller.SetTransientEntry(transient_entry); 2894 controller.SetTransientEntry(transient_entry);
2782 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2895 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2783 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); 2896 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true);
2784 main_test_rfh()->PrepareForCommit(); 2897 main_test_rfh()->PrepareForCommit();
2785 main_test_rfh()->SendNavigate(3, url3); 2898 main_test_rfh()->SendNavigate(3, 0, true, url3);
2786 // Transient entry should be gone. 2899 // Transient entry should be gone.
2787 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2900 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2788 EXPECT_EQ(controller.GetEntryCount(), 4); 2901 EXPECT_EQ(controller.GetEntryCount(), 4);
2789 2902
2790 // Initiate a navigation, add a transient then commit navigation. 2903 // Initiate a navigation, add a transient then commit navigation.
2791 controller.LoadURL( 2904 controller.LoadURL(
2792 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2905 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2906 entry = controller.GetPendingEntry();
2793 transient_entry = new NavigationEntryImpl; 2907 transient_entry = new NavigationEntryImpl;
2794 transient_entry->SetURL(transient_url); 2908 transient_entry->SetURL(transient_url);
2795 controller.SetTransientEntry(transient_entry); 2909 controller.SetTransientEntry(transient_entry);
2796 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2910 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2797 main_test_rfh()->PrepareForCommit(); 2911 main_test_rfh()->PrepareForCommit();
2798 main_test_rfh()->SendNavigate(4, url4); 2912 main_test_rfh()->SendNavigate(4, entry->GetUniqueID(), true, url4);
2799 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 2913 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
2800 EXPECT_EQ(controller.GetEntryCount(), 5); 2914 EXPECT_EQ(controller.GetEntryCount(), 5);
2801 2915
2802 // Add a transient and go back. This should simply remove the transient. 2916 // Add a transient and go back. This should simply remove the transient.
2803 transient_entry = new NavigationEntryImpl; 2917 transient_entry = new NavigationEntryImpl;
2804 transient_entry->SetURL(transient_url); 2918 transient_entry->SetURL(transient_url);
2805 controller.SetTransientEntry(transient_entry); 2919 controller.SetTransientEntry(transient_entry);
2806 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2920 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2807 EXPECT_TRUE(controller.CanGoBack()); 2921 EXPECT_TRUE(controller.CanGoBack());
2808 EXPECT_FALSE(controller.CanGoForward()); 2922 EXPECT_FALSE(controller.CanGoForward());
2809 controller.GoBack(); 2923 controller.GoBack();
2924 entry = controller.GetPendingEntry();
2810 // Transient entry should be gone. 2925 // Transient entry should be gone.
2811 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 2926 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
2812 EXPECT_EQ(controller.GetEntryCount(), 5); 2927 EXPECT_EQ(controller.GetEntryCount(), 5);
2813 2928
2814 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); 2929 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false);
2815 main_test_rfh()->PrepareForCommit(); 2930 main_test_rfh()->PrepareForCommit();
2816 main_test_rfh()->SendNavigate(3, url3); 2931 main_test_rfh()->SendNavigate(3, entry->GetUniqueID(), false, url3);
2817 2932
2818 // Add a transient and go to an entry before the current one. 2933 // Add a transient and go to an entry before the current one.
2819 transient_entry = new NavigationEntryImpl; 2934 transient_entry = new NavigationEntryImpl;
2820 transient_entry->SetURL(transient_url); 2935 transient_entry->SetURL(transient_url);
2821 controller.SetTransientEntry(transient_entry); 2936 controller.SetTransientEntry(transient_entry);
2822 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2937 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2823 controller.GoToIndex(1); 2938 controller.GoToIndex(1);
2939 entry = controller.GetPendingEntry();
2824 // The navigation should have been initiated, transient entry should be gone. 2940 // The navigation should have been initiated, transient entry should be gone.
2825 EXPECT_FALSE(controller.GetTransientEntry()); 2941 EXPECT_FALSE(controller.GetTransientEntry());
2826 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 2942 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2827 // Visible entry does not update for history navigations until commit. 2943 // Visible entry does not update for history navigations until commit.
2828 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2944 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2829 main_test_rfh()->PrepareForCommit(); 2945 main_test_rfh()->PrepareForCommit();
2830 main_test_rfh()->SendNavigate(1, url1); 2946 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), false, url1);
2831 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2947 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2832 2948
2833 // Add a transient and go to an entry after the current one. 2949 // Add a transient and go to an entry after the current one.
2834 transient_entry = new NavigationEntryImpl; 2950 transient_entry = new NavigationEntryImpl;
2835 transient_entry->SetURL(transient_url); 2951 transient_entry->SetURL(transient_url);
2836 controller.SetTransientEntry(transient_entry); 2952 controller.SetTransientEntry(transient_entry);
2837 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2953 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2838 controller.GoToIndex(3); 2954 controller.GoToIndex(3);
2955 entry = controller.GetPendingEntry();
2839 // The navigation should have been initiated, transient entry should be gone. 2956 // The navigation should have been initiated, transient entry should be gone.
2840 // Because of the transient entry that is removed, going to index 3 makes us 2957 // Because of the transient entry that is removed, going to index 3 makes us
2841 // land on url2 (which is visible after the commit). 2958 // land on url2 (which is visible after the commit).
2842 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); 2959 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
2843 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 2960 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
2844 main_test_rfh()->PrepareForCommit(); 2961 main_test_rfh()->PrepareForCommit();
2845 main_test_rfh()->SendNavigate(2, url2); 2962 main_test_rfh()->SendNavigate(2, entry->GetUniqueID(), false, url2);
2846 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2963 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2847 2964
2848 // Add a transient and go forward. 2965 // Add a transient and go forward.
2849 transient_entry = new NavigationEntryImpl; 2966 transient_entry = new NavigationEntryImpl;
2850 transient_entry->SetURL(transient_url); 2967 transient_entry->SetURL(transient_url);
2851 controller.SetTransientEntry(transient_entry); 2968 controller.SetTransientEntry(transient_entry);
2852 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2969 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2853 EXPECT_TRUE(controller.CanGoForward()); 2970 EXPECT_TRUE(controller.CanGoForward());
2854 controller.GoForward(); 2971 controller.GoForward();
2972 entry = controller.GetPendingEntry();
2855 // We should have navigated, transient entry should be gone. 2973 // We should have navigated, transient entry should be gone.
2856 EXPECT_FALSE(controller.GetTransientEntry()); 2974 EXPECT_FALSE(controller.GetTransientEntry());
2857 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); 2975 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL());
2858 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 2976 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
2859 main_test_rfh()->PrepareForCommit(); 2977 main_test_rfh()->PrepareForCommit();
2860 main_test_rfh()->SendNavigate(3, url3); 2978 main_test_rfh()->SendNavigate(3, entry->GetUniqueID(), false, url3);
2861 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); 2979 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL());
2862 2980
2863 // Add a transient and do an in-page navigation, replacing the current entry. 2981 // Add a transient and do an in-page navigation, replacing the current entry.
2864 transient_entry = new NavigationEntryImpl; 2982 transient_entry = new NavigationEntryImpl;
2865 transient_entry->SetURL(transient_url); 2983 transient_entry->SetURL(transient_url);
2866 controller.SetTransientEntry(transient_entry); 2984 controller.SetTransientEntry(transient_entry);
2867 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 2985 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2868 2986
2869 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); 2987 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false);
2870 main_test_rfh()->PrepareForCommit(); 2988 main_test_rfh()->PrepareForCommit();
2871 main_test_rfh()->SendNavigate(3, url3_ref); 2989 main_test_rfh()->SendNavigate(3, 0, false, url3_ref);
2872 // Transient entry should be gone. 2990 // Transient entry should be gone.
2873 EXPECT_FALSE(controller.GetTransientEntry()); 2991 EXPECT_FALSE(controller.GetTransientEntry());
2874 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); 2992 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL());
2875 2993
2876 // Ensure the URLs are correct. 2994 // Ensure the URLs are correct.
2877 EXPECT_EQ(controller.GetEntryCount(), 5); 2995 EXPECT_EQ(controller.GetEntryCount(), 5);
2878 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2996 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2879 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); 2997 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1);
2880 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); 2998 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2);
2881 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); 2999 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref);
2882 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); 3000 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4);
2883 } 3001 }
2884 3002
2885 // Test that Reload initiates a new navigation to a transient entry's URL. 3003 // Test that Reload initiates a new navigation to a transient entry's URL.
2886 TEST_F(NavigationControllerTest, ReloadTransient) { 3004 TEST_F(NavigationControllerTest, ReloadTransient) {
2887 NavigationControllerImpl& controller = controller_impl(); 3005 NavigationControllerImpl& controller = controller_impl();
2888 const GURL url0("http://foo/0"); 3006 const GURL url0("http://foo/0");
2889 const GURL url1("http://foo/1"); 3007 const GURL url1("http://foo/1");
2890 const GURL transient_url("http://foo/transient"); 3008 const GURL transient_url("http://foo/transient");
2891 3009
2892 // Load |url0|, and start a pending navigation to |url1|. 3010 // Load |url0|, and start a pending navigation to |url1|.
2893 controller.LoadURL( 3011 controller.LoadURL(
2894 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3012 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3013 NavigationEntry* entry = controller.GetPendingEntry();
2895 main_test_rfh()->PrepareForCommit(); 3014 main_test_rfh()->PrepareForCommit();
2896 main_test_rfh()->SendNavigate(0, url0); 3015 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url0);
2897 controller.LoadURL( 3016 controller.LoadURL(
2898 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3017 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2899 3018
2900 // A transient entry is added, interrupting the navigation. 3019 // A transient entry is added, interrupting the navigation.
2901 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; 3020 NavigationEntryImpl* transient_entry = new NavigationEntryImpl;
2902 transient_entry->SetURL(transient_url); 3021 transient_entry->SetURL(transient_url);
2903 controller.SetTransientEntry(transient_entry); 3022 controller.SetTransientEntry(transient_entry);
2904 EXPECT_TRUE(controller.GetTransientEntry()); 3023 EXPECT_TRUE(controller.GetTransientEntry());
2905 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 3024 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2906 3025
2907 // The page is reloaded, which should remove the pending entry for |url1| and 3026 // The page is reloaded, which should remove the pending entry for |url1| and
2908 // the transient entry for |transient_url|, and start a navigation to 3027 // the transient entry for |transient_url|, and start a navigation to
2909 // |transient_url|. 3028 // |transient_url|.
2910 controller.Reload(true); 3029 controller.Reload(true);
3030 entry = controller.GetPendingEntry();
2911 EXPECT_FALSE(controller.GetTransientEntry()); 3031 EXPECT_FALSE(controller.GetTransientEntry());
2912 EXPECT_TRUE(controller.GetPendingEntry()); 3032 EXPECT_TRUE(controller.GetPendingEntry());
2913 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); 3033 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL());
2914 ASSERT_EQ(controller.GetEntryCount(), 1); 3034 ASSERT_EQ(controller.GetEntryCount(), 1);
2915 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 3035 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2916 3036
2917 // Load of |transient_url| completes. 3037 // Load of |transient_url| completes.
2918 main_test_rfh()->PrepareForCommit(); 3038 main_test_rfh()->PrepareForCommit();
2919 main_test_rfh()->SendNavigate(1, transient_url); 3039 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), false, transient_url);
2920 ASSERT_EQ(controller.GetEntryCount(), 2); 3040 ASSERT_EQ(controller.GetEntryCount(), 2);
2921 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 3041 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2922 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); 3042 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url);
2923 } 3043 }
2924 3044
2925 // Ensure that renderer initiated pending entries get replaced, so that we 3045 // Ensure that renderer initiated pending entries get replaced, so that we
2926 // don't show a stale virtual URL when a navigation commits. 3046 // don't show a stale virtual URL when a navigation commits.
2927 // See http://crbug.com/266922. 3047 // See http://crbug.com/266922.
2928 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { 3048 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) {
2929 NavigationControllerImpl& controller = controller_impl(); 3049 NavigationControllerImpl& controller = controller_impl();
(...skipping 16 matching lines...) Expand all
2946 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); 3066 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL());
2947 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); 3067 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL());
2948 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); 3068 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated());
2949 3069
2950 // If the user clicks another link, we should replace the pending entry. 3070 // If the user clicks another link, we should replace the pending entry.
2951 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); 3071 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false);
2952 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); 3072 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
2953 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); 3073 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL());
2954 3074
2955 // Once it commits, the URL and virtual URL should reflect the actual page. 3075 // Once it commits, the URL and virtual URL should reflect the actual page.
2956 main_test_rfh()->SendNavigate(0, url2); 3076 main_test_rfh()->SendNavigate(0, 0, true, url2);
2957 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 3077 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
2958 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); 3078 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL());
2959 3079
2960 // We should not replace the pending entry for an error URL. 3080 // We should not replace the pending entry for an error URL.
2961 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); 3081 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false);
2962 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3082 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2963 navigator->DidStartProvisionalLoad(main_test_rfh(), 3083 navigator->DidStartProvisionalLoad(main_test_rfh(),
2964 GURL(kUnreachableWebDataURL), false); 3084 GURL(kUnreachableWebDataURL), false);
2965 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3085 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2966 3086
2967 // We should remember if the pending entry will replace the current one. 3087 // We should remember if the pending entry will replace the current one.
2968 // http://crbug.com/308444. 3088 // http://crbug.com/308444.
2969 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false); 3089 navigator->DidStartProvisionalLoad(main_test_rfh(), url1, false);
2970 controller.GetPendingEntry()->set_should_replace_entry(true); 3090 controller.GetPendingEntry()->set_should_replace_entry(true);
2971 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false); 3091 navigator->DidStartProvisionalLoad(main_test_rfh(), url2, false);
2972 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry()); 3092 EXPECT_TRUE(controller.GetPendingEntry()->should_replace_entry());
2973 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need 3093 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need
2974 // to go through the RenderViewHost. The TestRenderViewHost routes navigations 3094 // to go through the RenderViewHost. The TestRenderViewHost routes navigations
2975 // to the main frame. 3095 // to the main frame.
2976 main_test_rfh()->SendNavigate(0, url2); 3096 main_test_rfh()->SendNavigate(0, 0, false, url2);
2977 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 3097 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
2978 } 3098 }
2979 3099
2980 // Tests that the URLs for renderer-initiated navigations are not displayed to 3100 // Tests that the URLs for renderer-initiated navigations are not displayed to
2981 // the user until the navigation commits, to prevent URL spoof attacks. 3101 // the user until the navigation commits, to prevent URL spoof attacks.
2982 // See http://crbug.com/99016. 3102 // See http://crbug.com/99016.
2983 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { 3103 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
2984 NavigationControllerImpl& controller = controller_impl(); 3104 NavigationControllerImpl& controller = controller_impl();
2985 TestNotificationTracker notifications; 3105 TestNotificationTracker notifications;
2986 RegisterForAllNavNotifications(&notifications, &controller); 3106 RegisterForAllNavNotifications(&notifications, &controller);
2987 3107
2988 const GURL url0("http://foo/0"); 3108 const GURL url0("http://foo/0");
2989 const GURL url1("http://foo/1"); 3109 const GURL url1("http://foo/1");
2990 3110
2991 // For typed navigations (browser-initiated), both pending and visible entries 3111 // For typed navigations (browser-initiated), both pending and visible entries
2992 // should update before commit. 3112 // should update before commit.
2993 controller.LoadURL( 3113 controller.LoadURL(
2994 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3114 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3115 NavigationEntry* entry = controller.GetPendingEntry();
2995 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); 3116 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL());
2996 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); 3117 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL());
2997 main_test_rfh()->PrepareForCommit(); 3118 main_test_rfh()->PrepareForCommit();
2998 main_test_rfh()->SendNavigate(0, url0); 3119 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url0);
2999 3120
3000 // For link clicks (renderer-initiated navigations), the pending entry should 3121 // For link clicks (renderer-initiated navigations), the pending entry should
3001 // update before commit but the visible should not. 3122 // update before commit but the visible should not.
3002 NavigationController::LoadURLParams load_url_params(url1); 3123 NavigationController::LoadURLParams load_url_params(url1);
3003 load_url_params.is_renderer_initiated = true; 3124 load_url_params.is_renderer_initiated = true;
3004 controller.LoadURLWithParams(load_url_params); 3125 controller.LoadURLWithParams(load_url_params);
3126 entry = controller.GetPendingEntry();
3005 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); 3127 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL());
3006 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 3128 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
3007 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); 3129 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated());
3008 3130
3009 // After commit, both visible should be updated, there should be no pending 3131 // After commit, both visible should be updated, there should be no pending
3010 // entry, and we should no longer treat the entry as renderer-initiated. 3132 // entry, and we should no longer treat the entry as renderer-initiated.
3011 main_test_rfh()->PrepareForCommit(); 3133 main_test_rfh()->PrepareForCommit();
3012 main_test_rfh()->SendNavigate(1, url1); 3134 main_test_rfh()->SendNavigate(1, entry->GetUniqueID(), true, url1);
3013 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 3135 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
3014 EXPECT_FALSE(controller.GetPendingEntry()); 3136 EXPECT_FALSE(controller.GetPendingEntry());
3015 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); 3137 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated());
3016 3138
3017 notifications.Reset(); 3139 notifications.Reset();
3018 } 3140 }
3019 3141
3020 // Tests that the URLs for renderer-initiated navigations in new tabs are 3142 // Tests that the URLs for renderer-initiated navigations in new tabs are
3021 // displayed to the user before commit, as long as the initial about:blank 3143 // displayed to the user before commit, as long as the initial about:blank
3022 // page has not been modified. If so, we must revert to showing about:blank. 3144 // page has not been modified. If so, we must revert to showing about:blank.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
3160 const GURL url1("http://foo/eh"); 3282 const GURL url1("http://foo/eh");
3161 const GURL url2("http://foo/bee"); 3283 const GURL url2("http://foo/bee");
3162 3284
3163 // For renderer-initiated navigations in new tabs (with no committed entries), 3285 // For renderer-initiated navigations in new tabs (with no committed entries),
3164 // we show the pending entry's URL as long as the about:blank page is not 3286 // we show the pending entry's URL as long as the about:blank page is not
3165 // modified. 3287 // modified.
3166 NavigationController::LoadURLParams load_url_params(url1); 3288 NavigationController::LoadURLParams load_url_params(url1);
3167 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK; 3289 load_url_params.transition_type = ui::PAGE_TRANSITION_LINK;
3168 load_url_params.is_renderer_initiated = true; 3290 load_url_params.is_renderer_initiated = true;
3169 controller.LoadURLWithParams(load_url_params); 3291 controller.LoadURLWithParams(load_url_params);
3292 NavigationEntry* entry = controller.GetPendingEntry();
3170 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 3293 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
3171 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); 3294 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated());
3172 EXPECT_TRUE(controller.IsInitialNavigation()); 3295 EXPECT_TRUE(controller.IsInitialNavigation());
3173 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); 3296 EXPECT_FALSE(contents()->HasAccessedInitialDocument());
3174 3297
3175 // Simulate a commit and then starting a new pending navigation. 3298 // Simulate a commit and then starting a new pending navigation.
3176 main_test_rfh()->SendNavigate(0, url1); 3299 main_test_rfh()->SendNavigate(0, entry->GetUniqueID(), true, url1);
3177 NavigationController::LoadURLParams load_url2_params(url2); 3300 NavigationController::LoadURLParams load_url2_params(url2);
3178 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK; 3301 load_url2_params.transition_type = ui::PAGE_TRANSITION_LINK;
3179 load_url2_params.is_renderer_initiated = true; 3302 load_url2_params.is_renderer_initiated = true;
3180 controller.LoadURLWithParams(load_url2_params); 3303 controller.LoadURLWithParams(load_url2_params);
3181 3304
3182 // We should not consider this an initial navigation, and thus should 3305 // We should not consider this an initial navigation, and thus should
3183 // not show the pending URL. 3306 // not show the pending URL.
3184 EXPECT_FALSE(contents()->HasAccessedInitialDocument()); 3307 EXPECT_FALSE(contents()->HasAccessedInitialDocument());
3185 EXPECT_FALSE(controller.IsInitialNavigation()); 3308 EXPECT_FALSE(controller.IsInitialNavigation());
3186 EXPECT_TRUE(controller.GetVisibleEntry()); 3309 EXPECT_TRUE(controller.GetVisibleEntry());
3187 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); 3310 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL());
3188 3311
3189 notifications.Reset(); 3312 notifications.Reset();
3190 } 3313 }
3191 3314
3192 // Tests that IsInPageNavigation returns appropriate results. Prevents 3315 // Tests that IsInPageNavigation returns appropriate results. Prevents
3193 // regression for bug 1126349. 3316 // regression for bug 1126349.
3194 TEST_F(NavigationControllerTest, IsInPageNavigation) { 3317 TEST_F(NavigationControllerTest, IsInPageNavigation) {
3195 NavigationControllerImpl& controller = controller_impl(); 3318 NavigationControllerImpl& controller = controller_impl();
3196 const GURL url("http://www.google.com/home.html"); 3319 const GURL url("http://www.google.com/home.html");
3197 3320
3198 // If the renderer claims it performed an in-page navigation from 3321 // If the renderer claims it performed an in-page navigation from
3199 // about:blank, trust the renderer. 3322 // about:blank, trust the renderer.
3200 // This can happen when an iframe is created and populated via 3323 // This can happen when an iframe is created and populated via
3201 // document.write(), then tries to perform a fragment navigation. 3324 // document.write(), then tries to perform a fragment navigation.
3202 // TODO(japhet): We should only trust the renderer if the about:blank 3325 // TODO(japhet): We should only trust the renderer if the about:blank
3203 // was the first document in the given frame, but we don't have enough 3326 // was the first document in the given frame, but we don't have enough
3204 // information to identify that case currently. 3327 // information to identify that case currently.
3205 const GURL blank_url(url::kAboutBlankURL); 3328 const GURL blank_url(url::kAboutBlankURL);
3206 main_test_rfh()->SendNavigate(0, blank_url); 3329 main_test_rfh()->SendNavigate(0, 0, false, blank_url);
3207 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, 3330 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, main_test_rfh()));
3208 main_test_rfh()));
3209 3331
3210 // Navigate to URL with no refs. 3332 // Navigate to URL with no refs.
3211 main_test_rfh()->SendNavigate(0, url); 3333 main_test_rfh()->SendNavigate(0, 0, false, url);
3212 3334
3213 // Reloading the page is not an in-page navigation. 3335 // Reloading the page is not an in-page navigation.
3214 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, 3336 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, main_test_rfh()));
3215 main_test_rfh()));
3216 const GURL other_url("http://www.google.com/add.html"); 3337 const GURL other_url("http://www.google.com/add.html");
3217 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, 3338 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false,
3218 main_test_rfh())); 3339 main_test_rfh()));
3219 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); 3340 const GURL url_with_ref("http://www.google.com/home.html#my_ref");
3220 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, 3341 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true,
3221 main_test_rfh())); 3342 main_test_rfh()));
3222 3343
3223 // Navigate to URL with refs. 3344 // Navigate to URL with refs.
3224 main_test_rfh()->SendNavigate(1, url_with_ref); 3345 main_test_rfh()->SendNavigate(1, 0, true, url_with_ref);
3225 3346
3226 // Reloading the page is not an in-page navigation. 3347 // Reloading the page is not an in-page navigation.
3227 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false, 3348 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref, false,
3228 main_test_rfh())); 3349 main_test_rfh()));
3229 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false, 3350 EXPECT_FALSE(controller.IsURLInPageNavigation(url, false,
3230 main_test_rfh())); 3351 main_test_rfh()));
3231 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false, 3352 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url, false,
3232 main_test_rfh())); 3353 main_test_rfh()));
3233 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); 3354 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref");
3234 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true, 3355 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref, true,
(...skipping 18 matching lines...) Expand all
3253 const GURL different_origin_url("http://www.example.com"); 3374 const GURL different_origin_url("http://www.example.com");
3254 MockRenderProcessHost* rph = 3375 MockRenderProcessHost* rph =
3255 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); 3376 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess());
3256 WebPreferences prefs = test_rvh()->GetWebkitPreferences(); 3377 WebPreferences prefs = test_rvh()->GetWebkitPreferences();
3257 prefs.allow_universal_access_from_file_urls = true; 3378 prefs.allow_universal_access_from_file_urls = true;
3258 test_rvh()->UpdateWebkitPreferences(prefs); 3379 test_rvh()->UpdateWebkitPreferences(prefs);
3259 prefs = test_rvh()->GetWebkitPreferences(); 3380 prefs = test_rvh()->GetWebkitPreferences();
3260 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls); 3381 EXPECT_TRUE(prefs.allow_universal_access_from_file_urls);
3261 // Allow in page navigation if existing URL is file scheme. 3382 // Allow in page navigation if existing URL is file scheme.
3262 const GURL file_url("file:///foo/index.html"); 3383 const GURL file_url("file:///foo/index.html");
3263 main_test_rfh()->SendNavigate(0, file_url); 3384 main_test_rfh()->SendNavigate(0, 0, true, file_url);
3264 EXPECT_EQ(0, rph->bad_msg_count()); 3385 EXPECT_EQ(0, rph->bad_msg_count());
3265 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true, 3386 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true,
3266 main_test_rfh())); 3387 main_test_rfh()));
3267 EXPECT_EQ(0, rph->bad_msg_count()); 3388 EXPECT_EQ(0, rph->bad_msg_count());
3268 // Don't honor allow_universal_access_from_file_urls if existing URL is 3389 // Don't honor allow_universal_access_from_file_urls if existing URL is
3269 // not file scheme. 3390 // not file scheme.
3270 main_test_rfh()->SendNavigate(0, url); 3391 main_test_rfh()->SendNavigate(0, 0, true, url);
3271 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3392 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3272 main_test_rfh())); 3393 main_test_rfh()));
3273 EXPECT_EQ(1, rph->bad_msg_count()); 3394 EXPECT_EQ(1, rph->bad_msg_count());
3274 3395
3275 // Remove allow_universal_access_from_file_urls flag. 3396 // Remove allow_universal_access_from_file_urls flag.
3276 prefs.allow_universal_access_from_file_urls = false; 3397 prefs.allow_universal_access_from_file_urls = false;
3277 test_rvh()->UpdateWebkitPreferences(prefs); 3398 test_rvh()->UpdateWebkitPreferences(prefs);
3278 prefs = test_rvh()->GetWebkitPreferences(); 3399 prefs = test_rvh()->GetWebkitPreferences();
3279 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls); 3400 EXPECT_FALSE(prefs.allow_universal_access_from_file_urls);
3280 3401
3281 // Don't believe the renderer if it claims a cross-origin navigation is 3402 // Don't believe the renderer if it claims a cross-origin navigation is
3282 // in-page. 3403 // in-page.
3283 EXPECT_EQ(1, rph->bad_msg_count()); 3404 EXPECT_EQ(1, rph->bad_msg_count());
3284 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3405 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3285 main_test_rfh())); 3406 main_test_rfh()));
3286 EXPECT_EQ(2, rph->bad_msg_count()); 3407 EXPECT_EQ(2, rph->bad_msg_count());
3287 } 3408 }
3288 3409
3289 // Some pages can have subframes with the same base URL (minus the reference) as 3410 // Some pages can have subframes with the same base URL (minus the reference) as
3290 // the main page. Even though this is hard, it can happen, and we don't want 3411 // the main page. Even though this is hard, it can happen, and we don't want
3291 // these subframe navigations to affect the toplevel document. They should 3412 // these subframe navigations to affect the toplevel document. They should
3292 // instead be ignored. http://crbug.com/5585 3413 // instead be ignored. http://crbug.com/5585
3293 TEST_F(NavigationControllerTest, SameSubframe) { 3414 TEST_F(NavigationControllerTest, SameSubframe) {
3294 NavigationControllerImpl& controller = controller_impl(); 3415 NavigationControllerImpl& controller = controller_impl();
3295 // Navigate the main frame. 3416 // Navigate the main frame.
3296 const GURL url("http://www.google.com/"); 3417 const GURL url("http://www.google.com/");
3297 main_test_rfh()->SendNavigate(0, url); 3418 main_test_rfh()->SendNavigate(0, 0, true, url);
3298 3419
3299 // We should be at the first navigation entry. 3420 // We should be at the first navigation entry.
3300 EXPECT_EQ(controller.GetEntryCount(), 1); 3421 EXPECT_EQ(controller.GetEntryCount(), 1);
3301 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3422 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3302 3423
3303 // Navigate a subframe that would normally count as in-page. 3424 // Navigate a subframe that would normally count as in-page.
3304 const GURL subframe("http://www.google.com/#"); 3425 const GURL subframe("http://www.google.com/#");
3305 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3426 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3306 params.page_id = 0; 3427 params.page_id = 0;
3428 params.nav_entry_id = 0;
3429 params.did_create_new_entry = false;
3307 params.url = subframe; 3430 params.url = subframe;
3308 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3431 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3309 params.should_update_history = false; 3432 params.should_update_history = false;
3310 params.gesture = NavigationGestureAuto; 3433 params.gesture = NavigationGestureAuto;
3311 params.is_post = false; 3434 params.is_post = false;
3312 params.page_state = PageState::CreateFromURL(subframe); 3435 params.page_state = PageState::CreateFromURL(subframe);
3313 LoadCommittedDetails details; 3436 LoadCommittedDetails details;
3314 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3437 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params,
3315 &details)); 3438 &details));
3316 3439
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3442 // Now start a pending load to a totally different page, but don't commit it. 3565 // Now start a pending load to a totally different page, but don't commit it.
3443 const GURL url2("http://bar/"); 3566 const GURL url2("http://bar/");
3444 controller.LoadURL( 3567 controller.LoadURL(
3445 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3568 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3446 3569
3447 // Send a subframe update from the first page, as if one had just 3570 // Send a subframe update from the first page, as if one had just
3448 // automatically loaded. Auto subframes don't increment the page ID. 3571 // automatically loaded. Auto subframes don't increment the page ID.
3449 const GURL url1_sub("http://foo/subframe"); 3572 const GURL url1_sub("http://foo/subframe");
3450 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3573 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3451 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); 3574 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3575 params.nav_entry_id = 0;
3576 params.did_create_new_entry = false;
3452 params.url = url1_sub; 3577 params.url = url1_sub;
3453 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3578 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3454 params.should_update_history = false; 3579 params.should_update_history = false;
3455 params.gesture = NavigationGestureAuto; 3580 params.gesture = NavigationGestureAuto;
3456 params.is_post = false; 3581 params.is_post = false;
3457 params.page_state = PageState::CreateFromURL(url1_sub); 3582 params.page_state = PageState::CreateFromURL(url1_sub);
3458 LoadCommittedDetails details; 3583 LoadCommittedDetails details;
3459 3584
3460 // This should return false meaning that nothing was actually updated. 3585 // This should return false meaning that nothing was actually updated.
3461 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3586 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params,
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
4120 const GURL url1("http://foo/1"); 4245 const GURL url1("http://foo/1");
4121 const GURL url2("http://foo/2"); 4246 const GURL url2("http://foo/2");
4122 const GURL url3("http://foo/3"); 4247 const GURL url3("http://foo/3");
4123 4248
4124 NavigateAndCommit(url1); 4249 NavigateAndCommit(url1);
4125 NavigateAndCommit(url2); 4250 NavigateAndCommit(url2);
4126 4251
4127 // Create a pending entry that is not in the entry list. 4252 // Create a pending entry that is not in the entry list.
4128 controller.LoadURL( 4253 controller.LoadURL(
4129 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 4254 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
4255 NavigationEntry* entry = controller.GetPendingEntry();
4130 EXPECT_TRUE(controller.GetPendingEntry()); 4256 EXPECT_TRUE(controller.GetPendingEntry());
4131 EXPECT_EQ(2, controller.GetEntryCount()); 4257 EXPECT_EQ(2, controller.GetEntryCount());
4132 4258
4133 contents()->ExpectSetHistoryOffsetAndLength(0, 1); 4259 contents()->ExpectSetHistoryOffsetAndLength(0, 1);
4134 controller.PruneAllButLastCommitted(); 4260 controller.PruneAllButLastCommitted();
4135 4261
4136 // We should only have the last committed and pending entries at this point, 4262 // We should only have the last committed and pending entries at this point,
4137 // and the pending entry should still not be in the entry list. 4263 // and the pending entry should still not be in the entry list.
4138 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4264 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4139 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); 4265 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL());
4140 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4266 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4141 EXPECT_TRUE(controller.GetPendingEntry()); 4267 EXPECT_TRUE(controller.GetPendingEntry());
4142 EXPECT_EQ(1, controller.GetEntryCount()); 4268 EXPECT_EQ(1, controller.GetEntryCount());
4143 4269
4144 // Try to commit the pending entry. 4270 // Try to commit the pending entry.
4145 main_test_rfh()->PrepareForCommit(); 4271 main_test_rfh()->PrepareForCommit();
4146 main_test_rfh()->SendNavigate(2, url3); 4272 main_test_rfh()->SendNavigate(2, entry->GetUniqueID(), true, url3);
4147 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4273 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4148 EXPECT_FALSE(controller.GetPendingEntry()); 4274 EXPECT_FALSE(controller.GetPendingEntry());
4149 EXPECT_EQ(2, controller.GetEntryCount()); 4275 EXPECT_EQ(2, controller.GetEntryCount());
4150 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); 4276 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL());
4151 } 4277 }
4152 4278
4153 // Test to ensure that when we do a history navigation back to the current 4279 // Test to ensure that when we do a history navigation back to the current
4154 // committed page (e.g., going forward to a slow-loading page, then pressing 4280 // committed page (e.g., going forward to a slow-loading page, then pressing
4155 // the back button), we just stop the navigation to prevent the throbber from 4281 // the back button), we just stop the navigation to prevent the throbber from
4156 // running continuously. Otherwise, the RenderViewHost forces the throbber to 4282 // running continuously. Otherwise, the RenderViewHost forces the throbber to
(...skipping 21 matching lines...) Expand all
4178 TEST_F(NavigationControllerTest, IsInitialNavigation) { 4304 TEST_F(NavigationControllerTest, IsInitialNavigation) {
4179 NavigationControllerImpl& controller = controller_impl(); 4305 NavigationControllerImpl& controller = controller_impl();
4180 TestNotificationTracker notifications; 4306 TestNotificationTracker notifications;
4181 RegisterForAllNavNotifications(&notifications, &controller); 4307 RegisterForAllNavNotifications(&notifications, &controller);
4182 4308
4183 // Initial state. 4309 // Initial state.
4184 EXPECT_TRUE(controller.IsInitialNavigation()); 4310 EXPECT_TRUE(controller.IsInitialNavigation());
4185 4311
4186 // After commit, it stays false. 4312 // After commit, it stays false.
4187 const GURL url1("http://foo1"); 4313 const GURL url1("http://foo1");
4188 main_test_rfh()->SendNavigate(0, url1); 4314 main_test_rfh()->SendNavigate(0, 0, true, url1);
4189 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4315 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4190 navigation_entry_committed_counter_ = 0; 4316 navigation_entry_committed_counter_ = 0;
4191 EXPECT_FALSE(controller.IsInitialNavigation()); 4317 EXPECT_FALSE(controller.IsInitialNavigation());
4192 4318
4193 // After starting a new navigation, it stays false. 4319 // After starting a new navigation, it stays false.
4194 const GURL url2("http://foo2"); 4320 const GURL url2("http://foo2");
4195 controller.LoadURL( 4321 controller.LoadURL(
4196 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 4322 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
4197 } 4323 }
4198 4324
4199 // Check that the favicon is not reused across a client redirect. 4325 // Check that the favicon is not reused across a client redirect.
4200 // (crbug.com/28515) 4326 // (crbug.com/28515)
4201 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { 4327 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) {
4202 const GURL kPageWithFavicon("http://withfavicon.html"); 4328 const GURL kPageWithFavicon("http://withfavicon.html");
4203 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); 4329 const GURL kPageWithoutFavicon("http://withoutfavicon.html");
4204 const GURL kIconURL("http://withfavicon.ico"); 4330 const GURL kIconURL("http://withfavicon.ico");
4205 const gfx::Image kDefaultFavicon = FaviconStatus().image; 4331 const gfx::Image kDefaultFavicon = FaviconStatus().image;
4206 4332
4207 NavigationControllerImpl& controller = controller_impl(); 4333 NavigationControllerImpl& controller = controller_impl();
4208 TestNotificationTracker notifications; 4334 TestNotificationTracker notifications;
4209 RegisterForAllNavNotifications(&notifications, &controller); 4335 RegisterForAllNavNotifications(&notifications, &controller);
4210 4336
4211 main_test_rfh()->SendNavigate(0, kPageWithFavicon); 4337 main_test_rfh()->SendNavigate(0, 0, true, kPageWithFavicon);
4212 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4338 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4213 navigation_entry_committed_counter_ = 0; 4339 navigation_entry_committed_counter_ = 0;
4214 4340
4215 NavigationEntry* entry = controller.GetLastCommittedEntry(); 4341 NavigationEntry* entry = controller.GetLastCommittedEntry();
4216 EXPECT_TRUE(entry); 4342 EXPECT_TRUE(entry);
4217 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); 4343 EXPECT_EQ(kPageWithFavicon, entry->GetURL());
4218 4344
4219 // Simulate Chromium having set the favicon for |kPageWithFavicon|. 4345 // Simulate Chromium having set the favicon for |kPageWithFavicon|.
4220 content::FaviconStatus& favicon_status = entry->GetFavicon(); 4346 content::FaviconStatus& favicon_status = entry->GetFavicon();
4221 favicon_status.image = CreateImage(SK_ColorWHITE); 4347 favicon_status.image = CreateImage(SK_ColorWHITE);
4222 favicon_status.url = kIconURL; 4348 favicon_status.url = kIconURL;
4223 favicon_status.valid = true; 4349 favicon_status.valid = true;
4224 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); 4350 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
4225 4351
4226 main_test_rfh()->SendNavigateWithTransition( 4352 main_test_rfh()->SendNavigateWithTransition(
4227 0, // same page ID. 4353 0, // same page ID.
4354 0, // nav_entry_id
4355 false, // no new entry
4228 kPageWithoutFavicon, 4356 kPageWithoutFavicon,
4229 ui::PAGE_TRANSITION_CLIENT_REDIRECT); 4357 ui::PAGE_TRANSITION_CLIENT_REDIRECT);
4230 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4358 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4231 navigation_entry_committed_counter_ = 0; 4359 navigation_entry_committed_counter_ = 0;
4232 4360
4233 entry = controller.GetLastCommittedEntry(); 4361 entry = controller.GetLastCommittedEntry();
4234 EXPECT_TRUE(entry); 4362 EXPECT_TRUE(entry);
4235 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); 4363 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL());
4236 4364
4237 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); 4365 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image));
4238 } 4366 }
4239 4367
4240 // Check that the favicon is not cleared for NavigationEntries which were 4368 // Check that the favicon is not cleared for NavigationEntries which were
4241 // previously navigated to. 4369 // previously navigated to.
4242 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { 4370 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) {
4243 const GURL kUrl1("http://www.a.com/1"); 4371 const GURL kUrl1("http://www.a.com/1");
4244 const GURL kUrl2("http://www.a.com/2"); 4372 const GURL kUrl2("http://www.a.com/2");
4245 const GURL kIconURL("http://www.a.com/1/favicon.ico"); 4373 const GURL kIconURL("http://www.a.com/1/favicon.ico");
4246 4374
4247 NavigationControllerImpl& controller = controller_impl(); 4375 NavigationControllerImpl& controller = controller_impl();
4248 TestNotificationTracker notifications; 4376 TestNotificationTracker notifications;
4249 RegisterForAllNavNotifications(&notifications, &controller); 4377 RegisterForAllNavNotifications(&notifications, &controller);
4250 4378
4251 main_test_rfh()->SendNavigate(0, kUrl1); 4379 main_test_rfh()->SendNavigate(0, 0, true, kUrl1);
4252 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4380 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4253 navigation_entry_committed_counter_ = 0; 4381 navigation_entry_committed_counter_ = 0;
4254 4382
4255 // Simulate Chromium having set the favicon for |kUrl1|. 4383 // Simulate Chromium having set the favicon for |kUrl1|.
4256 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); 4384 gfx::Image favicon_image = CreateImage(SK_ColorWHITE);
4257 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); 4385 content::NavigationEntry* entry = controller.GetLastCommittedEntry();
4258 EXPECT_TRUE(entry); 4386 EXPECT_TRUE(entry);
4259 content::FaviconStatus& favicon_status = entry->GetFavicon(); 4387 content::FaviconStatus& favicon_status = entry->GetFavicon();
4260 favicon_status.image = favicon_image; 4388 favicon_status.image = favicon_image;
4261 favicon_status.url = kIconURL; 4389 favicon_status.url = kIconURL;
4262 favicon_status.valid = true; 4390 favicon_status.valid = true;
4263 4391
4264 // Navigate to another page and go back to the original page. 4392 // Navigate to another page and go back to the original page.
4265 main_test_rfh()->SendNavigate(1, kUrl2); 4393 main_test_rfh()->SendNavigate(1, 0, true, kUrl2);
4266 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4394 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4267 navigation_entry_committed_counter_ = 0; 4395 navigation_entry_committed_counter_ = 0;
4268 main_test_rfh()->SendNavigateWithTransition( 4396 main_test_rfh()->SendNavigateWithTransition(
4269 0, 4397 0,
4398 controller.GetEntryAtIndex(0)->GetUniqueID(),
4399 false,
4270 kUrl1, 4400 kUrl1,
4271 ui::PAGE_TRANSITION_FORWARD_BACK); 4401 ui::PAGE_TRANSITION_FORWARD_BACK);
4272 EXPECT_EQ(1U, navigation_entry_committed_counter_); 4402 EXPECT_EQ(1U, navigation_entry_committed_counter_);
4273 navigation_entry_committed_counter_ = 0; 4403 navigation_entry_committed_counter_ = 0;
4274 4404
4275 // Verify that the favicon for the page at |kUrl1| was not cleared. 4405 // Verify that the favicon for the page at |kUrl1| was not cleared.
4276 entry = controller.GetEntryAtIndex(0); 4406 entry = controller.GetEntryAtIndex(0);
4277 EXPECT_TRUE(entry); 4407 EXPECT_TRUE(entry);
4278 EXPECT_EQ(kUrl1, entry->GetURL()); 4408 EXPECT_EQ(kUrl1, entry->GetURL());
4279 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image)); 4409 EXPECT_TRUE(DoImagesMatch(favicon_image, entry->GetFavicon().image));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4361 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount()); 4491 EXPECT_EQ(0, screenshot_manager->GetScreenshotCount());
4362 for (int i = 0; i < controller.GetEntryCount(); ++i) { 4492 for (int i = 0; i < controller.GetEntryCount(); ++i) {
4363 entry = controller.GetEntryAtIndex(i); 4493 entry = controller.GetEntryAtIndex(i);
4364 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i 4494 EXPECT_FALSE(entry->screenshot().get()) << "Screenshot " << i
4365 << " not cleared"; 4495 << " not cleared";
4366 } 4496 }
4367 } 4497 }
4368 4498
4369 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { 4499 TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) {
4370 // Navigate. 4500 // Navigate.
4371 contents()->GetMainFrame()->SendNavigate(1, GURL("http://foo")); 4501 contents()->GetMainFrame()->SendNavigate(1, 0, true, GURL("http://foo"));
4372 4502
4373 // Set title and favicon. 4503 // Set title and favicon.
4374 base::string16 title(base::ASCIIToUTF16("Title")); 4504 base::string16 title(base::ASCIIToUTF16("Title"));
4375 FaviconStatus favicon; 4505 FaviconStatus favicon;
4376 favicon.valid = true; 4506 favicon.valid = true;
4377 favicon.url = GURL("http://foo/favicon.ico"); 4507 favicon.url = GURL("http://foo/favicon.ico");
4378 controller().GetLastCommittedEntry()->SetTitle(title); 4508 controller().GetLastCommittedEntry()->SetTitle(title);
4379 controller().GetLastCommittedEntry()->GetFavicon() = favicon; 4509 controller().GetLastCommittedEntry()->GetFavicon() = favicon;
4380 4510
4381 // history.pushState() is called. 4511 // history.pushState() is called.
4382 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4512 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4383 GURL url("http://foo#foo"); 4513 GURL url("http://foo#foo");
4384 params.page_id = 2; 4514 params.page_id = 2;
4515 params.nav_entry_id = 0;
4516 params.did_create_new_entry = true;
4385 params.url = url; 4517 params.url = url;
4386 params.page_state = PageState::CreateFromURL(url); 4518 params.page_state = PageState::CreateFromURL(url);
4387 params.was_within_same_page = true; 4519 params.was_within_same_page = true;
4388 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4520 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4389 4521
4390 // The title should immediately be visible on the new NavigationEntry. 4522 // The title should immediately be visible on the new NavigationEntry.
4391 base::string16 new_title = 4523 base::string16 new_title =
4392 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string()); 4524 controller().GetLastCommittedEntry()->GetTitleForDisplay(std::string());
4393 EXPECT_EQ(title, new_title); 4525 EXPECT_EQ(title, new_title);
4394 FaviconStatus new_favicon = 4526 FaviconStatus new_favicon =
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4451 4583
4452 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) { 4584 TEST_F(NavigationControllerTest, PostThenReplaceStateThenReload) {
4453 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); 4585 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate());
4454 EXPECT_FALSE(contents()->GetDelegate()); 4586 EXPECT_FALSE(contents()->GetDelegate());
4455 contents()->SetDelegate(delegate.get()); 4587 contents()->SetDelegate(delegate.get());
4456 4588
4457 // Submit a form. 4589 // Submit a form.
4458 GURL url("http://foo"); 4590 GURL url("http://foo");
4459 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4591 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4460 params.page_id = 1; 4592 params.page_id = 1;
4593 params.nav_entry_id = 0;
4594 params.did_create_new_entry = true;
4461 params.url = url; 4595 params.url = url;
4462 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT; 4596 params.transition = ui::PAGE_TRANSITION_FORM_SUBMIT;
4463 params.gesture = NavigationGestureUser; 4597 params.gesture = NavigationGestureUser;
4464 params.page_state = PageState::CreateFromURL(url); 4598 params.page_state = PageState::CreateFromURL(url);
4465 params.was_within_same_page = false; 4599 params.was_within_same_page = false;
4466 params.is_post = true; 4600 params.is_post = true;
4467 params.post_id = 2; 4601 params.post_id = 2;
4468 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4602 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4469 4603
4470 // history.replaceState() is called. 4604 // history.replaceState() is called.
4471 GURL replace_url("http://foo#foo"); 4605 GURL replace_url("http://foo#foo");
4472 params.page_id = 1; 4606 params.page_id = 1;
4607 params.nav_entry_id = 0;
4608 params.did_create_new_entry = false;
4473 params.url = replace_url; 4609 params.url = replace_url;
4474 params.transition = ui::PAGE_TRANSITION_LINK; 4610 params.transition = ui::PAGE_TRANSITION_LINK;
4475 params.gesture = NavigationGestureUser; 4611 params.gesture = NavigationGestureUser;
4476 params.page_state = PageState::CreateFromURL(replace_url); 4612 params.page_state = PageState::CreateFromURL(replace_url);
4477 params.was_within_same_page = true; 4613 params.was_within_same_page = true;
4478 params.is_post = false; 4614 params.is_post = false;
4479 params.post_id = -1; 4615 params.post_id = -1;
4480 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4616 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4481 4617
4482 // Now reload. replaceState overrides the POST, so we should not show a 4618 // Now reload. replaceState overrides the POST, so we should not show a
4483 // repost warning dialog. 4619 // repost warning dialog.
4484 controller_impl().Reload(true); 4620 controller_impl().Reload(true);
4485 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4621 EXPECT_EQ(0, delegate->repost_form_warning_count());
4486 } 4622 }
4487 4623
4488 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) { 4624 TEST_F(NavigationControllerTest, UnreachableURLGivesErrorPage) {
4489 GURL url("http://foo"); 4625 GURL url("http://foo");
4490 FrameHostMsg_DidCommitProvisionalLoad_Params params; 4626 FrameHostMsg_DidCommitProvisionalLoad_Params params;
4491 params.page_id = 1; 4627 params.page_id = 1;
4628 params.nav_entry_id = 0;
4629 params.did_create_new_entry = true;
4492 params.url = url; 4630 params.url = url;
4493 params.transition = ui::PAGE_TRANSITION_LINK; 4631 params.transition = ui::PAGE_TRANSITION_LINK;
4494 params.gesture = NavigationGestureUser; 4632 params.gesture = NavigationGestureUser;
4495 params.page_state = PageState::CreateFromURL(url); 4633 params.page_state = PageState::CreateFromURL(url);
4496 params.was_within_same_page = false; 4634 params.was_within_same_page = false;
4497 params.is_post = true; 4635 params.is_post = true;
4498 params.post_id = 2; 4636 params.post_id = 2;
4499 params.url_is_unreachable = true; 4637 params.url_is_unreachable = true;
4500 // Navigate to new page 4638 // Navigate to new page.
4501 { 4639 {
4502 LoadCommittedDetails details; 4640 LoadCommittedDetails details;
4503 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4641 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4504 EXPECT_EQ(PAGE_TYPE_ERROR, 4642 EXPECT_EQ(PAGE_TYPE_ERROR,
4505 controller_impl().GetLastCommittedEntry()->GetPageType()); 4643 controller_impl().GetLastCommittedEntry()->GetPageType());
4506 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type); 4644 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details.type);
4507 } 4645 }
4508 4646
4509 // Navigate to existing page. 4647 // Navigate to existing page.
4510 { 4648 {
(...skipping 25 matching lines...) Expand all
4536 { 4674 {
4537 LoadCommittedDetails details; 4675 LoadCommittedDetails details;
4538 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4676 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4539 EXPECT_EQ(PAGE_TYPE_ERROR, 4677 EXPECT_EQ(PAGE_TYPE_ERROR,
4540 controller_impl().GetLastCommittedEntry()->GetPageType()); 4678 controller_impl().GetLastCommittedEntry()->GetPageType());
4541 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4679 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4542 } 4680 }
4543 } 4681 }
4544 4682
4545 } // namespace content 4683 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698