Commit 699bbe1c authored by Sergio Collazos's avatar Sergio Collazos Committed by Commit Bot

Revert "[iOS][MF][EG2] Migrate keyboard observer test"

This reverts commit 959cddb1.

Reason for revert: The just enabled testKeyboardHideState test keeps failing:
https://ci.chromium.org/p/chromium/builders/try/ios-simulator/403589
https://ci.chromium.org/p/chromium/builders/try/ios-simulator/403581

Original change's description:
> [iOS][MF][EG2] Migrate keyboard observer test
> 
> Remove deprecate test that would require new code to be migrated.
> Update and enable keyboard disappear test.
> Create app interface to interact with a shared instance of the observer
> in the app.
> Remove OCMock usage in the test.
> 
> TBR=eugenebut@chromium.org
> 
> Change-Id: Iaa5384f241e63b95ee516d4666b2e2adf65b7da6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881566
> Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
> Reviewed-by: Javier Ernesto Flores Robles <javierrobles@chromium.org>
> Reviewed-by: Stepan Khapugin <stkhapugin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#709939}

TBR=eugenebut@chromium.org,stkhapugin@chromium.org,javierrobles@chromium.org

Change-Id: I40a1bfece2a1b3eb03aec11d58c1ab0496b420d9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1885252Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710050}
parent c2dcabd1
......@@ -216,7 +216,6 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/browser/ui/settings/password",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:test_support",
"//ios/chrome/test:eg_test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
......@@ -225,6 +224,7 @@ source_set("eg_tests") {
"//ios/web:earl_grey_test_support",
"//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server",
"//third_party/ocmock",
]
}
......@@ -240,7 +240,6 @@ source_set("eg2_tests") {
"card_view_controller_egtest.mm",
"fallback_coordinator_egtest.mm",
"fallback_view_controller_egtest.mm",
"keyboard_observer_egtest.mm",
"password_view_controller_egtest.mm",
]
deps = [
......@@ -249,9 +248,6 @@ source_set("eg2_tests") {
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/ui/autofill:eg_test_support+eg2",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:eg_test_support+eg2",
"//ios/chrome/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
......
......@@ -2,34 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <EarlGrey/GREYKeyboard.h>
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/ui/util/keyboard_observer_helper.h"
#import "ios/chrome/browser/ui/util/keyboard_observer_helper_app_interface.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/earl_grey/web_view_actions.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ios/web/public/test/element_selector.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#if defined(CHROME_EARL_GREY_2)
// TODO(crbug.com/1015113): The EG2 macro is breaking indexing for some reason
// without the trailing semicolon. For now, disable the extra semi warning
// so Xcode indexing works for the egtest.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(KeyboardObserverHelperAppInterface);
#pragma clang diagnostic pop
#endif // defined(CHROME_EARL_GREY_2)
using base::test::ios::WaitUntilConditionOrTimeout;
using chrome_test_util::TapWebElementWithId;
using chrome_test_util::WebViewMatcher;
namespace {
......@@ -41,10 +37,14 @@ const std::string kFormElementSubmit = "submit";
// If an element is focused in the webview, returns its ID. Returns an empty
// NSString otherwise.
NSString* GetFocusedElementID() {
NSString* javaScript = @"(function() {"
" return document.activeElement.id;"
"})();";
return [ChromeEarlGrey executeJavaScript:javaScript];
NSString* js =
@"(function() {"
" return document.activeElement.id;"
"})();";
NSError* error = nil;
NSString* result = chrome_test_util::ExecuteJavaScript(js, &error);
GREYAssertNil(error, @"Unexpected error when executing JavaScript.");
return result;
}
// Verifies that |elementId| is the selected element in the web page.
......@@ -57,13 +57,16 @@ void AssertElementIsFocused(const std::string& element_id) {
ConditionBlock condition = ^{
return base::SysNSStringToUTF8(GetFocusedElementID()) == element_id;
};
GREYAssert(WaitUntilConditionOrTimeout(10, condition), description);
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(10, condition),
description);
}
// Helper to tap a web element.
void TapOnWebElementWithID(const std::string& elementID) {
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:TapWebElementWithId(elementID)];
performAction:web::WebViewTapElement(
chrome_test_util::GetCurrentWebState(),
[ElementSelector selectorWithElementID:elementID])];
}
} // namespace
......@@ -72,7 +75,14 @@ void TapOnWebElementWithID(const std::string& elementID) {
@interface KeyboardObserverTestCase : ChromeTestCase
// Observer to be tested.
@property(nonatomic, strong) KeyboardObserverHelper* keyboardObserverHelper;
@property(nonatomic, strong) KeyboardObserverHelper* keyboardObserver;
// Token to register a NSNotificationCenter observer.
@property(nonatomic, strong) id<NSObject> notificationToken;
// Delegate mock to confirm the observer callbacks.
@property(nonatomic, strong)
OCMockObject<KeyboardObserverHelperConsumer>* keyboardObserverDelegateMock;
@end
......@@ -80,43 +90,100 @@ void TapOnWebElementWithID(const std::string& elementID) {
- (void)setUp {
[super setUp];
self.keyboardObserverHelper =
[KeyboardObserverHelperAppInterface appSharedInstance];
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
const GURL URL = self.testServer->GetURL("/multi_field_form.html");
self.keyboardObserver = [[KeyboardObserverHelper alloc] init];
self.keyboardObserverDelegateMock =
OCMProtocolMock(@protocol(KeyboardObserverHelperConsumer));
self.keyboardObserver.consumer = self.keyboardObserverDelegateMock;
web::test::SetUpFileBasedHttpServer();
GURL URL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/multi_field_form.html");
[ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForWebStateContainingText:"hello!"];
}
- (void)tearDown {
self.keyboardObserverHelper = nil;
self.notificationToken = nil;
self.keyboardObserverDelegateMock = nil;
self.keyboardObserver = nil;
[super tearDown];
}
// Tests that when the keyboard actually dismiss the right callback is done.
- (void)testKeyboardHideState {
// Tests the observer correctly identifies when the keyboard stays on screen.
- (void)testKeyboardDidStayOnScreen {
if (@available(iOS 13, *)) {
// On iOS 13 keyboardDidStayOnScreen is not called. This makes the
// workaround not needed anymore.
return;
}
// Opening the keyboard from a webview blocks EarlGrey's synchronization.
ScopedSynchronizationDisabler disabler;
// Brings up the keyboard by tapping on one of the form's field.
TapOnWebElementWithID(kFormElementID1);
// Wait for keyboard to finish animating.
__block BOOL keyboardDidAppear = NO;
self.notificationToken = [[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidShowNotification
object:nil
queue:nil
usingBlock:^(NSNotification* note) {
keyboardDidAppear = YES;
}];
ConditionBlock condition = ^{
return keyboardDidAppear;
};
using base::test::ios::WaitUntilConditionOrTimeout;
using base::test::ios::kWaitForUIElementTimeout;
GREYAssert(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, condition),
@"Wait for keyboard did show notification");
// Verifies that the taped element is focused.
AssertElementIsFocused(kFormElementID1);
// Create a new callback expectation.
OCMExpect([self.keyboardObserverDelegateMock keyboardDidStayOnScreen]);
// Reset our keyboard boolean.
keyboardDidAppear = NO;
// Tap the second field.
TapOnWebElementWithID(kFormElementID2);
// Wait for keyboard to finish animating.
GREYAssert(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, condition),
@"Wait for keyboard did show notification");
// Verifies that the taped element is focused.
AssertElementIsFocused(kFormElementID2);
// Verify the delegate call was made.
[self.keyboardObserverDelegateMock verify];
}
// Tests that when the keyboard actually dismiss the right callback is done.
// TODO(crbug.com/914374): Address flakiness and reenable.
- (void)DISABLED_testKeyboardDidHide {
// Opening the keyboard from a webview blocks EarlGrey's synchronization.
ScopedSynchronizationDisabler disabler;
// Brings up the keyboard by tapping on one of the form's field.
TapOnWebElementWithID(kFormElementID1);
// Verifies that the taped element is focused.
AssertElementIsFocused(kFormElementID1);
// Verify the visible state.
KeyboardObserverHelper* observer = self.keyboardObserverHelper;
GREYAssertTrue(observer.keyboardState.isVisible,
@"Keyboard should be visible.");
// Create the callback expectation.
KeyboardState keyboardState = {NO, NO, NO, NO, NO};
OCMExpect([self.keyboardObserverDelegateMock
keyboardWillChangeToState:keyboardState]);
// Tap the "Submit" button, and let the run loop spin.
TapOnWebElementWithID(kFormElementSubmit);
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSeconds(1));
// Verify the state changed.
GREYAssertFalse(observer.keyboardState.isVisible,
@"Keyboard shouldn't be visible.");
// Verify the delegate call was made.
[self.keyboardObserverDelegateMock verify];
}
@end
......@@ -214,56 +214,3 @@ bundle_data("terms_resources") {
"{{bundle_resources_dir}}/{{source_file_part}}",
]
}
source_set("test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"keyboard_observer_helper_app_interface.h",
"keyboard_observer_helper_app_interface.mm",
]
deps = [
":util",
"//base",
"//base/test:test_support",
"//ios/chrome/test/app:test_support",
"//ios/testing/earl_grey:earl_grey_support",
]
}
source_set("eg_app_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"keyboard_observer_helper_app_interface.h",
"keyboard_observer_helper_app_interface.mm",
]
deps = [
":util",
"//base",
"//base/test:test_support",
"//ios/chrome/test/app:test_support",
]
}
source_set("eg_test_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"keyboard_observer_helper_app_interface.h",
]
deps = [
":util",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
]
}
// 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_CHROME_BROWSER_UI_UTIL_KEYBOARD_OBSERVER_HELPER_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_UTIL_KEYBOARD_OBSERVER_HELPER_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
@class KeyboardObserverHelper;
// Utility to interact with a KeyboardObserverInstance on Earl Grey 2 tests.
@interface KeyboardObserverHelperAppInterface : NSObject
// Returns a shared instance of the observer.
+ (KeyboardObserverHelper*)appSharedInstance;
@end
#endif // IOS_CHROME_BROWSER_UI_UTIL_KEYBOARD_OBSERVER_HELPER_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/chrome/browser/ui/util/keyboard_observer_helper_app_interface.h"
#import "ios/chrome/browser/ui/util/keyboard_observer_helper.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation KeyboardObserverHelperAppInterface
+ (KeyboardObserverHelper*)appSharedInstance {
static KeyboardObserverHelper* sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[KeyboardObserverHelper alloc] init];
});
return sharedInstance;
}
@end
......@@ -404,7 +404,6 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/toolbar/keyboard_assist",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:eg_app_support+eg2",
"//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/base",
......
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