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