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

Side by Side Diff: ios/chrome/browser/ui/webui/web_ui_egtest.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <XCTest/XCTest.h>
6
7 #include "base/mac/foundation_util.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "components/strings/grit/components_strings.h"
11 #include "components/version_info/version_info.h"
12 #include "ios/chrome/browser/chrome_url_constants.h"
13 #include "ios/chrome/browser/experimental_flags.h"
14 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h"
15 #include "ios/chrome/test/app/navigation_test_util.h"
16 #include "ios/chrome/test/app/web_view_interaction_test_util.h"
17 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
18 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
19 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
20 #import "ios/testing/wait_util.h"
21 #import "ios/web/public/web_client.h"
22 #include "ui/base/device_form_factor.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "url/scheme_host_port.h"
25
26 using chrome_test_util::TapWebViewElementWithId;
27 using chrome_test_util::webViewContainingText;
28 using chrome_test_util::staticHtmlViewContainingText;
29
30 namespace {
31
32 // Loads WebUI page with given |host|.
33 void LoadWebUIUrl(const std::string& host) {
34 GURL web_ui_url(url::SchemeHostPort(kChromeUIScheme, host, 0).Serialize());
35 [ChromeEarlGrey loadURL:web_ui_url];
36 }
37
38 // Matcher for the navigate backward button.
39 id<GREYMatcher> backButton() {
40 return chrome_test_util::buttonWithAccessibilityLabelId(IDS_ACCNAME_BACK);
41 }
42
43 // Matcher for the navigate forward button.
44 id<GREYMatcher> forwardButton() {
45 return chrome_test_util::buttonWithAccessibilityLabelId(IDS_ACCNAME_FORWARD);
46 }
47
48 // Adds wait for omnibox text matcher so that omnibox text can be updated.
49 // TODO(crbug.com/642207): This method has to be unified with the omniboxText
50 // matcher or resides in the same location with the omniboxText matcher.
51 id<GREYMatcher> waitForOmniboxText(std::string text) {
52 MatchesBlock matches = ^BOOL(UIView* view) {
53 if (![view isKindOfClass:[OmniboxTextFieldIOS class]]) {
54 return NO;
55 }
56 OmniboxTextFieldIOS* omnibox =
57 base::mac::ObjCCast<OmniboxTextFieldIOS>(view);
58 GREYAssert(testing::WaitUntilConditionOrTimeout(
59 testing::kWaitForUIElementTimeout,
60 ^{
61 return base::SysNSStringToUTF8(omnibox.text) == text;
62 }),
63 @"Omnibox did not contain %@", base::SysUTF8ToNSString(text));
64 return YES;
65 };
66
67 DescribeToBlock describe = ^(id<GREYDescription> description) {
68 [description appendText:@"omnibox text "];
69 [description appendText:base::SysUTF8ToNSString(text)];
70 };
71
72 return grey_allOf(chrome_test_util::omnibox(),
73 [[[GREYElementMatcherBlock alloc]
74 initWithMatchesBlock:matches
75 descriptionBlock:describe] autorelease],
76 nil);
77 }
78
79 } // namespace
80
81 // Test case for chrome://* WebUI pages.
82 @interface WebUITestCase : ChromeTestCase
83 @end
84
85 @implementation WebUITestCase
86
87 // Tests that chrome://version renders and contains correct version number and
88 // user agent string.
89 - (void)testVersion {
90 LoadWebUIUrl(kChromeUIVersionHost);
91
92 // Verify that app version is present on the page.
93 const std::string version = version_info::GetVersionNumber();
94 [[EarlGrey selectElementWithMatcher:webViewContainingText(version)]
95 assertWithMatcher:grey_notNil()];
96
97 // Verify that mobile User Agent string is present on the page.
98 const bool isDesktopUA = false;
99 const std::string userAgent = web::GetWebClient()->GetUserAgent(isDesktopUA);
100 [[EarlGrey selectElementWithMatcher:webViewContainingText(userAgent)]
101 assertWithMatcher:grey_notNil()];
102 }
103
104 // Tests that chrome://physical-web renders and the page title is present.
105 - (void)testPhysicalWeb {
106 // Enable the Physical Web via Chrome variation.
107 base::FieldTrialList::CreateFieldTrial("PhysicalWebEnabled", "Enabled");
108
109 LoadWebUIUrl(kChromeUIPhysicalWebHost);
110
111 // Verify that the title string is present on the page.
112 std::string pageTitle = l10n_util::GetStringUTF8(IDS_PHYSICAL_WEB_UI_TITLE);
113 [[EarlGrey selectElementWithMatcher:webViewContainingText(pageTitle)]
114 assertWithMatcher:grey_notNil()];
115 }
116
117 // Tests that clicking on a link for a native page from chrome://chrome-urls
118 // navigates to that page.
119 - (void)testChromeURLNavigateToNativePage {
120 LoadWebUIUrl(kChromeUIChromeURLsHost);
121
122 // Tap on chrome://terms link on the page.
123 chrome_test_util::TapWebViewElementWithId(kChromeUITermsHost);
124
125 // Verify that the resulting page is chrome://terms.
126 [[EarlGrey selectElementWithMatcher:waitForOmniboxText("chrome://terms")]
127 assertWithMatcher:grey_sufficientlyVisible()];
128 NSString* kTermsText = @"Google Chrome Terms of Service";
129 [[EarlGrey selectElementWithMatcher:staticHtmlViewContainingText(kTermsText)]
130 assertWithMatcher:grey_notNil()];
131 }
132
133 // Tests that back navigation functions properly after navigation via anchor
134 // click.
135 - (void)testChromeURLBackNavigationFromAnchorClick {
136 LoadWebUIUrl(kChromeUIChromeURLsHost);
137
138 // Tap on chrome://version link on the page.
139 chrome_test_util::TapWebViewElementWithId(kChromeUIVersionHost);
140
141 // Verify that the resulting page is chrome://version.
142 [[EarlGrey selectElementWithMatcher:waitForOmniboxText("chrome://version")]
143 assertWithMatcher:grey_sufficientlyVisible()];
144 const std::string kAuthorsText = "The Chromium Authors";
145 [[EarlGrey selectElementWithMatcher:webViewContainingText(kAuthorsText)]
146 assertWithMatcher:grey_notNil()];
147
148 // Tap the back button in the toolbar and verify that the resulting page is
149 // the previously visited page chrome://chrome-urls.
150 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()];
151 [[EarlGrey
152 selectElementWithMatcher:waitForOmniboxText("chrome://chrome-urls")]
153 assertWithMatcher:grey_sufficientlyVisible()];
154 const std::string kChromeURLsText = "List of Chrome URLs";
155 [[EarlGrey selectElementWithMatcher:webViewContainingText(kChromeURLsText)]
156 assertWithMatcher:grey_notNil()];
157 }
158
159 // Tests that back and forward navigation between chrome URLs functions
160 // properly.
161 - (void)testChromeURLBackAndForwardNavigation {
162 // Navigate to the first URL chrome://version.
163 LoadWebUIUrl(kChromeUIVersionHost);
164
165 // Navigate to the second URL chrome://flags.
166 LoadWebUIUrl(kChromeUIFlagsHost);
167
168 // Tap the back button in the toolbar and verify that the resulting page's URL
169 // corresponds to the first URL chrome://version that was loaded.
170 [[EarlGrey selectElementWithMatcher:backButton()] performAction:grey_tap()];
171 [[EarlGrey selectElementWithMatcher:waitForOmniboxText("chrome://version")]
172 assertWithMatcher:grey_sufficientlyVisible()];
173
174 // Tap the forward button in the toolbar and verify that the resulting page's
175 // URL corresponds the second URL chrome://flags that was loaded.
176 [[EarlGrey selectElementWithMatcher:forwardButton()]
177 performAction:grey_tap()];
178 [[EarlGrey selectElementWithMatcher:waitForOmniboxText("chrome://flags")]
179 assertWithMatcher:grey_sufficientlyVisible()];
180 }
181
182 // Tests that all URLs on chrome://chrome-urls page load without error.
183 - (void)testChromeURLsLoadWithoutError {
184 // Load WebUI pages and verify they load without any error.
185 for (size_t i = 0; i < kNumberOfChromeHostURLs; ++i) {
186 const char* host = kChromeHostURLs[i];
187 // Exclude non-WebUI pages, as they do not go through a "loading" phase as
188 // expected in LoadWebUIUrl.
189 if (host == kChromeUIBookmarksHost || host == kChromeUINewTabHost ||
190 host == kChromeUITermsHost) {
191 continue;
192 }
193 if (host == kChromeUIPhysicalWebHost &&
194 !experimental_flags::IsPhysicalWebEnabled()) {
195 continue;
196 }
197 LoadWebUIUrl(host);
198 const std::string chrome_url_path =
199 url::SchemeHostPort(kChromeUIScheme, kChromeHostURLs[i], 0).Serialize();
200 [[EarlGrey selectElementWithMatcher:waitForOmniboxText(chrome_url_path)]
201 assertWithMatcher:grey_sufficientlyVisible()];
202 }
203 // Load chrome://terms differently since it is a Native page and is never in
204 // the "loading" phase.
205 chrome_test_util::LoadUrl(GURL(kChromeUITermsURL));
206 [[EarlGrey selectElementWithMatcher:waitForOmniboxText("chrome://terms")]
207 assertWithMatcher:grey_sufficientlyVisible()];
208 }
209
210 // Tests that loading an invalid Chrome URL results in an error page.
211 - (void)testChromeURLInvalid {
212 // Navigate to the native error page chrome://invalidchromeurl.
213 const std::string kChromeInvalidURL = "chrome://invalidchromeurl";
214 chrome_test_util::LoadUrl(GURL(kChromeInvalidURL));
215
216 // Verify that the resulting page is an error page.
217 [[EarlGrey selectElementWithMatcher:waitForOmniboxText(kChromeInvalidURL)]
218 assertWithMatcher:grey_sufficientlyVisible()];
219 NSString* kError =
220 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
221 id<GREYMatcher> messageMatcher = [GREYMatchers matcherForText:kError];
222 [[EarlGrey selectElementWithMatcher:messageMatcher]
223 assertWithMatcher:grey_notNil()];
224 }
225
226 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/signin_internals_ui_ios.cc ('k') | ios/chrome/browser/url_opening.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698