Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/navigation/navigation_manager_impl.h" | 5 #import "ios/web/navigation/navigation_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 9 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
| 10 #import "ios/web/navigation/navigation_manager_delegate.h" | 10 #import "ios/web/navigation/navigation_manager_delegate.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 NavigationManagerTest() : manager_(new NavigationManagerImpl()) { | 34 NavigationManagerTest() : manager_(new NavigationManagerImpl()) { |
| 35 manager_->SetDelegate(&delegate_); | 35 manager_->SetDelegate(&delegate_); |
| 36 manager_->SetBrowserState(&browser_state_); | 36 manager_->SetBrowserState(&browser_state_); |
| 37 controller_.reset( | 37 controller_.reset( |
| 38 [[CRWSessionController alloc] initWithBrowserState:&browser_state_]); | 38 [[CRWSessionController alloc] initWithBrowserState:&browser_state_]); |
| 39 manager_->SetSessionController(controller_.get()); | 39 manager_->SetSessionController(controller_.get()); |
| 40 } | 40 } |
| 41 CRWSessionController* session_controller() { return controller_.get(); } | 41 CRWSessionController* session_controller() { return controller_.get(); } |
| 42 NavigationManagerImpl* navigation_manager() { return manager_.get(); } | 42 NavigationManagerImpl* navigation_manager() { return manager_.get(); } |
| 43 | 43 |
| 44 // Adds a redirect pending item with |url|. | |
| 45 // NOTE: use with discretion only when other fields don't matter. | |
| 46 void AddRedirectPendingItem(GURL url) { | |
| 47 manager_->AddPendingItem(url, Referrer(), | |
| 48 ui::PAGE_TRANSITION_IS_REDIRECT_MASK, | |
| 49 web::NavigationInitiationType::USER_INITIATED); | |
| 50 } | |
| 51 | |
| 44 private: | 52 private: |
| 45 TestBrowserState browser_state_; | 53 TestBrowserState browser_state_; |
| 46 TestNavigationManagerDelegate delegate_; | 54 TestNavigationManagerDelegate delegate_; |
| 47 std::unique_ptr<NavigationManagerImpl> manager_; | 55 std::unique_ptr<NavigationManagerImpl> manager_; |
| 48 base::scoped_nsobject<CRWSessionController> controller_; | 56 base::scoped_nsobject<CRWSessionController> controller_; |
| 49 }; | 57 }; |
| 50 | 58 |
| 51 // Tests state of an empty navigation manager. | 59 // Tests state of an empty navigation manager. |
| 52 TEST_F(NavigationManagerTest, EmptyManager) { | 60 TEST_F(NavigationManagerTest, EmptyManager) { |
| 53 EXPECT_EQ(0, navigation_manager()->GetItemCount()); | 61 EXPECT_EQ(0, navigation_manager()->GetItemCount()); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 navigation_manager()->AddPendingItem( | 599 navigation_manager()->AddPendingItem( |
| 592 GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | 600 GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 593 web::NavigationInitiationType::USER_INITIATED); | 601 web::NavigationInitiationType::USER_INITIATED); |
| 594 [session_controller() commitPendingItem]; | 602 [session_controller() commitPendingItem]; |
| 595 web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem(); | 603 web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem(); |
| 596 | 604 |
| 597 // Verify that |item2|'s UserAgentType is propagated to |item3|. | 605 // Verify that |item2|'s UserAgentType is propagated to |item3|. |
| 598 EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType()); | 606 EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType()); |
| 599 } | 607 } |
| 600 | 608 |
| 601 // Tests that calling |Reload| on NavigationManager leaves the Url of the | 609 // Tests that calling |Reload| with web::ReloadType::NORMAL will not crash when |
| 602 // visible item unchanged. | 610 // there is no item. |
| 603 TEST_F(NavigationManagerTest, ReloadWithNormalReloadType) { | 611 TEST_F(NavigationManagerTest, ReloadEmptyWithNormal) { |
| 612 ASSERT_FALSE(navigation_manager()->GetPendingItem()); | |
| 613 ASSERT_EQ(0, navigation_manager()->GetItemCount()); | |
| 614 navigation_manager()->Reload(web::ReloadType::NORMAL, | |
| 615 false /* check_for_repost */); | |
|
Eugene But (OOO till 7-30)
2017/03/23 00:08:20
Can we also verify that NavigationManagerDelegate:
liaoyuke
2017/03/27 16:22:43
Done.
| |
| 616 } | |
| 617 | |
| 618 // Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of | |
| 619 // the pending item unchanged when there is one. | |
| 620 TEST_F(NavigationManagerTest, ReloadPendingItemWithNormal) { | |
| 604 navigation_manager()->AddPendingItem( | 621 navigation_manager()->AddPendingItem( |
| 605 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | 622 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 606 web::NavigationInitiationType::USER_INITIATED); | 623 web::NavigationInitiationType::USER_INITIATED); |
| 607 ASSERT_TRUE(navigation_manager()->GetVisibleItem()); | 624 ASSERT_TRUE(navigation_manager()->GetPendingItem()); |
| 608 | 625 |
| 609 GURL url_before_reload = navigation_manager()->GetVisibleItem()->GetURL(); | 626 GURL url_before_reload = navigation_manager()->GetPendingItem()->GetURL(); |
| 610 navigation_manager()->Reload(web::ReloadType::NORMAL, | 627 navigation_manager()->Reload(web::ReloadType::NORMAL, |
| 611 false /* check_for_repost */); | 628 false /* check_for_repost */); |
| 629 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 630 EXPECT_EQ(url_before_reload, | |
| 631 navigation_manager()->GetPendingItem()->GetURL()); | |
| 632 } | |
| 612 | 633 |
| 634 // Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of | |
| 635 // the last committed item unchanged when there is no pending item. | |
| 636 TEST_F(NavigationManagerTest, ReloadLastCommittedItemWithNormal) { | |
| 637 navigation_manager()->AddPendingItem( | |
| 638 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | |
| 639 web::NavigationInitiationType::USER_INITIATED); | |
| 640 [session_controller() commitPendingItem]; | |
| 641 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem()); | |
| 642 | |
| 643 GURL url_before_reload = | |
| 644 navigation_manager()->GetLastCommittedItem()->GetURL(); | |
| 645 navigation_manager()->Reload(web::ReloadType::NORMAL, | |
| 646 false /* check_for_repost */); | |
| 647 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem()); | |
| 613 EXPECT_EQ(url_before_reload, | 648 EXPECT_EQ(url_before_reload, |
| 614 navigation_manager()->GetVisibleItem()->GetURL()); | 649 navigation_manager()->GetLastCommittedItem()->GetURL()); |
| 650 } | |
| 651 | |
| 652 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL | |
| 653 // changes the current item's url to its original request url when there is a | |
| 654 // non-redirect pending item. | |
| 655 TEST_F(NavigationManagerTest, ReloadNonRedirectPendingItemWithOriginal) { | |
| 656 navigation_manager()->AddPendingItem( | |
| 657 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | |
| 658 web::NavigationInitiationType::USER_INITIATED); | |
| 659 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 660 | |
| 661 GURL expected_original_url = GURL("http://www.url.com/original"); | |
| 662 navigation_manager()->GetPendingItem()->SetOriginalRequestURL( | |
| 663 expected_original_url); | |
| 664 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL, | |
| 665 false /* check_for_repost */); | |
| 666 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 667 EXPECT_EQ(expected_original_url, | |
| 668 navigation_manager()->GetPendingItem()->GetURL()); | |
| 669 } | |
| 670 | |
| 671 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL skips | |
| 672 // discards redirect pending items and sets the current item as the last | |
| 673 // non-redirect item and changes its url to its original request url when there | |
| 674 // is a redirect pending item. | |
| 675 TEST_F(NavigationManagerTest, ReloadRedirectPendingItemWithOriginal) { | |
| 676 navigation_manager()->AddPendingItem( | |
| 677 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | |
| 678 web::NavigationInitiationType::USER_INITIATED); | |
| 679 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 680 GURL expected_original_url = GURL("http://www.url.com/original"); | |
| 681 navigation_manager()->GetPendingItem()->SetOriginalRequestURL( | |
| 682 expected_original_url); | |
| 683 [session_controller() commitPendingItem]; | |
| 684 | |
| 685 AddRedirectPendingItem(GURL("http://www.url.com/pending")); | |
| 686 | |
| 687 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL, | |
| 688 false /* check_for_repost */); | |
| 689 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem()); | |
| 690 EXPECT_FALSE(navigation_manager()->GetPendingItem()); | |
| 691 EXPECT_EQ(1, navigation_manager()->GetItemCount()); | |
| 692 EXPECT_EQ(expected_original_url, | |
| 693 navigation_manager()->GetLastCommittedItem()->GetURL()); | |
| 694 } | |
| 695 | |
| 696 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL | |
| 697 // skips redirect items and sets the current item as the last non-redirect item | |
| 698 // and changes its url to its original request url when there are multiple | |
| 699 // redirect items. | |
| 700 TEST_F(NavigationManagerTest, ReloadMultipleRedirectItemsWithOriginal) { | |
| 701 navigation_manager()->AddPendingItem( | |
| 702 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | |
| 703 web::NavigationInitiationType::USER_INITIATED); | |
| 704 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 705 GURL expected_original_url = GURL("http://www.url.com/original"); | |
| 706 navigation_manager()->GetPendingItem()->SetOriginalRequestURL( | |
| 707 expected_original_url); | |
| 708 [session_controller() commitPendingItem]; | |
| 709 | |
| 710 AddRedirectPendingItem(GURL("http://www.url.com/1")); | |
| 711 [session_controller() commitPendingItem]; | |
| 712 AddRedirectPendingItem(GURL("http://www.url.com/2")); | |
| 713 [session_controller() commitPendingItem]; | |
| 714 AddRedirectPendingItem(GURL("http://www.url.com/3")); | |
| 715 | |
| 716 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL, | |
| 717 false /* check_for_repost */); | |
| 718 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem()); | |
| 719 EXPECT_FALSE(navigation_manager()->GetPendingItem()); | |
| 720 EXPECT_EQ(1, navigation_manager()->GetItemCount()); | |
| 721 EXPECT_EQ(expected_original_url, | |
| 722 navigation_manager()->GetLastCommittedItem()->GetURL()); | |
| 723 } | |
| 724 | |
| 725 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL | |
| 726 // skips redirect items and sets the current item as the last, instead of | |
| 727 // earliest non-redirect item and changes its url to its original request url | |
| 728 // when there are multiple non-redirect items. | |
| 729 TEST_F(NavigationManagerTest, ReloadItemsWithOriginalNotEarlies) { | |
| 730 navigation_manager()->AddPendingItem( | |
| 731 GURL("http://www.url.com/1"), Referrer(), ui::PAGE_TRANSITION_TYPED, | |
| 732 web::NavigationInitiationType::USER_INITIATED); | |
| 733 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 734 navigation_manager()->GetPendingItem()->SetOriginalRequestURL( | |
| 735 GURL("http://www.url.com/1/original")); | |
| 736 [session_controller() commitPendingItem]; | |
| 737 | |
| 738 navigation_manager()->AddPendingItem( | |
| 739 GURL("http://www.url.com/2"), Referrer(), ui::PAGE_TRANSITION_TYPED, | |
| 740 web::NavigationInitiationType::USER_INITIATED); | |
| 741 ASSERT_TRUE(navigation_manager()->GetPendingItem()); | |
| 742 GURL expected_original_url = GURL("http://www.url.com/original/2"); | |
| 743 navigation_manager()->GetPendingItem()->SetOriginalRequestURL( | |
| 744 expected_original_url); | |
| 745 [session_controller() commitPendingItem]; | |
| 746 | |
| 747 AddRedirectPendingItem(GURL("http://www.url.com/3")); | |
| 748 | |
| 749 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL, | |
| 750 false /* check_for_repost */); | |
| 751 | |
| 752 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem()); | |
| 753 EXPECT_FALSE(navigation_manager()->GetPendingItem()); | |
| 754 EXPECT_EQ(2, navigation_manager()->GetItemCount()); | |
| 755 EXPECT_EQ(expected_original_url, | |
| 756 navigation_manager()->GetLastCommittedItem()->GetURL()); | |
| 615 } | 757 } |
| 616 | 758 |
|
Eugene But (OOO till 7-30)
2017/03/23 00:08:20
We should also test reloading with existing forwar
liaoyuke
2017/03/27 16:22:43
Do you mean redirect items exist before last non-r
Eugene But (OOO till 7-30)
2017/03/27 17:15:47
I mean reloading item which is in the middle of th
| |
| 617 } // namespace web | 759 } // namespace web |
| OLD | NEW |