| 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" |
| 6 |
| 5 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 6 | 8 |
| 9 #include <utility> |
| 10 |
| 7 #include "base/logging.h" | 11 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 11 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 15 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
| 12 #import "ios/web/navigation/crw_session_controller.h" | |
| 13 #include "ios/web/navigation/crw_session_entry.h" | 16 #include "ios/web/navigation/crw_session_entry.h" |
| 14 #include "ios/web/navigation/navigation_item_impl.h" | 17 #include "ios/web/navigation/navigation_item_impl.h" |
| 15 #include "ios/web/public/referrer.h" | 18 #include "ios/web/public/referrer.h" |
| 16 #include "ios/web/public/test/test_browser_state.h" | 19 #include "ios/web/public/test/test_browser_state.h" |
| 17 #include "ios/web/public/test/test_web_thread_bundle.h" | 20 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 18 #import "net/base/mac/url_conversions.h" | 21 #import "net/base/mac/url_conversions.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/gtest_mac.h" | 23 #include "testing/gtest_mac.h" |
| 21 #include "testing/platform_test.h" | 24 #include "testing/platform_test.h" |
| 22 | 25 |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 navigation_item->SetReferrer(referrer_object); | 750 navigation_item->SetReferrer(referrer_object); |
| 748 navigation_item->SetTitle(base::SysNSStringToUTF16(title)); | 751 navigation_item->SetTitle(base::SysNSStringToUTF16(title)); |
| 749 navigation_item->SetTransitionType(ui::PAGE_TRANSITION_TYPED); | 752 navigation_item->SetTransitionType(ui::PAGE_TRANSITION_TYPED); |
| 750 | 753 |
| 751 return navigation_item; | 754 return navigation_item; |
| 752 } | 755 } |
| 753 | 756 |
| 754 TEST_F(CRWSessionControllerTest, CreateWithEmptyNavigations) { | 757 TEST_F(CRWSessionControllerTest, CreateWithEmptyNavigations) { |
| 755 ScopedVector<web::NavigationItem> items; | 758 ScopedVector<web::NavigationItem> items; |
| 756 base::scoped_nsobject<CRWSessionController> controller( | 759 base::scoped_nsobject<CRWSessionController> controller( |
| 757 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() | 760 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 758 currentIndex:0 | 761 currentIndex:0 |
| 759 browserState:&browser_state_]); | 762 browserState:&browser_state_]); |
| 760 EXPECT_EQ(controller.get().entries.count, 0U); | 763 EXPECT_EQ(controller.get().entries.count, 0U); |
| 761 EXPECT_EQ(controller.get().currentNavigationIndex, -1); | 764 EXPECT_EQ(controller.get().currentNavigationIndex, -1); |
| 762 EXPECT_EQ(controller.get().previousNavigationIndex, -1); | 765 EXPECT_EQ(controller.get().previousNavigationIndex, -1); |
| 763 EXPECT_FALSE(controller.get().currentEntry); | 766 EXPECT_FALSE(controller.get().currentEntry); |
| 764 } | 767 } |
| 765 | 768 |
| 766 TEST_F(CRWSessionControllerTest, CreateWithNavList) { | 769 TEST_F(CRWSessionControllerTest, CreateWithNavList) { |
| 767 ScopedVector<web::NavigationItem> items; | 770 ScopedVector<web::NavigationItem> items; |
| 768 items.push_back(CreateNavigationItem("http://www.google.com", | 771 items.push_back(CreateNavigationItem("http://www.google.com", |
| 769 "http://www.referrer.com", @"Google")); | 772 "http://www.referrer.com", @"Google")); |
| 770 items.push_back(CreateNavigationItem("http://www.yahoo.com", | 773 items.push_back(CreateNavigationItem("http://www.yahoo.com", |
| 771 "http://www.google.com", @"Yahoo")); | 774 "http://www.google.com", @"Yahoo")); |
| 772 items.push_back(CreateNavigationItem("http://www.espn.com", | 775 items.push_back(CreateNavigationItem("http://www.espn.com", |
| 773 "http://www.nothing.com", @"ESPN")); | 776 "http://www.nothing.com", @"ESPN")); |
| 774 base::scoped_nsobject<CRWSessionController> controller( | 777 base::scoped_nsobject<CRWSessionController> controller( |
| 775 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() | 778 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 776 currentIndex:1 | 779 currentIndex:1 |
| 777 browserState:&browser_state_]); | 780 browserState:&browser_state_]); |
| 778 | 781 |
| 779 EXPECT_EQ(controller.get().entries.count, 3U); | 782 EXPECT_EQ(controller.get().entries.count, 3U); |
| 780 EXPECT_EQ(controller.get().currentNavigationIndex, 1); | 783 EXPECT_EQ(controller.get().currentNavigationIndex, 1); |
| 781 EXPECT_EQ(controller.get().previousNavigationIndex, -1); | 784 EXPECT_EQ(controller.get().previousNavigationIndex, -1); |
| 782 // Sanity check the current entry, the CRWSessionEntry unit test will ensure | 785 // Sanity check the current entry, the CRWSessionEntry unit test will ensure |
| 783 // the entire object is created properly. | 786 // the entire object is created properly. |
| 784 CRWSessionEntry* current_entry = controller.get().currentEntry; | 787 CRWSessionEntry* current_entry = controller.get().currentEntry; |
| 785 EXPECT_EQ(current_entry.navigationItem->GetURL(), | 788 EXPECT_EQ(current_entry.navigationItem->GetURL(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 827 |
| 825 TEST_F(CRWSessionControllerTest, PushNewEntry) { | 828 TEST_F(CRWSessionControllerTest, PushNewEntry) { |
| 826 ScopedVector<web::NavigationItem> items; | 829 ScopedVector<web::NavigationItem> items; |
| 827 items.push_back(CreateNavigationItem("http://www.firstpage.com", | 830 items.push_back(CreateNavigationItem("http://www.firstpage.com", |
| 828 "http://www.starturl.com", @"First")); | 831 "http://www.starturl.com", @"First")); |
| 829 items.push_back(CreateNavigationItem("http://www.secondpage.com", | 832 items.push_back(CreateNavigationItem("http://www.secondpage.com", |
| 830 "http://www.firstpage.com", @"Second")); | 833 "http://www.firstpage.com", @"Second")); |
| 831 items.push_back(CreateNavigationItem("http://www.thirdpage.com", | 834 items.push_back(CreateNavigationItem("http://www.thirdpage.com", |
| 832 "http://www.secondpage.com", @"Third")); | 835 "http://www.secondpage.com", @"Third")); |
| 833 base::scoped_nsobject<CRWSessionController> controller( | 836 base::scoped_nsobject<CRWSessionController> controller( |
| 834 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() | 837 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 835 currentIndex:0 | 838 currentIndex:0 |
| 836 browserState:&browser_state_]); | 839 browserState:&browser_state_]); |
| 837 | 840 |
| 838 GURL pushPageGurl1("http://www.firstpage.com/#push1"); | 841 GURL pushPageGurl1("http://www.firstpage.com/#push1"); |
| 839 NSString* stateObject1 = @"{'foo': 1}"; | 842 NSString* stateObject1 = @"{'foo': 1}"; |
| 840 [controller pushNewEntryWithURL:pushPageGurl1 | 843 [controller pushNewEntryWithURL:pushPageGurl1 |
| 841 stateObject:stateObject1 | 844 stateObject:stateObject1 |
| 842 transition:ui::PAGE_TRANSITION_LINK]; | 845 transition:ui::PAGE_TRANSITION_LINK]; |
| 843 CRWSessionEntry* pushedEntry = [controller currentEntry]; | 846 CRWSessionEntry* pushedEntry = [controller currentEntry]; |
| 844 web::NavigationItemImpl* pushedItem = pushedEntry.navigationItemImpl; | 847 web::NavigationItemImpl* pushedItem = pushedEntry.navigationItemImpl; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 "http://foo.com#bar", @"Third")); | 879 "http://foo.com#bar", @"Third")); |
| 877 items.push_back( | 880 items.push_back( |
| 878 CreateNavigationItem("http://foo.com", "http://google.com", @"Fourth")); | 881 CreateNavigationItem("http://foo.com", "http://google.com", @"Fourth")); |
| 879 // Push state navigation. | 882 // Push state navigation. |
| 880 items.push_back( | 883 items.push_back( |
| 881 CreateNavigationItem("http://foo.com/bar", "http://foo.com", @"Fifth")); | 884 CreateNavigationItem("http://foo.com/bar", "http://foo.com", @"Fifth")); |
| 882 // Push state navigation. | 885 // Push state navigation. |
| 883 items.push_back(CreateNavigationItem("http://foo.com/bar#bar", | 886 items.push_back(CreateNavigationItem("http://foo.com/bar#bar", |
| 884 "http://foo.com/bar", @"Sixth")); | 887 "http://foo.com/bar", @"Sixth")); |
| 885 base::scoped_nsobject<CRWSessionController> controller( | 888 base::scoped_nsobject<CRWSessionController> controller( |
| 886 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() | 889 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 887 currentIndex:0 | 890 currentIndex:0 |
| 888 browserState:&browser_state_]); | 891 browserState:&browser_state_]); |
| 889 CRWSessionEntry* entry0 = [controller.get().entries objectAtIndex:0]; | 892 CRWSessionEntry* entry0 = [controller.get().entries objectAtIndex:0]; |
| 890 CRWSessionEntry* entry1 = [controller.get().entries objectAtIndex:1]; | 893 CRWSessionEntry* entry1 = [controller.get().entries objectAtIndex:1]; |
| 891 CRWSessionEntry* entry2 = [controller.get().entries objectAtIndex:2]; | 894 CRWSessionEntry* entry2 = [controller.get().entries objectAtIndex:2]; |
| 892 CRWSessionEntry* entry3 = [controller.get().entries objectAtIndex:3]; | 895 CRWSessionEntry* entry3 = [controller.get().entries objectAtIndex:3]; |
| 893 CRWSessionEntry* entry4 = [controller.get().entries objectAtIndex:4]; | 896 CRWSessionEntry* entry4 = [controller.get().entries objectAtIndex:4]; |
| 894 CRWSessionEntry* entry5 = [controller.get().entries objectAtIndex:5]; | 897 CRWSessionEntry* entry5 = [controller.get().entries objectAtIndex:5]; |
| 895 entry1.navigationItemImpl->SetIsCreatedFromPushState(true); | 898 entry1.navigationItemImpl->SetIsCreatedFromPushState(true); |
| 896 entry4.navigationItemImpl->SetIsCreatedFromPushState(true); | 899 entry4.navigationItemImpl->SetIsCreatedFromPushState(true); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 912 | 915 |
| 913 TEST_F(CRWSessionControllerTest, UpdateCurrentEntry) { | 916 TEST_F(CRWSessionControllerTest, UpdateCurrentEntry) { |
| 914 ScopedVector<web::NavigationItem> items; | 917 ScopedVector<web::NavigationItem> items; |
| 915 items.push_back(CreateNavigationItem("http://www.firstpage.com", | 918 items.push_back(CreateNavigationItem("http://www.firstpage.com", |
| 916 "http://www.starturl.com", @"First")); | 919 "http://www.starturl.com", @"First")); |
| 917 items.push_back(CreateNavigationItem("http://www.secondpage.com", | 920 items.push_back(CreateNavigationItem("http://www.secondpage.com", |
| 918 "http://www.firstpage.com", @"Second")); | 921 "http://www.firstpage.com", @"Second")); |
| 919 items.push_back(CreateNavigationItem("http://www.thirdpage.com", | 922 items.push_back(CreateNavigationItem("http://www.thirdpage.com", |
| 920 "http://www.secondpage.com", @"Third")); | 923 "http://www.secondpage.com", @"Third")); |
| 921 base::scoped_nsobject<CRWSessionController> controller( | 924 base::scoped_nsobject<CRWSessionController> controller( |
| 922 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() | 925 [[CRWSessionController alloc] initWithNavigationItems:std::move(items) |
| 923 currentIndex:0 | 926 currentIndex:0 |
| 924 browserState:&browser_state_]); | 927 browserState:&browser_state_]); |
| 925 | 928 |
| 926 GURL replacePageGurl1("http://www.firstpage.com/#replace1"); | 929 GURL replacePageGurl1("http://www.firstpage.com/#replace1"); |
| 927 NSString* stateObject1 = @"{'foo': 1}"; | 930 NSString* stateObject1 = @"{'foo': 1}"; |
| 928 | 931 |
| 929 // Replace current entry and check the size of history and fields of the | 932 // Replace current entry and check the size of history and fields of the |
| 930 // modified entry. | 933 // modified entry. |
| 931 [controller updateCurrentEntryWithURL:replacePageGurl1 | 934 [controller updateCurrentEntryWithURL:replacePageGurl1 |
| 932 stateObject:stateObject1]; | 935 stateObject:stateObject1]; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1026 |
| 1024 // Remove an entry and attempt to go it. Ensure it outlives the removal. | 1027 // Remove an entry and attempt to go it. Ensure it outlives the removal. |
| 1025 base::scoped_nsobject<CRWSessionEntry> entry3( | 1028 base::scoped_nsobject<CRWSessionEntry> entry3( |
| 1026 [[session_controller_.get().entries objectAtIndex:3] retain]); | 1029 [[session_controller_.get().entries objectAtIndex:3] retain]); |
| 1027 [session_controller_ removeEntryAtIndex:3]; | 1030 [session_controller_ removeEntryAtIndex:3]; |
| 1028 [session_controller_ goToEntry:entry3]; | 1031 [session_controller_ goToEntry:entry3]; |
| 1029 EXPECT_EQ(1, session_controller_.get().currentNavigationIndex); | 1032 EXPECT_EQ(1, session_controller_.get().currentNavigationIndex); |
| 1030 } | 1033 } |
| 1031 | 1034 |
| 1032 } // anonymous namespace | 1035 } // anonymous namespace |
| OLD | NEW |