Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "base/mac/bind_objc_block.h" | 5 #import "base/mac/bind_objc_block.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #import "base/strings/sys_string_conversions.h" | 8 #import "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/ios/wait_util.h" | 10 #include "base/test/ios/wait_util.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Loads |url| in |web_state_|. | 137 // Loads |url| in |web_state_|. |
| 138 void LoadUrl(const GURL& url) { | 138 void LoadUrl(const GURL& url) { |
| 139 ExpectPageLoad(url); | 139 ExpectPageLoad(url); |
| 140 web::NavigationManager::WebLoadParams params(url); | 140 web::NavigationManager::WebLoadParams params(url); |
| 141 navigation_manager()->LoadURLWithParams(params); | 141 navigation_manager()->LoadURLWithParams(params); |
| 142 WaitForPageToLoad(); | 142 WaitForPageToLoad(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Reloads the page and waits for the load to finish. | |
| 146 void Reload() { | |
| 147 ExpectPageLoad(current_item()->GetURL()); | |
| 148 // TODO(crbug.com/677364): Use NavigationManager::Reload() once it no longer | |
| 149 // requires a web delegate. | |
| 150 web_state()->ExecuteJavaScript(ASCIIToUTF16("window.location.reload()")); | |
| 151 WaitForPageToLoad(); | |
| 152 } | |
| 153 | |
| 145 // Set the parameters to use for state operations on the test page. | 154 // Set the parameters to use for state operations on the test page. |
| 146 void SetStateParams(const std::string& state_object, | 155 void SetStateParams(const std::string& state_object, |
| 147 const std::string& title, | 156 const std::string& title, |
| 148 const GURL& url) { | 157 const GURL& url) { |
| 149 ASSERT_EQ(state_operations_url(), current_item()->GetURL()); | 158 ASSERT_EQ(state_operations_url(), current_item()->GetURL()); |
| 150 std::string url_spec = url.possibly_invalid_spec(); | 159 std::string url_spec = url.possibly_invalid_spec(); |
| 151 base::string16 set_params_script = ASCIIToUTF16( | 160 base::string16 set_params_script = ASCIIToUTF16( |
| 152 StringPrintf(kUpdateStateParamsScriptFormat, state_object.c_str(), | 161 StringPrintf(kUpdateStateParamsScriptFormat, state_object.c_str(), |
| 153 title.c_str(), url_spec.c_str())); | 162 title.c_str(), url_spec.c_str())); |
| 154 web_state()->ExecuteJavaScript(set_params_script); | 163 web_state()->ExecuteJavaScript(set_params_script); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 std::string item_state = | 335 std::string item_state = |
| 327 base::SysNSStringToUTF8(item->GetSerializedStateObject()); | 336 base::SysNSStringToUTF8(item->GetSerializedStateObject()); |
| 328 state_updated = item_state == serialized_state; | 337 state_updated = item_state == serialized_state; |
| 329 return state_updated; | 338 return state_updated; |
| 330 }); | 339 }); |
| 331 EXPECT_TRUE(state_updated); | 340 EXPECT_TRUE(state_updated); |
| 332 // Verify that the forward navigation was not pruned. | 341 // Verify that the forward navigation was not pruned. |
| 333 EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1, | 342 EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1, |
| 334 GetIndexOfNavigationItem(about_blank_item)); | 343 GetIndexOfNavigationItem(about_blank_item)); |
| 335 } | 344 } |
| 345 | |
| 346 // Tests that the state object is reset to the correct value after reloading a | |
| 347 // page whose state has been replaced. | |
| 348 TEST_F(HistoryStateOperationsTest, StateReplacementReload) { | |
| 349 // Set up the state parameters and tap the replace state button. | |
| 350 std::string new_state("STATE OBJECT"); | |
| 351 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.
| |
| 352 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.
| |
| 353 SetStateParams(new_state, empty_title, empty_url); | |
| 354 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateID)); | |
| 355 // Reload the page and check that the state object is present. | |
| 356 Reload(); | |
| 357 ASSERT_TRUE(IsOnLoadTextVisible()); | |
| 358 __block bool state_object_present = false; | |
| 359 base::string16 state_object_script = ASCIIToUTF16("window.history.state"); | |
| 360 base::test::ios::TimeUntilCondition( | |
| 361 ^{ | |
| 362 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.
| |
| 363 state_object_script, base::BindBlock(^(const base::Value* result) { | |
| 364 std::string state; | |
| 365 result->GetAsString(&state); | |
| 366 state_object_present = state == new_state; | |
| 367 })); | |
| 368 }, | |
| 369 ^bool { | |
| 370 return state_object_present; | |
| 371 }, | |
| 372 false, base::TimeDelta::FromSeconds(10.0)); | |
| 373 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.
| |
| 374 } | |
| OLD | NEW |