Commit 246f4097 authored by Lindsay Pasricha's avatar Lindsay Pasricha Committed by Commit Bot

[iOS] Add initial support for EG2 and simple smoke tests.

Creating 2 prototype tests using EG2 with the smoke_egtest suite.
The plan for migrating to EG2 is outlined at go/chrome-eg2-migration.

- Added the earl_grey2:all_tests as a build target
- Added the ios/chrome/test/earl_grey2 directory with BUILD and gni files
- Added the prototype smoke_test suite with 2 test cases
- Added the chrome_earl_grey_edo .h/mm files for the EDO helpers
- Tweaked and reorganized ios/third_party/earl_grey2/ BUILD and gni files.

Bug: 906201
Change-Id: I6521af6403ac9e4b320cba25f390be88522a0678
Reviewed-on: https://chromium-review.googlesource.com/c/1352532
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619732}
parent 2fcaf0a1
...@@ -52,6 +52,7 @@ group("all") { ...@@ -52,6 +52,7 @@ group("all") {
# List all the test targets that need to be built on iOS by default. # List all the test targets that need to be built on iOS by default.
"//ios/chrome/test:all_tests", "//ios/chrome/test:all_tests",
"//ios/chrome/test/earl_grey:all_tests", "//ios/chrome/test/earl_grey:all_tests",
"//ios/chrome/test/earl_grey2:all_tests",
"//ios/components:all_tests", "//ios/components:all_tests",
"//ios/net:all_tests", "//ios/net:all_tests",
"//ios/showcase:all_tests", "//ios/showcase:all_tests",
......
# Copyright 2018 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("//build/config/ios/ios_sdk.gni")
import("//build/config/ios/rules.gni")
import("//ios/chrome/test/earl_grey2/chrome_ios_eg2_test.gni")
group("all_tests") {
testonly = true
deps = [
":ios_chrome_eg2_test_app_host",
":ios_chrome_smoke_eg2tests",
]
}
chrome_ios_eg2_test_app_host("ios_chrome_eg2_test_app_host") {
deps = [
":earl_grey2_host_distant_object_sources",
]
}
chrome_ios_eg2_test("ios_chrome_smoke_eg2tests") {
xcode_test_application_name = "ios_chrome_eg2_test_app_host"
deps = [
"//ios/chrome/test/earl_grey2:eg2_tests",
]
}
source_set("earl_grey2_host_distant_object_headers") {
testonly = true
sources = [
"//ios/chrome/test/earl_grey2/chrome_earl_grey_edo.h",
]
}
source_set("earl_grey2_host_distant_object_sources") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"//ios/chrome/test/earl_grey2/chrome_earl_grey_edo.mm",
]
include_dirs = [
"//ios/third_party/earl_grey2/src",
"//ios/third_party/edo/src",
]
deps = [
":earl_grey2_host_distant_object_headers",
"//base",
"//base/test:test_support",
"//ios/chrome/test/app:test_support",
"//ios/third_party/earl_grey2:app_framework+link",
]
}
source_set("eg2_tests") {
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"smoke_egtest.mm",
]
include_dirs = [ "//ios/third_party/edo/src" ]
deps = [
"//ios/chrome/test/earl_grey2:earl_grey2_host_distant_object_headers",
"//ios/third_party/earl_grey2:test_lib",
]
libs = [ "UIKit.framework" ]
}
// Copyright 2018 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_TEST_EARL_GREY2_CHROME_EARL_GREY_EDO_H_
#define IOS_CHROME_TEST_EARL_GREY2_CHROME_EARL_GREY_EDO_H_
#import <CommonLib/DistantObject/GREYHostApplicationDistantObject.h>
@interface GREYHostApplicationDistantObject (RemoteTest)
// Returns the number of main tabs.
- (NSUInteger)GetMainTabCount;
@end
#endif // IOS_CHROME_TEST_EARL_GREY2_CHROME_EARL_GREY_EDO_H_
// Copyright 2018 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/test/earl_grey2/chrome_earl_grey_edo.h"
#import "ios/chrome/test/app/tab_test_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation GREYHostApplicationDistantObject (RemoteTest)
- (NSUInteger)GetMainTabCount {
return chrome_test_util::GetMainTabCount();
}
@end
# Copyright 2018 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("//build/config/ios/rules.gni")
import("//build/mac/tweak_info_plist.gni")
import("//ios/build/chrome_build.gni")
import("//ios/public/provider/chrome/browser/build_config.gni")
import("//ios/third_party/earl_grey2/ios_eg2_test.gni")
template("chrome_ios_eg2_test_app_host") {
if (!defined(entitlements_path) && !defined(entitlements_target)) {
_target_name = target_name
_tweak_entitlements = target_name + "_tweak_entitlements"
compile_entitlements(_tweak_entitlements) {
substitutions = [ "IOS_BUNDLE_ID_PREFIX=$ios_app_bundle_id_prefix" ]
output_name = "$target_gen_dir/$_target_name.entitlements"
entitlements_templates =
[ "//ios/chrome/test/earl_grey/resources/Chrome.entitlements" ]
if (ios_egtests_entitlements_additions != []) {
entitlements_templates += ios_egtests_entitlements_additions
}
}
}
if (!defined(info_plist) && !defined(info_plist_target)) {
_tweak_info_plist = target_name + "_tweak_info_plist"
tweak_info_plist(_tweak_info_plist) {
info_plists = [
"//ios/chrome/app/resources/Info.plist",
"//ios/chrome/app/resources/EarlGreyAddition+Info.plist",
]
if (ios_chrome_info_plist_additions != []) {
info_plists += ios_chrome_info_plist_additions
}
if (defined(invoker.extra_info_plists)) {
info_plists += invoker.extra_info_plists
}
args = [
"--breakpad=$breakpad_enabled_as_int",
"--branding=$chromium_short_name",
"--version-overrides=MINOR=9999",
]
}
}
_deps_group_name = target_name + "_deps_group"
group(_deps_group_name) {
testonly = true
public_deps = []
if (defined(invoker.deps)) {
public_deps += invoker.deps
}
if (defined(invoker.public_deps)) {
public_deps += invoker.public_deps
}
}
ios_eg2_test_app_host(target_name) {
forward_variables_from(invoker,
[
"entitlements_path",
"entitlements_target",
"eg_main_application_delegate",
"info_plist",
"info_plist_target",
],
[
"deps",
"public_deps",
])
testonly = true
if (!defined(entitlements_path) && !defined(entitlements_target)) {
entitlements_target = ":$_tweak_entitlements"
}
if (!defined(info_plist) && !defined(info_plist_target)) {
info_plist_target = ":$_tweak_info_plist"
}
_eg_main_application_delegate = "MainApplicationDelegate"
if (defined(eg_main_application_delegate)) {
_eg_main_application_delegate = eg_main_application_delegate
}
deps = [
":$_deps_group_name",
"//ios/chrome/app:main",
"//ios/chrome/test/earl_grey:hooks",
"//ios/testing:http_server_bundle_data",
"//ios/third_party/earl_grey2:app_framework+link",
]
if (!defined(bundle_deps)) {
bundle_deps = []
}
bundle_deps += [
"//ios/chrome/app/resources",
"//ios/third_party/earl_grey2:app_framework+bundle",
ios_application_icons_target,
]
if (!defined(extra_substitutions)) {
extra_substitutions = []
}
extra_substitutions += [
"CHROMIUM_HANDOFF_ID=$chromium_handoff_id",
"CHROMIUM_SHORT_NAME=$target_name",
"CHROMIUM_URL_SCHEME_1=$url_unsecure_scheme",
"CHROMIUM_URL_SCHEME_2=$url_secure_scheme",
"CHROMIUM_URL_SCHEME_3=$url_x_callback_scheme",
"CHROMIUM_URL_CHANNEL_SCHEME=$url_channel_scheme",
"EG_MAIN_APPLICATION_DELEGATE=$_eg_main_application_delegate",
"SSOAUTH_URL_SCHEME=$url_ssoauth_scheme",
"CONTENT_WIDGET_EXTENSION_BUNDLE_ID=$chromium_bundle_id.ContentTodayExtension",
]
if (ios_automatically_manage_certs) {
# Use the same bundle identifier for EarlGrey tests as for unit tests
# when managing certificates as the number of free certs is limited.
extra_substitutions +=
[ "CHROMIUM_BUNDLE_ID=gtest.${ios_generic_test_bundle_id_suffix}" ]
} else {
extra_substitutions += [ "CHROMIUM_BUNDLE_ID=gtest.$target_name" ]
}
}
}
set_defaults("chrome_ios_eg_v2_test_app_host") {
configs = default_executable_configs
}
template("chrome_ios_eg2_test") {
assert(defined(invoker.xcode_test_application_name),
"xcode_test_application_name must be defined for $target_name")
assert(
defined(invoker.deps),
"deps must be defined for $target_name to include at least one earl grey test file.")
ios_eg2_test(target_name) {
forward_variables_from(invoker,
[
"xcode_test_application_name",
"deps",
])
}
}
set_defaults("chrome_ios_eg2_test") {
configs = default_shared_library_configs
}
// Copyright 2018 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 <TestLib/EarlGreyImpl/EarlGrey.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "ios/chrome/test/earl_grey2/chrome_earl_grey_edo.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Test case to verify that EarlGrey tests can be launched and perform basic
// UI interactions.
@interface Eg2TestCase : XCTestCase
@end
@implementation Eg2TestCase
- (void)setUp {
[super setUp];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
XCUIApplication* application = [[XCUIApplication alloc] init];
[application launch];
});
}
// Tests that the tools menu is tappable.
- (void)testTapToolsMenu {
id<GREYMatcher> toolsMenuButtonID =
grey_allOf(grey_accessibilityID(@"kToolbarToolsMenuButtonIdentifier"),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:toolsMenuButtonID]
performAction:grey_tap()];
}
// Tests that a tab can be opened.
- (void)testOpenTab {
// Open tools menu.
// TODO(crbug.com/917114): Calling the string directly is temporary while we
// roll out a solution to access constants across the code base for EG2.
id<GREYMatcher> toolsMenuButtonID =
grey_allOf(grey_accessibilityID(@"kToolbarToolsMenuButtonIdentifier"),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:toolsMenuButtonID]
performAction:grey_tap()];
// Open new tab.
// TODO(crbug.com/917114): Calling the string directly is temporary while we
// roll out a solution to access constants across the code base for EG2.
id<GREYMatcher> newTabButtonMatcher =
grey_accessibilityID(@"kToolsMenuNewTabId");
[[EarlGrey selectElementWithMatcher:newTabButtonMatcher]
performAction:grey_tap()];
// Get tab count.
NSUInteger tabCount =
[[GREYHostApplicationDistantObject sharedInstance] GetMainTabCount];
GREYAssertEqual(2, tabCount, @"Expected 2 tabs.");
}
@end
...@@ -367,12 +367,9 @@ source_set("test_lib_shared_headers") { ...@@ -367,12 +367,9 @@ source_set("test_lib_shared_headers") {
] ]
} }
ios_framework_bundle("test_lib") { source_set("test_lib") {
testonly = true testonly = true
output_name = "EarlGreyTestLib"
info_plist = "Info.plist"
sources = [ sources = [
"src/AppFramework/Error/GREYFailureScreenshotterStub.m", "src/AppFramework/Error/GREYFailureScreenshotterStub.m",
"src/AppFramework/Matcher/GREYMatchersShorthand.m", "src/AppFramework/Matcher/GREYMatchersShorthand.m",
...@@ -433,8 +430,6 @@ ios_framework_bundle("test_lib") { ...@@ -433,8 +430,6 @@ ios_framework_bundle("test_lib") {
"UIKit.framework", "UIKit.framework",
] ]
public_headers = [ "src/TestLib/EarlGreyImpl/EarlGrey.h" ]
public_configs = [ ":config" ] public_configs = [ ":config" ]
configs -= [ configs -= [
......
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>English</string> <string>English</string>
</dict> </dict>
</plist> </plist>
\ No newline at end of file
# Copyright 2018 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("//build/config/ios/rules.gni")
import("//ios/third_party/firebase/firebase.gni")
template("ios_eg2_test_app_host") {
ios_app_bundle(target_name) {
testonly = true
forward_variables_from(invoker, "*")
configs += [ "//build/config/ios:xctest_config" ]
if (!defined(bundle_deps)) {
bundle_deps = []
}
bundle_deps += [ "//ios/third_party/earl_grey2:app_framework+bundle" ]
if (ios_enable_firebase_sdk) {
assert(ios_firebase_resources_target != "",
"ios_firebase_resources_target must be defined if Firebase SDK " +
"is enabled.")
bundle_deps += [ ios_firebase_resources_target ]
}
if (!defined(deps)) {
deps = []
}
deps += [ "//ios/third_party/earl_grey2:app_framework+link" ]
if (ios_enable_firebase_sdk) {
deps += [ "//ios/third_party/firebase" ]
}
# Xcode needs those two framework installed in the application (and signed)
# for the XCTest to run, so install them using extra_system_frameworks.
_ios_platform_library = "$ios_sdk_platform_path/Developer/Library"
extra_system_frameworks =
[ "$_ios_platform_library/Frameworks/XCTest.framework" ]
if (!defined(ldflags)) {
ldflags = []
}
ldflags += [
"-Xlinker",
"-rpath",
"-Xlinker",
"@executable_path/Frameworks",
"-Xlinker",
"-rpath",
"-Xlinker",
"@loader_path/Frameworks",
]
}
}
set_defaults("ios_eg2_test_app_host") {
configs = default_executable_configs
}
# EarlGrey2 tests are just XCUITests that also depends on EarlGrey2.
template("ios_eg2_test") {
assert(defined(invoker.xcode_test_application_name),
"xcode_test_application_name must be defined for $target_name")
assert(
defined(invoker.deps),
"deps must be defined for $target_name to include at least one earl grey test file.")
ios_xcuitest_test(target_name) {
forward_variables_from(invoker,
[
"xcode_test_application_name",
"bundle_deps",
"deps",
])
if (!defined(deps)) {
deps = []
}
deps += [ "//ios/third_party/earl_grey2:test_lib" ]
}
}
set_defaults("ios_eg2_test") {
configs = default_shared_library_configs
}
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