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

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

Issue 2602013002: Created test verifying setting the state object via replaceState() (Closed)
Patch Set: 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 | « 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 52cc4f2a149fd0cced972562b09fc14a0ba1fe08..8c0af0b77cbcaec5afecd7b21f3a904665cf85ef 100644
--- a/ios/web/navigation/history_state_operations_inttest.mm
+++ b/ios/web/navigation/history_state_operations_inttest.mm
@@ -5,8 +5,10 @@
#import "base/mac/bind_objc_block.h"
#include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h"
+#import "base/strings/sys_string_conversions.h"
Eugene But (OOO till 7-30) 2016/12/29 17:12:59 s/import/include
kkhorimoto 2017/01/24 04:57:15 Done.
#include "base/strings/utf_string_conversions.h"
#include "base/test/ios/wait_util.h"
+#import "ios/web/navigation/navigation_item_impl.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/navigation_manager.h"
#import "ios/web/public/test/http_server.h"
@@ -295,3 +297,39 @@ NSInteger GetIndexOfNavigationItem(const web::NavigationItem* item) {
EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1,
GetIndexOfNavigationItem(about_blank_item));
}
+
+// Tests that calling window.history.replaceState() with a new state object
+// replaces the state object for the current NavigationItem.
+TEST_F(HistoryStateOperationsTest, StateReplacement) {
+ // 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 = current_item();
+ ExpectPageLoad(state_operations_url());
+ navigation_manager()->GoBack();
+ WaitForPageToLoad();
+ ASSERT_EQ(state_operations_url(), current_item()->GetURL());
+ // Set up the state parameters and tap the replace state button.
+ std::string new_state("STATE OBJECT");
+ std::string empty_title("");
Eugene But (OOO till 7-30) 2016/12/29 17:12:59 std::string empty_title;
kkhorimoto 2017/01/24 04:57:15 Done.
+ GURL empty_url("");
Eugene But (OOO till 7-30) 2016/12/29 17:12:59 GURL empty_url;
kkhorimoto 2017/01/24 04:57:15 Done.
+ SetStateParams(new_state, empty_title, empty_url);
+ ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateID));
+ // Verify that the state is reflected in the latest NavigationItem.
+ std::string serialized_state("\"STATE OBJECT\"");
+ __block bool state_updated = false;
+ base::test::ios::WaitUntilCondition(^bool {
+ web::NavigationItemImpl* item =
+ static_cast<web::NavigationItemImpl*>(current_item());
+ std::string item_state =
+ base::SysNSStringToUTF8(item->GetSerializedStateObject());
Eugene But (OOO till 7-30) 2016/12/29 17:12:59 Is there a way to avoid using implementation detai
kkhorimoto 2017/01/24 04:57:15 Not really. NavigationEntry doesn't expose the st
+ state_updated = item_state == serialized_state;
Eugene But (OOO till 7-30) 2016/12/29 17:13:00 return item_state == serialized_state;
kkhorimoto 2017/01/24 04:57:15 Done.
+ return state_updated;
+ });
+ EXPECT_TRUE(state_updated);
Eugene But (OOO till 7-30) 2016/12/29 17:13:00 There is no need for this check.
kkhorimoto 2017/01/24 04:57:15 Done.
+ // Verify that the forward navigation was not pruned.
+ EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1,
+ 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