| 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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 14 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 15 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
| 15 #import "ios/web/navigation/crw_session_entry.h" | 16 #import "ios/web/navigation/crw_session_entry.h" |
| 16 #import "ios/web/navigation/navigation_item_impl.h" | 17 #import "ios/web/navigation/navigation_item_impl.h" |
| 17 #include "ios/web/public/referrer.h" | 18 #include "ios/web/public/referrer.h" |
| 18 #include "ios/web/public/test/test_browser_state.h" | 19 #include "ios/web/public/test/test_browser_state.h" |
| 19 #include "ios/web/public/test/test_web_thread_bundle.h" | 20 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 20 #import "net/base/mac/url_conversions.h" | 21 #import "net/base/mac/url_conversions.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #import "testing/gtest_mac.h" | 23 #import "testing/gtest_mac.h" |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 // Tests state of an empty session controller. | 667 // Tests state of an empty session controller. |
| 667 TEST_F(CRWSessionControllerTest, EmptyController) { | 668 TEST_F(CRWSessionControllerTest, EmptyController) { |
| 668 EXPECT_EQ(0U, [[session_controller_ entries] count]); | 669 EXPECT_EQ(0U, [[session_controller_ entries] count]); |
| 669 EXPECT_EQ(-1, [session_controller_ currentNavigationIndex]); | 670 EXPECT_EQ(-1, [session_controller_ currentNavigationIndex]); |
| 670 EXPECT_EQ(-1, [session_controller_ previousNavigationIndex]); | 671 EXPECT_EQ(-1, [session_controller_ previousNavigationIndex]); |
| 671 EXPECT_FALSE([session_controller_ currentEntry]); | 672 EXPECT_FALSE([session_controller_ currentEntry]); |
| 672 EXPECT_FALSE([session_controller_ pendingEntry]); | 673 EXPECT_FALSE([session_controller_ pendingEntry]); |
| 673 EXPECT_EQ(-1, [session_controller_ pendingEntryIndex]); | 674 EXPECT_EQ(-1, [session_controller_ pendingEntryIndex]); |
| 674 } | 675 } |
| 675 | 676 |
| 676 // Helper to create a NavigationItem. Caller is responsible for freeing | 677 // Helper to create a NavigationItem. |
| 677 // the memory. | 678 std::unique_ptr<web::NavigationItemImpl> CreateNavigationItem( |
| 678 web::NavigationItem* CreateNavigationItem(const std::string& url, | 679 const std::string& url, |
| 679 const std::string& referrer, | 680 const std::string& referrer, |
| 680 NSString* title) { | 681 NSString* title) { |
| 681 web::Referrer referrer_object(GURL(referrer), | 682 web::Referrer referrer_object(GURL(referrer), |
| 682 web::ReferrerPolicyDefault); | 683 web::ReferrerPolicyDefault); |
| 683 web::NavigationItemImpl* navigation_item = new web::NavigationItemImpl(); | 684 std::unique_ptr<web::NavigationItemImpl> navigation_item = |
| 685 base::MakeUnique<web::NavigationItemImpl>(); |
| 684 navigation_item->SetURL(GURL(url)); | 686 navigation_item->SetURL(GURL(url)); |
| 685 navigation_item->SetReferrer(referrer_object); | 687 navigation_item->SetReferrer(referrer_object); |
| 686 navigation_item->SetTitle(base::SysNSStringToUTF16(title)); | 688 navigation_item->SetTitle(base::SysNSStringToUTF16(title)); |
| 687 navigation_item->SetTransitionType(ui::PAGE_TRANSITION_TYPED); | 689 navigation_item->SetTransitionType(ui::PAGE_TRANSITION_TYPED); |
| 688 | 690 |
| 689 return navigation_item; | 691 return navigation_item; |
| 690 } | 692 } |
| 691 | 693 |
| 692 TEST_F(CRWSessionControllerTest, CreateWithEmptyNavigations) { | 694 TEST_F(CRWSessionControllerTest, CreateWithEmptyNavigations) { |
| 693 ScopedVector<web::NavigationItem> items; | 695 std::vector<std::unique_ptr<web::NavigationItem>> items; |
| 694 base::scoped_nsobject<CRWSessionController> controller( | 696 base::scoped_nsobject<CRWSessionController> controller( |
| 695 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) | 697 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 696 currentIndex:0 | 698 currentIndex:0 |
| 697 browserState:&browser_state_]); | 699 browserState:&browser_state_]); |
| 698 EXPECT_EQ(controller.get().entries.count, 0U); | 700 EXPECT_EQ(controller.get().entries.count, 0U); |
| 699 EXPECT_EQ(controller.get().currentNavigationIndex, -1); | 701 EXPECT_EQ(controller.get().currentNavigationIndex, -1); |
| 700 EXPECT_EQ(controller.get().previousNavigationIndex, -1); | 702 EXPECT_EQ(controller.get().previousNavigationIndex, -1); |
| 701 EXPECT_FALSE(controller.get().currentEntry); | 703 EXPECT_FALSE(controller.get().currentEntry); |
| 702 } | 704 } |
| 703 | 705 |
| 704 TEST_F(CRWSessionControllerTest, CreateWithNavList) { | 706 TEST_F(CRWSessionControllerTest, CreateWithNavList) { |
| 705 ScopedVector<web::NavigationItem> items; | 707 std::vector<std::unique_ptr<web::NavigationItem>> items; |
| 706 items.push_back(CreateNavigationItem("http://www.google.com", | 708 items.push_back(CreateNavigationItem("http://www.google.com", |
| 707 "http://www.referrer.com", @"Google")); | 709 "http://www.referrer.com", @"Google")); |
| 708 items.push_back(CreateNavigationItem("http://www.yahoo.com", | 710 items.push_back(CreateNavigationItem("http://www.yahoo.com", |
| 709 "http://www.google.com", @"Yahoo")); | 711 "http://www.google.com", @"Yahoo")); |
| 710 items.push_back(CreateNavigationItem("http://www.espn.com", | 712 items.push_back(CreateNavigationItem("http://www.espn.com", |
| 711 "http://www.nothing.com", @"ESPN")); | 713 "http://www.nothing.com", @"ESPN")); |
| 712 base::scoped_nsobject<CRWSessionController> controller( | 714 base::scoped_nsobject<CRWSessionController> controller( |
| 713 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) | 715 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 714 currentIndex:1 | 716 currentIndex:1 |
| 715 browserState:&browser_state_]); | 717 browserState:&browser_state_]); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); | 760 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); |
| 759 | 761 |
| 760 [session_controller_ goToEntryAtIndex:1]; | 762 [session_controller_ goToEntryAtIndex:1]; |
| 761 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 0); | 763 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 0); |
| 762 | 764 |
| 763 [session_controller_ goToEntryAtIndex:2]; | 765 [session_controller_ goToEntryAtIndex:2]; |
| 764 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); | 766 EXPECT_EQ(session_controller_.get().previousNavigationIndex, 1); |
| 765 } | 767 } |
| 766 | 768 |
| 767 TEST_F(CRWSessionControllerTest, PushNewEntry) { | 769 TEST_F(CRWSessionControllerTest, PushNewEntry) { |
| 768 ScopedVector<web::NavigationItem> items; | 770 std::vector<std::unique_ptr<web::NavigationItem>> items; |
| 769 items.push_back(CreateNavigationItem("http://www.firstpage.com", | 771 items.push_back(CreateNavigationItem("http://www.firstpage.com", |
| 770 "http://www.starturl.com", @"First")); | 772 "http://www.starturl.com", @"First")); |
| 771 items.push_back(CreateNavigationItem("http://www.secondpage.com", | 773 items.push_back(CreateNavigationItem("http://www.secondpage.com", |
| 772 "http://www.firstpage.com", @"Second")); | 774 "http://www.firstpage.com", @"Second")); |
| 773 items.push_back(CreateNavigationItem("http://www.thirdpage.com", | 775 items.push_back(CreateNavigationItem("http://www.thirdpage.com", |
| 774 "http://www.secondpage.com", @"Third")); | 776 "http://www.secondpage.com", @"Third")); |
| 775 base::scoped_nsobject<CRWSessionController> controller( | 777 base::scoped_nsobject<CRWSessionController> controller( |
| 776 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) | 778 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 777 currentIndex:0 | 779 currentIndex:0 |
| 778 browserState:&browser_state_]); | 780 browserState:&browser_state_]); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 801 pushedItem = pushedEntry.navigationItemImpl; | 803 pushedItem = pushedEntry.navigationItemImpl; |
| 802 expectedCount = 3; | 804 expectedCount = 3; |
| 803 EXPECT_EQ(expectedCount, controller.get().entries.count); | 805 EXPECT_EQ(expectedCount, controller.get().entries.count); |
| 804 EXPECT_EQ(pushPageGurl2, pushedEntry.navigationItem->GetURL()); | 806 EXPECT_EQ(pushPageGurl2, pushedEntry.navigationItem->GetURL()); |
| 805 EXPECT_TRUE(pushedItem->IsCreatedFromPushState()); | 807 EXPECT_TRUE(pushedItem->IsCreatedFromPushState()); |
| 806 EXPECT_EQ(nil, pushedItem->GetSerializedStateObject()); | 808 EXPECT_EQ(nil, pushedItem->GetSerializedStateObject()); |
| 807 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetReferrer().url); | 809 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetReferrer().url); |
| 808 } | 810 } |
| 809 | 811 |
| 810 TEST_F(CRWSessionControllerTest, IsSameDocumentNavigation) { | 812 TEST_F(CRWSessionControllerTest, IsSameDocumentNavigation) { |
| 811 ScopedVector<web::NavigationItem> items; | 813 std::vector<std::unique_ptr<web::NavigationItem>> items; |
| 812 items.push_back( | 814 items.push_back( |
| 813 CreateNavigationItem("http://foo.com", "http://google.com", @"First")); | 815 CreateNavigationItem("http://foo.com", "http://google.com", @"First")); |
| 814 // Push state navigation. | 816 // Push state navigation. |
| 815 items.push_back( | 817 items.push_back( |
| 816 CreateNavigationItem("http://foo.com#bar", "http://foo.com", @"Second")); | 818 CreateNavigationItem("http://foo.com#bar", "http://foo.com", @"Second")); |
| 817 items.push_back(CreateNavigationItem("http://google.com", | 819 items.push_back(CreateNavigationItem("http://google.com", |
| 818 "http://foo.com#bar", @"Third")); | 820 "http://foo.com#bar", @"Third")); |
| 819 items.push_back( | 821 items.push_back( |
| 820 CreateNavigationItem("http://foo.com", "http://google.com", @"Fourth")); | 822 CreateNavigationItem("http://foo.com", "http://google.com", @"Fourth")); |
| 821 // Push state navigation. | 823 // Push state navigation. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 848 [controller isSameDocumentNavigationBetweenEntry:entry4 andEntry:entry3]); | 850 [controller isSameDocumentNavigationBetweenEntry:entry4 andEntry:entry3]); |
| 849 EXPECT_FALSE( | 851 EXPECT_FALSE( |
| 850 [controller isSameDocumentNavigationBetweenEntry:entry1 andEntry:entry2]); | 852 [controller isSameDocumentNavigationBetweenEntry:entry1 andEntry:entry2]); |
| 851 EXPECT_FALSE( | 853 EXPECT_FALSE( |
| 852 [controller isSameDocumentNavigationBetweenEntry:entry0 andEntry:entry5]); | 854 [controller isSameDocumentNavigationBetweenEntry:entry0 andEntry:entry5]); |
| 853 EXPECT_FALSE( | 855 EXPECT_FALSE( |
| 854 [controller isSameDocumentNavigationBetweenEntry:entry2 andEntry:entry4]); | 856 [controller isSameDocumentNavigationBetweenEntry:entry2 andEntry:entry4]); |
| 855 } | 857 } |
| 856 | 858 |
| 857 TEST_F(CRWSessionControllerTest, UpdateCurrentEntry) { | 859 TEST_F(CRWSessionControllerTest, UpdateCurrentEntry) { |
| 858 ScopedVector<web::NavigationItem> items; | 860 std::vector<std::unique_ptr<web::NavigationItem>> items; |
| 859 items.push_back(CreateNavigationItem("http://www.firstpage.com", | 861 items.push_back(CreateNavigationItem("http://www.firstpage.com", |
| 860 "http://www.starturl.com", @"First")); | 862 "http://www.starturl.com", @"First")); |
| 861 items.push_back(CreateNavigationItem("http://www.secondpage.com", | 863 items.push_back(CreateNavigationItem("http://www.secondpage.com", |
| 862 "http://www.firstpage.com", @"Second")); | 864 "http://www.firstpage.com", @"Second")); |
| 863 items.push_back(CreateNavigationItem("http://www.thirdpage.com", | 865 items.push_back(CreateNavigationItem("http://www.thirdpage.com", |
| 864 "http://www.secondpage.com", @"Third")); | 866 "http://www.secondpage.com", @"Third")); |
| 865 base::scoped_nsobject<CRWSessionController> controller( | 867 base::scoped_nsobject<CRWSessionController> controller( |
| 866 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) | 868 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 867 currentIndex:0 | 869 currentIndex:0 |
| 868 browserState:&browser_state_]); | 870 browserState:&browser_state_]); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 [session_controller_ commitPendingEntry]; | 1122 [session_controller_ commitPendingEntry]; |
| 1121 [session_controller_ addPendingEntry:GURL("http://www.example.com/0") | 1123 [session_controller_ addPendingEntry:GURL("http://www.example.com/0") |
| 1122 referrer:MakeReferrer("http://www.example.com/b") | 1124 referrer:MakeReferrer("http://www.example.com/b") |
| 1123 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT | 1125 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT |
| 1124 rendererInitiated:YES]; | 1126 rendererInitiated:YES]; |
| 1125 [session_controller_ commitPendingEntry]; | 1127 [session_controller_ commitPendingEntry]; |
| 1126 EXPECT_EQ(0U, [session_controller_ backwardEntries].count); | 1128 EXPECT_EQ(0U, [session_controller_ backwardEntries].count); |
| 1127 } | 1129 } |
| 1128 | 1130 |
| 1129 } // anonymous namespace | 1131 } // anonymous namespace |
| OLD | NEW |