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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 NavigationControllerImpl& controller = controller_impl(); | 270 NavigationControllerImpl& controller = controller_impl(); |
271 TestNotificationTracker notifications; | 271 TestNotificationTracker notifications; |
272 RegisterForAllNavNotifications(¬ifications, &controller); | 272 RegisterForAllNavNotifications(¬ifications, &controller); |
273 | 273 |
274 const int kNumUrls = 5; | 274 const int kNumUrls = 5; |
275 std::vector<GURL> urls(kNumUrls); | 275 std::vector<GURL> urls(kNumUrls); |
276 for (int i = 0; i < kNumUrls; ++i) { | 276 for (int i = 0; i < kNumUrls; ++i) { |
277 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); | 277 urls[i] = GURL(base::StringPrintf("http://www.a.com/%d", i)); |
278 } | 278 } |
279 | 279 |
280 test_rvh()->SendNavigate(0, urls[0]); | 280 main_test_rfh()->SendNavigate(0, urls[0]); |
281 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 281 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
282 navigation_entry_committed_counter_ = 0; | 282 navigation_entry_committed_counter_ = 0; |
283 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); | 283 EXPECT_EQ(urls[0], controller.GetVisibleEntry()->GetVirtualURL()); |
284 EXPECT_FALSE(controller.CanGoBack()); | 284 EXPECT_FALSE(controller.CanGoBack()); |
285 EXPECT_FALSE(controller.CanGoForward()); | 285 EXPECT_FALSE(controller.CanGoForward()); |
286 EXPECT_FALSE(controller.CanGoToOffset(1)); | 286 EXPECT_FALSE(controller.CanGoToOffset(1)); |
287 | 287 |
288 for (int i = 1; i <= 4; ++i) { | 288 for (int i = 1; i <= 4; ++i) { |
289 test_rvh()->SendNavigate(i, urls[i]); | 289 main_test_rfh()->SendNavigate(i, urls[i]); |
290 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 290 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
291 navigation_entry_committed_counter_ = 0; | 291 navigation_entry_committed_counter_ = 0; |
292 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); | 292 EXPECT_EQ(urls[i], controller.GetVisibleEntry()->GetVirtualURL()); |
293 EXPECT_TRUE(controller.CanGoToOffset(-i)); | 293 EXPECT_TRUE(controller.CanGoToOffset(-i)); |
294 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); | 294 EXPECT_FALSE(controller.CanGoToOffset(-(i + 1))); |
295 EXPECT_FALSE(controller.CanGoToOffset(1)); | 295 EXPECT_FALSE(controller.CanGoToOffset(1)); |
296 } | 296 } |
297 | 297 |
298 // We have loaded 5 pages, and are currently at the last-loaded page. | 298 // We have loaded 5 pages, and are currently at the last-loaded page. |
299 int url_index = 4; | 299 int url_index = 4; |
(...skipping 14 matching lines...) Expand all Loading... |
314 GO_TO_BEGINNING, | 314 GO_TO_BEGINNING, |
315 GO_TO_END | 315 GO_TO_END |
316 }; | 316 }; |
317 | 317 |
318 for (int test = 0; test < NUM_TESTS; ++test) { | 318 for (int test = 0; test < NUM_TESTS; ++test) { |
319 int offset = test_offsets[test]; | 319 int offset = test_offsets[test]; |
320 controller.GoToOffset(offset); | 320 controller.GoToOffset(offset); |
321 url_index += offset; | 321 url_index += offset; |
322 // Check that the GoToOffset will land on the expected page. | 322 // Check that the GoToOffset will land on the expected page. |
323 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); | 323 EXPECT_EQ(urls[url_index], controller.GetPendingEntry()->GetVirtualURL()); |
324 test_rvh()->SendNavigate(url_index, urls[url_index]); | 324 main_test_rfh()->SendNavigate(url_index, urls[url_index]); |
325 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 325 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
326 navigation_entry_committed_counter_ = 0; | 326 navigation_entry_committed_counter_ = 0; |
327 // Check that we can go to any valid offset into the history. | 327 // Check that we can go to any valid offset into the history. |
328 for (size_t j = 0; j < urls.size(); ++j) | 328 for (size_t j = 0; j < urls.size(); ++j) |
329 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); | 329 EXPECT_TRUE(controller.CanGoToOffset(j - url_index)); |
330 // Check that we can't go beyond the beginning or end of the history. | 330 // Check that we can't go beyond the beginning or end of the history. |
331 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); | 331 EXPECT_FALSE(controller.CanGoToOffset(-(url_index + 1))); |
332 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); | 332 EXPECT_FALSE(controller.CanGoToOffset(urls.size() - url_index)); |
333 } | 333 } |
334 } | 334 } |
(...skipping 22 matching lines...) Expand all Loading... |
357 EXPECT_FALSE(controller.CanGoForward()); | 357 EXPECT_FALSE(controller.CanGoForward()); |
358 EXPECT_EQ(contents()->GetMaxPageID(), -1); | 358 EXPECT_EQ(contents()->GetMaxPageID(), -1); |
359 | 359 |
360 // Neither the timestamp nor the status code should have been set yet. | 360 // Neither the timestamp nor the status code should have been set yet. |
361 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); | 361 EXPECT_TRUE(controller.GetPendingEntry()->GetTimestamp().is_null()); |
362 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); | 362 EXPECT_EQ(0, controller.GetPendingEntry()->GetHttpStatusCode()); |
363 | 363 |
364 // We should have gotten no notifications from the preceeding checks. | 364 // We should have gotten no notifications from the preceeding checks. |
365 EXPECT_EQ(0U, notifications.size()); | 365 EXPECT_EQ(0U, notifications.size()); |
366 | 366 |
367 test_rvh()->SendNavigate(0, url1); | 367 main_test_rfh()->SendNavigate(0, url1); |
368 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 368 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
369 navigation_entry_committed_counter_ = 0; | 369 navigation_entry_committed_counter_ = 0; |
370 | 370 |
371 // The load should now be committed. | 371 // The load should now be committed. |
372 EXPECT_EQ(controller.GetEntryCount(), 1); | 372 EXPECT_EQ(controller.GetEntryCount(), 1); |
373 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 373 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
374 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 374 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
375 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 375 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
376 EXPECT_FALSE(controller.GetPendingEntry()); | 376 EXPECT_FALSE(controller.GetPendingEntry()); |
377 ASSERT_TRUE(controller.GetVisibleEntry()); | 377 ASSERT_TRUE(controller.GetVisibleEntry()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 438 |
439 // Set the clock to always return a timestamp of 1. | 439 // Set the clock to always return a timestamp of 1. |
440 controller.SetGetTimestampCallbackForTest( | 440 controller.SetGetTimestampCallbackForTest( |
441 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); | 441 base::Bind(&GetFixedTime, base::Time::FromInternalValue(1))); |
442 | 442 |
443 const GURL url1("http://foo1"); | 443 const GURL url1("http://foo1"); |
444 const GURL url2("http://foo2"); | 444 const GURL url2("http://foo2"); |
445 | 445 |
446 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 446 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
447 | 447 |
448 test_rvh()->SendNavigate(0, url1); | 448 main_test_rfh()->SendNavigate(0, url1); |
449 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 449 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
450 navigation_entry_committed_counter_ = 0; | 450 navigation_entry_committed_counter_ = 0; |
451 | 451 |
452 // Load another... | 452 // Load another... |
453 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 453 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
454 | 454 |
455 // Simulate the beforeunload ack for the cross-site transition, and then the | 455 // Simulate the beforeunload ack for the cross-site transition, and then the |
456 // commit. | 456 // commit. |
457 test_rvh()->SendShouldCloseACK(true); | 457 test_rvh()->SendShouldCloseACK(true); |
458 test_rvh()->SendNavigate(1, url2); | 458 main_test_rfh()->SendNavigate(1, url2); |
459 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 459 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
460 navigation_entry_committed_counter_ = 0; | 460 navigation_entry_committed_counter_ = 0; |
461 | 461 |
462 // The two loads should now be committed. | 462 // The two loads should now be committed. |
463 ASSERT_EQ(controller.GetEntryCount(), 2); | 463 ASSERT_EQ(controller.GetEntryCount(), 2); |
464 | 464 |
465 // Timestamps should be distinct despite the clock returning the | 465 // Timestamps should be distinct despite the clock returning the |
466 // same value. | 466 // same value. |
467 EXPECT_EQ(1u, | 467 EXPECT_EQ(1u, |
468 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); | 468 controller.GetEntryAtIndex(0)->GetTimestamp().ToInternalValue()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 // the load commits (because WebCore didn't actually make a new entry). | 571 // the load commits (because WebCore didn't actually make a new entry). |
572 TEST_F(NavigationControllerTest, LoadURL_SamePage) { | 572 TEST_F(NavigationControllerTest, LoadURL_SamePage) { |
573 NavigationControllerImpl& controller = controller_impl(); | 573 NavigationControllerImpl& controller = controller_impl(); |
574 TestNotificationTracker notifications; | 574 TestNotificationTracker notifications; |
575 RegisterForAllNavNotifications(¬ifications, &controller); | 575 RegisterForAllNavNotifications(¬ifications, &controller); |
576 | 576 |
577 const GURL url1("http://foo1"); | 577 const GURL url1("http://foo1"); |
578 | 578 |
579 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 579 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
580 EXPECT_EQ(0U, notifications.size()); | 580 EXPECT_EQ(0U, notifications.size()); |
581 test_rvh()->SendNavigate(0, url1); | 581 main_test_rfh()->SendNavigate(0, url1); |
582 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 582 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
583 navigation_entry_committed_counter_ = 0; | 583 navigation_entry_committed_counter_ = 0; |
584 | 584 |
585 ASSERT_TRUE(controller.GetVisibleEntry()); | 585 ASSERT_TRUE(controller.GetVisibleEntry()); |
586 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 586 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
587 EXPECT_FALSE(timestamp.is_null()); | 587 EXPECT_FALSE(timestamp.is_null()); |
588 | 588 |
589 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 589 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
590 EXPECT_EQ(0U, notifications.size()); | 590 EXPECT_EQ(0U, notifications.size()); |
591 test_rvh()->SendNavigate(0, url1); | 591 main_test_rfh()->SendNavigate(0, url1); |
592 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 592 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
593 navigation_entry_committed_counter_ = 0; | 593 navigation_entry_committed_counter_ = 0; |
594 | 594 |
595 // We should not have produced a new session history entry. | 595 // We should not have produced a new session history entry. |
596 EXPECT_EQ(controller.GetEntryCount(), 1); | 596 EXPECT_EQ(controller.GetEntryCount(), 1); |
597 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 597 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
598 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 598 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
599 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 599 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
600 EXPECT_FALSE(controller.GetPendingEntry()); | 600 EXPECT_FALSE(controller.GetPendingEntry()); |
601 ASSERT_TRUE(controller.GetVisibleEntry()); | 601 ASSERT_TRUE(controller.GetVisibleEntry()); |
(...skipping 10 matching lines...) Expand all Loading... |
612 // Load the same page twice, once as a GET and once as a POST. | 612 // Load the same page twice, once as a GET and once as a POST. |
613 // We should update the post state on the NavigationEntry. | 613 // We should update the post state on the NavigationEntry. |
614 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) { | 614 TEST_F(NavigationControllerTest, LoadURL_SamePage_DifferentMethod) { |
615 NavigationControllerImpl& controller = controller_impl(); | 615 NavigationControllerImpl& controller = controller_impl(); |
616 TestNotificationTracker notifications; | 616 TestNotificationTracker notifications; |
617 RegisterForAllNavNotifications(¬ifications, &controller); | 617 RegisterForAllNavNotifications(¬ifications, &controller); |
618 | 618 |
619 const GURL url1("http://foo1"); | 619 const GURL url1("http://foo1"); |
620 | 620 |
621 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 621 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
622 ViewHostMsg_FrameNavigate_Params params; | 622 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
623 params.page_id = 0; | 623 params.page_id = 0; |
624 params.url = url1; | 624 params.url = url1; |
625 params.transition = PAGE_TRANSITION_TYPED; | 625 params.transition = PAGE_TRANSITION_TYPED; |
626 params.is_post = true; | 626 params.is_post = true; |
627 params.post_id = 123; | 627 params.post_id = 123; |
628 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); | 628 params.page_state = PageState::CreateForTesting(url1, false, 0, 0); |
629 test_rvh()->SendNavigateWithParams(¶ms); | 629 main_test_rfh()->SendNavigateWithParams(¶ms); |
630 | 630 |
631 // The post data should be visible. | 631 // The post data should be visible. |
632 NavigationEntry* entry = controller.GetVisibleEntry(); | 632 NavigationEntry* entry = controller.GetVisibleEntry(); |
633 ASSERT_TRUE(entry); | 633 ASSERT_TRUE(entry); |
634 EXPECT_TRUE(entry->GetHasPostData()); | 634 EXPECT_TRUE(entry->GetHasPostData()); |
635 EXPECT_EQ(entry->GetPostID(), 123); | 635 EXPECT_EQ(entry->GetPostID(), 123); |
636 | 636 |
637 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 637 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
638 test_rvh()->SendNavigate(0, url1); | 638 main_test_rfh()->SendNavigate(0, url1); |
639 | 639 |
640 // We should not have produced a new session history entry. | 640 // We should not have produced a new session history entry. |
641 ASSERT_EQ(controller.GetVisibleEntry(), entry); | 641 ASSERT_EQ(controller.GetVisibleEntry(), entry); |
642 | 642 |
643 // The post data should have been cleared due to the GET. | 643 // The post data should have been cleared due to the GET. |
644 EXPECT_FALSE(entry->GetHasPostData()); | 644 EXPECT_FALSE(entry->GetHasPostData()); |
645 EXPECT_EQ(entry->GetPostID(), 0); | 645 EXPECT_EQ(entry->GetPostID(), 0); |
646 } | 646 } |
647 | 647 |
648 // Tests loading a URL but discarding it before the load commits. | 648 // Tests loading a URL but discarding it before the load commits. |
649 TEST_F(NavigationControllerTest, LoadURL_Discarded) { | 649 TEST_F(NavigationControllerTest, LoadURL_Discarded) { |
650 NavigationControllerImpl& controller = controller_impl(); | 650 NavigationControllerImpl& controller = controller_impl(); |
651 TestNotificationTracker notifications; | 651 TestNotificationTracker notifications; |
652 RegisterForAllNavNotifications(¬ifications, &controller); | 652 RegisterForAllNavNotifications(¬ifications, &controller); |
653 | 653 |
654 const GURL url1("http://foo1"); | 654 const GURL url1("http://foo1"); |
655 const GURL url2("http://foo2"); | 655 const GURL url2("http://foo2"); |
656 | 656 |
657 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 657 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
658 EXPECT_EQ(0U, notifications.size()); | 658 EXPECT_EQ(0U, notifications.size()); |
659 test_rvh()->SendNavigate(0, url1); | 659 main_test_rfh()->SendNavigate(0, url1); |
660 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 660 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
661 navigation_entry_committed_counter_ = 0; | 661 navigation_entry_committed_counter_ = 0; |
662 | 662 |
663 ASSERT_TRUE(controller.GetVisibleEntry()); | 663 ASSERT_TRUE(controller.GetVisibleEntry()); |
664 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 664 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
665 EXPECT_FALSE(timestamp.is_null()); | 665 EXPECT_FALSE(timestamp.is_null()); |
666 | 666 |
667 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 667 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
668 controller.DiscardNonCommittedEntries(); | 668 controller.DiscardNonCommittedEntries(); |
669 EXPECT_EQ(0U, notifications.size()); | 669 EXPECT_EQ(0U, notifications.size()); |
(...skipping 16 matching lines...) Expand all Loading... |
686 // navigates from the web page, and here we test that there is no pending entry. | 686 // navigates from the web page, and here we test that there is no pending entry. |
687 TEST_F(NavigationControllerTest, LoadURL_NoPending) { | 687 TEST_F(NavigationControllerTest, LoadURL_NoPending) { |
688 NavigationControllerImpl& controller = controller_impl(); | 688 NavigationControllerImpl& controller = controller_impl(); |
689 TestNotificationTracker notifications; | 689 TestNotificationTracker notifications; |
690 RegisterForAllNavNotifications(¬ifications, &controller); | 690 RegisterForAllNavNotifications(¬ifications, &controller); |
691 | 691 |
692 // First make an existing committed entry. | 692 // First make an existing committed entry. |
693 const GURL kExistingURL1("http://eh"); | 693 const GURL kExistingURL1("http://eh"); |
694 controller.LoadURL( | 694 controller.LoadURL( |
695 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 695 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
696 test_rvh()->SendNavigate(0, kExistingURL1); | 696 main_test_rfh()->SendNavigate(0, kExistingURL1); |
697 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 697 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
698 navigation_entry_committed_counter_ = 0; | 698 navigation_entry_committed_counter_ = 0; |
699 | 699 |
700 // Do a new navigation without making a pending one. | 700 // Do a new navigation without making a pending one. |
701 const GURL kNewURL("http://see"); | 701 const GURL kNewURL("http://see"); |
702 test_rvh()->SendNavigate(99, kNewURL); | 702 main_test_rfh()->SendNavigate(99, kNewURL); |
703 | 703 |
704 // There should no longer be any pending entry, and the third navigation we | 704 // There should no longer be any pending entry, and the third navigation we |
705 // just made should be committed. | 705 // just made should be committed. |
706 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 706 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
707 navigation_entry_committed_counter_ = 0; | 707 navigation_entry_committed_counter_ = 0; |
708 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 708 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
709 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 709 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
710 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 710 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
711 } | 711 } |
712 | 712 |
713 // Tests navigating to a new URL when there is a new pending navigation that is | 713 // Tests navigating to a new URL when there is a new pending navigation that is |
714 // not the one that just loaded. This will happen if the user types in a URL to | 714 // not the one that just loaded. This will happen if the user types in a URL to |
715 // somewhere slow, and then navigates the current page before the typed URL | 715 // somewhere slow, and then navigates the current page before the typed URL |
716 // commits. | 716 // commits. |
717 TEST_F(NavigationControllerTest, LoadURL_NewPending) { | 717 TEST_F(NavigationControllerTest, LoadURL_NewPending) { |
718 NavigationControllerImpl& controller = controller_impl(); | 718 NavigationControllerImpl& controller = controller_impl(); |
719 TestNotificationTracker notifications; | 719 TestNotificationTracker notifications; |
720 RegisterForAllNavNotifications(¬ifications, &controller); | 720 RegisterForAllNavNotifications(¬ifications, &controller); |
721 | 721 |
722 // First make an existing committed entry. | 722 // First make an existing committed entry. |
723 const GURL kExistingURL1("http://eh"); | 723 const GURL kExistingURL1("http://eh"); |
724 controller.LoadURL( | 724 controller.LoadURL( |
725 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 725 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
726 test_rvh()->SendNavigate(0, kExistingURL1); | 726 main_test_rfh()->SendNavigate(0, kExistingURL1); |
727 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 727 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
728 navigation_entry_committed_counter_ = 0; | 728 navigation_entry_committed_counter_ = 0; |
729 | 729 |
730 // Make a pending entry to somewhere new. | 730 // Make a pending entry to somewhere new. |
731 const GURL kExistingURL2("http://bee"); | 731 const GURL kExistingURL2("http://bee"); |
732 controller.LoadURL( | 732 controller.LoadURL( |
733 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 733 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
734 EXPECT_EQ(0U, notifications.size()); | 734 EXPECT_EQ(0U, notifications.size()); |
735 | 735 |
736 // After the beforeunload but before it commits, do a new navigation. | 736 // After the beforeunload but before it commits, do a new navigation. |
(...skipping 16 matching lines...) Expand all Loading... |
753 // they navigate somewhere new. | 753 // they navigate somewhere new. |
754 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { | 754 TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { |
755 NavigationControllerImpl& controller = controller_impl(); | 755 NavigationControllerImpl& controller = controller_impl(); |
756 TestNotificationTracker notifications; | 756 TestNotificationTracker notifications; |
757 RegisterForAllNavNotifications(¬ifications, &controller); | 757 RegisterForAllNavNotifications(¬ifications, &controller); |
758 | 758 |
759 // First make some history. | 759 // First make some history. |
760 const GURL kExistingURL1("http://foo/eh"); | 760 const GURL kExistingURL1("http://foo/eh"); |
761 controller.LoadURL( | 761 controller.LoadURL( |
762 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 762 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
763 test_rvh()->SendNavigate(0, kExistingURL1); | 763 main_test_rfh()->SendNavigate(0, kExistingURL1); |
764 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 764 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
765 navigation_entry_committed_counter_ = 0; | 765 navigation_entry_committed_counter_ = 0; |
766 | 766 |
767 const GURL kExistingURL2("http://foo/bee"); | 767 const GURL kExistingURL2("http://foo/bee"); |
768 controller.LoadURL( | 768 controller.LoadURL( |
769 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 769 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
770 test_rvh()->SendNavigate(1, kExistingURL2); | 770 main_test_rfh()->SendNavigate(1, kExistingURL2); |
771 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 771 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
772 navigation_entry_committed_counter_ = 0; | 772 navigation_entry_committed_counter_ = 0; |
773 | 773 |
774 // Now make a pending back/forward navigation. The zeroth entry should be | 774 // Now make a pending back/forward navigation. The zeroth entry should be |
775 // pending. | 775 // pending. |
776 controller.GoBack(); | 776 controller.GoBack(); |
777 EXPECT_EQ(0U, notifications.size()); | 777 EXPECT_EQ(0U, notifications.size()); |
778 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 778 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
779 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 779 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
780 | 780 |
781 // Before that commits, do a new navigation. | 781 // Before that commits, do a new navigation. |
782 const GURL kNewURL("http://foo/see"); | 782 const GURL kNewURL("http://foo/see"); |
783 LoadCommittedDetails details; | 783 LoadCommittedDetails details; |
784 test_rvh()->SendNavigate(3, kNewURL); | 784 main_test_rfh()->SendNavigate(3, kNewURL); |
785 | 785 |
786 // There should no longer be any pending entry, and the third navigation we | 786 // There should no longer be any pending entry, and the third navigation we |
787 // just made should be committed. | 787 // just made should be committed. |
788 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 788 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
789 navigation_entry_committed_counter_ = 0; | 789 navigation_entry_committed_counter_ = 0; |
790 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 790 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
791 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 791 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
792 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); | 792 EXPECT_EQ(kNewURL, controller.GetVisibleEntry()->GetURL()); |
793 } | 793 } |
794 | 794 |
795 // Tests navigating to a new URL when there is a pending back/forward | 795 // Tests navigating to a new URL when there is a pending back/forward |
796 // navigation to a cross-process, privileged URL. This will happen if the user | 796 // navigation to a cross-process, privileged URL. This will happen if the user |
797 // hits back, but before that commits, they navigate somewhere new. | 797 // hits back, but before that commits, they navigate somewhere new. |
798 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { | 798 TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { |
799 NavigationControllerImpl& controller = controller_impl(); | 799 NavigationControllerImpl& controller = controller_impl(); |
800 TestNotificationTracker notifications; | 800 TestNotificationTracker notifications; |
801 RegisterForAllNavNotifications(¬ifications, &controller); | 801 RegisterForAllNavNotifications(¬ifications, &controller); |
802 | 802 |
803 // First make some history, starting with a privileged URL. | 803 // First make some history, starting with a privileged URL. |
804 const GURL kExistingURL1("http://privileged"); | 804 const GURL kExistingURL1("http://privileged"); |
805 controller.LoadURL( | 805 controller.LoadURL( |
806 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 806 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
807 // Pretend it has bindings so we can tell if we incorrectly copy it. | 807 // Pretend it has bindings so we can tell if we incorrectly copy it. |
808 test_rvh()->AllowBindings(2); | 808 test_rvh()->AllowBindings(2); |
809 test_rvh()->SendNavigate(0, kExistingURL1); | 809 main_test_rfh()->SendNavigate(0, kExistingURL1); |
810 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 810 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
811 navigation_entry_committed_counter_ = 0; | 811 navigation_entry_committed_counter_ = 0; |
812 | 812 |
813 // Navigate cross-process to a second URL. | 813 // Navigate cross-process to a second URL. |
814 const GURL kExistingURL2("http://foo/eh"); | 814 const GURL kExistingURL2("http://foo/eh"); |
815 controller.LoadURL( | 815 controller.LoadURL( |
816 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 816 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
817 test_rvh()->SendShouldCloseACK(true); | 817 test_rvh()->SendShouldCloseACK(true); |
818 TestRenderViewHost* foo_rvh = static_cast<TestRenderViewHost*>( | 818 TestRenderViewHost* foo_rvh = static_cast<TestRenderViewHost*>( |
819 contents()->GetPendingRenderViewHost()); | 819 contents()->GetPendingRenderViewHost()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 // current page fires history.back(). | 852 // current page fires history.back(). |
853 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { | 853 TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { |
854 NavigationControllerImpl& controller = controller_impl(); | 854 NavigationControllerImpl& controller = controller_impl(); |
855 TestNotificationTracker notifications; | 855 TestNotificationTracker notifications; |
856 RegisterForAllNavNotifications(¬ifications, &controller); | 856 RegisterForAllNavNotifications(¬ifications, &controller); |
857 | 857 |
858 // First make some history. | 858 // First make some history. |
859 const GURL kExistingURL1("http://foo/eh"); | 859 const GURL kExistingURL1("http://foo/eh"); |
860 controller.LoadURL( | 860 controller.LoadURL( |
861 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 861 kExistingURL1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
862 test_rvh()->SendNavigate(0, kExistingURL1); | 862 main_test_rfh()->SendNavigate(0, kExistingURL1); |
863 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 863 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
864 navigation_entry_committed_counter_ = 0; | 864 navigation_entry_committed_counter_ = 0; |
865 | 865 |
866 const GURL kExistingURL2("http://foo/bee"); | 866 const GURL kExistingURL2("http://foo/bee"); |
867 controller.LoadURL( | 867 controller.LoadURL( |
868 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 868 kExistingURL2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
869 test_rvh()->SendNavigate(1, kExistingURL2); | 869 main_test_rfh()->SendNavigate(1, kExistingURL2); |
870 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 870 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
871 navigation_entry_committed_counter_ = 0; | 871 navigation_entry_committed_counter_ = 0; |
872 | 872 |
873 // Now make a pending new navigation. | 873 // Now make a pending new navigation. |
874 const GURL kNewURL("http://foo/see"); | 874 const GURL kNewURL("http://foo/see"); |
875 controller.LoadURL( | 875 controller.LoadURL( |
876 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 876 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
877 EXPECT_EQ(0U, notifications.size()); | 877 EXPECT_EQ(0U, notifications.size()); |
878 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 878 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
879 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 879 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
880 | 880 |
881 // Before that commits, a back navigation from the renderer commits. | 881 // Before that commits, a back navigation from the renderer commits. |
882 test_rvh()->SendNavigate(0, kExistingURL1); | 882 main_test_rfh()->SendNavigate(0, kExistingURL1); |
883 | 883 |
884 // There should no longer be any pending entry, and the back navigation we | 884 // There should no longer be any pending entry, and the back navigation we |
885 // just made should be committed. | 885 // just made should be committed. |
886 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 886 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
887 navigation_entry_committed_counter_ = 0; | 887 navigation_entry_committed_counter_ = 0; |
888 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 888 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
889 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 889 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
890 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); | 890 EXPECT_EQ(kExistingURL1, controller.GetVisibleEntry()->GetURL()); |
891 } | 891 } |
892 | 892 |
(...skipping 18 matching lines...) Expand all Loading... |
911 controller.LoadURL( | 911 controller.LoadURL( |
912 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 912 kNewURL, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
913 EXPECT_EQ(0U, notifications.size()); | 913 EXPECT_EQ(0U, notifications.size()); |
914 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 914 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
915 EXPECT_TRUE(controller.GetPendingEntry()); | 915 EXPECT_TRUE(controller.GetPendingEntry()); |
916 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 916 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
917 EXPECT_EQ(1, delegate->navigation_state_change_count()); | 917 EXPECT_EQ(1, delegate->navigation_state_change_count()); |
918 | 918 |
919 // Before that commits, a document.write and location.reload can cause the | 919 // Before that commits, a document.write and location.reload can cause the |
920 // renderer to send a FrameNavigate with page_id -1. | 920 // renderer to send a FrameNavigate with page_id -1. |
921 test_rvh()->SendNavigate(-1, kExistingURL); | 921 main_test_rfh()->SendNavigate(-1, kExistingURL); |
922 | 922 |
923 // This should clear the pending entry and notify of a navigation state | 923 // This should clear the pending entry and notify of a navigation state |
924 // change, so that we do not keep displaying kNewURL. | 924 // change, so that we do not keep displaying kNewURL. |
925 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 925 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
926 EXPECT_FALSE(controller.GetPendingEntry()); | 926 EXPECT_FALSE(controller.GetPendingEntry()); |
927 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); | 927 EXPECT_EQ(-1, controller.GetLastCommittedEntryIndex()); |
928 EXPECT_EQ(2, delegate->navigation_state_change_count()); | 928 EXPECT_EQ(2, delegate->navigation_state_change_count()); |
929 | 929 |
930 contents()->SetDelegate(NULL); | 930 contents()->SetDelegate(NULL); |
931 } | 931 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 // redirect and abort. See http://crbug.com/83031. | 988 // redirect and abort. See http://crbug.com/83031. |
989 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { | 989 TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { |
990 NavigationControllerImpl& controller = controller_impl(); | 990 NavigationControllerImpl& controller = controller_impl(); |
991 TestNotificationTracker notifications; | 991 TestNotificationTracker notifications; |
992 RegisterForAllNavNotifications(¬ifications, &controller); | 992 RegisterForAllNavNotifications(¬ifications, &controller); |
993 | 993 |
994 // First make an existing committed entry. | 994 // First make an existing committed entry. |
995 const GURL kExistingURL("http://foo/eh"); | 995 const GURL kExistingURL("http://foo/eh"); |
996 controller.LoadURL(kExistingURL, content::Referrer(), | 996 controller.LoadURL(kExistingURL, content::Referrer(), |
997 content::PAGE_TRANSITION_TYPED, std::string()); | 997 content::PAGE_TRANSITION_TYPED, std::string()); |
998 test_rvh()->SendNavigate(0, kExistingURL); | 998 main_test_rfh()->SendNavigate(0, kExistingURL); |
999 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 999 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1000 navigation_entry_committed_counter_ = 0; | 1000 navigation_entry_committed_counter_ = 0; |
1001 | 1001 |
1002 // Set a WebContentsDelegate to listen for state changes. | 1002 // Set a WebContentsDelegate to listen for state changes. |
1003 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); | 1003 scoped_ptr<TestWebContentsDelegate> delegate(new TestWebContentsDelegate()); |
1004 EXPECT_FALSE(contents()->GetDelegate()); | 1004 EXPECT_FALSE(contents()->GetDelegate()); |
1005 contents()->SetDelegate(delegate.get()); | 1005 contents()->SetDelegate(delegate.get()); |
1006 | 1006 |
1007 // Now make a pending new navigation, initiated by the renderer. | 1007 // Now make a pending new navigation, initiated by the renderer. |
1008 const GURL kNewURL("http://foo/bee"); | 1008 const GURL kNewURL("http://foo/bee"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 | 1115 |
1116 TEST_F(NavigationControllerTest, Reload) { | 1116 TEST_F(NavigationControllerTest, Reload) { |
1117 NavigationControllerImpl& controller = controller_impl(); | 1117 NavigationControllerImpl& controller = controller_impl(); |
1118 TestNotificationTracker notifications; | 1118 TestNotificationTracker notifications; |
1119 RegisterForAllNavNotifications(¬ifications, &controller); | 1119 RegisterForAllNavNotifications(¬ifications, &controller); |
1120 | 1120 |
1121 const GURL url1("http://foo1"); | 1121 const GURL url1("http://foo1"); |
1122 | 1122 |
1123 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1123 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1124 EXPECT_EQ(0U, notifications.size()); | 1124 EXPECT_EQ(0U, notifications.size()); |
1125 test_rvh()->SendNavigate(0, url1); | 1125 main_test_rfh()->SendNavigate(0, url1); |
1126 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1126 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1127 navigation_entry_committed_counter_ = 0; | 1127 navigation_entry_committed_counter_ = 0; |
1128 ASSERT_TRUE(controller.GetVisibleEntry()); | 1128 ASSERT_TRUE(controller.GetVisibleEntry()); |
1129 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); | 1129 controller.GetVisibleEntry()->SetTitle(base::ASCIIToUTF16("Title")); |
1130 controller.Reload(true); | 1130 controller.Reload(true); |
1131 EXPECT_EQ(0U, notifications.size()); | 1131 EXPECT_EQ(0U, notifications.size()); |
1132 | 1132 |
1133 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); | 1133 const base::Time timestamp = controller.GetVisibleEntry()->GetTimestamp(); |
1134 EXPECT_FALSE(timestamp.is_null()); | 1134 EXPECT_FALSE(timestamp.is_null()); |
1135 | 1135 |
1136 // The reload is pending. | 1136 // The reload is pending. |
1137 EXPECT_EQ(controller.GetEntryCount(), 1); | 1137 EXPECT_EQ(controller.GetEntryCount(), 1); |
1138 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1138 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1139 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1139 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1140 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1140 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1141 EXPECT_TRUE(controller.GetPendingEntry()); | 1141 EXPECT_TRUE(controller.GetPendingEntry()); |
1142 EXPECT_FALSE(controller.CanGoBack()); | 1142 EXPECT_FALSE(controller.CanGoBack()); |
1143 EXPECT_FALSE(controller.CanGoForward()); | 1143 EXPECT_FALSE(controller.CanGoForward()); |
1144 // Make sure the title has been cleared (will be redrawn just after reload). | 1144 // Make sure the title has been cleared (will be redrawn just after reload). |
1145 // Avoids a stale cached title when the new page being reloaded has no title. | 1145 // Avoids a stale cached title when the new page being reloaded has no title. |
1146 // See http://crbug.com/96041. | 1146 // See http://crbug.com/96041. |
1147 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1147 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
1148 | 1148 |
1149 test_rvh()->SendNavigate(0, url1); | 1149 main_test_rfh()->SendNavigate(0, url1); |
1150 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1150 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1151 navigation_entry_committed_counter_ = 0; | 1151 navigation_entry_committed_counter_ = 0; |
1152 | 1152 |
1153 // Now the reload is committed. | 1153 // Now the reload is committed. |
1154 EXPECT_EQ(controller.GetEntryCount(), 1); | 1154 EXPECT_EQ(controller.GetEntryCount(), 1); |
1155 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1155 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1156 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1156 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1157 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1157 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1158 EXPECT_FALSE(controller.GetPendingEntry()); | 1158 EXPECT_FALSE(controller.GetPendingEntry()); |
1159 EXPECT_FALSE(controller.CanGoBack()); | 1159 EXPECT_FALSE(controller.CanGoBack()); |
1160 EXPECT_FALSE(controller.CanGoForward()); | 1160 EXPECT_FALSE(controller.CanGoForward()); |
1161 | 1161 |
1162 // The timestamp should have been updated. | 1162 // The timestamp should have been updated. |
1163 ASSERT_TRUE(controller.GetVisibleEntry()); | 1163 ASSERT_TRUE(controller.GetVisibleEntry()); |
1164 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); | 1164 EXPECT_GE(controller.GetVisibleEntry()->GetTimestamp(), timestamp); |
1165 } | 1165 } |
1166 | 1166 |
1167 // Tests what happens when a reload navigation produces a new page. | 1167 // Tests what happens when a reload navigation produces a new page. |
1168 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { | 1168 TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { |
1169 NavigationControllerImpl& controller = controller_impl(); | 1169 NavigationControllerImpl& controller = controller_impl(); |
1170 TestNotificationTracker notifications; | 1170 TestNotificationTracker notifications; |
1171 RegisterForAllNavNotifications(¬ifications, &controller); | 1171 RegisterForAllNavNotifications(¬ifications, &controller); |
1172 | 1172 |
1173 const GURL url1("http://foo1"); | 1173 const GURL url1("http://foo1"); |
1174 const GURL url2("http://foo2"); | 1174 const GURL url2("http://foo2"); |
1175 | 1175 |
1176 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1176 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1177 test_rvh()->SendNavigate(0, url1); | 1177 main_test_rfh()->SendNavigate(0, url1); |
1178 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1178 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1179 navigation_entry_committed_counter_ = 0; | 1179 navigation_entry_committed_counter_ = 0; |
1180 | 1180 |
1181 controller.Reload(true); | 1181 controller.Reload(true); |
1182 EXPECT_EQ(0U, notifications.size()); | 1182 EXPECT_EQ(0U, notifications.size()); |
1183 | 1183 |
1184 test_rvh()->SendNavigate(1, url2); | 1184 main_test_rfh()->SendNavigate(1, url2); |
1185 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1185 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1186 navigation_entry_committed_counter_ = 0; | 1186 navigation_entry_committed_counter_ = 0; |
1187 | 1187 |
1188 // Now the reload is committed. | 1188 // Now the reload is committed. |
1189 EXPECT_EQ(controller.GetEntryCount(), 2); | 1189 EXPECT_EQ(controller.GetEntryCount(), 2); |
1190 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1190 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1191 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1191 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1192 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1192 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1193 EXPECT_FALSE(controller.GetPendingEntry()); | 1193 EXPECT_FALSE(controller.GetPendingEntry()); |
1194 EXPECT_TRUE(controller.CanGoBack()); | 1194 EXPECT_TRUE(controller.CanGoBack()); |
1195 EXPECT_FALSE(controller.CanGoForward()); | 1195 EXPECT_FALSE(controller.CanGoForward()); |
1196 } | 1196 } |
1197 | 1197 |
1198 // This test ensures that when a guest renderer reloads, the reload goes through | 1198 // This test ensures that when a guest renderer reloads, the reload goes through |
1199 // without ending up in the "we have a wrong process for the URL" branch in | 1199 // without ending up in the "we have a wrong process for the URL" branch in |
1200 // NavigationControllerImpl::ReloadInternal. | 1200 // NavigationControllerImpl::ReloadInternal. |
1201 TEST_F(NavigationControllerTest, ReloadWithGuest) { | 1201 TEST_F(NavigationControllerTest, ReloadWithGuest) { |
1202 NavigationControllerImpl& controller = controller_impl(); | 1202 NavigationControllerImpl& controller = controller_impl(); |
1203 | 1203 |
1204 const GURL url1("http://foo1"); | 1204 const GURL url1("http://foo1"); |
1205 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1205 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1206 test_rvh()->SendNavigate(0, url1); | 1206 main_test_rfh()->SendNavigate(0, url1); |
1207 ASSERT_TRUE(controller.GetVisibleEntry()); | 1207 ASSERT_TRUE(controller.GetVisibleEntry()); |
1208 | 1208 |
1209 // Make the entry believe its RenderProcessHost is a guest. | 1209 // Make the entry believe its RenderProcessHost is a guest. |
1210 NavigationEntryImpl* entry1 = | 1210 NavigationEntryImpl* entry1 = |
1211 NavigationEntryImpl::FromNavigationEntry(controller.GetVisibleEntry()); | 1211 NavigationEntryImpl::FromNavigationEntry(controller.GetVisibleEntry()); |
1212 reinterpret_cast<MockRenderProcessHost*>( | 1212 reinterpret_cast<MockRenderProcessHost*>( |
1213 entry1->site_instance()->GetProcess())->SetIsGuest(true); | 1213 entry1->site_instance()->GetProcess())->SetIsGuest(true); |
1214 | 1214 |
1215 // And reload. | 1215 // And reload. |
1216 controller.Reload(true); | 1216 controller.Reload(true); |
(...skipping 15 matching lines...) Expand all Loading... |
1232 TestNotificationTracker notifications; | 1232 TestNotificationTracker notifications; |
1233 RegisterForAllNavNotifications(¬ifications, &controller); | 1233 RegisterForAllNavNotifications(¬ifications, &controller); |
1234 | 1234 |
1235 const GURL original_url("http://foo1"); | 1235 const GURL original_url("http://foo1"); |
1236 const GURL final_url("http://foo2"); | 1236 const GURL final_url("http://foo2"); |
1237 | 1237 |
1238 // Load up the original URL, but get redirected. | 1238 // Load up the original URL, but get redirected. |
1239 controller.LoadURL( | 1239 controller.LoadURL( |
1240 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1240 original_url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1241 EXPECT_EQ(0U, notifications.size()); | 1241 EXPECT_EQ(0U, notifications.size()); |
1242 test_rvh()->SendNavigateWithOriginalRequestURL(0, final_url, original_url); | 1242 main_test_rfh()->SendNavigateWithOriginalRequestURL( |
| 1243 0, final_url, original_url); |
1243 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1244 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1244 navigation_entry_committed_counter_ = 0; | 1245 navigation_entry_committed_counter_ = 0; |
1245 | 1246 |
1246 // The NavigationEntry should save both the original URL and the final | 1247 // The NavigationEntry should save both the original URL and the final |
1247 // redirected URL. | 1248 // redirected URL. |
1248 EXPECT_EQ( | 1249 EXPECT_EQ( |
1249 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); | 1250 original_url, controller.GetVisibleEntry()->GetOriginalRequestURL()); |
1250 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); | 1251 EXPECT_EQ(final_url, controller.GetVisibleEntry()->GetURL()); |
1251 | 1252 |
1252 // Reload using the original URL. | 1253 // Reload using the original URL. |
(...skipping 10 matching lines...) Expand all Loading... |
1263 EXPECT_TRUE(controller.GetPendingEntry()); | 1264 EXPECT_TRUE(controller.GetPendingEntry()); |
1264 EXPECT_FALSE(controller.CanGoBack()); | 1265 EXPECT_FALSE(controller.CanGoBack()); |
1265 EXPECT_FALSE(controller.CanGoForward()); | 1266 EXPECT_FALSE(controller.CanGoForward()); |
1266 | 1267 |
1267 // Make sure the title has been cleared (will be redrawn just after reload). | 1268 // Make sure the title has been cleared (will be redrawn just after reload). |
1268 // Avoids a stale cached title when the new page being reloaded has no title. | 1269 // Avoids a stale cached title when the new page being reloaded has no title. |
1269 // See http://crbug.com/96041. | 1270 // See http://crbug.com/96041. |
1270 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); | 1271 EXPECT_TRUE(controller.GetVisibleEntry()->GetTitle().empty()); |
1271 | 1272 |
1272 // Send that the navigation has proceeded; say it got redirected again. | 1273 // Send that the navigation has proceeded; say it got redirected again. |
1273 test_rvh()->SendNavigate(0, final_url); | 1274 main_test_rfh()->SendNavigate(0, final_url); |
1274 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1275 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1275 navigation_entry_committed_counter_ = 0; | 1276 navigation_entry_committed_counter_ = 0; |
1276 | 1277 |
1277 // Now the reload is committed. | 1278 // Now the reload is committed. |
1278 EXPECT_EQ(controller.GetEntryCount(), 1); | 1279 EXPECT_EQ(controller.GetEntryCount(), 1); |
1279 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1280 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1280 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1281 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1281 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1282 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1282 EXPECT_FALSE(controller.GetPendingEntry()); | 1283 EXPECT_FALSE(controller.GetPendingEntry()); |
1283 EXPECT_FALSE(controller.CanGoBack()); | 1284 EXPECT_FALSE(controller.CanGoBack()); |
(...skipping 29 matching lines...) Expand all Loading... |
1313 pending_entry->set_should_replace_entry(true); | 1314 pending_entry->set_should_replace_entry(true); |
1314 pending_entry->set_redirect_chain(redirects); | 1315 pending_entry->set_redirect_chain(redirects); |
1315 pending_entry->set_should_clear_history_list(true); | 1316 pending_entry->set_should_clear_history_list(true); |
1316 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); | 1317 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); |
1317 EXPECT_TRUE(pending_entry->is_renderer_initiated()); | 1318 EXPECT_TRUE(pending_entry->is_renderer_initiated()); |
1318 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); | 1319 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); |
1319 EXPECT_TRUE(pending_entry->should_replace_entry()); | 1320 EXPECT_TRUE(pending_entry->should_replace_entry()); |
1320 EXPECT_EQ(1U, pending_entry->redirect_chain().size()); | 1321 EXPECT_EQ(1U, pending_entry->redirect_chain().size()); |
1321 EXPECT_TRUE(pending_entry->should_clear_history_list()); | 1322 EXPECT_TRUE(pending_entry->should_clear_history_list()); |
1322 | 1323 |
1323 test_rvh()->SendNavigate(0, url1); | 1324 main_test_rfh()->SendNavigate(0, url1); |
1324 | 1325 |
1325 // Certain values that are only used for pending entries get reset after | 1326 // Certain values that are only used for pending entries get reset after |
1326 // commit. | 1327 // commit. |
1327 NavigationEntryImpl* committed_entry = | 1328 NavigationEntryImpl* committed_entry = |
1328 NavigationEntryImpl::FromNavigationEntry( | 1329 NavigationEntryImpl::FromNavigationEntry( |
1329 controller.GetLastCommittedEntry()); | 1330 controller.GetLastCommittedEntry()); |
1330 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); | 1331 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); |
1331 EXPECT_FALSE(committed_entry->is_renderer_initiated()); | 1332 EXPECT_FALSE(committed_entry->is_renderer_initiated()); |
1332 EXPECT_EQ(GlobalRequestID(-1, -1), | 1333 EXPECT_EQ(GlobalRequestID(-1, -1), |
1333 committed_entry->transferred_global_request_id()); | 1334 committed_entry->transferred_global_request_id()); |
1334 EXPECT_FALSE(committed_entry->should_replace_entry()); | 1335 EXPECT_FALSE(committed_entry->should_replace_entry()); |
1335 EXPECT_EQ(0U, committed_entry->redirect_chain().size()); | 1336 EXPECT_EQ(0U, committed_entry->redirect_chain().size()); |
1336 EXPECT_FALSE(committed_entry->should_clear_history_list()); | 1337 EXPECT_FALSE(committed_entry->should_clear_history_list()); |
1337 } | 1338 } |
1338 | 1339 |
1339 // Tests what happens when we navigate back successfully | 1340 // Tests what happens when we navigate back successfully |
1340 TEST_F(NavigationControllerTest, Back) { | 1341 TEST_F(NavigationControllerTest, Back) { |
1341 NavigationControllerImpl& controller = controller_impl(); | 1342 NavigationControllerImpl& controller = controller_impl(); |
1342 TestNotificationTracker notifications; | 1343 TestNotificationTracker notifications; |
1343 RegisterForAllNavNotifications(¬ifications, &controller); | 1344 RegisterForAllNavNotifications(¬ifications, &controller); |
1344 | 1345 |
1345 const GURL url1("http://foo1"); | 1346 const GURL url1("http://foo1"); |
1346 test_rvh()->SendNavigate(0, url1); | 1347 main_test_rfh()->SendNavigate(0, url1); |
1347 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1348 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1348 navigation_entry_committed_counter_ = 0; | 1349 navigation_entry_committed_counter_ = 0; |
1349 | 1350 |
1350 const GURL url2("http://foo2"); | 1351 const GURL url2("http://foo2"); |
1351 test_rvh()->SendNavigate(1, url2); | 1352 main_test_rfh()->SendNavigate(1, url2); |
1352 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1353 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1353 navigation_entry_committed_counter_ = 0; | 1354 navigation_entry_committed_counter_ = 0; |
1354 | 1355 |
1355 controller.GoBack(); | 1356 controller.GoBack(); |
1356 EXPECT_EQ(0U, notifications.size()); | 1357 EXPECT_EQ(0U, notifications.size()); |
1357 | 1358 |
1358 // We should now have a pending navigation to go back. | 1359 // We should now have a pending navigation to go back. |
1359 EXPECT_EQ(controller.GetEntryCount(), 2); | 1360 EXPECT_EQ(controller.GetEntryCount(), 2); |
1360 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1361 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1361 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1362 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1362 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1363 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1363 EXPECT_TRUE(controller.GetPendingEntry()); | 1364 EXPECT_TRUE(controller.GetPendingEntry()); |
1364 EXPECT_FALSE(controller.CanGoBack()); | 1365 EXPECT_FALSE(controller.CanGoBack()); |
1365 EXPECT_FALSE(controller.CanGoToOffset(-1)); | 1366 EXPECT_FALSE(controller.CanGoToOffset(-1)); |
1366 EXPECT_TRUE(controller.CanGoForward()); | 1367 EXPECT_TRUE(controller.CanGoForward()); |
1367 EXPECT_TRUE(controller.CanGoToOffset(1)); | 1368 EXPECT_TRUE(controller.CanGoToOffset(1)); |
1368 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps. | 1369 EXPECT_FALSE(controller.CanGoToOffset(2)); // Cannot go foward 2 steps. |
1369 | 1370 |
1370 // Timestamp for entry 1 should be on or after that of entry 0. | 1371 // Timestamp for entry 1 should be on or after that of entry 0. |
1371 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1372 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1372 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), | 1373 EXPECT_GE(controller.GetEntryAtIndex(1)->GetTimestamp(), |
1373 controller.GetEntryAtIndex(0)->GetTimestamp()); | 1374 controller.GetEntryAtIndex(0)->GetTimestamp()); |
1374 | 1375 |
1375 test_rvh()->SendNavigate(0, url2); | 1376 main_test_rfh()->SendNavigate(0, url2); |
1376 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1377 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1377 navigation_entry_committed_counter_ = 0; | 1378 navigation_entry_committed_counter_ = 0; |
1378 | 1379 |
1379 // The back navigation completed successfully. | 1380 // The back navigation completed successfully. |
1380 EXPECT_EQ(controller.GetEntryCount(), 2); | 1381 EXPECT_EQ(controller.GetEntryCount(), 2); |
1381 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1382 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1382 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1383 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1383 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1384 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1384 EXPECT_FALSE(controller.GetPendingEntry()); | 1385 EXPECT_FALSE(controller.GetPendingEntry()); |
1385 EXPECT_FALSE(controller.CanGoBack()); | 1386 EXPECT_FALSE(controller.CanGoBack()); |
(...skipping 13 matching lines...) Expand all Loading... |
1399 NavigationControllerImpl& controller = controller_impl(); | 1400 NavigationControllerImpl& controller = controller_impl(); |
1400 TestNotificationTracker notifications; | 1401 TestNotificationTracker notifications; |
1401 RegisterForAllNavNotifications(¬ifications, &controller); | 1402 RegisterForAllNavNotifications(¬ifications, &controller); |
1402 | 1403 |
1403 const GURL url1("http://foo/1"); | 1404 const GURL url1("http://foo/1"); |
1404 const GURL url2("http://foo/2"); | 1405 const GURL url2("http://foo/2"); |
1405 const GURL url3("http://foo/3"); | 1406 const GURL url3("http://foo/3"); |
1406 | 1407 |
1407 controller.LoadURL( | 1408 controller.LoadURL( |
1408 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1409 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1409 test_rvh()->SendNavigate(0, url1); | 1410 main_test_rfh()->SendNavigate(0, url1); |
1410 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1411 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1411 navigation_entry_committed_counter_ = 0; | 1412 navigation_entry_committed_counter_ = 0; |
1412 | 1413 |
1413 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1414 controller.LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1414 test_rvh()->SendNavigate(1, url2); | 1415 main_test_rfh()->SendNavigate(1, url2); |
1415 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1416 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1416 navigation_entry_committed_counter_ = 0; | 1417 navigation_entry_committed_counter_ = 0; |
1417 | 1418 |
1418 controller.GoBack(); | 1419 controller.GoBack(); |
1419 EXPECT_EQ(0U, notifications.size()); | 1420 EXPECT_EQ(0U, notifications.size()); |
1420 | 1421 |
1421 // We should now have a pending navigation to go back. | 1422 // We should now have a pending navigation to go back. |
1422 EXPECT_EQ(controller.GetEntryCount(), 2); | 1423 EXPECT_EQ(controller.GetEntryCount(), 2); |
1423 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1424 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1424 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); | 1425 EXPECT_EQ(controller.GetPendingEntryIndex(), 0); |
1425 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1426 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1426 EXPECT_TRUE(controller.GetPendingEntry()); | 1427 EXPECT_TRUE(controller.GetPendingEntry()); |
1427 EXPECT_FALSE(controller.CanGoBack()); | 1428 EXPECT_FALSE(controller.CanGoBack()); |
1428 EXPECT_TRUE(controller.CanGoForward()); | 1429 EXPECT_TRUE(controller.CanGoForward()); |
1429 | 1430 |
1430 test_rvh()->SendNavigate(2, url3); | 1431 main_test_rfh()->SendNavigate(2, url3); |
1431 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1432 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1432 navigation_entry_committed_counter_ = 0; | 1433 navigation_entry_committed_counter_ = 0; |
1433 | 1434 |
1434 // The back navigation resulted in a completely new navigation. | 1435 // The back navigation resulted in a completely new navigation. |
1435 // TODO(darin): perhaps this behavior will be confusing to users? | 1436 // TODO(darin): perhaps this behavior will be confusing to users? |
1436 EXPECT_EQ(controller.GetEntryCount(), 3); | 1437 EXPECT_EQ(controller.GetEntryCount(), 3); |
1437 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); | 1438 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 2); |
1438 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1439 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1439 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1440 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1440 EXPECT_FALSE(controller.GetPendingEntry()); | 1441 EXPECT_FALSE(controller.GetPendingEntry()); |
1441 EXPECT_TRUE(controller.CanGoBack()); | 1442 EXPECT_TRUE(controller.CanGoBack()); |
1442 EXPECT_FALSE(controller.CanGoForward()); | 1443 EXPECT_FALSE(controller.CanGoForward()); |
1443 } | 1444 } |
1444 | 1445 |
1445 // Receives a back message when there is a new pending navigation entry. | 1446 // Receives a back message when there is a new pending navigation entry. |
1446 TEST_F(NavigationControllerTest, Back_NewPending) { | 1447 TEST_F(NavigationControllerTest, Back_NewPending) { |
1447 NavigationControllerImpl& controller = controller_impl(); | 1448 NavigationControllerImpl& controller = controller_impl(); |
1448 TestNotificationTracker notifications; | 1449 TestNotificationTracker notifications; |
1449 RegisterForAllNavNotifications(¬ifications, &controller); | 1450 RegisterForAllNavNotifications(¬ifications, &controller); |
1450 | 1451 |
1451 const GURL kUrl1("http://foo1"); | 1452 const GURL kUrl1("http://foo1"); |
1452 const GURL kUrl2("http://foo2"); | 1453 const GURL kUrl2("http://foo2"); |
1453 const GURL kUrl3("http://foo3"); | 1454 const GURL kUrl3("http://foo3"); |
1454 | 1455 |
1455 // First navigate two places so we have some back history. | 1456 // First navigate two places so we have some back history. |
1456 test_rvh()->SendNavigate(0, kUrl1); | 1457 main_test_rfh()->SendNavigate(0, kUrl1); |
1457 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1458 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1458 navigation_entry_committed_counter_ = 0; | 1459 navigation_entry_committed_counter_ = 0; |
1459 | 1460 |
1460 // controller.LoadURL(kUrl2, PAGE_TRANSITION_TYPED); | 1461 // controller.LoadURL(kUrl2, PAGE_TRANSITION_TYPED); |
1461 test_rvh()->SendNavigate(1, kUrl2); | 1462 main_test_rfh()->SendNavigate(1, kUrl2); |
1462 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1463 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1463 navigation_entry_committed_counter_ = 0; | 1464 navigation_entry_committed_counter_ = 0; |
1464 | 1465 |
1465 // Now start a new pending navigation and go back before it commits. | 1466 // Now start a new pending navigation and go back before it commits. |
1466 controller.LoadURL(kUrl3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1467 controller.LoadURL(kUrl3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1467 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1468 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1468 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); | 1469 EXPECT_EQ(kUrl3, controller.GetPendingEntry()->GetURL()); |
1469 controller.GoBack(); | 1470 controller.GoBack(); |
1470 | 1471 |
1471 // The pending navigation should now be the "back" item and the new one | 1472 // The pending navigation should now be the "back" item and the new one |
1472 // should be gone. | 1473 // should be gone. |
1473 EXPECT_EQ(0, controller.GetPendingEntryIndex()); | 1474 EXPECT_EQ(0, controller.GetPendingEntryIndex()); |
1474 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); | 1475 EXPECT_EQ(kUrl1, controller.GetPendingEntry()->GetURL()); |
1475 } | 1476 } |
1476 | 1477 |
1477 // Receives a back message when there is a different renavigation already | 1478 // Receives a back message when there is a different renavigation already |
1478 // pending. | 1479 // pending. |
1479 TEST_F(NavigationControllerTest, Back_OtherBackPending) { | 1480 TEST_F(NavigationControllerTest, Back_OtherBackPending) { |
1480 NavigationControllerImpl& controller = controller_impl(); | 1481 NavigationControllerImpl& controller = controller_impl(); |
1481 const GURL kUrl1("http://foo/1"); | 1482 const GURL kUrl1("http://foo/1"); |
1482 const GURL kUrl2("http://foo/2"); | 1483 const GURL kUrl2("http://foo/2"); |
1483 const GURL kUrl3("http://foo/3"); | 1484 const GURL kUrl3("http://foo/3"); |
1484 | 1485 |
1485 // First navigate three places so we have some back history. | 1486 // First navigate three places so we have some back history. |
1486 test_rvh()->SendNavigate(0, kUrl1); | 1487 main_test_rfh()->SendNavigate(0, kUrl1); |
1487 test_rvh()->SendNavigate(1, kUrl2); | 1488 main_test_rfh()->SendNavigate(1, kUrl2); |
1488 test_rvh()->SendNavigate(2, kUrl3); | 1489 main_test_rfh()->SendNavigate(2, kUrl3); |
1489 | 1490 |
1490 // With nothing pending, say we get a navigation to the second entry. | 1491 // With nothing pending, say we get a navigation to the second entry. |
1491 test_rvh()->SendNavigate(1, kUrl2); | 1492 main_test_rfh()->SendNavigate(1, kUrl2); |
1492 | 1493 |
1493 // We know all the entries have the same site instance, so we can just grab | 1494 // We know all the entries have the same site instance, so we can just grab |
1494 // a random one for looking up other entries. | 1495 // a random one for looking up other entries. |
1495 SiteInstance* site_instance = | 1496 SiteInstance* site_instance = |
1496 NavigationEntryImpl::FromNavigationEntry( | 1497 NavigationEntryImpl::FromNavigationEntry( |
1497 controller.GetLastCommittedEntry())->site_instance(); | 1498 controller.GetLastCommittedEntry())->site_instance(); |
1498 | 1499 |
1499 // That second URL should be the last committed and it should have gotten the | 1500 // That second URL should be the last committed and it should have gotten the |
1500 // new title. | 1501 // new title. |
1501 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); | 1502 EXPECT_EQ(kUrl2, controller.GetEntryWithPageID(site_instance, 1)->GetURL()); |
1502 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 1503 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
1503 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1504 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1504 | 1505 |
1505 // Now go forward to the last item again and say it was committed. | 1506 // Now go forward to the last item again and say it was committed. |
1506 controller.GoForward(); | 1507 controller.GoForward(); |
1507 test_rvh()->SendNavigate(2, kUrl3); | 1508 main_test_rfh()->SendNavigate(2, kUrl3); |
1508 | 1509 |
1509 // Now start going back one to the second page. It will be pending. | 1510 // Now start going back one to the second page. It will be pending. |
1510 controller.GoBack(); | 1511 controller.GoBack(); |
1511 EXPECT_EQ(1, controller.GetPendingEntryIndex()); | 1512 EXPECT_EQ(1, controller.GetPendingEntryIndex()); |
1512 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 1513 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
1513 | 1514 |
1514 // Not synthesize a totally new back event to the first page. This will not | 1515 // Not synthesize a totally new back event to the first page. This will not |
1515 // match the pending one. | 1516 // match the pending one. |
1516 test_rvh()->SendNavigate(0, kUrl1); | 1517 main_test_rfh()->SendNavigate(0, kUrl1); |
1517 | 1518 |
1518 // The committed navigation should clear the pending entry. | 1519 // The committed navigation should clear the pending entry. |
1519 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 1520 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
1520 | 1521 |
1521 // But the navigated entry should be the last committed. | 1522 // But the navigated entry should be the last committed. |
1522 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 1523 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
1523 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); | 1524 EXPECT_EQ(kUrl1, controller.GetLastCommittedEntry()->GetURL()); |
1524 } | 1525 } |
1525 | 1526 |
1526 // Tests what happens when we navigate forward successfully. | 1527 // Tests what happens when we navigate forward successfully. |
1527 TEST_F(NavigationControllerTest, Forward) { | 1528 TEST_F(NavigationControllerTest, Forward) { |
1528 NavigationControllerImpl& controller = controller_impl(); | 1529 NavigationControllerImpl& controller = controller_impl(); |
1529 TestNotificationTracker notifications; | 1530 TestNotificationTracker notifications; |
1530 RegisterForAllNavNotifications(¬ifications, &controller); | 1531 RegisterForAllNavNotifications(¬ifications, &controller); |
1531 | 1532 |
1532 const GURL url1("http://foo1"); | 1533 const GURL url1("http://foo1"); |
1533 const GURL url2("http://foo2"); | 1534 const GURL url2("http://foo2"); |
1534 | 1535 |
1535 test_rvh()->SendNavigate(0, url1); | 1536 main_test_rfh()->SendNavigate(0, url1); |
1536 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1537 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1537 navigation_entry_committed_counter_ = 0; | 1538 navigation_entry_committed_counter_ = 0; |
1538 | 1539 |
1539 test_rvh()->SendNavigate(1, url2); | 1540 main_test_rfh()->SendNavigate(1, url2); |
1540 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1541 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1541 navigation_entry_committed_counter_ = 0; | 1542 navigation_entry_committed_counter_ = 0; |
1542 | 1543 |
1543 controller.GoBack(); | 1544 controller.GoBack(); |
1544 test_rvh()->SendNavigate(0, url1); | 1545 main_test_rfh()->SendNavigate(0, url1); |
1545 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1546 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1546 navigation_entry_committed_counter_ = 0; | 1547 navigation_entry_committed_counter_ = 0; |
1547 | 1548 |
1548 controller.GoForward(); | 1549 controller.GoForward(); |
1549 | 1550 |
1550 // We should now have a pending navigation to go forward. | 1551 // We should now have a pending navigation to go forward. |
1551 EXPECT_EQ(controller.GetEntryCount(), 2); | 1552 EXPECT_EQ(controller.GetEntryCount(), 2); |
1552 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1553 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1553 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1554 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1554 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1555 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1555 EXPECT_TRUE(controller.GetPendingEntry()); | 1556 EXPECT_TRUE(controller.GetPendingEntry()); |
1556 EXPECT_TRUE(controller.CanGoBack()); | 1557 EXPECT_TRUE(controller.CanGoBack()); |
1557 EXPECT_TRUE(controller.CanGoToOffset(-1)); | 1558 EXPECT_TRUE(controller.CanGoToOffset(-1)); |
1558 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. | 1559 EXPECT_FALSE(controller.CanGoToOffset(-2)); // Cannot go back 2 steps. |
1559 EXPECT_FALSE(controller.CanGoForward()); | 1560 EXPECT_FALSE(controller.CanGoForward()); |
1560 EXPECT_FALSE(controller.CanGoToOffset(1)); | 1561 EXPECT_FALSE(controller.CanGoToOffset(1)); |
1561 | 1562 |
1562 // Timestamp for entry 0 should be on or after that of entry 1 | 1563 // Timestamp for entry 0 should be on or after that of entry 1 |
1563 // (since we went back to it). | 1564 // (since we went back to it). |
1564 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); | 1565 EXPECT_FALSE(controller.GetEntryAtIndex(0)->GetTimestamp().is_null()); |
1565 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), | 1566 EXPECT_GE(controller.GetEntryAtIndex(0)->GetTimestamp(), |
1566 controller.GetEntryAtIndex(1)->GetTimestamp()); | 1567 controller.GetEntryAtIndex(1)->GetTimestamp()); |
1567 | 1568 |
1568 test_rvh()->SendNavigate(1, url2); | 1569 main_test_rfh()->SendNavigate(1, url2); |
1569 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1570 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1570 navigation_entry_committed_counter_ = 0; | 1571 navigation_entry_committed_counter_ = 0; |
1571 | 1572 |
1572 // The forward navigation completed successfully. | 1573 // The forward navigation completed successfully. |
1573 EXPECT_EQ(controller.GetEntryCount(), 2); | 1574 EXPECT_EQ(controller.GetEntryCount(), 2); |
1574 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1575 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1575 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1576 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1576 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1577 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1577 EXPECT_FALSE(controller.GetPendingEntry()); | 1578 EXPECT_FALSE(controller.GetPendingEntry()); |
1578 EXPECT_TRUE(controller.CanGoBack()); | 1579 EXPECT_TRUE(controller.CanGoBack()); |
(...skipping 11 matching lines...) Expand all Loading... |
1590 // Tests what happens when a forward navigation produces a new page. | 1591 // Tests what happens when a forward navigation produces a new page. |
1591 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { | 1592 TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { |
1592 NavigationControllerImpl& controller = controller_impl(); | 1593 NavigationControllerImpl& controller = controller_impl(); |
1593 TestNotificationTracker notifications; | 1594 TestNotificationTracker notifications; |
1594 RegisterForAllNavNotifications(¬ifications, &controller); | 1595 RegisterForAllNavNotifications(¬ifications, &controller); |
1595 | 1596 |
1596 const GURL url1("http://foo1"); | 1597 const GURL url1("http://foo1"); |
1597 const GURL url2("http://foo2"); | 1598 const GURL url2("http://foo2"); |
1598 const GURL url3("http://foo3"); | 1599 const GURL url3("http://foo3"); |
1599 | 1600 |
1600 test_rvh()->SendNavigate(0, url1); | 1601 main_test_rfh()->SendNavigate(0, url1); |
1601 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1602 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1602 navigation_entry_committed_counter_ = 0; | 1603 navigation_entry_committed_counter_ = 0; |
1603 test_rvh()->SendNavigate(1, url2); | 1604 main_test_rfh()->SendNavigate(1, url2); |
1604 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1605 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1605 navigation_entry_committed_counter_ = 0; | 1606 navigation_entry_committed_counter_ = 0; |
1606 | 1607 |
1607 controller.GoBack(); | 1608 controller.GoBack(); |
1608 test_rvh()->SendNavigate(0, url1); | 1609 main_test_rfh()->SendNavigate(0, url1); |
1609 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1610 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1610 navigation_entry_committed_counter_ = 0; | 1611 navigation_entry_committed_counter_ = 0; |
1611 | 1612 |
1612 controller.GoForward(); | 1613 controller.GoForward(); |
1613 EXPECT_EQ(0U, notifications.size()); | 1614 EXPECT_EQ(0U, notifications.size()); |
1614 | 1615 |
1615 // Should now have a pending navigation to go forward. | 1616 // Should now have a pending navigation to go forward. |
1616 EXPECT_EQ(controller.GetEntryCount(), 2); | 1617 EXPECT_EQ(controller.GetEntryCount(), 2); |
1617 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 1618 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
1618 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); | 1619 EXPECT_EQ(controller.GetPendingEntryIndex(), 1); |
1619 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1620 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1620 EXPECT_TRUE(controller.GetPendingEntry()); | 1621 EXPECT_TRUE(controller.GetPendingEntry()); |
1621 EXPECT_TRUE(controller.CanGoBack()); | 1622 EXPECT_TRUE(controller.CanGoBack()); |
1622 EXPECT_FALSE(controller.CanGoForward()); | 1623 EXPECT_FALSE(controller.CanGoForward()); |
1623 | 1624 |
1624 test_rvh()->SendNavigate(2, url3); | 1625 main_test_rfh()->SendNavigate(2, url3); |
1625 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1626 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1626 navigation_entry_committed_counter_ = 0; | 1627 navigation_entry_committed_counter_ = 0; |
1627 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); | 1628 EXPECT_TRUE(notifications.Check1AndReset(NOTIFICATION_NAV_LIST_PRUNED)); |
1628 | 1629 |
1629 EXPECT_EQ(controller.GetEntryCount(), 2); | 1630 EXPECT_EQ(controller.GetEntryCount(), 2); |
1630 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1631 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1631 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1632 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1632 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1633 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1633 EXPECT_FALSE(controller.GetPendingEntry()); | 1634 EXPECT_FALSE(controller.GetPendingEntry()); |
1634 EXPECT_TRUE(controller.CanGoBack()); | 1635 EXPECT_TRUE(controller.CanGoBack()); |
1635 EXPECT_FALSE(controller.CanGoForward()); | 1636 EXPECT_FALSE(controller.CanGoForward()); |
1636 } | 1637 } |
1637 | 1638 |
1638 // Two consequent navigation for the same URL entered in should be considered | 1639 // Two consequent navigation for the same URL entered in should be considered |
1639 // as SAME_PAGE navigation even when we are redirected to some other page. | 1640 // as SAME_PAGE navigation even when we are redirected to some other page. |
1640 TEST_F(NavigationControllerTest, Redirect) { | 1641 TEST_F(NavigationControllerTest, Redirect) { |
1641 NavigationControllerImpl& controller = controller_impl(); | 1642 NavigationControllerImpl& controller = controller_impl(); |
1642 TestNotificationTracker notifications; | 1643 TestNotificationTracker notifications; |
1643 RegisterForAllNavNotifications(¬ifications, &controller); | 1644 RegisterForAllNavNotifications(¬ifications, &controller); |
1644 | 1645 |
1645 const GURL url1("http://foo1"); | 1646 const GURL url1("http://foo1"); |
1646 const GURL url2("http://foo2"); // Redirection target | 1647 const GURL url2("http://foo2"); // Redirection target |
1647 | 1648 |
1648 // First request | 1649 // First request |
1649 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1650 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1650 | 1651 |
1651 EXPECT_EQ(0U, notifications.size()); | 1652 EXPECT_EQ(0U, notifications.size()); |
1652 test_rvh()->SendNavigate(0, url2); | 1653 main_test_rfh()->SendNavigate(0, url2); |
1653 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1654 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1654 navigation_entry_committed_counter_ = 0; | 1655 navigation_entry_committed_counter_ = 0; |
1655 | 1656 |
1656 // Second request | 1657 // Second request |
1657 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1658 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1658 | 1659 |
1659 EXPECT_TRUE(controller.GetPendingEntry()); | 1660 EXPECT_TRUE(controller.GetPendingEntry()); |
1660 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1661 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1661 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1662 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
1662 | 1663 |
1663 ViewHostMsg_FrameNavigate_Params params; | 1664 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1664 params.page_id = 0; | 1665 params.page_id = 0; |
1665 params.url = url2; | 1666 params.url = url2; |
1666 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; | 1667 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
1667 params.redirects.push_back(GURL("http://foo1")); | 1668 params.redirects.push_back(GURL("http://foo1")); |
1668 params.redirects.push_back(GURL("http://foo2")); | 1669 params.redirects.push_back(GURL("http://foo2")); |
1669 params.should_update_history = false; | 1670 params.should_update_history = false; |
1670 params.gesture = NavigationGestureAuto; | 1671 params.gesture = NavigationGestureAuto; |
1671 params.is_post = false; | 1672 params.is_post = false; |
1672 params.page_state = PageState::CreateFromURL(url2); | 1673 params.page_state = PageState::CreateFromURL(url2); |
1673 | 1674 |
(...skipping 25 matching lines...) Expand all Loading... |
1699 RegisterForAllNavNotifications(¬ifications, &controller); | 1700 RegisterForAllNavNotifications(¬ifications, &controller); |
1700 | 1701 |
1701 const GURL url1("http://foo1"); | 1702 const GURL url1("http://foo1"); |
1702 const GURL url2("http://foo2"); // Redirection target | 1703 const GURL url2("http://foo2"); // Redirection target |
1703 | 1704 |
1704 // First request as POST | 1705 // First request as POST |
1705 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1706 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1706 controller.GetVisibleEntry()->SetHasPostData(true); | 1707 controller.GetVisibleEntry()->SetHasPostData(true); |
1707 | 1708 |
1708 EXPECT_EQ(0U, notifications.size()); | 1709 EXPECT_EQ(0U, notifications.size()); |
1709 test_rvh()->SendNavigate(0, url2); | 1710 main_test_rfh()->SendNavigate(0, url2); |
1710 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1711 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1711 navigation_entry_committed_counter_ = 0; | 1712 navigation_entry_committed_counter_ = 0; |
1712 | 1713 |
1713 // Second request | 1714 // Second request |
1714 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1715 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1715 | 1716 |
1716 EXPECT_TRUE(controller.GetPendingEntry()); | 1717 EXPECT_TRUE(controller.GetPendingEntry()); |
1717 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1718 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1718 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1719 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
1719 | 1720 |
1720 ViewHostMsg_FrameNavigate_Params params; | 1721 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1721 params.page_id = 0; | 1722 params.page_id = 0; |
1722 params.url = url2; | 1723 params.url = url2; |
1723 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; | 1724 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
1724 params.redirects.push_back(GURL("http://foo1")); | 1725 params.redirects.push_back(GURL("http://foo1")); |
1725 params.redirects.push_back(GURL("http://foo2")); | 1726 params.redirects.push_back(GURL("http://foo2")); |
1726 params.should_update_history = false; | 1727 params.should_update_history = false; |
1727 params.gesture = NavigationGestureAuto; | 1728 params.gesture = NavigationGestureAuto; |
1728 params.is_post = false; | 1729 params.is_post = false; |
1729 params.page_state = PageState::CreateFromURL(url2); | 1730 params.page_state = PageState::CreateFromURL(url2); |
1730 | 1731 |
(...skipping 26 matching lines...) Expand all Loading... |
1757 const GURL url1("http://foo1"); | 1758 const GURL url1("http://foo1"); |
1758 const GURL url2("http://foo2"); // Redirection target | 1759 const GURL url2("http://foo2"); // Redirection target |
1759 | 1760 |
1760 // First request | 1761 // First request |
1761 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 1762 controller.LoadURL(url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
1762 | 1763 |
1763 EXPECT_TRUE(controller.GetPendingEntry()); | 1764 EXPECT_TRUE(controller.GetPendingEntry()); |
1764 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1765 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1765 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 1766 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
1766 | 1767 |
1767 ViewHostMsg_FrameNavigate_Params params; | 1768 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1768 params.page_id = 0; | 1769 params.page_id = 0; |
1769 params.url = url2; | 1770 params.url = url2; |
1770 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; | 1771 params.transition = PAGE_TRANSITION_SERVER_REDIRECT; |
1771 params.redirects.push_back(GURL("http://foo1")); | 1772 params.redirects.push_back(GURL("http://foo1")); |
1772 params.redirects.push_back(GURL("http://foo2")); | 1773 params.redirects.push_back(GURL("http://foo2")); |
1773 params.should_update_history = false; | 1774 params.should_update_history = false; |
1774 params.gesture = NavigationGestureAuto; | 1775 params.gesture = NavigationGestureAuto; |
1775 params.is_post = false; | 1776 params.is_post = false; |
1776 params.page_state = PageState::CreateFromURL(url2); | 1777 params.page_state = PageState::CreateFromURL(url2); |
1777 | 1778 |
(...skipping 17 matching lines...) Expand all Loading... |
1795 } | 1796 } |
1796 | 1797 |
1797 // Tests navigation via link click within a subframe. A new navigation entry | 1798 // Tests navigation via link click within a subframe. A new navigation entry |
1798 // should be created. | 1799 // should be created. |
1799 TEST_F(NavigationControllerTest, NewSubframe) { | 1800 TEST_F(NavigationControllerTest, NewSubframe) { |
1800 NavigationControllerImpl& controller = controller_impl(); | 1801 NavigationControllerImpl& controller = controller_impl(); |
1801 TestNotificationTracker notifications; | 1802 TestNotificationTracker notifications; |
1802 RegisterForAllNavNotifications(¬ifications, &controller); | 1803 RegisterForAllNavNotifications(¬ifications, &controller); |
1803 | 1804 |
1804 const GURL url1("http://foo1"); | 1805 const GURL url1("http://foo1"); |
1805 test_rvh()->SendNavigate(0, url1); | 1806 main_test_rfh()->SendNavigate(0, url1); |
1806 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1807 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1807 navigation_entry_committed_counter_ = 0; | 1808 navigation_entry_committed_counter_ = 0; |
1808 | 1809 |
1809 const GURL url2("http://foo2"); | 1810 const GURL url2("http://foo2"); |
1810 ViewHostMsg_FrameNavigate_Params params; | 1811 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1811 params.page_id = 1; | 1812 params.page_id = 1; |
1812 params.url = url2; | 1813 params.url = url2; |
1813 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; | 1814 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
1814 params.should_update_history = false; | 1815 params.should_update_history = false; |
1815 params.gesture = NavigationGestureUser; | 1816 params.gesture = NavigationGestureUser; |
1816 params.is_post = false; | 1817 params.is_post = false; |
1817 params.page_state = PageState::CreateFromURL(url2); | 1818 params.page_state = PageState::CreateFromURL(url2); |
1818 | 1819 |
1819 LoadCommittedDetails details; | 1820 LoadCommittedDetails details; |
1820 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 1821 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
(...skipping 15 matching lines...) Expand all Loading... |
1836 // Some pages create a popup, then write an iframe into it. This causes a | 1837 // Some pages create a popup, then write an iframe into it. This causes a |
1837 // subframe navigation without having any committed entry. Such navigations | 1838 // subframe navigation without having any committed entry. Such navigations |
1838 // just get thrown on the ground, but we shouldn't crash. | 1839 // just get thrown on the ground, but we shouldn't crash. |
1839 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { | 1840 TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { |
1840 NavigationControllerImpl& controller = controller_impl(); | 1841 NavigationControllerImpl& controller = controller_impl(); |
1841 TestNotificationTracker notifications; | 1842 TestNotificationTracker notifications; |
1842 RegisterForAllNavNotifications(¬ifications, &controller); | 1843 RegisterForAllNavNotifications(¬ifications, &controller); |
1843 | 1844 |
1844 // Navigation controller currently has no entries. | 1845 // Navigation controller currently has no entries. |
1845 const GURL url("http://foo2"); | 1846 const GURL url("http://foo2"); |
1846 ViewHostMsg_FrameNavigate_Params params; | 1847 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1847 params.page_id = 1; | 1848 params.page_id = 1; |
1848 params.url = url; | 1849 params.url = url; |
1849 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; | 1850 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
1850 params.should_update_history = false; | 1851 params.should_update_history = false; |
1851 params.gesture = NavigationGestureAuto; | 1852 params.gesture = NavigationGestureAuto; |
1852 params.is_post = false; | 1853 params.is_post = false; |
1853 params.page_state = PageState::CreateFromURL(url); | 1854 params.page_state = PageState::CreateFromURL(url); |
1854 | 1855 |
1855 LoadCommittedDetails details; | 1856 LoadCommittedDetails details; |
1856 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 1857 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
1857 EXPECT_EQ(0U, notifications.size()); | 1858 EXPECT_EQ(0U, notifications.size()); |
1858 } | 1859 } |
1859 | 1860 |
1860 // Auto subframes are ones the page loads automatically like ads. They should | 1861 // Auto subframes are ones the page loads automatically like ads. They should |
1861 // not create new navigation entries. | 1862 // not create new navigation entries. |
1862 TEST_F(NavigationControllerTest, AutoSubframe) { | 1863 TEST_F(NavigationControllerTest, AutoSubframe) { |
1863 NavigationControllerImpl& controller = controller_impl(); | 1864 NavigationControllerImpl& controller = controller_impl(); |
1864 TestNotificationTracker notifications; | 1865 TestNotificationTracker notifications; |
1865 RegisterForAllNavNotifications(¬ifications, &controller); | 1866 RegisterForAllNavNotifications(¬ifications, &controller); |
1866 | 1867 |
1867 const GURL url1("http://foo1"); | 1868 const GURL url1("http://foo1"); |
1868 test_rvh()->SendNavigate(0, url1); | 1869 main_test_rfh()->SendNavigate(0, url1); |
1869 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1870 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1870 navigation_entry_committed_counter_ = 0; | 1871 navigation_entry_committed_counter_ = 0; |
1871 | 1872 |
1872 const GURL url2("http://foo2"); | 1873 const GURL url2("http://foo2"); |
1873 ViewHostMsg_FrameNavigate_Params params; | 1874 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1874 params.page_id = 0; | 1875 params.page_id = 0; |
1875 params.url = url2; | 1876 params.url = url2; |
1876 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; | 1877 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
1877 params.should_update_history = false; | 1878 params.should_update_history = false; |
1878 params.gesture = NavigationGestureUser; | 1879 params.gesture = NavigationGestureUser; |
1879 params.is_post = false; | 1880 params.is_post = false; |
1880 params.page_state = PageState::CreateFromURL(url2); | 1881 params.page_state = PageState::CreateFromURL(url2); |
1881 | 1882 |
1882 // Navigating should do nothing. | 1883 // Navigating should do nothing. |
1883 LoadCommittedDetails details; | 1884 LoadCommittedDetails details; |
1884 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 1885 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
1885 EXPECT_EQ(0U, notifications.size()); | 1886 EXPECT_EQ(0U, notifications.size()); |
1886 | 1887 |
1887 // There should still be only one entry. | 1888 // There should still be only one entry. |
1888 EXPECT_EQ(1, controller.GetEntryCount()); | 1889 EXPECT_EQ(1, controller.GetEntryCount()); |
1889 } | 1890 } |
1890 | 1891 |
1891 // Tests navigation and then going back to a subframe navigation. | 1892 // Tests navigation and then going back to a subframe navigation. |
1892 TEST_F(NavigationControllerTest, BackSubframe) { | 1893 TEST_F(NavigationControllerTest, BackSubframe) { |
1893 NavigationControllerImpl& controller = controller_impl(); | 1894 NavigationControllerImpl& controller = controller_impl(); |
1894 TestNotificationTracker notifications; | 1895 TestNotificationTracker notifications; |
1895 RegisterForAllNavNotifications(¬ifications, &controller); | 1896 RegisterForAllNavNotifications(¬ifications, &controller); |
1896 | 1897 |
1897 // Main page. | 1898 // Main page. |
1898 const GURL url1("http://foo1"); | 1899 const GURL url1("http://foo1"); |
1899 test_rvh()->SendNavigate(0, url1); | 1900 main_test_rfh()->SendNavigate(0, url1); |
1900 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1901 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1901 navigation_entry_committed_counter_ = 0; | 1902 navigation_entry_committed_counter_ = 0; |
1902 | 1903 |
1903 // First manual subframe navigation. | 1904 // First manual subframe navigation. |
1904 const GURL url2("http://foo2"); | 1905 const GURL url2("http://foo2"); |
1905 ViewHostMsg_FrameNavigate_Params params; | 1906 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
1906 params.page_id = 1; | 1907 params.page_id = 1; |
1907 params.url = url2; | 1908 params.url = url2; |
1908 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; | 1909 params.transition = PAGE_TRANSITION_MANUAL_SUBFRAME; |
1909 params.should_update_history = false; | 1910 params.should_update_history = false; |
1910 params.gesture = NavigationGestureUser; | 1911 params.gesture = NavigationGestureUser; |
1911 params.is_post = false; | 1912 params.is_post = false; |
1912 params.page_state = PageState::CreateFromURL(url2); | 1913 params.page_state = PageState::CreateFromURL(url2); |
1913 | 1914 |
1914 // This should generate a new entry. | 1915 // This should generate a new entry. |
1915 LoadCommittedDetails details; | 1916 LoadCommittedDetails details; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 } | 1955 } |
1955 | 1956 |
1956 TEST_F(NavigationControllerTest, LinkClick) { | 1957 TEST_F(NavigationControllerTest, LinkClick) { |
1957 NavigationControllerImpl& controller = controller_impl(); | 1958 NavigationControllerImpl& controller = controller_impl(); |
1958 TestNotificationTracker notifications; | 1959 TestNotificationTracker notifications; |
1959 RegisterForAllNavNotifications(¬ifications, &controller); | 1960 RegisterForAllNavNotifications(¬ifications, &controller); |
1960 | 1961 |
1961 const GURL url1("http://foo1"); | 1962 const GURL url1("http://foo1"); |
1962 const GURL url2("http://foo2"); | 1963 const GURL url2("http://foo2"); |
1963 | 1964 |
1964 test_rvh()->SendNavigate(0, url1); | 1965 main_test_rfh()->SendNavigate(0, url1); |
1965 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1966 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1966 navigation_entry_committed_counter_ = 0; | 1967 navigation_entry_committed_counter_ = 0; |
1967 | 1968 |
1968 test_rvh()->SendNavigate(1, url2); | 1969 main_test_rfh()->SendNavigate(1, url2); |
1969 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1970 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1970 navigation_entry_committed_counter_ = 0; | 1971 navigation_entry_committed_counter_ = 0; |
1971 | 1972 |
1972 // Should not have produced a new session history entry. | 1973 // Should not have produced a new session history entry. |
1973 EXPECT_EQ(controller.GetEntryCount(), 2); | 1974 EXPECT_EQ(controller.GetEntryCount(), 2); |
1974 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 1975 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
1975 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 1976 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
1976 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 1977 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
1977 EXPECT_FALSE(controller.GetPendingEntry()); | 1978 EXPECT_FALSE(controller.GetPendingEntry()); |
1978 EXPECT_TRUE(controller.CanGoBack()); | 1979 EXPECT_TRUE(controller.CanGoBack()); |
1979 EXPECT_FALSE(controller.CanGoForward()); | 1980 EXPECT_FALSE(controller.CanGoForward()); |
1980 } | 1981 } |
1981 | 1982 |
1982 TEST_F(NavigationControllerTest, InPage) { | 1983 TEST_F(NavigationControllerTest, InPage) { |
1983 NavigationControllerImpl& controller = controller_impl(); | 1984 NavigationControllerImpl& controller = controller_impl(); |
1984 TestNotificationTracker notifications; | 1985 TestNotificationTracker notifications; |
1985 RegisterForAllNavNotifications(¬ifications, &controller); | 1986 RegisterForAllNavNotifications(¬ifications, &controller); |
1986 | 1987 |
1987 // Main page. | 1988 // Main page. |
1988 const GURL url1("http://foo"); | 1989 const GURL url1("http://foo"); |
1989 test_rvh()->SendNavigate(0, url1); | 1990 main_test_rfh()->SendNavigate(0, url1); |
1990 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 1991 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
1991 navigation_entry_committed_counter_ = 0; | 1992 navigation_entry_committed_counter_ = 0; |
1992 | 1993 |
1993 // Ensure main page navigation to same url respects the was_within_same_page | 1994 // Ensure main page navigation to same url respects the was_within_same_page |
1994 // hint provided in the params. | 1995 // hint provided in the params. |
1995 ViewHostMsg_FrameNavigate_Params self_params; | 1996 FrameHostMsg_DidCommitProvisionalLoad_Params self_params; |
1996 self_params.page_id = 0; | 1997 self_params.page_id = 0; |
1997 self_params.url = url1; | 1998 self_params.url = url1; |
1998 self_params.transition = PAGE_TRANSITION_LINK; | 1999 self_params.transition = PAGE_TRANSITION_LINK; |
1999 self_params.should_update_history = false; | 2000 self_params.should_update_history = false; |
2000 self_params.gesture = NavigationGestureUser; | 2001 self_params.gesture = NavigationGestureUser; |
2001 self_params.is_post = false; | 2002 self_params.is_post = false; |
2002 self_params.page_state = PageState::CreateFromURL(url1); | 2003 self_params.page_state = PageState::CreateFromURL(url1); |
2003 self_params.was_within_same_page = true; | 2004 self_params.was_within_same_page = true; |
2004 | 2005 |
2005 LoadCommittedDetails details; | 2006 LoadCommittedDetails details; |
2006 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), self_params, | 2007 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), self_params, |
2007 &details)); | 2008 &details)); |
2008 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2009 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2009 navigation_entry_committed_counter_ = 0; | 2010 navigation_entry_committed_counter_ = 0; |
2010 EXPECT_TRUE(details.is_in_page); | 2011 EXPECT_TRUE(details.is_in_page); |
2011 EXPECT_TRUE(details.did_replace_entry); | 2012 EXPECT_TRUE(details.did_replace_entry); |
2012 EXPECT_EQ(1, controller.GetEntryCount()); | 2013 EXPECT_EQ(1, controller.GetEntryCount()); |
2013 | 2014 |
2014 // Fragment navigation to a new page_id. | 2015 // Fragment navigation to a new page_id. |
2015 const GURL url2("http://foo#a"); | 2016 const GURL url2("http://foo#a"); |
2016 ViewHostMsg_FrameNavigate_Params params; | 2017 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2017 params.page_id = 1; | 2018 params.page_id = 1; |
2018 params.url = url2; | 2019 params.url = url2; |
2019 params.transition = PAGE_TRANSITION_LINK; | 2020 params.transition = PAGE_TRANSITION_LINK; |
2020 params.should_update_history = false; | 2021 params.should_update_history = false; |
2021 params.gesture = NavigationGestureUser; | 2022 params.gesture = NavigationGestureUser; |
2022 params.is_post = false; | 2023 params.is_post = false; |
2023 params.page_state = PageState::CreateFromURL(url2); | 2024 params.page_state = PageState::CreateFromURL(url2); |
2024 params.was_within_same_page = true; | 2025 params.was_within_same_page = true; |
2025 | 2026 |
2026 // This should generate a new entry. | 2027 // This should generate a new entry. |
2027 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 2028 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
2028 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2029 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2029 navigation_entry_committed_counter_ = 0; | 2030 navigation_entry_committed_counter_ = 0; |
2030 EXPECT_TRUE(details.is_in_page); | 2031 EXPECT_TRUE(details.is_in_page); |
2031 EXPECT_FALSE(details.did_replace_entry); | 2032 EXPECT_FALSE(details.did_replace_entry); |
2032 EXPECT_EQ(2, controller.GetEntryCount()); | 2033 EXPECT_EQ(2, controller.GetEntryCount()); |
2033 | 2034 |
2034 // Go back one. | 2035 // Go back one. |
2035 ViewHostMsg_FrameNavigate_Params back_params(params); | 2036 FrameHostMsg_DidCommitProvisionalLoad_Params back_params(params); |
2036 controller.GoBack(); | 2037 controller.GoBack(); |
2037 back_params.url = url1; | 2038 back_params.url = url1; |
2038 back_params.page_id = 0; | 2039 back_params.page_id = 0; |
2039 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), back_params, | 2040 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), back_params, |
2040 &details)); | 2041 &details)); |
2041 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2042 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2042 navigation_entry_committed_counter_ = 0; | 2043 navigation_entry_committed_counter_ = 0; |
2043 EXPECT_TRUE(details.is_in_page); | 2044 EXPECT_TRUE(details.is_in_page); |
2044 EXPECT_EQ(2, controller.GetEntryCount()); | 2045 EXPECT_EQ(2, controller.GetEntryCount()); |
2045 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 2046 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
2046 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); | 2047 EXPECT_EQ(back_params.url, controller.GetVisibleEntry()->GetURL()); |
2047 | 2048 |
2048 // Go forward | 2049 // Go forward |
2049 ViewHostMsg_FrameNavigate_Params forward_params(params); | 2050 FrameHostMsg_DidCommitProvisionalLoad_Params forward_params(params); |
2050 controller.GoForward(); | 2051 controller.GoForward(); |
2051 forward_params.url = url2; | 2052 forward_params.url = url2; |
2052 forward_params.page_id = 1; | 2053 forward_params.page_id = 1; |
2053 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), forward_params, | 2054 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), forward_params, |
2054 &details)); | 2055 &details)); |
2055 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2056 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2056 navigation_entry_committed_counter_ = 0; | 2057 navigation_entry_committed_counter_ = 0; |
2057 EXPECT_TRUE(details.is_in_page); | 2058 EXPECT_TRUE(details.is_in_page); |
2058 EXPECT_EQ(2, controller.GetEntryCount()); | 2059 EXPECT_EQ(2, controller.GetEntryCount()); |
2059 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); | 2060 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); |
(...skipping 26 matching lines...) Expand all Loading... |
2086 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); | 2087 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
2087 } | 2088 } |
2088 | 2089 |
2089 TEST_F(NavigationControllerTest, InPage_Replace) { | 2090 TEST_F(NavigationControllerTest, InPage_Replace) { |
2090 NavigationControllerImpl& controller = controller_impl(); | 2091 NavigationControllerImpl& controller = controller_impl(); |
2091 TestNotificationTracker notifications; | 2092 TestNotificationTracker notifications; |
2092 RegisterForAllNavNotifications(¬ifications, &controller); | 2093 RegisterForAllNavNotifications(¬ifications, &controller); |
2093 | 2094 |
2094 // Main page. | 2095 // Main page. |
2095 const GURL url1("http://foo"); | 2096 const GURL url1("http://foo"); |
2096 test_rvh()->SendNavigate(0, url1); | 2097 main_test_rfh()->SendNavigate(0, url1); |
2097 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2098 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2098 navigation_entry_committed_counter_ = 0; | 2099 navigation_entry_committed_counter_ = 0; |
2099 | 2100 |
2100 // First navigation. | 2101 // First navigation. |
2101 const GURL url2("http://foo#a"); | 2102 const GURL url2("http://foo#a"); |
2102 ViewHostMsg_FrameNavigate_Params params; | 2103 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2103 params.page_id = 0; // Same page_id | 2104 params.page_id = 0; // Same page_id |
2104 params.url = url2; | 2105 params.url = url2; |
2105 params.transition = PAGE_TRANSITION_LINK; | 2106 params.transition = PAGE_TRANSITION_LINK; |
2106 params.should_update_history = false; | 2107 params.should_update_history = false; |
2107 params.gesture = NavigationGestureUser; | 2108 params.gesture = NavigationGestureUser; |
2108 params.is_post = false; | 2109 params.is_post = false; |
2109 params.page_state = PageState::CreateFromURL(url2); | 2110 params.page_state = PageState::CreateFromURL(url2); |
2110 | 2111 |
2111 // This should NOT generate a new entry, nor prune the list. | 2112 // This should NOT generate a new entry, nor prune the list. |
2112 LoadCommittedDetails details; | 2113 LoadCommittedDetails details; |
(...skipping 12 matching lines...) Expand all Loading... |
2125 // window.location='http://foo3/'; | 2126 // window.location='http://foo3/'; |
2126 // </script> | 2127 // </script> |
2127 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { | 2128 TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { |
2128 NavigationControllerImpl& controller = controller_impl(); | 2129 NavigationControllerImpl& controller = controller_impl(); |
2129 TestNotificationTracker notifications; | 2130 TestNotificationTracker notifications; |
2130 RegisterForAllNavNotifications(¬ifications, &controller); | 2131 RegisterForAllNavNotifications(¬ifications, &controller); |
2131 | 2132 |
2132 // Load an initial page. | 2133 // Load an initial page. |
2133 { | 2134 { |
2134 const GURL url("http://foo/"); | 2135 const GURL url("http://foo/"); |
2135 test_rvh()->SendNavigate(0, url); | 2136 main_test_rfh()->SendNavigate(0, url); |
2136 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2137 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2137 navigation_entry_committed_counter_ = 0; | 2138 navigation_entry_committed_counter_ = 0; |
2138 } | 2139 } |
2139 | 2140 |
2140 // Navigate to a new page. | 2141 // Navigate to a new page. |
2141 { | 2142 { |
2142 const GURL url("http://foo2/"); | 2143 const GURL url("http://foo2/"); |
2143 test_rvh()->SendNavigate(1, url); | 2144 main_test_rfh()->SendNavigate(1, url); |
2144 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2145 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2145 navigation_entry_committed_counter_ = 0; | 2146 navigation_entry_committed_counter_ = 0; |
2146 } | 2147 } |
2147 | 2148 |
2148 // Navigate within the page. | 2149 // Navigate within the page. |
2149 { | 2150 { |
2150 const GURL url("http://foo2/#a"); | 2151 const GURL url("http://foo2/#a"); |
2151 ViewHostMsg_FrameNavigate_Params params; | 2152 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2152 params.page_id = 1; // Same page_id | 2153 params.page_id = 1; // Same page_id |
2153 params.url = url; | 2154 params.url = url; |
2154 params.transition = PAGE_TRANSITION_LINK; | 2155 params.transition = PAGE_TRANSITION_LINK; |
2155 params.redirects.push_back(url); | 2156 params.redirects.push_back(url); |
2156 params.should_update_history = true; | 2157 params.should_update_history = true; |
2157 params.gesture = NavigationGestureUnknown; | 2158 params.gesture = NavigationGestureUnknown; |
2158 params.is_post = false; | 2159 params.is_post = false; |
2159 params.page_state = PageState::CreateFromURL(url); | 2160 params.page_state = PageState::CreateFromURL(url); |
2160 | 2161 |
2161 // This should NOT generate a new entry, nor prune the list. | 2162 // This should NOT generate a new entry, nor prune the list. |
2162 LoadCommittedDetails details; | 2163 LoadCommittedDetails details; |
2163 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 2164 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
2164 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2165 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2165 navigation_entry_committed_counter_ = 0; | 2166 navigation_entry_committed_counter_ = 0; |
2166 EXPECT_TRUE(details.is_in_page); | 2167 EXPECT_TRUE(details.is_in_page); |
2167 EXPECT_TRUE(details.did_replace_entry); | 2168 EXPECT_TRUE(details.did_replace_entry); |
2168 EXPECT_EQ(2, controller.GetEntryCount()); | 2169 EXPECT_EQ(2, controller.GetEntryCount()); |
2169 } | 2170 } |
2170 | 2171 |
2171 // Perform a client redirect to a new page. | 2172 // Perform a client redirect to a new page. |
2172 { | 2173 { |
2173 const GURL url("http://foo3/"); | 2174 const GURL url("http://foo3/"); |
2174 ViewHostMsg_FrameNavigate_Params params; | 2175 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2175 params.page_id = 2; // New page_id | 2176 params.page_id = 2; // New page_id |
2176 params.url = url; | 2177 params.url = url; |
2177 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT; | 2178 params.transition = PAGE_TRANSITION_CLIENT_REDIRECT; |
2178 params.redirects.push_back(GURL("http://foo2/#a")); | 2179 params.redirects.push_back(GURL("http://foo2/#a")); |
2179 params.redirects.push_back(url); | 2180 params.redirects.push_back(url); |
2180 params.should_update_history = true; | 2181 params.should_update_history = true; |
2181 params.gesture = NavigationGestureUnknown; | 2182 params.gesture = NavigationGestureUnknown; |
2182 params.is_post = false; | 2183 params.is_post = false; |
2183 params.page_state = PageState::CreateFromURL(url); | 2184 params.page_state = PageState::CreateFromURL(url); |
2184 | 2185 |
2185 // This SHOULD generate a new entry. | 2186 // This SHOULD generate a new entry. |
2186 LoadCommittedDetails details; | 2187 LoadCommittedDetails details; |
2187 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 2188 EXPECT_TRUE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
2188 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2189 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2189 navigation_entry_committed_counter_ = 0; | 2190 navigation_entry_committed_counter_ = 0; |
2190 EXPECT_FALSE(details.is_in_page); | 2191 EXPECT_FALSE(details.is_in_page); |
2191 EXPECT_EQ(3, controller.GetEntryCount()); | 2192 EXPECT_EQ(3, controller.GetEntryCount()); |
2192 } | 2193 } |
2193 | 2194 |
2194 // Verify that BACK brings us back to http://foo2/. | 2195 // Verify that BACK brings us back to http://foo2/. |
2195 { | 2196 { |
2196 const GURL url("http://foo2/"); | 2197 const GURL url("http://foo2/"); |
2197 controller.GoBack(); | 2198 controller.GoBack(); |
2198 test_rvh()->SendNavigate(1, url); | 2199 main_test_rfh()->SendNavigate(1, url); |
2199 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 2200 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
2200 navigation_entry_committed_counter_ = 0; | 2201 navigation_entry_committed_counter_ = 0; |
2201 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); | 2202 EXPECT_EQ(url, controller.GetVisibleEntry()->GetURL()); |
2202 } | 2203 } |
2203 } | 2204 } |
2204 | 2205 |
2205 // NotificationObserver implementation used in verifying we've received the | 2206 // NotificationObserver implementation used in verifying we've received the |
2206 // NOTIFICATION_NAV_LIST_PRUNED method. | 2207 // NOTIFICATION_NAV_LIST_PRUNED method. |
2207 class PrunedListener : public NotificationObserver { | 2208 class PrunedListener : public NotificationObserver { |
2208 public: | 2209 public: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2240 const int kMaxEntryCount = 5; | 2241 const int kMaxEntryCount = 5; |
2241 | 2242 |
2242 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); | 2243 NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount); |
2243 | 2244 |
2244 int url_index; | 2245 int url_index; |
2245 // Load up to the max count, all entries should be there. | 2246 // Load up to the max count, all entries should be there. |
2246 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { | 2247 for (url_index = 0; url_index < kMaxEntryCount; url_index++) { |
2247 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2248 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2248 controller.LoadURL( | 2249 controller.LoadURL( |
2249 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2250 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2250 test_rvh()->SendNavigate(url_index, url); | 2251 main_test_rfh()->SendNavigate(url_index, url); |
2251 } | 2252 } |
2252 | 2253 |
2253 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2254 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2254 | 2255 |
2255 // Created a PrunedListener to observe prune notifications. | 2256 // Created a PrunedListener to observe prune notifications. |
2256 PrunedListener listener(&controller); | 2257 PrunedListener listener(&controller); |
2257 | 2258 |
2258 // Navigate some more. | 2259 // Navigate some more. |
2259 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); | 2260 GURL url(base::StringPrintf("http://www.a.com/%d", url_index)); |
2260 controller.LoadURL( | 2261 controller.LoadURL( |
2261 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2262 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2262 test_rvh()->SendNavigate(url_index, url); | 2263 main_test_rfh()->SendNavigate(url_index, url); |
2263 url_index++; | 2264 url_index++; |
2264 | 2265 |
2265 // We should have got a pruned navigation. | 2266 // We should have got a pruned navigation. |
2266 EXPECT_EQ(1, listener.notification_count_); | 2267 EXPECT_EQ(1, listener.notification_count_); |
2267 EXPECT_TRUE(listener.details_.from_front); | 2268 EXPECT_TRUE(listener.details_.from_front); |
2268 EXPECT_EQ(1, listener.details_.count); | 2269 EXPECT_EQ(1, listener.details_.count); |
2269 | 2270 |
2270 // We expect http://www.a.com/0 to be gone. | 2271 // We expect http://www.a.com/0 to be gone. |
2271 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2272 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2272 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2273 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2273 GURL("http:////www.a.com/1")); | 2274 GURL("http:////www.a.com/1")); |
2274 | 2275 |
2275 // More navigations. | 2276 // More navigations. |
2276 for (int i = 0; i < 3; i++) { | 2277 for (int i = 0; i < 3; i++) { |
2277 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); | 2278 url = GURL(base::StringPrintf("http:////www.a.com/%d", url_index)); |
2278 controller.LoadURL( | 2279 controller.LoadURL( |
2279 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2280 url, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2280 test_rvh()->SendNavigate(url_index, url); | 2281 main_test_rfh()->SendNavigate(url_index, url); |
2281 url_index++; | 2282 url_index++; |
2282 } | 2283 } |
2283 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); | 2284 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
2284 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), | 2285 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), |
2285 GURL("http:////www.a.com/4")); | 2286 GURL("http:////www.a.com/4")); |
2286 | 2287 |
2287 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); | 2288 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); |
2288 } | 2289 } |
2289 | 2290 |
2290 // Tests that we can do a restore and navigate to the restored entries and | 2291 // Tests that we can do a restore and navigate to the restored entries and |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2331 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, | 2332 EXPECT_EQ(NavigationEntryImpl::RESTORE_NONE, |
2332 NavigationEntryImpl::FromNavigationEntry | 2333 NavigationEntryImpl::FromNavigationEntry |
2333 (our_controller.GetEntryAtIndex(0))->restore_type()); | 2334 (our_controller.GetEntryAtIndex(0))->restore_type()); |
2334 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( | 2335 EXPECT_TRUE(NavigationEntryImpl::FromNavigationEntry( |
2335 our_controller.GetEntryAtIndex(0))->site_instance()); | 2336 our_controller.GetEntryAtIndex(0))->site_instance()); |
2336 | 2337 |
2337 // Timestamp should remain the same before the navigation finishes. | 2338 // Timestamp should remain the same before the navigation finishes. |
2338 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); | 2339 EXPECT_EQ(timestamp, our_controller.GetEntryAtIndex(0)->GetTimestamp()); |
2339 | 2340 |
2340 // Say we navigated to that entry. | 2341 // Say we navigated to that entry. |
2341 ViewHostMsg_FrameNavigate_Params params; | 2342 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2342 params.page_id = 0; | 2343 params.page_id = 0; |
2343 params.url = url; | 2344 params.url = url; |
2344 params.transition = PAGE_TRANSITION_LINK; | 2345 params.transition = PAGE_TRANSITION_LINK; |
2345 params.should_update_history = false; | 2346 params.should_update_history = false; |
2346 params.gesture = NavigationGestureUser; | 2347 params.gesture = NavigationGestureUser; |
2347 params.is_post = false; | 2348 params.is_post = false; |
2348 params.page_state = PageState::CreateFromURL(url); | 2349 params.page_state = PageState::CreateFromURL(url); |
2349 LoadCommittedDetails details; | 2350 LoadCommittedDetails details; |
2350 our_controller.RendererDidNavigate(our_contents->GetRenderViewHost(), params, | 2351 our_controller.RendererDidNavigate(our_contents->GetRenderViewHost(), params, |
2351 &details); | 2352 &details); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2418 fail_load_params.is_main_frame = true; | 2419 fail_load_params.is_main_frame = true; |
2419 fail_load_params.error_code = net::ERR_ABORTED; | 2420 fail_load_params.error_code = net::ERR_ABORTED; |
2420 fail_load_params.error_description = base::string16(); | 2421 fail_load_params.error_description = base::string16(); |
2421 fail_load_params.url = url; | 2422 fail_load_params.url = url; |
2422 fail_load_params.showing_repost_interstitial = false; | 2423 fail_load_params.showing_repost_interstitial = false; |
2423 main_test_rfh()->OnMessageReceived( | 2424 main_test_rfh()->OnMessageReceived( |
2424 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id | 2425 FrameHostMsg_DidFailProvisionalLoadWithError(0, // routing_id |
2425 fail_load_params)); | 2426 fail_load_params)); |
2426 | 2427 |
2427 // Now the pending restored entry commits. | 2428 // Now the pending restored entry commits. |
2428 ViewHostMsg_FrameNavigate_Params params; | 2429 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2429 params.page_id = 0; | 2430 params.page_id = 0; |
2430 params.url = url; | 2431 params.url = url; |
2431 params.transition = PAGE_TRANSITION_LINK; | 2432 params.transition = PAGE_TRANSITION_LINK; |
2432 params.should_update_history = false; | 2433 params.should_update_history = false; |
2433 params.gesture = NavigationGestureUser; | 2434 params.gesture = NavigationGestureUser; |
2434 params.is_post = false; | 2435 params.is_post = false; |
2435 params.page_state = PageState::CreateFromURL(url); | 2436 params.page_state = PageState::CreateFromURL(url); |
2436 LoadCommittedDetails details; | 2437 LoadCommittedDetails details; |
2437 our_controller.RendererDidNavigate(rvh, params, &details); | 2438 our_controller.RendererDidNavigate(rvh, params, &details); |
2438 | 2439 |
(...skipping 10 matching lines...) Expand all Loading... |
2449 our_controller.GetEntryAtIndex(0))->restore_type()); | 2450 our_controller.GetEntryAtIndex(0))->restore_type()); |
2450 } | 2451 } |
2451 | 2452 |
2452 // Make sure that the page type and stuff is correct after an interstitial. | 2453 // Make sure that the page type and stuff is correct after an interstitial. |
2453 TEST_F(NavigationControllerTest, Interstitial) { | 2454 TEST_F(NavigationControllerTest, Interstitial) { |
2454 NavigationControllerImpl& controller = controller_impl(); | 2455 NavigationControllerImpl& controller = controller_impl(); |
2455 // First navigate somewhere normal. | 2456 // First navigate somewhere normal. |
2456 const GURL url1("http://foo"); | 2457 const GURL url1("http://foo"); |
2457 controller.LoadURL( | 2458 controller.LoadURL( |
2458 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2459 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2459 test_rvh()->SendNavigate(0, url1); | 2460 main_test_rfh()->SendNavigate(0, url1); |
2460 | 2461 |
2461 // Now navigate somewhere with an interstitial. | 2462 // Now navigate somewhere with an interstitial. |
2462 const GURL url2("http://bar"); | 2463 const GURL url2("http://bar"); |
2463 controller.LoadURL( | 2464 controller.LoadURL( |
2464 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2465 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2465 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2466 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2466 set_page_type(PAGE_TYPE_INTERSTITIAL); | 2467 set_page_type(PAGE_TYPE_INTERSTITIAL); |
2467 | 2468 |
2468 // At this point the interstitial will be displayed and the load will still | 2469 // At this point the interstitial will be displayed and the load will still |
2469 // be pending. If the user continues, the load will commit. | 2470 // be pending. If the user continues, the load will commit. |
2470 test_rvh()->SendNavigate(1, url2); | 2471 main_test_rfh()->SendNavigate(1, url2); |
2471 | 2472 |
2472 // The page should be a normal page again. | 2473 // The page should be a normal page again. |
2473 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2474 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2474 EXPECT_EQ(PAGE_TYPE_NORMAL, | 2475 EXPECT_EQ(PAGE_TYPE_NORMAL, |
2475 controller.GetLastCommittedEntry()->GetPageType()); | 2476 controller.GetLastCommittedEntry()->GetPageType()); |
2476 } | 2477 } |
2477 | 2478 |
2478 TEST_F(NavigationControllerTest, RemoveEntry) { | 2479 TEST_F(NavigationControllerTest, RemoveEntry) { |
2479 NavigationControllerImpl& controller = controller_impl(); | 2480 NavigationControllerImpl& controller = controller_impl(); |
2480 const GURL url1("http://foo/1"); | 2481 const GURL url1("http://foo/1"); |
2481 const GURL url2("http://foo/2"); | 2482 const GURL url2("http://foo/2"); |
2482 const GURL url3("http://foo/3"); | 2483 const GURL url3("http://foo/3"); |
2483 const GURL url4("http://foo/4"); | 2484 const GURL url4("http://foo/4"); |
2484 const GURL url5("http://foo/5"); | 2485 const GURL url5("http://foo/5"); |
2485 const GURL pending_url("http://foo/pending"); | 2486 const GURL pending_url("http://foo/pending"); |
2486 const GURL default_url("http://foo/default"); | 2487 const GURL default_url("http://foo/default"); |
2487 | 2488 |
2488 controller.LoadURL( | 2489 controller.LoadURL( |
2489 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2490 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2490 test_rvh()->SendNavigate(0, url1); | 2491 main_test_rfh()->SendNavigate(0, url1); |
2491 controller.LoadURL( | 2492 controller.LoadURL( |
2492 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2493 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2493 test_rvh()->SendNavigate(1, url2); | 2494 main_test_rfh()->SendNavigate(1, url2); |
2494 controller.LoadURL( | 2495 controller.LoadURL( |
2495 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2496 url3, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2496 test_rvh()->SendNavigate(2, url3); | 2497 main_test_rfh()->SendNavigate(2, url3); |
2497 controller.LoadURL( | 2498 controller.LoadURL( |
2498 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2499 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2499 test_rvh()->SendNavigate(3, url4); | 2500 main_test_rfh()->SendNavigate(3, url4); |
2500 controller.LoadURL( | 2501 controller.LoadURL( |
2501 url5, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2502 url5, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2502 test_rvh()->SendNavigate(4, url5); | 2503 main_test_rfh()->SendNavigate(4, url5); |
2503 | 2504 |
2504 // Try to remove the last entry. Will fail because it is the current entry. | 2505 // Try to remove the last entry. Will fail because it is the current entry. |
2505 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2506 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2506 EXPECT_EQ(5, controller.GetEntryCount()); | 2507 EXPECT_EQ(5, controller.GetEntryCount()); |
2507 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); | 2508 EXPECT_EQ(4, controller.GetLastCommittedEntryIndex()); |
2508 | 2509 |
2509 // Go back, but don't commit yet. Check that we can't delete the current | 2510 // Go back, but don't commit yet. Check that we can't delete the current |
2510 // and pending entries. | 2511 // and pending entries. |
2511 controller.GoBack(); | 2512 controller.GoBack(); |
2512 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2513 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2513 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); | 2514 EXPECT_FALSE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 2)); |
2514 | 2515 |
2515 // Now commit and delete the last entry. | 2516 // Now commit and delete the last entry. |
2516 test_rvh()->SendNavigate(3, url4); | 2517 main_test_rfh()->SendNavigate(3, url4); |
2517 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); | 2518 EXPECT_TRUE(controller.RemoveEntryAtIndex(controller.GetEntryCount() - 1)); |
2518 EXPECT_EQ(4, controller.GetEntryCount()); | 2519 EXPECT_EQ(4, controller.GetEntryCount()); |
2519 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); | 2520 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex()); |
2520 EXPECT_FALSE(controller.GetPendingEntry()); | 2521 EXPECT_FALSE(controller.GetPendingEntry()); |
2521 | 2522 |
2522 // Remove an entry which is not the last committed one. | 2523 // Remove an entry which is not the last committed one. |
2523 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); | 2524 EXPECT_TRUE(controller.RemoveEntryAtIndex(0)); |
2524 EXPECT_EQ(3, controller.GetEntryCount()); | 2525 EXPECT_EQ(3, controller.GetEntryCount()); |
2525 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | 2526 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
2526 EXPECT_FALSE(controller.GetPendingEntry()); | 2527 EXPECT_FALSE(controller.GetPendingEntry()); |
(...skipping 16 matching lines...) Expand all Loading... |
2543 const GURL url0("http://foo/0"); | 2544 const GURL url0("http://foo/0"); |
2544 const GURL url1("http://foo/1"); | 2545 const GURL url1("http://foo/1"); |
2545 const GURL url2("http://foo/2"); | 2546 const GURL url2("http://foo/2"); |
2546 const GURL url3("http://foo/3"); | 2547 const GURL url3("http://foo/3"); |
2547 const GURL url3_ref("http://foo/3#bar"); | 2548 const GURL url3_ref("http://foo/3#bar"); |
2548 const GURL url4("http://foo/4"); | 2549 const GURL url4("http://foo/4"); |
2549 const GURL transient_url("http://foo/transient"); | 2550 const GURL transient_url("http://foo/transient"); |
2550 | 2551 |
2551 controller.LoadURL( | 2552 controller.LoadURL( |
2552 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2553 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2553 test_rvh()->SendNavigate(0, url0); | 2554 main_test_rfh()->SendNavigate(0, url0); |
2554 controller.LoadURL( | 2555 controller.LoadURL( |
2555 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2556 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2556 test_rvh()->SendNavigate(1, url1); | 2557 main_test_rfh()->SendNavigate(1, url1); |
2557 | 2558 |
2558 notifications.Reset(); | 2559 notifications.Reset(); |
2559 | 2560 |
2560 // Adding a transient with no pending entry. | 2561 // Adding a transient with no pending entry. |
2561 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2562 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2562 transient_entry->SetURL(transient_url); | 2563 transient_entry->SetURL(transient_url); |
2563 controller.SetTransientEntry(transient_entry); | 2564 controller.SetTransientEntry(transient_entry); |
2564 | 2565 |
2565 // We should not have received any notifications. | 2566 // We should not have received any notifications. |
2566 EXPECT_EQ(0U, notifications.size()); | 2567 EXPECT_EQ(0U, notifications.size()); |
2567 | 2568 |
2568 // Check our state. | 2569 // Check our state. |
2569 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2570 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2570 EXPECT_EQ(controller.GetEntryCount(), 3); | 2571 EXPECT_EQ(controller.GetEntryCount(), 3); |
2571 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); | 2572 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 1); |
2572 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); | 2573 EXPECT_EQ(controller.GetPendingEntryIndex(), -1); |
2573 EXPECT_TRUE(controller.GetLastCommittedEntry()); | 2574 EXPECT_TRUE(controller.GetLastCommittedEntry()); |
2574 EXPECT_FALSE(controller.GetPendingEntry()); | 2575 EXPECT_FALSE(controller.GetPendingEntry()); |
2575 EXPECT_TRUE(controller.CanGoBack()); | 2576 EXPECT_TRUE(controller.CanGoBack()); |
2576 EXPECT_FALSE(controller.CanGoForward()); | 2577 EXPECT_FALSE(controller.CanGoForward()); |
2577 EXPECT_EQ(contents()->GetMaxPageID(), 1); | 2578 EXPECT_EQ(contents()->GetMaxPageID(), 1); |
2578 | 2579 |
2579 // Navigate. | 2580 // Navigate. |
2580 controller.LoadURL( | 2581 controller.LoadURL( |
2581 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2582 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2582 test_rvh()->SendNavigate(2, url2); | 2583 main_test_rfh()->SendNavigate(2, url2); |
2583 | 2584 |
2584 // We should have navigated, transient entry should be gone. | 2585 // We should have navigated, transient entry should be gone. |
2585 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2586 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2586 EXPECT_EQ(controller.GetEntryCount(), 3); | 2587 EXPECT_EQ(controller.GetEntryCount(), 3); |
2587 | 2588 |
2588 // Add a transient again, then navigate with no pending entry this time. | 2589 // Add a transient again, then navigate with no pending entry this time. |
2589 transient_entry = new NavigationEntryImpl; | 2590 transient_entry = new NavigationEntryImpl; |
2590 transient_entry->SetURL(transient_url); | 2591 transient_entry->SetURL(transient_url); |
2591 controller.SetTransientEntry(transient_entry); | 2592 controller.SetTransientEntry(transient_entry); |
2592 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2593 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2593 test_rvh()->SendNavigate(3, url3); | 2594 main_test_rfh()->SendNavigate(3, url3); |
2594 // Transient entry should be gone. | 2595 // Transient entry should be gone. |
2595 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2596 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2596 EXPECT_EQ(controller.GetEntryCount(), 4); | 2597 EXPECT_EQ(controller.GetEntryCount(), 4); |
2597 | 2598 |
2598 // Initiate a navigation, add a transient then commit navigation. | 2599 // Initiate a navigation, add a transient then commit navigation. |
2599 controller.LoadURL( | 2600 controller.LoadURL( |
2600 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2601 url4, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2601 transient_entry = new NavigationEntryImpl; | 2602 transient_entry = new NavigationEntryImpl; |
2602 transient_entry->SetURL(transient_url); | 2603 transient_entry->SetURL(transient_url); |
2603 controller.SetTransientEntry(transient_entry); | 2604 controller.SetTransientEntry(transient_entry); |
2604 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2605 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2605 test_rvh()->SendNavigate(4, url4); | 2606 main_test_rfh()->SendNavigate(4, url4); |
2606 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2607 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
2607 EXPECT_EQ(controller.GetEntryCount(), 5); | 2608 EXPECT_EQ(controller.GetEntryCount(), 5); |
2608 | 2609 |
2609 // Add a transient and go back. This should simply remove the transient. | 2610 // Add a transient and go back. This should simply remove the transient. |
2610 transient_entry = new NavigationEntryImpl; | 2611 transient_entry = new NavigationEntryImpl; |
2611 transient_entry->SetURL(transient_url); | 2612 transient_entry->SetURL(transient_url); |
2612 controller.SetTransientEntry(transient_entry); | 2613 controller.SetTransientEntry(transient_entry); |
2613 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2614 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2614 EXPECT_TRUE(controller.CanGoBack()); | 2615 EXPECT_TRUE(controller.CanGoBack()); |
2615 EXPECT_FALSE(controller.CanGoForward()); | 2616 EXPECT_FALSE(controller.CanGoForward()); |
2616 controller.GoBack(); | 2617 controller.GoBack(); |
2617 // Transient entry should be gone. | 2618 // Transient entry should be gone. |
2618 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 2619 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
2619 EXPECT_EQ(controller.GetEntryCount(), 5); | 2620 EXPECT_EQ(controller.GetEntryCount(), 5); |
2620 test_rvh()->SendNavigate(3, url3); | 2621 main_test_rfh()->SendNavigate(3, url3); |
2621 | 2622 |
2622 // Add a transient and go to an entry before the current one. | 2623 // Add a transient and go to an entry before the current one. |
2623 transient_entry = new NavigationEntryImpl; | 2624 transient_entry = new NavigationEntryImpl; |
2624 transient_entry->SetURL(transient_url); | 2625 transient_entry->SetURL(transient_url); |
2625 controller.SetTransientEntry(transient_entry); | 2626 controller.SetTransientEntry(transient_entry); |
2626 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2627 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2627 controller.GoToIndex(1); | 2628 controller.GoToIndex(1); |
2628 // The navigation should have been initiated, transient entry should be gone. | 2629 // The navigation should have been initiated, transient entry should be gone. |
2629 EXPECT_FALSE(controller.GetTransientEntry()); | 2630 EXPECT_FALSE(controller.GetTransientEntry()); |
2630 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2631 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2631 // Visible entry does not update for history navigations until commit. | 2632 // Visible entry does not update for history navigations until commit. |
2632 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2633 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2633 test_rvh()->SendNavigate(1, url1); | 2634 main_test_rfh()->SendNavigate(1, url1); |
2634 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2635 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2635 | 2636 |
2636 // Add a transient and go to an entry after the current one. | 2637 // Add a transient and go to an entry after the current one. |
2637 transient_entry = new NavigationEntryImpl; | 2638 transient_entry = new NavigationEntryImpl; |
2638 transient_entry->SetURL(transient_url); | 2639 transient_entry->SetURL(transient_url); |
2639 controller.SetTransientEntry(transient_entry); | 2640 controller.SetTransientEntry(transient_entry); |
2640 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2641 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2641 controller.GoToIndex(3); | 2642 controller.GoToIndex(3); |
2642 // The navigation should have been initiated, transient entry should be gone. | 2643 // The navigation should have been initiated, transient entry should be gone. |
2643 // Because of the transient entry that is removed, going to index 3 makes us | 2644 // Because of the transient entry that is removed, going to index 3 makes us |
2644 // land on url2 (which is visible after the commit). | 2645 // land on url2 (which is visible after the commit). |
2645 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2646 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
2646 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2647 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2647 test_rvh()->SendNavigate(2, url2); | 2648 main_test_rfh()->SendNavigate(2, url2); |
2648 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2649 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2649 | 2650 |
2650 // Add a transient and go forward. | 2651 // Add a transient and go forward. |
2651 transient_entry = new NavigationEntryImpl; | 2652 transient_entry = new NavigationEntryImpl; |
2652 transient_entry->SetURL(transient_url); | 2653 transient_entry->SetURL(transient_url); |
2653 controller.SetTransientEntry(transient_entry); | 2654 controller.SetTransientEntry(transient_entry); |
2654 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2655 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2655 EXPECT_TRUE(controller.CanGoForward()); | 2656 EXPECT_TRUE(controller.CanGoForward()); |
2656 controller.GoForward(); | 2657 controller.GoForward(); |
2657 // We should have navigated, transient entry should be gone. | 2658 // We should have navigated, transient entry should be gone. |
2658 EXPECT_FALSE(controller.GetTransientEntry()); | 2659 EXPECT_FALSE(controller.GetTransientEntry()); |
2659 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); | 2660 EXPECT_EQ(url3, controller.GetPendingEntry()->GetURL()); |
2660 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); | 2661 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); |
2661 test_rvh()->SendNavigate(3, url3); | 2662 main_test_rfh()->SendNavigate(3, url3); |
2662 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); | 2663 EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); |
2663 | 2664 |
2664 // Add a transient and do an in-page navigation, replacing the current entry. | 2665 // Add a transient and do an in-page navigation, replacing the current entry. |
2665 transient_entry = new NavigationEntryImpl; | 2666 transient_entry = new NavigationEntryImpl; |
2666 transient_entry->SetURL(transient_url); | 2667 transient_entry->SetURL(transient_url); |
2667 controller.SetTransientEntry(transient_entry); | 2668 controller.SetTransientEntry(transient_entry); |
2668 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2669 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2669 test_rvh()->SendNavigate(3, url3_ref); | 2670 main_test_rfh()->SendNavigate(3, url3_ref); |
2670 // Transient entry should be gone. | 2671 // Transient entry should be gone. |
2671 EXPECT_FALSE(controller.GetTransientEntry()); | 2672 EXPECT_FALSE(controller.GetTransientEntry()); |
2672 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); | 2673 EXPECT_EQ(url3_ref, controller.GetVisibleEntry()->GetURL()); |
2673 | 2674 |
2674 // Ensure the URLs are correct. | 2675 // Ensure the URLs are correct. |
2675 EXPECT_EQ(controller.GetEntryCount(), 5); | 2676 EXPECT_EQ(controller.GetEntryCount(), 5); |
2676 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2677 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
2677 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); | 2678 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), url1); |
2678 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); | 2679 EXPECT_EQ(controller.GetEntryAtIndex(2)->GetURL(), url2); |
2679 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); | 2680 EXPECT_EQ(controller.GetEntryAtIndex(3)->GetURL(), url3_ref); |
2680 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); | 2681 EXPECT_EQ(controller.GetEntryAtIndex(4)->GetURL(), url4); |
2681 } | 2682 } |
2682 | 2683 |
2683 // Test that Reload initiates a new navigation to a transient entry's URL. | 2684 // Test that Reload initiates a new navigation to a transient entry's URL. |
2684 TEST_F(NavigationControllerTest, ReloadTransient) { | 2685 TEST_F(NavigationControllerTest, ReloadTransient) { |
2685 NavigationControllerImpl& controller = controller_impl(); | 2686 NavigationControllerImpl& controller = controller_impl(); |
2686 const GURL url0("http://foo/0"); | 2687 const GURL url0("http://foo/0"); |
2687 const GURL url1("http://foo/1"); | 2688 const GURL url1("http://foo/1"); |
2688 const GURL transient_url("http://foo/transient"); | 2689 const GURL transient_url("http://foo/transient"); |
2689 | 2690 |
2690 // Load |url0|, and start a pending navigation to |url1|. | 2691 // Load |url0|, and start a pending navigation to |url1|. |
2691 controller.LoadURL( | 2692 controller.LoadURL( |
2692 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2693 url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2693 test_rvh()->SendNavigate(0, url0); | 2694 main_test_rfh()->SendNavigate(0, url0); |
2694 controller.LoadURL( | 2695 controller.LoadURL( |
2695 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2696 url1, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2696 | 2697 |
2697 // A transient entry is added, interrupting the navigation. | 2698 // A transient entry is added, interrupting the navigation. |
2698 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; | 2699 NavigationEntryImpl* transient_entry = new NavigationEntryImpl; |
2699 transient_entry->SetURL(transient_url); | 2700 transient_entry->SetURL(transient_url); |
2700 controller.SetTransientEntry(transient_entry); | 2701 controller.SetTransientEntry(transient_entry); |
2701 EXPECT_TRUE(controller.GetTransientEntry()); | 2702 EXPECT_TRUE(controller.GetTransientEntry()); |
2702 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2703 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2703 | 2704 |
2704 // The page is reloaded, which should remove the pending entry for |url1| and | 2705 // The page is reloaded, which should remove the pending entry for |url1| and |
2705 // the transient entry for |transient_url|, and start a navigation to | 2706 // the transient entry for |transient_url|, and start a navigation to |
2706 // |transient_url|. | 2707 // |transient_url|. |
2707 controller.Reload(true); | 2708 controller.Reload(true); |
2708 EXPECT_FALSE(controller.GetTransientEntry()); | 2709 EXPECT_FALSE(controller.GetTransientEntry()); |
2709 EXPECT_TRUE(controller.GetPendingEntry()); | 2710 EXPECT_TRUE(controller.GetPendingEntry()); |
2710 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); | 2711 EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); |
2711 ASSERT_EQ(controller.GetEntryCount(), 1); | 2712 ASSERT_EQ(controller.GetEntryCount(), 1); |
2712 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2713 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
2713 | 2714 |
2714 // Load of |transient_url| completes. | 2715 // Load of |transient_url| completes. |
2715 test_rvh()->SendNavigate(1, transient_url); | 2716 main_test_rfh()->SendNavigate(1, transient_url); |
2716 ASSERT_EQ(controller.GetEntryCount(), 2); | 2717 ASSERT_EQ(controller.GetEntryCount(), 2); |
2717 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); | 2718 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); |
2718 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); | 2719 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); |
2719 } | 2720 } |
2720 | 2721 |
2721 // Ensure that renderer initiated pending entries get replaced, so that we | 2722 // Ensure that renderer initiated pending entries get replaced, so that we |
2722 // don't show a stale virtual URL when a navigation commits. | 2723 // don't show a stale virtual URL when a navigation commits. |
2723 // See http://crbug.com/266922. | 2724 // See http://crbug.com/266922. |
2724 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { | 2725 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { |
2725 NavigationControllerImpl& controller = controller_impl(); | 2726 NavigationControllerImpl& controller = controller_impl(); |
(...skipping 18 matching lines...) Expand all Loading... |
2744 EXPECT_TRUE( | 2745 EXPECT_TRUE( |
2745 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2746 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2746 is_renderer_initiated()); | 2747 is_renderer_initiated()); |
2747 | 2748 |
2748 // If the user clicks another link, we should replace the pending entry. | 2749 // If the user clicks another link, we should replace the pending entry. |
2749 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url2); | 2750 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url2); |
2750 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); | 2751 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); |
2751 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); | 2752 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); |
2752 | 2753 |
2753 // Once it commits, the URL and virtual URL should reflect the actual page. | 2754 // Once it commits, the URL and virtual URL should reflect the actual page. |
2754 test_rvh()->SendNavigate(0, url2); | 2755 main_test_rfh()->SendNavigate(0, url2); |
2755 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2756 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2756 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); | 2757 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); |
2757 | 2758 |
2758 // We should not replace the pending entry for an error URL. | 2759 // We should not replace the pending entry for an error URL. |
2759 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1); | 2760 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1); |
2760 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2761 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2761 navigator->DidStartProvisionalLoad( | 2762 navigator->DidStartProvisionalLoad( |
2762 main_test_rfh(), 1, -1, true, GURL(kUnreachableWebDataURL)); | 2763 main_test_rfh(), 1, -1, true, GURL(kUnreachableWebDataURL)); |
2763 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2764 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2764 | 2765 |
2765 // We should remember if the pending entry will replace the current one. | 2766 // We should remember if the pending entry will replace the current one. |
2766 // http://crbug.com/308444. | 2767 // http://crbug.com/308444. |
2767 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1); | 2768 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1); |
2768 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2769 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2769 set_should_replace_entry(true); | 2770 set_should_replace_entry(true); |
2770 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url2); | 2771 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url2); |
2771 EXPECT_TRUE( | 2772 EXPECT_TRUE( |
2772 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2773 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2773 should_replace_entry()); | 2774 should_replace_entry()); |
2774 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need | 2775 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need |
2775 // to go through the RenderViewHost. The TestRenderViewHost routes navigations | 2776 // to go through the RenderViewHost. The TestRenderViewHost routes navigations |
2776 // to the main frame. | 2777 // to the main frame. |
2777 test_rvh()->SendNavigate(0, url2); | 2778 main_test_rfh()->SendNavigate(0, url2); |
2778 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); | 2779 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); |
2779 } | 2780 } |
2780 | 2781 |
2781 // Tests that the URLs for renderer-initiated navigations are not displayed to | 2782 // Tests that the URLs for renderer-initiated navigations are not displayed to |
2782 // the user until the navigation commits, to prevent URL spoof attacks. | 2783 // the user until the navigation commits, to prevent URL spoof attacks. |
2783 // See http://crbug.com/99016. | 2784 // See http://crbug.com/99016. |
2784 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { | 2785 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { |
2785 NavigationControllerImpl& controller = controller_impl(); | 2786 NavigationControllerImpl& controller = controller_impl(); |
2786 TestNotificationTracker notifications; | 2787 TestNotificationTracker notifications; |
2787 RegisterForAllNavNotifications(¬ifications, &controller); | 2788 RegisterForAllNavNotifications(¬ifications, &controller); |
2788 | 2789 |
2789 const GURL url0("http://foo/0"); | 2790 const GURL url0("http://foo/0"); |
2790 const GURL url1("http://foo/1"); | 2791 const GURL url1("http://foo/1"); |
2791 | 2792 |
2792 // For typed navigations (browser-initiated), both pending and visible entries | 2793 // For typed navigations (browser-initiated), both pending and visible entries |
2793 // should update before commit. | 2794 // should update before commit. |
2794 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 2795 controller.LoadURL(url0, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
2795 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); | 2796 EXPECT_EQ(url0, controller.GetPendingEntry()->GetURL()); |
2796 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2797 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
2797 test_rvh()->SendNavigate(0, url0); | 2798 main_test_rfh()->SendNavigate(0, url0); |
2798 | 2799 |
2799 // For link clicks (renderer-initiated navigations), the pending entry should | 2800 // For link clicks (renderer-initiated navigations), the pending entry should |
2800 // update before commit but the visible should not. | 2801 // update before commit but the visible should not. |
2801 NavigationController::LoadURLParams load_url_params(url1); | 2802 NavigationController::LoadURLParams load_url_params(url1); |
2802 load_url_params.is_renderer_initiated = true; | 2803 load_url_params.is_renderer_initiated = true; |
2803 controller.LoadURLWithParams(load_url_params); | 2804 controller.LoadURLWithParams(load_url_params); |
2804 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); | 2805 EXPECT_EQ(url0, controller.GetVisibleEntry()->GetURL()); |
2805 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); | 2806 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); |
2806 EXPECT_TRUE( | 2807 EXPECT_TRUE( |
2807 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2808 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2808 is_renderer_initiated()); | 2809 is_renderer_initiated()); |
2809 | 2810 |
2810 // After commit, both visible should be updated, there should be no pending | 2811 // After commit, both visible should be updated, there should be no pending |
2811 // entry, and we should no longer treat the entry as renderer-initiated. | 2812 // entry, and we should no longer treat the entry as renderer-initiated. |
2812 test_rvh()->SendNavigate(1, url1); | 2813 main_test_rfh()->SendNavigate(1, url1); |
2813 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2814 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2814 EXPECT_FALSE(controller.GetPendingEntry()); | 2815 EXPECT_FALSE(controller.GetPendingEntry()); |
2815 EXPECT_FALSE( | 2816 EXPECT_FALSE( |
2816 NavigationEntryImpl::FromNavigationEntry( | 2817 NavigationEntryImpl::FromNavigationEntry( |
2817 controller.GetLastCommittedEntry())->is_renderer_initiated()); | 2818 controller.GetLastCommittedEntry())->is_renderer_initiated()); |
2818 | 2819 |
2819 notifications.Reset(); | 2820 notifications.Reset(); |
2820 } | 2821 } |
2821 | 2822 |
2822 // Tests that the URLs for renderer-initiated navigations in new tabs are | 2823 // Tests that the URLs for renderer-initiated navigations in new tabs are |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2875 load_url_params.is_renderer_initiated = true; | 2876 load_url_params.is_renderer_initiated = true; |
2876 controller.LoadURLWithParams(load_url_params); | 2877 controller.LoadURLWithParams(load_url_params); |
2877 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2878 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2878 EXPECT_TRUE( | 2879 EXPECT_TRUE( |
2879 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> | 2880 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> |
2880 is_renderer_initiated()); | 2881 is_renderer_initiated()); |
2881 EXPECT_TRUE(controller.IsInitialNavigation()); | 2882 EXPECT_TRUE(controller.IsInitialNavigation()); |
2882 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2883 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); |
2883 | 2884 |
2884 // Simulate a commit and then starting a new pending navigation. | 2885 // Simulate a commit and then starting a new pending navigation. |
2885 test_rvh()->SendNavigate(0, url1); | 2886 main_test_rfh()->SendNavigate(0, url1); |
2886 NavigationController::LoadURLParams load_url2_params(url2); | 2887 NavigationController::LoadURLParams load_url2_params(url2); |
2887 load_url2_params.transition_type = PAGE_TRANSITION_LINK; | 2888 load_url2_params.transition_type = PAGE_TRANSITION_LINK; |
2888 load_url2_params.is_renderer_initiated = true; | 2889 load_url2_params.is_renderer_initiated = true; |
2889 controller.LoadURLWithParams(load_url2_params); | 2890 controller.LoadURLWithParams(load_url2_params); |
2890 | 2891 |
2891 // We should not consider this an initial navigation, and thus should | 2892 // We should not consider this an initial navigation, and thus should |
2892 // not show the pending URL. | 2893 // not show the pending URL. |
2893 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); | 2894 EXPECT_FALSE(test_rvh()->has_accessed_initial_document()); |
2894 EXPECT_FALSE(controller.IsInitialNavigation()); | 2895 EXPECT_FALSE(controller.IsInitialNavigation()); |
2895 EXPECT_TRUE(controller.GetVisibleEntry()); | 2896 EXPECT_TRUE(controller.GetVisibleEntry()); |
2896 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); | 2897 EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); |
2897 | 2898 |
2898 notifications.Reset(); | 2899 notifications.Reset(); |
2899 } | 2900 } |
2900 | 2901 |
2901 // Tests that IsInPageNavigation returns appropriate results. Prevents | 2902 // Tests that IsInPageNavigation returns appropriate results. Prevents |
2902 // regression for bug 1126349. | 2903 // regression for bug 1126349. |
2903 TEST_F(NavigationControllerTest, IsInPageNavigation) { | 2904 TEST_F(NavigationControllerTest, IsInPageNavigation) { |
2904 NavigationControllerImpl& controller = controller_impl(); | 2905 NavigationControllerImpl& controller = controller_impl(); |
2905 // Navigate to URL with no refs. | 2906 // Navigate to URL with no refs. |
2906 const GURL url("http://www.google.com/home.html"); | 2907 const GURL url("http://www.google.com/home.html"); |
2907 test_rvh()->SendNavigate(0, url); | 2908 main_test_rfh()->SendNavigate(0, url); |
2908 | 2909 |
2909 // Reloading the page is not an in-page navigation. | 2910 // Reloading the page is not an in-page navigation. |
2910 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); | 2911 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); |
2911 const GURL other_url("http://www.google.com/add.html"); | 2912 const GURL other_url("http://www.google.com/add.html"); |
2912 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); | 2913 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); |
2913 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); | 2914 const GURL url_with_ref("http://www.google.com/home.html#my_ref"); |
2914 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref)); | 2915 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref)); |
2915 | 2916 |
2916 // Navigate to URL with refs. | 2917 // Navigate to URL with refs. |
2917 test_rvh()->SendNavigate(1, url_with_ref); | 2918 main_test_rfh()->SendNavigate(1, url_with_ref); |
2918 | 2919 |
2919 // Reloading the page is not an in-page navigation. | 2920 // Reloading the page is not an in-page navigation. |
2920 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); | 2921 EXPECT_FALSE(controller.IsURLInPageNavigation(url_with_ref)); |
2921 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); | 2922 EXPECT_FALSE(controller.IsURLInPageNavigation(url)); |
2922 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); | 2923 EXPECT_FALSE(controller.IsURLInPageNavigation(other_url)); |
2923 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); | 2924 const GURL other_url_with_ref("http://www.google.com/home.html#my_other_ref"); |
2924 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref)); | 2925 EXPECT_TRUE(controller.IsURLInPageNavigation(other_url_with_ref)); |
2925 | 2926 |
2926 // Going to the same url again will be considered in-page | 2927 // Going to the same url again will be considered in-page |
2927 // if the renderer says it is even if the navigation type isn't IN_PAGE. | 2928 // if the renderer says it is even if the navigation type isn't IN_PAGE. |
2928 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, | 2929 EXPECT_TRUE(controller.IsURLInPageNavigation(url_with_ref, true, |
2929 NAVIGATION_TYPE_UNKNOWN)); | 2930 NAVIGATION_TYPE_UNKNOWN)); |
2930 | 2931 |
2931 // Going back to the non ref url will be considered in-page if the navigation | 2932 // Going back to the non ref url will be considered in-page if the navigation |
2932 // type is IN_PAGE. | 2933 // type is IN_PAGE. |
2933 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, | 2934 EXPECT_TRUE(controller.IsURLInPageNavigation(url, true, |
2934 NAVIGATION_TYPE_IN_PAGE)); | 2935 NAVIGATION_TYPE_IN_PAGE)); |
2935 } | 2936 } |
2936 | 2937 |
2937 // Some pages can have subframes with the same base URL (minus the reference) as | 2938 // Some pages can have subframes with the same base URL (minus the reference) as |
2938 // the main page. Even though this is hard, it can happen, and we don't want | 2939 // the main page. Even though this is hard, it can happen, and we don't want |
2939 // these subframe navigations to affect the toplevel document. They should | 2940 // these subframe navigations to affect the toplevel document. They should |
2940 // instead be ignored. http://crbug.com/5585 | 2941 // instead be ignored. http://crbug.com/5585 |
2941 TEST_F(NavigationControllerTest, SameSubframe) { | 2942 TEST_F(NavigationControllerTest, SameSubframe) { |
2942 NavigationControllerImpl& controller = controller_impl(); | 2943 NavigationControllerImpl& controller = controller_impl(); |
2943 // Navigate the main frame. | 2944 // Navigate the main frame. |
2944 const GURL url("http://www.google.com/"); | 2945 const GURL url("http://www.google.com/"); |
2945 test_rvh()->SendNavigate(0, url); | 2946 main_test_rfh()->SendNavigate(0, url); |
2946 | 2947 |
2947 // We should be at the first navigation entry. | 2948 // We should be at the first navigation entry. |
2948 EXPECT_EQ(controller.GetEntryCount(), 1); | 2949 EXPECT_EQ(controller.GetEntryCount(), 1); |
2949 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); | 2950 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); |
2950 | 2951 |
2951 // Navigate a subframe that would normally count as in-page. | 2952 // Navigate a subframe that would normally count as in-page. |
2952 const GURL subframe("http://www.google.com/#"); | 2953 const GURL subframe("http://www.google.com/#"); |
2953 ViewHostMsg_FrameNavigate_Params params; | 2954 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
2954 params.page_id = 0; | 2955 params.page_id = 0; |
2955 params.url = subframe; | 2956 params.url = subframe; |
2956 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; | 2957 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
2957 params.should_update_history = false; | 2958 params.should_update_history = false; |
2958 params.gesture = NavigationGestureAuto; | 2959 params.gesture = NavigationGestureAuto; |
2959 params.is_post = false; | 2960 params.is_post = false; |
2960 params.page_state = PageState::CreateFromURL(subframe); | 2961 params.page_state = PageState::CreateFromURL(subframe); |
2961 LoadCommittedDetails details; | 2962 LoadCommittedDetails details; |
2962 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details)); | 2963 EXPECT_FALSE(controller.RendererDidNavigate(test_rvh(), params, &details)); |
2963 | 2964 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3058 NavigateAndCommit(url1); | 3059 NavigateAndCommit(url1); |
3059 | 3060 |
3060 // Now start a pending load to a totally different page, but don't commit it. | 3061 // Now start a pending load to a totally different page, but don't commit it. |
3061 const GURL url2("http://bar/"); | 3062 const GURL url2("http://bar/"); |
3062 controller.LoadURL( | 3063 controller.LoadURL( |
3063 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 3064 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
3064 | 3065 |
3065 // Send a subframe update from the first page, as if one had just | 3066 // Send a subframe update from the first page, as if one had just |
3066 // automatically loaded. Auto subframes don't increment the page ID. | 3067 // automatically loaded. Auto subframes don't increment the page ID. |
3067 const GURL url1_sub("http://foo/subframe"); | 3068 const GURL url1_sub("http://foo/subframe"); |
3068 ViewHostMsg_FrameNavigate_Params params; | 3069 FrameHostMsg_DidCommitProvisionalLoad_Params params; |
3069 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); | 3070 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); |
3070 params.url = url1_sub; | 3071 params.url = url1_sub; |
3071 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; | 3072 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME; |
3072 params.should_update_history = false; | 3073 params.should_update_history = false; |
3073 params.gesture = NavigationGestureAuto; | 3074 params.gesture = NavigationGestureAuto; |
3074 params.is_post = false; | 3075 params.is_post = false; |
3075 params.page_state = PageState::CreateFromURL(url1_sub); | 3076 params.page_state = PageState::CreateFromURL(url1_sub); |
3076 LoadCommittedDetails details; | 3077 LoadCommittedDetails details; |
3077 | 3078 |
3078 // This should return false meaning that nothing was actually updated. | 3079 // This should return false meaning that nothing was actually updated. |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 | 3734 |
3734 // We should only have the last committed and pending entries at this point, | 3735 // We should only have the last committed and pending entries at this point, |
3735 // and the pending entry should still not be in the entry list. | 3736 // and the pending entry should still not be in the entry list. |
3736 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3737 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
3737 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); | 3738 EXPECT_EQ(url2, controller.GetEntryAtIndex(0)->GetURL()); |
3738 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3739 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3739 EXPECT_TRUE(controller.GetPendingEntry()); | 3740 EXPECT_TRUE(controller.GetPendingEntry()); |
3740 EXPECT_EQ(1, controller.GetEntryCount()); | 3741 EXPECT_EQ(1, controller.GetEntryCount()); |
3741 | 3742 |
3742 // Try to commit the pending entry. | 3743 // Try to commit the pending entry. |
3743 test_rvh()->SendNavigate(2, url3); | 3744 main_test_rfh()->SendNavigate(2, url3); |
3744 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 3745 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
3745 EXPECT_FALSE(controller.GetPendingEntry()); | 3746 EXPECT_FALSE(controller.GetPendingEntry()); |
3746 EXPECT_EQ(2, controller.GetEntryCount()); | 3747 EXPECT_EQ(2, controller.GetEntryCount()); |
3747 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); | 3748 EXPECT_EQ(url3, controller.GetEntryAtIndex(1)->GetURL()); |
3748 } | 3749 } |
3749 | 3750 |
3750 // Test to ensure that when we do a history navigation back to the current | 3751 // Test to ensure that when we do a history navigation back to the current |
3751 // committed page (e.g., going forward to a slow-loading page, then pressing | 3752 // committed page (e.g., going forward to a slow-loading page, then pressing |
3752 // the back button), we just stop the navigation to prevent the throbber from | 3753 // the back button), we just stop the navigation to prevent the throbber from |
3753 // running continuously. Otherwise, the RenderViewHost forces the throbber to | 3754 // running continuously. Otherwise, the RenderViewHost forces the throbber to |
(...skipping 21 matching lines...) Expand all Loading... |
3775 TEST_F(NavigationControllerTest, IsInitialNavigation) { | 3776 TEST_F(NavigationControllerTest, IsInitialNavigation) { |
3776 NavigationControllerImpl& controller = controller_impl(); | 3777 NavigationControllerImpl& controller = controller_impl(); |
3777 TestNotificationTracker notifications; | 3778 TestNotificationTracker notifications; |
3778 RegisterForAllNavNotifications(¬ifications, &controller); | 3779 RegisterForAllNavNotifications(¬ifications, &controller); |
3779 | 3780 |
3780 // Initial state. | 3781 // Initial state. |
3781 EXPECT_TRUE(controller.IsInitialNavigation()); | 3782 EXPECT_TRUE(controller.IsInitialNavigation()); |
3782 | 3783 |
3783 // After commit, it stays false. | 3784 // After commit, it stays false. |
3784 const GURL url1("http://foo1"); | 3785 const GURL url1("http://foo1"); |
3785 test_rvh()->SendNavigate(0, url1); | 3786 main_test_rfh()->SendNavigate(0, url1); |
3786 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3787 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3787 navigation_entry_committed_counter_ = 0; | 3788 navigation_entry_committed_counter_ = 0; |
3788 EXPECT_FALSE(controller.IsInitialNavigation()); | 3789 EXPECT_FALSE(controller.IsInitialNavigation()); |
3789 | 3790 |
3790 // After starting a new navigation, it stays false. | 3791 // After starting a new navigation, it stays false. |
3791 const GURL url2("http://foo2"); | 3792 const GURL url2("http://foo2"); |
3792 controller.LoadURL( | 3793 controller.LoadURL( |
3793 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); | 3794 url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
3794 } | 3795 } |
3795 | 3796 |
3796 // Check that the favicon is not reused across a client redirect. | 3797 // Check that the favicon is not reused across a client redirect. |
3797 // (crbug.com/28515) | 3798 // (crbug.com/28515) |
3798 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { | 3799 TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { |
3799 const GURL kPageWithFavicon("http://withfavicon.html"); | 3800 const GURL kPageWithFavicon("http://withfavicon.html"); |
3800 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); | 3801 const GURL kPageWithoutFavicon("http://withoutfavicon.html"); |
3801 const GURL kIconURL("http://withfavicon.ico"); | 3802 const GURL kIconURL("http://withfavicon.ico"); |
3802 const gfx::Image kDefaultFavicon = FaviconStatus().image; | 3803 const gfx::Image kDefaultFavicon = FaviconStatus().image; |
3803 | 3804 |
3804 NavigationControllerImpl& controller = controller_impl(); | 3805 NavigationControllerImpl& controller = controller_impl(); |
3805 TestNotificationTracker notifications; | 3806 TestNotificationTracker notifications; |
3806 RegisterForAllNavNotifications(¬ifications, &controller); | 3807 RegisterForAllNavNotifications(¬ifications, &controller); |
3807 | 3808 |
3808 test_rvh()->SendNavigate(0, kPageWithFavicon); | 3809 main_test_rfh()->SendNavigate(0, kPageWithFavicon); |
3809 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3810 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3810 navigation_entry_committed_counter_ = 0; | 3811 navigation_entry_committed_counter_ = 0; |
3811 | 3812 |
3812 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 3813 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
3813 EXPECT_TRUE(entry); | 3814 EXPECT_TRUE(entry); |
3814 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); | 3815 EXPECT_EQ(kPageWithFavicon, entry->GetURL()); |
3815 | 3816 |
3816 // Simulate Chromium having set the favicon for |kPageWithFavicon|. | 3817 // Simulate Chromium having set the favicon for |kPageWithFavicon|. |
3817 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 3818 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
3818 favicon_status.image = CreateImage(SK_ColorWHITE); | 3819 favicon_status.image = CreateImage(SK_ColorWHITE); |
3819 favicon_status.url = kIconURL; | 3820 favicon_status.url = kIconURL; |
3820 favicon_status.valid = true; | 3821 favicon_status.valid = true; |
3821 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 3822 EXPECT_FALSE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
3822 | 3823 |
3823 test_rvh()->SendNavigateWithTransition( | 3824 main_test_rfh()->SendNavigateWithTransition( |
3824 0, // same page ID. | 3825 0, // same page ID. |
3825 kPageWithoutFavicon, | 3826 kPageWithoutFavicon, |
3826 PAGE_TRANSITION_CLIENT_REDIRECT); | 3827 PAGE_TRANSITION_CLIENT_REDIRECT); |
3827 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3828 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3828 navigation_entry_committed_counter_ = 0; | 3829 navigation_entry_committed_counter_ = 0; |
3829 | 3830 |
3830 entry = controller.GetLastCommittedEntry(); | 3831 entry = controller.GetLastCommittedEntry(); |
3831 EXPECT_TRUE(entry); | 3832 EXPECT_TRUE(entry); |
3832 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); | 3833 EXPECT_EQ(kPageWithoutFavicon, entry->GetURL()); |
3833 | 3834 |
3834 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); | 3835 EXPECT_TRUE(DoImagesMatch(kDefaultFavicon, entry->GetFavicon().image)); |
3835 } | 3836 } |
3836 | 3837 |
3837 // Check that the favicon is not cleared for NavigationEntries which were | 3838 // Check that the favicon is not cleared for NavigationEntries which were |
3838 // previously navigated to. | 3839 // previously navigated to. |
3839 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { | 3840 TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { |
3840 const GURL kUrl1("http://www.a.com/1"); | 3841 const GURL kUrl1("http://www.a.com/1"); |
3841 const GURL kUrl2("http://www.a.com/2"); | 3842 const GURL kUrl2("http://www.a.com/2"); |
3842 const GURL kIconURL("http://www.a.com/1/favicon.ico"); | 3843 const GURL kIconURL("http://www.a.com/1/favicon.ico"); |
3843 | 3844 |
3844 NavigationControllerImpl& controller = controller_impl(); | 3845 NavigationControllerImpl& controller = controller_impl(); |
3845 TestNotificationTracker notifications; | 3846 TestNotificationTracker notifications; |
3846 RegisterForAllNavNotifications(¬ifications, &controller); | 3847 RegisterForAllNavNotifications(¬ifications, &controller); |
3847 | 3848 |
3848 test_rvh()->SendNavigate(0, kUrl1); | 3849 main_test_rfh()->SendNavigate(0, kUrl1); |
3849 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3850 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3850 navigation_entry_committed_counter_ = 0; | 3851 navigation_entry_committed_counter_ = 0; |
3851 | 3852 |
3852 // Simulate Chromium having set the favicon for |kUrl1|. | 3853 // Simulate Chromium having set the favicon for |kUrl1|. |
3853 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); | 3854 gfx::Image favicon_image = CreateImage(SK_ColorWHITE); |
3854 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 3855 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
3855 EXPECT_TRUE(entry); | 3856 EXPECT_TRUE(entry); |
3856 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 3857 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
3857 favicon_status.image = favicon_image; | 3858 favicon_status.image = favicon_image; |
3858 favicon_status.url = kIconURL; | 3859 favicon_status.url = kIconURL; |
3859 favicon_status.valid = true; | 3860 favicon_status.valid = true; |
3860 | 3861 |
3861 // Navigate to another page and go back to the original page. | 3862 // Navigate to another page and go back to the original page. |
3862 test_rvh()->SendNavigate(1, kUrl2); | 3863 main_test_rfh()->SendNavigate(1, kUrl2); |
3863 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3864 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3864 navigation_entry_committed_counter_ = 0; | 3865 navigation_entry_committed_counter_ = 0; |
3865 test_rvh()->SendNavigateWithTransition( | 3866 main_test_rfh()->SendNavigateWithTransition( |
3866 0, | 3867 0, |
3867 kUrl1, | 3868 kUrl1, |
3868 PAGE_TRANSITION_FORWARD_BACK); | 3869 PAGE_TRANSITION_FORWARD_BACK); |
3869 EXPECT_EQ(1U, navigation_entry_committed_counter_); | 3870 EXPECT_EQ(1U, navigation_entry_committed_counter_); |
3870 navigation_entry_committed_counter_ = 0; | 3871 navigation_entry_committed_counter_ = 0; |
3871 | 3872 |
3872 // Verify that the favicon for the page at |kUrl1| was not cleared. | 3873 // Verify that the favicon for the page at |kUrl1| was not cleared. |
3873 entry = controller.GetEntryAtIndex(0); | 3874 entry = controller.GetEntryAtIndex(0); |
3874 EXPECT_TRUE(entry); | 3875 EXPECT_TRUE(entry); |
3875 EXPECT_EQ(kUrl1, entry->GetURL()); | 3876 EXPECT_EQ(kUrl1, entry->GetURL()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4015 EXPECT_EQ(1, controller.GetEntryCount()); | 4016 EXPECT_EQ(1, controller.GetEntryCount()); |
4016 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 4017 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
4017 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 4018 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
4018 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); | 4019 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); |
4019 EXPECT_FALSE(controller.CanGoBack()); | 4020 EXPECT_FALSE(controller.CanGoBack()); |
4020 EXPECT_FALSE(controller.CanGoForward()); | 4021 EXPECT_FALSE(controller.CanGoForward()); |
4021 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); | 4022 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); |
4022 } | 4023 } |
4023 | 4024 |
4024 } // namespace content | 4025 } // namespace content |
OLD | NEW |