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

Unified Diff: ios/web/navigation/navigation_manager_impl_unittest.mm

Issue 2600263002: [ios] Fixed GetIndexForOffset for pending transient items. (Closed)
Patch Set: Fixed tests Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/navigation/navigation_manager_impl.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/navigation/navigation_manager_impl_unittest.mm
diff --git a/ios/web/navigation/navigation_manager_impl_unittest.mm b/ios/web/navigation/navigation_manager_impl_unittest.mm
index 011699ef33db300b9c939813e9cc4f7bd0c63340..c91c356ea8c4d846237b9a1e7efa02703c3726a5 100644
--- a/ios/web/navigation/navigation_manager_impl_unittest.mm
+++ b/ios/web/navigation/navigation_manager_impl_unittest.mm
@@ -459,11 +459,13 @@ TEST_F(NavigationManagerTest, OffsetsWithoutPendingIndex) {
EXPECT_EQ(-999999998, navigation_manager()->GetIndexForOffset(-1000000000));
EXPECT_EQ(1000000004, navigation_manager()->GetIndexForOffset(1000000000));
- // Test with existing transient entry.
+ // Test with existing transient entry in the end of the stack.
+ [session_controller() goToEntryAtIndex:4];
+ [session_controller() setPendingEntryIndex:-1];
[session_controller() addTransientEntryWithURL:GURL("http://www.url.com")];
ASSERT_EQ(5, navigation_manager()->GetItemCount());
- ASSERT_EQ(1, navigation_manager()->GetCurrentItemIndex());
- ASSERT_EQ(4, navigation_manager()->GetPendingItemIndex());
+ ASSERT_EQ(4, navigation_manager()->GetCurrentItemIndex());
+ ASSERT_EQ(-1, navigation_manager()->GetPendingItemIndex());
EXPECT_TRUE(navigation_manager()->CanGoToOffset(-1));
EXPECT_EQ(4, navigation_manager()->GetIndexForOffset(-1));
EXPECT_TRUE(navigation_manager()->CanGoToOffset(-2));
@@ -485,4 +487,45 @@ TEST_F(NavigationManagerTest, OffsetsWithoutPendingIndex) {
EXPECT_EQ(1000000004, navigation_manager()->GetIndexForOffset(1000000000));
}
+// Tests offsets with pending transient entries (specifically gong back and
+// forward from a pending navigation entry that is added to the middle of the
+// navigation stack).
+TEST_F(NavigationManagerTest, OffsetsWithPendingTransientEntry) {
+ // Create a transient item in the middle of the navigation stack and go back
+ // to it (pending index is 1, current index is 2).
+ [session_controller() addPendingEntry:GURL("http://www.url.com/0")
+ referrer:Referrer()
+ transition:ui::PAGE_TRANSITION_LINK
+ rendererInitiated:NO];
+ [session_controller() commitPendingEntry];
+ [session_controller() addPendingEntry:GURL("http://www.url.com/1")
+ referrer:Referrer()
+ transition:ui::PAGE_TRANSITION_LINK
+ rendererInitiated:NO];
+ [session_controller() commitPendingEntry];
+ [session_controller() addPendingEntry:GURL("http://www.url.com/2")
+ referrer:Referrer()
+ transition:ui::PAGE_TRANSITION_LINK
+ rendererInitiated:NO];
+ [session_controller() commitPendingEntry];
+ [session_controller() addTransientEntryWithURL:GURL("http://www.url.com/1")];
+ [session_controller() setPendingEntryIndex:1];
+
+ ASSERT_EQ(3, navigation_manager()->GetItemCount());
+ ASSERT_EQ(2, navigation_manager()->GetCurrentItemIndex());
+ ASSERT_EQ(1, navigation_manager()->GetPendingItemIndex());
+ EXPECT_EQ(2, navigation_manager()->GetIndexForOffset(1));
+ EXPECT_EQ(0, navigation_manager()->GetIndexForOffset(-1));
+
+ // Now go forward to that middle transient item (pending index is 1,
+ // current index is 0).
+ [session_controller() goToEntryAtIndex:0];
+ [session_controller() setPendingEntryIndex:1];
+ ASSERT_EQ(3, navigation_manager()->GetItemCount());
+ ASSERT_EQ(0, navigation_manager()->GetCurrentItemIndex());
+ ASSERT_EQ(1, navigation_manager()->GetPendingItemIndex());
+ EXPECT_EQ(2, navigation_manager()->GetIndexForOffset(1));
+ EXPECT_EQ(0, navigation_manager()->GetIndexForOffset(-1));
+}
+
} // namespace web
« no previous file with comments | « ios/web/navigation/navigation_manager_impl.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698