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