From 7bd43225c4e6c5ebbf8ecd1faaa214a21e766b14 Mon Sep 17 00:00:00 2001 From: eugenebut Date: Wed, 16 Nov 2016 09:37:00 -0800 Subject: [PATCH] [ios] Deprecated copyStateFromAndPrune:replaceState:. This method is called only with replaceState:NO and there is no need to support extra complexity. From now clients should use insertStateFromSessionController: which works in the same way as if replaceState was NO. BUG=664344 Review-Url: https://codereview.chromium.org/2489953005 Cr-Commit-Position: refs/heads/master@{#432539} --- ios/web/navigation/crw_session_controller.h | 6 + ios/web/navigation/crw_session_controller.mm | 4 + .../crw_session_controller_unittest.mm | 141 +----------------- 3 files changed, 14 insertions(+), 137 deletions(-) diff --git a/ios/web/navigation/crw_session_controller.h b/ios/web/navigation/crw_session_controller.h index 436aa712e096e0..19cd3471f403c1 100644 --- a/ios/web/navigation/crw_session_controller.h +++ b/ios/web/navigation/crw_session_controller.h @@ -105,9 +105,15 @@ struct SSLStatus; // Returns YES if there is a pending entry. - (BOOL)hasPendingEntry; +// Inserts history state from the given CRWSessionController to the front of +// this controller. +- (void)insertStateFromSessionController:(CRWSessionController*)otherController; + // Copies history state from the given CRWSessionController and adds it to this // controller. If |replaceState|, replaces the state of this controller with // the state of |otherSession|, instead of appending. +// DEPRECATED, use insertStateFromSessionController: instead. +// TODO(crbug.com/664344): Remove this method. - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession replaceState:(BOOL)replaceState; diff --git a/ios/web/navigation/crw_session_controller.mm b/ios/web/navigation/crw_session_controller.mm index 9eaab84b9c3160..326d589bea2b4e 100644 --- a/ios/web/navigation/crw_session_controller.mm +++ b/ios/web/navigation/crw_session_controller.mm @@ -571,6 +571,10 @@ - (BOOL)hasPendingEntry { return _pendingEntry != nil; } +- (void)insertStateFromSessionController:(CRWSessionController*)other { + [self copyStateFromAndPrune:other replaceState:NO]; +} + - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession replaceState:(BOOL)replaceState { DCHECK(otherSession); diff --git a/ios/web/navigation/crw_session_controller_unittest.mm b/ios/web/navigation/crw_session_controller_unittest.mm index 7e55650709b99a..120494731709ee 100644 --- a/ios/web/navigation/crw_session_controller_unittest.mm +++ b/ios/web/navigation/crw_session_controller_unittest.mm @@ -516,8 +516,8 @@ void SetUp() override { rendererInitiated:NO]; // Copy and verify the state of target session controller. - [session_controller_ copyStateFromAndPrune:other_session_controller.get() - replaceState:NO]; + [session_controller_ + insertStateFromSessionController:other_session_controller.get()]; EXPECT_EQ(2U, [[session_controller_ entries] count]); EXPECT_EQ(1, [session_controller_ currentNavigationIndex]); @@ -530,49 +530,6 @@ void SetUp() override { [[session_controller_ pendingEntry] navigationItem]->GetURL()); } -// Tests replacing session controller state. -TEST_F(CRWSessionControllerTest, ReplaceStateFromSessionController) { - // Add 1 committed and 1 pending entry to target controller. - [session_controller_ addPendingEntry:GURL("http://www.url.com/2") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [session_controller_ commitPendingEntry]; - [session_controller_ addPendingEntry:GURL("http://www.url.com/3") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - - // Create source session controller with 1 committed entry. - base::scoped_nsobject other_session_controller( - [[CRWSessionController alloc] initWithWindowName:nil - openerId:nil - openedByDOM:NO - openerNavigationIndex:0 - browserState:&browser_state_]); - [other_session_controller addPendingEntry:GURL("http://www.url.com/0") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [other_session_controller commitPendingEntry]; - [other_session_controller addPendingEntry:GURL("http://www.url.com/1") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - - // Copy and verify the state of target session controller. - [session_controller_ copyStateFromAndPrune:other_session_controller.get() - replaceState:YES]; - EXPECT_EQ(1U, [[session_controller_ entries] count]); - EXPECT_EQ(0, [session_controller_ currentNavigationIndex]); - EXPECT_EQ(-1, [session_controller_ previousNavigationIndex]); - EXPECT_EQ(GURL("http://www.url.com/0"), - [session_controller_ URLForSessionAtIndex:0]); - ASSERT_TRUE([session_controller_ pendingEntry]); - EXPECT_EQ(GURL("http://www.url.com/3"), - [[session_controller_ pendingEntry] navigationItem]->GetURL()); -} - // Tests copying session controller state without replacing it. Verifies that // pending entry index remains valid. TEST_F(CRWSessionControllerTest, @@ -604,8 +561,8 @@ void SetUp() override { [other_session_controller commitPendingEntry]; // Copy and verify the state of target session controller. - [session_controller_ copyStateFromAndPrune:other_session_controller.get() - replaceState:NO]; + [session_controller_ + insertStateFromSessionController:other_session_controller.get()]; EXPECT_EQ(3U, [[session_controller_ entries] count]); EXPECT_EQ(2, [session_controller_ currentNavigationIndex]); @@ -619,96 +576,6 @@ void SetUp() override { [[session_controller_ pendingEntry] navigationItem]->GetURL()); } -// Tests replacing session controller state. Verifies that pending entry index -// is reset. -TEST_F( - CRWSessionControllerTest, - ReplaceStateFromSessionControllerWithPendingEntryIndexInTargetController) { - // Add 2 committed entries and make first entry pending. - [session_controller_ addPendingEntry:GURL("http://www.url.com/2") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [session_controller_ commitPendingEntry]; - [session_controller_ addPendingEntry:GURL("http://www.url.com/3") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [session_controller_ commitPendingEntry]; - [session_controller_ setPendingEntryIndex:0]; - - // Create source session controller with 1 committed entry. - base::scoped_nsobject other_session_controller( - [[CRWSessionController alloc] initWithWindowName:nil - openerId:nil - openedByDOM:NO - openerNavigationIndex:0 - browserState:&browser_state_]); - [other_session_controller addPendingEntry:GURL("http://www.url.com/0") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [other_session_controller commitPendingEntry]; - - // Copy and verify the state of target session controller. - [session_controller_ copyStateFromAndPrune:other_session_controller.get() - replaceState:YES]; - EXPECT_EQ(1U, [[session_controller_ entries] count]); - EXPECT_EQ(0, [session_controller_ currentNavigationIndex]); - EXPECT_EQ(-1, [session_controller_ previousNavigationIndex]); - EXPECT_EQ(-1, [session_controller_ pendingEntryIndex]); - EXPECT_EQ(GURL("http://www.url.com/0"), - [session_controller_ URLForSessionAtIndex:0]); - ASSERT_TRUE([session_controller_ pendingEntry]); - EXPECT_EQ(GURL("http://www.url.com/2"), - [[session_controller_ pendingEntry] navigationItem]->GetURL()); -} - -// Tests replacing session controller state. -TEST_F( - CRWSessionControllerTest, - ReplaceStateFromSessionControllerWithPendingEntryIndexInSourceController) { - // Add 2 committed entries and make first entry pending. - [session_controller_ addPendingEntry:GURL("http://www.url.com/2") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [session_controller_ commitPendingEntry]; - [session_controller_ addPendingEntry:GURL("http://www.url.com/3") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [session_controller_ commitPendingEntry]; - [session_controller_ setPendingEntryIndex:0]; - - // Create source session controller with 1 committed entry. - base::scoped_nsobject other_session_controller( - [[CRWSessionController alloc] initWithWindowName:nil - openerId:nil - openedByDOM:NO - openerNavigationIndex:0 - browserState:&browser_state_]); - [other_session_controller addPendingEntry:GURL("http://www.url.com/0") - referrer:web::Referrer() - transition:ui::PAGE_TRANSITION_TYPED - rendererInitiated:NO]; - [other_session_controller commitPendingEntry]; - [other_session_controller setPendingEntryIndex:0]; - - // Copy and verify the state of target session controller. - [session_controller_ copyStateFromAndPrune:other_session_controller.get() - replaceState:YES]; - EXPECT_EQ(1U, [[session_controller_ entries] count]); - EXPECT_EQ(0, [session_controller_ currentNavigationIndex]); - EXPECT_EQ(-1, [session_controller_ previousNavigationIndex]); - EXPECT_EQ(-1, [session_controller_ pendingEntryIndex]); - EXPECT_EQ(GURL("http://www.url.com/0"), - [session_controller_ URLForSessionAtIndex:0]); - ASSERT_TRUE([session_controller_ pendingEntry]); - EXPECT_EQ(GURL("http://www.url.com/2"), - [[session_controller_ pendingEntry] navigationItem]->GetURL()); -} - TEST_F(CRWSessionControllerTest, GoBackWithoutCommitedEntry) { [session_controller_ goBack];