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

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

Issue 2604123002: Created test for window.history.pushState(). (Closed)
Patch Set: rebase + eugene's comments Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/navigation/history_state_operations_inttest.mm
diff --git a/ios/web/navigation/history_state_operations_inttest.mm b/ios/web/navigation/history_state_operations_inttest.mm
index afd2c86dc0991329f1fbade03b40acf4a56aee24..a305cf3b3a3e3e5c80992120181440eccfc7115d 100644
--- a/ios/web/navigation/history_state_operations_inttest.mm
+++ b/ios/web/navigation/history_state_operations_inttest.mm
@@ -339,3 +339,34 @@ void WaitForNoOpText() {
return GetJavaScriptState() == new_state;
});
}
+
+// Tests that calling window.history.pushState() creates a new NavigationItem
+// and prunes trailing items.
+TEST_F(HistoryStateOperationsTest, PushState) {
+ // Navigate to about:blank then navigate back to the test page. The created
+ // NavigationItem can be used later to verify that the state is replaced
+ // rather than pushed.
+ GURL about_blank("about:blank");
+ LoadUrl(about_blank);
+ web::NavigationItem* about_blank_item = GetLastCommittedItem();
+ ExecuteBlockAndWaitForLoad(state_operations_url(), ^{
Eugene But (OOO till 7-30) 2017/01/24 19:26:37 Not related to this CL, but ExecuteBlockAndWaitFor
+ navigation_manager()->GoBack();
+ });
+ ASSERT_EQ(state_operations_url(), GetLastCommittedItem()->GetURL());
+ web::NavigationItem* non_pushed_item = GetLastCommittedItem();
+ // Set up the state parameters and tap the replace state button.
+ std::string empty_state;
+ std::string empty_title;
+ GURL new_url = state_operations_url().Resolve("path");
+ SetStateParams(empty_state, empty_title, new_url);
+ ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kPushStateId));
+ // Verify that the url with the path is pushed.
+ base::test::ios::WaitUntilCondition(^bool {
+ return GetLastCommittedItem()->GetURL() == new_url;
+ });
+ // Verify that a new NavigationItem was created and that the forward item was
+ // pruned.
+ EXPECT_EQ(GetIndexOfNavigationItem(non_pushed_item) + 1,
+ GetIndexOfNavigationItem(GetLastCommittedItem()));
+ EXPECT_EQ(NSNotFound, GetIndexOfNavigationItem(about_blank_item));
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698