Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: ios/chrome/browser/web/browsing_egtest.mm

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: review comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
33 #include "ios/web/public/test/http_server/http_server_util.h" 33 #include "ios/web/public/test/http_server/http_server_util.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 #if !defined(__has_feature) || !__has_feature(objc_arc) 38 #if !defined(__has_feature) || !__has_feature(objc_arc)
39 #error "This file requires ARC support." 39 #error "This file requires ARC support."
40 #endif 40 #endif
41 41
42 using chrome_test_util::OmniboxText; 42 using chrome_test_util::OmniboxText;
43 using chrome_test_util::WebViewContainingText;
44 43
45 namespace { 44 namespace {
46 45
47 // URL used for the reload test. 46 // URL used for the reload test.
48 const char kReloadTestUrl[] = "http://mock/reloadTest"; 47 const char kReloadTestUrl[] = "http://mock/reloadTest";
49 48
50 // Returns the number of serviced requests in HTTP body. 49 // Returns the number of serviced requests in HTTP body.
51 class ReloadResponseProvider : public web::DataResponseProvider { 50 class ReloadResponseProvider : public web::DataResponseProvider {
52 public: 51 public:
53 ReloadResponseProvider() : request_number_(0) {} 52 ReloadResponseProvider() : request_number_(0) {}
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 - (void)testReload { 140 - (void)testReload {
142 // Set up test HTTP server responses. 141 // Set up test HTTP server responses.
143 std::unique_ptr<web::DataResponseProvider> provider( 142 std::unique_ptr<web::DataResponseProvider> provider(
144 new ReloadResponseProvider()); 143 new ReloadResponseProvider());
145 web::test::SetUpHttpServer(std::move(provider)); 144 web::test::SetUpHttpServer(std::move(provider));
146 145
147 GURL URL = ReloadResponseProvider::GetReloadTestUrl(); 146 GURL URL = ReloadResponseProvider::GetReloadTestUrl();
148 [ChromeEarlGrey loadURL:URL]; 147 [ChromeEarlGrey loadURL:URL];
149 std::string expectedBodyBeforeReload( 148 std::string expectedBodyBeforeReload(
150 ReloadResponseProvider::GetResponseBody(0 /* request number */)); 149 ReloadResponseProvider::GetResponseBody(0 /* request number */));
151 [[EarlGrey 150 [ChromeEarlGrey waitForWebViewContainingText:expectedBodyBeforeReload];
152 selectElementWithMatcher:WebViewContainingText(expectedBodyBeforeReload)]
153 assertWithMatcher:grey_notNil()];
154 151
155 [ChromeEarlGreyUI reload]; 152 [ChromeEarlGreyUI reload];
156 std::string expectedBodyAfterReload( 153 std::string expectedBodyAfterReload(
157 ReloadResponseProvider::GetResponseBody(1 /* request_number */)); 154 ReloadResponseProvider::GetResponseBody(1 /* request_number */));
158 [[EarlGrey 155 [ChromeEarlGrey waitForWebViewContainingText:expectedBodyAfterReload];
159 selectElementWithMatcher:WebViewContainingText(expectedBodyAfterReload)]
160 assertWithMatcher:grey_notNil()];
161 } 156 }
162 157
163 // Tests that a tab's title is based on the URL when no other information is 158 // Tests that a tab's title is based on the URL when no other information is
164 // available. 159 // available.
165 - (void)testBrowsingTabTitleSetFromURL { 160 - (void)testBrowsingTabTitleSetFromURL {
166 if (!IsIPadIdiom()) { 161 if (!IsIPadIdiom()) {
167 EARL_GREY_TEST_SKIPPED(@"Tab Title not displayed on handset."); 162 EARL_GREY_TEST_SKIPPED(@"Tab Title not displayed on handset.");
168 } 163 }
169 164
170 web::test::SetUpFileBasedHttpServer(); 165 web::test::SetUpFileBasedHttpServer();
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 422
428 [ChromeEarlGrey loadURL:URL]; 423 [ChromeEarlGrey loadURL:URL];
429 424
430 // Tap on chrome://version link. 425 // Tap on chrome://version link.
431 [ChromeEarlGrey tapWebViewElementWithID:@"link"]; 426 [ChromeEarlGrey tapWebViewElementWithID:@"link"];
432 427
433 // Verify that page did not change by checking its URL and message printed by 428 // Verify that page did not change by checking its URL and message printed by
434 // onclick event. 429 // onclick event.
435 [[EarlGrey selectElementWithMatcher:OmniboxText("chrome://version")] 430 [[EarlGrey selectElementWithMatcher:OmniboxText("chrome://version")]
436 assertWithMatcher:grey_nil()]; 431 assertWithMatcher:grey_nil()];
437 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Hello world!")] 432 [ChromeEarlGrey waitForWebViewContainingText:"Hello world!"];
438 assertWithMatcher:grey_notNil()];
439 433
440 // Verify that no new tabs were open which could load chrome://version. 434 // Verify that no new tabs were open which could load chrome://version.
441 chrome_test_util::AssertMainTabCount(1U); 435 chrome_test_util::AssertMainTabCount(1U);
442 } 436 }
443 437
444 // Tests that pressing the button on a POST-based form with same-page action 438 // Tests that pressing the button on a POST-based form with same-page action
445 // does not change the page and that the back button works as expected 439 // does not change the page and that the back button works as expected
446 // afterwards. 440 // afterwards.
447 - (void)testBrowsingPostToSamePage { 441 - (void)testBrowsingPostToSamePage {
448 // TODO(crbug.com/714303): Re-enable this test on devices. 442 // TODO(crbug.com/714303): Re-enable this test on devices.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 533
540 [ChromeEarlGrey loadURL:firstURL]; 534 [ChromeEarlGrey loadURL:firstURL];
541 [ChromeEarlGrey loadURL:secondURL]; 535 [ChromeEarlGrey loadURL:secondURL];
542 536
543 // Execute some JavaScript in the omnibox. 537 // Execute some JavaScript in the omnibox.
544 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 538 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
545 performAction:grey_typeText(@"javascript:document.write('foo')")]; 539 performAction:grey_typeText(@"javascript:document.write('foo')")];
546 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")] 540 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Go")]
547 performAction:grey_tap()]; 541 performAction:grey_tap()];
548 542
549 id<GREYMatcher> webView = chrome_test_util::WebViewContainingText("foo"); 543 [ChromeEarlGrey waitForWebViewContainingText:"foo"];
550 [[EarlGrey selectElementWithMatcher:webView] assertWithMatcher:grey_notNil()];
551 544
552 // Verify that the JavaScript did not affect history by going back and then 545 // Verify that the JavaScript did not affect history by going back and then
553 // forward again. 546 // forward again.
554 [self goBack]; 547 [self goBack];
555 [[EarlGrey selectElementWithMatcher:OmniboxText(firstURL.GetContent())] 548 [[EarlGrey selectElementWithMatcher:OmniboxText(firstURL.GetContent())]
556 assertWithMatcher:grey_notNil()]; 549 assertWithMatcher:grey_notNil()];
557 [self goForward]; 550 [self goForward];
558 [[EarlGrey selectElementWithMatcher:OmniboxText(secondURL.GetContent())] 551 [[EarlGrey selectElementWithMatcher:OmniboxText(secondURL.GetContent())]
559 assertWithMatcher:grey_notNil()]; 552 assertWithMatcher:grey_notNil()];
560 } 553 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 "<form action='%s' method='post'>" 625 "<form action='%s' method='post'>"
633 "<input value='textfield' id='textfield' type='text'></label>" 626 "<input value='textfield' id='textfield' type='text'></label>"
634 "<input type='submit'></form>", 627 "<input type='submit'></form>",
635 destinationURL.spec().c_str()); 628 destinationURL.spec().c_str());
636 // This is the page that should be showing at the end of the test. 629 // This is the page that should be showing at the end of the test.
637 responses[destinationURL] = "baz!"; 630 responses[destinationURL] = "baz!";
638 web::test::SetUpSimpleHttpServer(responses); 631 web::test::SetUpSimpleHttpServer(responses);
639 632
640 // Open the URL, focus the textfield,and submit via keyboard. 633 // Open the URL, focus the textfield,and submit via keyboard.
641 [ChromeEarlGrey loadURL:URL]; 634 [ChromeEarlGrey loadURL:URL];
642 [[EarlGrey selectElementWithMatcher:WebViewContainingText("hello!")] 635 [ChromeEarlGrey waitForWebViewContainingText:"hello!"];
643 assertWithMatcher:grey_notNil()];
644 636
645 [self submitFormUsingKeyboardGoButtonWithInputID:"textfield"]; 637 [self submitFormUsingKeyboardGoButtonWithInputID:"textfield"];
646 638
647 // Verify that the browser navigates to the expected URL. 639 // Verify that the browser navigates to the expected URL.
648 [[EarlGrey selectElementWithMatcher:WebViewContainingText("baz!")] 640 [ChromeEarlGrey waitForWebViewContainingText:"baz!"];
649 assertWithMatcher:grey_notNil()];
650 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] 641 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())]
651 assertWithMatcher:grey_notNil()]; 642 assertWithMatcher:grey_notNil()];
652 643
653 // Go back and verify that the browser navigates to the original URL. 644 // Go back and verify that the browser navigates to the original URL.
654 [self goBack]; 645 [self goBack];
655 [[EarlGrey selectElementWithMatcher:WebViewContainingText("hello!")] 646 [ChromeEarlGrey waitForWebViewContainingText:"hello!"];
656 assertWithMatcher:grey_notNil()];
657 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] 647 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())]
658 assertWithMatcher:grey_notNil()]; 648 assertWithMatcher:grey_notNil()];
659 } 649 }
660 650
661 @end 651 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/web_ui_egtest.mm ('k') | ios/chrome/browser/web/browsing_prevent_default_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698