Commit 0a4f4499 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

[EG2] Convert form_input_egtest.mm

Tbr: eugenebut
Bug: 987646
Change-Id: I5856f970fac3af18be19761d09cf649d953a05b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1883717
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710780}
parent 242c1522
...@@ -142,6 +142,7 @@ source_set("unit_tests") { ...@@ -142,6 +142,7 @@ source_set("unit_tests") {
sources = [ sources = [
"autofill_controller_js_unittest.mm", "autofill_controller_js_unittest.mm",
"autofill_controller_unittest.mm", "autofill_controller_unittest.mm",
"form_input_accessory_view_handler_unittest.mm",
"form_structure_browsertest.mm", "form_structure_browsertest.mm",
"form_suggestion_controller_unittest.mm", "form_suggestion_controller_unittest.mm",
"js_autofill_manager_unittest.mm", "js_autofill_manager_unittest.mm",
...@@ -150,6 +151,7 @@ source_set("unit_tests") { ...@@ -150,6 +151,7 @@ source_set("unit_tests") {
deps = [ deps = [
":autofill", ":autofill",
":autofill_internal", ":autofill_internal",
":autofill_shared",
":unit_tests_bundle_data", ":unit_tests_bundle_data",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
...@@ -511,6 +513,7 @@ bundle_data("unit_tests_bundle_data") { ...@@ -511,6 +513,7 @@ bundle_data("unit_tests_bundle_data") {
} }
source_set("eg_tests") { source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ sources = [
...@@ -535,3 +538,29 @@ source_set("eg_tests") { ...@@ -535,3 +538,29 @@ source_set("eg_tests") {
"//ios/web/public/test/http_server", "//ios/web/public/test/http_server",
] ]
} }
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"form_input_egtest.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//ios/chrome/app/strings:ios_strings_grit",
"//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",
"//ios/web/public",
"//ios/web/public/deprecated",
"//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server",
]
libs = [ "UIKit.framework" ]
}
// 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/autofill/form_input_accessory_view_handler.h"
#include "base/mac/foundation_util.h"
#import "components/autofill/ios/browser/js_suggestion_manager.h"
#import "ios/web/public/deprecated/crw_js_injection_receiver.h"
#import "ios/web/public/test/web_test_with_web_state.h"
#import "ios/web/public/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
class FormInputAccessoryViewHandlerTest : public web::WebTestWithWebState {};
// Tests that trying to programmatically dismiss the keyboard when it isn't
// visible doesn't crash the browser.
TEST_F(FormInputAccessoryViewHandlerTest, FormInputAccessoryViewHandler) {
FormInputAccessoryViewHandler* accessoryViewDelegate =
[[FormInputAccessoryViewHandler alloc] init];
ASSERT_TRUE(accessoryViewDelegate);
[accessoryViewDelegate closeKeyboardWithoutButtonPress];
CRWJSInjectionReceiver* injectionReceiver =
web_state()->GetJSInjectionReceiver();
accessoryViewDelegate.JSSuggestionManager =
base::mac::ObjCCastStrict<JsSuggestionManager>(
[injectionReceiver instanceOfClass:[JsSuggestionManager class]]);
[accessoryViewDelegate closeKeyboardWithoutButtonPress];
}
...@@ -2,24 +2,18 @@ ...@@ -2,24 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#import "components/autofill/ios/browser/js_suggestion_manager.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_handler.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/earl_grey/chrome_actions.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_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.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/chrome/test/scoped_eg_synchronization_disabler.h" #import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/deprecated/crw_js_injection_receiver.h" #import "ios/web/public/deprecated/crw_js_injection_receiver.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" #include "ios/web/public/test/element_selector.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h" #include "ios/web/public/test/http_server/http_server_util.h"
...@@ -32,6 +26,7 @@ ...@@ -32,6 +26,7 @@
using base::test::ios::kWaitForUIElementTimeout; using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout; using base::test::ios::WaitUntilConditionOrTimeout;
using chrome_test_util::TapWebElementWithId;
using chrome_test_util::WebViewMatcher; using chrome_test_util::WebViewMatcher;
namespace { namespace {
...@@ -46,7 +41,8 @@ NSString* GetFocusedElementId() { ...@@ -46,7 +41,8 @@ NSString* GetFocusedElementId() {
" return document.activeElement.id;" " return document.activeElement.id;"
"})();"; "})();";
NSError* error = nil; NSError* error = nil;
NSString* result = chrome_test_util::ExecuteJavaScript(js, &error); NSString* result = [ChromeEarlGreyAppInterface executeJavaScript:js
error:&error];
GREYAssertTrue(!error, @"Unexpected error when executing JavaScript."); GREYAssertTrue(!error, @"Unexpected error when executing JavaScript.");
return result; return result;
} }
...@@ -71,10 +67,6 @@ void AssertElementIsFocused(const std::string& element_id) { ...@@ -71,10 +67,6 @@ void AssertElementIsFocused(const std::string& element_id) {
@implementation FormInputTestCase @implementation FormInputTestCase
- (void)tearDown {
[super tearDown];
}
// Tests finding the correct "next" and "previous" form assist controls in the // Tests finding the correct "next" and "previous" form assist controls in the
// iOS built-in form assist view. // iOS built-in form assist view.
- (void)testFindDefaultFormAssistControls { - (void)testFindDefaultFormAssistControls {
...@@ -99,10 +91,7 @@ void AssertElementIsFocused(const std::string& element_id) { ...@@ -99,10 +91,7 @@ void AssertElementIsFocused(const std::string& element_id) {
// Brings up the keyboard by tapping on one of the form's field. // Brings up the keyboard by tapping on one of the form's field.
[[EarlGrey selectElementWithMatcher:WebViewMatcher()] [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:web::WebViewTapElement( performAction:TapWebElementWithId(kFormElementId1)];
chrome_test_util::GetCurrentWebState(),
[ElementSelector
selectorWithElementID:kFormElementId1])];
id<GREYMatcher> nextButtonMatcher = id<GREYMatcher> nextButtonMatcher =
chrome_test_util::ButtonWithAccessibilityLabelId( chrome_test_util::ButtonWithAccessibilityLabelId(
...@@ -147,20 +136,4 @@ void AssertElementIsFocused(const std::string& element_id) { ...@@ -147,20 +136,4 @@ void AssertElementIsFocused(const std::string& element_id) {
} }
} }
// Tests that trying to programmatically dismiss the keyboard when it isn't
// visible doesn't crash the browser.
- (void)testCloseKeyboardWhenNotVisible {
FormInputAccessoryViewHandler* accessoryViewDelegate =
[[FormInputAccessoryViewHandler alloc] init];
GREYAssertNotNil(accessoryViewDelegate,
@"The Accessory View Delegate should not be non nil.");
[accessoryViewDelegate closeKeyboardWithoutButtonPress];
CRWJSInjectionReceiver* injectionReceiver =
chrome_test_util::GetCurrentWebState()->GetJSInjectionReceiver();
accessoryViewDelegate.JSSuggestionManager =
base::mac::ObjCCastStrict<JsSuggestionManager>(
[injectionReceiver instanceOfClass:[JsSuggestionManager class]]);
[accessoryViewDelegate closeKeyboardWithoutButtonPress];
}
@end @end
...@@ -34,6 +34,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") { ...@@ -34,6 +34,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") {
xcode_test_application_name = "ios_chrome_eg2tests" xcode_test_application_name = "ios_chrome_eg2tests"
deps = [ deps = [
"//ios/chrome/browser/autofill:eg2_tests",
"//ios/chrome/browser/device_sharing:eg2_tests", "//ios/chrome/browser/device_sharing:eg2_tests",
"//ios/chrome/browser/net:eg2_tests", "//ios/chrome/browser/net:eg2_tests",
"//ios/chrome/browser/ntp_tiles:eg2_tests", "//ios/chrome/browser/ntp_tiles:eg2_tests",
......
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