| 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 #include <map> | 6 #include <map> |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 347 |
| 348 chrome_test_util::TapWebViewElementWithId("link"); | 348 chrome_test_util::TapWebViewElementWithId("link"); |
| 349 | 349 |
| 350 chrome_test_util::AssertMainTabCount(2); | 350 chrome_test_util::AssertMainTabCount(2); |
| 351 | 351 |
| 352 // Verify the new tab was opened with the expected URL. | 352 // Verify the new tab was opened with the expected URL. |
| 353 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] | 353 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] |
| 354 assertWithMatcher:grey_notNil()]; | 354 assertWithMatcher:grey_notNil()]; |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Tests that pressing the button on a POST-based form changes the page and that | |
| 358 // the back button works as expected afterwards. | |
| 359 - (void)testBrowsingPostEntryWithButton { | |
| 360 // Create map of canned responses and set up the test HTML server. | |
| 361 std::map<GURL, std::string> responses; | |
| 362 const GURL URL = web::test::HttpServer::MakeUrl("http://postEntryWithButton"); | |
| 363 const GURL destinationURL = web::test::HttpServer::MakeUrl("http://foo"); | |
| 364 // This is a page with a button that posts to the destination. | |
| 365 responses[URL] = base::StringPrintf( | |
| 366 "<form action='%s' method='post'>" | |
| 367 "<input value='button' type='submit' id='button'></form>", | |
| 368 destinationURL.spec().c_str()); | |
| 369 // This is the page that should be showing at the end of the test. | |
| 370 responses[destinationURL] = "bar!"; | |
| 371 web::test::SetUpSimpleHttpServer(responses); | |
| 372 | |
| 373 [ChromeEarlGrey loadURL:URL]; | |
| 374 chrome_test_util::TapWebViewElementWithId("button"); | |
| 375 | |
| 376 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] | |
| 377 assertWithMatcher:grey_notNil()]; | |
| 378 | |
| 379 // Go back and verify the browser navigates to the original URL. | |
| 380 [self goBack]; | |
| 381 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] | |
| 382 assertWithMatcher:grey_notNil()]; | |
| 383 } | |
| 384 | |
| 385 // Tests that a link with a JavaScript-based navigation changes the page and | 357 // Tests that a link with a JavaScript-based navigation changes the page and |
| 386 // that the back button works as expected afterwards. | 358 // that the back button works as expected afterwards. |
| 387 - (void)testBrowsingJavaScriptBasedNavigation { | 359 - (void)testBrowsingJavaScriptBasedNavigation { |
| 388 std::map<GURL, std::string> responses; | 360 std::map<GURL, std::string> responses; |
| 389 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); | 361 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); |
| 390 const GURL destURL = web::test::HttpServer::MakeUrl("http://destination"); | 362 const GURL destURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 391 // Page containing a link with onclick attribute that sets window.location | 363 // Page containing a link with onclick attribute that sets window.location |
| 392 // to the destination URL. | 364 // to the destination URL. |
| 393 responses[URL] = base::StringPrintf( | 365 responses[URL] = base::StringPrintf( |
| 394 "<a href='#' onclick=\"window.location='%s';\" id='link'>Link</a>", | 366 "<a href='#' onclick=\"window.location='%s';\" id='link'>Link</a>", |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] | 637 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] |
| 666 assertWithMatcher:grey_notNil()]; | 638 assertWithMatcher:grey_notNil()]; |
| 667 | 639 |
| 668 // Go back and verify that the browser navigates to the original URL. | 640 // Go back and verify that the browser navigates to the original URL. |
| 669 [self goBack]; | 641 [self goBack]; |
| 670 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] | 642 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] |
| 671 assertWithMatcher:grey_notNil()]; | 643 assertWithMatcher:grey_notNil()]; |
| 672 } | 644 } |
| 673 | 645 |
| 674 @end | 646 @end |
| OLD | NEW |