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

Side by Side Diff: ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm

Issue 2789433006: Implement request mobile site. (Closed)
Patch Set: Address self review comments 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 #import <XCTest/XCTest.h> 6 #import <XCTest/XCTest.h>
7 7
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/ui/chrome_web_view_factory.h" 10 #import "ios/chrome/browser/ui/chrome_web_view_factory.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 } 59 }
60 }; 60 };
61 61
62 // Matcher for the button to find in page. 62 // Matcher for the button to find in page.
63 id<GREYMatcher> FindInPageButton() { 63 id<GREYMatcher> FindInPageButton() {
64 return chrome_test_util::ButtonWithAccessibilityLabel( 64 return chrome_test_util::ButtonWithAccessibilityLabel(
65 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)); 65 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE));
66 } 66 }
67 67
68 // Matcher for the button to request desktop version. 68 // Matcher for the button to request desktop site.
69 id<GREYMatcher> RequestDesktopButton() { 69 id<GREYMatcher> RequestDesktopButton() {
70 return grey_accessibilityID(kToolsMenuRequestDesktopId); 70 return grey_accessibilityID(kToolsMenuRequestDesktopId);
71 } 71 }
72 72
73 // Matcher for the button to request mobile site.
74 id<GREYMatcher> RequestMobileButton() {
75 return grey_accessibilityID(kToolsMenuRequestMobileId);
76 }
77
78 // Matcher for the button to close the tools menu.
79 id<GREYMatcher> CloseToolsMenuButton() {
80 NSString* closeMenuButtonText =
81 l10n_util::GetNSString(IDS_IOS_TOOLBAR_CLOSE_MENU);
82 return grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
83 grey_accessibilityLabel(closeMenuButtonText), nil);
84 }
85
73 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf"; 86 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
87 const char kUserAgentTestURL[] =
88 "http://ios/testing/data/http_server_files/user_agent_test_page.html";
89 const char kMobileSiteLabel[] = "Mobile";
90 const char kDesktopSiteLabel[] = "Desktop";
74 91
75 } // namespace 92 } // namespace
76 93
77 // Tests for the tools popup menu. 94 // Tests for the tools popup menu.
78 @interface ToolsPopupMenuTestCase : ChromeTestCase 95 @interface ToolsPopupMenuTestCase : ChromeTestCase
79 - (void)verifyMobileAndDesktopVersions:(const GURL&)url;
80 @end 96 @end
81 97
82 @implementation ToolsPopupMenuTestCase 98 @implementation ToolsPopupMenuTestCase
83 99
84 // Verify that requesting desktop and mobile versions works.
85 - (void)verifyMobileAndDesktopVersions:(const GURL&)url {
86 NSString* const kMobileSiteLabel = @"Mobile";
87 NSString* const kDesktopSiteLabel = @"Desktop";
88
89 [ChromeEarlGrey loadURL:url];
90
91 // Verify initial reception of the mobile site.
92 [[EarlGrey
93 selectElementWithMatcher:chrome_test_util::WebViewContainingText(
94 base::SysNSStringToUTF8(kMobileSiteLabel))]
95 assertWithMatcher:grey_notNil()];
96
97 // Request and verify reception of the desktop site.
98 [ChromeEarlGreyUI openToolsMenu];
99 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
100 performAction:grey_tap()];
101 [[EarlGrey
102 selectElementWithMatcher:chrome_test_util::WebViewContainingText(
103 base::SysNSStringToUTF8(kDesktopSiteLabel))]
104 assertWithMatcher:grey_notNil()];
105
106 // Verify that going back returns to the mobile site.
107 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
108 performAction:grey_tap()];
109 [[EarlGrey
110 selectElementWithMatcher:chrome_test_util::WebViewContainingText(
111 base::SysNSStringToUTF8(kMobileSiteLabel))]
112 assertWithMatcher:grey_notNil()];
113 }
114
115 // Tests that the menu is closed when tapping the close button. 100 // Tests that the menu is closed when tapping the close button.
116 - (void)testOpenAndCloseToolsMenu { 101 - (void)testOpenAndCloseToolsMenu {
117 [ChromeEarlGreyUI openToolsMenu]; 102 [ChromeEarlGreyUI openToolsMenu];
118 103
119 if (!IsCompact()) { 104 if (!IsCompact()) {
120 [[EarlGrey 105 [[EarlGrey
121 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( 106 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
122 IDS_IOS_TOOLBAR_CLOSE_MENU))] 107 IDS_IOS_TOOLBAR_CLOSE_MENU))]
123 performAction:grey_tap()]; 108 performAction:grey_tap()];
124 } else { 109 } else {
(...skipping 13 matching lines...) Expand all
138 const GURL URL = web::test::HttpServer::MakeUrl(kPDFURL); 123 const GURL URL = web::test::HttpServer::MakeUrl(kPDFURL);
139 124
140 // Navigate to a mock pdf and verify that the find button is disabled. 125 // Navigate to a mock pdf and verify that the find button is disabled.
141 [ChromeEarlGrey loadURL:URL]; 126 [ChromeEarlGrey loadURL:URL];
142 [ChromeEarlGreyUI openToolsMenu]; 127 [ChromeEarlGreyUI openToolsMenu];
143 [[EarlGrey selectElementWithMatcher:FindInPageButton()] 128 [[EarlGrey selectElementWithMatcher:FindInPageButton()]
144 assertWithMatcher:grey_accessibilityTrait( 129 assertWithMatcher:grey_accessibilityTrait(
145 UIAccessibilityTraitNotEnabled)]; 130 UIAccessibilityTraitNotEnabled)];
146 } 131 }
147 132
148 // Test requesting desktop version of page works and going back re-opens mobile 133 // Tests requesting desktop site of a page works and the user agent sticks for
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 nit: |Tests that| ?
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 This is really great set of tests, do you want to
liaoyuke 2017/04/11 18:27:20 sure, that sounds reasonable, and btw, thank you f
liaoyuke 2017/04/11 18:27:20 Done.
149 // version of page. 134 // next navigations in the same tab.
Eugene But (OOO till 7-30) 2017/04/11 02:11:56 nit: |the next navigations|?
liaoyuke 2017/04/11 18:27:20 Done.
150 - (void)testToolsMenuRequestDesktopNetwork { 135 - (void)testRequestDesktopSiteSticksForNextNavigation {
151 std::unique_ptr<web::DataResponseProvider> provider( 136 std::unique_ptr<web::DataResponseProvider> provider(
152 new UserAgentResponseProvider()); 137 new UserAgentResponseProvider());
153 web::test::SetUpHttpServer(std::move(provider)); 138 web::test::SetUpHttpServer(std::move(provider));
154 139
155 const GURL networkLayerTestURL = 140 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")];
156 web::test::HttpServer::MakeUrl("http://network"); 141 // Verify initial reception of the mobile site.
157 [self verifyMobileAndDesktopVersions:networkLayerTestURL]; 142 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 Do you want to add |using chrome_test_util::WebVie
liaoyuke 2017/04/11 18:27:20 Done.
158 } 143 kMobileSiteLabel)]
159 144 assertWithMatcher:grey_notNil()];
160 // Test requesting the desktop version of a page works correctly for 145
161 // script-based desktop/mobile differentation. 146 // Request and verify reception of the desktop site.
147 [ChromeEarlGreyUI openToolsMenu];
148 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
149 performAction:grey_tap()];
150 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
151 kDesktopSiteLabel)]
152 assertWithMatcher:grey_notNil()];
153
154 // Verify that desktop user agent sticks.
155 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://2.com")];
156 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
157 kDesktopSiteLabel)]
158 assertWithMatcher:grey_notNil()];
159 }
160
161 // Tests requesting desktop site of a page works and desktop user agent doesn't
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 nit: |Tests the requesting|?
liaoyuke 2017/04/11 18:27:20 Done.
162 // stick in new tab.
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 nit: s/doesn't stick in new tab/does not propagate
liaoyuke 2017/04/11 18:27:20 Done.
163 - (void)testRequestDesktopSiteDoesNotStickInNewTab {
164 std::unique_ptr<web::DataResponseProvider> provider(
165 new UserAgentResponseProvider());
166 web::test::SetUpHttpServer(std::move(provider));
167
168 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")];
169 // Verify initial reception of the mobile site.
170 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
171 kMobileSiteLabel)]
172 assertWithMatcher:grey_notNil()];
173
174 // Request and verify reception of the desktop site.
175 [ChromeEarlGreyUI openToolsMenu];
176 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
177 performAction:grey_tap()];
178 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
179 kDesktopSiteLabel)]
180 assertWithMatcher:grey_notNil()];
181
182 // Verify that desktop user agent doesn't stick in tab.
183 [ChromeEarlGreyUI openNewTab];
184 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://2.com")];
185 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
186 kMobileSiteLabel)]
187 assertWithMatcher:grey_notNil()];
188 }
189
190 // Tests requesting desktop site of a page works and going back re-opens mobile
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 |Tests that requesting|
liaoyuke 2017/04/11 18:27:20 Done.
191 // version of the page.
192 - (void)testRequestDesktopSiteGoBackToMobile {
193 std::unique_ptr<web::DataResponseProvider> provider(
194 new UserAgentResponseProvider());
195 web::test::SetUpHttpServer(std::move(provider));
196
197 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")];
198 // Verify initial reception of the mobile site.
199 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
200 kMobileSiteLabel)]
201 assertWithMatcher:grey_notNil()];
202
203 // Request and verify reception of the desktop site.
204 [ChromeEarlGreyUI openToolsMenu];
205 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
206 performAction:grey_tap()];
207 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
208 kDesktopSiteLabel)]
209 assertWithMatcher:grey_notNil()];
210
211 // Verify that going back returns to the mobile site.
212 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
213 performAction:grey_tap()];
214 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
215 kMobileSiteLabel)]
216 assertWithMatcher:grey_notNil()];
217 }
218
219 // Tests requesting mobile site of a page works and the user agent sticks for
220 // next navigations in the same tab.
221 - (void)testRequestMobileSiteSticksForNextNavigation {
222 std::unique_ptr<web::DataResponseProvider> provider(
223 new UserAgentResponseProvider());
224 web::test::SetUpHttpServer(std::move(provider));
225
226 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")];
227 // Verify initial reception of the mobile site.
228 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
229 kMobileSiteLabel)]
230 assertWithMatcher:grey_notNil()];
231
232 // Request and verify reception of the desktop site.
233 [ChromeEarlGreyUI openToolsMenu];
234 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
235 performAction:grey_tap()];
236 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
237 kDesktopSiteLabel)]
238 assertWithMatcher:grey_notNil()];
239
240 // Request and verify reception of the mobile site.
241 [ChromeEarlGreyUI openToolsMenu];
242 [[EarlGrey selectElementWithMatcher:RequestMobileButton()]
243 performAction:grey_tap()];
244 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
245 kMobileSiteLabel)]
246 assertWithMatcher:grey_notNil()];
247
248 // Verify that mobile user agent sticks.
249 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://2.com")];
250 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
251 kMobileSiteLabel)]
252 assertWithMatcher:grey_notNil()];
253 }
254
255 // Tests requesting mobile site of a page works and going back re-opens desktop
256 // version of the page.
257 - (void)testRequestMobileSiteGoBackToDesktop {
258 std::unique_ptr<web::DataResponseProvider> provider(
259 new UserAgentResponseProvider());
260 web::test::SetUpHttpServer(std::move(provider));
261
262 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")];
263 // Verify initial reception of the mobile site.
264 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
265 kMobileSiteLabel)]
266 assertWithMatcher:grey_notNil()];
267
268 // Request and verify reception of the desktop site.
269 [ChromeEarlGreyUI openToolsMenu];
270 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
271 performAction:grey_tap()];
272 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
273 kDesktopSiteLabel)]
274 assertWithMatcher:grey_notNil()];
275
276 // Request and verify reception of the mobile site.
277 [ChromeEarlGreyUI openToolsMenu];
278 [[EarlGrey selectElementWithMatcher:RequestMobileButton()]
279 performAction:grey_tap()];
280 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
281 kMobileSiteLabel)]
282 assertWithMatcher:grey_notNil()];
283
284 // Verify that going back returns to the desktop site.
285 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
286 performAction:grey_tap()];
287 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
288 kDesktopSiteLabel)]
289 assertWithMatcher:grey_notNil()];
290 }
291
292 // Tests requesting desktop site button is not enabled on new tab pages.
293 - (void)testRequestDesktopSiteNotEnabledOnNewTabPage {
294 // Verify tapping on request desktop button is no-op.
295 [ChromeEarlGreyUI openToolsMenu];
296 [[[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
297 assertWithMatcher:grey_notNil()] performAction:grey_tap()];
298 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
299 assertWithMatcher:grey_notNil()];
300
301 [[EarlGrey selectElementWithMatcher:CloseToolsMenuButton()]
302 performAction:grey_tap()];
303 }
304
305 // Tests requesting desktop site button is not enabled on native pages.
306 - (void)testRequestDesktopSiteNotEnabledOnNativePage {
307 [ChromeEarlGrey loadURL:GURL("chrome://version")];
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 chrome://version is not native but WebUI. Do you w
liaoyuke 2017/04/11 18:27:20 Done.
308
309 // Verify tapping on request desktop button is no-op.
310 [ChromeEarlGreyUI openToolsMenu];
311 [[[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
312 assertWithMatcher:grey_notNil()] performAction:grey_tap()];
313 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
314 assertWithMatcher:grey_notNil()];
315
316 [[EarlGrey selectElementWithMatcher:CloseToolsMenuButton()]
317 performAction:grey_tap()];
318 }
319
320 // Tests requesting desktop site works correctly for script-based desktop/mobile
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 What is "script-based desktop/mobile differentatio
liaoyuke 2017/04/11 18:27:20 Here is the script in the html file: <script type=
Eugene But (OOO till 7-30) 2017/04/11 22:21:19 Those are useful tests in general, so I think we s
Eugene But (OOO till 7-30) 2017/04/11 22:21:19 How about "Tests that navigator.appVersion JavaScr
liaoyuke 2017/04/12 00:26:18 Thanks! The new name and comments are much more de
liaoyuke 2017/04/12 00:26:18 Acknowledged.
321 // differentation.
162 - (void)testToolsMenuRequestDesktopScript { 322 - (void)testToolsMenuRequestDesktopScript {
Eugene But (OOO till 7-30) 2017/04/11 22:21:19 How about |testAppVersionJSAPIWithDesktopUser| age
liaoyuke 2017/04/12 00:26:18 Done.
163 web::test::SetUpFileBasedHttpServer(); 323 web::test::SetUpFileBasedHttpServer();
164 const GURL scriptLayerTestURL = web::test::HttpServer::MakeUrl( 324 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUserAgentTestURL)];
165 "http://ios/testing/data/http_server_files/" 325 // Verify initial reception of the mobile site.
166 "request_desktop_test_page.html"); 326 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
167 [self verifyMobileAndDesktopVersions:scriptLayerTestURL]; 327 kMobileSiteLabel)]
328 assertWithMatcher:grey_notNil()];
329
330 // Request and verify reception of the desktop site.
331 [ChromeEarlGreyUI openToolsMenu];
332 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
333 performAction:grey_tap()];
334 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
335 kDesktopSiteLabel)]
336 assertWithMatcher:grey_notNil()];
337 }
338
339 // Tests requesting mobile site works correctly for script-based desktop/mobile
Eugene But (OOO till 7-30) 2017/04/11 02:11:57 Same questions here.
liaoyuke 2017/04/11 18:27:20 Acknowledged.
340 // differentation.
341 - (void)testToolsMenuRequestMobileScript {
342 web::test::SetUpFileBasedHttpServer();
343 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUserAgentTestURL)];
344 // Verify initial reception of the mobile site.
345 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
346 kMobileSiteLabel)]
347 assertWithMatcher:grey_notNil()];
348
349 // Request and verify reception of the desktop site.
350 [ChromeEarlGreyUI openToolsMenu];
351 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
352 performAction:grey_tap()];
353 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
354 kDesktopSiteLabel)]
355 assertWithMatcher:grey_notNil()];
356
357 // Request and verify reception of the mobile site.
358 [ChromeEarlGreyUI openToolsMenu];
359 [[EarlGrey selectElementWithMatcher:RequestMobileButton()]
360 performAction:grey_tap()];
361 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
362 kMobileSiteLabel)]
363 assertWithMatcher:grey_notNil()];
168 } 364 }
169 365
170 // Open tools menu and verify elements are accessible. 366 // Open tools menu and verify elements are accessible.
171 - (void)testAccessibilityOnToolsMenu { 367 - (void)testAccessibilityOnToolsMenu {
172 [ChromeEarlGreyUI openToolsMenu]; 368 [ChromeEarlGreyUI openToolsMenu];
173 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 369 chrome_test_util::VerifyAccessibilityForCurrentScreen();
174 // Close Tools menu. 370 // Close Tools menu.
175 [ChromeTestCase removeAnyOpenMenusAndInfoBars]; 371 [ChromeTestCase removeAnyOpenMenusAndInfoBars];
176 } 372 }
177 373
178 @end 374 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698