Chromium Code Reviews| Index: ios/chrome/browser/web/browsing_egtest.mm |
| diff --git a/ios/chrome/browser/web/browsing_egtest.mm b/ios/chrome/browser/web/browsing_egtest.mm |
| index ac51f9bc840fb67d3533341e4f40865f76fa4d99..6f9a75a3821212634e639116dbda654cb128af0b 100644 |
| --- a/ios/chrome/browser/web/browsing_egtest.mm |
| +++ b/ios/chrome/browser/web/browsing_egtest.mm |
| @@ -45,6 +45,8 @@ namespace { |
| // URL used for the reload test. |
| const char kReloadTestUrl[] = "http://mock/reloadTest"; |
| +const char kFormPageUrl[] = "http://form/"; |
| +const char kFirstPageUrl[] = "http://first/"; |
| // Returns the number of serviced requests in HTTP body. |
| class ReloadResponseProvider : public web::DataResponseProvider { |
| @@ -78,6 +80,43 @@ class ReloadResponseProvider : public web::DataResponseProvider { |
| int request_number_; // Count of requests received by the response provider. |
| }; |
| +// A ResponseProvider that provides post form on the same page. |
| +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
|
| + public: |
| + // URLs used for the post form test. |
| + static GURL GetFirstPageUrl() { |
| + return web::test::HttpServer::MakeUrl(kFirstPageUrl); |
| + } |
| + static GURL GetFormPageUrl() { |
| + return web::test::HttpServer::MakeUrl(kFormPageUrl); |
| + } |
| + |
| + bool CanHandleRequest(const Request& request) override { |
| + return request.url == GetFormPageUrl() || request.url == GetFirstPageUrl(); |
| + } |
| + void GetResponseHeadersAndBody( |
| + const Request& request, |
| + scoped_refptr<net::HttpResponseHeaders>* headers, |
| + std::string* response_body) override { |
| + const GURL& url = request.url; |
| + *headers = web::ResponseProvider::GetDefaultResponseHeaders(); |
| + if (url == GetFirstPageUrl()) { |
| + *response_body = "foo"; |
| + return; |
| + } else if (url == GetFormPageUrl()) { |
| + if (request.method == "POST") { |
| + *response_body = request.method + std::string(" ") + request.body; |
| + } else { |
| + *response_body = |
| + "<form method='post'>" |
| + "<input value='button' type='submit' id='button'></form>"; |
| + } |
| + return; |
| + } |
| + NOTREACHED(); |
| + } |
| +}; |
| + |
| // ScopedBlockPopupsPref modifies the block popups preference and resets the |
| // preference to its original value when this object goes out of scope. |
| // TODO(crbug.com/638674): Evaluate if this can move to shared code |
| @@ -436,7 +475,7 @@ id<GREYMatcher> GoButtonMatcher() { |
| } |
| // Tests that pressing the button on a POST-based form with same-page action |
| -// does not change the page and that the back button works as expected |
| +// does not change the page URL and that the back button works as expected |
| // afterwards. |
| - (void)testBrowsingPostToSamePage { |
| // TODO(crbug.com/714303): Re-enable this test on devices. |
| @@ -444,17 +483,12 @@ id<GREYMatcher> GoButtonMatcher() { |
| EARL_GREY_TEST_DISABLED(@"Test disabled on device."); |
| #endif |
| - // Create map of canned responses and set up the test HTML server. |
| - std::map<GURL, std::string> responses; |
| - const GURL firstURL = web::test::HttpServer::MakeUrl("http://first"); |
| - const GURL formURL = web::test::HttpServer::MakeUrl("http://form"); |
| - // This is just a page with some text. |
| - responses[firstURL] = "foo"; |
| - // This is a page with at button that posts to the current URL. |
| - responses[formURL] = |
| - "<form method='post'>" |
| - "<input value='button' type='submit' id='button'></form>"; |
| - web::test::SetUpSimpleHttpServer(responses); |
| + // Set up test HTTP server responses. |
| + std::unique_ptr<web::DataResponseProvider> provider( |
| + new TestPostFormResponseProvider()); |
| + web::test::SetUpHttpServer(std::move(provider)); |
| + const GURL firstURL = TestPostFormResponseProvider::GetFirstPageUrl(); |
| + const GURL formURL = TestPostFormResponseProvider::GetFormPageUrl(); |
| // Open the first URL so it's in history. |
| [ChromeEarlGrey loadURL:firstURL]; |
| @@ -463,6 +497,7 @@ id<GREYMatcher> GoButtonMatcher() { |
| // the expected URL. |
| [ChromeEarlGrey loadURL:formURL]; |
| chrome_test_util::TapWebViewElementWithId("button"); |
| + [ChromeEarlGrey waitForWebViewContainingText:"POST"]; |
| [[EarlGrey selectElementWithMatcher:OmniboxText(formURL.GetContent())] |
| assertWithMatcher:grey_notNil()]; |