Commit d6574afa authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Add support for side_swipe in EG2.

Also adds helpers for isCompactHeight and isSplitToolbarMode in
ChromeEarlGreyImpl.

Bug: 987646
Change-Id: Id8f48a0e126faab215ffb6ed8d2e306b13f33bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864355
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Auto-Submit: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707040}
parent 1e070364
...@@ -71,6 +71,7 @@ source_set("unit_tests") { ...@@ -71,6 +71,7 @@ source_set("unit_tests") {
source_set("eg_tests") { source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true testonly = true
sources = [ sources = [
"side_swipe_egtest.mm", "side_swipe_egtest.mm",
...@@ -90,3 +91,24 @@ source_set("eg_tests") { ...@@ -90,3 +91,24 @@ source_set("eg_tests") {
] ]
libs = [ "XCTest.framework" ] libs = [ "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 = [
"side_swipe_egtest.mm",
]
deps = [
"//base",
"//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/http_server",
"//net:test_support",
]
libs = [ "UIKit.framework" ]
}
...@@ -2,17 +2,12 @@ ...@@ -2,17 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#import "ios/chrome/browser/ui/toolbar/primary_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/secondary_toolbar_view.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.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"
#include "ios/testing/earl_grey/disabled_test_macros.h" #include "ios/testing/earl_grey/disabled_test_macros.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/default_handlers.h" #include "net/test/embedded_test_server/default_handlers.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -29,24 +24,24 @@ ...@@ -29,24 +24,24 @@
// Tests that swiping horizontally on the bottom toolbar is changing tab. // Tests that swiping horizontally on the bottom toolbar is changing tab.
- (void)testSideSwipeBottomToolbar { - (void)testSideSwipeBottomToolbar {
if (!IsSplitToolbarMode()) { if (![ChromeEarlGrey isSplitToolbarMode]) {
EARL_GREY_TEST_SKIPPED( EARL_GREY_TEST_SKIPPED(
@"This tests should only be tested if the secondary toolbar is " @"This tests should only be tested if the secondary toolbar is "
@"present"); @"present");
} }
[self checkSideSwipeOnToolbarClass:[SecondaryToolbarView class]]; [self checkSideSwipeOnToolbarClassName:@"SecondaryToolbarView"];
} }
// Tests that swiping horizontally on the top toolbar is changing tab. // Tests that swiping horizontally on the top toolbar is changing tab.
- (void)testSideSwipeTopToolbar { - (void)testSideSwipeTopToolbar {
[self checkSideSwipeOnToolbarClass:[PrimaryToolbarView class]]; [self checkSideSwipeOnToolbarClassName:@"PrimaryToolbarView"];
} }
#pragma mark - Helpers #pragma mark - Helpers
// Checks that side swipe on an element of class |klass| is working to change // Checks that side swipe on an element of class |klass| is working to change
// tab. // tab.
- (void)checkSideSwipeOnToolbarClass:(Class)klass { - (void)checkSideSwipeOnToolbarClassName:(NSString*)className {
// Setup the server. // Setup the server.
net::test_server::RegisterDefaultHandlers(self.testServer); net::test_server::RegisterDefaultHandlers(self.testServer);
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start."); GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
...@@ -63,7 +58,7 @@ ...@@ -63,7 +58,7 @@
[ChromeEarlGrey waitForWebStateContainingText:"Default response"]; [ChromeEarlGrey waitForWebStateContainingText:"Default response"];
// Side swipe on the toolbar. // Side swipe on the toolbar.
[[EarlGrey selectElementWithMatcher:grey_kindOfClass(klass)] [[EarlGrey selectElementWithMatcher:grey_kindOfClassName(className)]
performAction:grey_swipeSlowInDirection(kGREYDirectionRight)]; performAction:grey_swipeSlowInDirection(kGREYDirectionRight)];
// Check that we swiped back to our web page. // Check that we swiped back to our web page.
......
...@@ -47,6 +47,14 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -47,6 +47,14 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// horizontal size class. // horizontal size class.
- (BOOL)isCompactWidth; - (BOOL)isCompactWidth;
// Returns YES if the main application window's rootViewController has a compact
// vertical size class.
- (BOOL)isCompactHeight;
// Returns whether the toolbar is split between top and bottom toolbar or if it
// is displayed as only one toolbar.
- (BOOL)isSplitToolbarMode;
#pragma mark - History Utilities (EG2) #pragma mark - History Utilities (EG2)
// Clears browsing history. Raises an EarlGrey exception if history is not // Clears browsing history. Raises an EarlGrey exception if history is not
// cleared within a timeout. // cleared within a timeout.
......
...@@ -78,18 +78,33 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -78,18 +78,33 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
} }
- (BOOL)isCompactWidth { - (BOOL)isCompactWidth {
#if defined(CHROME_EARL_GREY_1)
UIUserInterfaceSizeClass horizontalSpace = UIUserInterfaceSizeClass horizontalSpace =
#if defined(CHROME_EARL_GREY_1)
[[[[UIApplication sharedApplication] keyWindow] traitCollection] [[[[UIApplication sharedApplication] keyWindow] traitCollection]
horizontalSizeClass]; horizontalSizeClass];
#elif defined(CHROME_EARL_GREY_2) #elif defined(CHROME_EARL_GREY_2)
UIUserInterfaceSizeClass horizontalSpace =
[[[[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] keyWindow] [[[[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] keyWindow]
traitCollection] horizontalSizeClass]; traitCollection] horizontalSizeClass];
#endif #endif
return horizontalSpace == UIUserInterfaceSizeClassCompact; return horizontalSpace == UIUserInterfaceSizeClassCompact;
} }
- (BOOL)isCompactHeight {
UIUserInterfaceSizeClass verticalSpace =
#if defined(CHROME_EARL_GREY_1)
[[[[UIApplication sharedApplication] keyWindow] traitCollection]
verticalSizeClass];
#elif defined(CHROME_EARL_GREY_2)
[[[[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] keyWindow]
traitCollection] verticalSizeClass];
#endif
return verticalSpace == UIUserInterfaceSizeClassCompact;
}
- (BOOL)isSplitToolbarMode {
return [self isCompactWidth] && ![self isCompactHeight];
}
#pragma mark - History Utilities (EG2) #pragma mark - History Utilities (EG2)
- (void)clearBrowsingHistory { - (void)clearBrowsingHistory {
......
...@@ -58,6 +58,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") { ...@@ -58,6 +58,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/page_info:eg2_tests", "//ios/chrome/browser/ui/page_info:eg2_tests",
"//ios/chrome/browser/ui/sad_tab:eg2_tests", "//ios/chrome/browser/ui/sad_tab:eg2_tests",
"//ios/chrome/browser/ui/settings/autofill:eg2_tests", "//ios/chrome/browser/ui/settings/autofill:eg2_tests",
"//ios/chrome/browser/ui/side_swipe:eg2_tests",
"//ios/chrome/browser/ui/tabs:eg2_tests", "//ios/chrome/browser/ui/tabs:eg2_tests",
"//ios/chrome/browser/ui/toolbar: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