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

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

Issue 2961483002: Refactor PostOnSamePage test to ensure the form is posted. (Closed)
Patch Set: Refactor PostOnSamePage test to ensure the form is posted. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 27 matching lines...) Expand all
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 43
44 namespace { 44 namespace {
45 45
46 // URL used for the reload test. 46 // URL used for the reload test.
47 const char kReloadTestUrl[] = "http://mock/reloadTest"; 47 const char kReloadTestUrl[] = "http://mock/reloadTest";
48 const char kFormPageUrl[] = "http://form/";
49 const char kFirstPageUrl[] = "http://first/";
48 50
49 // Returns the number of serviced requests in HTTP body. 51 // Returns the number of serviced requests in HTTP body.
50 class ReloadResponseProvider : public web::DataResponseProvider { 52 class ReloadResponseProvider : public web::DataResponseProvider {
51 public: 53 public:
52 ReloadResponseProvider() : request_number_(0) {} 54 ReloadResponseProvider() : request_number_(0) {}
53 55
54 // URL used for the reload test. 56 // URL used for the reload test.
55 static GURL GetReloadTestUrl() { 57 static GURL GetReloadTestUrl() {
56 return web::test::HttpServer::MakeUrl(kReloadTestUrl); 58 return web::test::HttpServer::MakeUrl(kReloadTestUrl);
57 } 59 }
(...skipping 13 matching lines...) Expand all
71 73
72 // static 74 // static
73 static std::string GetResponseBody(int request_number) { 75 static std::string GetResponseBody(int request_number) {
74 return base::StringPrintf("Load request %d", request_number); 76 return base::StringPrintf("Load request %d", request_number);
75 } 77 }
76 78
77 private: 79 private:
78 int request_number_; // Count of requests received by the response provider. 80 int request_number_; // Count of requests received by the response provider.
79 }; 81 };
80 82
83 // A ResponseProvider that provides post form on the same page.
84 class TestPostFormResponseProvider : public web::DataResponseProvider {
Eugene But (OOO till 7-30) 2017/06/24 00:26:09 Looks like forms_egtest has a response provider th
85 public:
86 // URLs used for the post form test.
87 static GURL GetFirstPageUrl() {
88 return web::test::HttpServer::MakeUrl(kFirstPageUrl);
89 }
90 static GURL GetFormPageUrl() {
91 return web::test::HttpServer::MakeUrl(kFormPageUrl);
92 }
93
94 bool CanHandleRequest(const Request& request) override {
95 return request.url == GetFormPageUrl() || request.url == GetFirstPageUrl();
96 }
97 void GetResponseHeadersAndBody(
98 const Request& request,
99 scoped_refptr<net::HttpResponseHeaders>* headers,
100 std::string* response_body) override {
101 const GURL& url = request.url;
102 *headers = web::ResponseProvider::GetDefaultResponseHeaders();
103 if (url == GetFirstPageUrl()) {
104 *response_body = "foo";
105 return;
106 } else if (url == GetFormPageUrl()) {
107 if (request.method == "POST") {
108 *response_body = request.method + std::string(" ") + request.body;
109 } else {
110 *response_body =
111 "<form method='post'>"
112 "<input value='button' type='submit' id='button'></form>";
113 }
114 return;
115 }
116 NOTREACHED();
117 }
118 };
119
81 // ScopedBlockPopupsPref modifies the block popups preference and resets the 120 // ScopedBlockPopupsPref modifies the block popups preference and resets the
82 // preference to its original value when this object goes out of scope. 121 // preference to its original value when this object goes out of scope.
83 // TODO(crbug.com/638674): Evaluate if this can move to shared code 122 // TODO(crbug.com/638674): Evaluate if this can move to shared code
84 class ScopedBlockPopupsPref { 123 class ScopedBlockPopupsPref {
85 public: 124 public:
86 ScopedBlockPopupsPref(ContentSetting setting) { 125 ScopedBlockPopupsPref(ContentSetting setting) {
87 original_setting_ = GetPrefValue(); 126 original_setting_ = GetPrefValue();
88 SetPrefValue(setting); 127 SetPrefValue(setting);
89 } 128 }
90 ~ScopedBlockPopupsPref() { SetPrefValue(original_setting_); } 129 ~ScopedBlockPopupsPref() { SetPrefValue(original_setting_); }
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // onclick event. 468 // onclick event.
430 [[EarlGrey selectElementWithMatcher:OmniboxText("chrome://version")] 469 [[EarlGrey selectElementWithMatcher:OmniboxText("chrome://version")]
431 assertWithMatcher:grey_nil()]; 470 assertWithMatcher:grey_nil()];
432 [ChromeEarlGrey waitForWebViewContainingText:"Hello world!"]; 471 [ChromeEarlGrey waitForWebViewContainingText:"Hello world!"];
433 472
434 // Verify that no new tabs were open which could load chrome://version. 473 // Verify that no new tabs were open which could load chrome://version.
435 chrome_test_util::AssertMainTabCount(1U); 474 chrome_test_util::AssertMainTabCount(1U);
436 } 475 }
437 476
438 // Tests that pressing the button on a POST-based form with same-page action 477 // Tests that pressing the button on a POST-based form with same-page action
439 // does not change the page and that the back button works as expected 478 // does not change the page URL and that the back button works as expected
440 // afterwards. 479 // afterwards.
441 - (void)testBrowsingPostToSamePage { 480 - (void)testBrowsingPostToSamePage {
442 // TODO(crbug.com/714303): Re-enable this test on devices. 481 // TODO(crbug.com/714303): Re-enable this test on devices.
443 #if !TARGET_IPHONE_SIMULATOR 482 #if !TARGET_IPHONE_SIMULATOR
444 EARL_GREY_TEST_DISABLED(@"Test disabled on device."); 483 EARL_GREY_TEST_DISABLED(@"Test disabled on device.");
445 #endif 484 #endif
446 485
447 // Create map of canned responses and set up the test HTML server. 486 // Set up test HTTP server responses.
448 std::map<GURL, std::string> responses; 487 std::unique_ptr<web::DataResponseProvider> provider(
449 const GURL firstURL = web::test::HttpServer::MakeUrl("http://first"); 488 new TestPostFormResponseProvider());
450 const GURL formURL = web::test::HttpServer::MakeUrl("http://form"); 489 web::test::SetUpHttpServer(std::move(provider));
451 // This is just a page with some text. 490 const GURL firstURL = TestPostFormResponseProvider::GetFirstPageUrl();
452 responses[firstURL] = "foo"; 491 const GURL formURL = TestPostFormResponseProvider::GetFormPageUrl();
453 // This is a page with at button that posts to the current URL.
454 responses[formURL] =
455 "<form method='post'>"
456 "<input value='button' type='submit' id='button'></form>";
457 web::test::SetUpSimpleHttpServer(responses);
458 492
459 // Open the first URL so it's in history. 493 // Open the first URL so it's in history.
460 [ChromeEarlGrey loadURL:firstURL]; 494 [ChromeEarlGrey loadURL:firstURL];
461 495
462 // Open the second URL, tap the button, and verify the browser navigates to 496 // Open the second URL, tap the button, and verify the browser navigates to
463 // the expected URL. 497 // the expected URL.
464 [ChromeEarlGrey loadURL:formURL]; 498 [ChromeEarlGrey loadURL:formURL];
465 chrome_test_util::TapWebViewElementWithId("button"); 499 chrome_test_util::TapWebViewElementWithId("button");
500 [ChromeEarlGrey waitForWebViewContainingText:"POST"];
466 [[EarlGrey selectElementWithMatcher:OmniboxText(formURL.GetContent())] 501 [[EarlGrey selectElementWithMatcher:OmniboxText(formURL.GetContent())]
467 assertWithMatcher:grey_notNil()]; 502 assertWithMatcher:grey_notNil()];
468 503
469 // Go back once and verify the browser navigates to the form URL. 504 // Go back once and verify the browser navigates to the form URL.
470 [self goBack]; 505 [self goBack];
471 [[EarlGrey selectElementWithMatcher:OmniboxText(formURL.GetContent())] 506 [[EarlGrey selectElementWithMatcher:OmniboxText(formURL.GetContent())]
472 assertWithMatcher:grey_notNil()]; 507 assertWithMatcher:grey_notNil()];
473 508
474 // Go back a second time and verify the browser navigates to the first URL. 509 // Go back a second time and verify the browser navigates to the first URL.
475 [self goBack]; 510 [self goBack];
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 assertWithMatcher:grey_notNil()]; 677 assertWithMatcher:grey_notNil()];
643 678
644 // Go back and verify that the browser navigates to the original URL. 679 // Go back and verify that the browser navigates to the original URL.
645 [self goBack]; 680 [self goBack];
646 [ChromeEarlGrey waitForWebViewContainingText:"hello!"]; 681 [ChromeEarlGrey waitForWebViewContainingText:"hello!"];
647 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())] 682 [[EarlGrey selectElementWithMatcher:OmniboxText(URL.GetContent())]
648 assertWithMatcher:grey_notNil()]; 683 assertWithMatcher:grey_notNil()];
649 } 684 }
650 685
651 @end 686 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698