OLD | NEW |
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 NavigationControllerImpl& controller = controller_impl(); | 309 NavigationControllerImpl& controller = controller_impl(); |
310 TestNotificationTracker notifications; | 310 TestNotificationTracker notifications; |
311 RegisterForAllNavNotifications(¬ifications, &controller); | 311 RegisterForAllNavNotifications(¬ifications, &controller); |
312 | 312 |
313 const int kNumUrls = 5; | 313 const int kNumUrls = 5; |
314 std::vector<GURL> urls(kNumUrls); | 314 std::vector<GURL> urls(kNumUrls); |
315 for (int i = 0; i < kNumUrls; ++i) { | 315 for (int i = 0; i < kNumUrls; ++i) { |
316 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 316 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
317 } | 317 } |
318 | 318 |
319 main_test_rfh()->PrepareForCommit(urls[0]); | 319 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[0], true); |
| 320 main_test_rfh()->PrepareForCommit(); |
320 main_test_rfh()->SendNavigate(0, urls[0]); | 321 main_test_rfh()->SendNavigate(0, urls[0]); |
321 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 322 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
322 navigation_entry_committed_counter_ = 0; | 323 navigation_entry_committed_counter_ = 0; |
323 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); | 324 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
324 EXPECT_FALSE(controller.CanGoBack()); | 325 EXPECT_FALSE(controller.CanGoBack()); |
325 EXPECT_FALSE(controller.CanGoForward()); | 326 EXPECT_FALSE(controller.CanGoForward()); |
326 EXPECT_FALSE(controller.CanGoToOffset(1)); | 327 EXPECT_FALSE(controller.CanGoToOffset(1)); |
327 | 328 |
328 for (int i = 1; i <= 4; ++i) { | 329 for (int i = 1; i <= 4; ++i) { |
329 main_test_rfh()->PrepareForCommit(urls[i]); | 330 main_test_rfh()->SendRendererInitiatedNavigationRequest(urls[i], true); |
| 331 main_test_rfh()->PrepareForCommit(); |
330 main_test_rfh()->SendNavigate(i, urls[i]); | 332 main_test_rfh()->SendNavigate(i, urls[i]); |
331 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 333 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
332 navigation_entry_committed_counter_ = 0; | 334 navigation_entry_committed_counter_ = 0; |
333 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); | 335 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
334 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 336 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
335 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 337 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
336 EXPECT_FALSE(controller.CanGoToOffset(1)); | 338 EXPECT_FALSE(controller.CanGoToOffset(1)); |
337 } | 339 } |
338 | 340 |
339 // We have loaded 5 pages, and are currently at the last-loaded page. | 341 // We have loaded 5 pages, and are currently at the last-loaded page. |
(...skipping 15 matching lines...) Expand all Loading... |
355 GO_TO_BEGINNING, | 357 GO_TO_BEGINNING, |
356 GO_TO_END | 358 GO_TO_END |
357 }; | 359 }; |
358 | 360 |
359 for (int test = 0; test < NUM_TESTS; ++test) { | 361 for (int test = 0; test < NUM_TESTS; ++test) { |
360 int offset = test_offsets[test]; | 362 int offset = test_offsets[test]; |
361 controller.GoToOffset(offset); | 363 controller.GoToOffset(offset); |
362 url_index += offset; | 364 url_index += offset; |
363 // Check that the GoToOffset will land on the expected page. | 365 // Check that the GoToOffset will land on the expected page. |
364 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 366 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
365 main_test_rfh()->PrepareForCommit(urls[url_index]); | 367 main_test_rfh()->PrepareForCommit(); |
366 main_test_rfh()->SendNavigate(url_index, urls[url_index]); | 368 main_test_rfh()->SendNavigate(url_index, urls[url_index]); |
367 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 369 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
368 navigation_entry_committed_counter_ = 0; | 370 navigation_entry_committed_counter_ = 0; |
369 // Check that we can go to any valid offset into the history. | 371 // Check that we can go to any valid offset into the history. |
370 for (size_t j = 0; j < urls.size(); ++j) | 372 for (size_t j = 0; j < urls.size(); ++j) |
371 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 373 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
372 // Check that we can't go beyond the beginning or end of the history. | 374 // Check that we can't go beyond the beginning or end of the history. |
373 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 375 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
374 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 376 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
375 } | 377 } |
(...skipping 24 matching lines...) Expand all Loading... |
400 EXPECT_FALSE(controller.CanGoForward()); | 402 EXPECT_FALSE(controller.CanGoForward()); |
401 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 403 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
402 | 404 |
403 // Neither the timestamp nor the status code should have been set yet. | 405 // Neither the timestamp nor the status code should have been set yet. |
404 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 406 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
405 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 407 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
406 | 408 |
407 // We should have gotten no notifications from the preceeding checks. | 409 // We should have gotten no notifications from the preceeding checks. |
408 EXPECT_EQ(0U, notifications.size()); | 410 EXPECT_EQ(0U, notifications.size()); |
409 | 411 |
410 main_test_rfh()->PrepareForCommit(url1); | 412 main_test_rfh()->PrepareForCommit(); |
411 main_test_rfh()->SendNavigate(0, url1); | 413 main_test_rfh()->SendNavigate(0, url1); |
412 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 414 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
413 navigation_entry_committed_counter_ = 0; | 415 navigation_entry_committed_counter_ = 0; |
414 | 416 |
415 // The load should now be committed. | 417 // The load should now be committed. |
416 EXPECT_EQ(controller.GetEntryCount(), 1); | 418 EXPECT_EQ(controller.GetEntryCount(), 1); |
417 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 419 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
418 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 420 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
419 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 421 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
420 EXPECT_FALSE(controller.GetPendingEntry()); | 422 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 19 matching lines...) Expand all Loading... |
440 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); | 442 EXPECT_EQ(controller.GetPendingEntry(), controller.GetVisibleEntry()); |
441 // TODO(darin): maybe this should really be true? | 443 // TODO(darin): maybe this should really be true? |
442 EXPECT_FALSE(controller.CanGoBack()); | 444 EXPECT_FALSE(controller.CanGoBack()); |
443 EXPECT_FALSE(controller.CanGoForward()); | 445 EXPECT_FALSE(controller.CanGoForward()); |
444 EXPECT_EQ(contents()->GetMaxPageID(), 0); | 446 EXPECT_EQ(contents()->GetMaxPageID(), 0); |
445 | 447 |
446 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 448 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
447 | 449 |
448 // Simulate the beforeunload ack for the cross-site transition, and then the | 450 // Simulate the beforeunload ack for the cross-site transition, and then the |
449 // commit. | 451 // commit. |
450 main_test_rfh()->PrepareForCommit(url2); | 452 main_test_rfh()->PrepareForCommit(); |
451 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 453 contents()->GetPendingMainFrame()->SendNavigate(1, url2); |
452 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 454 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
453 navigation_entry_committed_counter_ = 0; | 455 navigation_entry_committed_counter_ = 0; |
454 | 456 |
455 // The load should now be committed. | 457 // The load should now be committed. |
456 EXPECT_EQ(controller.GetEntryCount(), 2); | 458 EXPECT_EQ(controller.GetEntryCount(), 2); |
457 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 459 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
458 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 460 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
459 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 461 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
460 EXPECT_FALSE(controller.GetPendingEntry()); | 462 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 21 matching lines...) Expand all Loading... |
482 // Set the clock to always return a timestamp of 1. | 484 // Set the clock to always return a timestamp of 1. |
483 controller.SetGetTimestampCallbackForTest( | 485 controller.SetGetTimestampCallbackForTest( |
484 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 486 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
485 | 487 |
486 const GURL url1("http://foo1"); | 488 const GURL url1("http://foo1"); |
487 const GURL url2("http://foo2"); | 489 const GURL url2("http://foo2"); |
488 | 490 |
489 controller.LoadURL( | 491 controller.LoadURL( |
490 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 492 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
491 | 493 |
492 main_test_rfh()->PrepareForCommit(url1); | 494 main_test_rfh()->PrepareForCommit(); |
493 main_test_rfh()->SendNavigate(0, url1); | 495 main_test_rfh()->SendNavigate(0, url1); |
494 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 496 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
495 navigation_entry_committed_counter_ = 0; | 497 navigation_entry_committed_counter_ = 0; |
496 | 498 |
497 // Load another... | 499 // Load another... |
498 controller.LoadURL( | 500 controller.LoadURL( |
499 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 501 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
500 | 502 |
501 // Simulate the beforeunload ack for the cross-site transition, and then the | 503 // Simulate the beforeunload ack for the cross-site transition, and then the |
502 // commit. | 504 // commit. |
503 main_test_rfh()->PrepareForCommit(url2); | 505 main_test_rfh()->PrepareForCommit(); |
504 contents()->GetPendingMainFrame()->SendNavigate(1, url2); | 506 contents()->GetPendingMainFrame()->SendNavigate(1, url2); |
505 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 507 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
506 navigation_entry_committed_counter_ = 0; | 508 navigation_entry_committed_counter_ = 0; |
507 | 509 |
508 // The two loads should now be committed. | 510 // The two loads should now be committed. |
509 ASSERT_EQ(controller.GetEntryCount(), 2); | 511 ASSERT_EQ(controller.GetEntryCount(), 2); |
510 | 512 |
511 // Timestamps should be distinct despite the clock returning the | 513 // Timestamps should be distinct despite the clock returning the |
512 // same value. | 514 // same value. |
513 EXPECT_EQ(1u, | 515 EXPECT_EQ(1u, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 614 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
613 NavigationControllerImpl& controller = controller_impl(); | 615 NavigationControllerImpl& controller = controller_impl(); |
614 TestNotificationTracker notifications; | 616 TestNotificationTracker notifications; |
615 RegisterForAllNavNotifications(¬ifications, &controller); | 617 RegisterForAllNavNotifications(¬ifications, &controller); |
616 | 618 |
617 const GURL url1("http://foo1"); | 619 const GURL url1("http://foo1"); |
618 | 620 |
619 controller.LoadURL( | 621 controller.LoadURL( |
620 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 622 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
621 EXPECT_EQ(0U, notifications.size()); | 623 EXPECT_EQ(0U, notifications.size()); |
622 main_test_rfh()->PrepareForCommit(url1); | 624 main_test_rfh()->PrepareForCommit(); |
623 main_test_rfh()->SendNavigate(0, url1); | 625 main_test_rfh()->SendNavigate(0, url1); |
624 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 626 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
625 navigation_entry_committed_counter_ = 0; | 627 navigation_entry_committed_counter_ = 0; |
626 | 628 |
627 ASSERT_TRUE(controller.GetVisibleEntry()); | 629 ASSERT_TRUE(controller.GetVisibleEntry()); |
628 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 630 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
629 EXPECT_FALSE(timestamp.is_null()); | 631 EXPECT_FALSE(timestamp.is_null()); |
630 | 632 |
631 controller.LoadURL( | 633 controller.LoadURL( |
632 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 634 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
633 EXPECT_EQ(0U, notifications.size()); | 635 EXPECT_EQ(0U, notifications.size()); |
634 main_test_rfh()->PrepareForCommit(url1); | 636 main_test_rfh()->PrepareForCommit(); |
635 main_test_rfh()->SendNavigate(0, url1); | 637 main_test_rfh()->SendNavigate(0, url1); |
636 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 638 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
637 navigation_entry_committed_counter_ = 0; | 639 navigation_entry_committed_counter_ = 0; |
638 | 640 |
639 // We should not have produced a new session history entry. | 641 // We should not have produced a new session history entry. |
640 EXPECT_EQ(controller.GetEntryCount(), 1); | 642 EXPECT_EQ(controller.GetEntryCount(), 1); |
641 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 643 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
642 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 644 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
643 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 645 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
644 EXPECT_FALSE(controller.GetPendingEntry()); | 646 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 19 matching lines...) Expand all Loading... |
664 | 666 |
665 controller.LoadURL( | 667 controller.LoadURL( |
666 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 668 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
667 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 669 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
668 params.page_id = 0; | 670 params.page_id = 0; |
669 params.url = url1; | 671 params.url = url1; |
670 params.transition = ui::PAGE_TRANSITION_TYPED; | 672 params.transition = ui::PAGE_TRANSITION_TYPED; |
671 params.is_post = true; | 673 params.is_post = true; |
672 params.post_id = 123; | 674 params.post_id = 123; |
673 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); | 675 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); |
674 main_test_rfh()->PrepareForCommit(url1); | 676 main_test_rfh()->PrepareForCommit(); |
675 main_test_rfh()->SendNavigateWithParams(¶ms); | 677 main_test_rfh()->SendNavigateWithParams(¶ms); |
676 | 678 |
677 // The post data should be visible. | 679 // The post data should be visible. |
678 NavigationEntry* entry = controller.GetVisibleEntry(); | 680 NavigationEntry* entry = controller.GetVisibleEntry(); |
679 ASSERT_TRUE(entry); | 681 ASSERT_TRUE(entry); |
680 EXPECT_TRUE(entry->GetHasPostData()); | 682 EXPECT_TRUE(entry->GetHasPostData()); |
681 EXPECT_EQ(entry->GetPostID(), 123); | 683 EXPECT_EQ(entry->GetPostID(), 123); |
682 | 684 |
683 controller.LoadURL( | 685 controller.LoadURL( |
684 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 686 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
685 main_test_rfh()->PrepareForCommit(url1); | 687 main_test_rfh()->PrepareForCommit(); |
686 main_test_rfh()->SendNavigate(0, url1); | 688 main_test_rfh()->SendNavigate(0, url1); |
687 | 689 |
688 // We should not have produced a new session history entry. | 690 // We should not have produced a new session history entry. |
689 ASSERT_EQ(controller.GetVisibleEntry(), entry); | 691 ASSERT_EQ(controller.GetVisibleEntry(), entry); |
690 | 692 |
691 // The post data should have been cleared due to the GET. | 693 // The post data should have been cleared due to the GET. |
692 EXPECT_FALSE(entry->GetHasPostData()); | 694 EXPECT_FALSE(entry->GetHasPostData()); |
693 EXPECT_EQ(entry->GetPostID(), 0); | 695 EXPECT_EQ(entry->GetPostID(), 0); |
694 } | 696 } |
695 | 697 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 // commits. | 768 // commits. |
767 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 769 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
768 NavigationControllerImpl& controller = controller_impl(); | 770 NavigationControllerImpl& controller = controller_impl(); |
769 TestNotificationTracker notifications; | 771 TestNotificationTracker notifications; |
770 RegisterForAllNavNotifications(¬ifications, &controller); | 772 RegisterForAllNavNotifications(¬ifications, &controller); |
771 | 773 |
772 // First make an existing committed entry. | 774 // First make an existing committed entry. |
773 const GURL kExistingURL1("http://eh"); | 775 const GURL kExistingURL1("http://eh"); |
774 controller.LoadURL( | 776 controller.LoadURL( |
775 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 777 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
776 main_test_rfh()->PrepareForCommit(kExistingURL1); | 778 main_test_rfh()->PrepareForCommit(); |
777 main_test_rfh()->SendNavigate(0, kExistingURL1); | 779 main_test_rfh()->SendNavigate(0, kExistingURL1); |
778 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 780 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
779 navigation_entry_committed_counter_ = 0; | 781 navigation_entry_committed_counter_ = 0; |
780 | 782 |
781 // Make a pending entry to somewhere new. | 783 // Make a pending entry to somewhere new. |
782 const GURL kExistingURL2("http://bee"); | 784 const GURL kExistingURL2("http://bee"); |
783 controller.LoadURL( | 785 controller.LoadURL( |
784 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 786 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
785 EXPECT_EQ(0U, notifications.size()); | 787 EXPECT_EQ(0U, notifications.size()); |
786 | 788 |
787 // After the beforeunload but before it commits, do a new navigation. | 789 // After the beforeunload but before it commits, do a new navigation. |
788 main_test_rfh()->PrepareForCommit(kExistingURL2); | 790 main_test_rfh()->PrepareForCommit(); |
789 const GURL kNewURL("http://see"); | 791 const GURL kNewURL("http://see"); |
790 main_test_rfh()->PrepareForCommit(kNewURL); | 792 main_test_rfh()->PrepareForCommit(); |
791 contents()->GetMainFrame()->SendNavigate(3, kNewURL); | 793 contents()->GetMainFrame()->SendNavigate(3, kNewURL); |
792 | 794 |
793 // There should no longer be any pending entry, and the third navigation we | 795 // There should no longer be any pending entry, and the third navigation we |
794 // just made should be committed. | 796 // just made should be committed. |
795 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 797 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
796 navigation_entry_committed_counter_ = 0; | 798 navigation_entry_committed_counter_ = 0; |
797 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 799 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
798 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 800 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
799 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 801 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
800 } | 802 } |
801 | 803 |
802 // Tests navigating to a new URL when there is a pending back/forward | 804 // Tests navigating to a new URL when there is a pending back/forward |
803 // navigation. This will happen if the user hits back, but before that commits, | 805 // navigation. This will happen if the user hits back, but before that commits, |
804 // they navigate somewhere new. | 806 // they navigate somewhere new. |
805 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 807 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
806 NavigationControllerImpl& controller = controller_impl(); | 808 NavigationControllerImpl& controller = controller_impl(); |
807 TestNotificationTracker notifications; | 809 TestNotificationTracker notifications; |
808 RegisterForAllNavNotifications(¬ifications, &controller); | 810 RegisterForAllNavNotifications(¬ifications, &controller); |
809 | 811 |
810 // First make some history. | 812 // First make some history. |
811 const GURL kExistingURL1("http://foo/eh"); | 813 const GURL kExistingURL1("http://foo/eh"); |
812 controller.LoadURL( | 814 controller.LoadURL( |
813 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 815 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
814 main_test_rfh()->PrepareForCommit(kExistingURL1); | 816 main_test_rfh()->PrepareForCommit(); |
815 main_test_rfh()->SendNavigate(0, kExistingURL1); | 817 main_test_rfh()->SendNavigate(0, kExistingURL1); |
816 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 818 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
817 navigation_entry_committed_counter_ = 0; | 819 navigation_entry_committed_counter_ = 0; |
818 | 820 |
819 const GURL kExistingURL2("http://foo/bee"); | 821 const GURL kExistingURL2("http://foo/bee"); |
820 controller.LoadURL( | 822 controller.LoadURL( |
821 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 823 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
822 main_test_rfh()->PrepareForCommit(kExistingURL2); | 824 main_test_rfh()->PrepareForCommit(); |
823 main_test_rfh()->SendNavigate(1, kExistingURL2); | 825 main_test_rfh()->SendNavigate(1, kExistingURL2); |
824 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 826 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
825 navigation_entry_committed_counter_ = 0; | 827 navigation_entry_committed_counter_ = 0; |
826 | 828 |
827 // Now make a pending back/forward navigation. The zeroth entry should be | 829 // Now make a pending back/forward navigation. The zeroth entry should be |
828 // pending. | 830 // pending. |
829 controller.GoBack(); | 831 controller.GoBack(); |
830 EXPECT_EQ(0U, notifications.size()); | 832 EXPECT_EQ(0U, notifications.size()); |
831 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 833 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
832 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 834 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
833 | 835 |
834 // Before that commits, do a new navigation. | 836 // Before that commits, do a new navigation. |
835 const GURL kNewURL("http://foo/see"); | 837 const GURL kNewURL("http://foo/see"); |
836 main_test_rfh()->PrepareForCommit(kNewURL); | 838 main_test_rfh()->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 839 main_test_rfh()->PrepareForCommit(); |
837 main_test_rfh()->SendNavigate(3, kNewURL); | 840 main_test_rfh()->SendNavigate(3, kNewURL); |
838 | 841 |
839 // There should no longer be any pending entry, and the third navigation we | 842 // There should no longer be any pending entry, and the third navigation we |
840 // just made should be committed. | 843 // just made should be committed. |
841 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 844 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
842 navigation_entry_committed_counter_ = 0; | 845 navigation_entry_committed_counter_ = 0; |
843 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 846 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
844 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 847 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
845 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 848 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
846 } | 849 } |
847 | 850 |
848 // Tests navigating to a new URL when there is a pending back/forward | 851 // Tests navigating to a new URL when there is a pending back/forward |
849 // navigation to a cross-process, privileged URL. This will happen if the user | 852 // navigation to a cross-process, privileged URL. This will happen if the user |
850 // hits back, but before that commits, they navigate somewhere new. | 853 // hits back, but before that commits, they navigate somewhere new. |
851 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { | 854 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { |
852 NavigationControllerImpl& controller = controller_impl(); | 855 NavigationControllerImpl& controller = controller_impl(); |
853 TestNotificationTracker notifications; | 856 TestNotificationTracker notifications; |
854 RegisterForAllNavNotifications(¬ifications, &controller); | 857 RegisterForAllNavNotifications(¬ifications, &controller); |
855 | 858 |
856 // First make some history, starting with a privileged URL. | 859 // First make some history, starting with a privileged URL. |
857 const GURL kExistingURL1("http://privileged"); | 860 const GURL kExistingURL1("http://privileged"); |
858 controller.LoadURL( | 861 controller.LoadURL( |
859 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 862 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
860 // Pretend it has bindings so we can tell if we incorrectly copy it. | 863 // Pretend it has bindings so we can tell if we incorrectly copy it. |
861 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); | 864 main_test_rfh()->GetRenderViewHost()->AllowBindings(2); |
862 main_test_rfh()->PrepareForCommit(kExistingURL1); | 865 main_test_rfh()->PrepareForCommit(); |
863 main_test_rfh()->SendNavigate(0, kExistingURL1); | 866 main_test_rfh()->SendNavigate(0, kExistingURL1); |
864 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 867 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
865 navigation_entry_committed_counter_ = 0; | 868 navigation_entry_committed_counter_ = 0; |
866 | 869 |
867 // Navigate cross-process to a second URL. | 870 // Navigate cross-process to a second URL. |
868 const GURL kExistingURL2("http://foo/eh"); | 871 const GURL kExistingURL2("http://foo/eh"); |
869 controller.LoadURL( | 872 controller.LoadURL( |
870 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 873 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
871 main_test_rfh()->PrepareForCommit(kExistingURL2); | 874 main_test_rfh()->PrepareForCommit(); |
872 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); | 875 TestRenderFrameHost* foo_rfh = contents()->GetPendingMainFrame(); |
873 foo_rfh->SendNavigate(1, kExistingURL2); | 876 foo_rfh->SendNavigate(1, kExistingURL2); |
874 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 877 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
875 navigation_entry_committed_counter_ = 0; | 878 navigation_entry_committed_counter_ = 0; |
876 | 879 |
877 // Now make a pending back/forward navigation to a privileged entry. | 880 // Now make a pending back/forward navigation to a privileged entry. |
878 // The zeroth entry should be pending. | 881 // The zeroth entry should be pending. |
879 controller.GoBack(); | 882 controller.GoBack(); |
880 foo_rfh->SendBeforeUnloadACK(true); | 883 foo_rfh->SendBeforeUnloadACK(true); |
881 EXPECT_EQ(0U, notifications.size()); | 884 EXPECT_EQ(0U, notifications.size()); |
882 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 885 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
883 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 886 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
884 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); | 887 EXPECT_EQ(2, controller.GetPendingEntry()->bindings()); |
885 | 888 |
886 // Before that commits, do a new navigation. | 889 // Before that commits, do a new navigation. |
887 const GURL kNewURL("http://foo/bee"); | 890 const GURL kNewURL("http://foo/bee"); |
888 foo_rfh->PrepareForCommit(kNewURL); | 891 foo_rfh->SendRendererInitiatedNavigationRequest(kNewURL, true); |
| 892 foo_rfh->PrepareForCommit(); |
889 foo_rfh->SendNavigate(3, kNewURL); | 893 foo_rfh->SendNavigate(3, kNewURL); |
890 | 894 |
891 // There should no longer be any pending entry, and the third navigation we | 895 // There should no longer be any pending entry, and the third navigation we |
892 // just made should be committed. | 896 // just made should be committed. |
893 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 897 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
894 navigation_entry_committed_counter_ = 0; | 898 navigation_entry_committed_counter_ = 0; |
895 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 899 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
896 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 900 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
897 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 901 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
898 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 902 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
899 } | 903 } |
900 | 904 |
901 // Tests navigating to an existing URL when there is a pending new navigation. | 905 // Tests navigating to an existing URL when there is a pending new navigation. |
902 // This will happen if the user enters a URL, but before that commits, the | 906 // This will happen if the user enters a URL, but before that commits, the |
903 // current page fires history.back(). | 907 // current page fires history.back(). |
904 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 908 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
905 NavigationControllerImpl& controller = controller_impl(); | 909 NavigationControllerImpl& controller = controller_impl(); |
906 TestNotificationTracker notifications; | 910 TestNotificationTracker notifications; |
907 RegisterForAllNavNotifications(¬ifications, &controller); | 911 RegisterForAllNavNotifications(¬ifications, &controller); |
908 | 912 |
909 // First make some history. | 913 // First make some history. |
910 const GURL kExistingURL1("http://foo/eh"); | 914 const GURL kExistingURL1("http://foo/eh"); |
911 controller.LoadURL( | 915 controller.LoadURL( |
912 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 916 kExistingURL1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
913 main_test_rfh()->PrepareForCommit(kExistingURL1); | 917 main_test_rfh()->PrepareForCommit(); |
914 main_test_rfh()->SendNavigate(0, kExistingURL1); | 918 main_test_rfh()->SendNavigate(0, kExistingURL1); |
915 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 919 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
916 navigation_entry_committed_counter_ = 0; | 920 navigation_entry_committed_counter_ = 0; |
917 | 921 |
918 const GURL kExistingURL2("http://foo/bee"); | 922 const GURL kExistingURL2("http://foo/bee"); |
919 controller.LoadURL( | 923 controller.LoadURL( |
920 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 924 kExistingURL2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
921 main_test_rfh()->PrepareForCommit(kExistingURL2); | 925 main_test_rfh()->PrepareForCommit(); |
922 main_test_rfh()->SendNavigate(1, kExistingURL2); | 926 main_test_rfh()->SendNavigate(1, kExistingURL2); |
923 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 927 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
924 navigation_entry_committed_counter_ = 0; | 928 navigation_entry_committed_counter_ = 0; |
925 | 929 |
926 // Now make a pending new navigation. | 930 // Now make a pending new navigation. |
927 const GURL kNewURL("http://foo/see"); | 931 const GURL kNewURL("http://foo/see"); |
928 controller.LoadURL( | 932 controller.LoadURL( |
929 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 933 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
930 EXPECT_EQ(0U, notifications.size()); | 934 EXPECT_EQ(0U, notifications.size()); |
931 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 935 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
932 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 936 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
933 | 937 |
934 // Before that commits, a back navigation from the renderer commits. | 938 // Before that commits, a back navigation from the renderer commits. |
935 main_test_rfh()->PrepareForCommit(kExistingURL1); | 939 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL1, true); |
| 940 main_test_rfh()->PrepareForCommit(); |
936 main_test_rfh()->SendNavigate(0, kExistingURL1); | 941 main_test_rfh()->SendNavigate(0, kExistingURL1); |
937 | 942 |
938 // There should no longer be any pending entry, and the back navigation we | 943 // There should no longer be any pending entry, and the back navigation we |
939 // just made should be committed. | 944 // just made should be committed. |
940 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 945 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
941 navigation_entry_committed_counter_ = 0; | 946 navigation_entry_committed_counter_ = 0; |
942 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 947 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
943 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 948 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
944 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); | 949 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
945 } | 950 } |
(...skipping 19 matching lines...) Expand all Loading... |
965 controller.LoadURL( | 970 controller.LoadURL( |
966 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 971 kNewURL, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
967 EXPECT_EQ(0U, notifications.size()); | 972 EXPECT_EQ(0U, notifications.size()); |
968 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 973 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
969 EXPECT_TRUE(controller.GetPendingEntry()); | 974 EXPECT_TRUE(controller.GetPendingEntry()); |
970 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 975 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
971 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 976 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
972 | 977 |
973 // Before that commits, a document.write and location.reload can cause the | 978 // Before that commits, a document.write and location.reload can cause the |
974 // renderer to send a FrameNavigate with page_id -1. | 979 // renderer to send a FrameNavigate with page_id -1. |
975 main_test_rfh()->PrepareForCommit(kExistingURL); | 980 main_test_rfh()->SendRendererInitiatedNavigationRequest(kExistingURL, true); |
| 981 main_test_rfh()->PrepareForCommit(); |
976 main_test_rfh()->SendNavigate(-1, kExistingURL); | 982 main_test_rfh()->SendNavigate(-1, kExistingURL); |
977 | 983 |
978 // This should clear the pending entry and notify of a navigation state | 984 // This should clear the pending entry and notify of a navigation state |
979 // change, so that we do not keep displaying kNewURL. | 985 // change, so that we do not keep displaying kNewURL. |
980 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 986 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
981 EXPECT_FALSE(controller.GetPendingEntry()); | 987 EXPECT_FALSE(controller.GetPendingEntry()); |
982 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 988 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
983 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 989 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
984 | 990 |
985 contents()->SetDelegate(NULL); | 991 contents()->SetDelegate(NULL); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 const GURL url2("http://foo2"); | 1122 const GURL url2("http://foo2"); |
1117 | 1123 |
1118 // Navigate to a first, unprivileged URL. | 1124 // Navigate to a first, unprivileged URL. |
1119 controller.LoadURL( | 1125 controller.LoadURL( |
1120 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1126 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1121 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, | 1127 EXPECT_EQ(NavigationEntryImpl::kInvalidBindings, |
1122 controller.GetPendingEntry()->bindings()); | 1128 controller.GetPendingEntry()->bindings()); |
1123 | 1129 |
1124 // Commit. | 1130 // Commit. |
1125 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); | 1131 TestRenderFrameHost* orig_rfh = contents()->GetMainFrame(); |
1126 orig_rfh->PrepareForCommit(url1); | 1132 orig_rfh->PrepareForCommit(); |
1127 orig_rfh->SendNavigate(0, url1); | 1133 orig_rfh->SendNavigate(0, url1); |
1128 EXPECT_EQ(controller.GetEntryCount(), 1); | 1134 EXPECT_EQ(controller.GetEntryCount(), 1); |
1129 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1135 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1130 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1136 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
1131 | 1137 |
1132 // Manually increase the number of active frames in the SiteInstance | 1138 // Manually increase the number of active frames in the SiteInstance |
1133 // that orig_rfh belongs to, to prevent it from being destroyed when | 1139 // that orig_rfh belongs to, to prevent it from being destroyed when |
1134 // it gets swapped out, so that we can reuse orig_rfh when the | 1140 // it gets swapped out, so that we can reuse orig_rfh when the |
1135 // controller goes back. | 1141 // controller goes back. |
1136 orig_rfh->GetSiteInstance()->increment_active_frame_count(); | 1142 orig_rfh->GetSiteInstance()->increment_active_frame_count(); |
1137 | 1143 |
1138 // Navigate to a second URL, simulate the beforeunload ack for the cross-site | 1144 // Navigate to a second URL, simulate the beforeunload ack for the cross-site |
1139 // transition, and set bindings on the pending RenderViewHost to simulate a | 1145 // transition, and set bindings on the pending RenderViewHost to simulate a |
1140 // privileged url. | 1146 // privileged url. |
1141 controller.LoadURL( | 1147 controller.LoadURL( |
1142 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1148 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1143 orig_rfh->PrepareForCommit(url2); | 1149 orig_rfh->PrepareForCommit(); |
1144 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); | 1150 TestRenderFrameHost* new_rfh = contents()->GetPendingMainFrame(); |
1145 new_rfh->GetRenderViewHost()->AllowBindings(1); | 1151 new_rfh->GetRenderViewHost()->AllowBindings(1); |
1146 new_rfh->SendNavigate(1, url2); | 1152 new_rfh->SendNavigate(1, url2); |
1147 | 1153 |
1148 // The second load should be committed, and bindings should be remembered. | 1154 // The second load should be committed, and bindings should be remembered. |
1149 EXPECT_EQ(controller.GetEntryCount(), 2); | 1155 EXPECT_EQ(controller.GetEntryCount(), 2); |
1150 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1156 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1151 EXPECT_TRUE(controller.CanGoBack()); | 1157 EXPECT_TRUE(controller.CanGoBack()); |
1152 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); | 1158 EXPECT_EQ(1, controller.GetLastCommittedEntry()->bindings()); |
1153 | 1159 |
1154 // Going back, the first entry should still appear unprivileged. | 1160 // Going back, the first entry should still appear unprivileged. |
1155 controller.GoBack(); | 1161 controller.GoBack(); |
1156 new_rfh->PrepareForCommit(url1); | 1162 new_rfh->PrepareForCommit(); |
1157 orig_rfh->SendNavigate(0, url1); | 1163 orig_rfh->SendNavigate(0, url1); |
1158 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1164 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1159 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); | 1165 EXPECT_EQ(0, controller.GetLastCommittedEntry()->bindings()); |
1160 } | 1166 } |
1161 | 1167 |
1162 TEST_F(NavigationControllerTest, Reload) { | 1168 TEST_F(NavigationControllerTest, Reload) { |
1163 NavigationControllerImpl& controller = controller_impl(); | 1169 NavigationControllerImpl& controller = controller_impl(); |
1164 TestNotificationTracker notifications; | 1170 TestNotificationTracker notifications; |
1165 RegisterForAllNavNotifications(¬ifications, &controller); | 1171 RegisterForAllNavNotifications(¬ifications, &controller); |
1166 | 1172 |
1167 const GURL url1("http://foo1"); | 1173 const GURL url1("http://foo1"); |
1168 | 1174 |
1169 controller.LoadURL( | 1175 controller.LoadURL( |
1170 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1176 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1171 EXPECT_EQ(0U, notifications.size()); | 1177 EXPECT_EQ(0U, notifications.size()); |
1172 main_test_rfh()->PrepareForCommit(url1); | 1178 main_test_rfh()->PrepareForCommit(); |
1173 main_test_rfh()->SendNavigate(0, url1); | 1179 main_test_rfh()->SendNavigate(0, url1); |
1174 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1180 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1175 navigation_entry_committed_counter_ = 0; | 1181 navigation_entry_committed_counter_ = 0; |
1176 ASSERT_TRUE(controller.GetVisibleEntry()); | 1182 ASSERT_TRUE(controller.GetVisibleEntry()); |
1177 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1183 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
1178 controller.Reload(true); | 1184 controller.Reload(true); |
1179 EXPECT_EQ(0U, notifications.size()); | 1185 EXPECT_EQ(0U, notifications.size()); |
1180 | 1186 |
1181 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1187 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
1182 EXPECT_FALSE(timestamp.is_null()); | 1188 EXPECT_FALSE(timestamp.is_null()); |
1183 | 1189 |
1184 // The reload is pending. | 1190 // The reload is pending. |
1185 EXPECT_EQ(controller.GetEntryCount(), 1); | 1191 EXPECT_EQ(controller.GetEntryCount(), 1); |
1186 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1192 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1187 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1193 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1188 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1194 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1189 EXPECT_TRUE(controller.GetPendingEntry()); | 1195 EXPECT_TRUE(controller.GetPendingEntry()); |
1190 EXPECT_FALSE(controller.CanGoBack()); | 1196 EXPECT_FALSE(controller.CanGoBack()); |
1191 EXPECT_FALSE(controller.CanGoForward()); | 1197 EXPECT_FALSE(controller.CanGoForward()); |
1192 // Make sure the title has been cleared (will be redrawn just after reload). | 1198 // Make sure the title has been cleared (will be redrawn just after reload). |
1193 // Avoids a stale cached title when the new page being reloaded has no title. | 1199 // Avoids a stale cached title when the new page being reloaded has no title. |
1194 // See http://crbug.com/96041. | 1200 // See http://crbug.com/96041. |
1195 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1201 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
1196 | 1202 |
1197 main_test_rfh()->PrepareForCommit(url1); | 1203 main_test_rfh()->PrepareForCommit(); |
1198 main_test_rfh()->SendNavigate(0, url1); | 1204 main_test_rfh()->SendNavigate(0, url1); |
1199 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1205 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1200 navigation_entry_committed_counter_ = 0; | 1206 navigation_entry_committed_counter_ = 0; |
1201 | 1207 |
1202 // Now the reload is committed. | 1208 // Now the reload is committed. |
1203 EXPECT_EQ(controller.GetEntryCount(), 1); | 1209 EXPECT_EQ(controller.GetEntryCount(), 1); |
1204 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1210 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1205 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1211 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1206 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1212 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1207 EXPECT_FALSE(controller.GetPendingEntry()); | 1213 EXPECT_FALSE(controller.GetPendingEntry()); |
1208 EXPECT_FALSE(controller.CanGoBack()); | 1214 EXPECT_FALSE(controller.CanGoBack()); |
1209 EXPECT_FALSE(controller.CanGoForward()); | 1215 EXPECT_FALSE(controller.CanGoForward()); |
1210 | 1216 |
1211 // The timestamp should have been updated. | 1217 // The timestamp should have been updated. |
1212 ASSERT_TRUE(controller.GetVisibleEntry()); | 1218 ASSERT_TRUE(controller.GetVisibleEntry()); |
1213 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); | 1219 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
1214 } | 1220 } |
1215 | 1221 |
1216 // Tests what happens when a reload navigation produces a new page. | 1222 // Tests what happens when a reload navigation produces a new page. |
1217 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1223 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
1218 NavigationControllerImpl& controller = controller_impl(); | 1224 NavigationControllerImpl& controller = controller_impl(); |
1219 TestNotificationTracker notifications; | 1225 TestNotificationTracker notifications; |
1220 RegisterForAllNavNotifications(¬ifications, &controller); | 1226 RegisterForAllNavNotifications(¬ifications, &controller); |
1221 | 1227 |
1222 const GURL url1("http://foo1"); | 1228 const GURL url1("http://foo1"); |
1223 const GURL url2("http://foo2"); | 1229 const GURL url2("http://foo2"); |
1224 | 1230 |
1225 controller.LoadURL( | 1231 controller.LoadURL( |
1226 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1232 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1227 main_test_rfh()->PrepareForCommit(url1); | 1233 main_test_rfh()->PrepareForCommit(); |
1228 main_test_rfh()->SendNavigate(0, url1); | 1234 main_test_rfh()->SendNavigate(0, url1); |
1229 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1235 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1230 navigation_entry_committed_counter_ = 0; | 1236 navigation_entry_committed_counter_ = 0; |
1231 | 1237 |
1232 controller.Reload(true); | 1238 controller.Reload(true); |
1233 EXPECT_EQ(0U, notifications.size()); | 1239 EXPECT_EQ(0U, notifications.size()); |
1234 | 1240 |
1235 main_test_rfh()->PrepareForCommit(url2); | 1241 main_test_rfh()->PrepareForCommitWithServerRedirect(url2); |
1236 main_test_rfh()->SendNavigate(1, url2); | 1242 main_test_rfh()->SendNavigate(1, url2); |
1237 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1243 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1238 navigation_entry_committed_counter_ = 0; | 1244 navigation_entry_committed_counter_ = 0; |
1239 | 1245 |
1240 // Now the reload is committed. | 1246 // Now the reload is committed. |
1241 EXPECT_EQ(controller.GetEntryCount(), 2); | 1247 EXPECT_EQ(controller.GetEntryCount(), 2); |
1242 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1248 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1243 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1249 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1244 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1250 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1245 EXPECT_FALSE(controller.GetPendingEntry()); | 1251 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 TestNotificationTracker notifications; | 1289 TestNotificationTracker notifications; |
1284 RegisterForAllNavNotifications(¬ifications, &controller); | 1290 RegisterForAllNavNotifications(¬ifications, &controller); |
1285 | 1291 |
1286 const GURL original_url("http://foo1"); | 1292 const GURL original_url("http://foo1"); |
1287 const GURL final_url("http://foo2"); | 1293 const GURL final_url("http://foo2"); |
1288 | 1294 |
1289 // Load up the original URL, but get redirected. | 1295 // Load up the original URL, but get redirected. |
1290 controller.LoadURL( | 1296 controller.LoadURL( |
1291 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1297 original_url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1292 EXPECT_EQ(0U, notifications.size()); | 1298 EXPECT_EQ(0U, notifications.size()); |
1293 main_test_rfh()->PrepareForCommit(final_url); | 1299 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); |
1294 main_test_rfh()->SendNavigateWithOriginalRequestURL( | 1300 main_test_rfh()->SendNavigateWithOriginalRequestURL( |
1295 0, final_url, original_url); | 1301 0, final_url, original_url); |
1296 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1302 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1297 navigation_entry_committed_counter_ = 0; | 1303 navigation_entry_committed_counter_ = 0; |
1298 | 1304 |
1299 // The NavigationEntry should save both the original URL and the final | 1305 // The NavigationEntry should save both the original URL and the final |
1300 // redirected URL. | 1306 // redirected URL. |
1301 EXPECT_EQ( | 1307 EXPECT_EQ( |
1302 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1308 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
1303 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1309 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
(...skipping 12 matching lines...) Expand all Loading... |
1316 EXPECT_TRUE(controller.GetPendingEntry()); | 1322 EXPECT_TRUE(controller.GetPendingEntry()); |
1317 EXPECT_FALSE(controller.CanGoBack()); | 1323 EXPECT_FALSE(controller.CanGoBack()); |
1318 EXPECT_FALSE(controller.CanGoForward()); | 1324 EXPECT_FALSE(controller.CanGoForward()); |
1319 | 1325 |
1320 // Make sure the title has been cleared (will be redrawn just after reload). | 1326 // Make sure the title has been cleared (will be redrawn just after reload). |
1321 // Avoids a stale cached title when the new page being reloaded has no title. | 1327 // Avoids a stale cached title when the new page being reloaded has no title. |
1322 // See http://crbug.com/96041. | 1328 // See http://crbug.com/96041. |
1323 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1329 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
1324 | 1330 |
1325 // Send that the navigation has proceeded; say it got redirected again. | 1331 // Send that the navigation has proceeded; say it got redirected again. |
1326 main_test_rfh()->PrepareForCommit(final_url); | 1332 main_test_rfh()->PrepareForCommitWithServerRedirect(final_url); |
1327 main_test_rfh()->SendNavigate(0, final_url); | 1333 main_test_rfh()->SendNavigate(0, final_url); |
1328 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1334 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1329 navigation_entry_committed_counter_ = 0; | 1335 navigation_entry_committed_counter_ = 0; |
1330 | 1336 |
1331 // Now the reload is committed. | 1337 // Now the reload is committed. |
1332 EXPECT_EQ(controller.GetEntryCount(), 1); | 1338 EXPECT_EQ(controller.GetEntryCount(), 1); |
1333 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1339 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1334 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1340 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1335 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1341 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1336 EXPECT_FALSE(controller.GetPendingEntry()); | 1342 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 NavigationControllerImpl& controller = controller_impl(); | 1486 NavigationControllerImpl& controller = controller_impl(); |
1481 TestNotificationTracker notifications; | 1487 TestNotificationTracker notifications; |
1482 RegisterForAllNavNotifications(¬ifications, &controller); | 1488 RegisterForAllNavNotifications(¬ifications, &controller); |
1483 | 1489 |
1484 const GURL url1("http://foo/1"); | 1490 const GURL url1("http://foo/1"); |
1485 const GURL url2("http://foo/2"); | 1491 const GURL url2("http://foo/2"); |
1486 const GURL url3("http://foo/3"); | 1492 const GURL url3("http://foo/3"); |
1487 | 1493 |
1488 controller.LoadURL( | 1494 controller.LoadURL( |
1489 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1495 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1490 main_test_rfh()->PrepareForCommit(url1); | 1496 main_test_rfh()->PrepareForCommit(); |
1491 main_test_rfh()->SendNavigate(0, url1); | 1497 main_test_rfh()->SendNavigate(0, url1); |
1492 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1498 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1493 navigation_entry_committed_counter_ = 0; | 1499 navigation_entry_committed_counter_ = 0; |
1494 | 1500 |
1495 controller.LoadURL( | 1501 controller.LoadURL( |
1496 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1502 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
1497 main_test_rfh()->PrepareForCommit(url2); | 1503 main_test_rfh()->PrepareForCommit(); |
1498 main_test_rfh()->SendNavigate(1, url2); | 1504 main_test_rfh()->SendNavigate(1, url2); |
1499 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1505 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1500 navigation_entry_committed_counter_ = 0; | 1506 navigation_entry_committed_counter_ = 0; |
1501 | 1507 |
1502 controller.GoBack(); | 1508 controller.GoBack(); |
1503 EXPECT_EQ(0U, notifications.size()); | 1509 EXPECT_EQ(0U, notifications.size()); |
1504 | 1510 |
1505 // We should now have a pending navigation to go back. | 1511 // We should now have a pending navigation to go back. |
1506 EXPECT_EQ(controller.GetEntryCount(), 2); | 1512 EXPECT_EQ(controller.GetEntryCount(), 2); |
1507 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1513 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1508 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1514 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1509 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1515 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1510 EXPECT_TRUE(controller.GetPendingEntry()); | 1516 EXPECT_TRUE(controller.GetPendingEntry()); |
1511 EXPECT_FALSE(controller.CanGoBack()); | 1517 EXPECT_FALSE(controller.CanGoBack()); |
1512 EXPECT_TRUE(controller.CanGoForward()); | 1518 EXPECT_TRUE(controller.CanGoForward()); |
1513 | 1519 |
1514 main_test_rfh()->PrepareForCommit(url3); | 1520 main_test_rfh()->PrepareForCommitWithServerRedirect(url3); |
1515 main_test_rfh()->SendNavigate(2, url3); | 1521 main_test_rfh()->SendNavigate(2, url3); |
1516 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1522 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1517 navigation_entry_committed_counter_ = 0; | 1523 navigation_entry_committed_counter_ = 0; |
1518 | 1524 |
1519 // The back navigation resulted in a completely new navigation. | 1525 // The back navigation resulted in a completely new navigation. |
1520 // TODO(darin): perhaps this behavior will be confusing to users? | 1526 // TODO(darin): perhaps this behavior will be confusing to users? |
1521 EXPECT_EQ(controller.GetEntryCount(), 3); | 1527 EXPECT_EQ(controller.GetEntryCount(), 3); |
1522 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1528 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
1523 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1529 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1524 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1530 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 | 1568 |
1563 // Receives a back message when there is a different renavigation already | 1569 // Receives a back message when there is a different renavigation already |
1564 // pending. | 1570 // pending. |
1565 TEST_F(NavigationControllerTest, Back_OtherBackPending) { | 1571 TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
1566 NavigationControllerImpl& controller = controller_impl(); | 1572 NavigationControllerImpl& controller = controller_impl(); |
1567 const GURL kUrl1("http://foo/1"); | 1573 const GURL kUrl1("http://foo/1"); |
1568 const GURL kUrl2("http://foo/2"); | 1574 const GURL kUrl2("http://foo/2"); |
1569 const GURL kUrl3("http://foo/3"); | 1575 const GURL kUrl3("http://foo/3"); |
1570 | 1576 |
1571 // First navigate three places so we have some back history. | 1577 // First navigate three places so we have some back history. |
1572 main_test_rfh()->PrepareForCommit(kUrl1); | 1578 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); |
| 1579 main_test_rfh()->PrepareForCommit(); |
1573 main_test_rfh()->SendNavigate(0, kUrl1); | 1580 main_test_rfh()->SendNavigate(0, kUrl1); |
1574 main_test_rfh()->PrepareForCommit(kUrl2); | 1581 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); |
| 1582 main_test_rfh()->PrepareForCommit(); |
1575 main_test_rfh()->SendNavigate(1, kUrl2); | 1583 main_test_rfh()->SendNavigate(1, kUrl2); |
1576 main_test_rfh()->PrepareForCommit(kUrl3); | 1584 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl3, true); |
| 1585 main_test_rfh()->PrepareForCommit(); |
1577 main_test_rfh()->SendNavigate(2, kUrl3); | 1586 main_test_rfh()->SendNavigate(2, kUrl3); |
1578 | 1587 |
1579 // With nothing pending, say we get a navigation to the second entry. | 1588 // With nothing pending, say we get a navigation to the second entry. |
1580 main_test_rfh()->PrepareForCommit(kUrl2); | 1589 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl2, true); |
| 1590 main_test_rfh()->PrepareForCommit(); |
1581 main_test_rfh()->SendNavigate(1, kUrl2); | 1591 main_test_rfh()->SendNavigate(1, kUrl2); |
1582 | 1592 |
1583 // We know all the entries have the same site instance, so we can just grab | 1593 // We know all the entries have the same site instance, so we can just grab |
1584 // a random one for looking up other entries. | 1594 // a random one for looking up other entries. |
1585 SiteInstance* site_instance = | 1595 SiteInstance* site_instance = |
1586 controller.GetLastCommittedEntry()->site_instance(); | 1596 controller.GetLastCommittedEntry()->site_instance(); |
1587 | 1597 |
1588 // That second URL should be the last committed and it should have gotten the | 1598 // That second URL should be the last committed and it should have gotten the |
1589 // new title. | 1599 // new title. |
1590 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1600 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
1591 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1601 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1592 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1602 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1593 | 1603 |
1594 // Now go forward to the last item again and say it was committed. | 1604 // Now go forward to the last item again and say it was committed. |
1595 controller.GoForward(); | 1605 controller.GoForward(); |
1596 main_test_rfh()->PrepareForCommit(kUrl3); | 1606 main_test_rfh()->PrepareForCommit(); |
1597 main_test_rfh()->SendNavigate(2, kUrl3); | 1607 main_test_rfh()->SendNavigate(2, kUrl3); |
1598 | 1608 |
1599 // Now start going back one to the second page. It will be pending. | 1609 // Now start going back one to the second page. It will be pending. |
1600 controller.GoBack(); | 1610 controller.GoBack(); |
1601 EXPECT_EQ(1, controller.GetPendingEntryIndex()); | 1611 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
1602 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 1612 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
1603 | 1613 |
1604 // Not synthesize a totally new back event to the first page. This will not | 1614 // Now synthesize a totally new back event to the first page. This will not |
1605 // match the pending one. | 1615 // match the pending one. |
1606 main_test_rfh()->PrepareForCommit(kUrl1); | 1616 main_test_rfh()->SendRendererInitiatedNavigationRequest(kUrl1, true); |
| 1617 main_test_rfh()->PrepareForCommit(); |
1607 main_test_rfh()->SendNavigate(0, kUrl1); | 1618 main_test_rfh()->SendNavigate(0, kUrl1); |
1608 | 1619 |
1609 // The committed navigation should clear the pending entry. | 1620 // The committed navigation should clear the pending entry. |
1610 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1621 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1611 | 1622 |
1612 // But the navigated entry should be the last committed. | 1623 // But the navigated entry should be the last committed. |
1613 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1624 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1614 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); | 1625 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); |
1615 } | 1626 } |
1616 | 1627 |
1617 // Tests what happens when we navigate forward successfully. | 1628 // Tests what happens when we navigate forward successfully. |
1618 TEST_F(NavigationControllerTest, Forward) { | 1629 TEST_F(NavigationControllerTest, Forward) { |
1619 NavigationControllerImpl& controller = controller_impl(); | 1630 NavigationControllerImpl& controller = controller_impl(); |
1620 TestNotificationTracker notifications; | 1631 TestNotificationTracker notifications; |
1621 RegisterForAllNavNotifications(¬ifications, &controller); | 1632 RegisterForAllNavNotifications(¬ifications, &controller); |
1622 | 1633 |
1623 const GURL url1("http://foo1"); | 1634 const GURL url1("http://foo1"); |
1624 const GURL url2("http://foo2"); | 1635 const GURL url2("http://foo2"); |
1625 | 1636 |
1626 main_test_rfh()->PrepareForCommit(url1); | 1637 main_test_rfh()->PrepareForCommit(); |
1627 main_test_rfh()->SendNavigate(0, url1); | 1638 main_test_rfh()->SendNavigate(0, url1); |
1628 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1639 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1629 navigation_entry_committed_counter_ = 0; | 1640 navigation_entry_committed_counter_ = 0; |
1630 | 1641 |
1631 main_test_rfh()->PrepareForCommit(url2); | 1642 main_test_rfh()->PrepareForCommit(); |
1632 main_test_rfh()->SendNavigate(1, url2); | 1643 main_test_rfh()->SendNavigate(1, url2); |
1633 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1644 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1634 navigation_entry_committed_counter_ = 0; | 1645 navigation_entry_committed_counter_ = 0; |
1635 | 1646 |
1636 controller.GoBack(); | 1647 controller.GoBack(); |
1637 main_test_rfh()->PrepareForCommit(url1); | 1648 main_test_rfh()->PrepareForCommit(); |
1638 main_test_rfh()->SendNavigate(0, url1); | 1649 main_test_rfh()->SendNavigate(0, url1); |
1639 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1650 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1640 navigation_entry_committed_counter_ = 0; | 1651 navigation_entry_committed_counter_ = 0; |
1641 | 1652 |
1642 controller.GoForward(); | 1653 controller.GoForward(); |
1643 | 1654 |
1644 // We should now have a pending navigation to go forward. | 1655 // We should now have a pending navigation to go forward. |
1645 EXPECT_EQ(controller.GetEntryCount(), 2); | 1656 EXPECT_EQ(controller.GetEntryCount(), 2); |
1646 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1657 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1647 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1658 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1648 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1659 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1649 EXPECT_TRUE(controller.GetPendingEntry()); | 1660 EXPECT_TRUE(controller.GetPendingEntry()); |
1650 EXPECT_TRUE(controller.CanGoBack()); | 1661 EXPECT_TRUE(controller.CanGoBack()); |
1651 EXPECT_TRUE(controller.CanGoToOffset(-1)); | 1662 EXPECT_TRUE(controller.CanGoToOffset(-1)); |
1652 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. | 1663 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. |
1653 EXPECT_FALSE(controller.CanGoForward()); | 1664 EXPECT_FALSE(controller.CanGoForward()); |
1654 EXPECT_FALSE(controller.CanGoToOffset(1)); | 1665 EXPECT_FALSE(controller.CanGoToOffset(1)); |
1655 | 1666 |
1656 // Timestamp for entry 0 should be on or after that of entry 1 | 1667 // Timestamp for entry 0 should be on or after that of entry 1 |
1657 // (since we went back to it). | 1668 // (since we went back to it). |
1658 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1669 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1659 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1670 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
1660 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1671 controller.GetEntryAtIndex(1)->GetTimestamp()); |
1661 | 1672 |
1662 main_test_rfh()->PrepareForCommit(url2); | 1673 main_test_rfh()->PrepareForCommit(); |
1663 main_test_rfh()->SendNavigate(1, url2); | 1674 main_test_rfh()->SendNavigate(1, url2); |
1664 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1675 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1665 navigation_entry_committed_counter_ = 0; | 1676 navigation_entry_committed_counter_ = 0; |
1666 | 1677 |
1667 // The forward navigation completed successfully. | 1678 // The forward navigation completed successfully. |
1668 EXPECT_EQ(controller.GetEntryCount(), 2); | 1679 EXPECT_EQ(controller.GetEntryCount(), 2); |
1669 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1680 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1670 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1681 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1671 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1682 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1672 EXPECT_FALSE(controller.GetPendingEntry()); | 1683 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 12 matching lines...) Expand all Loading... |
1685 // Tests what happens when a forward navigation produces a new page. | 1696 // Tests what happens when a forward navigation produces a new page. |
1686 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { | 1697 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { |
1687 NavigationControllerImpl& controller = controller_impl(); | 1698 NavigationControllerImpl& controller = controller_impl(); |
1688 TestNotificationTracker notifications; | 1699 TestNotificationTracker notifications; |
1689 RegisterForAllNavNotifications(¬ifications, &controller); | 1700 RegisterForAllNavNotifications(¬ifications, &controller); |
1690 | 1701 |
1691 const GURL url1("http://foo1"); | 1702 const GURL url1("http://foo1"); |
1692 const GURL url2("http://foo2"); | 1703 const GURL url2("http://foo2"); |
1693 const GURL url3("http://foo3"); | 1704 const GURL url3("http://foo3"); |
1694 | 1705 |
1695 main_test_rfh()->PrepareForCommit(url1); | 1706 main_test_rfh()->PrepareForCommit(); |
1696 main_test_rfh()->SendNavigate(0, url1); | 1707 main_test_rfh()->SendNavigate(0, url1); |
1697 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1708 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1698 navigation_entry_committed_counter_ = 0; | 1709 navigation_entry_committed_counter_ = 0; |
1699 main_test_rfh()->PrepareForCommit(url2); | 1710 main_test_rfh()->PrepareForCommit(); |
1700 main_test_rfh()->SendNavigate(1, url2); | 1711 main_test_rfh()->SendNavigate(1, url2); |
1701 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1712 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1702 navigation_entry_committed_counter_ = 0; | 1713 navigation_entry_committed_counter_ = 0; |
1703 | 1714 |
1704 controller.GoBack(); | 1715 controller.GoBack(); |
1705 main_test_rfh()->PrepareForCommit(url1); | 1716 main_test_rfh()->PrepareForCommit(); |
1706 main_test_rfh()->SendNavigate(0, url1); | 1717 main_test_rfh()->SendNavigate(0, url1); |
1707 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1718 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1708 navigation_entry_committed_counter_ = 0; | 1719 navigation_entry_committed_counter_ = 0; |
1709 | 1720 |
1710 controller.GoForward(); | 1721 controller.GoForward(); |
1711 EXPECT_EQ(0U, notifications.size()); | 1722 EXPECT_EQ(0U, notifications.size()); |
1712 | 1723 |
1713 // Should now have a pending navigation to go forward. | 1724 // Should now have a pending navigation to go forward. |
1714 EXPECT_EQ(controller.GetEntryCount(), 2); | 1725 EXPECT_EQ(controller.GetEntryCount(), 2); |
1715 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1726 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1716 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1727 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1717 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1728 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1718 EXPECT_TRUE(controller.GetPendingEntry()); | 1729 EXPECT_TRUE(controller.GetPendingEntry()); |
1719 EXPECT_TRUE(controller.CanGoBack()); | 1730 EXPECT_TRUE(controller.CanGoBack()); |
1720 EXPECT_FALSE(controller.CanGoForward()); | 1731 EXPECT_FALSE(controller.CanGoForward()); |
1721 | 1732 |
1722 main_test_rfh()->PrepareForCommit(url3); | 1733 main_test_rfh()->PrepareForCommit(); |
1723 main_test_rfh()->SendNavigate(2, url3); | 1734 main_test_rfh()->SendNavigate(2, url3); |
1724 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1735 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1725 navigation_entry_committed_counter_ = 0; | 1736 navigation_entry_committed_counter_ = 0; |
1726 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); | 1737 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); |
1727 | 1738 |
1728 EXPECT_EQ(controller.GetEntryCount(), 2); | 1739 EXPECT_EQ(controller.GetEntryCount(), 2); |
1729 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1740 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1730 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1741 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1731 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1742 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1732 EXPECT_FALSE(controller.GetPendingEntry()); | 1743 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 const int kMaxEntryCount = 5; | 2388 const int kMaxEntryCount = 5; |
2378 | 2389 |
2379 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2390 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
2380 | 2391 |
2381 int url_index; | 2392 int url_index; |
2382 // Load up to the max count, all entries should be there. | 2393 // Load up to the max count, all entries should be there. |
2383 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2394 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
2384 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2395 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2385 controller.LoadURL( | 2396 controller.LoadURL( |
2386 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2397 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2387 main_test_rfh()->PrepareForCommit(url); | 2398 main_test_rfh()->PrepareForCommit(); |
2388 main_test_rfh()->SendNavigate(url_index, url); | 2399 main_test_rfh()->SendNavigate(url_index, url); |
2389 } | 2400 } |
2390 | 2401 |
2391 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2402 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2392 | 2403 |
2393 // Created a PrunedListener to observe prune notifications. | 2404 // Created a PrunedListener to observe prune notifications. |
2394 PrunedListener listener(&controller); | 2405 PrunedListener listener(&controller); |
2395 | 2406 |
2396 // Navigate some more. | 2407 // Navigate some more. |
2397 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2408 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2398 controller.LoadURL( | 2409 controller.LoadURL( |
2399 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2410 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2400 main_test_rfh()->PrepareForCommit(url); | 2411 main_test_rfh()->PrepareForCommit(); |
2401 main_test_rfh()->SendNavigate(url_index, url); | 2412 main_test_rfh()->SendNavigate(url_index, url); |
2402 url_index++; | 2413 url_index++; |
2403 | 2414 |
2404 // We should have got a pruned navigation. | 2415 // We should have got a pruned navigation. |
2405 EXPECT_EQ(1, listener.notification_count_); | 2416 EXPECT_EQ(1, listener.notification_count_); |
2406 EXPECT_TRUE(listener.details_.from_front); | 2417 EXPECT_TRUE(listener.details_.from_front); |
2407 EXPECT_EQ(1, listener.details_.count); | 2418 EXPECT_EQ(1, listener.details_.count); |
2408 | 2419 |
2409 // We expect http://www.a.com/0 to be gone. | 2420 // We expect http://www.a.com/0 to be gone. |
2410 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2421 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2411 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2422 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2412 GURL("http:////www.a.com/1")); | 2423 GURL("http:////www.a.com/1")); |
2413 | 2424 |
2414 // More navigations. | 2425 // More navigations. |
2415 for (int i = 0; i < 3; i++) { | 2426 for (int i = 0; i < 3; i++) { |
2416 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); | 2427 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); |
2417 controller.LoadURL( | 2428 controller.LoadURL( |
2418 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2429 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2419 main_test_rfh()->PrepareForCommit(url); | 2430 main_test_rfh()->PrepareForCommit(); |
2420 main_test_rfh()->SendNavigate(url_index, url); | 2431 main_test_rfh()->SendNavigate(url_index, url); |
2421 url_index++; | 2432 url_index++; |
2422 } | 2433 } |
2423 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2434 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2424 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2435 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2425 GURL("http:////www.a.com/4")); | 2436 GURL("http:////www.a.com/4")); |
2426 | 2437 |
2427 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2438 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
2428 } | 2439 } |
2429 | 2440 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2574 our_controller.GetEntryAtIndex(0)->restore_type()); | 2585 our_controller.GetEntryAtIndex(0)->restore_type()); |
2575 } | 2586 } |
2576 | 2587 |
2577 // Make sure that the page type and stuff is correct after an interstitial. | 2588 // Make sure that the page type and stuff is correct after an interstitial. |
2578 TEST_F(NavigationControllerTest, Interstitial) { | 2589 TEST_F(NavigationControllerTest, Interstitial) { |
2579 NavigationControllerImpl& controller = controller_impl(); | 2590 NavigationControllerImpl& controller = controller_impl(); |
2580 // First navigate somewhere normal. | 2591 // First navigate somewhere normal. |
2581 const GURL url1("http://foo"); | 2592 const GURL url1("http://foo"); |
2582 controller.LoadURL( | 2593 controller.LoadURL( |
2583 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2594 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2584 main_test_rfh()->PrepareForCommit(url1); | 2595 main_test_rfh()->PrepareForCommit(); |
2585 main_test_rfh()->SendNavigate(0, url1); | 2596 main_test_rfh()->SendNavigate(0, url1); |
2586 | 2597 |
2587 // Now navigate somewhere with an interstitial. | 2598 // Now navigate somewhere with an interstitial. |
2588 const GURL url2("http://bar"); | 2599 const GURL url2("http://bar"); |
2589 controller.LoadURL( | 2600 controller.LoadURL(url2, Referrer(), ui::PAGE_TRANSITION_TYPED, |
2590 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2601 std::string()); |
2591 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); | 2602 controller.GetPendingEntry()->set_page_type(PAGE_TYPE_INTERSTITIAL); |
2592 | 2603 |
2593 // At this point the interstitial will be displayed and the load will still | 2604 // At this point the interstitial will be displayed and the load will still |
2594 // be pending. If the user continues, the load will commit. | 2605 // be pending. If the user continues, the load will commit. |
2595 main_test_rfh()->PrepareForCommit(url2); | 2606 main_test_rfh()->PrepareForCommit(); |
2596 main_test_rfh()->SendNavigate(1, url2); | 2607 main_test_rfh()->SendNavigate(1, url2); |
2597 | 2608 |
2598 // The page should be a normal page again. | 2609 // The page should be a normal page again. |
2599 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2610 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2600 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2611 EXPECT_EQ(PAGE_TYPE_NORMAL, |
2601 controller.GetLastCommittedEntry()->GetPageType()); | 2612 controller.GetLastCommittedEntry()->GetPageType()); |
2602 } | 2613 } |
2603 | 2614 |
2604 TEST_F(NavigationControllerTest, RemoveEntry) { | 2615 TEST_F(NavigationControllerTest, RemoveEntry) { |
2605 NavigationControllerImpl& controller = controller_impl(); | 2616 NavigationControllerImpl& controller = controller_impl(); |
2606 const GURL url1("http://foo/1"); | 2617 const GURL url1("http://foo/1"); |
2607 const GURL url2("http://foo/2"); | 2618 const GURL url2("http://foo/2"); |
2608 const GURL url3("http://foo/3"); | 2619 const GURL url3("http://foo/3"); |
2609 const GURL url4("http://foo/4"); | 2620 const GURL url4("http://foo/4"); |
2610 const GURL url5("http://foo/5"); | 2621 const GURL url5("http://foo/5"); |
2611 const GURL pending_url("http://foo/pending"); | 2622 const GURL pending_url("http://foo/pending"); |
2612 const GURL default_url("http://foo/default"); | 2623 const GURL default_url("http://foo/default"); |
2613 | 2624 |
2614 controller.LoadURL( | 2625 controller.LoadURL( |
2615 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2626 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2616 main_test_rfh()->PrepareForCommit(url1); | 2627 main_test_rfh()->PrepareForCommit(); |
2617 main_test_rfh()->SendNavigate(0, url1); | 2628 main_test_rfh()->SendNavigate(0, url1); |
2618 controller.LoadURL( | 2629 controller.LoadURL( |
2619 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2630 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2620 main_test_rfh()->PrepareForCommit(url2); | 2631 main_test_rfh()->PrepareForCommit(); |
2621 main_test_rfh()->SendNavigate(1, url2); | 2632 main_test_rfh()->SendNavigate(1, url2); |
2622 controller.LoadURL( | 2633 controller.LoadURL( |
2623 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2634 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2624 main_test_rfh()->PrepareForCommit(url3); | 2635 main_test_rfh()->PrepareForCommit(); |
2625 main_test_rfh()->SendNavigate(2, url3); | 2636 main_test_rfh()->SendNavigate(2, url3); |
2626 controller.LoadURL( | 2637 controller.LoadURL( |
2627 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2638 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2628 main_test_rfh()->PrepareForCommit(url4); | 2639 main_test_rfh()->PrepareForCommit(); |
2629 main_test_rfh()->SendNavigate(3, url4); | 2640 main_test_rfh()->SendNavigate(3, url4); |
2630 controller.LoadURL( | 2641 controller.LoadURL( |
2631 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2642 url5, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2632 main_test_rfh()->PrepareForCommit(url5); | 2643 main_test_rfh()->PrepareForCommit(); |
2633 main_test_rfh()->SendNavigate(4, url5); | 2644 main_test_rfh()->SendNavigate(4, url5); |
2634 | 2645 |
2635 // Try to remove the last entry. Will fail because it is the current entry. | 2646 // Try to remove the last entry. Will fail because it is the current entry. |
2636 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2647 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2637 EXPECT_EQ(5, controller.GetEntryCount()); | 2648 EXPECT_EQ(5, controller.GetEntryCount()); |
2638 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2649 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
2639 | 2650 |
2640 // Go back, but don't commit yet. Check that we can't delete the current | 2651 // Go back, but don't commit yet. Check that we can't delete the current |
2641 // and pending entries. | 2652 // and pending entries. |
2642 controller.GoBack(); | 2653 controller.GoBack(); |
2643 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2654 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2644 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2655 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
2645 | 2656 |
2646 // Now commit and delete the last entry. | 2657 // Now commit and delete the last entry. |
2647 main_test_rfh()->PrepareForCommit(url4); | 2658 main_test_rfh()->PrepareForCommit(); |
2648 main_test_rfh()->SendNavigate(3, url4); | 2659 main_test_rfh()->SendNavigate(3, url4); |
2649 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2660 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2650 EXPECT_EQ(4, controller.GetEntryCount()); | 2661 EXPECT_EQ(4, controller.GetEntryCount()); |
2651 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2662 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
2652 EXPECT_FALSE(controller.GetPendingEntry()); | 2663 EXPECT_FALSE(controller.GetPendingEntry()); |
2653 | 2664 |
2654 // Remove an entry which is not the last committed one. | 2665 // Remove an entry which is not the last committed one. |
2655 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2666 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2656 EXPECT_EQ(3, controller.GetEntryCount()); | 2667 EXPECT_EQ(3, controller.GetEntryCount()); |
2657 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2668 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
(...skipping 10 matching lines...) Expand all Loading... |
2668 | 2679 |
2669 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { | 2680 TEST_F(NavigationControllerTest, RemoveEntryWithPending) { |
2670 NavigationControllerImpl& controller = controller_impl(); | 2681 NavigationControllerImpl& controller = controller_impl(); |
2671 const GURL url1("http://foo/1"); | 2682 const GURL url1("http://foo/1"); |
2672 const GURL url2("http://foo/2"); | 2683 const GURL url2("http://foo/2"); |
2673 const GURL url3("http://foo/3"); | 2684 const GURL url3("http://foo/3"); |
2674 const GURL default_url("http://foo/default"); | 2685 const GURL default_url("http://foo/default"); |
2675 | 2686 |
2676 controller.LoadURL( | 2687 controller.LoadURL( |
2677 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2688 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2678 main_test_rfh()->PrepareForCommit(url1); | 2689 main_test_rfh()->PrepareForCommit(); |
2679 main_test_rfh()->SendNavigate(0, url1); | 2690 main_test_rfh()->SendNavigate(0, url1); |
2680 controller.LoadURL( | 2691 controller.LoadURL( |
2681 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2692 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2682 main_test_rfh()->PrepareForCommit(url2); | 2693 main_test_rfh()->PrepareForCommit(); |
2683 main_test_rfh()->SendNavigate(1, url2); | 2694 main_test_rfh()->SendNavigate(1, url2); |
2684 controller.LoadURL( | 2695 controller.LoadURL( |
2685 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2696 url3, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2686 main_test_rfh()->PrepareForCommit(url3); | 2697 main_test_rfh()->PrepareForCommit(); |
2687 main_test_rfh()->SendNavigate(2, url3); | 2698 main_test_rfh()->SendNavigate(2, url3); |
2688 | 2699 |
2689 // Go back, but don't commit yet. Check that we can't delete the current | 2700 // Go back, but don't commit yet. Check that we can't delete the current |
2690 // and pending entries. | 2701 // and pending entries. |
2691 controller.GoBack(); | 2702 controller.GoBack(); |
2692 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); | 2703 EXPECT_FALSE(controller.RemoveEntryAtIndex(2)); |
2693 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); | 2704 EXPECT_FALSE(controller.RemoveEntryAtIndex(1)); |
2694 | 2705 |
2695 // Remove the first entry, while there is a pending entry. This is expected | 2706 // Remove the first entry, while there is a pending entry. This is expected |
2696 // to discard the pending entry. | 2707 // to discard the pending entry. |
2697 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2708 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2698 EXPECT_FALSE(controller.GetPendingEntry()); | 2709 EXPECT_FALSE(controller.GetPendingEntry()); |
2699 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 2710 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
2700 | 2711 |
2701 // We should update the last committed entry index. | 2712 // We should update the last committed entry index. |
2702 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 2713 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
2703 | 2714 |
2704 // Now commit and ensure we land on the right entry. | 2715 // Now commit and ensure we land on the right entry. |
2705 main_test_rfh()->PrepareForCommit(url2); | 2716 main_test_rfh()->PrepareForCommit(); |
2706 main_test_rfh()->SendNavigate(1, url2); | 2717 main_test_rfh()->SendNavigate(1, url2); |
2707 EXPECT_EQ(2, controller.GetEntryCount()); | 2718 EXPECT_EQ(2, controller.GetEntryCount()); |
2708 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 2719 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
2709 EXPECT_FALSE(controller.GetPendingEntry()); | 2720 EXPECT_FALSE(controller.GetPendingEntry()); |
2710 } | 2721 } |
2711 | 2722 |
2712 // Tests the transient entry, making sure it goes away with all navigations. | 2723 // Tests the transient entry, making sure it goes away with all navigations. |
2713 TEST_F(NavigationControllerTest, TransientEntry) { | 2724 TEST_F(NavigationControllerTest, TransientEntry) { |
2714 NavigationControllerImpl& controller = controller_impl(); | 2725 NavigationControllerImpl& controller = controller_impl(); |
2715 TestNotificationTracker notifications; | 2726 TestNotificationTracker notifications; |
2716 RegisterForAllNavNotifications(¬ifications, &controller); | 2727 RegisterForAllNavNotifications(¬ifications, &controller); |
2717 | 2728 |
2718 const GURL url0("http://foo/0"); | 2729 const GURL url0("http://foo/0"); |
2719 const GURL url1("http://foo/1"); | 2730 const GURL url1("http://foo/1"); |
2720 const GURL url2("http://foo/2"); | 2731 const GURL url2("http://foo/2"); |
2721 const GURL url3("http://foo/3"); | 2732 const GURL url3("http://foo/3"); |
2722 const GURL url3_ref("http://foo/3#bar"); | 2733 const GURL url3_ref("http://foo/3#bar"); |
2723 const GURL url4("http://foo/4"); | 2734 const GURL url4("http://foo/4"); |
2724 const GURL transient_url("http://foo/transient"); | 2735 const GURL transient_url("http://foo/transient"); |
2725 | 2736 |
2726 controller.LoadURL( | 2737 controller.LoadURL( |
2727 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2738 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2728 main_test_rfh()->PrepareForCommit(url0); | 2739 main_test_rfh()->PrepareForCommit(); |
2729 main_test_rfh()->SendNavigate(0, url0); | 2740 main_test_rfh()->SendNavigate(0, url0); |
2730 controller.LoadURL( | 2741 controller.LoadURL( |
2731 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2742 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2732 main_test_rfh()->PrepareForCommit(url1); | 2743 main_test_rfh()->PrepareForCommit(); |
2733 main_test_rfh()->SendNavigate(1, url1); | 2744 main_test_rfh()->SendNavigate(1, url1); |
2734 | 2745 |
2735 notifications.Reset(); | 2746 notifications.Reset(); |
2736 | 2747 |
2737 // Adding a transient with no pending entry. | 2748 // Adding a transient with no pending entry. |
2738 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2749 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2739 transient_entry->SetURL(transient_url); | 2750 transient_entry->SetURL(transient_url); |
2740 controller.SetTransientEntry(transient_entry); | 2751 controller.SetTransientEntry(transient_entry); |
2741 | 2752 |
2742 // We should not have received any notifications. | 2753 // We should not have received any notifications. |
2743 EXPECT_EQ(0U, notifications.size()); | 2754 EXPECT_EQ(0U, notifications.size()); |
2744 | 2755 |
2745 // Check our state. | 2756 // Check our state. |
2746 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2757 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2747 EXPECT_EQ(controller.GetEntryCount(), 3); | 2758 EXPECT_EQ(controller.GetEntryCount(), 3); |
2748 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2759 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2749 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2760 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2750 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2761 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2751 EXPECT_FALSE(controller.GetPendingEntry()); | 2762 EXPECT_FALSE(controller.GetPendingEntry()); |
2752 EXPECT_TRUE(controller.CanGoBack()); | 2763 EXPECT_TRUE(controller.CanGoBack()); |
2753 EXPECT_FALSE(controller.CanGoForward()); | 2764 EXPECT_FALSE(controller.CanGoForward()); |
2754 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2765 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
2755 | 2766 |
2756 // Navigate. | 2767 // Navigate. |
2757 controller.LoadURL( | 2768 controller.LoadURL( |
2758 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2769 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2759 main_test_rfh()->PrepareForCommit(url2); | 2770 main_test_rfh()->PrepareForCommit(); |
2760 main_test_rfh()->SendNavigate(2, url2); | 2771 main_test_rfh()->SendNavigate(2, url2); |
2761 | 2772 |
2762 // We should have navigated, transient entry should be gone. | 2773 // We should have navigated, transient entry should be gone. |
2763 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2774 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2764 EXPECT_EQ(controller.GetEntryCount(), 3); | 2775 EXPECT_EQ(controller.GetEntryCount(), 3); |
2765 | 2776 |
2766 // Add a transient again, then navigate with no pending entry this time. | 2777 // Add a transient again, then navigate with no pending entry this time. |
2767 transient_entry = new NavigationEntryImpl; | 2778 transient_entry = new NavigationEntryImpl; |
2768 transient_entry->SetURL(transient_url); | 2779 transient_entry->SetURL(transient_url); |
2769 controller.SetTransientEntry(transient_entry); | 2780 controller.SetTransientEntry(transient_entry); |
2770 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2781 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2771 main_test_rfh()->PrepareForCommit(url3); | 2782 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); |
| 2783 main_test_rfh()->PrepareForCommit(); |
2772 main_test_rfh()->SendNavigate(3, url3); | 2784 main_test_rfh()->SendNavigate(3, url3); |
2773 // Transient entry should be gone. | 2785 // Transient entry should be gone. |
2774 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2786 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2775 EXPECT_EQ(controller.GetEntryCount(), 4); | 2787 EXPECT_EQ(controller.GetEntryCount(), 4); |
2776 | 2788 |
2777 // Initiate a navigation, add a transient then commit navigation. | 2789 // Initiate a navigation, add a transient then commit navigation. |
2778 controller.LoadURL( | 2790 controller.LoadURL( |
2779 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2791 url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2780 transient_entry = new NavigationEntryImpl; | 2792 transient_entry = new NavigationEntryImpl; |
2781 transient_entry->SetURL(transient_url); | 2793 transient_entry->SetURL(transient_url); |
2782 controller.SetTransientEntry(transient_entry); | 2794 controller.SetTransientEntry(transient_entry); |
2783 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2795 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2784 main_test_rfh()->PrepareForCommit(url4); | 2796 main_test_rfh()->PrepareForCommit(); |
2785 main_test_rfh()->SendNavigate(4, url4); | 2797 main_test_rfh()->SendNavigate(4, url4); |
2786 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2798 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
2787 EXPECT_EQ(controller.GetEntryCount(), 5); | 2799 EXPECT_EQ(controller.GetEntryCount(), 5); |
2788 | 2800 |
2789 // Add a transient and go back. This should simply remove the transient. | 2801 // Add a transient and go back. This should simply remove the transient. |
2790 transient_entry = new NavigationEntryImpl; | 2802 transient_entry = new NavigationEntryImpl; |
2791 transient_entry->SetURL(transient_url); | 2803 transient_entry->SetURL(transient_url); |
2792 controller.SetTransientEntry(transient_entry); | 2804 controller.SetTransientEntry(transient_entry); |
2793 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2805 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2794 EXPECT_TRUE(controller.CanGoBack()); | 2806 EXPECT_TRUE(controller.CanGoBack()); |
2795 EXPECT_FALSE(controller.CanGoForward()); | 2807 EXPECT_FALSE(controller.CanGoForward()); |
2796 controller.GoBack(); | 2808 controller.GoBack(); |
2797 // Transient entry should be gone. | 2809 // Transient entry should be gone. |
2798 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2810 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
2799 EXPECT_EQ(controller.GetEntryCount(), 5); | 2811 EXPECT_EQ(controller.GetEntryCount(), 5); |
2800 main_test_rfh()->PrepareForCommit(url3); | 2812 |
| 2813 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, false); |
| 2814 main_test_rfh()->PrepareForCommit(); |
2801 main_test_rfh()->SendNavigate(3, url3); | 2815 main_test_rfh()->SendNavigate(3, url3); |
2802 | 2816 |
2803 // Add a transient and go to an entry before the current one. | 2817 // Add a transient and go to an entry before the current one. |
2804 transient_entry = new NavigationEntryImpl; | 2818 transient_entry = new NavigationEntryImpl; |
2805 transient_entry->SetURL(transient_url); | 2819 transient_entry->SetURL(transient_url); |
2806 controller.SetTransientEntry(transient_entry); | 2820 controller.SetTransientEntry(transient_entry); |
2807 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2821 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2808 controller.GoToIndex(1); | 2822 controller.GoToIndex(1); |
2809 // The navigation should have been initiated, transient entry should be gone. | 2823 // The navigation should have been initiated, transient entry should be gone. |
2810 EXPECT_FALSE(controller.GetTransientEntry()); | 2824 EXPECT_FALSE(controller.GetTransientEntry()); |
2811 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2825 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2812 // Visible entry does not update for history navigations until commit. | 2826 // Visible entry does not update for history navigations until commit. |
2813 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2827 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2814 main_test_rfh()->PrepareForCommit(url1); | 2828 main_test_rfh()->PrepareForCommit(); |
2815 main_test_rfh()->SendNavigate(1, url1); | 2829 main_test_rfh()->SendNavigate(1, url1); |
2816 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2830 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2817 | 2831 |
2818 // Add a transient and go to an entry after the current one. | 2832 // Add a transient and go to an entry after the current one. |
2819 transient_entry = new NavigationEntryImpl; | 2833 transient_entry = new NavigationEntryImpl; |
2820 transient_entry->SetURL(transient_url); | 2834 transient_entry->SetURL(transient_url); |
2821 controller.SetTransientEntry(transient_entry); | 2835 controller.SetTransientEntry(transient_entry); |
2822 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2836 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2823 controller.GoToIndex(3); | 2837 controller.GoToIndex(3); |
2824 // The navigation should have been initiated, transient entry should be gone. | 2838 // The navigation should have been initiated, transient entry should be gone. |
2825 // Because of the transient entry that is removed, going to index 3 makes us | 2839 // Because of the transient entry that is removed, going to index 3 makes us |
2826 // land on url2 (which is visible after the commit). | 2840 // land on url2 (which is visible after the commit). |
2827 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2841 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
2828 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2842 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2829 main_test_rfh()->PrepareForCommit(url2); | 2843 main_test_rfh()->PrepareForCommit(); |
2830 main_test_rfh()->SendNavigate(2, url2); | 2844 main_test_rfh()->SendNavigate(2, url2); |
2831 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2845 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2832 | 2846 |
2833 // Add a transient and go forward. | 2847 // Add a transient and go forward. |
2834 transient_entry = new NavigationEntryImpl; | 2848 transient_entry = new NavigationEntryImpl; |
2835 transient_entry->SetURL(transient_url); | 2849 transient_entry->SetURL(transient_url); |
2836 controller.SetTransientEntry(transient_entry); | 2850 controller.SetTransientEntry(transient_entry); |
2837 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2851 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2838 EXPECT_TRUE(controller.CanGoForward()); | 2852 EXPECT_TRUE(controller.CanGoForward()); |
2839 controller.GoForward(); | 2853 controller.GoForward(); |
2840 // We should have navigated, transient entry should be gone. | 2854 // We should have navigated, transient entry should be gone. |
2841 EXPECT_FALSE(controller.GetTransientEntry()); | 2855 EXPECT_FALSE(controller.GetTransientEntry()); |
2842 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 2856 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
2843 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2857 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2844 main_test_rfh()->PrepareForCommit(url3); | 2858 main_test_rfh()->PrepareForCommit(); |
2845 main_test_rfh()->SendNavigate(3, url3); | 2859 main_test_rfh()->SendNavigate(3, url3); |
2846 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2860 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2847 | 2861 |
2848 // Add a transient and do an in-page navigation, replacing the current entry. | 2862 // Add a transient and do an in-page navigation, replacing the current entry. |
2849 transient_entry = new NavigationEntryImpl; | 2863 transient_entry = new NavigationEntryImpl; |
2850 transient_entry->SetURL(transient_url); | 2864 transient_entry->SetURL(transient_url); |
2851 controller.SetTransientEntry(transient_entry); | 2865 controller.SetTransientEntry(transient_entry); |
2852 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2866 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2853 main_test_rfh()->PrepareForCommit(url3_ref); | 2867 |
| 2868 main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); |
| 2869 main_test_rfh()->PrepareForCommit(); |
2854 main_test_rfh()->SendNavigate(3, url3_ref); | 2870 main_test_rfh()->SendNavigate(3, url3_ref); |
2855 // Transient entry should be gone. | 2871 // Transient entry should be gone. |
2856 EXPECT_FALSE(controller.GetTransientEntry()); | 2872 EXPECT_FALSE(controller.GetTransientEntry()); |
2857 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 2873 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
2858 | 2874 |
2859 // Ensure the URLs are correct. | 2875 // Ensure the URLs are correct. |
2860 EXPECT_EQ(controller.GetEntryCount(), 5); | 2876 EXPECT_EQ(controller.GetEntryCount(), 5); |
2861 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2877 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
2862 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 2878 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
2863 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 2879 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
2864 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 2880 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
2865 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 2881 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
2866 } | 2882 } |
2867 | 2883 |
2868 // Test that Reload initiates a new navigation to a transient entry's URL. | 2884 // Test that Reload initiates a new navigation to a transient entry's URL. |
2869 TEST_F(NavigationControllerTest, ReloadTransient) { | 2885 TEST_F(NavigationControllerTest, ReloadTransient) { |
2870 NavigationControllerImpl& controller = controller_impl(); | 2886 NavigationControllerImpl& controller = controller_impl(); |
2871 const GURL url0("http://foo/0"); | 2887 const GURL url0("http://foo/0"); |
2872 const GURL url1("http://foo/1"); | 2888 const GURL url1("http://foo/1"); |
2873 const GURL transient_url("http://foo/transient"); | 2889 const GURL transient_url("http://foo/transient"); |
2874 | 2890 |
2875 // Load |url0|, and start a pending navigation to |url1|. | 2891 // Load |url0|, and start a pending navigation to |url1|. |
2876 controller.LoadURL( | 2892 controller.LoadURL( |
2877 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2893 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2878 main_test_rfh()->PrepareForCommit(url0); | 2894 main_test_rfh()->PrepareForCommit(); |
2879 main_test_rfh()->SendNavigate(0, url0); | 2895 main_test_rfh()->SendNavigate(0, url0); |
2880 controller.LoadURL( | 2896 controller.LoadURL( |
2881 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2897 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2882 | 2898 |
2883 // A transient entry is added, interrupting the navigation. | 2899 // A transient entry is added, interrupting the navigation. |
2884 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2900 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2885 transient_entry->SetURL(transient_url); | 2901 transient_entry->SetURL(transient_url); |
2886 controller.SetTransientEntry(transient_entry); | 2902 controller.SetTransientEntry(transient_entry); |
2887 EXPECT_TRUE(controller.GetTransientEntry()); | 2903 EXPECT_TRUE(controller.GetTransientEntry()); |
2888 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2904 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2889 | 2905 |
2890 // The page is reloaded, which should remove the pending entry for |url1| and | 2906 // The page is reloaded, which should remove the pending entry for |url1| and |
2891 // the transient entry for |transient_url|, and start a navigation to | 2907 // the transient entry for |transient_url|, and start a navigation to |
2892 // |transient_url|. | 2908 // |transient_url|. |
2893 controller.Reload(true); | 2909 controller.Reload(true); |
2894 EXPECT_FALSE(controller.GetTransientEntry()); | 2910 EXPECT_FALSE(controller.GetTransientEntry()); |
2895 EXPECT_TRUE(controller.GetPendingEntry()); | 2911 EXPECT_TRUE(controller.GetPendingEntry()); |
2896 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2912 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2897 ASSERT_EQ(controller.GetEntryCount(), 1); | 2913 ASSERT_EQ(controller.GetEntryCount(), 1); |
2898 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2914 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
2899 | 2915 |
2900 // Load of |transient_url| completes. | 2916 // Load of |transient_url| completes. |
2901 main_test_rfh()->PrepareForCommit(transient_url); | 2917 main_test_rfh()->PrepareForCommit(); |
2902 main_test_rfh()->SendNavigate(1, transient_url); | 2918 main_test_rfh()->SendNavigate(1, transient_url); |
2903 ASSERT_EQ(controller.GetEntryCount(), 2); | 2919 ASSERT_EQ(controller.GetEntryCount(), 2); |
2904 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2920 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
2905 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2921 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
2906 } | 2922 } |
2907 | 2923 |
2908 // Ensure that renderer initiated pending entries get replaced, so that we | 2924 // Ensure that renderer initiated pending entries get replaced, so that we |
2909 // don't show a stale virtual URL when a navigation commits. | 2925 // don't show a stale virtual URL when a navigation commits. |
2910 // See http://crbug.com/266922. | 2926 // See http://crbug.com/266922. |
2911 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 2927 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2970 | 2986 |
2971 const GURL url0("http://foo/0"); | 2987 const GURL url0("http://foo/0"); |
2972 const GURL url1("http://foo/1"); | 2988 const GURL url1("http://foo/1"); |
2973 | 2989 |
2974 // For typed navigations (browser-initiated), both pending and visible entries | 2990 // For typed navigations (browser-initiated), both pending and visible entries |
2975 // should update before commit. | 2991 // should update before commit. |
2976 controller.LoadURL( | 2992 controller.LoadURL( |
2977 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 2993 url0, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
2978 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 2994 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
2979 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2995 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
2980 main_test_rfh()->PrepareForCommit(url0); | 2996 main_test_rfh()->PrepareForCommit(); |
2981 main_test_rfh()->SendNavigate(0, url0); | 2997 main_test_rfh()->SendNavigate(0, url0); |
2982 | 2998 |
2983 // For link clicks (renderer-initiated navigations), the pending entry should | 2999 // For link clicks (renderer-initiated navigations), the pending entry should |
2984 // update before commit but the visible should not. | 3000 // update before commit but the visible should not. |
2985 NavigationController::LoadURLParams load_url_params(url1); | 3001 NavigationController::LoadURLParams load_url_params(url1); |
2986 load_url_params.is_renderer_initiated = true; | 3002 load_url_params.is_renderer_initiated = true; |
2987 controller.LoadURLWithParams(load_url_params); | 3003 controller.LoadURLWithParams(load_url_params); |
2988 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 3004 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
2989 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 3005 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2990 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); | 3006 EXPECT_TRUE(controller.GetPendingEntry()->is_renderer_initiated()); |
2991 | 3007 |
2992 // After commit, both visible should be updated, there should be no pending | 3008 // After commit, both visible should be updated, there should be no pending |
2993 // entry, and we should no longer treat the entry as renderer-initiated. | 3009 // entry, and we should no longer treat the entry as renderer-initiated. |
2994 main_test_rfh()->PrepareForCommit(url1); | 3010 main_test_rfh()->PrepareForCommit(); |
2995 main_test_rfh()->SendNavigate(1, url1); | 3011 main_test_rfh()->SendNavigate(1, url1); |
2996 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 3012 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2997 EXPECT_FALSE(controller.GetPendingEntry()); | 3013 EXPECT_FALSE(controller.GetPendingEntry()); |
2998 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); | 3014 EXPECT_FALSE(controller.GetLastCommittedEntry()->is_renderer_initiated()); |
2999 | 3015 |
3000 notifications.Reset(); | 3016 notifications.Reset(); |
3001 } | 3017 } |
3002 | 3018 |
3003 // Tests that the URLs for renderer-initiated navigations in new tabs are | 3019 // Tests that the URLs for renderer-initiated navigations in new tabs are |
3004 // displayed to the user before commit, as long as the initial about:blank | 3020 // displayed to the user before commit, as long as the initial about:blank |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4118 | 4134 |
4119 // We should only have the last committed and pending entries at this point, | 4135 // We should only have the last committed and pending entries at this point, |
4120 // and the pending entry should still not be in the entry list. | 4136 // and the pending entry should still not be in the entry list. |
4121 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4137 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4122 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 4138 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
4123 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4139 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4124 EXPECT_TRUE(controller.GetPendingEntry()); | 4140 EXPECT_TRUE(controller.GetPendingEntry()); |
4125 EXPECT_EQ(1, controller.GetEntryCount()); | 4141 EXPECT_EQ(1, controller.GetEntryCount()); |
4126 | 4142 |
4127 // Try to commit the pending entry. | 4143 // Try to commit the pending entry. |
4128 main_test_rfh()->PrepareForCommit(url3); | 4144 main_test_rfh()->PrepareForCommit(); |
4129 main_test_rfh()->SendNavigate(2, url3); | 4145 main_test_rfh()->SendNavigate(2, url3); |
4130 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4146 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4131 EXPECT_FALSE(controller.GetPendingEntry()); | 4147 EXPECT_FALSE(controller.GetPendingEntry()); |
4132 EXPECT_EQ(2, controller.GetEntryCount()); | 4148 EXPECT_EQ(2, controller.GetEntryCount()); |
4133 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 4149 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
4134 } | 4150 } |
4135 | 4151 |
4136 // Test to ensure that when we do a history navigation back to the current | 4152 // Test to ensure that when we do a history navigation back to the current |
4137 // committed page (e.g., going forward to a slow-loading page, then pressing | 4153 // committed page (e.g., going forward to a slow-loading page, then pressing |
4138 // the back button), we just stop the navigation to prevent the throbber from | 4154 // the back button), we just stop the navigation to prevent the throbber from |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4404 NavigationController::LoadURLParams params(url4); | 4420 NavigationController::LoadURLParams params(url4); |
4405 params.should_clear_history_list = true; | 4421 params.should_clear_history_list = true; |
4406 controller.LoadURLWithParams(params); | 4422 controller.LoadURLWithParams(params); |
4407 | 4423 |
4408 // Verify that the pending entry correctly indicates that the session history | 4424 // Verify that the pending entry correctly indicates that the session history |
4409 // should be cleared. | 4425 // should be cleared. |
4410 NavigationEntryImpl* entry = controller.GetPendingEntry(); | 4426 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
4411 ASSERT_TRUE(entry); | 4427 ASSERT_TRUE(entry); |
4412 EXPECT_TRUE(entry->should_clear_history_list()); | 4428 EXPECT_TRUE(entry->should_clear_history_list()); |
4413 | 4429 |
4414 // Assume that the RF correctly cleared its history and commit the navigation. | 4430 // Assume that the RenderFrame correctly cleared its history and commit the |
| 4431 // navigation. |
4415 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 4432 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
4416 switches::kEnableBrowserSideNavigation)) { | 4433 switches::kEnableBrowserSideNavigation)) { |
4417 contents()->GetMainFrame()->PrepareForCommit(entry->GetURL()); | 4434 contents()->GetMainFrame()->SendBeforeUnloadACK(true); |
4418 } | 4435 } |
4419 contents()->GetPendingMainFrame()-> | 4436 contents()->GetPendingMainFrame()-> |
4420 set_simulate_history_list_was_cleared(true); | 4437 set_simulate_history_list_was_cleared(true); |
4421 contents()->CommitPendingNavigation(); | 4438 contents()->CommitPendingNavigation(); |
4422 | 4439 |
4423 // Verify that the NavigationController's session history was correctly | 4440 // Verify that the NavigationController's session history was correctly |
4424 // cleared. | 4441 // cleared. |
4425 EXPECT_EQ(1, controller.GetEntryCount()); | 4442 EXPECT_EQ(1, controller.GetEntryCount()); |
4426 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4443 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
4427 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4444 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4518 { | 4535 { |
4519 LoadCommittedDetails details; | 4536 LoadCommittedDetails details; |
4520 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); | 4537 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); |
4521 EXPECT_EQ(PAGE_TYPE_ERROR, | 4538 EXPECT_EQ(PAGE_TYPE_ERROR, |
4522 controller_impl().GetLastCommittedEntry()->GetPageType()); | 4539 controller_impl().GetLastCommittedEntry()->GetPageType()); |
4523 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); | 4540 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); |
4524 } | 4541 } |
4525 } | 4542 } |
4526 | 4543 |
4527 } // namespace content | 4544 } // namespace content |
OLD | NEW |