| 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 "base/strings/sys_string_conversions.h" |
| 8 #include "components/strings/grit/components_strings.h" | 9 #include "components/strings/grit/components_strings.h" |
| 9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 10 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 11 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 12 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 13 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 13 #import "ios/web/public/test/http_server.h" | 14 #import "ios/web/public/test/http_server.h" |
| 14 #include "ios/web/public/test/http_server_util.h" | 15 #include "ios/web/public/test/http_server_util.h" |
| 15 #include "ios/web/public/test/response_providers/data_response_provider.h" | 16 #include "ios/web/public/test/response_providers/data_response_provider.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 | 18 |
| 18 using chrome_test_util::BackButton; | 19 using chrome_test_util::BackButton; |
| 19 using chrome_test_util::ForwardButton; | 20 using chrome_test_util::ForwardButton; |
| 20 using chrome_test_util::TapWebViewElementWithId; | 21 using chrome_test_util::TapWebViewElementWithId; |
| 21 using chrome_test_util::WebViewContainingText; | |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // URL for the test window.history.go() test file. The page at this URL | 25 // URL for the test window.history.go() test file. The page at this URL |
| 26 // contains several buttons that trigger window.history commands. Additionally | 26 // contains several buttons that trigger window.history commands. Additionally |
| 27 // the page contains several divs used to display the state of the page: | 27 // the page contains several divs used to display the state of the page: |
| 28 // - A div that is populated with |kOnLoadText| when the onload event fires. | 28 // - A div that is populated with |kOnLoadText| when the onload event fires. |
| 29 // - A div that is populated with |kNoOpText| 1s after a button is tapped. | 29 // - A div that is populated with |kNoOpText| 1s after a button is tapped. |
| 30 // - A div that is populated with |kPopStateReceivedText| when a popstate event | 30 // - A div that is populated with |kPopStateReceivedText| when a popstate event |
| 31 // is received by the page. | 31 // is received by the page. |
| 32 // - A div that is populated with the state object (if it's a string) upon the | 32 // - A div that is populated with the state object (if it's a string) upon the |
| 33 // receipt of a popstate event. | 33 // receipt of a popstate event. |
| 34 // - A div that is populated with |kHashChangeReceivedText| when a hashchange | 34 // - A div that is populated with |kHashChangeReceivedText| when a hashchange |
| 35 // event is received. | 35 // event is received. |
| 36 // When a button on the page is tapped, all pre-existing div text is cleared, | 36 // When a button on the page is tapped, all pre-existing div text is cleared, |
| 37 // so matching against this webview text after a button is tapped ensures that | 37 // so matching against this webview text after a button is tapped ensures that |
| 38 // the state is set in response to the most recently executed script. | 38 // the state is set in response to the most recently executed script. |
| 39 const char kWindowHistoryGoTestURL[] = | 39 const char kWindowHistoryGoTestURL[] = |
| 40 "http://ios/testing/data/http_server_files/history_go.html"; | 40 "http://ios/testing/data/http_server_files/history_go.html"; |
| 41 | 41 |
| 42 // URL of a sample file-based page. | 42 // URL of a sample file-based page. |
| 43 const char kSampleFileBasedURL[] = | 43 const char kSampleFileBasedURL[] = |
| 44 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; | 44 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; |
| 45 | 45 |
| 46 // Strings used by history_go.html. | 46 // Strings used by history_go.html. |
| 47 const char kOnLoadText[] = "OnLoadText"; | 47 NSString* const kOnLoadText = @"OnLoadText"; |
| 48 const char kNoOpText[] = "NoOpText"; | 48 NSString* const kNoOpText = @"NoOpText"; |
| 49 | 49 |
| 50 // Button ids for history_go.html. | 50 // Button ids for history_go.html. |
| 51 NSString* const kGoNoParameterID = @"go-no-parameter"; | 51 NSString* const kGoNoParameterID = @"go-no-parameter"; |
| 52 NSString* const kGoZeroID = @"go-zero"; | 52 NSString* const kGoZeroID = @"go-zero"; |
| 53 NSString* const kGoTwoID = @"go-2"; | 53 NSString* const kGoTwoID = @"go-2"; |
| 54 NSString* const kGoBackTwoID = @"go-back-2"; | 54 NSString* const kGoBackTwoID = @"go-back-2"; |
| 55 | 55 |
| 56 // URLs and labels for tests that navigate back and forward. | 56 // URLs and labels for tests that navigate back and forward. |
| 57 const char kBackHTMLButtonLabel[] = "BackHTMLButton"; | 57 const char kBackHTMLButtonLabel[] = "BackHTMLButton"; |
| 58 const char kForwardHTMLButtonLabel[] = "ForwardHTMLButton"; | 58 const char kForwardHTMLButtonLabel[] = "ForwardHTMLButton"; |
| 59 const char kForwardHTMLSentinel[] = "Forward page loaded"; | |
| 60 const char kTestPageSentinel[] = "Test Page"; | |
| 61 const char kBackURL[] = "http://back"; | 59 const char kBackURL[] = "http://back"; |
| 62 const char kForwardURL[] = "http://forward"; | 60 const char kForwardURL[] = "http://forward"; |
| 63 const char kTestURL[] = "http://test"; | 61 const char kTestURL[] = "http://test"; |
| 62 NSString* const kForwardHTMLSentinel = @"Forward page loaded"; |
| 63 NSString* const kTestPageSentinel = @"Test Page"; |
| 64 | 64 |
| 65 // URLs and labels for scenarioWindowLocation* tests. | 65 // URLs and labels for scenarioWindowLocation* tests. |
| 66 const char kHashChangeWithHistoryLabel[] = "hashChangedWithHistory"; | 66 const char kHashChangeWithHistoryLabel[] = "hashChangedWithHistory"; |
| 67 const char kHashChangeWithoutHistoryLabel[] = "hashChangedWithoutHistory"; | 67 const char kHashChangeWithoutHistoryLabel[] = "hashChangedWithoutHistory"; |
| 68 const char kPage1URL[] = "http://page1"; | 68 const char kPage1URL[] = "http://page1"; |
| 69 const char kHashChangedWithHistoryURL[] = | 69 const char kHashChangedWithHistoryURL[] = |
| 70 "http://page1/#hashChangedWithHistory"; | 70 "http://page1/#hashChangedWithHistory"; |
| 71 const char kHashChangedWithoutHistoryURL[] = | 71 const char kHashChangedWithoutHistoryURL[] = |
| 72 "http://page1/#hashChangedWithoutHistory"; | 72 "http://page1/#hashChangedWithoutHistory"; |
| 73 const char kNoHashChangeText[] = "No hash change"; | 73 const char kNoHashChangeText[] = "No hash change"; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 #pragma mark window.history.go operations | 197 #pragma mark window.history.go operations |
| 198 | 198 |
| 199 // Tests reloading the current page via window.history.go() with no parameters. | 199 // Tests reloading the current page via window.history.go() with no parameters. |
| 200 - (void)testHistoryGoNoParameter { | 200 - (void)testHistoryGoNoParameter { |
| 201 web::test::SetUpFileBasedHttpServer(); | 201 web::test::SetUpFileBasedHttpServer(); |
| 202 | 202 |
| 203 // Load the history test page and ensure that its onload text is visible. | 203 // Load the history test page and ensure that its onload text is visible. |
| 204 const GURL windowHistoryURL = | 204 const GURL windowHistoryURL = |
| 205 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 205 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 206 [ChromeEarlGrey loadURL:windowHistoryURL]; | 206 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 207 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 207 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 208 assertWithMatcher:grey_notNil()]; | |
| 209 | 208 |
| 210 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so | 209 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so |
| 211 // the subsequent check for |kOnLoadText| will only pass if a reload has | 210 // the subsequent check for |kOnLoadText| will only pass if a reload has |
| 212 // occurred. | 211 // occurred. |
| 213 [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID]; | 212 [ChromeEarlGrey tapWebViewElementWithID:kGoNoParameterID]; |
| 214 | 213 |
| 215 // Verify that the onload text is reset. | 214 // Verify that the onload text is reset. |
| 216 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 215 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 217 assertWithMatcher:grey_notNil()]; | |
| 218 } | 216 } |
| 219 | 217 |
| 220 // Tests reloading the current page via history.go(0). | 218 // Tests reloading the current page via history.go(0). |
| 221 - (void)testHistoryGoDeltaZero { | 219 - (void)testHistoryGoDeltaZero { |
| 222 web::test::SetUpFileBasedHttpServer(); | 220 web::test::SetUpFileBasedHttpServer(); |
| 223 | 221 |
| 224 // Load the history test page and ensure that its onload text is visible. | 222 // Load the history test page and ensure that its onload text is visible. |
| 225 const GURL windowHistoryURL = | 223 const GURL windowHistoryURL = |
| 226 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 224 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 227 [ChromeEarlGrey loadURL:windowHistoryURL]; | 225 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 228 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 226 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 229 assertWithMatcher:grey_notNil()]; | |
| 230 | 227 |
| 231 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so | 228 // Tap on the window.history.go() button. This will clear |kOnLoadText|, so |
| 232 // the subsequent check for |kOnLoadText| will only pass if a reload has | 229 // the subsequent check for |kOnLoadText| will only pass if a reload has |
| 233 // occurred. | 230 // occurred. |
| 234 [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID]; | 231 [ChromeEarlGrey tapWebViewElementWithID:kGoZeroID]; |
| 235 | 232 |
| 236 // Verify that the onload text is reset. | 233 // Verify that the onload text is reset. |
| 237 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 234 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 238 assertWithMatcher:grey_notNil()]; | |
| 239 } | 235 } |
| 240 | 236 |
| 241 // Tests that calling window.history.go() with an offset that is out of bounds | 237 // Tests that calling window.history.go() with an offset that is out of bounds |
| 242 // is a no-op. | 238 // is a no-op. |
| 243 - (void)testHistoryGoOutOfBounds { | 239 - (void)testHistoryGoOutOfBounds { |
| 244 web::test::SetUpFileBasedHttpServer(); | 240 web::test::SetUpFileBasedHttpServer(); |
| 245 | 241 |
| 246 // Load the history test page and ensure that its onload text is visible. | 242 // Load the history test page and ensure that its onload text is visible. |
| 247 const GURL windowHistoryURL = | 243 const GURL windowHistoryURL = |
| 248 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 244 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 249 [ChromeEarlGrey loadURL:windowHistoryURL]; | 245 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 250 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 246 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 251 assertWithMatcher:grey_notNil()]; | |
| 252 | 247 |
| 253 // Tap on the window.history.go(2) button. This will clear all div text, so | 248 // Tap on the window.history.go(2) button. This will clear all div text, so |
| 254 // the subsequent check for |kNoOpText| will only pass if no navigations have | 249 // the subsequent check for |kNoOpText| will only pass if no navigations have |
| 255 // occurred. | 250 // occurred. |
| 256 [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID]; | 251 [ChromeEarlGrey tapWebViewElementWithID:kGoTwoID]; |
| 257 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)] | 252 [ChromeEarlGrey waitForWebViewContainingText:kNoOpText]; |
| 258 assertWithMatcher:grey_notNil()]; | |
| 259 | 253 |
| 260 // Tap on the window.history.go(-2) button. This will clear all div text, so | 254 // Tap on the window.history.go(-2) button. This will clear all div text, so |
| 261 // the subsequent check for |kNoOpText| will only pass if no navigations have | 255 // the subsequent check for |kNoOpText| will only pass if no navigations have |
| 262 // occurred. | 256 // occurred. |
| 263 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; | 257 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; |
| 264 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kNoOpText)] | 258 [ChromeEarlGrey waitForWebViewContainingText:kNoOpText]; |
| 265 assertWithMatcher:grey_notNil()]; | |
| 266 } | 259 } |
| 267 | 260 |
| 268 // Tests going back and forward via history.go(). | 261 // Tests going back and forward via history.go(). |
| 269 - (void)testHistoryGoDelta { | 262 - (void)testHistoryGoDelta { |
| 270 std::map<GURL, std::string> responses; | 263 std::map<GURL, std::string> responses; |
| 271 const GURL firstURL = web::test::HttpServer::MakeUrl("http://page1"); | 264 const GURL firstURL = web::test::HttpServer::MakeUrl("http://page1"); |
| 272 const GURL secondURL = web::test::HttpServer::MakeUrl("http://page2"); | 265 const GURL secondURL = web::test::HttpServer::MakeUrl("http://page2"); |
| 273 const GURL thirdURL = web::test::HttpServer::MakeUrl("http://page3"); | 266 const GURL thirdURL = web::test::HttpServer::MakeUrl("http://page3"); |
| 274 const GURL fourthURL = web::test::HttpServer::MakeUrl("http://page4"); | 267 const GURL fourthURL = web::test::HttpServer::MakeUrl("http://page4"); |
| 275 responses[firstURL] = | 268 responses[firstURL] = |
| 276 "page1 <input type='button' value='goForward' id='goForward' " | 269 "page1 <input type='button' value='goForward' id='goForward' " |
| 277 "onclick='window.history.go(2)' />"; | 270 "onclick='window.history.go(2)' />"; |
| 278 responses[secondURL] = "page2"; | 271 responses[secondURL] = "page2"; |
| 279 responses[thirdURL] = "page3"; | 272 responses[thirdURL] = "page3"; |
| 280 responses[fourthURL] = | 273 responses[fourthURL] = |
| 281 "page4 <input type='button' value='goBack' id='goBack' " | 274 "page4 <input type='button' value='goBack' id='goBack' " |
| 282 "onclick='window.history.go(-3)' />"; | 275 "onclick='window.history.go(-3)' />"; |
| 283 web::test::SetUpSimpleHttpServer(responses); | 276 web::test::SetUpSimpleHttpServer(responses); |
| 284 | 277 |
| 285 // Load 4 pages. | 278 // Load 4 pages. |
| 286 [ChromeEarlGrey loadURL:firstURL]; | 279 [ChromeEarlGrey loadURL:firstURL]; |
| 287 [ChromeEarlGrey loadURL:secondURL]; | 280 [ChromeEarlGrey loadURL:secondURL]; |
| 288 [ChromeEarlGrey loadURL:thirdURL]; | 281 [ChromeEarlGrey loadURL:thirdURL]; |
| 289 [ChromeEarlGrey loadURL:fourthURL]; | 282 [ChromeEarlGrey loadURL:fourthURL]; |
| 290 [[EarlGrey selectElementWithMatcher:WebViewContainingText("page4")] | 283 [ChromeEarlGrey waitForWebViewContainingText:@"page4"]; |
| 291 assertWithMatcher:grey_notNil()]; | |
| 292 | 284 |
| 293 // Tap button to go back 3 pages. | 285 // Tap button to go back 3 pages. |
| 294 TapWebViewElementWithId("goBack"); | 286 TapWebViewElementWithId("goBack"); |
| 295 [[EarlGrey selectElementWithMatcher:WebViewContainingText("page1")] | 287 [ChromeEarlGrey waitForWebViewContainingText:@"page1"]; |
| 296 assertWithMatcher:grey_notNil()]; | |
| 297 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 288 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 298 firstURL.GetContent())] | 289 firstURL.GetContent())] |
| 299 assertWithMatcher:grey_notNil()]; | 290 assertWithMatcher:grey_notNil()]; |
| 300 | 291 |
| 301 // Tap button to go forward 2 pages. | 292 // Tap button to go forward 2 pages. |
| 302 TapWebViewElementWithId("goForward"); | 293 TapWebViewElementWithId("goForward"); |
| 303 [[EarlGrey selectElementWithMatcher:WebViewContainingText("page3")] | 294 [ChromeEarlGrey waitForWebViewContainingText:@"page3"]; |
| 304 assertWithMatcher:grey_notNil()]; | |
| 305 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 295 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 306 thirdURL.GetContent())] | 296 thirdURL.GetContent())] |
| 307 assertWithMatcher:grey_notNil()]; | 297 assertWithMatcher:grey_notNil()]; |
| 308 } | 298 } |
| 309 | 299 |
| 310 // Tests that calls to window.history.go() that span multiple documents causes | 300 // Tests that calls to window.history.go() that span multiple documents causes |
| 311 // a load to occur. | 301 // a load to occur. |
| 312 - (void)testHistoryCrossDocumentLoad { | 302 - (void)testHistoryCrossDocumentLoad { |
| 313 web::test::SetUpFileBasedHttpServer(); | 303 web::test::SetUpFileBasedHttpServer(); |
| 314 | 304 |
| 315 // Load the history test page and ensure that its onload text is visible. | 305 // Load the history test page and ensure that its onload text is visible. |
| 316 const GURL windowHistoryURL = | 306 const GURL windowHistoryURL = |
| 317 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); | 307 web::test::HttpServer::MakeUrl(kWindowHistoryGoTestURL); |
| 318 [ChromeEarlGrey loadURL:windowHistoryURL]; | 308 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 319 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 309 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 320 assertWithMatcher:grey_notNil()]; | |
| 321 | 310 |
| 322 const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); | 311 const GURL sampleURL = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); |
| 323 [ChromeEarlGrey loadURL:sampleURL]; | 312 [ChromeEarlGrey loadURL:sampleURL]; |
| 324 | 313 |
| 325 [ChromeEarlGrey loadURL:windowHistoryURL]; | 314 [ChromeEarlGrey loadURL:windowHistoryURL]; |
| 326 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 315 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 327 assertWithMatcher:grey_notNil()]; | |
| 328 | 316 |
| 329 // Tap the window.history.go(-2) button. This will clear the current page's | 317 // Tap the window.history.go(-2) button. This will clear the current page's |
| 330 // |kOnLoadText|, so the subsequent check will only pass if another load | 318 // |kOnLoadText|, so the subsequent check will only pass if another load |
| 331 // occurs. | 319 // occurs. |
| 332 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; | 320 [ChromeEarlGrey tapWebViewElementWithID:kGoBackTwoID]; |
| 333 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kOnLoadText)] | 321 [ChromeEarlGrey waitForWebViewContainingText:kOnLoadText]; |
| 334 assertWithMatcher:grey_notNil()]; | |
| 335 } | 322 } |
| 336 | 323 |
| 337 #pragma mark window.history.[back/forward] operations | 324 #pragma mark window.history.[back/forward] operations |
| 338 | 325 |
| 339 // Tests going back via history.back() then forward via forward button. | 326 // Tests going back via history.back() then forward via forward button. |
| 340 - (void)testHistoryBackNavigation { | 327 - (void)testHistoryBackNavigation { |
| 341 SetupBackAndForwardResponseProvider(); | 328 SetupBackAndForwardResponseProvider(); |
| 342 | 329 |
| 343 // Navigate to a URL. | 330 // Navigate to a URL. |
| 344 const GURL firstURL = web::test::HttpServer::MakeUrl(kTestURL); | 331 const GURL firstURL = web::test::HttpServer::MakeUrl(kTestURL); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 370 const GURL firstURL = web::test::HttpServer::MakeUrl(kForwardURL); | 357 const GURL firstURL = web::test::HttpServer::MakeUrl(kForwardURL); |
| 371 [ChromeEarlGrey loadURL:firstURL]; | 358 [ChromeEarlGrey loadURL:firstURL]; |
| 372 | 359 |
| 373 // Navigate to some other page. | 360 // Navigate to some other page. |
| 374 const GURL secondURL = web::test::HttpServer::MakeUrl(kTestURL); | 361 const GURL secondURL = web::test::HttpServer::MakeUrl(kTestURL); |
| 375 [ChromeEarlGrey loadURL:secondURL]; | 362 [ChromeEarlGrey loadURL:secondURL]; |
| 376 | 363 |
| 377 // Tap the back button in the toolbar and verify the page with forward button | 364 // Tap the back button in the toolbar and verify the page with forward button |
| 378 // is loaded. | 365 // is loaded. |
| 379 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; | 366 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 380 [[EarlGrey | 367 [ChromeEarlGrey waitForWebViewContainingText:kForwardHTMLSentinel]; |
| 381 selectElementWithMatcher:WebViewContainingText(kForwardHTMLSentinel)] | |
| 382 assertWithMatcher:grey_notNil()]; | |
| 383 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 368 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 384 firstURL.GetContent())] | 369 firstURL.GetContent())] |
| 385 assertWithMatcher:grey_notNil()]; | 370 assertWithMatcher:grey_notNil()]; |
| 386 | 371 |
| 387 // Tap the forward button in the HTML and verify the second URL is loaded. | 372 // Tap the forward button in the HTML and verify the second URL is loaded. |
| 388 TapWebViewElementWithId(kForwardHTMLButtonLabel); | 373 TapWebViewElementWithId(kForwardHTMLButtonLabel); |
| 389 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTestPageSentinel)] | 374 [ChromeEarlGrey waitForWebViewContainingText:kTestPageSentinel]; |
| 390 assertWithMatcher:grey_notNil()]; | |
| 391 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 375 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 392 secondURL.GetContent())] | 376 secondURL.GetContent())] |
| 393 assertWithMatcher:grey_notNil()]; | 377 assertWithMatcher:grey_notNil()]; |
| 394 | 378 |
| 395 // Verify that the forward button is not enabled. | 379 // Verify that the forward button is not enabled. |
| 396 // TODO(crbug.com/638674): Evaluate if size class determination can move to | 380 // TODO(crbug.com/638674): Evaluate if size class determination can move to |
| 397 // shared code. | 381 // shared code. |
| 398 if (UIApplication.sharedApplication.keyWindow.traitCollection | 382 if (UIApplication.sharedApplication.keyWindow.traitCollection |
| 399 .horizontalSizeClass == UIUserInterfaceSizeClassCompact) { | 383 .horizontalSizeClass == UIUserInterfaceSizeClassCompact) { |
| 400 // In horizontally compact environments, the forward button is not visible. | 384 // In horizontally compact environments, the forward button is not visible. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // Click link to update location.hash and go to new URL (same page). | 444 // Click link to update location.hash and go to new URL (same page). |
| 461 chrome_test_util::TapWebViewElementWithId(kHashChangeWithHistoryLabel); | 445 chrome_test_util::TapWebViewElementWithId(kHashChangeWithHistoryLabel); |
| 462 | 446 |
| 463 // Navigate back to original URL. This should fire a hashchange event. | 447 // Navigate back to original URL. This should fire a hashchange event. |
| 464 std::string backHashChangeContent = "backHashChange"; | 448 std::string backHashChangeContent = "backHashChange"; |
| 465 [self addHashChangeListenerWithContent:backHashChangeContent]; | 449 [self addHashChangeListenerWithContent:backHashChangeContent]; |
| 466 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; | 450 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 467 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 451 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 468 page1URL.GetContent())] | 452 page1URL.GetContent())] |
| 469 assertWithMatcher:grey_notNil()]; | 453 assertWithMatcher:grey_notNil()]; |
| 470 [[EarlGrey | 454 [ChromeEarlGrey waitForWebViewContainingText:base::SysUTF8ToNSString( |
| 471 selectElementWithMatcher:WebViewContainingText(backHashChangeContent)] | 455 backHashChangeContent)]; |
| 472 assertWithMatcher:grey_notNil()]; | |
| 473 | 456 |
| 474 // Navigate forward to the new URL. This should fire a hashchange event. | 457 // Navigate forward to the new URL. This should fire a hashchange event. |
| 475 std::string forwardHashChangeContent = "forwardHashChange"; | 458 std::string forwardHashChangeContent = "forwardHashChange"; |
| 476 [self addHashChangeListenerWithContent:forwardHashChangeContent]; | 459 [self addHashChangeListenerWithContent:forwardHashChangeContent]; |
| 477 [[EarlGrey selectElementWithMatcher:ForwardButton()] | 460 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 478 performAction:grey_tap()]; | 461 performAction:grey_tap()]; |
| 479 [[EarlGrey | 462 [[EarlGrey |
| 480 selectElementWithMatcher:chrome_test_util::OmniboxText( | 463 selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 481 hashChangedWithHistoryURL.GetContent())] | 464 hashChangedWithHistoryURL.GetContent())] |
| 482 assertWithMatcher:grey_notNil()]; | 465 assertWithMatcher:grey_notNil()]; |
| 483 [[EarlGrey | 466 [ChromeEarlGrey waitForWebViewContainingText:base::SysUTF8ToNSString( |
| 484 selectElementWithMatcher:WebViewContainingText(forwardHashChangeContent)] | 467 forwardHashChangeContent)]; |
| 485 assertWithMatcher:grey_notNil()]; | |
| 486 | 468 |
| 487 // Load a hash URL directly. This shouldn't fire a hashchange event. | 469 // Load a hash URL directly. This shouldn't fire a hashchange event. |
| 488 std::string hashChangeContent = "FAIL_loadUrlHashChange"; | 470 std::string hashChangeContent = "FAIL_loadUrlHashChange"; |
| 489 [self addHashChangeListenerWithContent:hashChangeContent]; | 471 [self addHashChangeListenerWithContent:hashChangeContent]; |
| 490 [ChromeEarlGrey loadURL:hashChangedWithHistoryURL]; | 472 [ChromeEarlGrey loadURL:hashChangedWithHistoryURL]; |
| 491 [[EarlGrey selectElementWithMatcher:WebViewContainingText(hashChangeContent)] | 473 // TODO(crbug.com/714157): Remove matcher that waits. |
| 492 assertWithMatcher:grey_nil()]; | 474 [[EarlGrey |
| 475 selectElementWithMatcher:chrome_test_util::WebViewNotContainingText( |
| 476 hashChangeContent)] |
| 477 assertWithMatcher:grey_notNil()]; |
| 493 } | 478 } |
| 494 | 479 |
| 495 // Loads a URL and replaces its location, then updates its location.hash | 480 // Loads a URL and replaces its location, then updates its location.hash |
| 496 // and verifies that going back returns to the replaced entry. | 481 // and verifies that going back returns to the replaced entry. |
| 497 - (void)testWindowLocationReplaceAndChangeHash { | 482 - (void)testWindowLocationReplaceAndChangeHash { |
| 498 std::map<GURL, std::string> responses; | 483 std::map<GURL, std::string> responses; |
| 499 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); | 484 const GURL page1URL = web::test::HttpServer::MakeUrl(kPage1URL); |
| 500 const GURL hashChangedWithoutHistoryURL = | 485 const GURL hashChangedWithoutHistoryURL = |
| 501 web::test::HttpServer::MakeUrl(kHashChangedWithoutHistoryURL); | 486 web::test::HttpServer::MakeUrl(kHashChangedWithoutHistoryURL); |
| 502 const GURL hashChangedWithHistoryURL = | 487 const GURL hashChangedWithHistoryURL = |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 // Navigate forward and assert the the resulting page is the proper | 660 // Navigate forward and assert the the resulting page is the proper |
| 676 // destination. | 661 // destination. |
| 677 [[EarlGrey selectElementWithMatcher:ForwardButton()] | 662 [[EarlGrey selectElementWithMatcher:ForwardButton()] |
| 678 performAction:grey_tap()]; | 663 performAction:grey_tap()]; |
| 679 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 664 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 680 destinationURL.GetContent())] | 665 destinationURL.GetContent())] |
| 681 assertWithMatcher:grey_notNil()]; | 666 assertWithMatcher:grey_notNil()]; |
| 682 } | 667 } |
| 683 | 668 |
| 684 @end | 669 @end |
| OLD | NEW |