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

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

Issue 2784943002: Remove matcher to wait for static HTML view. (Closed)
Patch Set: typo Created 3 years, 8 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 #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::StaticHtmlViewContainingText;
27 using chrome_test_util::TapWebViewElementWithId; 26 using chrome_test_util::TapWebViewElementWithId;
28 using chrome_test_util::WebViewContainingText; 27 using chrome_test_util::WebViewContainingText;
29 28
30 using web::test::HttpServer; 29 using web::test::HttpServer;
31 30
32 // Tests display of error pages for bad URLs. 31 // Tests display of error pages for bad URLs.
33 @interface ErrorPageTestCase : ChromeTestCase 32 @interface ErrorPageTestCase : ChromeTestCase
34 33
35 // Checks that the DNS error page is visible.
36 - (void)checkErrorPageIsVisible;
37
38 // Checks that the DNS error page is not visible. 34 // Checks that the DNS error page is not visible.
39 - (void)checkErrorPageIsNotVisible; 35 - (void)checkErrorPageIsNotVisible;
40 36
41 @end 37 @end
42 38
43 @implementation ErrorPageTestCase 39 @implementation ErrorPageTestCase
44 40
45 #pragma mark - utilities 41 #pragma mark - utilities
46 42
47 // TODO(crbug.com/638674): Evaluate if this can move to shared code.
48 - (void)checkErrorPageIsVisible {
49 // The DNS error page is static HTML content, so it isn't part of the webview
50 // owned by the webstate.
51 NSString* const kError =
52 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
53 [[EarlGrey selectElementWithMatcher:StaticHtmlViewContainingText(kError)]
54 assertWithMatcher:grey_notNil()];
55 }
56
57 - (void)checkErrorPageIsNotVisible { 43 - (void)checkErrorPageIsNotVisible {
58 // Check that the webview belongs to the web controller, and that the error 44 // Check that the webview belongs to the web controller, and that the error
59 // text doesn't appear in the webview. 45 // text doesn't appear in the webview.
60 id<GREYMatcher> webViewMatcher = 46 id<GREYMatcher> webViewMatcher =
61 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); 47 web::WebViewInWebState(chrome_test_util::GetCurrentWebState());
62 [[EarlGrey selectElementWithMatcher:webViewMatcher] 48 [[EarlGrey selectElementWithMatcher:webViewMatcher]
63 assertWithMatcher:grey_notNil()]; 49 assertWithMatcher:grey_notNil()];
64 const std::string kError = 50 const std::string kError =
65 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); 51 l10n_util::GetStringUTF8(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
66 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kError)] 52 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kError)]
67 assertWithMatcher:grey_nil()]; 53 assertWithMatcher:grey_nil()];
68 } 54 }
69 55
70 #pragma mark - tests 56 #pragma mark - tests
71 57
72 // Tests whether the error page is displayed for a bad URL. 58 // Tests whether the error page is displayed for a bad URL.
73 - (void)testErrorPage { 59 - (void)testErrorPage {
74 std::unique_ptr<web::DataResponseProvider> provider( 60 std::unique_ptr<web::DataResponseProvider> provider(
75 new ErrorPageResponseProvider()); 61 new ErrorPageResponseProvider());
76 web::test::SetUpHttpServer(std::move(provider)); 62 web::test::SetUpHttpServer(std::move(provider));
77 63
78 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()]; 64 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()];
79 65
80 [self checkErrorPageIsVisible]; 66 [ChromeEarlGrey waitForErrorPage];
81 } 67 }
82 68
83 // Tests whether the error page is displayed if it is behind a redirect. 69 // Tests whether the error page is displayed if it is behind a redirect.
84 - (void)testErrorPageRedirect { 70 - (void)testErrorPageRedirect {
85 std::unique_ptr<web::DataResponseProvider> provider( 71 std::unique_ptr<web::DataResponseProvider> provider(
86 new ErrorPageResponseProvider()); 72 new ErrorPageResponseProvider());
87 web::test::SetUpHttpServer(std::move(provider)); 73 web::test::SetUpHttpServer(std::move(provider));
88 74
89 // Load a URL that redirects to the DNS-failing URL. 75 // Load a URL that redirects to the DNS-failing URL.
90 [ChromeEarlGrey 76 [ChromeEarlGrey
91 loadURL:ErrorPageResponseProvider::GetRedirectToDnsFailureUrl()]; 77 loadURL:ErrorPageResponseProvider::GetRedirectToDnsFailureUrl()];
92 78
93 // Verify that the redirect occurred before checking for the DNS error. 79 // Verify that the redirect occurred before checking for the DNS error.
94 const std::string& redirectedURL = 80 const std::string& redirectedURL =
95 ErrorPageResponseProvider::GetDnsFailureUrl().GetContent(); 81 ErrorPageResponseProvider::GetDnsFailureUrl().GetContent();
96 [[EarlGrey selectElementWithMatcher:OmniboxText(redirectedURL)] 82 [[EarlGrey selectElementWithMatcher:OmniboxText(redirectedURL)]
97 assertWithMatcher:grey_notNil()]; 83 assertWithMatcher:grey_notNil()];
98 84
99 [self checkErrorPageIsVisible]; 85 [ChromeEarlGrey waitForErrorPage];
100 } 86 }
101 87
102 // Tests that the error page is not displayed if the bad URL is in a <iframe> 88 // Tests that the error page is not displayed if the bad URL is in a <iframe>
103 // tag. 89 // tag.
104 - (void)testErrorPageInIFrame { 90 - (void)testErrorPageInIFrame {
105 std::map<GURL, std::string> responses; 91 std::map<GURL, std::string> responses;
106 const GURL URL = HttpServer::MakeUrl("http://browsingErrorPageInIFrame"); 92 const GURL URL = HttpServer::MakeUrl("http://browsingErrorPageInIFrame");
107 // This page contains an iframe to a bad URL. 93 // This page contains an iframe to a bad URL.
108 responses[URL] = std::string("This page contains an iframe.<iframe src='") + 94 responses[URL] = std::string("This page contains an iframe.<iframe src='") +
109 ErrorPageResponseProvider::GetDnsFailureUrl().spec() + 95 ErrorPageResponseProvider::GetDnsFailureUrl().spec() +
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 [ChromeEarlGrey loadURL:URL]; 163 [ChromeEarlGrey loadURL:URL];
178 TapWebViewElementWithId(kButtonId); 164 TapWebViewElementWithId(kButtonId);
179 // Check that the timer has completed. 165 // Check that the timer has completed.
180 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)] 166 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kTimerCompleted)]
181 assertWithMatcher:grey_notNil()]; 167 assertWithMatcher:grey_notNil()];
182 // DNS error page should still not appear. 168 // DNS error page should still not appear.
183 [self checkErrorPageIsNotVisible]; 169 [self checkErrorPageIsNotVisible];
184 } 170 }
185 171
186 @end 172 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698