| 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 <XCTest/XCTest.h> | 5 #import <XCTest/XCTest.h> |
| 6 | 6 |
| 7 #include "base/ios/ios_util.h" | 7 #include "base/ios/ios_util.h" |
| 8 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
| 9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 13 #import "ios/testing/earl_grey/disabled_test_macros.h" | 13 #import "ios/testing/earl_grey/disabled_test_macros.h" |
| 14 #import "ios/web/public/test/http_server.h" | 14 #import "ios/web/public/test/http_server.h" |
| 15 #include "ios/web/public/test/http_server_util.h" | 15 #include "ios/web/public/test/http_server_util.h" |
| 16 #include "ios/web/public/test/response_providers/data_response_provider.h" | 16 #include "ios/web/public/test/response_providers/data_response_provider.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 | 18 |
| 19 using chrome_test_util::backButton; | 19 using chrome_test_util::BackButton; |
| 20 using chrome_test_util::forwardButton; | 20 using chrome_test_util::ForwardButton; |
| 21 using chrome_test_util::TapWebViewElementWithId; | 21 using chrome_test_util::TapWebViewElementWithId; |
| 22 using chrome_test_util::webViewContainingText; | 22 using chrome_test_util::WebViewContainingText; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // URL for the test window.history.go() test file. The page at this URL | 26 // URL for the test window.history.go() test file. The page at this URL |
| 27 // contains several buttons that trigger window.history commands. Additionally | 27 // contains several buttons that trigger window.history commands. Additionally |
| 28 // the page contains several divs used to display the state of the page: | 28 // the page contains several divs used to display the state of the page: |
| 29 // - A div that is populated with |kOnLoadText| when the onload event fires. | 29 // - A div that is populated with |kOnLoadText| when the onload event fires. |
| 30 // - A div that is populated with |kNoOpText| 1s after a button is tapped. | 30 // - A div that is populated with |kNoOpText| 1s after a button is tapped. |
| 31 // - A div that is populated with |kPopStateReceivedText| when a popstate event | 31 // - A div that is populated with |kPopStateReceivedText| when a popstate event |
| 32 // is received by the page. | 32 // is received by the page. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 "<html>" | 99 "<html>" |
| 100 "<input type=\"button\" value=\"ForwardHTMLButton\"" | 100 "<input type=\"button\" value=\"ForwardHTMLButton\"" |
| 101 "id=\"ForwardHTMLButton\" onclick=\"window.history.forward()\" /></br>" | 101 "id=\"ForwardHTMLButton\" onclick=\"window.history.forward()\" /></br>" |
| 102 "Forward page loaded</html>"; | 102 "Forward page loaded</html>"; |
| 103 web::test::SetUpSimpleHttpServer(responses); | 103 web::test::SetUpSimpleHttpServer(responses); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Matcher for the error page. | 106 // Matcher for the error page. |
| 107 // TODO(crbug.com/638674): Evaluate if this can move to shared code. See | 107 // TODO(crbug.com/638674): Evaluate if this can move to shared code. See |
| 108 // ios/chrome/browser/ui/error_page_egtest.mm. | 108 // ios/chrome/browser/ui/error_page_egtest.mm. |
| 109 id<GREYMatcher> errorPage() { | 109 id<GREYMatcher> ErrorPage() { |
| 110 NSString* const kDNSError = | 110 NSString* const kDNSError = |
| 111 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); | 111 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |
| 112 NSString* const kInternetDisconnectedError = | 112 NSString* const kInternetDisconnectedError = |
| 113 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED); | 113 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_INTERNET_DISCONNECTED); |
| 114 return grey_anyOf(chrome_test_util::staticHtmlViewContainingText(kDNSError), | 114 return grey_anyOf(chrome_test_util::StaticHtmlViewContainingText(kDNSError), |
| 115 chrome_test_util::staticHtmlViewContainingText( | 115 chrome_test_util::StaticHtmlViewContainingText( |
| 116 kInternetDisconnectedError), | 116 kInternetDisconnectedError), |
| 117 nil); | 117 nil); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // URLs for server redirect tests. | 120 // URLs for server redirect tests. |
| 121 const char kRedirectIndexURL[] = "http://redirect"; | 121 const char kRedirectIndexURL[] = "http://redirect"; |
| 122 const char kRedirect301URL[] = "http://redirect/redirect?code=301"; | 122 const char kRedirect301URL[] = "http://redirect/redirect?code=301"; |
| 123 const char kRedirectWindowURL[] = "http://redirect/redirectWindow.html"; | 123 const char kRedirectWindowURL[] = "http://redirect/redirectWindow.html"; |
| 124 const char kRedirectRefreshURL[] = "http://redirect/redirectRefresh.html"; | 124 const char kRedirectRefreshURL[] = "http://redirect/redirectRefresh.html"; |
| 125 const char kDestinationURL[] = "http://redirect/destination.html"; | 125 const char kDestinationURL[] = "http://redirect/destination.html"; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 #pragma mark window.history.go operations | 212 #pragma mark window.history.go operations |
| 213 | 213 |
| 214 // Tests reloading the current page via window.history.go() with no parameters. | 214 // Tests reloading the current page via window.history.go() with no parameters. |
| 215 - (void)testHistoryGoNoParameter { | 215 - (void)testHistoryGoNoParameter { |
| 216 web::test::SetUpFileBasedHttpServer(); | 216 web::test::SetUpFileBasedHttpServer(); |
| 217 | 217 |
| 218 // Load the history test page and ensure that its onload text is visible. | 218 // Load the history test page and ensure that its onload text is visible. |
| 219 const GURL windowHistoryURL = | 219 const GURL windowHistoryURL = |
| 220 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 220 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 221 [ChromeEarlGrey loadURL:windowHistoryURL]; | 221 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 222 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 222 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 223 assertWithMatcher:grey_notNil()]; | 223 assertWithMatcher:grey_notNil()]; |
| 224 | 224 |
| 225 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so | 225 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so |
| 226 // the subsequent check for |kOnLoadText| will only pass if a reload has | 226 // the subsequent check for |kOnLoadText| will only pass if a reload has |
| 227 // occurred. | 227 // occurred. |
| 228 [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID]; | 228 [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID]; |
| 229 | 229 |
| 230 // Verify that the onload text is reset. | 230 // Verify that the onload text is reset. |
| 231 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 231 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 232 assertWithMatcher:grey_notNil()]; | 232 assertWithMatcher:grey_notNil()]; |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Tests reloading the current page via history.go(0). | 235 // Tests reloading the current page via history.go(0). |
| 236 - (void)testHistoryGoDeltaZero { | 236 - (void)testHistoryGoDeltaZero { |
| 237 web::test::SetUpFileBasedHttpServer(); | 237 web::test::SetUpFileBasedHttpServer(); |
| 238 | 238 |
| 239 // Load the history test page and ensure that its onload text is visible. | 239 // Load the history test page and ensure that its onload text is visible. |
| 240 const GURL windowHistoryURL = | 240 const GURL windowHistoryURL = |
| 241 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 241 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 242 [ChromeEarlGrey loadURL:windowHistoryURL]; | 242 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 243 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 243 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 244 assertWithMatcher:grey_notNil()]; | 244 assertWithMatcher:grey_notNil()]; |
| 245 | 245 |
| 246 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so | 246 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so |
| 247 // the subsequent check for |kOnLoadText| will only pass if a reload has | 247 // the subsequent check for |kOnLoadText| will only pass if a reload has |
| 248 // occurred. | 248 // occurred. |
| 249 [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID]; | 249 [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID]; |
| 250 | 250 |
| 251 // Verify that the onload text is reset. | 251 // Verify that the onload text is reset. |
| 252 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 252 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 253 assertWithMatcher:grey_notNil()]; | 253 assertWithMatcher:grey_notNil()]; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Tests that calling window.history.go() with an offset that is out of bounds | 256 // Tests that calling window.history.go() with an offset that is out of bounds |
| 257 // is a no-op. | 257 // is a no-op. |
| 258 - (void)testHistoryGoOutOfBounds { | 258 - (void)testHistoryGoOutOfBounds { |
| 259 web::test::SetUpFileBasedHttpServer(); | 259 web::test::SetUpFileBasedHttpServer(); |
| 260 | 260 |
| 261 // Load the history test page and ensure that its onload text is visible. | 261 // Load the history test page and ensure that its onload text is visible. |
| 262 const GURL windowHistoryURL = | 262 const GURL windowHistoryURL = |
| 263 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 263 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 264 [ChromeEarlGrey loadURL:windowHistoryURL]; | 264 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 265 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 265 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 266 assertWithMatcher:grey_notNil()]; | 266 assertWithMatcher:grey_notNil()]; |
| 267 | 267 |
| 268 // Tap on the window.history.go(2) button. This will clear all div text, so | 268 // Tap on the window.history.go(2) button. This will clear all div text, so |
| 269 // the subsequent check for |kNoOpText| will only pass if no navigations have | 269 // the subsequent check for |kNoOpText| will only pass if no navigations have |
| 270 // occurred. | 270 // occurred. |
| 271 [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID]; | 271 [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID]; |
| 272 [[EarlGrey selectElementWithMatcher:webViewContainingText(kNoOpText)] | 272 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)] |
| 273 assertWithMatcher:grey_notNil()]; | 273 assertWithMatcher:grey_notNil()]; |
| 274 | 274 |
| 275 // Tap on the window.history.go(-2) button. This will clear all div text, so | 275 // Tap on the window.history.go(-2) button. This will clear all div text, so |
| 276 // the subsequent check for |kNoOpText| will only pass if no navigations have | 276 // the subsequent check for |kNoOpText| will only pass if no navigations have |
| 277 // occurred. | 277 // occurred. |
| 278 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; | 278 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; |
| 279 [[EarlGrey selectElementWithMatcher:webViewContainingText(kNoOpText)] | 279 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)] |
| 280 assertWithMatcher:grey_notNil()]; | 280 assertWithMatcher:grey_notNil()]; |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Tests going back and forward via history.go(). | 283 // Tests going back and forward via history.go(). |
| 284 - (void)testHistoryGoDelta { | 284 - (void)testHistoryGoDelta { |
| 285 std::map<GURL, std::string> responses; | 285 std::map<GURL, std::string> responses; |
| 286 const GURL firstURL = web::test::HttpServer::MakeUrl("http://page1"); | 286 const GURL firstURL = web::test::HttpServer::MakeUrl("http://page1"); |
| 287 const GURL secondURL = web::test::HttpServer::MakeUrl("http://page2"); | 287 const GURL secondURL = web::test::HttpServer::MakeUrl("http://page2"); |
| 288 const GURL thirdURL = web::test::HttpServer::MakeUrl("http://page3"); | 288 const GURL thirdURL = web::test::HttpServer::MakeUrl("http://page3"); |
| 289 const GURL fourthURL = web::test::HttpServer::MakeUrl("http://page4"); | 289 const GURL fourthURL = web::test::HttpServer::MakeUrl("http://page4"); |
| 290 responses[firstURL] = | 290 responses[firstURL] = |
| 291 "page1 <input type='button' value='goForward' id='goForward' " | 291 "page1 <input type='button' value='goForward' id='goForward' " |
| 292 "onclick='window.history.go(2)' />"; | 292 "onclick='window.history.go(2)' />"; |
| 293 responses[secondURL] = "page2"; | 293 responses[secondURL] = "page2"; |
| 294 responses[thirdURL] = "page3"; | 294 responses[thirdURL] = "page3"; |
| 295 responses[fourthURL] = | 295 responses[fourthURL] = |
| 296 "page4 <input type='button' value='goBack' id='goBack' " | 296 "page4 <input type='button' value='goBack' id='goBack' " |
| 297 "onclick='window.history.go(-3)' />"; | 297 "onclick='window.history.go(-3)' />"; |
| 298 web::test::SetUpSimpleHttpServer(responses); | 298 web::test::SetUpSimpleHttpServer(responses); |
| 299 | 299 |
| 300 // Load 4 pages. | 300 // Load 4 pages. |
| 301 [ChromeEarlGrey loadURL:firstURL]; | 301 [ChromeEarlGrey loadURL:firstURL]; |
| 302 [ChromeEarlGrey loadURL:secondURL]; | 302 [ChromeEarlGrey loadURL:secondURL]; |
| 303 [ChromeEarlGrey loadURL:thirdURL]; | 303 [ChromeEarlGrey loadURL:thirdURL]; |
| 304 [ChromeEarlGrey loadURL:fourthURL]; | 304 [ChromeEarlGrey loadURL:fourthURL]; |
| 305 [[EarlGrey selectElementWithMatcher:webViewContainingText("page4")] | 305 [[EarlGrey selectElementWithMatcher:WebViewContainingText("page4")] |
| 306 assertWithMatcher:grey_notNil()]; | 306 assertWithMatcher:grey_notNil()]; |
| 307 | 307 |
| 308 // Tap button to go back 3 pages. | 308 // Tap button to go back 3 pages. |
| 309 TapWebViewElementWithId("goBack"); | 309 TapWebViewElementWithId("goBack"); |
| 310 [[EarlGrey selectElementWithMatcher:webViewContainingText("page1")] | 310 [[EarlGrey selectElementWithMatcher:WebViewContainingText("page1")] |
| 311 assertWithMatcher:grey_notNil()]; | 311 assertWithMatcher:grey_notNil()]; |
| 312 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 312 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 313 firstURL.GetContent())] | 313 firstURL.GetContent())] |
| 314 assertWithMatcher:grey_notNil()]; | 314 assertWithMatcher:grey_notNil()]; |
| 315 | 315 |
| 316 // Tap button to go forward 2 pages. | 316 // Tap button to go forward 2 pages. |
| 317 TapWebViewElementWithId("goForward"); | 317 TapWebViewElementWithId("goForward"); |
| 318 [[EarlGrey selectElementWithMatcher:webViewContainingText("page3")] | 318 [[EarlGrey selectElementWithMatcher:WebViewContainingText("page3")] |
| 319 assertWithMatcher:grey_notNil()]; | 319 assertWithMatcher:grey_notNil()]; |
| 320 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 320 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 321 thirdURL.GetContent())] | 321 thirdURL.GetContent())] |
| 322 assertWithMatcher:grey_notNil()]; | 322 assertWithMatcher:grey_notNil()]; |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Tests that calls to window.history.go() that span multiple documents causes | 325 // Tests that calls to window.history.go() that span multiple documents causes |
| 326 // a load to occur. | 326 // a load to occur. |
| 327 - (void)testHistoryCrossDocumentLoad { | 327 - (void)testHistoryCrossDocumentLoad { |
| 328 web::test::SetUpFileBasedHttpServer(); | 328 web::test::SetUpFileBasedHttpServer(); |
| 329 | 329 |
| 330 // Load the history test page and ensure that its onload text is visible. | 330 // Load the history test page and ensure that its onload text is visible. |
| 331 const GURL windowHistoryURL = | 331 const GURL windowHistoryURL = |
| 332 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 332 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 333 [ChromeEarlGrey loadURL:windowHistoryURL]; | 333 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 334 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 334 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 335 assertWithMatcher:grey_notNil()]; | 335 assertWithMatcher:grey_notNil()]; |
| 336 | 336 |
| 337 const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); | 337 const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); |
| 338 [ChromeEarlGrey loadURL:sampleURL]; | 338 [ChromeEarlGrey loadURL:sampleURL]; |
| 339 | 339 |
| 340 [ChromeEarlGrey loadURL:windowHistoryURL]; | 340 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 341 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 341 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 342 assertWithMatcher:grey_notNil()]; | 342 assertWithMatcher:grey_notNil()]; |
| 343 | 343 |
| 344 // Tap the window.history.go(-2) button. This will clear the current page's | 344 // Tap the window.history.go(-2) button. This will clear the current page's |
| 345 // |kOnLoadText|, so the subsequent check will only pass if another load | 345 // |kOnLoadText|, so the subsequent check will only pass if another load |
| 346 // occurs. | 346 // occurs. |
| 347 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; | 347 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; |
| 348 [[EarlGrey selectElementWithMatcher:webViewContainingText(kOnLoadText)] | 348 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] |
| 349 assertWithMatcher:grey_notNil()]; | 349 assertWithMatcher:grey_notNil()]; |
| 350 } | 350 } |
| 351 | 351 |
| 352 #pragma mark window.history.[back/forward] operations | 352 #pragma mark window.history.[back/forward] operations |
| 353 | 353 |
| 354 // Tests going back via history.back() then forward via forward button. | 354 // Tests going back via history.back() then forward via forward button. |
| 355 - (void)testHistoryBackNavigation { | 355 - (void)testHistoryBackNavigation { |
| 356 SetupBackAndForwardResponseProvider(); | 356 SetupBackAndForwardResponseProvider(); |
| 357 | 357 |
| 358 // Navigate to a URL. | 358 // Navigate to a URL. |
| 359 const GURL firstURL = web::test::HttpServer::MakeUrl(kTestURL); | 359 const GURL firstURL = web::test::HttpServer::MakeUrl(kTestURL); |
| 360 [ChromeEarlGrey loadURL:firstURL]; | 360 [ChromeEarlGrey loadURL:firstURL]; |
| 361 | 361 |
| 362 // Navigate to an HTML page with a back button. | 362 // Navigate to an HTML page with a back button. |
| 363 const GURL secondURL = web::test::HttpServer::MakeUrl(kBackURL); | 363 const GURL secondURL = web::test::HttpServer::MakeUrl(kBackURL); |
| 364 [ChromeEarlGrey loadURL:secondURL]; | 364 [ChromeEarlGrey loadURL:secondURL]; |
| 365 | 365 |
| 366 // Tap the back button in the HTML and verify the first URL is loaded. | 366 // Tap the back button in the HTML and verify the first URL is loaded. |
| 367 TapWebViewElementWithId(kBackHTMLButtonLabel); | 367 TapWebViewElementWithId(kBackHTMLButtonLabel); |
| 368 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 368 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 369 firstURL.GetContent())] | 369 firstURL.GetContent())] |
| 370 assertWithMatcher:grey_notNil()]; | 370 assertWithMatcher:grey_notNil()]; |
| 371 | 371 |
| 372 // Tap the forward button in the toolbar and verify the second URL is loaded. | 372 // Tap the forward button in the toolbar and verify the second URL is loaded. |
| 373 [[EarlGrey selectElementWithMatcher:forwardButton()] | 373 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 374 performAction:grey_tap()]; | 374 performAction:grey_tap()]; |
| 375 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 375 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 376 secondURL.GetContent())] | 376 secondURL.GetContent())] |
| 377 assertWithMatcher:grey_notNil()]; | 377 assertWithMatcher:grey_notNil()]; |
| 378 } | 378 } |
| 379 | 379 |
| 380 // Tests going back via back button then forward via history.forward(). | 380 // Tests going back via back button then forward via history.forward(). |
| 381 - (void)testHistoryForwardNavigation { | 381 - (void)testHistoryForwardNavigation { |
| 382 SetupBackAndForwardResponseProvider(); | 382 SetupBackAndForwardResponseProvider(); |
| 383 | 383 |
| 384 // Navigate to an HTML page with a forward button. | 384 // Navigate to an HTML page with a forward button. |
| 385 const GURL firstURL = web::test::HttpServer::MakeUrl(kForwardURL); | 385 const GURL firstURL = web::test::HttpServer::MakeUrl(kForwardURL); |
| 386 [ChromeEarlGrey loadURL:firstURL]; | 386 [ChromeEarlGrey loadURL:firstURL]; |
| 387 | 387 |
| 388 // Navigate to some other page. | 388 // Navigate to some other page. |
| 389 const GURL secondURL = web::test::HttpServer::MakeUrl(kTestURL); | 389 const GURL secondURL = web::test::HttpServer::MakeUrl(kTestURL); |
| 390 [ChromeEarlGrey loadURL:secondURL]; | 390 [ChromeEarlGrey loadURL:secondURL]; |
| 391 | 391 |
| 392 // Tap the back button in the toolbar and verify the page with forward button | 392 // Tap the back button in the toolbar and verify the page with forward button |
| 393 // is loaded. | 393 // is loaded. |
| 394 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 394 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 395 [[EarlGrey | 395 [[EarlGrey |
| 396 selectElementWithMatcher:webViewContainingText(kForwardHTMLSentinel)] | 396 selectElementWithMatcher:WebViewContainingText(kForwardHTMLSentinel)] |
| 397 assertWithMatcher:grey_notNil()]; | 397 assertWithMatcher:grey_notNil()]; |
| 398 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 398 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 399 firstURL.GetContent())] | 399 firstURL.GetContent())] |
| 400 assertWithMatcher:grey_notNil()]; | 400 assertWithMatcher:grey_notNil()]; |
| 401 | 401 |
| 402 // Tap the forward button in the HTML and verify the second URL is loaded. | 402 // Tap the forward button in the HTML and verify the second URL is loaded. |
| 403 TapWebViewElementWithId(kForwardHTMLButtonLabel); | 403 TapWebViewElementWithId(kForwardHTMLButtonLabel); |
| 404 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTestPageSentinel)] | 404 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPageSentinel)] |
| 405 assertWithMatcher:grey_notNil()]; | 405 assertWithMatcher:grey_notNil()]; |
| 406 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 406 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 407 secondURL.GetContent())] | 407 secondURL.GetContent())] |
| 408 assertWithMatcher:grey_notNil()]; | 408 assertWithMatcher:grey_notNil()]; |
| 409 | 409 |
| 410 // Verify that the forward button is not enabled. | 410 // Verify that the forward button is not enabled. |
| 411 // TODO(crbug.com/638674): Evaluate if size class determination can move to | 411 // TODO(crbug.com/638674): Evaluate if size class determination can move to |
| 412 // shared code. | 412 // shared code. |
| 413 if (UIApplication.sharedApplication.keyWindow.traitCollection | 413 if (UIApplication.sharedApplication.keyWindow.traitCollection |
| 414 .horizontalSizeClass == UIUserInterfaceSizeClassCompact) { | 414 .horizontalSizeClass == UIUserInterfaceSizeClassCompact) { |
| 415 // In horizontally compact environments, the forward button is not visible. | 415 // In horizontally compact environments, the forward button is not visible. |
| 416 [[EarlGrey selectElementWithMatcher:forwardButton()] | 416 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 417 assertWithMatcher:grey_nil()]; | 417 assertWithMatcher:grey_nil()]; |
| 418 } else { | 418 } else { |
| 419 // In horizontally regular environments, the forward button is visible and | 419 // In horizontally regular environments, the forward button is visible and |
| 420 // disabled. | 420 // disabled. |
| 421 id<GREYMatcher> disabledForwardButton = grey_allOf( | 421 id<GREYMatcher> disabledForwardButton = grey_allOf( |
| 422 forwardButton(), | 422 ForwardButton(), |
| 423 grey_accessibilityTrait(UIAccessibilityTraitNotEnabled), nil); | 423 grey_accessibilityTrait(UIAccessibilityTraitNotEnabled), nil); |
| 424 [[EarlGrey selectElementWithMatcher:disabledForwardButton] | 424 [[EarlGrey selectElementWithMatcher:disabledForwardButton] |
| 425 assertWithMatcher:grey_notNil()]; | 425 assertWithMatcher:grey_notNil()]; |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Tests navigating forward via window.history.forward() to an error page. | 429 // Tests navigating forward via window.history.forward() to an error page. |
| 430 - (void)testHistoryForwardToErrorPage { | 430 - (void)testHistoryForwardToErrorPage { |
| 431 SetupBackAndForwardResponseProvider(); | 431 SetupBackAndForwardResponseProvider(); |
| 432 | 432 |
| 433 // Go to page 1 with a button which calls window.history.forward(). | 433 // Go to page 1 with a button which calls window.history.forward(). |
| 434 const GURL forwardURL = web::test::HttpServer::MakeUrl(kForwardURL); | 434 const GURL forwardURL = web::test::HttpServer::MakeUrl(kForwardURL); |
| 435 [ChromeEarlGrey loadURL:forwardURL]; | 435 [ChromeEarlGrey loadURL:forwardURL]; |
| 436 | 436 |
| 437 // Go to page 2: 'www.badurljkljkljklfloofy.com'. This page should display a | 437 // Go to page 2: 'www.badurljkljkljklfloofy.com'. This page should display a |
| 438 // page not available error. | 438 // page not available error. |
| 439 const GURL badURL("http://www.badurljkljkljklfloofy.com"); | 439 const GURL badURL("http://www.badurljkljkljklfloofy.com"); |
| 440 [ChromeEarlGrey loadURL:badURL]; | 440 [ChromeEarlGrey loadURL:badURL]; |
| 441 [[EarlGrey selectElementWithMatcher:errorPage()] | 441 [[EarlGrey selectElementWithMatcher:ErrorPage()] |
| 442 assertWithMatcher:grey_notNil()]; | 442 assertWithMatcher:grey_notNil()]; |
| 443 | 443 |
| 444 // Go back to page 1 by clicking back button. | 444 // Go back to page 1 by clicking back button. |
| 445 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 445 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 446 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 446 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 447 forwardURL.GetContent())] | 447 forwardURL.GetContent())] |
| 448 assertWithMatcher:grey_notNil()]; | 448 assertWithMatcher:grey_notNil()]; |
| 449 | 449 |
| 450 // Go forward to page 2 by calling window.history.forward() and assert that | 450 // Go forward to page 2 by calling window.history.forward() and assert that |
| 451 // the error page is shown. | 451 // the error page is shown. |
| 452 TapWebViewElementWithId(kForwardHTMLButtonLabel); | 452 TapWebViewElementWithId(kForwardHTMLButtonLabel); |
| 453 [[EarlGrey selectElementWithMatcher:errorPage()] | 453 [[EarlGrey selectElementWithMatcher:ErrorPage()] |
| 454 assertWithMatcher:grey_notNil()]; | 454 assertWithMatcher:grey_notNil()]; |
| 455 } | 455 } |
| 456 | 456 |
| 457 #pragma mark window.location.hash operations | 457 #pragma mark window.location.hash operations |
| 458 | 458 |
| 459 // Loads a URL and modifies window.location.hash, then goes back and forward | 459 // Loads a URL and modifies window.location.hash, then goes back and forward |
| 460 // and verifies the URLs and that hashchange event is fired. | 460 // and verifies the URLs and that hashchange event is fired. |
| 461 - (void)testWindowLocationChangeHash { | 461 - (void)testWindowLocationChangeHash { |
| 462 std::map<GURL, std::string> responses; | 462 std::map<GURL, std::string> responses; |
| 463 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); | 463 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); |
| 464 const GURL hashChangedWithHistoryURL = | 464 const GURL hashChangedWithHistoryURL = |
| 465 web::test::HttpServer::MakeUrl(kHashChangedWithHistoryURL); | 465 web::test::HttpServer::MakeUrl(kHashChangedWithHistoryURL); |
| 466 responses[page1URL] = kHashChangedHTML; | 466 responses[page1URL] = kHashChangedHTML; |
| 467 responses[hashChangedWithHistoryURL] = kHashChangedHTML; | 467 responses[hashChangedWithHistoryURL] = kHashChangedHTML; |
| 468 web::test::SetUpSimpleHttpServer(responses); | 468 web::test::SetUpSimpleHttpServer(responses); |
| 469 [ChromeEarlGrey loadURL:page1URL]; | 469 [ChromeEarlGrey loadURL:page1URL]; |
| 470 | 470 |
| 471 // Click link to update location.hash and go to new URL (same page). | 471 // Click link to update location.hash and go to new URL (same page). |
| 472 chrome_test_util::TapWebViewElementWithId(kHashChangeWithHistoryLabel); | 472 chrome_test_util::TapWebViewElementWithId(kHashChangeWithHistoryLabel); |
| 473 | 473 |
| 474 // Navigate back to original URL. This should fire a hashchange event. | 474 // Navigate back to original URL. This should fire a hashchange event. |
| 475 std::string backHashChangeContent = "backHashChange"; | 475 std::string backHashChangeContent = "backHashChange"; |
| 476 [self addHashChangeListenerWithContent:backHashChangeContent]; | 476 [self addHashChangeListenerWithContent:backHashChangeContent]; |
| 477 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 477 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 478 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 478 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 479 page1URL.GetContent())] | 479 page1URL.GetContent())] |
| 480 assertWithMatcher:grey_notNil()]; | 480 assertWithMatcher:grey_notNil()]; |
| 481 [[EarlGrey | 481 [[EarlGrey |
| 482 selectElementWithMatcher:webViewContainingText(backHashChangeContent)] | 482 selectElementWithMatcher:WebViewContainingText(backHashChangeContent)] |
| 483 assertWithMatcher:grey_notNil()]; | 483 assertWithMatcher:grey_notNil()]; |
| 484 | 484 |
| 485 // Navigate forward to the new URL. This should fire a hashchange event. | 485 // Navigate forward to the new URL. This should fire a hashchange event. |
| 486 std::string forwardHashChangeContent = "forwardHashChange"; | 486 std::string forwardHashChangeContent = "forwardHashChange"; |
| 487 [self addHashChangeListenerWithContent:forwardHashChangeContent]; | 487 [self addHashChangeListenerWithContent:forwardHashChangeContent]; |
| 488 [[EarlGrey selectElementWithMatcher:forwardButton()] | 488 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 489 performAction:grey_tap()]; | 489 performAction:grey_tap()]; |
| 490 [[EarlGrey | 490 [[EarlGrey |
| 491 selectElementWithMatcher:chrome_test_util::omniboxText( | 491 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 492 hashChangedWithHistoryURL.GetContent())] | 492 hashChangedWithHistoryURL.GetContent())] |
| 493 assertWithMatcher:grey_notNil()]; | 493 assertWithMatcher:grey_notNil()]; |
| 494 [[EarlGrey | 494 [[EarlGrey |
| 495 selectElementWithMatcher:webViewContainingText(forwardHashChangeContent)] | 495 selectElementWithMatcher:WebViewContainingText(forwardHashChangeContent)] |
| 496 assertWithMatcher:grey_notNil()]; | 496 assertWithMatcher:grey_notNil()]; |
| 497 | 497 |
| 498 // Load a hash URL directly. This shouldn't fire a hashchange event. | 498 // Load a hash URL directly. This shouldn't fire a hashchange event. |
| 499 std::string hashChangeContent = "FAIL_loadUrlHashChange"; | 499 std::string hashChangeContent = "FAIL_loadUrlHashChange"; |
| 500 [self addHashChangeListenerWithContent:hashChangeContent]; | 500 [self addHashChangeListenerWithContent:hashChangeContent]; |
| 501 [ChromeEarlGrey loadURL:hashChangedWithHistoryURL]; | 501 [ChromeEarlGrey loadURL:hashChangedWithHistoryURL]; |
| 502 [[EarlGrey selectElementWithMatcher:webViewContainingText(hashChangeContent)] | 502 [[EarlGrey selectElementWithMatcher:WebViewContainingText(hashChangeContent)] |
| 503 assertWithMatcher:grey_nil()]; | 503 assertWithMatcher:grey_nil()]; |
| 504 } | 504 } |
| 505 | 505 |
| 506 // Loads a URL and replaces its location, then updates its location.hash | 506 // Loads a URL and replaces its location, then updates its location.hash |
| 507 // and verifies that going back returns to the replaced entry. | 507 // and verifies that going back returns to the replaced entry. |
| 508 - (void)testWindowLocationReplaceAndChangeHash { | 508 - (void)testWindowLocationReplaceAndChangeHash { |
| 509 std::map<GURL, std::string> responses; | 509 std::map<GURL, std::string> responses; |
| 510 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); | 510 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); |
| 511 const GURL hashChangedWithoutHistoryURL = | 511 const GURL hashChangedWithoutHistoryURL = |
| 512 web::test::HttpServer::MakeUrl(kHashChangedWithoutHistoryURL); | 512 web::test::HttpServer::MakeUrl(kHashChangedWithoutHistoryURL); |
| 513 const GURL hashChangedWithHistoryURL = | 513 const GURL hashChangedWithHistoryURL = |
| 514 web::test::HttpServer::MakeUrl(kHashChangedWithHistoryURL); | 514 web::test::HttpServer::MakeUrl(kHashChangedWithHistoryURL); |
| 515 responses[page1URL] = kHashChangedHTML; | 515 responses[page1URL] = kHashChangedHTML; |
| 516 web::test::SetUpSimpleHttpServer(responses); | 516 web::test::SetUpSimpleHttpServer(responses); |
| 517 [ChromeEarlGrey loadURL:page1URL]; | 517 [ChromeEarlGrey loadURL:page1URL]; |
| 518 | 518 |
| 519 // Tap link to replace the location value. | 519 // Tap link to replace the location value. |
| 520 TapWebViewElementWithId(kHashChangeWithoutHistoryLabel); | 520 TapWebViewElementWithId(kHashChangeWithoutHistoryLabel); |
| 521 [[EarlGrey | 521 [[EarlGrey |
| 522 selectElementWithMatcher:chrome_test_util::omniboxText( | 522 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 523 hashChangedWithoutHistoryURL.GetContent())] | 523 hashChangedWithoutHistoryURL.GetContent())] |
| 524 assertWithMatcher:grey_notNil()]; | 524 assertWithMatcher:grey_notNil()]; |
| 525 | 525 |
| 526 // Tap link to update the location.hash with a new value. | 526 // Tap link to update the location.hash with a new value. |
| 527 TapWebViewElementWithId(kHashChangeWithHistoryLabel); | 527 TapWebViewElementWithId(kHashChangeWithHistoryLabel); |
| 528 [[EarlGrey | 528 [[EarlGrey |
| 529 selectElementWithMatcher:chrome_test_util::omniboxText( | 529 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 530 hashChangedWithHistoryURL.GetContent())] | 530 hashChangedWithHistoryURL.GetContent())] |
| 531 assertWithMatcher:grey_notNil()]; | 531 assertWithMatcher:grey_notNil()]; |
| 532 | 532 |
| 533 // Navigate back and verify that the URL that replaced window.location | 533 // Navigate back and verify that the URL that replaced window.location |
| 534 // has been reached. | 534 // has been reached. |
| 535 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 535 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 536 [[EarlGrey | 536 [[EarlGrey |
| 537 selectElementWithMatcher:chrome_test_util::omniboxText( | 537 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 538 hashChangedWithoutHistoryURL.GetContent())] | 538 hashChangedWithoutHistoryURL.GetContent())] |
| 539 assertWithMatcher:grey_notNil()]; | 539 assertWithMatcher:grey_notNil()]; |
| 540 } | 540 } |
| 541 | 541 |
| 542 // Loads a URL and modifies window.location.hash twice, verifying that there is | 542 // Loads a URL and modifies window.location.hash twice, verifying that there is |
| 543 // only one entry in the history by navigating back. | 543 // only one entry in the history by navigating back. |
| 544 - (void)testWindowLocationChangeToSameHash { | 544 - (void)testWindowLocationChangeToSameHash { |
| 545 std::map<GURL, std::string> responses; | 545 std::map<GURL, std::string> responses; |
| 546 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); | 546 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); |
| 547 const GURL hashChangedWithHistoryURL = | 547 const GURL hashChangedWithHistoryURL = |
| 548 web::test::HttpServer::MakeUrl(kHashChangedWithHistoryURL); | 548 web::test::HttpServer::MakeUrl(kHashChangedWithHistoryURL); |
| 549 responses[page1URL] = kHashChangedHTML; | 549 responses[page1URL] = kHashChangedHTML; |
| 550 web::test::SetUpSimpleHttpServer(responses); | 550 web::test::SetUpSimpleHttpServer(responses); |
| 551 [ChromeEarlGrey loadURL:page1URL]; | 551 [ChromeEarlGrey loadURL:page1URL]; |
| 552 | 552 |
| 553 // Tap link to update location.hash with a new value. | 553 // Tap link to update location.hash with a new value. |
| 554 TapWebViewElementWithId(kHashChangeWithHistoryLabel); | 554 TapWebViewElementWithId(kHashChangeWithHistoryLabel); |
| 555 [[EarlGrey | 555 [[EarlGrey |
| 556 selectElementWithMatcher:chrome_test_util::omniboxText( | 556 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 557 hashChangedWithHistoryURL.GetContent())] | 557 hashChangedWithHistoryURL.GetContent())] |
| 558 assertWithMatcher:grey_notNil()]; | 558 assertWithMatcher:grey_notNil()]; |
| 559 | 559 |
| 560 // Tap link to update location.hash with the same value. | 560 // Tap link to update location.hash with the same value. |
| 561 TapWebViewElementWithId(kHashChangeWithHistoryLabel); | 561 TapWebViewElementWithId(kHashChangeWithHistoryLabel); |
| 562 | 562 |
| 563 // Tap back once to return to original URL. | 563 // Tap back once to return to original URL. |
| 564 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 564 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 565 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 565 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 566 page1URL.GetContent())] | 566 page1URL.GetContent())] |
| 567 assertWithMatcher:grey_notNil()]; | 567 assertWithMatcher:grey_notNil()]; |
| 568 | 568 |
| 569 // Navigate forward and verify the URL. | 569 // Navigate forward and verify the URL. |
| 570 [[EarlGrey selectElementWithMatcher:forwardButton()] | 570 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 571 performAction:grey_tap()]; | 571 performAction:grey_tap()]; |
| 572 [[EarlGrey | 572 [[EarlGrey |
| 573 selectElementWithMatcher:chrome_test_util::omniboxText( | 573 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 574 hashChangedWithHistoryURL.GetContent())] | 574 hashChangedWithHistoryURL.GetContent())] |
| 575 assertWithMatcher:grey_notNil()]; | 575 assertWithMatcher:grey_notNil()]; |
| 576 } | 576 } |
| 577 | 577 |
| 578 #pragma mark Redirect operations | 578 #pragma mark Redirect operations |
| 579 | 579 |
| 580 // Navigates to a page that immediately redirects to another page via JavaScript | 580 // Navigates to a page that immediately redirects to another page via JavaScript |
| 581 // then verifies the browsing history. | 581 // then verifies the browsing history. |
| 582 - (void)testJavaScriptRedirect { | 582 - (void)testJavaScriptRedirect { |
| 583 std::map<GURL, std::string> responses; | 583 std::map<GURL, std::string> responses; |
| 584 // A starting page. | 584 // A starting page. |
| 585 const GURL initialURL = web::test::HttpServer::MakeUrl("http://initialURL"); | 585 const GURL initialURL = web::test::HttpServer::MakeUrl("http://initialURL"); |
| 586 // A page that redirects immediately via the window.open JavaScript method. | 586 // A page that redirects immediately via the window.open JavaScript method. |
| 587 const GURL originURL = web::test::HttpServer::MakeUrl( | 587 const GURL originURL = web::test::HttpServer::MakeUrl( |
| 588 "http://scenarioJavaScriptRedirect_origin"); | 588 "http://scenarioJavaScriptRedirect_origin"); |
| 589 const GURL destinationURL = | 589 const GURL destinationURL = |
| 590 web::test::HttpServer::MakeUrl("http://destination"); | 590 web::test::HttpServer::MakeUrl("http://destination"); |
| 591 responses[initialURL] = "<html><body>Initial page</body></html>"; | 591 responses[initialURL] = "<html><body>Initial page</body></html>"; |
| 592 responses[originURL] = | 592 responses[originURL] = |
| 593 "<script>window.open('" + destinationURL.spec() + "', '_self');</script>"; | 593 "<script>window.open('" + destinationURL.spec() + "', '_self');</script>"; |
| 594 responses[destinationURL] = "scenarioJavaScriptRedirect destination"; | 594 responses[destinationURL] = "scenarioJavaScriptRedirect destination"; |
| 595 | 595 |
| 596 web::test::SetUpSimpleHttpServer(responses); | 596 web::test::SetUpSimpleHttpServer(responses); |
| 597 [ChromeEarlGrey loadURL:initialURL]; | 597 [ChromeEarlGrey loadURL:initialURL]; |
| 598 [ChromeEarlGrey loadURL:originURL]; | 598 [ChromeEarlGrey loadURL:originURL]; |
| 599 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 599 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 600 destinationURL.GetContent())] | 600 destinationURL.GetContent())] |
| 601 assertWithMatcher:grey_notNil()]; | 601 assertWithMatcher:grey_notNil()]; |
| 602 | 602 |
| 603 // Navigating back takes the user to the new tab page. | 603 // Navigating back takes the user to the new tab page. |
| 604 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 604 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 605 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 605 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 606 initialURL.GetContent())] | 606 initialURL.GetContent())] |
| 607 assertWithMatcher:grey_notNil()]; | 607 assertWithMatcher:grey_notNil()]; |
| 608 | 608 |
| 609 // Navigating forward take the user to destination page. | 609 // Navigating forward take the user to destination page. |
| 610 [[EarlGrey selectElementWithMatcher:forwardButton()] | 610 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 611 performAction:grey_tap()]; | 611 performAction:grey_tap()]; |
| 612 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 612 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 613 destinationURL.GetContent())] | 613 destinationURL.GetContent())] |
| 614 assertWithMatcher:grey_notNil()]; | 614 assertWithMatcher:grey_notNil()]; |
| 615 } | 615 } |
| 616 | 616 |
| 617 // Test to load a page that contains a redirect window, then does multiple back | 617 // Test to load a page that contains a redirect window, then does multiple back |
| 618 // and forth navigations. | 618 // and forth navigations. |
| 619 - (void)testRedirectWindow { | 619 - (void)testRedirectWindow { |
| 620 std::unique_ptr<web::DataResponseProvider> provider( | 620 std::unique_ptr<web::DataResponseProvider> provider( |
| 621 new RedirectResponseProvider()); | 621 new RedirectResponseProvider()); |
| 622 web::test::SetUpHttpServer(std::move(provider)); | 622 web::test::SetUpHttpServer(std::move(provider)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 658 |
| 659 - (void)verifyBackAndForwardAfterRedirect:(std::string)redirectLabel { | 659 - (void)verifyBackAndForwardAfterRedirect:(std::string)redirectLabel { |
| 660 const GURL indexURL(web::test::HttpServer::MakeUrl(kRedirectIndexURL)); | 660 const GURL indexURL(web::test::HttpServer::MakeUrl(kRedirectIndexURL)); |
| 661 const GURL destinationURL(web::test::HttpServer::MakeUrl(kDestinationURL)); | 661 const GURL destinationURL(web::test::HttpServer::MakeUrl(kDestinationURL)); |
| 662 const GURL lastURL(web::test::HttpServer::MakeUrl(kLastURL)); | 662 const GURL lastURL(web::test::HttpServer::MakeUrl(kLastURL)); |
| 663 | 663 |
| 664 // Load index, tap on redirect link, and assert that the page is redirected | 664 // Load index, tap on redirect link, and assert that the page is redirected |
| 665 // to the proper destination. | 665 // to the proper destination. |
| 666 [ChromeEarlGrey loadURL:indexURL]; | 666 [ChromeEarlGrey loadURL:indexURL]; |
| 667 TapWebViewElementWithId(redirectLabel); | 667 TapWebViewElementWithId(redirectLabel); |
| 668 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 668 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 669 destinationURL.GetContent())] | 669 destinationURL.GetContent())] |
| 670 assertWithMatcher:grey_notNil()]; | 670 assertWithMatcher:grey_notNil()]; |
| 671 | 671 |
| 672 // Navigate to a new URL, navigate back and assert that the resulting page is | 672 // Navigate to a new URL, navigate back and assert that the resulting page is |
| 673 // the proper destination. | 673 // the proper destination. |
| 674 [ChromeEarlGrey loadURL:lastURL]; | 674 [ChromeEarlGrey loadURL:lastURL]; |
| 675 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 675 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 676 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 676 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 677 destinationURL.GetContent())] | 677 destinationURL.GetContent())] |
| 678 assertWithMatcher:grey_notNil()]; | 678 assertWithMatcher:grey_notNil()]; |
| 679 | 679 |
| 680 // Navigate back and assert that the resulting page is the initial index. | 680 // Navigate back and assert that the resulting page is the initial index. |
| 681 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()]; | 681 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 682 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 682 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 683 indexURL.GetContent())] | 683 indexURL.GetContent())] |
| 684 assertWithMatcher:grey_notNil()]; | 684 assertWithMatcher:grey_notNil()]; |
| 685 | 685 |
| 686 // Navigate forward and assert the the resulting page is the proper | 686 // Navigate forward and assert the the resulting page is the proper |
| 687 // destination. | 687 // destination. |
| 688 [[EarlGrey selectElementWithMatcher:forwardButton()] | 688 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 689 performAction:grey_tap()]; | 689 performAction:grey_tap()]; |
| 690 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( | 690 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 691 destinationURL.GetContent())] | 691 destinationURL.GetContent())] |
| 692 assertWithMatcher:grey_notNil()]; | 692 assertWithMatcher:grey_notNil()]; |
| 693 } | 693 } |
| 694 | 694 |
| 695 @end | 695 @end |
| OLD | NEW |