OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/crw_session_controller.h" | 5 #import "ios/web/navigation/crw_session_controller.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 base::MakeUnique<web::NavigationItemImpl>(); | 681 base::MakeUnique<web::NavigationItemImpl>(); |
682 navigation_item->SetURL(GURL(url)); | 682 navigation_item->SetURL(GURL(url)); |
683 navigation_item->SetReferrer(referrer_object); | 683 navigation_item->SetReferrer(referrer_object); |
684 navigation_item->SetTitle(base::SysNSStringToUTF16(title)); | 684 navigation_item->SetTitle(base::SysNSStringToUTF16(title)); |
685 navigation_item->SetTransitionType(ui::PAGE_TRANSITION_TYPED); | 685 navigation_item->SetTransitionType(ui::PAGE_TRANSITION_TYPED); |
686 | 686 |
687 return navigation_item; | 687 return navigation_item; |
688 } | 688 } |
689 | 689 |
690 TEST_F(CRWSessionControllerTest, CreateWithEmptyNavigations) { | 690 TEST_F(CRWSessionControllerTest, CreateWithEmptyNavigations) { |
691 std::vector<std::unique_ptr<web::NavigationItem>> items; | 691 web::ScopedNavigationItemList items; |
692 base::scoped_nsobject<CRWSessionController> controller( | 692 base::scoped_nsobject<CRWSessionController> controller( |
693 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ | 693 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ |
694 navigationItems:std::move(items) | 694 navigationItems:std::move(items) |
695 currentIndex:0]); | 695 currentIndex:0]); |
696 EXPECT_EQ(controller.get().entries.count, 0U); | 696 EXPECT_EQ(controller.get().entries.count, 0U); |
697 EXPECT_EQ(controller.get().currentNavigationIndex, -1); | 697 EXPECT_EQ(controller.get().currentNavigationIndex, -1); |
698 EXPECT_EQ(controller.get().previousNavigationIndex, -1); | 698 EXPECT_EQ(controller.get().previousNavigationIndex, -1); |
699 EXPECT_FALSE(controller.get().currentEntry); | 699 EXPECT_FALSE(controller.get().currentEntry); |
700 } | 700 } |
701 | 701 |
702 TEST_F(CRWSessionControllerTest, CreateWithNavList) { | 702 TEST_F(CRWSessionControllerTest, CreateWithNavList) { |
703 std::vector<std::unique_ptr<web::NavigationItem>> items; | 703 web::ScopedNavigationItemList items; |
704 items.push_back(CreateNavigationItem("http://www.google.com", | 704 items.push_back(CreateNavigationItem("http://www.google.com", |
705 "http://www.referrer.com", @"Google")); | 705 "http://www.referrer.com", @"Google")); |
706 items.push_back(CreateNavigationItem("http://www.yahoo.com", | 706 items.push_back(CreateNavigationItem("http://www.yahoo.com", |
707 "http://www.google.com", @"Yahoo")); | 707 "http://www.google.com", @"Yahoo")); |
708 items.push_back(CreateNavigationItem("http://www.espn.com", | 708 items.push_back(CreateNavigationItem("http://www.espn.com", |
709 "http://www.nothing.com", @"ESPN")); | 709 "http://www.nothing.com", @"ESPN")); |
710 base::scoped_nsobject<CRWSessionController> controller( | 710 base::scoped_nsobject<CRWSessionController> controller( |
711 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ | 711 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ |
712 navigationItems:std::move(items) | 712 navigationItems:std::move(items) |
713 currentIndex:1]); | 713 currentIndex:1]); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); | 755 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); |
756 | 756 |
757 [session_controller_ goToItemAtIndex:1]; | 757 [session_controller_ goToItemAtIndex:1]; |
758 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 0); | 758 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 0); |
759 | 759 |
760 [session_controller_ goToItemAtIndex:2]; | 760 [session_controller_ goToItemAtIndex:2]; |
761 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); | 761 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); |
762 } | 762 } |
763 | 763 |
764 TEST_F(CRWSessionControllerTest, PushNewEntry) { | 764 TEST_F(CRWSessionControllerTest, PushNewEntry) { |
765 std::vector<std::unique_ptr<web::NavigationItem>> items; | 765 web::ScopedNavigationItemList items; |
766 items.push_back(CreateNavigationItem("http://www.firstpage.com", | 766 items.push_back(CreateNavigationItem("http://www.firstpage.com", |
767 "http://www.starturl.com", @"First")); | 767 "http://www.starturl.com", @"First")); |
768 items.push_back(CreateNavigationItem("http://www.secondpage.com", | 768 items.push_back(CreateNavigationItem("http://www.secondpage.com", |
769 "http://www.firstpage.com", @"Second")); | 769 "http://www.firstpage.com", @"Second")); |
770 items.push_back(CreateNavigationItem("http://www.thirdpage.com", | 770 items.push_back(CreateNavigationItem("http://www.thirdpage.com", |
771 "http://www.secondpage.com", @"Third")); | 771 "http://www.secondpage.com", @"Third")); |
772 base::scoped_nsobject<CRWSessionController> controller( | 772 base::scoped_nsobject<CRWSessionController> controller( |
773 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ | 773 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ |
774 navigationItems:std::move(items) | 774 navigationItems:std::move(items) |
775 currentIndex:0]); | 775 currentIndex:0]); |
(...skipping 22 matching lines...) Expand all Loading... |
798 pushedItem = pushedEntry.navigationItemImpl; | 798 pushedItem = pushedEntry.navigationItemImpl; |
799 expectedCount = 3; | 799 expectedCount = 3; |
800 EXPECT_EQ(expectedCount, controller.get().entries.count); | 800 EXPECT_EQ(expectedCount, controller.get().entries.count); |
801 EXPECT_EQ(pushPageGurl2, pushedEntry.navigationItem->GetURL()); | 801 EXPECT_EQ(pushPageGurl2, pushedEntry.navigationItem->GetURL()); |
802 EXPECT_TRUE(pushedItem->IsCreatedFromPushState()); | 802 EXPECT_TRUE(pushedItem->IsCreatedFromPushState()); |
803 EXPECT_EQ(nil, pushedItem->GetSerializedStateObject()); | 803 EXPECT_EQ(nil, pushedItem->GetSerializedStateObject()); |
804 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetReferrer().url); | 804 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetReferrer().url); |
805 } | 805 } |
806 | 806 |
807 TEST_F(CRWSessionControllerTest, IsSameDocumentNavigation) { | 807 TEST_F(CRWSessionControllerTest, IsSameDocumentNavigation) { |
808 std::vector<std::unique_ptr<web::NavigationItem>> items; | 808 web::ScopedNavigationItemList items; |
809 items.push_back( | 809 items.push_back( |
810 CreateNavigationItem("http://foo.com", "http://google.com", @"First")); | 810 CreateNavigationItem("http://foo.com", "http://google.com", @"First")); |
811 // Push state navigation. | 811 // Push state navigation. |
812 items.push_back( | 812 items.push_back( |
813 CreateNavigationItem("http://foo.com#bar", "http://foo.com", @"Second")); | 813 CreateNavigationItem("http://foo.com#bar", "http://foo.com", @"Second")); |
814 items.push_back(CreateNavigationItem("http://google.com", | 814 items.push_back(CreateNavigationItem("http://google.com", |
815 "http://foo.com#bar", @"Third")); | 815 "http://foo.com#bar", @"Third")); |
816 items.push_back( | 816 items.push_back( |
817 CreateNavigationItem("http://foo.com", "http://google.com", @"Fourth")); | 817 CreateNavigationItem("http://foo.com", "http://google.com", @"Fourth")); |
818 // Push state navigation. | 818 // Push state navigation. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 [controller isSameDocumentNavigationBetweenItem:item4 andItem:item3]); | 851 [controller isSameDocumentNavigationBetweenItem:item4 andItem:item3]); |
852 EXPECT_FALSE( | 852 EXPECT_FALSE( |
853 [controller isSameDocumentNavigationBetweenItem:item1 andItem:item2]); | 853 [controller isSameDocumentNavigationBetweenItem:item1 andItem:item2]); |
854 EXPECT_FALSE( | 854 EXPECT_FALSE( |
855 [controller isSameDocumentNavigationBetweenItem:item0 andItem:item5]); | 855 [controller isSameDocumentNavigationBetweenItem:item0 andItem:item5]); |
856 EXPECT_FALSE( | 856 EXPECT_FALSE( |
857 [controller isSameDocumentNavigationBetweenItem:item2 andItem:item4]); | 857 [controller isSameDocumentNavigationBetweenItem:item2 andItem:item4]); |
858 } | 858 } |
859 | 859 |
860 TEST_F(CRWSessionControllerTest, UpdateCurrentEntry) { | 860 TEST_F(CRWSessionControllerTest, UpdateCurrentEntry) { |
861 std::vector<std::unique_ptr<web::NavigationItem>> items; | 861 web::ScopedNavigationItemList items; |
862 items.push_back(CreateNavigationItem("http://www.firstpage.com", | 862 items.push_back(CreateNavigationItem("http://www.firstpage.com", |
863 "http://www.starturl.com", @"First")); | 863 "http://www.starturl.com", @"First")); |
864 items.push_back(CreateNavigationItem("http://www.secondpage.com", | 864 items.push_back(CreateNavigationItem("http://www.secondpage.com", |
865 "http://www.firstpage.com", @"Second")); | 865 "http://www.firstpage.com", @"Second")); |
866 items.push_back(CreateNavigationItem("http://www.thirdpage.com", | 866 items.push_back(CreateNavigationItem("http://www.thirdpage.com", |
867 "http://www.secondpage.com", @"Third")); | 867 "http://www.secondpage.com", @"Third")); |
868 base::scoped_nsobject<CRWSessionController> controller( | 868 base::scoped_nsobject<CRWSessionController> controller( |
869 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ | 869 [[CRWSessionController alloc] initWithBrowserState:&browser_state_ |
870 navigationItems:std::move(items) | 870 navigationItems:std::move(items) |
871 currentIndex:0]); | 871 currentIndex:0]); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 [session_controller_ | 1143 [session_controller_ |
1144 addPendingItem:GURL("http://www.example.com/0") | 1144 addPendingItem:GURL("http://www.example.com/0") |
1145 referrer:MakeReferrer("http://www.example.com/b") | 1145 referrer:MakeReferrer("http://www.example.com/b") |
1146 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT | 1146 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT |
1147 initiationType:web::NavigationInitiationType::RENDERER_INITIATED]; | 1147 initiationType:web::NavigationInitiationType::RENDERER_INITIATED]; |
1148 [session_controller_ commitPendingItem]; | 1148 [session_controller_ commitPendingItem]; |
1149 EXPECT_EQ(0U, [session_controller_ backwardEntries].count); | 1149 EXPECT_EQ(0U, [session_controller_ backwardEntries].count); |
1150 } | 1150 } |
1151 | 1151 |
1152 } // anonymous namespace | 1152 } // anonymous namespace |
OLD | NEW |