| 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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 | 6 |
| 7 #include "components/strings/grit/components_strings.h" | 7 #include "components/strings/grit/components_strings.h" |
| 8 #import "ios/chrome/test/app/chrome_test_util.h" | 8 #import "ios/chrome/test/app/chrome_test_util.h" |
| 9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" | 9 #include "ios/chrome/test/app/web_view_interaction_test_util.h" |
| 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 10 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 @end | 37 @end |
| 38 | 38 |
| 39 @implementation ErrorPageTestCase | 39 @implementation ErrorPageTestCase |
| 40 | 40 |
| 41 #pragma mark - utilities | 41 #pragma mark - utilities |
| 42 | 42 |
| 43 // TODO(crbug.com/638674): Evaluate if this can move to shared code. | 43 // TODO(crbug.com/638674): Evaluate if this can move to shared code. |
| 44 - (void)checkErrorPageIsVisible { | 44 - (void)checkErrorPageIsVisible { |
| 45 // The DNS error page is static HTML content, so it isn't part of the webview | 45 // The DNS error page is static HTML content, so it isn't part of the webview |
| 46 // owned by the webstate. | 46 // owned by the webstate. |
| 47 id<GREYMatcher> webViewMatcher = | |
| 48 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); | |
| 49 [[EarlGrey selectElementWithMatcher:webViewMatcher] | |
| 50 assertWithMatcher:grey_nil()]; | |
| 51 NSString* const kError = | 47 NSString* const kError = |
| 52 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); | 48 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |
| 53 [[EarlGrey selectElementWithMatcher:StaticHtmlViewContainingText(kError)] | 49 [[EarlGrey selectElementWithMatcher:StaticHtmlViewContainingText(kError)] |
| 54 assertWithMatcher:grey_notNil()]; | 50 assertWithMatcher:grey_notNil()]; |
| 55 } | 51 } |
| 56 | 52 |
| 57 - (void)checkErrorPageIsNotVisible { | 53 - (void)checkErrorPageIsNotVisible { |
| 58 // Check that the webview belongs to the web controller, and that the error | 54 // Check that the webview belongs to the web controller, and that the error |
| 59 // text doesn't appear in the webview. | 55 // text doesn't appear in the webview. |
| 60 id<GREYMatcher> webViewMatcher = | 56 id<GREYMatcher> webViewMatcher = |
| 61 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); | 57 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); |
| 62 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 58 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 63 assertWithMatcher:grey_notNil()]; | 59 assertWithMatcher:grey_notNil()]; |
| 64 const std::string kError = | 60 const std::string kError = |
| 65 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); | 61 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |
| 66 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kError)] | 62 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kError)] |
| 67 assertWithMatcher:grey_nil()]; | 63 assertWithMatcher:grey_nil()]; |
| 68 } | 64 } |
| 69 | 65 |
| 70 #pragma mark - tests | 66 #pragma mark - tests |
| 71 | 67 |
| 72 // Tests whether the error page is displayed for a bad URL. | 68 // Tests whether the error page is displayed for a bad URL. |
| 73 // TODO(crbug.com/684987): Re-enable this test. | 69 - (void)testErrorPage { |
| 74 - (void)DISABLED_testErrorPage { | |
| 75 std::unique_ptr<web::DataResponseProvider> provider( | 70 std::unique_ptr<web::DataResponseProvider> provider( |
| 76 new ErrorPageResponseProvider()); | 71 new ErrorPageResponseProvider()); |
| 77 web::test::SetUpHttpServer(std::move(provider)); | 72 web::test::SetUpHttpServer(std::move(provider)); |
| 78 | 73 |
| 79 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()]; | 74 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()]; |
| 80 | 75 |
| 81 [self checkErrorPageIsVisible]; | 76 [self checkErrorPageIsVisible]; |
| 82 } | 77 } |
| 83 | 78 |
| 84 // Tests whether the error page is displayed if it is behind a redirect. | 79 // Tests whether the error page is displayed if it is behind a redirect. |
| 85 // TODO(crbug.com/684987): Re-enable this test. | 80 - (void)testErrorPageRedirect { |
| 86 - (void)DISABLED_testErrorPageRedirect { | |
| 87 std::unique_ptr<web::DataResponseProvider> provider( | 81 std::unique_ptr<web::DataResponseProvider> provider( |
| 88 new ErrorPageResponseProvider()); | 82 new ErrorPageResponseProvider()); |
| 89 web::test::SetUpHttpServer(std::move(provider)); | 83 web::test::SetUpHttpServer(std::move(provider)); |
| 90 | 84 |
| 91 // Load a URL that redirects to the DNS-failing URL. | 85 // Load a URL that redirects to the DNS-failing URL. |
| 92 [ChromeEarlGrey | 86 [ChromeEarlGrey |
| 93 loadURL:ErrorPageResponseProvider::GetRedirectToDnsFailureUrl()]; | 87 loadURL:ErrorPageResponseProvider::GetRedirectToDnsFailureUrl()]; |
| 94 | 88 |
| 95 // Verify that the redirect occurred before checking for the DNS error. | 89 // Verify that the redirect occurred before checking for the DNS error. |
| 96 const std::string& redirectedURL = | 90 const std::string& redirectedURL = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 [ChromeEarlGrey loadURL:URL]; | 173 [ChromeEarlGrey loadURL:URL]; |
| 180 TapWebViewElementWithId(kButtonId); | 174 TapWebViewElementWithId(kButtonId); |
| 181 // Check that the timer has completed. | 175 // Check that the timer has completed. |
| 182 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)] | 176 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)] |
| 183 assertWithMatcher:grey_notNil()]; | 177 assertWithMatcher:grey_notNil()]; |
| 184 // DNS error page should still not appear. | 178 // DNS error page should still not appear. |
| 185 [self checkErrorPageIsNotVisible]; | 179 [self checkErrorPageIsNotVisible]; |
| 186 } | 180 } |
| 187 | 181 |
| 188 @end | 182 @end |
| OLD | NEW |