| 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 18 matching lines...) Expand all Loading... |
| 29 #import "ios/web/public/test/earl_grey/web_view_actions.h" | 29 #import "ios/web/public/test/earl_grey/web_view_actions.h" |
| 30 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 30 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 31 #import "ios/web/public/test/http_server.h" | 31 #import "ios/web/public/test/http_server.h" |
| 32 #include "ios/web/public/test/http_server_util.h" | 32 #include "ios/web/public/test/http_server_util.h" |
| 33 #include "ios/web/public/test/response_providers/data_response_provider.h" | 33 #include "ios/web/public/test/response_providers/data_response_provider.h" |
| 34 #include "net/http/http_response_headers.h" | 34 #include "net/http/http_response_headers.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 37 | 37 |
| 38 using chrome_test_util::OmniboxText; | 38 using chrome_test_util::OmniboxText; |
| 39 using chrome_test_util::WebViewContainingText; | |
| 40 | 39 |
| 41 namespace { | 40 namespace { |
| 42 | 41 |
| 43 // URL used for the reload test. | 42 // URL used for the reload test. |
| 44 const char kReloadTestUrl[] = "http://mock/reloadTest"; | 43 const char kReloadTestUrl[] = "http://mock/reloadTest"; |
| 45 | 44 |
| 46 // Returns the number of serviced requests in HTTP body. | 45 // Returns the number of serviced requests in HTTP body. |
| 47 class ReloadResponseProvider : public web::DataResponseProvider { | 46 class ReloadResponseProvider : public web::DataResponseProvider { |
| 48 public: | 47 public: |
| 49 ReloadResponseProvider() : request_number_(0) {} | 48 ReloadResponseProvider() : request_number_(0) {} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 134 |
| 136 // Tests that page successfully reloads. | 135 // Tests that page successfully reloads. |
| 137 - (void)testReload { | 136 - (void)testReload { |
| 138 // Set up test HTTP server responses. | 137 // Set up test HTTP server responses. |
| 139 std::unique_ptr<web::DataResponseProvider> provider( | 138 std::unique_ptr<web::DataResponseProvider> provider( |
| 140 new ReloadResponseProvider()); | 139 new ReloadResponseProvider()); |
| 141 web::test::SetUpHttpServer(std::move(provider)); | 140 web::test::SetUpHttpServer(std::move(provider)); |
| 142 | 141 |
| 143 GURL URL = ReloadResponseProvider::GetReloadTestUrl(); | 142 GURL URL = ReloadResponseProvider::GetReloadTestUrl(); |
| 144 [ChromeEarlGrey loadURL:URL]; | 143 [ChromeEarlGrey loadURL:URL]; |
| 145 std::string expectedBodyBeforeReload( | 144 |
| 145 NSString* expectedBodyBeforeReload = base::SysUTF8ToNSString( |
| 146 ReloadResponseProvider::GetResponseBody(0 /* request number */)); | 146 ReloadResponseProvider::GetResponseBody(0 /* request number */)); |
| 147 [[EarlGrey | 147 [ChromeEarlGrey waitForWebViewContainingText:expectedBodyBeforeReload]; |
| 148 selectElementWithMatcher:WebViewContainingText(expectedBodyBeforeReload)] | |
| 149 assertWithMatcher:grey_notNil()]; | |
| 150 | 148 |
| 151 [ChromeEarlGreyUI reload]; | 149 [ChromeEarlGreyUI reload]; |
| 152 std::string expectedBodyAfterReload( | 150 NSString* expectedBodyAfterReload = base::SysUTF8ToNSString( |
| 153 ReloadResponseProvider::GetResponseBody(1 /* request_number */)); | 151 ReloadResponseProvider::GetResponseBody(1 /* request_number */)); |
| 154 [[EarlGrey | 152 [ChromeEarlGrey waitForWebViewContainingText:expectedBodyAfterReload]; |
| 155 selectElementWithMatcher:WebViewContainingText(expectedBodyAfterReload)] | |
| 156 assertWithMatcher:grey_notNil()]; | |
| 157 } | 153 } |
| 158 | 154 |
| 159 // Tests that a tab's title is based on the URL when no other information is | 155 // Tests that a tab's title is based on the URL when no other information is |
| 160 // available. | 156 // available. |
| 161 - (void)testBrowsingTabTitleSetFromURL { | 157 - (void)testBrowsingTabTitleSetFromURL { |
| 162 if (!IsIPadIdiom()) { | 158 if (!IsIPadIdiom()) { |
| 163 EARL_GREY_TEST_SKIPPED(@"Tab Title not displayed on handset."); | 159 EARL_GREY_TEST_SKIPPED(@"Tab Title not displayed on handset."); |
| 164 } | 160 } |
| 165 | 161 |
| 166 web::test::SetUpFileBasedHttpServer(); | 162 web::test::SetUpFileBasedHttpServer(); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 | 419 |
| 424 [ChromeEarlGrey loadURL:URL]; | 420 [ChromeEarlGrey loadURL:URL]; |
| 425 | 421 |
| 426 // Tap on chrome://version link. | 422 // Tap on chrome://version link. |
| 427 [ChromeEarlGrey tapWebViewElementWithID:@"link"]; | 423 [ChromeEarlGrey tapWebViewElementWithID:@"link"]; |
| 428 | 424 |
| 429 // Verify that page did not change by checking its URL and message printed by | 425 // Verify that page did not change by checking its URL and message printed by |
| 430 // onclick event. | 426 // onclick event. |
| 431 [[EarlGrey selectElementWithMatcher:OmniboxText("chrome://version")] | 427 [[EarlGrey selectElementWithMatcher:OmniboxText("chrome://version")] |
| 432 assertWithMatcher:grey_nil()]; | 428 assertWithMatcher:grey_nil()]; |
| 433 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Hello world!")] | 429 [ChromeEarlGrey waitForWebViewContainingText:@"Hello world!"]; |
| 434 assertWithMatcher:grey_notNil()]; | |
| 435 | 430 |
| 436 // Verify that no new tabs were open which could load chrome://version. | 431 // Verify that no new tabs were open which could load chrome://version. |
| 437 chrome_test_util::AssertMainTabCount(1U); | 432 chrome_test_util::AssertMainTabCount(1U); |
| 438 } | 433 } |
| 439 | 434 |
| 440 // Tests that pressing the button on a POST-based form with same-page action | 435 // Tests that pressing the button on a POST-based form with same-page action |
| 441 // does not change the page and that the back button works as expected | 436 // does not change the page and that the back button works as expected |
| 442 // afterwards. | 437 // afterwards. |
| 443 - (void)testBrowsingPostToSamePage { | 438 - (void)testBrowsingPostToSamePage { |
| 444 // Create map of canned responses and set up the test HTML server. | 439 // Create map of canned responses and set up the test HTML server. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 525 |
| 531 [ChromeEarlGrey loadURL:firstURL]; | 526 [ChromeEarlGrey loadURL:firstURL]; |
| 532 [ChromeEarlGrey loadURL:secondURL]; | 527 [ChromeEarlGrey loadURL:secondURL]; |
| 533 | 528 |
| 534 // Execute some JavaScript in the omnibox. | 529 // Execute some JavaScript in the omnibox. |
| 535 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] | 530 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] |
| 536 performAction:grey_typeText(@"javascript:document.write('foo')")]; | 531 performAction:grey_typeText(@"javascript:document.write('foo')")]; |
| 537 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")] | 532 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")] |
| 538 performAction:grey_tap()]; | 533 performAction:grey_tap()]; |
| 539 | 534 |
| 540 id<GREYMatcher> webView = chrome_test_util::WebViewContainingText("foo"); | 535 [ChromeEarlGrey waitForWebViewContainingText:@"foo"]; |
| 541 [[EarlGrey selectElementWithMatcher:webView] assertWithMatcher:grey_notNil()]; | |
| 542 | 536 |
| 543 // Verify that the JavaScript did not affect history by going back and then | 537 // Verify that the JavaScript did not affect history by going back and then |
| 544 // forward again. | 538 // forward again. |
| 545 [self goBack]; | 539 [self goBack]; |
| 546 [[EarlGrey selectElementWithMatcher:OmniboxText(firstURL.GetContent())] | 540 [[EarlGrey selectElementWithMatcher:OmniboxText(firstURL.GetContent())] |
| 547 assertWithMatcher:grey_notNil()]; | 541 assertWithMatcher:grey_notNil()]; |
| 548 [self goForward]; | 542 [self goForward]; |
| 549 [[EarlGrey selectElementWithMatcher:OmniboxText(secondURL.GetContent())] | 543 [[EarlGrey selectElementWithMatcher:OmniboxText(secondURL.GetContent())] |
| 550 assertWithMatcher:grey_notNil()]; | 544 assertWithMatcher:grey_notNil()]; |
| 551 } | 545 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 "<form action='%s' method='post'>" | 612 "<form action='%s' method='post'>" |
| 619 "<input value='textfield' id='textfield' type='text'></label>" | 613 "<input value='textfield' id='textfield' type='text'></label>" |
| 620 "<input type='submit'></form>", | 614 "<input type='submit'></form>", |
| 621 destinationURL.spec().c_str()); | 615 destinationURL.spec().c_str()); |
| 622 // This is the page that should be showing at the end of the test. | 616 // This is the page that should be showing at the end of the test. |
| 623 responses[destinationURL] = "baz!"; | 617 responses[destinationURL] = "baz!"; |
| 624 web::test::SetUpSimpleHttpServer(responses); | 618 web::test::SetUpSimpleHttpServer(responses); |
| 625 | 619 |
| 626 // Open the URL, focus the textfield,and submit via keyboard. | 620 // Open the URL, focus the textfield,and submit via keyboard. |
| 627 [ChromeEarlGrey loadURL:URL]; | 621 [ChromeEarlGrey loadURL:URL]; |
| 628 [[EarlGrey selectElementWithMatcher:WebViewContainingText("hello!")] | 622 [ChromeEarlGrey waitForWebViewContainingText:@"hello!"]; |
| 629 assertWithMatcher:grey_notNil()]; | |
| 630 | 623 |
| 631 [self submitFormUsingKeyboardGoButtonWithInputID:"textfield"]; | 624 [self submitFormUsingKeyboardGoButtonWithInputID:"textfield"]; |
| 632 | 625 |
| 633 // Verify that the browser navigates to the expected URL. | 626 // Verify that the browser navigates to the expected URL. |
| 634 [[EarlGrey selectElementWithMatcher:WebViewContainingText("baz!")] | 627 [ChromeEarlGrey waitForWebViewContainingText:@"baz!"]; |
| 635 assertWithMatcher:grey_notNil()]; | |
| 636 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] | 628 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] |
| 637 assertWithMatcher:grey_notNil()]; | 629 assertWithMatcher:grey_notNil()]; |
| 638 | 630 |
| 639 // Go back and verify that the browser navigates to the original URL. | 631 // Go back and verify that the browser navigates to the original URL. |
| 640 [self goBack]; | 632 [self goBack]; |
| 641 [[EarlGrey selectElementWithMatcher:WebViewContainingText("hello!")] | 633 [ChromeEarlGrey waitForWebViewContainingText:@"hello!"]; |
| 642 assertWithMatcher:grey_notNil()]; | |
| 643 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] | 634 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] |
| 644 assertWithMatcher:grey_notNil()]; | 635 assertWithMatcher:grey_notNil()]; |
| 645 } | 636 } |
| 646 | 637 |
| 647 @end | 638 @end |
| OLD | NEW |