| 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
|
| index 79784cc5d55b84130ef0bcee09ef3c8c5e027ccc..0b52bc2865bad982d7c6ba8cee73e1890978f8b6 100644
|
| --- a/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm
|
| +++ b/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm
|
| @@ -5,9 +5,6 @@
|
| #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"
|
| #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h"
|
| #import "ios/chrome/browser/ui/uikit_ui_util.h"
|
| @@ -19,7 +16,6 @@
|
| #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"
|
|
|
| #if !defined(__has_feature) || !__has_feature(objc_arc)
|
| @@ -28,90 +24,21 @@
|
|
|
| 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");
|
| - }
|
| - }
|
| -};
|
| +const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf";
|
|
|
| // 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);
|
| -}
|
| -
|
| -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:chrome_test_util::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];
|
| @@ -145,28 +72,6 @@ - (void)testNoSearchForPDF {
|
| 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];
|
| -}
|
| -
|
| // Open tools menu and verify elements are accessible.
|
| - (void)testAccessibilityOnToolsMenu {
|
| [ChromeEarlGreyUI openToolsMenu];
|
|
|