| 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" |
| 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 11 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 12 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 13 #import "ios/web/public/test/http_server.h" | 13 #import "ios/web/public/test/http_server.h" |
| 14 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 14 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 15 #include "ios/web/public/test/http_server_util.h" | 15 #include "ios/web/public/test/http_server_util.h" |
| 16 #include "ios/web/public/test/response_providers/data_response_provider.h" | 16 #include "ios/web/public/test/response_providers/data_response_provider.h" |
| 17 #include "ios/web/public/test/response_providers/error_page_response_provider.h" | 17 #include "ios/web/public/test/response_providers/error_page_response_provider.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/l10n/l10n_util_mac.h" | 19 #include "ui/base/l10n/l10n_util_mac.h" |
| 20 | 20 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 using chrome_test_util::OmniboxText; | 25 using chrome_test_util::OmniboxText; |
| 26 using chrome_test_util::TapWebViewElementWithId; | 26 using chrome_test_util::TapWebViewElementWithId; |
| 27 using chrome_test_util::WebViewContainingText; | 27 using chrome_test_util::WebViewContainingText; |
| 28 using chrome_test_util::WebViewNotContainingText; |
| 28 | 29 |
| 29 using web::test::HttpServer; | 30 using web::test::HttpServer; |
| 30 | 31 |
| 31 // Tests display of error pages for bad URLs. | 32 // Tests display of error pages for bad URLs. |
| 32 @interface ErrorPageTestCase : ChromeTestCase | 33 @interface ErrorPageTestCase : ChromeTestCase |
| 33 | 34 |
| 34 // Checks that the DNS error page is not visible. | 35 // Checks that the DNS error page is not visible. |
| 35 - (void)checkErrorPageIsNotVisible; | 36 - (void)checkErrorPageIsNotVisible; |
| 36 | 37 |
| 37 @end | 38 @end |
| 38 | 39 |
| 39 @implementation ErrorPageTestCase | 40 @implementation ErrorPageTestCase |
| 40 | 41 |
| 41 #pragma mark - utilities | 42 #pragma mark - utilities |
| 42 | 43 |
| 43 - (void)checkErrorPageIsNotVisible { | 44 - (void)checkErrorPageIsNotVisible { |
| 44 // Check that the webview belongs to the web controller, and that the error | 45 // Check that the webview belongs to the web controller, and that the error |
| 45 // text doesn't appear in the webview. | 46 // text doesn't appear in the webview. |
| 46 id<GREYMatcher> webViewMatcher = | 47 id<GREYMatcher> webViewMatcher = |
| 47 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); | 48 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); |
| 48 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 49 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 49 assertWithMatcher:grey_notNil()]; | 50 assertWithMatcher:grey_notNil()]; |
| 50 const std::string kError = | 51 const std::string kError = |
| 51 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); | 52 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |
| 52 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kError)] | 53 [[EarlGrey selectElementWithMatcher:WebViewNotContainingText(kError)] |
| 53 assertWithMatcher:grey_nil()]; | 54 assertWithMatcher:grey_notNil()]; |
| 54 } | 55 } |
| 55 | 56 |
| 56 #pragma mark - tests | 57 #pragma mark - tests |
| 57 | 58 |
| 58 // Tests whether the error page is displayed for a bad URL. | 59 // Tests whether the error page is displayed for a bad URL. |
| 59 - (void)testErrorPage { | 60 - (void)testErrorPage { |
| 60 std::unique_ptr<web::DataResponseProvider> provider( | 61 std::unique_ptr<web::DataResponseProvider> provider( |
| 61 new ErrorPageResponseProvider()); | 62 new ErrorPageResponseProvider()); |
| 62 web::test::SetUpHttpServer(std::move(provider)); | 63 web::test::SetUpHttpServer(std::move(provider)); |
| 63 | 64 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 [ChromeEarlGrey loadURL:URL]; | 164 [ChromeEarlGrey loadURL:URL]; |
| 164 TapWebViewElementWithId(kButtonId); | 165 TapWebViewElementWithId(kButtonId); |
| 165 // Check that the timer has completed. | 166 // Check that the timer has completed. |
| 166 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)] | 167 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)] |
| 167 assertWithMatcher:grey_notNil()]; | 168 assertWithMatcher:grey_notNil()]; |
| 168 // DNS error page should still not appear. | 169 // DNS error page should still not appear. |
| 169 [self checkErrorPageIsNotVisible]; | 170 [self checkErrorPageIsNotVisible]; |
| 170 } | 171 } |
| 171 | 172 |
| 172 @end | 173 @end |
| OLD | NEW |