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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm
diff --git a/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm b/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..beb071e9253a2ba3cb27d972421c08a758c7b017
--- /dev/null
+++ b/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm
@@ -0,0 +1,169 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <EarlGrey/EarlGrey.h>
+#import <XCTest/XCTest.h>
+
+#include "base/strings/sys_string_conversions.h"
+#include "components/strings/grit/components_strings.h"
+#import "ios/chrome/browser/ui/chrome_web_view_factory.h"
+#import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
+#import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
+#include "ios/chrome/grit/ios_strings.h"
+#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
+#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
+#import "ios/chrome/test/earl_grey/chrome_matchers.h"
+#import "ios/chrome/test/earl_grey/chrome_test_case.h"
+#import "ios/web/public/test/http_server.h"
+#include "ios/web/public/test/http_server_util.h"
+#include "ios/web/public/test/response_providers/data_response_provider.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+
+// A ResponseProvider that provides user agent for httpServer request.
+class UserAgentResponseProvider : public web::DataResponseProvider {
+ public:
+ bool CanHandleRequest(const Request& request) override { return true; }
+
+ void GetResponseHeadersAndBody(
+ const Request& request,
+ scoped_refptr<net::HttpResponseHeaders>* headers,
+ std::string* response_body) override {
+ // Do not return anything if static plist file has been requested,
+ // as plain text is not a valid property list content.
+ if ([[base::SysUTF8ToNSString(request.url.spec()) pathExtension]
+ isEqualToString:@"plist"]) {
+ *headers =
+ web::ResponseProvider::GetResponseHeaders("", net::HTTP_NO_CONTENT);
+ return;
+ }
+
+ *headers = web::ResponseProvider::GetDefaultResponseHeaders();
+ std::string userAgent;
+ const std::string kDesktopUserAgent =
+ base::SysNSStringToUTF8(ChromeWebView::kDesktopUserAgent);
+ if (request.headers.GetHeader("User-Agent", &userAgent) &&
+ userAgent == kDesktopUserAgent) {
+ response_body->assign("Desktop");
+ } else {
+ response_body->assign("Mobile");
+ }
+ }
+};
+
+// Matcher for the button to find in page.
+id<GREYMatcher> FindInPageButton() {
+ return chrome_test_util::buttonWithAccessibilityLabel(
+ l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE));
+}
+
+// Matcher for the button to request desktop version.
+id<GREYMatcher> RequestDesktopButton() {
+ return grey_accessibilityID(kToolsMenuRequestDesktopId);
+}
+
+// Matcher for the navigate backward button.
+id<GREYMatcher> BackButton() {
+ return chrome_test_util::buttonWithAccessibilityLabelId(IDS_ACCNAME_BACK);
+}
+
+const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
+
+} // namespace
+
+// Tests for the tools popup menu.
+@interface ToolsPopupMenuTestCase : ChromeTestCase
+- (void)verifyMobileAndDesktopVersions:(const GURL&)url;
+@end
+
+@implementation ToolsPopupMenuTestCase
+
+// Verify that requesting desktop and mobile versions works.
+- (void)verifyMobileAndDesktopVersions:(const GURL&)url {
+ NSString* const kMobileSiteLabel = @"Mobile";
+ NSString* const kDesktopSiteLabel = @"Desktop";
+
+ [ChromeEarlGrey loadURL:url];
+
+ // Verify initial reception of the mobile site.
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::webViewContainingText(
+ base::SysNSStringToUTF8(kMobileSiteLabel))]
+ assertWithMatcher:grey_notNil()];
+
+ // Request and verify reception of the desktop site.
+ [ChromeEarlGreyUI openToolsMenu];
+ [[EarlGrey selectElementWithMatcher:RequestDesktopButton()]
+ performAction:grey_tap()];
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::webViewContainingText(
+ base::SysNSStringToUTF8(kDesktopSiteLabel))]
+ assertWithMatcher:grey_notNil()];
+
+ // Verify that going back returns to the mobile site.
+ [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
+ [[EarlGrey
+ selectElementWithMatcher:chrome_test_util::webViewContainingText(
+ base::SysNSStringToUTF8(kMobileSiteLabel))]
+ assertWithMatcher:grey_notNil()];
+}
+
+// Tests that the menu is closed when tapping the close button.
+- (void)testOpenAndCloseToolsMenu {
+ [ChromeEarlGreyUI openToolsMenu];
+
+ if (!IsCompact()) {
+ [[EarlGrey
+ selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
+ IDS_IOS_TOOLBAR_CLOSE_MENU))]
+ performAction:grey_tap()];
+ } else {
+ [[EarlGrey selectElementWithMatcher:chrome_test_util::toolsMenuButton()]
+ performAction:grey_tap()];
+ }
+
+ [[EarlGrey
+ selectElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)]
+ assertWithMatcher:grey_notVisible()];
+}
+
+// Navigates to a pdf page and verifies that the "Find in Page..." tool
+// is not enabled
+- (void)testNoSearchForPDF {
+ web::test::SetUpFileBasedHttpServer();
+ const GURL URL = web::test::HttpServer::MakeUrl(kPDFURL);
+
+ // Navigate to a mock pdf and verify that the find button is disabled.
+ [ChromeEarlGrey loadURL:URL];
+ [ChromeEarlGreyUI openToolsMenu];
+ [[EarlGrey selectElementWithMatcher:FindInPageButton()]
+ assertWithMatcher:grey_accessibilityTrait(
+ UIAccessibilityTraitNotEnabled)];
+}
+
+// Test requesting desktop version of page works and going back re-opens mobile
+// version of page.
+- (void)testToolsMenuRequestDesktopNetwork {
+ std::unique_ptr<web::DataResponseProvider> provider(
+ new UserAgentResponseProvider());
+ web::test::SetUpHttpServer(std::move(provider));
+
+ const GURL networkLayerTestURL =
+ web::test::HttpServer::MakeUrl("http://network");
+ [self verifyMobileAndDesktopVersions:networkLayerTestURL];
+}
+
+// Test requesting the desktop version of a page works correctly for
+// script-based desktop/mobile differentation.
+- (void)testToolsMenuRequestDesktopScript {
+ web::test::SetUpFileBasedHttpServer();
+ const GURL scriptLayerTestURL = web::test::HttpServer::MakeUrl(
+ "http://ios/testing/data/http_server_files/"
+ "request_desktop_test_page.html");
+ [self verifyMobileAndDesktopVersions:scriptLayerTestURL];
+}
+
+@end
« 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