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

[iOS][EG2] Create keyboard app interface

Create an app interface for the app code in fallback_coordinator_egtest
related to the keyboard.
Move the code from the test to this interface so it can be used later
to migrate the test to EG2.

Bug: 1017175
Change-Id: I08a85c003a1797d2ef5fa0cd8e4ec444dd05fb3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876392
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708952}
parent f2ac6241
...@@ -62,7 +62,7 @@ source_set("manual_fill") { ...@@ -62,7 +62,7 @@ source_set("manual_fill") {
"//ios/web/public", "//ios/web/public",
"//ios/web/public/deprecated", "//ios/web/public/deprecated",
"//ios/web/public/js_messaging", "//ios/web/public/js_messaging",
"//ui/base:base", "//ui/base",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
...@@ -183,7 +183,7 @@ source_set("requesters") { ...@@ -183,7 +183,7 @@ source_set("requesters") {
"//ios/chrome/browser/web_state_list:web_state_list", "//ios/chrome/browser/web_state_list:web_state_list",
"//ios/web/public:public", "//ios/web/public:public",
"//ios/web/public/js_messaging", "//ios/web/public/js_messaging",
"//ui/base:base", "//ui/base",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#import <EarlGrey/EarlGrey.h> #import <EarlGrey/EarlGrey.h>
#import <EarlGrey/GREYAppleInternals.h> #import <EarlGrey/GREYAppleInternals.h>
#import <EarlGrey/GREYKeyboard.h> #import <EarlGrey/GREYKeyboard.h>
#include <atomic>
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -25,6 +24,7 @@ ...@@ -25,6 +24,7 @@
#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"
#import "ios/testing/earl_grey/keyboard_app_interface.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h" #import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ios/web/public/test/element_selector.h" #include "ios/web/public/test/element_selector.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
...@@ -43,10 +43,6 @@ constexpr char kFormElementCity[] = "city"; ...@@ -43,10 +43,6 @@ constexpr char kFormElementCity[] = "city";
constexpr char kFormHTMLFile[] = "/profile_form.html"; constexpr char kFormHTMLFile[] = "/profile_form.html";
// EarlGrey fails to detect undocked keyboards on screen, so this help check
// for them.
static std::atomic_bool gCHRIsKeyboardShown(false);
// Returns a matcher for the scroll view in keyboard accessory bar. // Returns a matcher for the scroll view in keyboard accessory bar.
id<GREYMatcher> FormSuggestionViewMatcher() { id<GREYMatcher> FormSuggestionViewMatcher() {
return grey_accessibilityID(kFormSuggestionsViewAccessibilityIdentifier); return grey_accessibilityID(kFormSuggestionsViewAccessibilityIdentifier);
...@@ -118,75 +114,6 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -118,75 +114,6 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
return [condition waitWithTimeout:timeout]; return [condition waitWithTimeout:timeout];
} }
// If the keyboard is not present this will add a text field to the hierarchy,
// make it first responder and return it. If it is already present, this does
// nothing and returns nil.
UITextField* ShowKeyboard() {
UITextField* textField = nil;
if (!gCHRIsKeyboardShown) {
CGRect rect = CGRectMake(0, 0, 300, 100);
textField = [[UITextField alloc] initWithFrame:rect];
textField.backgroundColor = [UIColor blueColor];
[[[UIApplication sharedApplication] keyWindow] addSubview:textField];
[textField becomeFirstResponder];
}
auto verify_block = ^BOOL {
return gCHRIsKeyboardShown;
};
NSTimeInterval timeout = base::test::ios::kWaitForUIElementTimeout;
NSString* condition_name =
[NSString stringWithFormat:@"Wait for keyboard to appear"];
GREYCondition* condition = [GREYCondition conditionWithName:condition_name
block:verify_block];
[condition waitWithTimeout:timeout];
return textField;
}
// Returns the dismiss key if present in the passed keyboard layout. Returns nil
// if not found.
UIAccessibilityElement* KeyboardDismissKeyInLayout(UIView* layout) {
UIAccessibilityElement* key = nil;
if ([layout accessibilityElementCount] != NSNotFound) {
for (NSInteger i = [layout accessibilityElementCount]; i >= 0; --i) {
id element = [layout accessibilityElementAtIndex:i];
if ([[[element key] valueForKey:@"name"]
isEqualToString:@"Dismiss-Key"]) {
key = element;
break;
}
}
}
return key;
}
// Matcher for the Keyboard Window.
id<GREYMatcher> KeyboardWindow(UIView* layout) {
id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout);
id<GREYMatcher> parentMatcher =
grey_descendant(grey_accessibilityLabel(key.accessibilityLabel));
return grey_allOf(classMatcher, parentMatcher, nil);
}
// Returns YES if the keyboard is docked at the bottom. NO otherwise.
BOOL IsKeyboardDockedForLayout(UIView* layout) {
CGRect windowBounds = layout.window.bounds;
UIView* viewToCompare = layout;
while (viewToCompare &&
viewToCompare.bounds.size.height < windowBounds.size.height) {
CGRect keyboardFrameInWindow =
[viewToCompare.window convertRect:viewToCompare.bounds
fromView:viewToCompare];
CGFloat maxY = CGRectGetMaxY(keyboardFrameInWindow);
if ([@(maxY) isEqualToNumber:@(windowBounds.size.height)]) {
return YES;
}
viewToCompare = viewToCompare.superview;
}
return NO;
}
// 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. Some devices, like iPhone or iPad Pro, do not allow undocking or // undocked. 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.
...@@ -194,46 +121,23 @@ BOOL UndockAndSplitKeyboard() { ...@@ -194,46 +121,23 @@ BOOL UndockAndSplitKeyboard() {
if (![ChromeEarlGrey isIPadIdiom]) { if (![ChromeEarlGrey isIPadIdiom]) {
return NO; return NO;
} }
UITextField* textField = [KeyboardAppInterface showKeyboard];
UITextField* textField = ShowKeyboard();
// Assert the "Dismiss-Key" is present.
UIView* layout = [[UIKeyboardImpl sharedInstance] _layout];
GREYAssert([[layout valueForKey:@"keyplaneContainsDismissKey"] boolValue],
@"No dismiss key is pressent");
// Return if already undocked. // Return if already undocked.
if (!IsKeyboardDockedForLayout(layout)) { if (![KeyboardAppInterface isKeyboadDocked]) {
// If we created a dummy textfield for this, remove it. // If a dummy textfield was created for this, remove it.
[textField removeFromSuperview]; [textField removeFromSuperview];
return YES; return YES;
} }
// Swipe it up. [[EarlGrey
if (!layout.accessibilityIdentifier.length) { selectElementWithMatcher:[KeyboardAppInterface keyboardWindowMatcher]]
layout.accessibilityIdentifier = @"CRKBLayout"; performAction:[KeyboardAppInterface keyboardUndockAction]];
}
UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout);
CGRect keyFrameInScreen = [key accessibilityFrame];
CGRect keyFrameInWindow = [UIScreen.mainScreen.coordinateSpace
convertRect:keyFrameInScreen
toCoordinateSpace:layout.window.coordinateSpace];
CGRect windowBounds = layout.window.bounds;
CGPoint startPoint = CGPointMake(
(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( // If a dummy textfield was created for this, remove it.
kGREYDirectionUp, startPoint.x, startPoint.y); [textField removeFromSuperview];
[[EarlGrey selectElementWithMatcher:KeyboardWindow(layout)]
performAction:action];
return !IsKeyboardDockedForLayout(layout); return ![KeyboardAppInterface isKeyboadDocked];
} }
// Docks the keyboard by swiping it down. Does nothing if already docked. // Docks the keyboard by swiping it down. Does nothing if already docked.
...@@ -242,56 +146,33 @@ void DockKeyboard() { ...@@ -242,56 +146,33 @@ void DockKeyboard() {
return; return;
} }
UITextField* textField = ShowKeyboard(); UITextField* textField = [KeyboardAppInterface showKeyboard];
// Assert the "Dismiss-Key" is present.
UIView* layout = [[UIKeyboardImpl sharedInstance] _layout];
GREYAssert([[layout valueForKey:@"keyplaneContainsDismissKey"] boolValue],
@"No dismiss key is pressent");
// Return if already docked. // Return if already docked.
if (IsKeyboardDockedForLayout(layout)) { if ([KeyboardAppInterface isKeyboadDocked]) {
// If we created a dummy textfield for this, remove it. // If we created a dummy textfield for this, remove it.
[textField removeFromSuperview]; [textField removeFromSuperview];
return; return;
} }
// Swipe it down. [[EarlGrey
UIAccessibilityElement* key = KeyboardDismissKeyInLayout(layout); selectElementWithMatcher:[KeyboardAppInterface keyboardWindowMatcher]]
performAction:[KeyboardAppInterface keyboardDockAction]];
CGRect keyFrameInScreen = [key accessibilityFrame];
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");
CGPoint startPoint = CGPointMake(
(keyFrameInWindow.origin.x + keyFrameInWindow.size.width / 2.0) /
windowBounds.size.width,
(keyFrameInWindow.origin.y + keyFrameInWindow.size.height / 2.0) /
windowBounds.size.height);
id<GREYAction> action = grey_swipeFastInDirectionWithStartPoint(
kGREYDirectionDown, startPoint.x, startPoint.y);
[[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];
GREYCondition* waitForDockedKeyboard = GREYCondition* waitForDockedKeyboard = [GREYCondition
[GREYCondition conditionWithName:@"Wait For Docked Keyboard Animations" conditionWithName:@"Wait For Docked Keyboard Animations"
block:^BOOL { block:^BOOL {
return IsKeyboardDockedForLayout(layout); BOOL isDocked = [KeyboardAppInterface isKeyboadDocked];
return isDocked;
}]; }];
GREYAssertTrue([waitForDockedKeyboard GREYAssertTrue([waitForDockedKeyboard
waitWithTimeout:base::test::ios::kWaitForActionTimeout], waitWithTimeout:base::test::ios::kWaitForActionTimeout],
@"Keyboard animations still present."); @"Keyboard animations still present.");
} }
} // namespace } // namespace
// Integration Tests for fallback coordinator. // Integration Tests for fallback coordinator.
...@@ -304,41 +185,6 @@ void DockKeyboard() { ...@@ -304,41 +185,6 @@ void DockKeyboard() {
@implementation FallbackCoordinatorTestCase @implementation FallbackCoordinatorTestCase
+ (void)load {
@autoreleasepool {
// EarlGrey fails to detect undocked keyboards on screen, so this help check
// for them.
auto block = ^(NSNotification* note) {
CGRect keyboardFrame =
[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
keyboardFrame = [window convertRect:keyboardFrame fromWindow:nil];
CGRect windowFrame = window.frame;
CGRect frameIntersection = CGRectIntersection(windowFrame, keyboardFrame);
gCHRIsKeyboardShown =
frameIntersection.size.width > 1 && frameIntersection.size.height > 1;
};
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidChangeFrameNotification
object:nil
queue:nil
usingBlock:block];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidShowNotification
object:nil
queue:nil
usingBlock:block];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidHideNotification
object:nil
queue:nil
usingBlock:block];
}
}
+ (void)setUp { + (void)setUp {
[super setUp]; [super setUp];
// If the previous run was manually stopped then the profile will be in the // If the previous run was manually stopped then the profile will be in the
......
...@@ -31,6 +31,8 @@ source_set("earl_grey_support") { ...@@ -31,6 +31,8 @@ source_set("earl_grey_support") {
"earl_grey_app.mm", "earl_grey_app.mm",
"earl_grey_test.h", "earl_grey_test.h",
"earl_grey_test.mm", "earl_grey_test.mm",
"keyboard_app_interface.h",
"keyboard_app_interface.mm",
"matchers.h", "matchers.h",
"matchers.mm", "matchers.mm",
] ]
...@@ -43,6 +45,7 @@ source_set("eg_app_support+eg2") { ...@@ -43,6 +45,7 @@ source_set("eg_app_support+eg2") {
deps = [ deps = [
"//base/test:test_support", "//base/test:test_support",
"//build/config/ios:xctest",
"//ios/third_party/earl_grey2:app_framework+link", "//ios/third_party/earl_grey2:app_framework+link",
"//testing/gtest:gtest", "//testing/gtest:gtest",
] ]
...@@ -54,6 +57,8 @@ source_set("eg_app_support+eg2") { ...@@ -54,6 +57,8 @@ source_set("eg_app_support+eg2") {
"coverage_utils.mm", "coverage_utils.mm",
"earl_grey_app.h", "earl_grey_app.h",
"earl_grey_app.mm", "earl_grey_app.mm",
"keyboard_app_interface.h",
"keyboard_app_interface.mm",
] ]
} }
...@@ -78,6 +83,7 @@ source_set("eg_test_support+eg2") { ...@@ -78,6 +83,7 @@ source_set("eg_test_support+eg2") {
"disabled_test_macros.h", "disabled_test_macros.h",
"earl_grey_test.h", "earl_grey_test.h",
"earl_grey_test.mm", "earl_grey_test.mm",
"keyboard_app_interface.h",
"matchers.h", "matchers.h",
"matchers.mm", "matchers.mm",
] ]
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#if defined(CHROME_EARL_GREY_1) #if defined(CHROME_EARL_GREY_1)
#import <EarlGrey/EarlGrey.h> #import <EarlGrey/EarlGrey.h>
#import <EarlGrey/GREYAppleInternals.h>
#import <EarlGrey/GREYKeyboard.h>
typedef DescribeToBlock GREYDescribeToBlock; typedef DescribeToBlock GREYDescribeToBlock;
typedef MatchesBlock GREYMatchesBlock; typedef MatchesBlock GREYMatchesBlock;
...@@ -30,6 +32,7 @@ void grey_dispatch_sync_on_main_thread(void (^block)(void)); ...@@ -30,6 +32,7 @@ void grey_dispatch_sync_on_main_thread(void (^block)(void));
#import <AppFramework/Matcher/GREYMatchersShorthand.h> #import <AppFramework/Matcher/GREYMatchersShorthand.h>
#import <AppFramework/Synchronization/GREYSyncAPI.h> #import <AppFramework/Synchronization/GREYSyncAPI.h>
#import <CommonLib/Error/GREYErrorConstants.h> #import <CommonLib/Error/GREYErrorConstants.h>
#import <CommonLib/GREYAppleInternals.h>
#else #else
#error Must define either CHROME_EARL_GREY_1 or CHROME_EARL_GREY_2. #error Must define either CHROME_EARL_GREY_1 or CHROME_EARL_GREY_2.
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_TESTING_EARL_GREY_KEYBOARD_APP_INTERFACE_H_
#define IOS_TESTING_EARL_GREY_KEYBOARD_APP_INTERFACE_H_
#import <UIKit/UIKit.h>
@protocol GREYAction;
@protocol GREYMatcher;
// KeyboardAppInterface contains helpers for interacting with the keyboard.
// These are compiled into the app binary and can be called from either app or
// test code.
@interface KeyboardAppInterface : NSObject
// Return a boolean indicating if the keyboard is docked.
+ (BOOL)isKeyboadDocked;
// Matcher for the Keyboard Window.
+ (id<GREYMatcher>)keyboardWindowMatcher;
// Swipe action to undock the keyboard.
+ (id<GREYAction>)keyboardUndockAction;
// Swipe action to dock the keyboard.
+ (id<GREYAction>)keyboardDockAction;
// If the keyboard is not present this will add a text field to the hierarchy,
// make it first responder and return it. If it is already present, this does
// nothing and returns nil.
+ (UITextField*)showKeyboard;
@end
#endif // IOS_TESTING_EARL_GREY_KEYBOARD_APP_INTERFACE_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/testing/earl_grey/keyboard_app_interface.h"
#import <UIKit/UIKit.h>
#include <atomic>
#import "base/test/ios/wait_util.h"
#import "ios/testing/earl_grey/earl_grey_app.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// EarlGrey fails to detect undocked keyboards on screen, so this help check
// for them.
static std::atomic_bool gCHRIsKeyboardShown(false);
// Returns the dismiss key if present in the passed keyboard layout. Returns nil
// if not found.
UIAccessibilityElement* KeyboardDismissKeyInLayout() {
UIView* layout = [[UIKeyboardImpl sharedInstance] _layout];
UIAccessibilityElement* key = nil;
if ([layout accessibilityElementCount] != NSNotFound) {
for (NSInteger i = [layout accessibilityElementCount]; i >= 0; --i) {
id element = [layout accessibilityElementAtIndex:i];
if ([[[element key] valueForKey:@"name"] isEqual:@"Dismiss-Key"]) {
key = element;
break;
}
}
}
return key;
}
// Returns YES if the keyboard is docked at the bottom. NO otherwise.
BOOL IsKeyboardDockedForLayout() {
UIView* layout = [[UIKeyboardImpl sharedInstance] _layout];
CGRect windowBounds = layout.window.bounds;
UIView* viewToCompare = layout;
while (viewToCompare &&
viewToCompare.bounds.size.height < windowBounds.size.height) {
CGRect keyboardFrameInWindow =
[viewToCompare.window convertRect:viewToCompare.bounds
fromView:viewToCompare];
CGFloat maxY = CGRectGetMaxY(keyboardFrameInWindow);
if ([@(maxY) isEqualToNumber:@(windowBounds.size.height)]) {
return YES;
}
viewToCompare = viewToCompare.superview;
}
return NO;
}
} // namespace
@implementation KeyboardAppInterface
+ (void)load {
@autoreleasepool {
// EarlGrey fails to detect undocked keyboards on screen, so this help check
// for them.
auto block = ^(NSNotification* note) {
CGRect keyboardFrame =
[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
keyboardFrame = [window convertRect:keyboardFrame fromWindow:nil];
CGRect windowFrame = window.frame;
CGRect frameIntersection = CGRectIntersection(windowFrame, keyboardFrame);
gCHRIsKeyboardShown =
frameIntersection.size.width > 1 && frameIntersection.size.height > 1;
};
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidChangeFrameNotification
object:nil
queue:nil
usingBlock:block];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidShowNotification
object:nil
queue:nil
usingBlock:block];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidHideNotification
object:nil
queue:nil
usingBlock:block];
}
}
+ (BOOL)isKeyboadDocked {
return IsKeyboardDockedForLayout();
}
+ (id<GREYMatcher>)keyboardWindowMatcher {
id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
UIAccessibilityElement* key = KeyboardDismissKeyInLayout();
id<GREYMatcher> parentMatcher =
grey_descendant(grey_accessibilityLabel(key.accessibilityLabel));
return grey_allOf(classMatcher, parentMatcher, nil);
}
+ (id<GREYAction>)keyboardUndockAction {
UIAccessibilityElement* key = KeyboardDismissKeyInLayout();
CGRect keyFrameInScreen = [key accessibilityFrame];
UIView* layout = [[UIKeyboardImpl sharedInstance] _layout];
CGRect keyFrameInWindow = [UIScreen.mainScreen.coordinateSpace
convertRect:keyFrameInScreen
toCoordinateSpace:layout.window.coordinateSpace];
CGRect windowBounds = layout.window.bounds;
CGPoint startPoint = CGPointMake(
(keyFrameInWindow.origin.x + keyFrameInWindow.size.width / 2.0) /
windowBounds.size.width,
(keyFrameInWindow.origin.y + keyFrameInWindow.size.height / 2.0) /
windowBounds.size.height);
return grey_swipeFastInDirectionWithStartPoint(kGREYDirectionUp, startPoint.x,
startPoint.y);
}
+ (id<GREYAction>)keyboardDockAction {
UIAccessibilityElement* key = KeyboardDismissKeyInLayout();
CGRect keyFrameInScreen = [key accessibilityFrame];
UIView* layout = [[UIKeyboardImpl sharedInstance] _layout];
CGRect keyFrameInWindow = [UIScreen.mainScreen.coordinateSpace
convertRect:keyFrameInScreen
toCoordinateSpace:layout.window.coordinateSpace];
CGRect windowBounds = layout.window.bounds;
CGPoint startPoint = CGPointMake(
(keyFrameInWindow.origin.x + keyFrameInWindow.size.width / 2.0) /
windowBounds.size.width,
(keyFrameInWindow.origin.y + keyFrameInWindow.size.height / 2.0) /
windowBounds.size.height);
return grey_swipeFastInDirectionWithStartPoint(kGREYDirectionDown,
startPoint.x, startPoint.y);
}
// If the keyboard is not present this will add a text field to the hierarchy,
// make it first responder and return it. If it is already present, this does
// nothing and returns nil.
+ (UITextField*)showKeyboard {
UITextField* textField = nil;
if (!gCHRIsKeyboardShown) {
CGRect rect = CGRectMake(0, 0, 300, 100);
textField = [[UITextField alloc] initWithFrame:rect];
textField.backgroundColor = [UIColor blueColor];
[[[UIApplication sharedApplication] keyWindow] addSubview:textField];
[textField becomeFirstResponder];
}
ConditionBlock conditionBlock = ^bool {
return gCHRIsKeyboardShown;
};
base::test::ios::TimeUntilCondition(
nil, conditionBlock, false,
base::TimeDelta::FromSeconds(base::test::ios::kWaitForUIElementTimeout));
return textField;
}
@end
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