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

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

Issue 2606003002: Created test for title replacement via window.history.replaceState(). (Closed)
Patch Set: rebase & eugene's comments 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 #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/utf_string_conversions.h"
7 #include "base/test/ios/wait_util.h" 8 #include "base/test/ios/wait_util.h"
8 #import "ios/web/public/navigation_item.h" 9 #import "ios/web/public/navigation_item.h"
9 #import "ios/web/public/navigation_manager.h" 10 #import "ios/web/public/navigation_manager.h"
10 #import "ios/web/public/test/http_server.h" 11 #import "ios/web/public/test/http_server.h"
11 #include "ios/web/public/test/http_server_util.h" 12 #include "ios/web/public/test/http_server_util.h"
12 #import "ios/web/public/test/web_view_interaction_test_util.h" 13 #import "ios/web/public/test/web_view_interaction_test_util.h"
13 #import "ios/web/public/web_state/web_state.h" 14 #import "ios/web/public/web_state/web_state.h"
14 #import "ios/web/test/web_int_test.h" 15 #import "ios/web/test/web_int_test.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/gtest_mac.h" 17 #include "testing/gtest_mac.h"
17 #include "url/url_canon.h" 18 #include "url/url_canon.h"
18 19
20 using base::ASCIIToUTF16;
21
19 namespace { 22 namespace {
20 23
21 // URL for the test window.location test file. The page at this URL contains 24 // URL for the test window.location test file. The page at this URL contains
22 // several buttons that trigger window.location commands. The page supports 25 // several buttons that trigger window.location commands. The page supports
23 // several JavaScript functions: 26 // several JavaScript functions:
24 // - updateUrlToLoadText(), which takes a URL and updates a div on the page to 27 // - updateUrlToLoadText(), which takes a URL and updates a div on the page to
25 // contain that text. This URL is used as the parameter for window.location 28 // contain that text. This URL is used as the parameter for window.location
26 // function calls triggered by button taps. 29 // function calls triggered by button taps.
27 // - getUrl(), which returns the URL that was set via updateUrlToLoadText(). 30 // - getUrl(), which returns the URL that was set via updateUrlToLoadText().
28 // - isOnLoadTextVisible(), which returns whether a placeholder string is 31 // - isOnLoadTextVisible(), which returns whether a placeholder string is
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 url::Replacements<char> port_replacement; 201 url::Replacements<char> port_replacement;
199 port_replacement.SetPort(new_port_string.c_str(), 202 port_replacement.SetPort(new_port_string.c_str(),
200 url::Component(0, new_port_string.length())); 203 url::Component(0, new_port_string.length()));
201 GURL different_origin_url = 204 GURL different_origin_url =
202 state_operations_url().ReplaceComponents(port_replacement); 205 state_operations_url().ReplaceComponents(port_replacement);
203 ASSERT_TRUE(IsOnLoadTextVisible()); 206 ASSERT_TRUE(IsOnLoadTextVisible());
204 SetStateParams(empty_state, empty_title, different_origin_url); 207 SetStateParams(empty_state, empty_title, different_origin_url);
205 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId)); 208 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId));
206 WaitForNoOpText(); 209 WaitForNoOpText();
207 } 210 }
211
212 // Tests that calling window.history.replaceState() with only a new title
213 // successfully replaces the current NavigationItem's title.
214 // TODO(crbug.com/677356): Enable this test once the NavigationItem's title is
215 // updated from within the web layer.
216 TEST_F(HistoryStateOperationsTest, DISABLED_TitleReplacement) {
217 // Navigate to about:blank then navigate back to the test page. The created
218 // NavigationItem can be used later to verify that the title is replaced
219 // rather than pushed.
220 GURL about_blank("about:blank");
221 LoadUrl(about_blank);
222 web::NavigationItem* about_blank_item = GetLastCommittedItem();
223 ExecuteBlockAndWaitForLoad(state_operations_url(), ^{
224 navigation_manager()->GoBack();
225 });
226 EXPECT_EQ(state_operations_url(), GetLastCommittedItem()->GetURL());
227 // Set up the state parameters and tap the replace state button.
228 std::string empty_state;
229 std::string new_title("NEW TITLE");
230 GURL empty_url;
231 SetStateParams(empty_state, new_title, empty_url);
232 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId));
233 // Wait for the title to be reflected in the NavigationItem.
234 base::test::ios::WaitUntilCondition(^bool {
235 return GetLastCommittedItem()->GetTitle() == ASCIIToUTF16(new_title);
236 });
237 // Verify that the forward navigation was not pruned.
238 EXPECT_EQ(GetIndexOfNavigationItem(GetLastCommittedItem()) + 1,
239 GetIndexOfNavigationItem(about_blank_item));
240 }
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