Commit 071693c8 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Create Open-in EG2 Test

This test was not possible in EG1 as EG1 can't detect system views
(in this case the activity view).

- Test that open in bar appears when a PDF is opened and test that
  interacting with it will show the activityView. Also test that after
  dismiss the activity view tapping on the web view will bring back
  the open in bar.

- This CL also include a fix for the path problem where the default
  EmbededTestServer uses the Runner.app directory as the root directory.
  Instead change that to use the bundle path in the server initialization
  inside ChromeTestCase (This is a variation of Eugenebut@ solution created
  on https://chromium-review.googlesource.com/c/chromium/src/+/1650271 )

Bug: 945461

Change-Id: Ie8b53a7b662412b6516d8f2c654a19ac657416da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1650613
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668502}
parent af8bb909
......@@ -39,11 +39,6 @@ id<GREYMatcher> DownloadButton() {
return ButtonWithAccessibilityLabelId(IDS_IOS_DOWNLOAD_MANAGER_DOWNLOAD);
}
// Matcher for "Open In..." button on Download Manager UI.
id<GREYMatcher> OpenInButton() {
return ButtonWithAccessibilityLabelId(IDS_IOS_OPEN_IN);
}
// Provides downloads landing page with download link.
std::unique_ptr<net::test_server::HttpResponse> GetResponse(
const net::test_server::HttpRequest& request) {
......@@ -60,7 +55,7 @@ bool WaitForOpenInButton() {
const NSTimeInterval kLongDownloadTimeout = 35;
return base::test::ios::WaitUntilConditionOrTimeout(kLongDownloadTimeout, ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:OpenInButton()]
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
assertWithMatcher:grey_notNil()
error:&error];
return (error == nil);
......
......@@ -49,3 +49,27 @@ source_set("unit_tests") {
"//third_party/ocmock",
]
}
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"open_in_controller_egtest.mm",
]
deps = [
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//net:test_support",
"//ui/base",
]
libs = [ "UIKit.framework" ]
}
// Copyright 2019 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 <UIKit/UIKit.h>
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_actions.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/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Path which leads to a PDF file.
const char kPDFPath[] = "/testpage.pdf";
} // namespace
// Tests Open in Feature for PDF files.
@interface OpenInManagerTestCase : ChromeTestCase
@end
@implementation OpenInManagerTestCase
- (void)setUp {
[super setUp];
GREYAssertTrue(self.testServer->Start(), @"Server did not start.");
}
// Tests that open in button appears when opening a PDF, and that tapping on it
// will open the activity view.
- (void)testOpenIn {
[ChromeEarlGrey loadURL:self.testServer->GetURL(kPDFPath)];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
performAction:grey_tap()];
// Check and tap on the Cancel button that appears below the activity menu.
// Other actions buttons can't be checked from EarlGrey.
[[[EarlGrey selectElementWithMatcher:chrome_test_util::CancelButton()]
assertWithMatcher:grey_interactable()] performAction:grey_tap()];
// Check that after dismissing the activity view, tapping on the web view will
// bring the open in bar again.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
assertWithMatcher:grey_interactable()];
}
@end
......@@ -283,6 +283,9 @@ id<GREYMatcher> WebStateScrollViewMatcher();
// Returns a matcher for the Clear Browsing Data button in the History UI.
id<GREYMatcher> HistoryClearBrowsingDataButton();
// Returns a matcher for "Open In..." button.
id<GREYMatcher> OpenInButton();
}
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_H_
......@@ -361,4 +361,8 @@ id<GREYMatcher> HistoryClearBrowsingDataButton() {
return [ChromeMatchersAppInterface historyClearBrowsingDataButton];
}
id<GREYMatcher> OpenInButton() {
return [ChromeMatchersAppInterface openInButton];
}
} // namespace chrome_test_util
......@@ -11,6 +11,8 @@
// Helper class to return matchers for EG tests. These helpers are compiled
// into the app binary and can be called from either app or test code.
// All calls of grey_... involve the App process, so it's more efficient to
// define the matchers in the app process.
@interface ChromeMatchersAppInterface : NSObject
// Matcher for element with accessibility label corresponding to |label| and
......@@ -286,6 +288,9 @@
// Returns a matcher for the Clear Browsing Data button in the History UI.
+ (id<GREYMatcher>)historyClearBrowsingDataButton;
// Returns a matcher for "Open In..." button.
+ (id<GREYMatcher>)openInButton;
@end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_APP_INTERFACE_H_
......@@ -588,4 +588,9 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kHistoryToolbarClearBrowsingButtonIdentifier);
}
+ (id<GREYMatcher>)openInButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:IDS_IOS_OPEN_IN];
}
@end
......@@ -16,6 +16,7 @@
#import "ios/testing/earl_grey/coverage_utils.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "net/test/embedded_test_server/default_handlers.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -218,8 +219,11 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
- (net::EmbeddedTestServer*)testServer {
if (!_testServer) {
_testServer = std::make_unique<net::EmbeddedTestServer>();
_testServer->AddDefaultHandlers(base::FilePath(
FILE_PATH_LITERAL("ios/testing/data/http_server_files/")));
NSString* bundlePath = [NSBundle bundleForClass:[self class]].resourcePath;
_testServer->ServeFilesFromDirectory(
base::FilePath(base::SysNSStringToUTF8(bundlePath))
.AppendASCII("ios/testing/data/http_server_files/"));
net::test_server::RegisterDefaultHandlers(_testServer.get());
}
return _testServer.get();
}
......
......@@ -41,6 +41,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
deps = [
"//ios/chrome/browser/ui/activity_services:eg2_tests",
"//ios/chrome/browser/ui/download:eg2_tests",
"//ios/chrome/browser/ui/open_in:eg2_tests",
"//ios/chrome/browser/ui/toolbar:eg2_tests",
]
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment