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

Side by Side Diff: ios/chrome/browser/web/visible_url_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 <EarlGrey/EarlGrey.h> 5 #import <EarlGrey/EarlGrey.h>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/version_info/version_info.h" 11 #include "components/version_info/version_info.h"
12 #include "ios/chrome/browser/chrome_url_constants.h" 12 #include "ios/chrome/browser/chrome_url_constants.h"
13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
15 #include "ios/chrome/browser/ui/ui_util.h" 15 #include "ios/chrome/browser/ui/ui_util.h"
16 #import "ios/chrome/test/app/chrome_test_util.h" 16 #import "ios/chrome/test/app/chrome_test_util.h"
17 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 17 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
18 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" 18 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
19 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 19 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
20 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 20 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
21 #import "ios/web/public/test/http_server.h" 21 #import "ios/web/public/test/http_server.h"
22 #include "ios/web/public/test/http_server_util.h" 22 #include "ios/web/public/test/http_server_util.h"
23 #include "ios/web/public/test/response_providers/html_response_provider.h" 23 #include "ios/web/public/test/response_providers/html_response_provider.h"
24 #include "ios/web/public/test/url_test_util.h" 24 #include "ios/web/public/test/url_test_util.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 using chrome_test_util::WebViewContainingText; 27 using base::SysUTF8ToNSString;
28 using chrome_test_util::OmniboxText; 28 using chrome_test_util::OmniboxText;
29 29
30 namespace { 30 namespace {
31 31
32 const char kTestPage1[] = "Test Page 1"; 32 const char kTestPage1[] = "Test Page 1";
33 const char kTestPage2[] = "Test Page 2"; 33 const char kTestPage2[] = "Test Page 2";
34 const char kTestPage3[] = "Test Page 3"; 34 const char kTestPage3[] = "Test Page 3";
35 const char kGoBackLink[] = "go-back"; 35 const char kGoBackLink[] = "go-back";
36 const char kGoForwardLink[] = "go-forward"; 36 const char kGoForwardLink[] = "go-forward";
37 const char kGoNegativeDeltaLink[] = "go-negative-delta"; 37 const char kGoNegativeDeltaLink[] = "go-negative-delta";
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // displayed even though URL1 is a pending URL. 187 // displayed even though URL1 is a pending URL.
188 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 188 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
189 performAction:grey_tap()]; 189 performAction:grey_tap()];
190 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 190 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
191 @"Last request URL: %@", self.lastRequestURLSpec); 191 @"Last request URL: %@", self.lastRequestURLSpec);
192 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 192 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
193 assertWithMatcher:grey_notNil()]; 193 assertWithMatcher:grey_notNil()];
194 194
195 // Make server respond so URL1 becomes committed. 195 // Make server respond so URL1 becomes committed.
196 [self setServerPaused:NO]; 196 [self setServerPaused:NO];
197 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 197 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
198 assertWithMatcher:grey_notNil()];
199 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 198 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
200 assertWithMatcher:grey_notNil()]; 199 assertWithMatcher:grey_notNil()];
201 200
202 // Purge web view caches and pause the server to make sure that tests can 201 // Purge web view caches and pause the server to make sure that tests can
203 // verify omnibox state before server starts responding. 202 // verify omnibox state before server starts responding.
204 PurgeCachedWebViewPages(); 203 PurgeCachedWebViewPages();
205 [self setServerPaused:YES]; 204 [self setServerPaused:YES];
206 205
207 // Tap the forward button in the toolbar and verify that URL1 (committed URL) 206 // Tap the forward button in the toolbar and verify that URL1 (committed URL)
208 // is displayed even though URL2 is a pending URL. 207 // is displayed even though URL2 is a pending URL.
209 [[EarlGrey selectElementWithMatcher:chrome_test_util::ForwardButton()] 208 [[EarlGrey selectElementWithMatcher:chrome_test_util::ForwardButton()]
210 performAction:grey_tap()]; 209 performAction:grey_tap()];
211 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], 210 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
212 @"Last request URL: %@", self.lastRequestURLSpec); 211 @"Last request URL: %@", self.lastRequestURLSpec);
213 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 212 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
214 assertWithMatcher:grey_notNil()]; 213 assertWithMatcher:grey_notNil()];
215 214
216 // Make server respond so URL2 becomes committed. 215 // Make server respond so URL2 becomes committed.
217 [self setServerPaused:NO]; 216 [self setServerPaused:NO];
218 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] 217 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage2)];
219 assertWithMatcher:grey_notNil()];
220 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 218 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
221 assertWithMatcher:grey_notNil()]; 219 assertWithMatcher:grey_notNil()];
222 } 220 }
223 221
224 // Tests that visible URL is always the same as last committed URL during 222 // Tests that visible URL is always the same as last committed URL during
225 // pending navigations initialted from back history popover. 223 // pending navigations initialted from back history popover.
226 - (void)testHistoryNavigation { 224 - (void)testHistoryNavigation {
227 // Purge web view caches and pause the server to make sure that tests can 225 // Purge web view caches and pause the server to make sure that tests can
228 // verify omnibox state before server starts responding. 226 // verify omnibox state before server starts responding.
229 PurgeCachedWebViewPages(); 227 PurgeCachedWebViewPages();
230 [self setServerPaused:YES]; 228 [self setServerPaused:YES];
231 229
232 // Go back in history and verify that URL2 (committed URL) is displayed even 230 // Go back in history and verify that URL2 (committed URL) is displayed even
233 // though URL1 is a pending URL. 231 // though URL1 is a pending URL.
234 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 232 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
235 performAction:grey_longPress()]; 233 performAction:grey_longPress()];
236 NSString* URL1Title = 234 NSString* URL1Title =
237 base::SysUTF16ToNSString(web::GetDisplayTitleForUrl(_testURL1)); 235 base::SysUTF16ToNSString(web::GetDisplayTitleForUrl(_testURL1));
238 [[EarlGrey selectElementWithMatcher:grey_text(URL1Title)] 236 [[EarlGrey selectElementWithMatcher:grey_text(URL1Title)]
239 performAction:grey_tap()]; 237 performAction:grey_tap()];
240 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 238 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
241 @"Last request URL: %@", self.lastRequestURLSpec); 239 @"Last request URL: %@", self.lastRequestURLSpec);
242 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 240 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
243 assertWithMatcher:grey_notNil()]; 241 assertWithMatcher:grey_notNil()];
244 242
245 // Make server respond so URL1 becomes committed. 243 // Make server respond so URL1 becomes committed.
246 [self setServerPaused:NO]; 244 [self setServerPaused:NO];
247 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 245 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
248 assertWithMatcher:grey_notNil()];
249 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 246 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
250 assertWithMatcher:grey_notNil()]; 247 assertWithMatcher:grey_notNil()];
251 } 248 }
252 249
253 // Tests that stopping a pending Back navigation and reloading reloads committed 250 // Tests that stopping a pending Back navigation and reloading reloads committed
254 // URL, not pending URL. 251 // URL, not pending URL.
255 - (void)testStoppingPendingBackNavigationAndReload { 252 - (void)testStoppingPendingBackNavigationAndReload {
256 // Purge web view caches and pause the server to make sure that tests can 253 // Purge web view caches and pause the server to make sure that tests can
257 // verify omnibox state before server starts responding. 254 // verify omnibox state before server starts responding.
258 PurgeCachedWebViewPages(); 255 PurgeCachedWebViewPages();
(...skipping 11 matching lines...) Expand all
270 setValue:@YES 267 setValue:@YES
271 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 268 forConfigKey:kGREYConfigKeySynchronizationEnabled];
272 [ChromeEarlGreyUI openToolsMenu]; 269 [ChromeEarlGreyUI openToolsMenu];
273 } 270 }
274 [[EarlGrey selectElementWithMatcher:chrome_test_util::StopButton()] 271 [[EarlGrey selectElementWithMatcher:chrome_test_util::StopButton()]
275 performAction:grey_tap()]; 272 performAction:grey_tap()];
276 [ChromeEarlGreyUI reload]; 273 [ChromeEarlGreyUI reload];
277 274
278 // Make server respond and verify that page2 was reloaded, not page1. 275 // Make server respond and verify that page2 was reloaded, not page1.
279 [self setServerPaused:NO]; 276 [self setServerPaused:NO];
280 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] 277 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage2)];
281 assertWithMatcher:grey_notNil()];
282 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 278 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
283 assertWithMatcher:grey_notNil()]; 279 assertWithMatcher:grey_notNil()];
284 } 280 }
285 281
286 // Tests that visible URL is always the same as last committed URL during 282 // Tests that visible URL is always the same as last committed URL during
287 // back forward navigations initiated with JS. 283 // back forward navigations initiated with JS.
288 - (void)testJSBackForwardNavigation { 284 - (void)testJSBackForwardNavigation {
289 // Purge web view caches and pause the server to make sure that tests can 285 // Purge web view caches and pause the server to make sure that tests can
290 // verify omnibox state before server starts responding. 286 // verify omnibox state before server starts responding.
291 PurgeCachedWebViewPages(); 287 PurgeCachedWebViewPages();
292 [self setServerPaused:YES]; 288 [self setServerPaused:YES];
293 289
294 // Tap the back button on the page and verify that URL2 (committed URL) is 290 // Tap the back button on the page and verify that URL2 (committed URL) is
295 // displayed even though URL1 is a pending URL. 291 // displayed even though URL1 is a pending URL.
296 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; 292 [ChromeEarlGrey tapWebViewElementWithID:SysUTF8ToNSString(kGoBackLink)];
297 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 293 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
298 @"Last request URL: %@", self.lastRequestURLSpec); 294 @"Last request URL: %@", self.lastRequestURLSpec);
299 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 295 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
300 assertWithMatcher:grey_notNil()]; 296 assertWithMatcher:grey_notNil()];
301 297
302 // Make server respond so URL1 becomes committed. 298 // Make server respond so URL1 becomes committed.
303 [self setServerPaused:NO]; 299 [self setServerPaused:NO];
304 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 300 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
305 assertWithMatcher:grey_notNil()];
306 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 301 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
307 assertWithMatcher:grey_notNil()]; 302 assertWithMatcher:grey_notNil()];
308 303
309 // Purge web view caches and pause the server to make sure that tests can 304 // Purge web view caches and pause the server to make sure that tests can
310 // verify omnibox state before server starts responding. 305 // verify omnibox state before server starts responding.
311 PurgeCachedWebViewPages(); 306 PurgeCachedWebViewPages();
312 [self setServerPaused:YES]; 307 [self setServerPaused:YES];
313 308
314 // Tap the forward button on the page and verify that URL1 (committed URL) 309 // Tap the forward button on the page and verify that URL1 (committed URL)
315 // is displayed even though URL2 is a pending URL. 310 // is displayed even though URL2 is a pending URL.
316 [ChromeEarlGrey 311 [ChromeEarlGrey tapWebViewElementWithID:SysUTF8ToNSString(kGoForwardLink)];
317 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoForwardLink)];
318 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], 312 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
319 @"Last request URL: %@", self.lastRequestURLSpec); 313 @"Last request URL: %@", self.lastRequestURLSpec);
320 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 314 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
321 assertWithMatcher:grey_notNil()]; 315 assertWithMatcher:grey_notNil()];
322 316
323 // Make server respond so URL2 becomes committed. 317 // Make server respond so URL2 becomes committed.
324 [self setServerPaused:NO]; 318 [self setServerPaused:NO];
325 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] 319 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage2)];
326 assertWithMatcher:grey_notNil()];
327 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 320 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
328 assertWithMatcher:grey_notNil()]; 321 assertWithMatcher:grey_notNil()];
329 } 322 }
330 323
331 // Tests that visible URL is always the same as last committed URL during go 324 // Tests that visible URL is always the same as last committed URL during go
332 // navigations initiated with JS. 325 // navigations initiated with JS.
333 - (void)testJSGoNavigation { 326 - (void)testJSGoNavigation {
334 // Purge web view caches and pause the server to make sure that tests can 327 // Purge web view caches and pause the server to make sure that tests can
335 // verify omnibox state before server starts responding. 328 // verify omnibox state before server starts responding.
336 PurgeCachedWebViewPages(); 329 PurgeCachedWebViewPages();
337 [self setServerPaused:YES]; 330 [self setServerPaused:YES];
338 331
339 // Tap the go negative delta button on the page and verify that URL2 332 // Tap the go negative delta button on the page and verify that URL2
340 // (committed URL) is displayed even though URL1 is a pending URL. 333 // (committed URL) is displayed even though URL1 is a pending URL.
341 [ChromeEarlGrey 334 [ChromeEarlGrey
342 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoNegativeDeltaLink)]; 335 tapWebViewElementWithID:SysUTF8ToNSString(kGoNegativeDeltaLink)];
343 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 336 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
344 @"Last request URL: %@", self.lastRequestURLSpec); 337 @"Last request URL: %@", self.lastRequestURLSpec);
345 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 338 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
346 assertWithMatcher:grey_notNil()]; 339 assertWithMatcher:grey_notNil()];
347 340
348 // Make server respond so URL1 becomes committed. 341 // Make server respond so URL1 becomes committed.
349 [self setServerPaused:NO]; 342 [self setServerPaused:NO];
350 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 343 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
351 assertWithMatcher:grey_notNil()];
352 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 344 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
353 assertWithMatcher:grey_notNil()]; 345 assertWithMatcher:grey_notNil()];
354 346
355 // Purge web view caches and pause the server to make sure that tests can 347 // Purge web view caches and pause the server to make sure that tests can
356 // verify omnibox state before server starts responding. 348 // verify omnibox state before server starts responding.
357 PurgeCachedWebViewPages(); 349 PurgeCachedWebViewPages();
358 [self setServerPaused:YES]; 350 [self setServerPaused:YES];
359 351
360 // Tap go positive delta button on the page and verify that URL1 (committed 352 // Tap go positive delta button on the page and verify that URL1 (committed
361 // URL) is displayed even though URL2 is a pending URL. 353 // URL) is displayed even though URL2 is a pending URL.
362 [ChromeEarlGrey 354 [ChromeEarlGrey
363 tapWebViewElementWithID:base::SysUTF8ToNSString(kGoPositiveDeltaLink)]; 355 tapWebViewElementWithID:SysUTF8ToNSString(kGoPositiveDeltaLink)];
364 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2], 356 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL2],
365 @"Last request URL: %@", self.lastRequestURLSpec); 357 @"Last request URL: %@", self.lastRequestURLSpec);
366 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 358 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
367 assertWithMatcher:grey_notNil()]; 359 assertWithMatcher:grey_notNil()];
368 360
369 // Make server respond so URL2 becomes committed. 361 // Make server respond so URL2 becomes committed.
370 [self setServerPaused:NO]; 362 [self setServerPaused:NO];
371 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage2)] 363 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage2)];
372 assertWithMatcher:grey_notNil()];
373 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 364 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
374 assertWithMatcher:grey_notNil()]; 365 assertWithMatcher:grey_notNil()];
375 } 366 }
376 367
377 // Tests that visible URL is always the same as last committed URL during go 368 // Tests that visible URL is always the same as last committed URL during go
378 // back navigation started with pending reload in progress. 369 // back navigation started with pending reload in progress.
379 - (void)testBackNavigationWithPendingReload { 370 - (void)testBackNavigationWithPendingReload {
380 // Purge web view caches and pause the server to make sure that tests can 371 // Purge web view caches and pause the server to make sure that tests can
381 // verify omnibox state before server starts responding. 372 // verify omnibox state before server starts responding.
382 PurgeCachedWebViewPages(); 373 PurgeCachedWebViewPages();
(...skipping 15 matching lines...) Expand all
398 // pending URL. 389 // pending URL.
399 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 390 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
400 performAction:grey_tap()]; 391 performAction:grey_tap()];
401 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 392 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
402 @"Last request URL: %@", self.lastRequestURLSpec); 393 @"Last request URL: %@", self.lastRequestURLSpec);
403 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 394 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
404 assertWithMatcher:grey_notNil()]; 395 assertWithMatcher:grey_notNil()];
405 396
406 // Make server respond so URL1 becomes committed. 397 // Make server respond so URL1 becomes committed.
407 [self setServerPaused:NO]; 398 [self setServerPaused:NO];
408 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 399 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
409 assertWithMatcher:grey_notNil()];
410 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 400 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
411 assertWithMatcher:grey_notNil()]; 401 assertWithMatcher:grey_notNil()];
412 } 402 }
413 403
414 // Tests that visible URL is always the same as last committed URL during go 404 // Tests that visible URL is always the same as last committed URL during go
415 // back navigation initiated with pending renderer-initiated navigation in 405 // back navigation initiated with pending renderer-initiated navigation in
416 // progress. 406 // progress.
417 - (void)testBackNavigationWithPendingRendererInitiatedNavigation { 407 - (void)testBackNavigationWithPendingRendererInitiatedNavigation {
418 // Purge web view caches and pause the server to make sure that tests can 408 // Purge web view caches and pause the server to make sure that tests can
419 // verify omnibox state before server starts responding. 409 // verify omnibox state before server starts responding.
420 PurgeCachedWebViewPages(); 410 PurgeCachedWebViewPages();
421 [self setServerPaused:YES]; 411 [self setServerPaused:YES];
422 412
423 // Start renderer initiated navigation. 413 // Start renderer initiated navigation.
424 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; 414 [ChromeEarlGrey tapWebViewElementWithID:SysUTF8ToNSString(kPage3Link)];
425 415
426 // Do not wait until renderer-initiated navigation is finished, tap the back 416 // Do not wait until renderer-initiated navigation is finished, tap the back
427 // button in the toolbar and verify that URL2 (committed URL) is displayed 417 // button in the toolbar and verify that URL2 (committed URL) is displayed
428 // even though URL1 is a pending URL. 418 // even though URL1 is a pending URL.
429 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 419 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
430 performAction:grey_tap()]; 420 performAction:grey_tap()];
431 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 421 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
432 @"Last request URL: %@", self.lastRequestURLSpec); 422 @"Last request URL: %@", self.lastRequestURLSpec);
433 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 423 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
434 assertWithMatcher:grey_notNil()]; 424 assertWithMatcher:grey_notNil()];
435 425
436 // Make server respond so URL1 becomes committed. 426 // Make server respond so URL1 becomes committed.
437 [self setServerPaused:NO]; 427 [self setServerPaused:NO];
438 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 428 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
439 assertWithMatcher:grey_notNil()];
440 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 429 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
441 assertWithMatcher:grey_notNil()]; 430 assertWithMatcher:grey_notNil()];
442 } 431 }
443 432
444 // Tests that visible URL is always the same as last committed URL during 433 // Tests that visible URL is always the same as last committed URL during
445 // renderer-initiated navigation started with pending back navigation in 434 // renderer-initiated navigation started with pending back navigation in
446 // progress. 435 // progress.
447 - (void)testRendererInitiatedNavigationWithPendingBackNavigation { 436 - (void)testRendererInitiatedNavigationWithPendingBackNavigation {
448 // Purge web view caches and pause the server to make sure that tests can 437 // Purge web view caches and pause the server to make sure that tests can
449 // verify omnibox state before server starts responding. 438 // verify omnibox state before server starts responding.
450 PurgeCachedWebViewPages(); 439 PurgeCachedWebViewPages();
451 [self setServerPaused:YES]; 440 [self setServerPaused:YES];
452 441
453 // Tap the back button in the toolbar and verify that URL2 (committed URL) is 442 // Tap the back button in the toolbar and verify that URL2 (committed URL) is
454 // displayed even though URL1 is a pending URL. 443 // displayed even though URL1 is a pending URL.
455 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 444 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
456 performAction:grey_tap()]; 445 performAction:grey_tap()];
457 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1], 446 GREYAssert([self waitForServerToReceiveRequestWithURL:_testURL1],
458 @"Last request URL: %@", self.lastRequestURLSpec); 447 @"Last request URL: %@", self.lastRequestURLSpec);
459 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 448 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
460 assertWithMatcher:grey_notNil()]; 449 assertWithMatcher:grey_notNil()];
461 450
462 // Interrupt back navigation with renderer initiated navigation. 451 // Interrupt back navigation with renderer initiated navigation.
463 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kPage3Link)]; 452 [ChromeEarlGrey tapWebViewElementWithID:SysUTF8ToNSString(kPage3Link)];
464 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())] 453 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL2.GetContent())]
465 assertWithMatcher:grey_notNil()]; 454 assertWithMatcher:grey_notNil()];
466 455
467 // Make server respond so URL1 becomes committed. 456 // Make server respond so URL1 becomes committed.
468 [self setServerPaused:NO]; 457 [self setServerPaused:NO];
469 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage3)] 458 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage3)];
470 assertWithMatcher:grey_notNil()];
471 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] 459 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())]
472 assertWithMatcher:grey_notNil()]; 460 assertWithMatcher:grey_notNil()];
473 } 461 }
474 462
475 // Tests that visible URL is always the same as last committed URL if user 463 // Tests that visible URL is always the same as last committed URL if user
476 // issues 2 go back commands. 464 // issues 2 go back commands.
477 - (void)testDoubleBackNavigation { 465 - (void)testDoubleBackNavigation {
478 // Create 3rd entry in the history, to be able to go back twice. 466 // Create 3rd entry in the history, to be able to go back twice.
479 [ChromeEarlGrey loadURL:_testURL3]; 467 [ChromeEarlGrey loadURL:_testURL3];
480 468
481 // Purge web view caches and pause the server to make sure that tests can 469 // Purge web view caches and pause the server to make sure that tests can
482 // verify omnibox state before server starts responding. 470 // verify omnibox state before server starts responding.
483 PurgeCachedWebViewPages(); 471 PurgeCachedWebViewPages();
484 [self setServerPaused:YES]; 472 [self setServerPaused:YES];
485 473
486 // Tap the back button twice in the toolbar and verify that URL3 (committed 474 // Tap the back button twice in the toolbar and verify that URL3 (committed
487 // URL) is displayed even though URL1 is a pending URL. 475 // URL) is displayed even though URL1 is a pending URL.
488 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 476 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
489 performAction:grey_tap()]; 477 performAction:grey_tap()];
490 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 478 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
491 performAction:grey_tap()]; 479 performAction:grey_tap()];
492 // Server will receive only one request either for |_testURL2| or for 480 // Server will receive only one request either for |_testURL2| or for
493 // |_testURL1| depending on load timing and then will pause. So there is no 481 // |_testURL1| depending on load timing and then will pause. So there is no
494 // need to wait for particular request. 482 // need to wait for particular request.
495 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] 483 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())]
496 assertWithMatcher:grey_notNil()]; 484 assertWithMatcher:grey_notNil()];
497 485
498 // Make server respond so URL1 becomes committed. 486 // Make server respond so URL1 becomes committed.
499 [self setServerPaused:NO]; 487 [self setServerPaused:NO];
500 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 488 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
501 assertWithMatcher:grey_notNil()];
502 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 489 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
503 assertWithMatcher:grey_notNil()]; 490 assertWithMatcher:grey_notNil()];
504 } 491 }
505 492
506 // Tests that visible URL is always the same as last committed URL if user 493 // Tests that visible URL is always the same as last committed URL if user
507 // issues 2 go forward commands to WebUI page (crbug.com/711465). 494 // issues 2 go forward commands to WebUI page (crbug.com/711465).
508 - (void)testDoubleForwardNavigationToWebUIPage { 495 - (void)testDoubleForwardNavigationToWebUIPage {
509 // Create 3rd entry in the history, to be able to go back twice. 496 // Create 3rd entry in the history, to be able to go back twice.
510 GURL URL(kChromeUIVersionURL); 497 GURL URL(kChromeUIVersionURL);
511 [ChromeEarlGrey loadURL:GURL(kChromeUIVersionURL)]; 498 [ChromeEarlGrey loadURL:GURL(kChromeUIVersionURL)];
512 499
513 // Tap the back button twice in the toolbar and wait for URL 1 to load. 500 // Tap the back button twice in the toolbar and wait for URL 1 to load.
514 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 501 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
515 performAction:grey_tap()]; 502 performAction:grey_tap()];
516 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 503 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
517 performAction:grey_tap()]; 504 performAction:grey_tap()];
518 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 505 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
519 assertWithMatcher:grey_notNil()];
520 506
521 // Quickly (using chrome command) navigate forward twice and wait for 507 // Quickly (using chrome command) navigate forward twice and wait for
522 // kChromeUIVersionURL to load. 508 // kChromeUIVersionURL to load.
523 base::scoped_nsobject<GenericChromeCommand> forwardCommand( 509 base::scoped_nsobject<GenericChromeCommand> forwardCommand(
524 [[GenericChromeCommand alloc] initWithTag:IDC_FORWARD]); 510 [[GenericChromeCommand alloc] initWithTag:IDC_FORWARD]);
525 chrome_test_util::RunCommandWithActiveViewController(forwardCommand); 511 chrome_test_util::RunCommandWithActiveViewController(forwardCommand);
526 chrome_test_util::RunCommandWithActiveViewController(forwardCommand); 512 chrome_test_util::RunCommandWithActiveViewController(forwardCommand);
527 513
528 const std::string version = version_info::GetVersionNumber(); 514 const std::string version = version_info::GetVersionNumber();
529 [[EarlGrey selectElementWithMatcher:WebViewContainingText(version)] 515 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(version)];
530 assertWithMatcher:grey_notNil()];
531 516
532 // Make sure that kChromeUIVersionURL URL is displayed in the omnibox. 517 // Make sure that kChromeUIVersionURL URL is displayed in the omnibox.
533 std::string expectedText = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(URL)); 518 std::string expectedText = base::UTF16ToUTF8(web::GetDisplayTitleForUrl(URL));
534 [[EarlGrey selectElementWithMatcher:OmniboxText(expectedText)] 519 [[EarlGrey selectElementWithMatcher:OmniboxText(expectedText)]
535 assertWithMatcher:grey_notNil()]; 520 assertWithMatcher:grey_notNil()];
536 } 521 }
537 522
538 // Tests that visible URL is always the same as last committed URL if page calls 523 // Tests that visible URL is always the same as last committed URL if page calls
539 // window.history.back() twice. 524 // window.history.back() twice.
540 - (void)testDoubleBackJSNavigation { 525 - (void)testDoubleBackJSNavigation {
541 // Create 3rd entry in the history, to be able to go back twice. 526 // Create 3rd entry in the history, to be able to go back twice.
542 [ChromeEarlGrey loadURL:_testURL3]; 527 [ChromeEarlGrey loadURL:_testURL3];
543 528
544 // Purge web view caches and pause the server to make sure that tests can 529 // Purge web view caches and pause the server to make sure that tests can
545 // verify omnibox state before server starts responding. 530 // verify omnibox state before server starts responding.
546 PurgeCachedWebViewPages(); 531 PurgeCachedWebViewPages();
547 [self setServerPaused:YES]; 532 [self setServerPaused:YES];
548 533
549 // Tap the back button twice on the page and verify that URL3 (committed URL) 534 // Tap the back button twice on the page and verify that URL3 (committed URL)
550 // is displayed even though URL1 is a pending URL. 535 // is displayed even though URL1 is a pending URL.
551 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; 536 [ChromeEarlGrey tapWebViewElementWithID:SysUTF8ToNSString(kGoBackLink)];
552 [ChromeEarlGrey tapWebViewElementWithID:base::SysUTF8ToNSString(kGoBackLink)]; 537 [ChromeEarlGrey tapWebViewElementWithID:SysUTF8ToNSString(kGoBackLink)];
553 // Server will receive only one request either for |_testURL2| or for 538 // Server will receive only one request either for |_testURL2| or for
554 // |_testURL1| depending on load timing and then will pause. So there is no 539 // |_testURL1| depending on load timing and then will pause. So there is no
555 // need to wait for particular request. 540 // need to wait for particular request.
556 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())] 541 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL3.GetContent())]
557 assertWithMatcher:grey_notNil()]; 542 assertWithMatcher:grey_notNil()];
558 543
559 // Make server respond so URL1 becomes committed. 544 // Make server respond so URL1 becomes committed.
560 [self setServerPaused:NO]; 545 [self setServerPaused:NO];
561 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPage1)] 546 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kTestPage1)];
562 assertWithMatcher:grey_notNil()];
563 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())] 547 [[EarlGrey selectElementWithMatcher:OmniboxText(_testURL1.GetContent())]
564 assertWithMatcher:grey_notNil()]; 548 assertWithMatcher:grey_notNil()];
565 } 549 }
566 550
567 #pragma mark - 551 #pragma mark -
568 #pragma mark Private 552 #pragma mark Private
569 553
570 - (NSString*)lastRequestURLSpec { 554 - (NSString*)lastRequestURLSpec {
571 return base::SysUTF8ToNSString(_responseProvider->last_request_url().spec()); 555 return SysUTF8ToNSString(_responseProvider->last_request_url().spec());
572 } 556 }
573 557
574 - (void)setServerPaused:(BOOL)paused { 558 - (void)setServerPaused:(BOOL)paused {
575 // Disable EG synchronization if server is paused so the framework does not 559 // Disable EG synchronization if server is paused so the framework does not
576 // wait until the tab loading spinner or progress bar indicator becomes idle 560 // wait until the tab loading spinner or progress bar indicator becomes idle
577 // (which will not happen until server responds and the navigation is 561 // (which will not happen until server responds and the navigation is
578 // finished). 562 // finished).
579 [[GREYConfiguration sharedInstance] 563 [[GREYConfiguration sharedInstance]
580 setValue:@(!paused) 564 setValue:@(!paused)
581 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 565 forConfigKey:kGREYConfigKeySynchronizationEnabled];
582 566
583 _responseProvider->set_paused(paused); 567 _responseProvider->set_paused(paused);
584 } 568 }
585 569
586 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL { 570 - (BOOL)waitForServerToReceiveRequestWithURL:(GURL)URL {
587 return [[GREYCondition 571 return [[GREYCondition
588 conditionWithName:@"Wait for received request" 572 conditionWithName:@"Wait for received request"
589 block:^{ 573 block:^{
590 return _responseProvider->last_request_url() == URL ? YES 574 return _responseProvider->last_request_url() == URL ? YES
591 : NO; 575 : NO;
592 }] waitWithTimeout:10]; 576 }] waitWithTimeout:10];
593 } 577 }
594 578
595 @end 579 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698