Commit 77fdec7b authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Fix undocking tests on iOS 13

Reenable undocking and docking the keyboard on iPad tests.

Bug: 985977
Change-Id: I2744a197ee1d0592fd03229e61bc0ac651178afb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1814917
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705528}
parent 0583f458
...@@ -161,41 +161,33 @@ UIAccessibilityElement* KeyboardDismissKeyInLayout(UIView* layout) { ...@@ -161,41 +161,33 @@ UIAccessibilityElement* KeyboardDismissKeyInLayout(UIView* layout) {
return key; return key;
} }
// Finds the first view containing the keyboard which origin is not zero. // Matcher for the Keyboard Window.
UIView* KeyboardContainerForLayout(UIView* layout) { id<GREYMatcher> KeyboardWindow(UIView* layout) {
CGRect frame = CGRectZero; id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
UIView* keyboardContainer = layout; UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout);
while (CGPointEqualToPoint(frame.origin, CGPointZero) && keyboardContainer) { id<GREYMatcher> parentMatcher =
keyboardContainer = [keyboardContainer superview]; grey_descendant(grey_accessibilityLabel(key.accessibilityLabel));
if (keyboardContainer) { return grey_allOf(classMatcher, parentMatcher, nil);
frame = keyboardContainer.frame;
}
}
return keyboardContainer;
} }
// Returns YES if the keyboard is docked at the bottom. NO otherwise. // Returns YES if the keyboard is docked at the bottom. NO otherwise.
BOOL IsKeyboardDockedForLayout(UIView* layout) { BOOL IsKeyboardDockedForLayout(UIView* layout) {
UIView* keyboardContainer = KeyboardContainerForLayout(layout); CGRect keyboardFrameInWindow = [layout.window convertRect:layout.bounds
CGRect screenBounds = [[UIScreen mainScreen] bounds]; fromView:layout];
CGFloat maxY = CGRectGetMaxY(keyboardContainer.frame); CGRect windowBounds = layout.window.bounds;
return [@(maxY) isEqualToNumber:@(screenBounds.size.height)]; CGFloat maxY = CGRectGetMaxY(keyboardFrameInWindow);
return [@(maxY) isEqualToNumber:@(windowBounds.size.height)];
} }
// Undocks and split the keyboard by swiping it up. Does nothing if already // Undocks and split the keyboard by swiping it up. Does nothing if already
// undocked. Only works on iOS 12; it is an error to call this method on // undocked. Some devices, like iPhone or iPad Pro, do not allow undocking or
// iOS 13. Some devices, like iPhone or iPad Pro, do not allow undocking or
// splitting, this returns NO if it is the case. // splitting, this returns NO if it is the case.
BOOL UndockAndSplitKeyboard() { BOOL UndockAndSplitKeyboard() {
if (![ChromeEarlGrey isIPadIdiom]) { if (![ChromeEarlGrey isIPadIdiom]) {
return NO; return NO;
} }
// TODO(crbug.com/985977): Remove this DCHECK once this method is updated to
// support iOS 13.
DCHECK(!base::ios::IsRunningOnIOS13OrLater())
<< "Undocking the keyboard via this method does not work on iOS 13";
UITextField* textField = ShowKeyboard(); UITextField* textField = ShowKeyboard();
// Assert the "Dismiss-Key" is present. // Assert the "Dismiss-Key" is present.
...@@ -215,38 +207,34 @@ BOOL UndockAndSplitKeyboard() { ...@@ -215,38 +207,34 @@ BOOL UndockAndSplitKeyboard() {
layout.accessibilityIdentifier = @"CRKBLayout"; layout.accessibilityIdentifier = @"CRKBLayout";
} }
id<GREYMatcher> matcher =
grey_accessibilityID(layout.accessibilityIdentifier);
UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout); UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout);
CGRect keyFrame = [key accessibilityFrame]; CGRect keyFrameInScreen = [key accessibilityFrame];
CGRect keyboardContainerFrame = KeyboardContainerForLayout(layout).frame; CGRect keyFrameInWindow = [UIScreen.mainScreen.coordinateSpace
CGPoint pointToKey = {keyFrame.origin.x - keyboardContainerFrame.origin.x, convertRect:keyFrameInScreen
keyFrame.origin.y - keyboardContainerFrame.origin.y}; toCoordinateSpace:layout.window.coordinateSpace];
CGPoint startPoint = CGPointMake((pointToKey.x + keyFrame.size.width / 2.0) / CGRect windowBounds = layout.window.bounds;
keyboardContainerFrame.size.width,
(pointToKey.y + keyFrame.size.height / 2.0) / CGPoint startPoint = CGPointMake(
keyboardContainerFrame.size.height); (keyFrameInWindow.origin.x + keyFrameInWindow.size.width / 2.0) /
windowBounds.size.width,
(keyFrameInWindow.origin.y + keyFrameInWindow.size.height / 2.0) /
windowBounds.size.height);
id action = grey_swipeFastInDirectionWithStartPoint( id action = grey_swipeFastInDirectionWithStartPoint(
kGREYDirectionUp, startPoint.x, startPoint.y); kGREYDirectionUp, startPoint.x, startPoint.y);
[[EarlGrey selectElementWithMatcher:matcher] performAction:action];
[[EarlGrey selectElementWithMatcher:KeyboardWindow(layout)]
performAction:action];
return !IsKeyboardDockedForLayout(layout); return !IsKeyboardDockedForLayout(layout);
} }
// Docks the keyboard by swiping it down. Does nothing if already docked. Only // Docks the keyboard by swiping it down. Does nothing if already docked.
// works on iOS 12; it is an error to call this method on iOS 13.
void DockKeyboard() { void DockKeyboard() {
if (![ChromeEarlGrey isIPadIdiom]) { if (![ChromeEarlGrey isIPadIdiom]) {
return; return;
} }
// TODO(crbug.com/985977): Remove this DCHECK once this method is updated to
// support iOS 13.
DCHECK(!base::ios::IsRunningOnIOS13OrLater())
<< "Docking the keyboard via this method does not work on iOS 13";
UITextField* textField = ShowKeyboard(); UITextField* textField = ShowKeyboard();
// Assert the "Dismiss-Key" is present. // Assert the "Dismiss-Key" is present.
...@@ -262,30 +250,39 @@ void DockKeyboard() { ...@@ -262,30 +250,39 @@ void DockKeyboard() {
} }
// Swipe it down. // Swipe it down.
id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout); UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout);
id<GREYMatcher> parentMatcher =
grey_descendant(grey_accessibilityLabel(key.accessibilityLabel));
id matcher = grey_allOf(classMatcher, parentMatcher, nil);
CGRect keyFrame = [key accessibilityFrame]; CGRect keyFrameInScreen = [key accessibilityFrame];
GREYAssertFalse(CGRectEqualToRect(keyFrame, CGRectZero), CGRect keyFrameInWindow = [UIScreen.mainScreen.coordinateSpace
convertRect:keyFrameInScreen
toCoordinateSpace:layout.window.coordinateSpace];
CGRect windowBounds = layout.window.bounds;
GREYAssertFalse(CGRectEqualToRect(keyFrameInWindow, CGRectZero),
@"The dismiss key accessibility frame musn't be zero"); @"The dismiss key accessibility frame musn't be zero");
CGPoint startPoint = CGPoint startPoint = CGPointMake(
CGPointMake((keyFrame.origin.x + keyFrame.size.width / 2.0) / (keyFrameInWindow.origin.x + keyFrameInWindow.size.width / 2.0) /
[UIScreen mainScreen].bounds.size.width, windowBounds.size.width,
(keyFrame.origin.y + keyFrame.size.height / 2.0) / (keyFrameInWindow.origin.y + keyFrameInWindow.size.height / 2.0) /
[UIScreen mainScreen].bounds.size.height); windowBounds.size.height);
id<GREYAction> action = grey_swipeFastInDirectionWithStartPoint( id<GREYAction> action = grey_swipeFastInDirectionWithStartPoint(
kGREYDirectionDown, startPoint.x, startPoint.y); kGREYDirectionDown, startPoint.x, startPoint.y);
[[EarlGrey selectElementWithMatcher:matcher] performAction:action]; [[EarlGrey selectElementWithMatcher:KeyboardWindow(layout)]
performAction:action];
// If we created a dummy textfield for this, remove it. // If we created a dummy textfield for this, remove it.
[textField removeFromSuperview]; [textField removeFromSuperview];
GREYAssertTrue(IsKeyboardDockedForLayout(layout), GREYCondition* waitForDockedKeyboard =
@"Keyboard should be docked"); [GREYCondition conditionWithName:@"Wait For Docked Keyboard Animations"
block:^BOOL {
return IsKeyboardDockedForLayout(layout);
}];
GREYAssertTrue([waitForDockedKeyboard
waitWithTimeout:base::test::ios::kWaitForActionTimeout],
@"Keyboard animations still present.");
} }
} // namespace } // namespace
...@@ -382,11 +379,6 @@ void DockKeyboard() { ...@@ -382,11 +379,6 @@ void DockKeyboard() {
[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITableView class])] [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITableView class])]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
if (!base::ios::IsRunningOnIOS13OrLater()) {
// TODO(crbug.com/985977): Remove this conditional once DockKeyboard() is
// updated to support iOS 13.
DockKeyboard();
}
[super tearDown]; [super tearDown];
} }
...@@ -558,11 +550,6 @@ void DockKeyboard() { ...@@ -558,11 +550,6 @@ void DockKeyboard() {
EARL_GREY_TEST_SKIPPED(@"Test not applicable for iPhone."); EARL_GREY_TEST_SKIPPED(@"Test not applicable for iPhone.");
} }
// TODO(crbug.com/985977): Reenable once undocking is supported on iOS 13.
if (base::ios::IsRunningOnIOS13OrLater()) {
EARL_GREY_TEST_DISABLED(@"Undocking the keyboard does not work on iOS 13");
}
// Add the profile to be used. // Add the profile to be used.
AddAutofillProfile(_personalDataManager); AddAutofillProfile(_personalDataManager);
...@@ -636,11 +623,6 @@ void DockKeyboard() { ...@@ -636,11 +623,6 @@ void DockKeyboard() {
EARL_GREY_TEST_SKIPPED(@"Test not applicable for iPhone."); EARL_GREY_TEST_SKIPPED(@"Test not applicable for iPhone.");
} }
// TODO(crbug.com/985977): Reenable once undocking is supported on iOS 13.
if (base::ios::IsRunningOnIOS13OrLater()) {
EARL_GREY_TEST_DISABLED(@"Undocking the keyboard does not work on iOS 13");
}
// Add the profile to use for verification. // Add the profile to use for verification.
AddAutofillProfile(_personalDataManager); AddAutofillProfile(_personalDataManager);
......
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