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

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

Issue 2588733002: Upstream Chrome on iOS source code [9/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 <EarlGrey/EarlGrey.h>
6 #import <XCTest/XCTest.h>
7
8 #include "base/strings/sys_string_conversions.h"
9 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/ui/chrome_web_view_factory.h"
11 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
12 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
13 #import "ios/chrome/browser/ui/uikit_ui_util.h"
14 #include "ios/chrome/grit/ios_strings.h"
15 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
16 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
17 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
18 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
19 #import "ios/web/public/test/http_server.h"
20 #include "ios/web/public/test/http_server_util.h"
21 #include "ios/web/public/test/response_providers/data_response_provider.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 namespace {
25
26 // A ResponseProvider that provides user agent for httpServer request.
27 class UserAgentResponseProvider : public web::DataResponseProvider {
28 public:
29 bool CanHandleRequest(const Request& request) override { return true; }
30
31 void GetResponseHeadersAndBody(
32 const Request& request,
33 scoped_refptr<net::HttpResponseHeaders>* headers,
34 std::string* response_body) override {
35 // Do not return anything if static plist file has been requested,
36 // as plain text is not a valid property list content.
37 if ([[base::SysUTF8ToNSString(request.url.spec()) pathExtension]
38 isEqualToString:@"plist"]) {
39 *headers =
40 web::ResponseProvider::GetResponseHeaders("", net::HTTP_NO_CONTENT);
41 return;
42 }
43
44 *headers = web::ResponseProvider::GetDefaultResponseHeaders();
45 std::string userAgent;
46 const std::string kDesktopUserAgent =
47 base::SysNSStringToUTF8(ChromeWebView::kDesktopUserAgent);
48 if (request.headers.GetHeader("User-Agent", &userAgent) &&
49 userAgent == kDesktopUserAgent) {
50 response_body->assign("Desktop");
51 } else {
52 response_body->assign("Mobile");
53 }
54 }
55 };
56
57 // Matcher for the button to find in page.
58 id<GREYMatcher> FindInPageButton() {
59 return chrome_test_util::buttonWithAccessibilityLabel(
60 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE));
61 }
62
63 // Matcher for the button to request desktop version.
64 id<GREYMatcher> RequestDesktopButton() {
65 return grey_accessibilityID(kToolsMenuRequestDesktopId);
66 }
67
68 // Matcher for the navigate backward button.
69 id<GREYMatcher> BackButton() {
70 return chrome_test_util::buttonWithAccessibilityLabelId(IDS_ACCNAME_BACK);
71 }
72
73 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
74
75 } // namespace
76
77 // Tests for the tools popup menu.
78 @interface ToolsPopupMenuTestCase : ChromeTestCase
79 - (void)verifyMobileAndDesktopVersions:(const GURL&)url;
80 @end
81
82 @implementation ToolsPopupMenuTestCase
83
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:BackButton()] performAction:grey_tap()];
108 [[EarlGrey
109 selectElementWithMatcher:chrome_test_util::webViewContainingText(
110 base::SysNSStringToUTF8(kMobileSiteLabel))]
111 assertWithMatcher:grey_notNil()];
112 }
113
114 // Tests that the menu is closed when tapping the close button.
115 - (void)testOpenAndCloseToolsMenu {
116 [ChromeEarlGreyUI openToolsMenu];
117
118 if (!IsCompact()) {
119 [[EarlGrey
120 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
121 IDS_IOS_TOOLBAR_CLOSE_MENU))]
122 performAction:grey_tap()];
123 } else {
124 [[EarlGrey selectElementWithMatcher:chrome_test_util::toolsMenuButton()]
125 performAction:grey_tap()];
126 }
127
128 [[EarlGrey
129 selectElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)]
130 assertWithMatcher:grey_notVisible()];
131 }
132
133 // Navigates to a pdf page and verifies that the "Find in Page..." tool
134 // is not enabled
135 - (void)testNoSearchForPDF {
136 web::test::SetUpFileBasedHttpServer();
137 const GURL URL = web::test::HttpServer::MakeUrl(kPDFURL);
138
139 // Navigate to a mock pdf and verify that the find button is disabled.
140 [ChromeEarlGrey loadURL:URL];
141 [ChromeEarlGreyUI openToolsMenu];
142 [[EarlGrey selectElementWithMatcher:FindInPageButton()]
143 assertWithMatcher:grey_accessibilityTrait(
144 UIAccessibilityTraitNotEnabled)];
145 }
146
147 // Test requesting desktop version of page works and going back re-opens mobile
148 // version of page.
149 - (void)testToolsMenuRequestDesktopNetwork {
150 std::unique_ptr<web::DataResponseProvider> provider(
151 new UserAgentResponseProvider());
152 web::test::SetUpHttpServer(std::move(provider));
153
154 const GURL networkLayerTestURL =
155 web::test::HttpServer::MakeUrl("http://network");
156 [self verifyMobileAndDesktopVersions:networkLayerTestURL];
157 }
158
159 // Test requesting the desktop version of a page works correctly for
160 // script-based desktop/mobile differentation.
161 - (void)testToolsMenuRequestDesktopScript {
162 web::test::SetUpFileBasedHttpServer();
163 const GURL scriptLayerTestURL = web::test::HttpServer::MakeUrl(
164 "http://ios/testing/data/http_server_files/"
165 "request_desktop_test_page.html");
166 [self verifyMobileAndDesktopVersions:scriptLayerTestURL];
167 }
168
169 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/tools_menu/tools_popup_controller.mm ('k') | ios/chrome/browser/ui/ui_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698