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

Side by Side Diff: ios/web/navigation/navigation_manager_impl_unittest.mm

Issue 2766453002: Implement Reload for ORIGINAL_REQUEST_URL in NavigationManagerImpl. (Closed)
Patch Set: Addressed comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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"
11 #include "ios/web/public/navigation_item.h" 11 #include "ios/web/public/navigation_item.h"
12 #include "ios/web/public/test/fakes/test_browser_state.h" 12 #include "ios/web/public/test/fakes/test_browser_state.h"
13 #include "ios/web/test/test_url_constants.h" 13 #include "ios/web/test/test_url_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
16 16
17 namespace web { 17 namespace web {
18 namespace { 18 namespace {
19 // Stub class for NavigationManagerDelegate. 19 // Stub class for NavigationManagerDelegate.
20 class TestNavigationManagerDelegate : public NavigationManagerDelegate { 20 class TestNavigationManagerDelegate : public NavigationManagerDelegate {
21 public:
21 void GoToIndex(int index) override {} 22 void GoToIndex(int index) override {}
22 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override {} 23 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override {}
23 void Reload() override {} 24 void Reload() override { reload_called_ = true; }
24 void OnNavigationItemsPruned(size_t pruned_item_count) override {} 25 void OnNavigationItemsPruned(size_t pruned_item_count) override {}
25 void OnNavigationItemChanged() override{}; 26 void OnNavigationItemChanged() override{};
26 void OnNavigationItemCommitted(const LoadCommittedDetails&) override {} 27 void OnNavigationItemCommitted(const LoadCommittedDetails&) override {}
27 WebState* GetWebState() override { return nullptr; } 28 WebState* GetWebState() override { return nullptr; }
29
30 bool ReloadCalled() { return reload_called_; }
Eugene But (OOO till 7-30) 2017/03/27 17:15:47 nit: s/ReloadCalled/reload_called
liaoyuke 2017/03/28 00:16:40 Done.
31
32 private:
33 bool reload_called_ = false;
28 }; 34 };
29 } // namespace 35 } // namespace
30 36
31 // Test fixture for NavigationManagerImpl testing. 37 // Test fixture for NavigationManagerImpl testing.
32 class NavigationManagerTest : public PlatformTest { 38 class NavigationManagerTest : public PlatformTest {
33 protected: 39 protected:
34 NavigationManagerTest() : manager_(new NavigationManagerImpl()) { 40 NavigationManagerTest() : manager_(new NavigationManagerImpl()) {
35 manager_->SetDelegate(&delegate_); 41 manager_->SetDelegate(&delegate_);
36 manager_->SetBrowserState(&browser_state_); 42 manager_->SetBrowserState(&browser_state_);
37 controller_.reset( 43 controller_.reset(
38 [[CRWSessionController alloc] initWithBrowserState:&browser_state_]); 44 [[CRWSessionController alloc] initWithBrowserState:&browser_state_]);
39 manager_->SetSessionController(controller_.get()); 45 manager_->SetSessionController(controller_.get());
40 } 46 }
41 CRWSessionController* session_controller() { return controller_.get(); } 47 CRWSessionController* session_controller() { return controller_.get(); }
42 NavigationManagerImpl* navigation_manager() { return manager_.get(); } 48 NavigationManagerImpl* navigation_manager() { return manager_.get(); }
49 TestNavigationManagerDelegate navigation_manager_delegate() {
50 return delegate_;
51 }
43 52
44 private: 53 private:
45 TestBrowserState browser_state_; 54 TestBrowserState browser_state_;
46 TestNavigationManagerDelegate delegate_; 55 TestNavigationManagerDelegate delegate_;
47 std::unique_ptr<NavigationManagerImpl> manager_; 56 std::unique_ptr<NavigationManagerImpl> manager_;
48 base::scoped_nsobject<CRWSessionController> controller_; 57 base::scoped_nsobject<CRWSessionController> controller_;
49 }; 58 };
50 59
51 // Tests state of an empty navigation manager. 60 // Tests state of an empty navigation manager.
52 TEST_F(NavigationManagerTest, EmptyManager) { 61 TEST_F(NavigationManagerTest, EmptyManager) {
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 navigation_manager()->AddPendingItem( 600 navigation_manager()->AddPendingItem(
592 GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, 601 GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
593 web::NavigationInitiationType::USER_INITIATED); 602 web::NavigationInitiationType::USER_INITIATED);
594 [session_controller() commitPendingItem]; 603 [session_controller() commitPendingItem];
595 web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem(); 604 web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem();
596 605
597 // Verify that |item2|'s UserAgentType is propagated to |item3|. 606 // Verify that |item2|'s UserAgentType is propagated to |item3|.
598 EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType()); 607 EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType());
599 } 608 }
600 609
601 // Tests that calling |Reload| on NavigationManager leaves the Url of the 610 // Tests that calling |Reload| with web::ReloadType::NORMAL will not crash when
602 // visible item unchanged. 611 // there is no item.
Eugene But (OOO till 7-30) 2017/03/27 17:15:47 nit: s/is no item/are no committed and pending ite
liaoyuke 2017/03/28 00:16:40 Done.
603 TEST_F(NavigationManagerTest, ReloadWithNormalReloadType) { 612 TEST_F(NavigationManagerTest, ReloadEmptyWithNormalType) {
613 ASSERT_FALSE(navigation_manager()->GetPendingItem());
614 ASSERT_EQ(0, navigation_manager()->GetItemCount());
615 navigation_manager()->Reload(web::ReloadType::NORMAL,
616 false /* check_for_repost */);
617 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
618 }
619
620 // Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of
621 // the renderer initiated pending item unchanged when there is one.
622 TEST_F(NavigationManagerTest, ReloadRendererPendingItemWithNormalType) {
623 GURL url_before_reload = GURL("http://www.url.com");
624 navigation_manager()->AddPendingItem(
625 url_before_reload, Referrer(), ui::PAGE_TRANSITION_TYPED,
626 web::NavigationInitiationType::RENDERER_INITIATED);
627
628 navigation_manager()->Reload(web::ReloadType::NORMAL,
629 false /* check_for_repost */);
630 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
631
632 ASSERT_TRUE(navigation_manager()->GetPendingItem());
633 EXPECT_EQ(url_before_reload,
634 navigation_manager()->GetPendingItem()->GetURL());
635 }
636
637 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
638 // changes the renderer initiated pending item's url to its original request url
639 // when there is one.
640 TEST_F(NavigationManagerTest, ReloadRendererPendingItemWithOriginalType) {
604 navigation_manager()->AddPendingItem( 641 navigation_manager()->AddPendingItem(
605 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, 642 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
606 web::NavigationInitiationType::USER_INITIATED); 643 web::NavigationInitiationType::RENDERER_INITIATED);
607 ASSERT_TRUE(navigation_manager()->GetVisibleItem()); 644 ASSERT_TRUE(navigation_manager()->GetPendingItem());
608 645 GURL expected_original_url = GURL("http://www.url.com/original");
609 GURL url_before_reload = navigation_manager()->GetVisibleItem()->GetURL(); 646 navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
610 navigation_manager()->Reload(web::ReloadType::NORMAL, 647 expected_original_url);
611 false /* check_for_repost */); 648
612 649 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
613 EXPECT_EQ(url_before_reload, 650 false /* check_for_repost */);
614 navigation_manager()->GetVisibleItem()->GetURL()); 651 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
652
653 ASSERT_TRUE(navigation_manager()->GetPendingItem());
654 EXPECT_EQ(expected_original_url,
655 navigation_manager()->GetPendingItem()->GetURL());
656 }
657
658 // Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of
659 // the user initiated pending item unchanged when there is one.
660 TEST_F(NavigationManagerTest, ReloadUserPendingItemWithNormalType) {
Eugene But (OOO till 7-30) 2017/03/27 17:15:47 Optional nit: Do you want to swap the order for Re
liaoyuke 2017/03/28 00:16:40 Done.
661 GURL url_before_reload = GURL("http://www.url.com");
662 navigation_manager()->AddPendingItem(
663 url_before_reload, Referrer(), ui::PAGE_TRANSITION_TYPED,
664 web::NavigationInitiationType::USER_INITIATED);
665
666 navigation_manager()->Reload(web::ReloadType::NORMAL,
667 false /* check_for_repost */);
668 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
669
670 ASSERT_TRUE(navigation_manager()->GetPendingItem());
671 EXPECT_EQ(url_before_reload,
672 navigation_manager()->GetPendingItem()->GetURL());
673 }
674
675 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
676 // changes the user initiated pending item's url to its original request url
677 // when there is one.
678 TEST_F(NavigationManagerTest, ReloadUserPendingItemWithOriginalType) {
679 navigation_manager()->AddPendingItem(
680 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED,
681 web::NavigationInitiationType::USER_INITIATED);
682 ASSERT_TRUE(navigation_manager()->GetPendingItem());
683 GURL expected_original_url = GURL("http://www.url.com/original");
684 navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
685 expected_original_url);
686
687 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
688 false /* check_for_repost */);
689 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
690
691 ASSERT_TRUE(navigation_manager()->GetPendingItem());
692 EXPECT_EQ(expected_original_url,
693 navigation_manager()->GetPendingItem()->GetURL());
694 }
695
696 // Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of
697 // the last committed item unchanged when there is no pending item.
698 TEST_F(NavigationManagerTest, ReloadLastCommittedItemWithNormalType) {
Eugene But (OOO till 7-30) 2017/03/27 17:15:47 ditto, do you move this test to the rest of web::R
liaoyuke 2017/03/28 00:16:40 Done.
699 navigation_manager()->AddPendingItem(
700 GURL("http://www.url.com/0"), Referrer(), ui::PAGE_TRANSITION_TYPED,
701 web::NavigationInitiationType::USER_INITIATED);
702 [session_controller() commitPendingItem];
703
704 GURL url_before_reload = GURL("http://www.url.com/1");
705 navigation_manager()->AddPendingItem(
706 url_before_reload, Referrer(), ui::PAGE_TRANSITION_TYPED,
707 web::NavigationInitiationType::USER_INITIATED);
708 [session_controller() commitPendingItem];
709
710 navigation_manager()->Reload(web::ReloadType::NORMAL,
711 false /* check_for_repost */);
712 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
713
714 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
715 EXPECT_EQ(url_before_reload,
716 navigation_manager()->GetLastCommittedItem()->GetURL());
717 }
718
719 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
720 // changes the last committed item's url to its original request url when there
721 // is no pending item.
722 TEST_F(NavigationManagerTest, ReloadLastCommittedItemWithOriginalType) {
723 navigation_manager()->AddPendingItem(
724 GURL("http://www.url.com/0"), Referrer(), ui::PAGE_TRANSITION_TYPED,
725 web::NavigationInitiationType::USER_INITIATED);
726 [session_controller() commitPendingItem];
727
728 navigation_manager()->AddPendingItem(
729 GURL("http://www.url.com/1"), Referrer(), ui::PAGE_TRANSITION_TYPED,
730 web::NavigationInitiationType::USER_INITIATED);
731 GURL expected_original_url = GURL("http://www.url.com/1/original");
732 ASSERT_TRUE(navigation_manager()->GetPendingItem());
733 navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
734 expected_original_url);
735 [session_controller() commitPendingItem];
736
737 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
738 false /* check_for_repost */);
739 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
740
741 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
742 EXPECT_EQ(expected_original_url,
743 navigation_manager()->GetLastCommittedItem()->GetURL());
744 }
745
746 // Tests that calling |Reload| with web::ReloadType::NORMAL leaves the url of
Eugene But (OOO till 7-30) 2017/03/27 17:15:47 ditto
liaoyuke 2017/03/28 00:16:40 Done.
747 // the last committed item unchanged when there is no pending item, but there
748 // forward items after last committed item.
749 TEST_F(NavigationManagerTest,
750 ReloadLastCommittedItemWithNormalTypeWithForwardItems) {
751 navigation_manager()->AddPendingItem(
752 GURL("http://www.url.com/0"), Referrer(), ui::PAGE_TRANSITION_TYPED,
753 web::NavigationInitiationType::USER_INITIATED);
754 [session_controller() commitPendingItem];
755
756 GURL url_before_reload = GURL("http://www.url.com/1");
757 navigation_manager()->AddPendingItem(
758 url_before_reload, Referrer(), ui::PAGE_TRANSITION_TYPED,
759 web::NavigationInitiationType::USER_INITIATED);
760 [session_controller() commitPendingItem];
761
762 navigation_manager()->AddPendingItem(
763 GURL("http://www.url.com/2"), Referrer(), ui::PAGE_TRANSITION_TYPED,
764 web::NavigationInitiationType::USER_INITIATED);
765 [session_controller() commitPendingItem];
766
767 [session_controller() goToItemAtIndex:1];
768 EXPECT_EQ(1, navigation_manager()->GetLastCommittedItemIndex());
769
770 navigation_manager()->Reload(web::ReloadType::NORMAL,
771 false /* check_for_repost */);
772 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
773
774 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
775 EXPECT_EQ(url_before_reload,
776 navigation_manager()->GetLastCommittedItem()->GetURL());
777 }
778
779 // Tests that calling |Reload| with web::ReloadType::ORIGINAL_REQUEST_URL
780 // changes the last committed item's url to its original request url when there
781 // is no pending item, but there are forward items after last committed item.
782 TEST_F(NavigationManagerTest,
783 ReloadLastCommittedItemWithOriginalTypeWithForwardItems) {
784 navigation_manager()->AddPendingItem(
785 GURL("http://www.url.com/0"), Referrer(), ui::PAGE_TRANSITION_TYPED,
786 web::NavigationInitiationType::USER_INITIATED);
787 [session_controller() commitPendingItem];
788
789 navigation_manager()->AddPendingItem(
790 GURL("http://www.url.com/1"), Referrer(), ui::PAGE_TRANSITION_TYPED,
791 web::NavigationInitiationType::USER_INITIATED);
792 GURL expected_original_url = GURL("http://www.url.com/1/original");
793 ASSERT_TRUE(navigation_manager()->GetPendingItem());
794 navigation_manager()->GetPendingItem()->SetOriginalRequestURL(
795 expected_original_url);
796 [session_controller() commitPendingItem];
797
798 navigation_manager()->AddPendingItem(
799 GURL("http://www.url.com/2"), Referrer(), ui::PAGE_TRANSITION_TYPED,
800 web::NavigationInitiationType::USER_INITIATED);
801 [session_controller() commitPendingItem];
802
803 [session_controller() goToItemAtIndex:1];
804 EXPECT_EQ(1, navigation_manager()->GetLastCommittedItemIndex());
805
806 navigation_manager()->Reload(web::ReloadType::ORIGINAL_REQUEST_URL,
807 false /* check_for_repost */);
808 EXPECT_TRUE(navigation_manager_delegate().ReloadCalled());
809
810 ASSERT_TRUE(navigation_manager()->GetLastCommittedItem());
811 EXPECT_EQ(expected_original_url,
812 navigation_manager()->GetLastCommittedItem()->GetURL());
615 } 813 }
616 814
617 } // namespace web 815 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698