Commit 42e6451b authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Convert ContextMenuTestCase tests to EarlGrey2

Bug: 987646
Change-Id: I01c8a58a8f51d7aeee0a03d1eed0e3cd040ea941
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902068
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715337}
parent 850aa23b
......@@ -4,6 +4,7 @@
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true
sources = [
"context_menu_egtest.mm",
......@@ -13,17 +14,11 @@ source_set("eg_tests") {
"//base/test:test_support",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/app:test_support",
"//ios/chrome/browser/ui/fullscreen/test:eg_test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/ui",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ios/web:earl_grey_test_support",
"//ios/web/public",
"//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server",
"//net:test_support",
"//url",
]
......@@ -32,3 +27,29 @@ source_set("eg_tests") {
"XCTest.framework",
]
}
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"context_menu_egtest.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/fullscreen/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test:element_selector",
"//net:test_support",
"//url",
]
libs = [ "UIKit.framework" ]
}
......@@ -2,30 +2,23 @@
// 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 <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#include "base/bind.h"
#import "base/mac/foundation_util.h"
#import "base/test/ios/wait_util.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/fullscreen/test/fullscreen_app_interface.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/histogram_test_util.h"
#import "ios/chrome/test/app/tab_test_util.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"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/ui/fullscreen_provider.h"
#import "ios/testing/earl_grey/disabled_test_macros.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ios/web/public/test/element_selector.h"
#import "ios/web/public/ui/crw_web_view_proxy.h"
#import "ios/web/public/web_state.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
......@@ -141,20 +134,6 @@ void TapOnContextMenuButton(id<GREYMatcher> context_menu_item_button) {
WaitForContextMenuItemDisappeared(context_menu_item_button);
}
// A simple wrapper that sleeps for 1s to wait for the animation, triggered from
// opening a new tab through context menu, to finish before selecting tab.
// TODO(crbug.com/643792): Remove this function when the bug is fixed.
void SelectTabAtIndexInCurrentMode(NSUInteger index) {
// Delay for 1 second.
GREYCondition* myCondition = [GREYCondition conditionWithName:@"delay"
block:^BOOL {
return NO;
}];
[myCondition waitWithTimeout:1];
[ChromeEarlGrey selectTabAtIndex:index];
}
} // namespace
// Context menu tests for Chrome.
......@@ -163,8 +142,8 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
@implementation ContextMenuTestCase
+ (void)setUp {
[super setUp];
+ (void)setUpForTestCase {
[super setUpForTestCase];
[ChromeEarlGrey setContentSettings:CONTENT_SETTING_ALLOW];
}
......@@ -210,7 +189,7 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
TapOnContextMenuButton(OpenImageInNewTabButton());
[ChromeEarlGrey waitForMainTabCount:2];
SelectTabAtIndexInCurrentMode(1U);
[ChromeEarlGrey selectTabAtIndex:1];
[ChromeEarlGrey waitForPageToFinishLoading];
// Verify url.
......@@ -230,7 +209,7 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
TapOnContextMenuButton(OpenLinkInNewTabButton());
[ChromeEarlGrey waitForMainTabCount:2];
SelectTabAtIndexInCurrentMode(1U);
[ChromeEarlGrey selectTabAtIndex:1];
[ChromeEarlGrey waitForWebStateContainingText:kDestinationPageText];
// Verify url.
......@@ -244,27 +223,36 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
const GURL imageURL = self.testServer->GetURL(kLogoPageImageSourcePath);
[ChromeEarlGrey loadURL:imageURL];
// Calculate a point inside the displayed image. Javascript can not be used to
// find the element because no DOM exists. If the viewport is adjusted using
// the contentInset, the top inset needs to be added to the touch point.
id<CRWWebViewProxy> webViewProxy =
chrome_test_util::GetCurrentWebState()->GetWebViewProxy();
BOOL usesContentInset =
webViewProxy.shouldUseViewContentInset ||
ios::GetChromeBrowserProvider()->GetFullscreenProvider()->IsInitialized();
CGFloat topInset = usesContentInset ? webViewProxy.contentInset.top : 0.0;
CGPoint point = CGPointMake(
CGRectGetMidX([chrome_test_util::GetActiveViewController() view].bounds),
topInset + 20.0);
// Calculate a point inside the displayed image.
CGFloat topInset = 0.0;
if ([ChromeEarlGrey webStateWebViewUsesContentInset] ||
[FullscreenAppInterface isFullscreenInitialized]) {
topInset = [FullscreenAppInterface currentViewportInsets].top;
}
CGPoint pointOnImage = CGPointZero;
// Offset by at least status bar height.
pointOnImage.y = topInset + 25.0;
pointOnImage.x = [ChromeEarlGrey webStateWebViewSize].width / 2.0;
// Duration should match |kContextMenuLongPressDuration| as defined in
// web_view_actions.mm.
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:grey_longPressAtPointWithDuration(point, 1.0)];
performAction:grey_longPressAtPointWithDuration(pointOnImage, 1.0)];
TapOnContextMenuButton(OpenImageInNewTabButton());
[ChromeEarlGrey waitForMainTabCount:2];
SelectTabAtIndexInCurrentMode(1U);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-result"
// TODO(crbug.com/643792): Remove this wait the bug is fixed.
// Delay for 1 second before selecting tab.
[[GREYCondition conditionWithName:@"delay"
block:^BOOL {
return NO;
}] waitWithTimeout:1];
#pragma clang diagnostic pop
[ChromeEarlGrey selectTabAtIndex:1];
[ChromeEarlGrey waitForPageToFinishLoading];
// Verify url.
......@@ -274,8 +262,6 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
// Tests that system touches are cancelled when the context menu is shown.
- (void)testContextMenuCancelSystemTouchesMetric {
chrome_test_util::HistogramTester histogramTester;
const GURL pageURL = self.testServer->GetURL(kLogoPagePath);
[ChromeEarlGrey loadURL:pageURL];
[ChromeEarlGrey waitForWebStateContainingText:kLogoPageText];
......@@ -284,18 +270,15 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
TapOnContextMenuButton(OpenImageButton());
[ChromeEarlGrey waitForPageToFinishLoading];
// Verify that system touches were cancelled.
histogramTester.ExpectTotalCount("ContextMenu.CancelSystemTouches", 1,
^(NSString* error) {
GREYFail(error);
});
// Verify that system touches were cancelled by ensuring the system text
// selection callout is not displayed.
[[EarlGrey selectElementWithMatcher:SystemSelectionCalloutCopyButton()]
assertWithMatcher:grey_nil()];
}
// Tests that the system selected text callout is displayed instead of the
// context menu when user long presses on plain text.
- (void)testContextMenuSelectedTextCallout {
chrome_test_util::HistogramTester histogramTester;
// Load the destination page directly because it has a plain text message on
// it.
const GURL destinationURL = self.testServer->GetURL(kDestinationPageUrl);
......@@ -311,12 +294,6 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
// Verify that system text selection callout is displayed.
[[EarlGrey selectElementWithMatcher:SystemSelectionCalloutCopyButton()]
assertWithMatcher:grey_notNil()];
// Verify that system touches were not cancelled.
histogramTester.ExpectTotalCount("ContextMenu.CancelSystemTouches", 0,
^(NSString* error) {
GREYFail(error);
});
}
// Tests cancelling the context menu.
......
......@@ -41,6 +41,8 @@ source_set("eg_test_support") {
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/test/app:test_support",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/ui",
]
}
......@@ -56,6 +58,8 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/test/app:test_support",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/ui",
]
}
......
......@@ -12,6 +12,9 @@
// app or test code.
@interface FullscreenAppInterface : NSObject
// Whether or not the fullscreen provider has been initialized.
+ (BOOL)isFullscreenInitialized;
// Returns the current viewport insets for the visible web content view.
+ (UIEdgeInsets)currentViewportInsets;
......
......@@ -8,6 +8,8 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h"
#import "ios/chrome/test/app/tab_test_util.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/ui/fullscreen_provider.h"
#import "ios/web/public/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -16,6 +18,12 @@
@implementation FullscreenAppInterface
+ (BOOL)isFullscreenInitialized {
return ios::GetChromeBrowserProvider()
->GetFullscreenProvider()
->IsInitialized();
}
+ (UIEdgeInsets)currentViewportInsets {
web::WebState* webState = chrome_test_util::GetCurrentWebState();
if (!webState)
......
......@@ -370,6 +370,13 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// of EG1, by simply doing a tab grid close all / undo / done.
- (void)triggerRestoreViaTabGridRemoveAllUndo;
// Returns YES if the current WebState's web view uses the content inset to
// correctly align the top of the content with the bottom of the top bar.
- (BOOL)webStateWebViewUsesContentInset;
// Returns the size of the current WebState's web view.
- (CGSize)webStateWebViewSize;
#pragma mark - Bookmarks Utilities (EG2)
// Waits for the bookmark internal state to be done loading.
......
......@@ -529,6 +529,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
[self waitForPageToFinishLoading];
}
- (BOOL)webStateWebViewUsesContentInset {
return [ChromeEarlGreyAppInterface webStateWebViewUsesContentInset];
}
- (CGSize)webStateWebViewSize {
return [ChromeEarlGreyAppInterface webStateWebViewSize];
}
#pragma mark - Settings Utilities (EG2)
- (void)setContentSettings:(ContentSetting)setting {
......
......@@ -194,6 +194,13 @@
// restoring session state.
+ (BOOL)isRestoreSessionInProgress;
// Returns YES if the current WebState's web view uses the content inset to
// correctly align the top of the content with the bottom of the top bar.
+ (BOOL)webStateWebViewUsesContentInset;
// Returns the size of the current WebState's web view.
+ (CGSize)webStateWebViewSize;
#pragma mark - Sync Utilities (EG2)
// Clears the autofill profile for the given |GUID|.
......
......@@ -39,6 +39,7 @@
#include "ios/web/public/test/url_test_util.h"
#import "ios/web/public/test/web_view_content_test_util.h"
#import "ios/web/public/test/web_view_interaction_test_util.h"
#import "ios/web/public/ui/crw_web_view_proxy.h"
#import "ios/web/public/web_client.h"
#import "ios/web/public/web_state.h"
#import "services/metrics/public/cpp/ukm_recorder.h"
......@@ -342,6 +343,16 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
return web_state->GetNavigationManager()->IsRestoreSessionInProgress();
}
+ (BOOL)webStateWebViewUsesContentInset {
web::WebState* web_state = chrome_test_util::GetCurrentWebState();
return web_state->GetWebViewProxy().shouldUseViewContentInset;
}
+ (CGSize)webStateWebViewSize {
web::WebState* web_state = chrome_test_util::GetCurrentWebState();
return [web_state->GetWebViewProxy() bounds].size;
}
#pragma mark - Sync Utilities (EG2)
+ (void)clearAutofillProfileWithGUID:(NSString*)GUID {
......
......@@ -36,6 +36,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") {
deps = [
"//ios/chrome/browser/autofill:eg2_tests",
"//ios/chrome/browser/context_menu:eg2_tests",
"//ios/chrome/browser/device_sharing:eg2_tests",
"//ios/chrome/browser/net:eg2_tests",
"//ios/chrome/browser/ntp_tiles: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