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

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

Issue 1106963003: Re-sync ios/web with downstream version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add forgotten file Created 5 years, 7 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
« no previous file with comments | « ios/web/navigation/crw_session_controller.mm ('k') | ios/web/navigation/crw_session_entry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <Foundation/Foundation.h> 5 #import <Foundation/Foundation.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 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 "http://www.secondpage.com", @"Third")); 830 "http://www.secondpage.com", @"Third"));
831 base::scoped_nsobject<CRWSessionController> controller( 831 base::scoped_nsobject<CRWSessionController> controller(
832 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() 832 [[CRWSessionController alloc] initWithNavigationItems:items.Pass()
833 currentIndex:0 833 currentIndex:0
834 browserState:&browser_state_]); 834 browserState:&browser_state_]);
835 835
836 GURL pushPageGurl1("http://www.firstpage.com/#push1"); 836 GURL pushPageGurl1("http://www.firstpage.com/#push1");
837 NSString* stateObject1 = @"{'foo': 1}"; 837 NSString* stateObject1 = @"{'foo': 1}";
838 [controller pushNewEntryWithURL:pushPageGurl1 stateObject:stateObject1]; 838 [controller pushNewEntryWithURL:pushPageGurl1 stateObject:stateObject1];
839 CRWSessionEntry* pushedEntry = [controller currentEntry]; 839 CRWSessionEntry* pushedEntry = [controller currentEntry];
840 web::NavigationItemImpl* pushedItem = pushedEntry.navigationItemImpl;
840 NSUInteger expectedCount = 2; 841 NSUInteger expectedCount = 2;
841 EXPECT_EQ(expectedCount, controller.get().entries.count); 842 EXPECT_EQ(expectedCount, controller.get().entries.count);
842 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetURL()); 843 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetURL());
843 EXPECT_TRUE(pushedEntry.createdFromPushState); 844 EXPECT_TRUE(pushedItem->IsCreatedFromPushState());
844 EXPECT_NSEQ(stateObject1, pushedEntry.serializedStateObject); 845 EXPECT_NSEQ(stateObject1, pushedItem->GetSerializedStateObject());
845 EXPECT_EQ(GURL("http://www.firstpage.com/"), 846 EXPECT_EQ(GURL("http://www.firstpage.com/"),
846 pushedEntry.navigationItem->GetReferrer().url); 847 pushedEntry.navigationItem->GetReferrer().url);
847 848
848 // Add another new entry and check size and fields again. 849 // Add another new entry and check size and fields again.
849 GURL pushPageGurl2("http://www.firstpage.com/push2"); 850 GURL pushPageGurl2("http://www.firstpage.com/push2");
850 [controller pushNewEntryWithURL:pushPageGurl2 stateObject:nil]; 851 [controller pushNewEntryWithURL:pushPageGurl2 stateObject:nil];
851 pushedEntry = [controller currentEntry]; 852 pushedEntry = [controller currentEntry];
853 pushedItem = pushedEntry.navigationItemImpl;
852 expectedCount = 3; 854 expectedCount = 3;
853 EXPECT_EQ(expectedCount, controller.get().entries.count); 855 EXPECT_EQ(expectedCount, controller.get().entries.count);
854 EXPECT_EQ(pushPageGurl2, pushedEntry.navigationItem->GetURL()); 856 EXPECT_EQ(pushPageGurl2, pushedEntry.navigationItem->GetURL());
855 EXPECT_TRUE(pushedEntry.createdFromPushState); 857 EXPECT_TRUE(pushedItem->IsCreatedFromPushState());
856 EXPECT_EQ(nil, pushedEntry.serializedStateObject); 858 EXPECT_EQ(nil, pushedItem->GetSerializedStateObject());
857 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetReferrer().url); 859 EXPECT_EQ(pushPageGurl1, pushedEntry.navigationItem->GetReferrer().url);
858 } 860 }
859 861
860 TEST_F(CRWSessionControllerTest, IsPushStateNavigation) { 862 TEST_F(CRWSessionControllerTest, IsPushStateNavigation) {
861 ScopedVector<web::NavigationItem> items; 863 ScopedVector<web::NavigationItem> items;
862 items.push_back( 864 items.push_back(
863 CreateNavigationItem("http://foo.com", "http://google.com", @"First")); 865 CreateNavigationItem("http://foo.com", "http://google.com", @"First"));
864 // Push state navigation. 866 // Push state navigation.
865 items.push_back( 867 items.push_back(
866 CreateNavigationItem("http://foo.com#bar", "http://foo.com", @"Second")); 868 CreateNavigationItem("http://foo.com#bar", "http://foo.com", @"Second"));
(...skipping 10 matching lines...) Expand all
877 base::scoped_nsobject<CRWSessionController> controller( 879 base::scoped_nsobject<CRWSessionController> controller(
878 [[CRWSessionController alloc] initWithNavigationItems:items.Pass() 880 [[CRWSessionController alloc] initWithNavigationItems:items.Pass()
879 currentIndex:0 881 currentIndex:0
880 browserState:&browser_state_]); 882 browserState:&browser_state_]);
881 CRWSessionEntry* entry0 = [controller.get().entries objectAtIndex:0]; 883 CRWSessionEntry* entry0 = [controller.get().entries objectAtIndex:0];
882 CRWSessionEntry* entry1 = [controller.get().entries objectAtIndex:1]; 884 CRWSessionEntry* entry1 = [controller.get().entries objectAtIndex:1];
883 CRWSessionEntry* entry2 = [controller.get().entries objectAtIndex:2]; 885 CRWSessionEntry* entry2 = [controller.get().entries objectAtIndex:2];
884 CRWSessionEntry* entry3 = [controller.get().entries objectAtIndex:3]; 886 CRWSessionEntry* entry3 = [controller.get().entries objectAtIndex:3];
885 CRWSessionEntry* entry4 = [controller.get().entries objectAtIndex:4]; 887 CRWSessionEntry* entry4 = [controller.get().entries objectAtIndex:4];
886 CRWSessionEntry* entry5 = [controller.get().entries objectAtIndex:5]; 888 CRWSessionEntry* entry5 = [controller.get().entries objectAtIndex:5];
887 entry1.createdFromPushState = YES; 889 entry1.navigationItemImpl->SetIsCreatedFromPushState(true);
888 entry4.createdFromPushState = YES; 890 entry4.navigationItemImpl->SetIsCreatedFromPushState(true);
889 entry5.createdFromPushState = YES; 891 entry5.navigationItemImpl->SetIsCreatedFromPushState(true);
890 892
891 EXPECT_TRUE( 893 EXPECT_TRUE(
892 [controller isPushStateNavigationBetweenEntry:entry0 andEntry:entry1]); 894 [controller isPushStateNavigationBetweenEntry:entry0 andEntry:entry1]);
893 EXPECT_TRUE( 895 EXPECT_TRUE(
894 [controller isPushStateNavigationBetweenEntry:entry5 andEntry:entry3]); 896 [controller isPushStateNavigationBetweenEntry:entry5 andEntry:entry3]);
895 EXPECT_TRUE( 897 EXPECT_TRUE(
896 [controller isPushStateNavigationBetweenEntry:entry4 andEntry:entry3]); 898 [controller isPushStateNavigationBetweenEntry:entry4 andEntry:entry3]);
897 EXPECT_FALSE( 899 EXPECT_FALSE(
898 [controller isPushStateNavigationBetweenEntry:entry1 andEntry:entry2]); 900 [controller isPushStateNavigationBetweenEntry:entry1 andEntry:entry2]);
899 EXPECT_FALSE( 901 EXPECT_FALSE(
(...skipping 16 matching lines...) Expand all
916 browserState:&browser_state_]); 918 browserState:&browser_state_]);
917 919
918 GURL replacePageGurl1("http://www.firstpage.com/#replace1"); 920 GURL replacePageGurl1("http://www.firstpage.com/#replace1");
919 NSString* stateObject1 = @"{'foo': 1}"; 921 NSString* stateObject1 = @"{'foo': 1}";
920 922
921 // Replace current entry and check the size of history and fields of the 923 // Replace current entry and check the size of history and fields of the
922 // modified entry. 924 // modified entry.
923 [controller updateCurrentEntryWithURL:replacePageGurl1 925 [controller updateCurrentEntryWithURL:replacePageGurl1
924 stateObject:stateObject1]; 926 stateObject:stateObject1];
925 CRWSessionEntry* replacedEntry = [controller currentEntry]; 927 CRWSessionEntry* replacedEntry = [controller currentEntry];
928 web::NavigationItemImpl* replacedItem = replacedEntry.navigationItemImpl;
926 NSUInteger expectedCount = 3; 929 NSUInteger expectedCount = 3;
927 EXPECT_EQ(expectedCount, controller.get().entries.count); 930 EXPECT_EQ(expectedCount, controller.get().entries.count);
928 EXPECT_EQ(replacePageGurl1, replacedEntry.navigationItem->GetURL()); 931 EXPECT_EQ(replacePageGurl1, replacedEntry.navigationItem->GetURL());
929 EXPECT_FALSE(replacedEntry.createdFromPushState); 932 EXPECT_FALSE(replacedItem->IsCreatedFromPushState());
930 EXPECT_NSEQ(stateObject1, replacedEntry.serializedStateObject); 933 EXPECT_NSEQ(stateObject1, replacedItem->GetSerializedStateObject());
931 EXPECT_EQ(GURL("http://www.starturl.com/"), 934 EXPECT_EQ(GURL("http://www.starturl.com/"),
932 replacedEntry.navigationItem->GetReferrer().url); 935 replacedEntry.navigationItem->GetReferrer().url);
933 936
934 // Replace current entry and check size and fields again. 937 // Replace current entry and check size and fields again.
935 GURL replacePageGurl2("http://www.firstpage.com/#replace2"); 938 GURL replacePageGurl2("http://www.firstpage.com/#replace2");
936 [controller.get() updateCurrentEntryWithURL:replacePageGurl2 stateObject:nil]; 939 [controller.get() updateCurrentEntryWithURL:replacePageGurl2 stateObject:nil];
937 replacedEntry = [controller currentEntry]; 940 replacedEntry = [controller currentEntry];
941 replacedItem = replacedEntry.navigationItemImpl;
938 EXPECT_EQ(expectedCount, controller.get().entries.count); 942 EXPECT_EQ(expectedCount, controller.get().entries.count);
939 EXPECT_EQ(replacePageGurl2, replacedEntry.navigationItem->GetURL()); 943 EXPECT_EQ(replacePageGurl2, replacedEntry.navigationItem->GetURL());
940 EXPECT_FALSE(replacedEntry.createdFromPushState); 944 EXPECT_FALSE(replacedItem->IsCreatedFromPushState());
941 EXPECT_NSEQ(nil, replacedEntry.serializedStateObject); 945 EXPECT_NSEQ(nil, replacedItem->GetSerializedStateObject());
942 EXPECT_EQ(GURL("http://www.starturl.com/"), 946 EXPECT_EQ(GURL("http://www.starturl.com/"),
943 replacedEntry.navigationItem->GetReferrer().url); 947 replacedEntry.navigationItem->GetReferrer().url);
944 } 948 }
945 949
946 TEST_F(CRWSessionControllerTest, TestBackwardForwardEntries) { 950 TEST_F(CRWSessionControllerTest, TestBackwardForwardEntries) {
947 [session_controller_ addPendingEntry:GURL("http://www.example.com/0") 951 [session_controller_ addPendingEntry:GURL("http://www.example.com/0")
948 referrer:MakeReferrer("http://www.example.com/a") 952 referrer:MakeReferrer("http://www.example.com/a")
949 transition:ui::PAGE_TRANSITION_LINK 953 transition:ui::PAGE_TRANSITION_LINK
950 rendererInitiated:NO]; 954 rendererInitiated:NO];
951 [session_controller_ commitPendingEntry]; 955 [session_controller_ commitPendingEntry];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 1017
1014 // Remove an entry and attempt to go it. Ensure it outlives the removal. 1018 // Remove an entry and attempt to go it. Ensure it outlives the removal.
1015 base::scoped_nsobject<CRWSessionEntry> entry3( 1019 base::scoped_nsobject<CRWSessionEntry> entry3(
1016 [[session_controller_.get().entries objectAtIndex:3] retain]); 1020 [[session_controller_.get().entries objectAtIndex:3] retain]);
1017 [session_controller_ removeEntryAtIndex:3]; 1021 [session_controller_ removeEntryAtIndex:3];
1018 [session_controller_ goToEntry:entry3]; 1022 [session_controller_ goToEntry:entry3];
1019 EXPECT_EQ(1, session_controller_.get().currentNavigationIndex); 1023 EXPECT_EQ(1, session_controller_.get().currentNavigationIndex);
1020 } 1024 }
1021 1025
1022 } // anonymous namespace 1026 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/web/navigation/crw_session_controller.mm ('k') | ios/web/navigation/crw_session_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698