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

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

Issue 2602013002: Created test verifying setting the state object via replaceState() (Closed)
Patch Set: Created 3 years, 11 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 #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"
Eugene But (OOO till 7-30) 2016/12/29 17:12:59 s/import/include
kkhorimoto 2017/01/24 04:57:15 Done.
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/ios/wait_util.h" 10 #include "base/test/ios/wait_util.h"
11 #import "ios/web/navigation/navigation_item_impl.h"
10 #include "ios/web/public/navigation_item.h" 12 #include "ios/web/public/navigation_item.h"
11 #include "ios/web/public/navigation_manager.h" 13 #include "ios/web/public/navigation_manager.h"
12 #import "ios/web/public/test/http_server.h" 14 #import "ios/web/public/test/http_server.h"
13 #include "ios/web/public/test/http_server_util.h" 15 #include "ios/web/public/test/http_server_util.h"
14 #import "ios/web/public/test/web_view_interaction_test_util.h" 16 #import "ios/web/public/test/web_view_interaction_test_util.h"
15 #include "ios/web/public/web_state/web_state.h" 17 #include "ios/web/public/web_state/web_state.h"
16 #include "ios/web/public/web_state/web_state_observer.h" 18 #include "ios/web/public/web_state/web_state_observer.h"
17 #import "ios/web/test/web_int_test.h" 19 #import "ios/web/test/web_int_test.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/gtest_mac.h" 21 #include "testing/gtest_mac.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 __block bool title_updated = false; 290 __block bool title_updated = false;
289 base::test::ios::WaitUntilCondition(^bool { 291 base::test::ios::WaitUntilCondition(^bool {
290 title_updated = current_item()->GetTitle() == ASCIIToUTF16(new_title); 292 title_updated = current_item()->GetTitle() == ASCIIToUTF16(new_title);
291 return title_updated; 293 return title_updated;
292 }); 294 });
293 EXPECT_TRUE(title_updated); 295 EXPECT_TRUE(title_updated);
294 // Verify that the forward navigation was not pruned. 296 // Verify that the forward navigation was not pruned.
295 EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1, 297 EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1,
296 GetIndexOfNavigationItem(about_blank_item)); 298 GetIndexOfNavigationItem(about_blank_item));
297 } 299 }
300
301 // Tests that calling window.history.replaceState() with a new state object
302 // replaces the state object for the current NavigationItem.
303 TEST_F(HistoryStateOperationsTest, StateReplacement) {
304 // Navigate to about:blank then navigate back to the test page. The created
305 // NavigationItem can be used later to verify that the state is replaced
306 // rather than pushed.
307 GURL about_blank("about:blank");
308 LoadUrl(about_blank);
309 web::NavigationItem* about_blank_item = current_item();
310 ExpectPageLoad(state_operations_url());
311 navigation_manager()->GoBack();
312 WaitForPageToLoad();
313 ASSERT_EQ(state_operations_url(), current_item()->GetURL());
314 // Set up the state parameters and tap the replace state button.
315 std::string new_state("STATE OBJECT");
316 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.
317 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.
318 SetStateParams(new_state, empty_title, empty_url);
319 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateID));
320 // Verify that the state is reflected in the latest NavigationItem.
321 std::string serialized_state("\"STATE OBJECT\"");
322 __block bool state_updated = false;
323 base::test::ios::WaitUntilCondition(^bool {
324 web::NavigationItemImpl* item =
325 static_cast<web::NavigationItemImpl*>(current_item());
326 std::string item_state =
327 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
328 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.
329 return state_updated;
330 });
331 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.
332 // Verify that the forward navigation was not pruned.
333 EXPECT_EQ(GetIndexOfNavigationItem(current_item()) + 1,
334 GetIndexOfNavigationItem(about_blank_item));
335 }
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