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

Side by Side Diff: ios/chrome/browser/ui/error_page_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: mistake Created 3 years, 11 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
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 <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 #include "ios/chrome/test/app/web_view_interaction_test_util.h" 8 #include "ios/chrome/test/app/web_view_interaction_test_util.h"
9 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 9 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
10 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 10 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
11 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 11 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
12 #import "ios/web/public/test/http_server.h" 12 #import "ios/web/public/test/http_server.h"
13 #include "ios/web/public/test/http_server_util.h" 13 #include "ios/web/public/test/http_server_util.h"
14 #include "ios/web/public/test/response_providers/data_response_provider.h" 14 #include "ios/web/public/test/response_providers/data_response_provider.h"
15 #include "ios/web/public/test/response_providers/error_page_response_provider.h" 15 #include "ios/web/public/test/response_providers/error_page_response_provider.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/l10n/l10n_util_mac.h" 17 #include "ui/base/l10n/l10n_util_mac.h"
18 18
19 using chrome_test_util::omniboxText; 19 using chrome_test_util::OmniboxText;
20 using chrome_test_util::staticHtmlViewContainingText; 20 using chrome_test_util::StaticHtmlViewContainingText;
21 using chrome_test_util::TapWebViewElementWithId; 21 using chrome_test_util::TapWebViewElementWithId;
22 using chrome_test_util::webViewBelongingToWebController; 22 using chrome_test_util::WebViewBelongingToWebController;
Eugene But (OOO till 7-30) 2017/01/23 19:39:03 Please use WebViewInWebState instead.
baxley 2017/01/24 22:18:49 Done.
23 using chrome_test_util::webViewContainingText; 23 using chrome_test_util::WebViewContainingText;
24 24
25 using web::test::HttpServer; 25 using web::test::HttpServer;
26 26
27 // Tests display of error pages for bad URLs. 27 // Tests display of error pages for bad URLs.
28 @interface ErrorPageTestCase : ChromeTestCase 28 @interface ErrorPageTestCase : ChromeTestCase
29 29
30 // Checks that the DNS error page is visible. 30 // Checks that the DNS error page is visible.
31 - (void)checkErrorPageIsVisible; 31 - (void)checkErrorPageIsVisible;
32 32
33 // Checks that the DNS error page is not visible. 33 // Checks that the DNS error page is not visible.
34 - (void)checkErrorPageIsNotVisible; 34 - (void)checkErrorPageIsNotVisible;
35 35
36 @end 36 @end
37 37
38 @implementation ErrorPageTestCase 38 @implementation ErrorPageTestCase
39 39
40 #pragma mark - utilities 40 #pragma mark - utilities
41 41
42 // TODO(crbug.com/638674): Evaluate if this can move to shared code. 42 // TODO(crbug.com/638674): Evaluate if this can move to shared code.
43 - (void)checkErrorPageIsVisible { 43 - (void)checkErrorPageIsVisible {
44 // The DNS error page is static HTML content, so it isn't part of the webview 44 // The DNS error page is static HTML content, so it isn't part of the webview
45 // owned by the webstate. 45 // owned by the webstate.
46 [[EarlGrey selectElementWithMatcher:webViewBelongingToWebController()] 46 [[EarlGrey selectElementWithMatcher:WebViewBelongingToWebController()]
47 assertWithMatcher:grey_nil()]; 47 assertWithMatcher:grey_nil()];
48 NSString* const kError = 48 NSString* const kError =
49 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); 49 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
50 [[EarlGrey selectElementWithMatcher:staticHtmlViewContainingText(kError)] 50 [[EarlGrey selectElementWithMatcher:StaticHtmlViewContainingText(kError)]
51 assertWithMatcher:grey_notNil()]; 51 assertWithMatcher:grey_notNil()];
52 } 52 }
53 53
54 - (void)checkErrorPageIsNotVisible { 54 - (void)checkErrorPageIsNotVisible {
55 // Check that the webview belongs to the web controller, and that the error 55 // Check that the webview belongs to the web controller, and that the error
56 // text doesn't appear in the webview. 56 // text doesn't appear in the webview.
57 [[EarlGrey selectElementWithMatcher:webViewBelongingToWebController()] 57 [[EarlGrey selectElementWithMatcher:WebViewBelongingToWebController()]
58 assertWithMatcher:grey_notNil()]; 58 assertWithMatcher:grey_notNil()];
59 const std::string kError = 59 const std::string kError =
60 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); 60 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
61 [[EarlGrey selectElementWithMatcher:webViewContainingText(kError)] 61 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kError)]
62 assertWithMatcher:grey_nil()]; 62 assertWithMatcher:grey_nil()];
63 } 63 }
64 64
65 #pragma mark - tests 65 #pragma mark - tests
66 66
67 // Tests whether the error page is displayed for a bad URL. 67 // Tests whether the error page is displayed for a bad URL.
68 - (void)testErrorPage { 68 - (void)testErrorPage {
69 std::unique_ptr<web::DataResponseProvider> provider( 69 std::unique_ptr<web::DataResponseProvider> provider(
70 new ErrorPageResponseProvider()); 70 new ErrorPageResponseProvider());
71 web::test::SetUpHttpServer(std::move(provider)); 71 web::test::SetUpHttpServer(std::move(provider));
72 72
73 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()]; 73 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()];
74 74
75 [self checkErrorPageIsVisible]; 75 [self checkErrorPageIsVisible];
76 } 76 }
77 77
78 // Tests whether the error page is displayed if it is behind a redirect. 78 // Tests whether the error page is displayed if it is behind a redirect.
79 - (void)testErrorPageRedirect { 79 - (void)testErrorPageRedirect {
80 std::unique_ptr<web::DataResponseProvider> provider( 80 std::unique_ptr<web::DataResponseProvider> provider(
81 new ErrorPageResponseProvider()); 81 new ErrorPageResponseProvider());
82 web::test::SetUpHttpServer(std::move(provider)); 82 web::test::SetUpHttpServer(std::move(provider));
83 83
84 // Load a URL that redirects to the DNS-failing URL. 84 // Load a URL that redirects to the DNS-failing URL.
85 [ChromeEarlGrey 85 [ChromeEarlGrey
86 loadURL:ErrorPageResponseProvider::GetRedirectToDnsFailureUrl()]; 86 loadURL:ErrorPageResponseProvider::GetRedirectToDnsFailureUrl()];
87 87
88 // Verify that the redirect occurred before checking for the DNS error. 88 // Verify that the redirect occurred before checking for the DNS error.
89 const std::string& redirectedURL = 89 const std::string& redirectedURL =
90 ErrorPageResponseProvider::GetDnsFailureUrl().GetContent(); 90 ErrorPageResponseProvider::GetDnsFailureUrl().GetContent();
91 [[EarlGrey selectElementWithMatcher:omniboxText(redirectedURL)] 91 [[EarlGrey selectElementWithMatcher:OmniboxText(redirectedURL)]
92 assertWithMatcher:grey_notNil()]; 92 assertWithMatcher:grey_notNil()];
93 93
94 [self checkErrorPageIsVisible]; 94 [self checkErrorPageIsVisible];
95 } 95 }
96 96
97 // Tests that the error page is not displayed if the bad URL is in a <iframe> 97 // Tests that the error page is not displayed if the bad URL is in a <iframe>
98 // tag. 98 // tag.
99 - (void)testErrorPageInIFrame { 99 - (void)testErrorPageInIFrame {
100 std::map<GURL, std::string> responses; 100 std::map<GURL, std::string> responses;
101 const GURL URL = HttpServer::MakeUrl("http://browsingErrorPageInIFrame"); 101 const GURL URL = HttpServer::MakeUrl("http://browsingErrorPageInIFrame");
(...skipping 26 matching lines...) Expand all
128 "<script>setTimeout(" + "function() { document.body.innerHTML+='<p>" + 128 "<script>setTimeout(" + "function() { document.body.innerHTML+='<p>" +
129 kTimerCompleted + "</p>" + "<iframe src=\"" + 129 kTimerCompleted + "</p>" + "<iframe src=\"" +
130 ErrorPageResponseProvider::GetDnsFailureUrl().spec() + 130 ErrorPageResponseProvider::GetDnsFailureUrl().spec() +
131 "\"></iframe>'}, 1000);" + "</script>"; 131 "\"></iframe>'}, 1000);" + "</script>";
132 std::unique_ptr<web::DataResponseProvider> provider( 132 std::unique_ptr<web::DataResponseProvider> provider(
133 new ErrorPageResponseProvider(responses)); 133 new ErrorPageResponseProvider(responses));
134 web::test::SetUpHttpServer(std::move(provider)); 134 web::test::SetUpHttpServer(std::move(provider));
135 135
136 [ChromeEarlGrey loadURL:URL]; 136 [ChromeEarlGrey loadURL:URL];
137 // Check that the timer has completed. 137 // Check that the timer has completed.
138 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTimerCompleted)] 138 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)]
139 assertWithMatcher:grey_notNil()]; 139 assertWithMatcher:grey_notNil()];
140 // DNS error page should still not appear. 140 // DNS error page should still not appear.
141 [self checkErrorPageIsNotVisible]; 141 [self checkErrorPageIsNotVisible];
142 } 142 }
143 143
144 // Tests that the error page is not displayed if the navigation was not 144 // Tests that the error page is not displayed if the navigation was not
145 // user-initiated. 145 // user-initiated.
146 - (void)testErrorPageNoUserInteraction { 146 - (void)testErrorPageNoUserInteraction {
147 // Create map of canned responses and set up the test HTML server. 147 // Create map of canned responses and set up the test HTML server.
148 std::map<GURL, std::string> responses; 148 std::map<GURL, std::string> responses;
(...skipping 16 matching lines...) Expand all
165 "</p><iframe src=" + 165 "</p><iframe src=" +
166 ErrorPageResponseProvider::GetDnsFailureUrl().spec() + 166 ErrorPageResponseProvider::GetDnsFailureUrl().spec() +
167 ">\"}, " + kTimeoutMs + ");'></form>"; 167 ">\"}, " + kTimeoutMs + ");'></form>";
168 std::unique_ptr<web::DataResponseProvider> provider( 168 std::unique_ptr<web::DataResponseProvider> provider(
169 new ErrorPageResponseProvider(responses)); 169 new ErrorPageResponseProvider(responses));
170 web::test::SetUpHttpServer(std::move(provider)); 170 web::test::SetUpHttpServer(std::move(provider));
171 171
172 [ChromeEarlGrey loadURL:URL]; 172 [ChromeEarlGrey loadURL:URL];
173 TapWebViewElementWithId(kButtonId); 173 TapWebViewElementWithId(kButtonId);
174 // Check that the timer has completed. 174 // Check that the timer has completed.
175 [[EarlGrey selectElementWithMatcher:webViewContainingText(kTimerCompleted)] 175 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)]
176 assertWithMatcher:grey_notNil()]; 176 assertWithMatcher:grey_notNil()];
177 // DNS error page should still not appear. 177 // DNS error page should still not appear.
178 [self checkErrorPageIsNotVisible]; 178 [self checkErrorPageIsNotVisible];
179 } 179 }
180 180
181 @end 181 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698