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

Side by Side Diff: ios/chrome/browser/web/push_and_replace_state_navigation_egtest.mm

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting Created 3 years, 8 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
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 <XCTest/XCTest.h> 5 #import <XCTest/XCTest.h>
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
9 #include "ios/chrome/browser/ui/ui_util.h" 9 #include "ios/chrome/browser/ui/ui_util.h"
10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 // Tests calling pushState with unicode characters. 225 // Tests calling pushState with unicode characters.
226 - (void)testHtml5HistoryPushUnicodeCharacters { 226 - (void)testHtml5HistoryPushUnicodeCharacters {
227 const GURL pushStateUnicodeURLEncoded = web::test::HttpServer::MakeUrl( 227 const GURL pushStateUnicodeURLEncoded = web::test::HttpServer::MakeUrl(
228 "http://ios/testing/data/http_server_files/" 228 "http://ios/testing/data/http_server_files/"
229 "history.html#unicode%E1%84%91"); 229 "history.html#unicode%E1%84%91");
230 const GURL pushStateUnicode2URLEncoded = web::test::HttpServer::MakeUrl( 230 const GURL pushStateUnicode2URLEncoded = web::test::HttpServer::MakeUrl(
231 "http://ios/testing/data/http_server_files/" 231 "http://ios/testing/data/http_server_files/"
232 "history.html#unicode2%E2%88%A2"); 232 "history.html#unicode2%E2%88%A2");
233 std::string pushStateUnicodeLabel = "Action: pushStateUnicodeᄑ"; 233 NSString* pushStateUnicodeLabel = @"Action: pushStateUnicodeᄑ";
234 NSString* pushStateUnicodeStatus = @"pushStateUnicodeᄑ"; 234 NSString* pushStateUnicodeStatus = @"pushStateUnicodeᄑ";
235 std::string pushStateUnicode2Label = "Action: pushStateUnicode2∢"; 235 NSString* pushStateUnicode2Label = @"Action: pushStateUnicode2∢";
236 NSString* pushStateUnicode2Status = @"pushStateUnicode2∢"; 236 NSString* pushStateUnicode2Status = @"pushStateUnicode2∢";
237 237
238 web::test::SetUpFileBasedHttpServer(); 238 web::test::SetUpFileBasedHttpServer();
239 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kHistoryTestUrl)]; 239 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kHistoryTestUrl)];
240 240
241 // TODO(crbug.com/643458): The fact that the URL shows %-escaped is due to 241 // TODO(crbug.com/643458): The fact that the URL shows %-escaped is due to
242 // NSURL escaping to make UIWebView/JS happy. See if it's possible to 242 // NSURL escaping to make UIWebView/JS happy. See if it's possible to
243 // represent differently such that it displays unescaped. 243 // represent differently such that it displays unescaped.
244 // Do 2 push states with unicode characters. 244 // Do 2 push states with unicode characters.
245 [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode"]; 245 [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode"];
246 [[EarlGrey 246 [[EarlGrey
247 selectElementWithMatcher:chrome_test_util::OmniboxText( 247 selectElementWithMatcher:chrome_test_util::OmniboxText(
248 pushStateUnicodeURLEncoded.GetContent())] 248 pushStateUnicodeURLEncoded.GetContent())]
249 assertWithMatcher:grey_notNil()]; 249 assertWithMatcher:grey_notNil()];
250 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 250 [ChromeEarlGrey waitForWebViewContainingText:pushStateUnicodeLabel];
251 pushStateUnicodeLabel)]
252 assertWithMatcher:grey_notNil()];
253 251
254 [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode2"]; 252 [ChromeEarlGrey tapWebViewElementWithID:@"pushStateUnicode2"];
255 [[EarlGrey 253 [[EarlGrey
256 selectElementWithMatcher:chrome_test_util::OmniboxText( 254 selectElementWithMatcher:chrome_test_util::OmniboxText(
257 pushStateUnicode2URLEncoded.GetContent())] 255 pushStateUnicode2URLEncoded.GetContent())]
258 assertWithMatcher:grey_notNil()]; 256 assertWithMatcher:grey_notNil()];
259 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 257 [ChromeEarlGrey waitForWebViewContainingText:pushStateUnicode2Label];
260 pushStateUnicode2Label)]
261 assertWithMatcher:grey_notNil()];
262 258
263 // Do a push state without a unicode character. 259 // Do a push state without a unicode character.
264 const GURL pushStatePathURL = 260 const GURL pushStatePathURL =
265 web::test::HttpServer::MakeUrl(kPushStatePathURL); 261 web::test::HttpServer::MakeUrl(kPushStatePathURL);
266 [ChromeEarlGrey tapWebViewElementWithID:@"pushStatePath"]; 262 [ChromeEarlGrey tapWebViewElementWithID:@"pushStatePath"];
267 263
268 [self assertStatusText:@"pushStatePath" 264 [self assertStatusText:@"pushStatePath"
269 withURL:pushStatePathURL 265 withURL:pushStatePathURL
270 pageLoaded:NO]; 266 pageLoaded:NO];
271 267
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 assertWithMatcher:grey_notNil()]; 315 assertWithMatcher:grey_notNil()];
320 } 316 }
321 317
322 #pragma mark - Utility methods 318 #pragma mark - Utility methods
323 319
324 // Assert that status text |status| is displayed in the webview, that "onloaded" 320 // Assert that status text |status| is displayed in the webview, that "onloaded"
325 // text is displayed if pageLoaded is YES, and that the URL is as expected. 321 // text is displayed if pageLoaded is YES, and that the URL is as expected.
326 - (void)assertStatusText:(NSString*)status 322 - (void)assertStatusText:(NSString*)status
327 withURL:(const GURL&)urlToVerify 323 withURL:(const GURL&)urlToVerify
328 pageLoaded:(BOOL)pageLoaded { 324 pageLoaded:(BOOL)pageLoaded {
329 id<GREYMatcher> pageLoadedMatcher = 325 if (pageLoaded) {
330 pageLoaded ? chrome_test_util::WebViewContainingText("onload") 326 [ChromeEarlGrey waitForWebViewContainingText:@"onload"];
331 : chrome_test_util::WebViewNotContainingText("onload"); 327 } else {
332 [[EarlGrey selectElementWithMatcher:pageLoadedMatcher] 328 id<GREYMatcher> pageLoadedMatcher =
333 assertWithMatcher:grey_notNil()]; 329 chrome_test_util::WebViewNotContainingText("onload");
330 [[EarlGrey selectElementWithMatcher:pageLoadedMatcher]
331 assertWithMatcher:grey_notNil()];
332 }
334 333
335 if (status != NULL) { 334 if (status != NULL) {
336 NSString* statusLabel = [NSString stringWithFormat:@"Action: %@", status]; 335 NSString* statusLabel = [NSString stringWithFormat:@"Action: %@", status];
337 [[EarlGrey 336 [ChromeEarlGrey waitForWebViewContainingText:statusLabel];
338 selectElementWithMatcher:chrome_test_util::WebViewContainingText(
339 base::SysNSStringToUTF8(statusLabel))]
340 assertWithMatcher:grey_notNil()];
341 } 337 }
342 338
343 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( 339 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
344 urlToVerify.GetContent())] 340 urlToVerify.GetContent())]
345 assertWithMatcher:grey_notNil()]; 341 assertWithMatcher:grey_notNil()];
346 } 342 }
347 343
348 @end 344 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698