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

Side by Side Diff: ios/web/navigation/history_state_operations_inttest.mm

Issue 2607603005: Created test verifying resetting the state object after reloading. (Closed)
Patch Set: rebase + eugene's comments Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/ios/wait_util.h" 9 #include "base/test/ios/wait_util.h"
10 #import "ios/web/navigation/navigation_item_impl.h" 10 #import "ios/web/navigation/navigation_item_impl.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 // Load the history state test page. 63 // Load the history state test page.
64 state_operations_url_ = 64 state_operations_url_ =
65 web::test::HttpServer::MakeUrl(kHistoryStateOperationsTestUrl); 65 web::test::HttpServer::MakeUrl(kHistoryStateOperationsTestUrl);
66 LoadUrl(state_operations_url()); 66 LoadUrl(state_operations_url());
67 } 67 }
68 68
69 // The URL of the window.location test page. 69 // The URL of the window.location test page.
70 const GURL& state_operations_url() { return state_operations_url_; } 70 const GURL& state_operations_url() { return state_operations_url_; }
71 71
72 // Reloads the page and waits for the load to finish.
73 void Reload() {
74 ExecuteBlockAndWaitForLoad(GetLastCommittedItem()->GetURL(), ^{
75 // TODO(crbug.com/677364): Use NavigationManager::Reload() once it no
76 // longer requires a web delegate.
77 web_state()->ExecuteJavaScript(ASCIIToUTF16("window.location.reload()"));
78 });
79 }
80
72 // Sets the parameters to use for state operations on the test page. This 81 // Sets the parameters to use for state operations on the test page. This
73 // function executes a script that populates JavaScript values on the test 82 // function executes a script that populates JavaScript values on the test
74 // page. When the "push-state" or "replace-state" buttons are tapped, these 83 // page. When the "push-state" or "replace-state" buttons are tapped, these
75 // parameters will be passed to their corresponding JavaScript function calls. 84 // parameters will be passed to their corresponding JavaScript function calls.
76 void SetStateParams(const std::string& state_object, 85 void SetStateParams(const std::string& state_object,
77 const std::string& title, 86 const std::string& title,
78 const GURL& url) { 87 const GURL& url) {
79 ASSERT_EQ(state_operations_url(), GetLastCommittedItem()->GetURL()); 88 ASSERT_EQ(state_operations_url(), GetLastCommittedItem()->GetURL());
80 std::string url_spec = url.possibly_invalid_spec(); 89 std::string url_spec = url.possibly_invalid_spec();
81 NSString* set_params_script = [NSString 90 NSString* set_params_script = [NSString
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 web::NavigationItemImpl* item = 284 web::NavigationItemImpl* item =
276 static_cast<web::NavigationItemImpl*>(GetLastCommittedItem()); 285 static_cast<web::NavigationItemImpl*>(GetLastCommittedItem());
277 std::string item_state = 286 std::string item_state =
278 base::SysNSStringToUTF8(item->GetSerializedStateObject()); 287 base::SysNSStringToUTF8(item->GetSerializedStateObject());
279 return item_state == serialized_state; 288 return item_state == serialized_state;
280 }); 289 });
281 // Verify that the forward navigation was not pruned. 290 // Verify that the forward navigation was not pruned.
282 EXPECT_EQ(GetIndexOfNavigationItem(GetLastCommittedItem()) + 1, 291 EXPECT_EQ(GetIndexOfNavigationItem(GetLastCommittedItem()) + 1,
283 GetIndexOfNavigationItem(about_blank_item)); 292 GetIndexOfNavigationItem(about_blank_item));
284 } 293 }
294
295 // Tests that the state object is reset to the correct value after reloading a
296 // page whose state has been replaced.
297 TEST_F(HistoryStateOperationsTest, StateReplacementReload) {
298 // Set up the state parameters and tap the replace state button.
299 std::string new_state("STATE OBJECT");
300 std::string empty_title;
301 GURL empty_url;
302 SetStateParams(new_state, empty_title, empty_url);
303 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId));
304 // Reload the page and check that the state object is present.
305 Reload();
306 ASSERT_TRUE(IsOnLoadTextVisible());
307 base::test::ios::WaitUntilCondition(^bool {
308 return GetJavaScriptState() == new_state;
309 });
310 }
OLDNEW
« 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