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

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 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
« no previous file with comments | « ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm ('k') | ios/testing/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
Eugene But (OOO till 7-30) 2017/04/11 22:21:19 Is this include still necessary? Could you please
liaoyuke 2017/04/12 00:26:18 Done.
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"
11 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" 11 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
12 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" 12 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h"
13 #import "ios/chrome/browser/ui/uikit_ui_util.h" 13 #import "ios/chrome/browser/ui/uikit_ui_util.h"
14 #include "ios/chrome/grit/ios_strings.h" 14 #include "ios/chrome/grit/ios_strings.h"
15 #import "ios/chrome/test/earl_grey/accessibility_util.h" 15 #import "ios/chrome/test/earl_grey/accessibility_util.h"
16 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 16 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
17 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" 17 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
18 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 18 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
19 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 19 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
20 #import "ios/web/public/test/http_server.h" 20 #import "ios/web/public/test/http_server.h"
21 #include "ios/web/public/test/http_server_util.h" 21 #include "ios/web/public/test/http_server_util.h"
22 #include "ios/web/public/test/response_providers/data_response_provider.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 23
25 #if !defined(__has_feature) || !__has_feature(objc_arc) 24 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support." 25 #error "This file requires ARC support."
27 #endif 26 #endif
28 27
29 namespace { 28 namespace {
30 29
31 // A ResponseProvider that provides user agent for httpServer request. 30 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
32 class UserAgentResponseProvider : public web::DataResponseProvider {
33 public:
34 bool CanHandleRequest(const Request& request) override { return true; }
35
36 void GetResponseHeadersAndBody(
37 const Request& request,
38 scoped_refptr<net::HttpResponseHeaders>* headers,
39 std::string* response_body) override {
40 // Do not return anything if static plist file has been requested,
41 // as plain text is not a valid property list content.
42 if ([[base::SysUTF8ToNSString(request.url.spec()) pathExtension]
43 isEqualToString:@"plist"]) {
44 *headers =
45 web::ResponseProvider::GetResponseHeaders("", net::HTTP_NO_CONTENT);
46 return;
47 }
48
49 *headers = web::ResponseProvider::GetDefaultResponseHeaders();
50 std::string userAgent;
51 const std::string kDesktopUserAgent =
52 base::SysNSStringToUTF8(ChromeWebView::kDesktopUserAgent);
53 if (request.headers.GetHeader("User-Agent", &userAgent) &&
54 userAgent == kDesktopUserAgent) {
55 response_body->assign("Desktop");
56 } else {
57 response_body->assign("Mobile");
58 }
59 }
60 };
61 31
62 // Matcher for the button to find in page. 32 // Matcher for the button to find in page.
63 id<GREYMatcher> FindInPageButton() { 33 id<GREYMatcher> FindInPageButton() {
64 return chrome_test_util::ButtonWithAccessibilityLabel( 34 return chrome_test_util::ButtonWithAccessibilityLabel(
65 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)); 35 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE));
66 } 36 }
67
68 // Matcher for the button to request desktop version.
69 id<GREYMatcher> RequestDesktopButton() {
70 return grey_accessibilityID(kToolsMenuRequestDesktopId);
71 }
72
73 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
74
75 } // namespace 37 } // namespace
76 38
77 // Tests for the tools popup menu. 39 // Tests for the tools popup menu.
78 @interface ToolsPopupMenuTestCase : ChromeTestCase 40 @interface ToolsPopupMenuTestCase : ChromeTestCase
79 - (void)verifyMobileAndDesktopVersions:(const GURL&)url;
80 @end 41 @end
81 42
82 @implementation ToolsPopupMenuTestCase 43 @implementation ToolsPopupMenuTestCase
83 44
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. 45 // Tests that the menu is closed when tapping the close button.
116 - (void)testOpenAndCloseToolsMenu { 46 - (void)testOpenAndCloseToolsMenu {
117 [ChromeEarlGreyUI openToolsMenu]; 47 [ChromeEarlGreyUI openToolsMenu];
118 48
119 if (!IsCompact()) { 49 if (!IsCompact()) {
120 [[EarlGrey 50 [[EarlGrey
121 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( 51 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
122 IDS_IOS_TOOLBAR_CLOSE_MENU))] 52 IDS_IOS_TOOLBAR_CLOSE_MENU))]
123 performAction:grey_tap()]; 53 performAction:grey_tap()];
124 } else { 54 } else {
(...skipping 13 matching lines...) Expand all
138 const GURL URL = web::test::HttpServer::MakeUrl(kPDFURL); 68 const GURL URL = web::test::HttpServer::MakeUrl(kPDFURL);
139 69
140 // Navigate to a mock pdf and verify that the find button is disabled. 70 // Navigate to a mock pdf and verify that the find button is disabled.
141 [ChromeEarlGrey loadURL:URL]; 71 [ChromeEarlGrey loadURL:URL];
142 [ChromeEarlGreyUI openToolsMenu]; 72 [ChromeEarlGreyUI openToolsMenu];
143 [[EarlGrey selectElementWithMatcher:FindInPageButton()] 73 [[EarlGrey selectElementWithMatcher:FindInPageButton()]
144 assertWithMatcher:grey_accessibilityTrait( 74 assertWithMatcher:grey_accessibilityTrait(
145 UIAccessibilityTraitNotEnabled)]; 75 UIAccessibilityTraitNotEnabled)];
146 } 76 }
147 77
148 // Test requesting desktop version of page works and going back re-opens mobile
149 // version of page.
150 - (void)testToolsMenuRequestDesktopNetwork {
151 std::unique_ptr<web::DataResponseProvider> provider(
152 new UserAgentResponseProvider());
153 web::test::SetUpHttpServer(std::move(provider));
154
155 const GURL networkLayerTestURL =
156 web::test::HttpServer::MakeUrl("http://network");
157 [self verifyMobileAndDesktopVersions:networkLayerTestURL];
158 }
159
160 // Test requesting the desktop version of a page works correctly for
161 // script-based desktop/mobile differentation.
162 - (void)testToolsMenuRequestDesktopScript {
163 web::test::SetUpFileBasedHttpServer();
164 const GURL scriptLayerTestURL = web::test::HttpServer::MakeUrl(
165 "http://ios/testing/data/http_server_files/"
166 "request_desktop_test_page.html");
167 [self verifyMobileAndDesktopVersions:scriptLayerTestURL];
168 }
169
170 // Open tools menu and verify elements are accessible. 78 // Open tools menu and verify elements are accessible.
171 - (void)testAccessibilityOnToolsMenu { 79 - (void)testAccessibilityOnToolsMenu {
172 [ChromeEarlGreyUI openToolsMenu]; 80 [ChromeEarlGreyUI openToolsMenu];
173 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 81 chrome_test_util::VerifyAccessibilityForCurrentScreen();
174 // Close Tools menu. 82 // Close Tools menu.
175 [ChromeTestCase removeAnyOpenMenusAndInfoBars]; 83 [ChromeTestCase removeAnyOpenMenusAndInfoBars];
176 } 84 }
177 85
178 @end 86 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm ('k') | ios/testing/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698