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 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
12 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 12 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
13 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 13 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
14 #include "ios/chrome/browser/ui/ui_util.h" | 14 #include "ios/chrome/browser/ui/ui_util.h" |
15 #import "ios/chrome/test/app/chrome_test_util.h" | 15 #import "ios/chrome/test/app/chrome_test_util.h" |
16 #include "ios/chrome/test/app/navigation_test_util.h" | 16 #include "ios/chrome/test/app/navigation_test_util.h" |
17 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 17 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
18 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 18 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
19 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 19 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
20 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 20 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
21 #import "ios/testing/wait_util.h" | 21 #import "ios/testing/wait_util.h" |
22 #import "ios/web/public/test/http_server.h" | 22 #import "ios/web/public/test/http_server.h" |
23 #import "ios/web/public/test/http_server_util.h" | 23 #import "ios/web/public/test/http_server_util.h" |
24 #include "ios/web/public/test/response_providers/data_response_provider.h" | 24 #include "ios/web/public/test/response_providers/data_response_provider.h" |
25 #include "ios/web/public/test/url_test_util.h" | 25 #include "ios/web/public/test/url_test_util.h" |
26 | 26 |
27 using chrome_test_util::OmniboxText; | |
28 using chrome_test_util::WebViewContainingText; | |
29 | |
27 namespace { | 30 namespace { |
28 | 31 |
29 // URL for a generic website in the user navigation flow. | 32 // URL for a generic website in the user navigation flow. |
30 const char kGenericUrl[] = "http://generic"; | 33 const char kGenericUrl[] = "http://generic"; |
31 | 34 |
32 // URL to print the HTTP method and the request body. | 35 // URL to print the HTTP method and the request body. |
33 const char kPrintFormDataUrl[] = "http://printFormData"; | 36 const char kPrintFormDataUrl[] = "http://printFormData"; |
34 | 37 |
35 // URL that redirects to kPrintPostData with a 302. | 38 // URL that redirects to kPrintPostData with a 302. |
36 const char kRedirectUrl[] = "http://redirect"; | 39 const char kRedirectUrl[] = "http://redirect"; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 return; | 120 return; |
118 } else if (url == TestResponseProvider::GetPrintFormDataUrl()) { | 121 } else if (url == TestResponseProvider::GetPrintFormDataUrl()) { |
119 *response_body = request.method + std::string(" ") + request.body; | 122 *response_body = request.method + std::string(" ") + request.body; |
120 return; | 123 return; |
121 } | 124 } |
122 NOTREACHED(); | 125 NOTREACHED(); |
123 } | 126 } |
124 | 127 |
125 } // namespace | 128 } // namespace |
126 | 129 |
127 using chrome_test_util::OmniboxText; | |
128 | |
129 // Tests submition of HTTP forms POST data including cases involving navigation. | 130 // Tests submition of HTTP forms POST data including cases involving navigation. |
130 @interface FormsTestCase : ChromeTestCase | 131 @interface FormsTestCase : ChromeTestCase |
131 @end | 132 @end |
132 | 133 |
133 @implementation FormsTestCase | 134 @implementation FormsTestCase |
134 | 135 |
135 // Sets up server urls and responses. | 136 // Sets up server urls and responses. |
136 - (void)setUp { | 137 - (void)setUp { |
137 [super setUp]; | 138 [super setUp]; |
138 | 139 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 // Check that the popup did not show | 340 // Check that the popup did not show |
340 id<GREYMatcher> resendWarning = | 341 id<GREYMatcher> resendWarning = |
341 chrome_test_util::ButtonWithAccessibilityLabelId( | 342 chrome_test_util::ButtonWithAccessibilityLabelId( |
342 IDS_HTTP_POST_WARNING_RESEND); | 343 IDS_HTTP_POST_WARNING_RESEND); |
343 [[EarlGrey selectElementWithMatcher:resendWarning] | 344 [[EarlGrey selectElementWithMatcher:resendWarning] |
344 assertWithMatcher:grey_nil()]; | 345 assertWithMatcher:grey_nil()]; |
345 | 346 |
346 [self waitForExpectedResponse:"GET"]; | 347 [self waitForExpectedResponse:"GET"]; |
347 } | 348 } |
348 | 349 |
350 // Tests that pressing the button on a POST-based form changes the page and that | |
351 // the back button works as expected afterwards. | |
352 - (void)testGoBackButtonAfterFormSubmission { | |
353 GURL formURL = TestResponseProvider::GetFormUrl(); | |
354 GURL destinationURL = TestResponseProvider::GetPrintFormDataUrl(); | |
355 | |
356 [ChromeEarlGrey loadURL:formURL]; | |
357 chrome_test_util::TapWebViewElementWithId(kSubmitButton); | |
358 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kExpectedPostData)] | |
gchatz
2017/04/10 18:43:23
Should this use [self waitForExpectedResponse]?
liaoyuke
2017/04/10 18:48:09
I think we should remove this method (in a separat
gchatz
2017/04/10 20:46:10
Ok sounds good
Eugene But (OOO till 7-30)
2017/04/10 20:46:45
Could you please file a bug and add a TODO for thi
| |
359 assertWithMatcher:grey_notNil()]; | |
360 [[EarlGrey selectElementWithMatcher:OmniboxText(destinationURL.GetContent())] | |
361 assertWithMatcher:grey_notNil()]; | |
362 | |
363 // Go back and verify the browser navigates to the original URL. | |
364 [self goBack]; | |
365 [[EarlGrey selectElementWithMatcher:WebViewContainingText("Unicorn")] | |
366 assertWithMatcher:grey_notNil()]; | |
367 [[EarlGrey selectElementWithMatcher:OmniboxText(formURL.GetContent())] | |
368 assertWithMatcher:grey_notNil()]; | |
369 } | |
370 | |
349 @end | 371 @end |
OLD | NEW |