Commit b88b3f35 authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS][OpenIn] Refactors EG2 tests

This CL refactors EG2 tests related to the open in toolbar.
The toolbar and the display of the activity view is now tested
on a PDF file and a PNG image.
It also Tests that the open in bar is correctly displayed
when a compatible URL is loaded and tapping on the web view
makes it appear or disappear.

Bug: 1124310, 1146303, 1135805
Change-Id: I57f962a31a7e34a02ae37fb72bf649abb6fb74fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532004
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830570}
parent d53d6278
...@@ -72,6 +72,8 @@ source_set("eg2_tests") { ...@@ -72,6 +72,8 @@ source_set("eg2_tests") {
deps = [ deps = [
"//base", "//base",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/open_in:features",
"//ios/chrome/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
......
...@@ -6,12 +6,16 @@ ...@@ -6,12 +6,16 @@
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/open_in/features.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_actions.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.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.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_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#import "ios/testing/earl_grey/app_launch_configuration.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -25,6 +29,10 @@ namespace { ...@@ -25,6 +29,10 @@ namespace {
// Path which leads to a PDF file. // Path which leads to a PDF file.
const char kPDFPath[] = "/testpage.pdf"; const char kPDFPath[] = "/testpage.pdf";
// Path wich leads to a PNG file.
const char KPNGPath[] = "/chromium_logo.png";
// Matcher for the Cancel button.
id<GREYMatcher> ShareMenuDismissButton() { id<GREYMatcher> ShareMenuDismissButton() {
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
return chrome_test_util::CloseButton(); return chrome_test_util::CloseButton();
...@@ -35,12 +43,18 @@ id<GREYMatcher> ShareMenuDismissButton() { ...@@ -35,12 +43,18 @@ id<GREYMatcher> ShareMenuDismissButton() {
} // namespace } // namespace
// Tests Open in Feature for PDF files. // Tests Open in Feature.
@interface OpenInManagerTestCase : ChromeTestCase @interface OpenInManagerTestCase : ChromeTestCase
@end @end
@implementation OpenInManagerTestCase @implementation OpenInManagerTestCase
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
config.features_enabled.push_back(kExtendOpenInFilesSupport);
return config;
}
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
GREYAssertTrue(self.testServer->Start(), @"Server did not start."); GREYAssertTrue(self.testServer->Start(), @"Server did not start.");
...@@ -48,40 +62,103 @@ id<GREYMatcher> ShareMenuDismissButton() { ...@@ -48,40 +62,103 @@ id<GREYMatcher> ShareMenuDismissButton() {
// Tests that open in button appears when opening a PDF, and that tapping on it // Tests that open in button appears when opening a PDF, and that tapping on it
// will open the activity view. // will open the activity view.
// - (void)testOpenInPDF {
// Disabled due to flakiness: http://crbug.com/1146303 // Apple is hiding UIActivityViewController's content from the host app on
- (void)DISABLED_testOpenIn { // iPad.
// TODO(crbug.com/1135805): The share menu displays in a popover on iPad, if ([ChromeEarlGrey isIPadIdiom])
// which causes this test to fail. EARL_GREY_TEST_SKIPPED(@"Test skipped on iPad.");
if ([ChromeEarlGrey isIPadIdiom]) {
EARL_GREY_TEST_DISABLED(@"Disabled on iPad"); // Open the activity menu.
[ChromeEarlGrey loadURL:self.testServer->GetURL(kPDFPath)];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
performAction:grey_tap()];
// UIActivityViewController doesn't display the filename on iOS 12.
if (@available(iOS 13, *)) {
// Test filename label.
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_text(@"testpage"),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_notNil()];
} }
// TODO(crbug.com/982845): A bug is causing the "Open in" toolbar to disappear // Check that tapping on the Cancel button closes the activity menu and hides
// after any VC is presented fullscreen over the BVC. The iOS 13 share menu // the open in toolbar.
// is presented fullscreen, but only when compiling with the iOS 12 SDK. [[EarlGrey selectElementWithMatcher:ShareMenuDismissButton()]
// Disable this test in this configuration until the underlying bug is fixed. performAction:grey_tap()];
#if !defined(__IPHONE_13_0) || (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_13_0) [[EarlGrey selectElementWithMatcher:ShareMenuDismissButton()]
if (base::ios::IsRunningOnIOS13OrLater()) { assertWithMatcher:grey_notVisible()];
EARL_GREY_TEST_DISABLED( [[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
@"Disabled on iOS 13 when compiled with the iOS 12 SDK."); assertWithMatcher:grey_notVisible()];
}
// Tests that open in button appears when opening a PNG, and that tapping on it
// will open the activity view.
- (void)testOpenInPNG {
// Apple is hiding UIActivityViewController's content from the host app on
// iPad.
if ([ChromeEarlGrey isIPadIdiom])
EARL_GREY_TEST_SKIPPED(@"Test skipped on iPad.");
// Open the activity menu.
[ChromeEarlGrey loadURL:self.testServer->GetURL(KPNGPath)];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
performAction:grey_tap()];
// UIActivityViewController doesn't display the filename on iOS 12.
if (@available(iOS 13, *)) {
// Test filename label.
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_text(@"chromium_logo"),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_notNil()];
} }
#endif
// Check that tapping on the Cancel button closes the activity menu and hides
// the open in toolbar.
[[EarlGrey selectElementWithMatcher:ShareMenuDismissButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:ShareMenuDismissButton()]
assertWithMatcher:grey_notVisible()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
assertWithMatcher:grey_notVisible()];
}
// Tests that the open in bar is correctly displayed when a compatible URL is
// loaded and tapping on the web view makes it appear or disappear.
- (void)testOpenInDisplay {
// Check that the open in bar is correctly displayed when a compatible URL is
// loaded.
[ChromeEarlGrey loadURL:self.testServer->GetURL(kPDFPath)]; [ChromeEarlGrey loadURL:self.testServer->GetURL(kPDFPath)];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
performAction:grey_tap()]; assertWithMatcher:grey_sufficientlyVisible()];
// Check and tap on the Cancel button that appears below the activity menu.
// Other actions buttons can't be checked from EarlGrey.
[[[EarlGrey selectElementWithMatcher:ShareMenuDismissButton()]
assertWithMatcher:grey_interactable()] performAction:grey_tap()];
// Check that after dismissing the activity view, tapping on the web view will // Check that tapping on the web view makes the open in toolbar disappear.
// bring the open in bar again.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::OpenInButton()]
assertWithMatcher:grey_interactable()]; assertWithMatcher:grey_notVisible()];
// Check that tapping on the web view makes the open in toolbar appear.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:grey_tap()];
// Turn off synchronization of GREYAssert to test the appearance of open in
// toolbar. If synchronization is on, the open in toolbar exists but it's not
// considered visible.
ScopedSynchronizationDisabler disabler;
GREYCondition* openInVisibleCondition = [GREYCondition
conditionWithName:@"Check that the open in toolbar is visible"
block:^BOOL {
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:chrome_test_util::
OpenInButton()]
assertWithMatcher:grey_sufficientlyVisible()
error:&error];
return error == nil;
}];
BOOL openInVisible = [openInVisibleCondition
waitWithTimeout:base::test::ios::kWaitForUIElementTimeout];
GREYAssertTrue(openInVisible, @"The open in toolbar never became visible.");
} }
@end @end
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