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 d6e790bdc46580b257fb360e304530e19b0065cf..2f5c18828ee79a7e7c3c40ff6d520c13c611a5fe 100644 |
--- a/ios/web/navigation/history_state_operations_inttest.mm |
+++ b/ios/web/navigation/history_state_operations_inttest.mm |
@@ -134,21 +134,28 @@ void WaitForPageToLoad() { |
}); |
} |
- // Loads |url| in |web_state_|. |
- void LoadUrl(const GURL& url) { |
+ // Executes |block| and waits for |url| to be successfully loaded. |
+ void ExecuteBlockAndWaitForLoad(const GURL& url, ProceduralBlock block) { |
ExpectPageLoad(url); |
- web::NavigationManager::WebLoadParams params(url); |
- navigation_manager()->LoadURLWithParams(params); |
+ block(); |
WaitForPageToLoad(); |
} |
+ // Loads |url| in |web_state_|. |
+ void LoadUrl(const GURL& url) { |
+ ExecuteBlockAndWaitForLoad(url, ^{ |
+ web::NavigationManager::WebLoadParams params(url); |
+ navigation_manager()->LoadURLWithParams(params); |
+ }); |
+ } |
+ |
// Reloads the page and waits for the load to finish. |
void Reload() { |
- ExpectPageLoad(current_item()->GetURL()); |
- // TODO(crbug.com/677364): Use NavigationManager::Reload() once it no longer |
- // requires a web delegate. |
- web_state()->ExecuteJavaScript(ASCIIToUTF16("window.location.reload()")); |
- WaitForPageToLoad(); |
+ ExecuteBlockAndWaitForLoad(current_item()->GetURL(), ^{ |
+ // TODO(crbug.com/677364): Use NavigationManager::Reload() once it no |
+ // longer requires a web delegate. |
+ web_state()->ExecuteJavaScript(ASCIIToUTF16("window.location.reload()")); |
+ }); |
} |
// Set the parameters to use for state operations on the test page. |
@@ -372,3 +379,47 @@ NSInteger GetIndexOfNavigationItem(const web::NavigationItem* item) { |
false, base::TimeDelta::FromSeconds(10.0)); |
EXPECT_TRUE(state_object_present); |
} |
+ |
+// Tests that the state object is correctly set for a page after a back/forward |
+// navigation. |
+TEST_F(HistoryStateOperationsTest, StateReplacementBackForward) { |
+ // 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); |
+ ExecuteBlockAndWaitForLoad(state_operations_url(), ^{ |
+ navigation_manager()->GoBack(); |
+ }); |
+ 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:19:24
std::string empty_title;
kkhorimoto
2017/01/24 05:22:54
Done.
|
+ GURL empty_url(""); |
Eugene But (OOO till 7-30)
2016/12/29 17:19:24
GURL empty_url;
kkhorimoto
2017/01/24 05:22:54
Done.
|
+ SetStateParams(new_state, empty_title, empty_url); |
+ ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateID)); |
+ // Go forward and back, then check that the state object is present. |
+ ExecuteBlockAndWaitForLoad(about_blank, ^{ |
+ navigation_manager()->GoForward(); |
+ }); |
+ ExecuteBlockAndWaitForLoad(state_operations_url(), ^{ |
+ navigation_manager()->GoBack(); |
+ }); |
+ ASSERT_TRUE(IsOnLoadTextVisible()); |
+ __block bool state_object_present = false; |
+ base::string16 state_object_script = ASCIIToUTF16("window.history.state"); |
+ base::test::ios::TimeUntilCondition( |
+ ^{ |
+ web_state()->ExecuteJavaScript( |
Eugene But (OOO till 7-30)
2016/12/29 17:19:24
Please use synchronous API.
kkhorimoto
2017/01/24 05:22:54
Done.
|
+ state_object_script, base::BindBlock(^(const base::Value* result) { |
+ std::string state; |
+ result->GetAsString(&state); |
+ state_object_present = state == new_state; |
+ })); |
+ }, |
+ ^bool { |
+ return state_object_present; |
+ }, |
+ false, base::TimeDelta::FromSeconds(10.0)); |
+ EXPECT_TRUE(state_object_present); |
Eugene But (OOO till 7-30)
2016/12/29 17:19:24
No need for this line.
kkhorimoto
2017/01/24 05:22:54
Done.
|
+} |