Commit 254044d9 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][EG2] Add a common method for rotation

This adds a common method to our testing class that can be used in EG1
and EG2.
|EarlGrey| has 2 methods to rotate the device, once for EG1 and another
for EG2. Which makes this check pretty common in the EG2 migration.
Adding it to the base test class instead of to |EarlGrey| to avoid
creating a 3rd method signature for it. Once EG1 support is removed a
simple search and replace can be used to clean this.

Bug: 1016368

Change-Id: I24b2c4ae56266111e6069990252164090df80bb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1871874
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708696}
parent 1330d786
......@@ -30,14 +30,8 @@
}
if ([[UIDevice currentDevice] orientation] != UIDeviceOrientationPortrait) {
#if defined(CHROME_EARL_GREY_1)
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait error:nil];
#else
#error Neither CHROME_EARL_GREY_1 nor CHROME_EARL_GREY_2 are defined
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
}
[ChromeEarlGrey loadURL:GURL("https://invalid")];
......@@ -54,16 +48,8 @@
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kPageInfoViewAccessibilityIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
#if defined(CHROME_EARL_GREY_1)
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight
error:nil];
#else
#error Neither CHROME_EARL_GREY_1 nor CHROME_EARL_GREY_2 are defined
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight
error:nil];
// Expect that the page info view has disappeared.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
......
......@@ -30,17 +30,6 @@ using chrome_test_util::TabGridOpenTabsPanelButton;
namespace {
// Rotates the device to the given orientation.
void RotateDevice(UIDeviceOrientation orientation) {
#if defined(CHROME_EARL_GREY_1)
[EarlGrey rotateDeviceToOrientation:orientation errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:orientation error:nil];
#else
#error
#endif
}
// Shows the tab switcher by tapping the switcher button. Works on both phone
// and tablet.
void ShowTabSwitcher() {
......@@ -108,7 +97,8 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Rotate the device back to portrait if needed, since some tests attempt to run
// in landscape.
- (void)tearDown {
RotateDevice(UIDeviceOrientationPortrait);
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
[super tearDown];
}
......@@ -370,21 +360,24 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab_title]];
// Show the tab switcher and return to the BVC, in portrait.
RotateDevice(UIDeviceOrientationPortrait);
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
ShowTabSwitcher();
SelectTab(tab_title);
[ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
// Show the tab switcher and return to the BVC, in landscape.
RotateDevice(UIDeviceOrientationLandscapeLeft);
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
error:nil];
ShowTabSwitcher();
SelectTab(tab_title);
[ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
// Show the tab switcher and return to the BVC, in portrait.
RotateDevice(UIDeviceOrientationPortrait);
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
ShowTabSwitcher();
SelectTab(tab_title);
[ChromeEarlGrey
......
......@@ -202,12 +202,8 @@ UITraitCollection* RotateOrChangeTraitCollection(
forViewController:topViewController];
} else {
// On iPhone rotate to test the the landscape orientation.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
#if defined(CHROME_EARL_GREY_1)
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
error:nil];
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
error:nil];
return topViewController.traitCollection;
}
}
......@@ -496,12 +492,8 @@ UIViewController* TopPresentedViewController() {
}
} else {
// Cancel the rotation.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
#if defined(CHROME_EARL_GREY_1)
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
error:nil];
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
}
// Check the visiblity after a rotation.
......@@ -539,12 +531,8 @@ UIViewController* TopPresentedViewController() {
}
} else {
// Cancel the rotation.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
#if defined(CHROME_EARL_GREY_1)
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
error:nil];
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
}
// Check the visiblity after a size class change. This should let the trait
......@@ -721,12 +709,8 @@ UIViewController* TopPresentedViewController() {
- (void)testShareButton {
if (![ChromeEarlGrey isIPadIdiom]) {
// If this test is run on an iPhone, rotate it to have the unsplit toolbar.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
#if defined(CHROME_EARL_GREY_1)
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
error:nil];
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
error:nil];
}
// Setup the server.
......@@ -742,12 +726,8 @@ UIViewController* TopPresentedViewController() {
if (![ChromeEarlGrey isIPadIdiom]) {
// Cancel rotation.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
#if defined(CHROME_EARL_GREY_1)
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
error:nil];
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
}
}
......@@ -808,12 +788,8 @@ UIViewController* TopPresentedViewController() {
}
} else {
// Cancel the rotation.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
#if defined(CHROME_EARL_GREY_1)
errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
error:nil];
#endif
[ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
error:nil];
}
}
......
......@@ -5,7 +5,7 @@
#ifndef IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_H_
#define IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_H_
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include <string>
......@@ -40,6 +40,11 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
#pragma mark - Device Utilities
// Simulate the user action to rotate the device to a certain orientation.
// TODO(crbug.com/1017265): Remove along EG1 support.
- (void)rotateDeviceToOrientation:(UIDeviceOrientation)deviceOrientation
error:(NSError**)error;
// Returns YES if running on an iPad.
- (BOOL)isIPadIdiom;
......
......@@ -66,6 +66,21 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
#pragma mark - Device Utilities
- (void)rotateDeviceToOrientation:(UIDeviceOrientation)deviceOrientation
error:(NSError**)error {
#if defined(CHROME_EARL_GREY_1)
NSError* strongErrorReference = nil;
[EarlGrey rotateDeviceToOrientation:deviceOrientation
errorOrNil:&strongErrorReference];
if (error)
*error = strongErrorReference;
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:deviceOrientation error:error];
#else
#error Neither CHROME_EARL_GREY_1 nor CHROME_EARL_GREY_2 are defined
#endif
}
- (BOOL)isIPadIdiom {
#if defined(CHROME_EARL_GREY_1)
UIUserInterfaceIdiom idiom = [[UIDevice currentDevice] userInterfaceIdiom];
......
......@@ -271,13 +271,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
if (GetCurrentDeviceOrientation() != _originalOrientation) {
// Rotate the device back to the original orientation, since some tests
// attempt to run in other orientations.
#if defined(CHROME_EARL_GREY_1)
[EarlGrey rotateDeviceToOrientation:_originalOrientation errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:_originalOrientation error:nil];
#else
#error Neither CHROME_EARL_GREY_1 nor CHROME_EARL_GREY_2 are defined
#endif
[ChromeEarlGrey rotateDeviceToOrientation:_originalOrientation error:nil];
}
[super tearDown];
_executedTestMethodSetUp = NO;
......
......@@ -114,6 +114,8 @@ bool g_needs_set_up_for_test_case = true;
forceRestart:NO];
}
#pragma mark - Private
// Prevents tests inheriting from this class from putting logic in +setUp.
// +setUp will be called before the application is launched,
// and thus is not suitable for most test case setup. Inheriting tests should
......
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