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

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

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting 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 <XCTest/XCTest.h> 5 #import <XCTest/XCTest.h>
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "components/strings/grit/components_strings.h" 10 #include "components/strings/grit/components_strings.h"
(...skipping 12 matching lines...) Expand all
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "url/scheme_host_port.h" 24 #include "url/scheme_host_port.h"
25 25
26 #if !defined(__has_feature) || !__has_feature(objc_arc) 26 #if !defined(__has_feature) || !__has_feature(objc_arc)
27 #error "This file requires ARC support." 27 #error "This file requires ARC support."
28 #endif 28 #endif
29 29
30 using chrome_test_util::BackButton; 30 using chrome_test_util::BackButton;
31 using chrome_test_util::ForwardButton; 31 using chrome_test_util::ForwardButton;
32 using chrome_test_util::TapWebViewElementWithId; 32 using chrome_test_util::TapWebViewElementWithId;
33 using chrome_test_util::WebViewContainingText;
34 33
35 namespace { 34 namespace {
36 35
37 // Loads WebUI page with given |host|. 36 // Loads WebUI page with given |host|.
38 void LoadWebUIUrl(const std::string& host) { 37 void LoadWebUIUrl(const std::string& host) {
39 GURL web_ui_url(url::SchemeHostPort(kChromeUIScheme, host, 0).Serialize()); 38 GURL web_ui_url(url::SchemeHostPort(kChromeUIScheme, host, 0).Serialize());
40 [ChromeEarlGrey loadURL:web_ui_url]; 39 [ChromeEarlGrey loadURL:web_ui_url];
41 } 40 }
42 41
43 // Adds wait for omnibox text matcher so that omnibox text can be updated. 42 // Adds wait for omnibox text matcher so that omnibox text can be updated.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 @end 77 @end
79 78
80 @implementation WebUITestCase 79 @implementation WebUITestCase
81 80
82 // Tests that chrome://version renders and contains correct version number and 81 // Tests that chrome://version renders and contains correct version number and
83 // user agent string. 82 // user agent string.
84 - (void)testVersion { 83 - (void)testVersion {
85 LoadWebUIUrl(kChromeUIVersionHost); 84 LoadWebUIUrl(kChromeUIVersionHost);
86 85
87 // Verify that app version is present on the page. 86 // Verify that app version is present on the page.
88 const std::string version = version_info::GetVersionNumber(); 87 NSString* version = base::SysUTF8ToNSString(version_info::GetVersionNumber());
89 [[EarlGrey selectElementWithMatcher:WebViewContainingText(version)] 88 [ChromeEarlGrey waitForWebViewContainingText:version];
90 assertWithMatcher:grey_notNil()];
91 89
92 // Verify that mobile User Agent string is present on the page. 90 // Verify that mobile User Agent string is present on the page.
93 const std::string userAgent = 91 NSString* userAgent = base::SysUTF8ToNSString(
94 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE); 92 web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE));
95 [[EarlGrey selectElementWithMatcher:WebViewContainingText(userAgent)] 93 [ChromeEarlGrey waitForWebViewContainingText:userAgent];
96 assertWithMatcher:grey_notNil()];
97 } 94 }
98 95
99 // Tests that chrome://physical-web renders and the page title is present. 96 // Tests that chrome://physical-web renders and the page title is present.
100 - (void)testPhysicalWeb { 97 - (void)testPhysicalWeb {
101 // Enable the Physical Web via Chrome variation. 98 // Enable the Physical Web via Chrome variation.
102 base::FieldTrialList::CreateFieldTrial("PhysicalWebEnabled", "Enabled"); 99 base::FieldTrialList::CreateFieldTrial("PhysicalWebEnabled", "Enabled");
103 100
104 LoadWebUIUrl(kChromeUIPhysicalWebHost); 101 LoadWebUIUrl(kChromeUIPhysicalWebHost);
105 102
106 // Verify that the title string is present on the page. 103 // Verify that the title string is present on the page.
107 std::string pageTitle = l10n_util::GetStringUTF8(IDS_PHYSICAL_WEB_UI_TITLE); 104 NSString* pageTitle = l10n_util::GetNSString(IDS_PHYSICAL_WEB_UI_TITLE);
108 [[EarlGrey selectElementWithMatcher:WebViewContainingText(pageTitle)] 105 [ChromeEarlGrey waitForWebViewContainingText:pageTitle];
109 assertWithMatcher:grey_notNil()];
110 } 106 }
111 107
112 // Tests that clicking on a link for a native page from chrome://chrome-urls 108 // Tests that clicking on a link for a native page from chrome://chrome-urls
113 // navigates to that page. 109 // navigates to that page.
114 - (void)testChromeURLNavigateToNativePage { 110 - (void)testChromeURLNavigateToNativePage {
115 LoadWebUIUrl(kChromeUIChromeURLsHost); 111 LoadWebUIUrl(kChromeUIChromeURLsHost);
116 112
117 // Tap on chrome://terms link on the page. 113 // Tap on chrome://terms link on the page.
118 chrome_test_util::TapWebViewElementWithId(kChromeUITermsHost); 114 chrome_test_util::TapWebViewElementWithId(kChromeUITermsHost);
119 115
120 // Verify that the resulting page is chrome://terms. 116 // Verify that the resulting page is chrome://terms.
121 [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://terms")] 117 [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://terms")]
122 assertWithMatcher:grey_sufficientlyVisible()]; 118 assertWithMatcher:grey_sufficientlyVisible()];
123 NSString* kTermsText = @"Google Chrome Terms of Service"; 119 NSString* kTermsText = @"Google Chrome Terms of Service";
124 [ChromeEarlGrey waitForStaticHTMLViewContainingText:kTermsText]; 120 [ChromeEarlGrey waitForStaticHTMLViewContainingText:kTermsText];
125 } 121 }
126 122
127 // Tests that back navigation functions properly after navigation via anchor 123 // Tests that back navigation functions properly after navigation via anchor
128 // click. 124 // click.
129 - (void)testChromeURLBackNavigationFromAnchorClick { 125 - (void)testChromeURLBackNavigationFromAnchorClick {
130 LoadWebUIUrl(kChromeUIChromeURLsHost); 126 LoadWebUIUrl(kChromeUIChromeURLsHost);
131 127
132 // Tap on chrome://version link on the page. 128 // Tap on chrome://version link on the page.
133 chrome_test_util::TapWebViewElementWithId(kChromeUIVersionHost); 129 chrome_test_util::TapWebViewElementWithId(kChromeUIVersionHost);
134 130
135 // Verify that the resulting page is chrome://version. 131 // Verify that the resulting page is chrome://version.
136 [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://version")] 132 [[EarlGrey selectElementWithMatcher:WaitForOmniboxText("chrome://version")]
137 assertWithMatcher:grey_sufficientlyVisible()]; 133 assertWithMatcher:grey_sufficientlyVisible()];
138 const std::string kAuthorsText = "The Chromium Authors"; 134 [ChromeEarlGrey waitForWebViewContainingText:@"The Chromium Authors"];
139 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kAuthorsText)]
140 assertWithMatcher:grey_notNil()];
141 135
142 // Tap the back button in the toolbar and verify that the resulting page is 136 // Tap the back button in the toolbar and verify that the resulting page is
143 // the previously visited page chrome://chrome-urls. 137 // the previously visited page chrome://chrome-urls.
144 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; 138 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
145 [[EarlGrey 139 [[EarlGrey
146 selectElementWithMatcher:WaitForOmniboxText("chrome://chrome-urls")] 140 selectElementWithMatcher:WaitForOmniboxText("chrome://chrome-urls")]
147 assertWithMatcher:grey_sufficientlyVisible()]; 141 assertWithMatcher:grey_sufficientlyVisible()];
148 const std::string kChromeURLsText = "List of Chrome URLs"; 142 [ChromeEarlGrey waitForWebViewContainingText:@"List of Chrome URLs"];
149 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kChromeURLsText)]
150 assertWithMatcher:grey_notNil()];
151 } 143 }
152 144
153 // Tests that back and forward navigation between chrome URLs functions 145 // Tests that back and forward navigation between chrome URLs functions
154 // properly. 146 // properly.
155 - (void)testChromeURLBackAndForwardNavigation { 147 - (void)testChromeURLBackAndForwardNavigation {
156 // Navigate to the first URL chrome://version. 148 // Navigate to the first URL chrome://version.
157 LoadWebUIUrl(kChromeUIVersionHost); 149 LoadWebUIUrl(kChromeUIVersionHost);
158 150
159 // Navigate to the second URL chrome://flags. 151 // Navigate to the second URL chrome://flags.
160 LoadWebUIUrl(kChromeUIFlagsHost); 152 LoadWebUIUrl(kChromeUIFlagsHost);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 [[EarlGrey selectElementWithMatcher:WaitForOmniboxText(kChromeInvalidURL)] 203 [[EarlGrey selectElementWithMatcher:WaitForOmniboxText(kChromeInvalidURL)]
212 assertWithMatcher:grey_sufficientlyVisible()]; 204 assertWithMatcher:grey_sufficientlyVisible()];
213 NSString* kError = 205 NSString* kError =
214 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); 206 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
215 id<GREYMatcher> messageMatcher = [GREYMatchers matcherForText:kError]; 207 id<GREYMatcher> messageMatcher = [GREYMatchers matcherForText:kError];
216 [[EarlGrey selectElementWithMatcher:messageMatcher] 208 [[EarlGrey selectElementWithMatcher:messageMatcher]
217 assertWithMatcher:grey_notNil()]; 209 assertWithMatcher:grey_notNil()];
218 } 210 }
219 211
220 @end 212 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698