Chromium Code Reviews| 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 8c0af0b77cbcaec5afecd7b21f3a904665cf85ef..d6e790bdc46580b257fb360e304530e19b0065cf 100644 |
| --- a/ios/web/navigation/history_state_operations_inttest.mm |
| +++ b/ios/web/navigation/history_state_operations_inttest.mm |
| @@ -142,6 +142,15 @@ void LoadUrl(const GURL& url) { |
| WaitForPageToLoad(); |
| } |
| + // 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(); |
| + } |
| + |
| // Set the parameters to use for state operations on the test page. |
| void SetStateParams(const std::string& state_object, |
| const std::string& title, |
| @@ -333,3 +342,33 @@ NSInteger GetIndexOfNavigationItem(const web::NavigationItem* item) { |
| EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1, |
| GetIndexOfNavigationItem(about_blank_item)); |
| } |
| + |
| +// Tests that the state object is reset to the correct value after reloading a |
| +// page whose state has been replaced. |
| +TEST_F(HistoryStateOperationsTest, StateReplacementReload) { |
| + // 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:15:27
std::string empty_title;
kkhorimoto
2017/01/24 05:15:36
Done.
|
| + GURL empty_url(""); |
|
Eugene But (OOO till 7-30)
2016/12/29 17:15:27
GURL empty_url;
kkhorimoto
2017/01/24 05:15:36
Done.
|
| + SetStateParams(new_state, empty_title, empty_url); |
| + ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateID)); |
| + // Reload the page and check that the state object is present. |
| + Reload(); |
| + 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:15:27
Could you please use synchronous API for this.
kkhorimoto
2017/01/24 05:15:36
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:15:27
No need for this check.
kkhorimoto
2017/01/24 05:15:36
Done.
|
| +} |