Skip to content

Commit 246f409

Browse files
Lindsay PasrichaCommit Bot
Lindsay Pasricha
authored and
Commit Bot
committed
[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 <[email protected]> Reviewed-by: Rohit Rao <[email protected]> Reviewed-by: Justin Cohen <[email protected]> Cr-Commit-Position: refs/heads/master@{#619732}
1 parent 2fcaf0a commit 246f409

File tree

9 files changed

+418
-7
lines changed

9 files changed

+418
-7
lines changed

ios/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ group("all") {
5252
# List all the test targets that need to be built on iOS by default.
5353
"//ios/chrome/test:all_tests",
5454
"//ios/chrome/test/earl_grey:all_tests",
55+
"//ios/chrome/test/earl_grey2:all_tests",
5556
"//ios/components:all_tests",
5657
"//ios/net:all_tests",
5758
"//ios/showcase:all_tests",

ios/chrome/test/earl_grey2/BUILD.gn

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2018 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//build/config/ios/ios_sdk.gni")
6+
import("//build/config/ios/rules.gni")
7+
import("//ios/chrome/test/earl_grey2/chrome_ios_eg2_test.gni")
8+
9+
group("all_tests") {
10+
testonly = true
11+
deps = [
12+
":ios_chrome_eg2_test_app_host",
13+
":ios_chrome_smoke_eg2tests",
14+
]
15+
}
16+
17+
chrome_ios_eg2_test_app_host("ios_chrome_eg2_test_app_host") {
18+
deps = [
19+
":earl_grey2_host_distant_object_sources",
20+
]
21+
}
22+
23+
chrome_ios_eg2_test("ios_chrome_smoke_eg2tests") {
24+
xcode_test_application_name = "ios_chrome_eg2_test_app_host"
25+
26+
deps = [
27+
"//ios/chrome/test/earl_grey2:eg2_tests",
28+
]
29+
}
30+
31+
source_set("earl_grey2_host_distant_object_headers") {
32+
testonly = true
33+
sources = [
34+
"//ios/chrome/test/earl_grey2/chrome_earl_grey_edo.h",
35+
]
36+
}
37+
38+
source_set("earl_grey2_host_distant_object_sources") {
39+
configs += [ "//build/config/compiler:enable_arc" ]
40+
testonly = true
41+
sources = [
42+
"//ios/chrome/test/earl_grey2/chrome_earl_grey_edo.mm",
43+
]
44+
45+
include_dirs = [
46+
"//ios/third_party/earl_grey2/src",
47+
"//ios/third_party/edo/src",
48+
]
49+
50+
deps = [
51+
":earl_grey2_host_distant_object_headers",
52+
"//base",
53+
"//base/test:test_support",
54+
"//ios/chrome/test/app:test_support",
55+
"//ios/third_party/earl_grey2:app_framework+link",
56+
]
57+
}
58+
59+
source_set("eg2_tests") {
60+
configs += [
61+
"//build/config/compiler:enable_arc",
62+
"//build/config/ios:xctest_config",
63+
]
64+
testonly = true
65+
66+
sources = [
67+
"smoke_egtest.mm",
68+
]
69+
70+
include_dirs = [ "//ios/third_party/edo/src" ]
71+
72+
deps = [
73+
"//ios/chrome/test/earl_grey2:earl_grey2_host_distant_object_headers",
74+
"//ios/third_party/earl_grey2:test_lib",
75+
]
76+
77+
libs = [ "UIKit.framework" ]
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef IOS_CHROME_TEST_EARL_GREY2_CHROME_EARL_GREY_EDO_H_
6+
#define IOS_CHROME_TEST_EARL_GREY2_CHROME_EARL_GREY_EDO_H_
7+
8+
#import <CommonLib/DistantObject/GREYHostApplicationDistantObject.h>
9+
10+
@interface GREYHostApplicationDistantObject (RemoteTest)
11+
12+
// Returns the number of main tabs.
13+
- (NSUInteger)GetMainTabCount;
14+
15+
@end
16+
17+
#endif // IOS_CHROME_TEST_EARL_GREY2_CHROME_EARL_GREY_EDO_H_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "ios/chrome/test/earl_grey2/chrome_earl_grey_edo.h"
6+
7+
#import "ios/chrome/test/app/tab_test_util.h"
8+
9+
#if !defined(__has_feature) || !__has_feature(objc_arc)
10+
#error "This file requires ARC support."
11+
#endif
12+
13+
@implementation GREYHostApplicationDistantObject (RemoteTest)
14+
15+
- (NSUInteger)GetMainTabCount {
16+
return chrome_test_util::GetMainTabCount();
17+
}
18+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Copyright 2018 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//build/config/ios/rules.gni")
6+
import("//build/mac/tweak_info_plist.gni")
7+
import("//ios/build/chrome_build.gni")
8+
import("//ios/public/provider/chrome/browser/build_config.gni")
9+
import("//ios/third_party/earl_grey2/ios_eg2_test.gni")
10+
11+
template("chrome_ios_eg2_test_app_host") {
12+
if (!defined(entitlements_path) && !defined(entitlements_target)) {
13+
_target_name = target_name
14+
_tweak_entitlements = target_name + "_tweak_entitlements"
15+
compile_entitlements(_tweak_entitlements) {
16+
substitutions = [ "IOS_BUNDLE_ID_PREFIX=$ios_app_bundle_id_prefix" ]
17+
output_name = "$target_gen_dir/$_target_name.entitlements"
18+
entitlements_templates =
19+
[ "//ios/chrome/test/earl_grey/resources/Chrome.entitlements" ]
20+
if (ios_egtests_entitlements_additions != []) {
21+
entitlements_templates += ios_egtests_entitlements_additions
22+
}
23+
}
24+
}
25+
26+
if (!defined(info_plist) && !defined(info_plist_target)) {
27+
_tweak_info_plist = target_name + "_tweak_info_plist"
28+
tweak_info_plist(_tweak_info_plist) {
29+
info_plists = [
30+
"//ios/chrome/app/resources/Info.plist",
31+
"//ios/chrome/app/resources/EarlGreyAddition+Info.plist",
32+
]
33+
if (ios_chrome_info_plist_additions != []) {
34+
info_plists += ios_chrome_info_plist_additions
35+
}
36+
if (defined(invoker.extra_info_plists)) {
37+
info_plists += invoker.extra_info_plists
38+
}
39+
args = [
40+
"--breakpad=$breakpad_enabled_as_int",
41+
"--branding=$chromium_short_name",
42+
"--version-overrides=MINOR=9999",
43+
]
44+
}
45+
}
46+
47+
_deps_group_name = target_name + "_deps_group"
48+
group(_deps_group_name) {
49+
testonly = true
50+
51+
public_deps = []
52+
if (defined(invoker.deps)) {
53+
public_deps += invoker.deps
54+
}
55+
56+
if (defined(invoker.public_deps)) {
57+
public_deps += invoker.public_deps
58+
}
59+
}
60+
61+
ios_eg2_test_app_host(target_name) {
62+
forward_variables_from(invoker,
63+
[
64+
"entitlements_path",
65+
"entitlements_target",
66+
"eg_main_application_delegate",
67+
"info_plist",
68+
"info_plist_target",
69+
],
70+
[
71+
"deps",
72+
"public_deps",
73+
])
74+
testonly = true
75+
76+
if (!defined(entitlements_path) && !defined(entitlements_target)) {
77+
entitlements_target = ":$_tweak_entitlements"
78+
}
79+
80+
if (!defined(info_plist) && !defined(info_plist_target)) {
81+
info_plist_target = ":$_tweak_info_plist"
82+
}
83+
84+
_eg_main_application_delegate = "MainApplicationDelegate"
85+
if (defined(eg_main_application_delegate)) {
86+
_eg_main_application_delegate = eg_main_application_delegate
87+
}
88+
89+
deps = [
90+
":$_deps_group_name",
91+
"//ios/chrome/app:main",
92+
"//ios/chrome/test/earl_grey:hooks",
93+
"//ios/testing:http_server_bundle_data",
94+
"//ios/third_party/earl_grey2:app_framework+link",
95+
]
96+
97+
if (!defined(bundle_deps)) {
98+
bundle_deps = []
99+
}
100+
bundle_deps += [
101+
"//ios/chrome/app/resources",
102+
"//ios/third_party/earl_grey2:app_framework+bundle",
103+
ios_application_icons_target,
104+
]
105+
106+
if (!defined(extra_substitutions)) {
107+
extra_substitutions = []
108+
}
109+
extra_substitutions += [
110+
"CHROMIUM_HANDOFF_ID=$chromium_handoff_id",
111+
"CHROMIUM_SHORT_NAME=$target_name",
112+
"CHROMIUM_URL_SCHEME_1=$url_unsecure_scheme",
113+
"CHROMIUM_URL_SCHEME_2=$url_secure_scheme",
114+
"CHROMIUM_URL_SCHEME_3=$url_x_callback_scheme",
115+
"CHROMIUM_URL_CHANNEL_SCHEME=$url_channel_scheme",
116+
"EG_MAIN_APPLICATION_DELEGATE=$_eg_main_application_delegate",
117+
"SSOAUTH_URL_SCHEME=$url_ssoauth_scheme",
118+
"CONTENT_WIDGET_EXTENSION_BUNDLE_ID=$chromium_bundle_id.ContentTodayExtension",
119+
]
120+
if (ios_automatically_manage_certs) {
121+
# Use the same bundle identifier for EarlGrey tests as for unit tests
122+
# when managing certificates as the number of free certs is limited.
123+
extra_substitutions +=
124+
[ "CHROMIUM_BUNDLE_ID=gtest.${ios_generic_test_bundle_id_suffix}" ]
125+
} else {
126+
extra_substitutions += [ "CHROMIUM_BUNDLE_ID=gtest.$target_name" ]
127+
}
128+
}
129+
}
130+
131+
set_defaults("chrome_ios_eg_v2_test_app_host") {
132+
configs = default_executable_configs
133+
}
134+
135+
template("chrome_ios_eg2_test") {
136+
assert(defined(invoker.xcode_test_application_name),
137+
"xcode_test_application_name must be defined for $target_name")
138+
assert(
139+
defined(invoker.deps),
140+
"deps must be defined for $target_name to include at least one earl grey test file.")
141+
142+
ios_eg2_test(target_name) {
143+
forward_variables_from(invoker,
144+
[
145+
"xcode_test_application_name",
146+
"deps",
147+
])
148+
}
149+
}
150+
151+
set_defaults("chrome_ios_eg2_test") {
152+
configs = default_shared_library_configs
153+
}
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <TestLib/EarlGreyImpl/EarlGrey.h>
6+
#import <UIKit/UIKit.h>
7+
#import <XCTest/XCTest.h>
8+
9+
#import "ios/chrome/test/earl_grey2/chrome_earl_grey_edo.h"
10+
11+
#if !defined(__has_feature) || !__has_feature(objc_arc)
12+
#error "This file requires ARC support."
13+
#endif
14+
15+
// Test case to verify that EarlGrey tests can be launched and perform basic
16+
// UI interactions.
17+
@interface Eg2TestCase : XCTestCase
18+
@end
19+
20+
@implementation Eg2TestCase
21+
22+
- (void)setUp {
23+
[super setUp];
24+
static dispatch_once_t onceToken;
25+
dispatch_once(&onceToken, ^{
26+
XCUIApplication* application = [[XCUIApplication alloc] init];
27+
[application launch];
28+
});
29+
}
30+
31+
// Tests that the tools menu is tappable.
32+
- (void)testTapToolsMenu {
33+
id<GREYMatcher> toolsMenuButtonID =
34+
grey_allOf(grey_accessibilityID(@"kToolbarToolsMenuButtonIdentifier"),
35+
grey_sufficientlyVisible(), nil);
36+
[[EarlGrey selectElementWithMatcher:toolsMenuButtonID]
37+
performAction:grey_tap()];
38+
}
39+
40+
// Tests that a tab can be opened.
41+
- (void)testOpenTab {
42+
// Open tools menu.
43+
// TODO(crbug.com/917114): Calling the string directly is temporary while we
44+
// roll out a solution to access constants across the code base for EG2.
45+
id<GREYMatcher> toolsMenuButtonID =
46+
grey_allOf(grey_accessibilityID(@"kToolbarToolsMenuButtonIdentifier"),
47+
grey_sufficientlyVisible(), nil);
48+
[[EarlGrey selectElementWithMatcher:toolsMenuButtonID]
49+
performAction:grey_tap()];
50+
51+
// Open new tab.
52+
// TODO(crbug.com/917114): Calling the string directly is temporary while we
53+
// roll out a solution to access constants across the code base for EG2.
54+
id<GREYMatcher> newTabButtonMatcher =
55+
grey_accessibilityID(@"kToolsMenuNewTabId");
56+
[[EarlGrey selectElementWithMatcher:newTabButtonMatcher]
57+
performAction:grey_tap()];
58+
59+
// Get tab count.
60+
NSUInteger tabCount =
61+
[[GREYHostApplicationDistantObject sharedInstance] GetMainTabCount];
62+
GREYAssertEqual(2, tabCount, @"Expected 2 tabs.");
63+
}
64+
@end

ios/third_party/earl_grey2/BUILD.gn

+1-6
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,9 @@ source_set("test_lib_shared_headers") {
367367
]
368368
}
369369

370-
ios_framework_bundle("test_lib") {
370+
source_set("test_lib") {
371371
testonly = true
372372

373-
output_name = "EarlGreyTestLib"
374-
info_plist = "Info.plist"
375-
376373
sources = [
377374
"src/AppFramework/Error/GREYFailureScreenshotterStub.m",
378375
"src/AppFramework/Matcher/GREYMatchersShorthand.m",
@@ -433,8 +430,6 @@ ios_framework_bundle("test_lib") {
433430
"UIKit.framework",
434431
]
435432

436-
public_headers = [ "src/TestLib/EarlGreyImpl/EarlGrey.h" ]
437-
438433
public_configs = [ ":config" ]
439434

440435
configs -= [

ios/third_party/earl_grey2/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
<key>CFBundleDevelopmentRegion</key>
1818
<string>English</string>
1919
</dict>
20-
</plist>
20+
</plist>

0 commit comments

Comments
 (0)