Skip to content

Commit

Permalink
[ios] Deprecated copyStateFromAndPrune:replaceState:.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
eugenebut authored and Commit bot committed Nov 16, 2016
1 parent c021ad0 commit 7bd4322
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 137 deletions.
6 changes: 6 additions & 0 deletions ios/web/navigation/crw_session_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions ios/web/navigation/crw_session_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
141 changes: 4 additions & 137 deletions ios/web/navigation/crw_session_controller_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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<CRWSessionController> 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,
Expand Down Expand Up @@ -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]);
Expand All @@ -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<CRWSessionController> 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<CRWSessionController> 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];

Expand Down

0 comments on commit 7bd4322

Please sign in to comment.