Commit ee8d0c64 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Compiles ChromeTestCase under EG2.

BUG=922813

Change-Id: Ie9545589a8f99ff3ef7652ce06d3ab117fe2499e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1628049Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663131}
parent e61302d7
...@@ -245,6 +245,8 @@ source_set("test_support") { ...@@ -245,6 +245,8 @@ source_set("test_support") {
"chrome_matchers_app_interface.mm", "chrome_matchers_app_interface.mm",
"chrome_test_case.h", "chrome_test_case.h",
"chrome_test_case.mm", "chrome_test_case.mm",
"chrome_test_case_app_interface.h",
"chrome_test_case_app_interface.mm",
] ]
deps = [ deps = [
...@@ -332,6 +334,8 @@ source_set("eg_app_support+eg2") { ...@@ -332,6 +334,8 @@ source_set("eg_app_support+eg2") {
"chrome_earl_grey_app_interface.mm", "chrome_earl_grey_app_interface.mm",
"chrome_matchers_app_interface.h", "chrome_matchers_app_interface.h",
"chrome_matchers_app_interface.mm", "chrome_matchers_app_interface.mm",
"chrome_test_case_app_interface.h",
"chrome_test_case_app_interface.mm",
] ]
deps = [ deps = [
...@@ -392,6 +396,9 @@ source_set("eg_test_support+eg2") { ...@@ -392,6 +396,9 @@ source_set("eg_test_support+eg2") {
"chrome_matchers.h", "chrome_matchers.h",
"chrome_matchers.mm", "chrome_matchers.mm",
"chrome_matchers_app_interface.h", "chrome_matchers_app_interface.h",
"chrome_test_case.h",
"chrome_test_case.mm",
"chrome_test_case_app_interface.h",
] ]
deps = [ deps = [
...@@ -406,6 +413,8 @@ source_set("eg_test_support+eg2") { ...@@ -406,6 +413,8 @@ source_set("eg_test_support+eg2") {
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test:element_selector", "//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server",
"//net:test_support",
"//ui/base", "//ui/base",
"//url", "//url",
] ]
......
...@@ -3,22 +3,18 @@ ...@@ -3,22 +3,18 @@
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/chrome/test/earl_grey/chrome_error_util.h"
#import <objc/runtime.h> #import <objc/runtime.h>
#import <EarlGrey/EarlGrey.h>
#include <memory> #include <memory>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/mac/scoped_block.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/signin/core/browser/signin_switches.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#include "ios/chrome/test/app/signin_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_error_util.h"
#import "ios/chrome/test/earl_grey/chrome_test_case_app_interface.h"
#import "ios/testing/earl_grey/coverage_utils.h" #import "ios/testing/earl_grey/coverage_utils.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -81,8 +77,36 @@ NSArray* whiteListedMultitaskingTests = @[ ...@@ -81,8 +77,36 @@ NSArray* whiteListedMultitaskingTests = @[
const CFTimeInterval kDrainTimeout = 5; const CFTimeInterval kDrainTimeout = 5;
void SetUpMockAuthentication() {
[ChromeTestCaseAppInterface setUpMockAuthentication];
}
void TearDownMockAuthentication() {
[ChromeTestCaseAppInterface tearDownMockAuthentication];
}
void ResetAuthentication() {
[ChromeTestCaseAppInterface resetAuthentication];
}
void RemoveInfoBarsAndPresentedState() {
[ChromeTestCaseAppInterface removeInfoBarsAndPresentedState];
}
UIDeviceOrientation GetCurrentDeviceOrientation() {
#if defined(CHROME_EARL_GREY_1)
return [[UIDevice currentDevice] orientation];
#elif defined(CHROME_EARL_GREY_2)
return [[GREY_REMOTE_CLASS_IN_APP(UIDevice) currentDevice] orientation];
#endif
}
} // namespace } // namespace
#if defined(CHROME_EARL_GREY_2)
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
#endif
@interface ChromeTestCase () { @interface ChromeTestCase () {
// Block to be executed during object tearDown. // Block to be executed during object tearDown.
ProceduralBlock _tearDownHandler; ProceduralBlock _tearDownHandler;
...@@ -165,8 +189,7 @@ const CFTimeInterval kDrainTimeout = 5; ...@@ -165,8 +189,7 @@ const CFTimeInterval kDrainTimeout = 5;
// ensure the UI is in a clean state. // ensure the UI is in a clean state.
[self removeAnyOpenMenusAndInfoBars]; [self removeAnyOpenMenusAndInfoBars];
[self closeAllTabs]; [self closeAllTabs];
CHROME_EG_ASSERT_NO_ERROR( [ChromeEarlGrey setContentSettings:CONTENT_SETTING_DEFAULT];
[ChromeEarlGrey setContentSettings:CONTENT_SETTING_DEFAULT]);
[CoverageUtils configureCoverageReportPath]; [CoverageUtils configureCoverageReportPath];
} }
...@@ -194,16 +217,13 @@ const CFTimeInterval kDrainTimeout = 5; ...@@ -194,16 +217,13 @@ const CFTimeInterval kDrainTimeout = 5;
_isHTTPServerStopped = NO; _isHTTPServerStopped = NO;
_isMockAuthenticationDisabled = NO; _isMockAuthenticationDisabled = NO;
_tearDownHandler = nil; _tearDownHandler = nil;
_originalOrientation = [[UIDevice currentDevice] orientation]; _originalOrientation = GetCurrentDeviceOrientation();
chrome_test_util::ResetSigninPromoPreferences(); ResetAuthentication();
chrome_test_util::ResetMockAuthentication();
// Reset any remaining sign-in state from previous tests. // Reset any remaining sign-in state from previous tests.
GREYAssert(chrome_test_util::SignOutAndClearAccounts(), [ChromeEarlGrey signOutAndClearAccounts];
@"Failed to clean up the sign-in state before starting the test."); [ChromeEarlGrey openNewTab];
CHROME_EG_ASSERT_NO_ERROR([ChromeEarlGrey openNewTab]);
} }
// Tear down called once per test, to close all tabs and menus, and clear the // Tear down called once per test, to close all tabs and menus, and clear the
...@@ -215,7 +235,7 @@ const CFTimeInterval kDrainTimeout = 5; ...@@ -215,7 +235,7 @@ const CFTimeInterval kDrainTimeout = 5;
} }
// Clear any remaining test accounts and signed in users. // Clear any remaining test accounts and signed in users.
chrome_test_util::SignOutAndClearAccounts(); [ChromeEarlGrey signOutAndClearAccounts];
// Re-start anything that was disabled this test, so it is running when the // Re-start anything that was disabled this test, so it is running when the
// next test starts. // next test starts.
...@@ -233,10 +253,16 @@ const CFTimeInterval kDrainTimeout = 5; ...@@ -233,10 +253,16 @@ const CFTimeInterval kDrainTimeout = 5;
[[self class] removeAnyOpenMenusAndInfoBars]; [[self class] removeAnyOpenMenusAndInfoBars];
[[self class] closeAllTabs]; [[self class] closeAllTabs];
if ([[UIDevice currentDevice] orientation] != _originalOrientation) { if (GetCurrentDeviceOrientation() != _originalOrientation) {
// Rotate the device back to the original orientation, since some tests // Rotate the device back to the original orientation, since some tests
// attempt to run in other orientations. // attempt to run in other orientations.
#if defined(CHROME_EARL_GREY_1)
[EarlGrey rotateDeviceToOrientation:_originalOrientation errorOrNil:nil]; [EarlGrey rotateDeviceToOrientation:_originalOrientation errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:_originalOrientation error:nil];
#else
#error Neither CHROME_EARL_GREY_1 nor CHROME_EARL_GREY_2 are defined
#endif
} }
[super tearDown]; [super tearDown];
} }
...@@ -250,8 +276,7 @@ const CFTimeInterval kDrainTimeout = 5; ...@@ -250,8 +276,7 @@ const CFTimeInterval kDrainTimeout = 5;
} }
+ (void)removeAnyOpenMenusAndInfoBars { + (void)removeAnyOpenMenusAndInfoBars {
chrome_test_util::RemoveAllInfoBars(); RemoveInfoBarsAndPresentedState();
chrome_test_util::ClearPresentedState();
// After programatically removing UI elements, allow Earl Grey's // After programatically removing UI elements, allow Earl Grey's
// UI synchronization to become idle, so subsequent steps won't start before // UI synchronization to become idle, so subsequent steps won't start before
// the UI is in a good state. // the UI is in a good state.
...@@ -285,15 +310,13 @@ const CFTimeInterval kDrainTimeout = 5; ...@@ -285,15 +310,13 @@ const CFTimeInterval kDrainTimeout = 5;
+ (void)disableMockAuthentication { + (void)disableMockAuthentication {
// Make sure local data is cleared, before disabling mock authentication, // Make sure local data is cleared, before disabling mock authentication,
// where data may be sent to real servers. // where data may be sent to real servers.
chrome_test_util::SignOutAndClearAccounts(); [ChromeEarlGrey signOutAndClearAccounts];
[ChromeEarlGrey tearDownFakeSyncServer]; [ChromeEarlGrey tearDownFakeSyncServer];
chrome_test_util::TearDownMockAccountReconcilor(); TearDownMockAuthentication();
chrome_test_util::TearDownMockAuthentication();
} }
+ (void)enableMockAuthentication { + (void)enableMockAuthentication {
chrome_test_util::SetUpMockAuthentication(); SetUpMockAuthentication();
chrome_test_util::SetUpMockAccountReconcilor();
[ChromeEarlGrey setUpFakeSyncServer]; [ChromeEarlGrey setUpFakeSyncServer];
} }
......
// 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_TEST_EARL_GREY_CHROME_TEST_CASE_APP_INTERFACE_H_
#define IOS_CHROME_TEST_EARL_GREY_CHROME_TEST_CASE_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
@interface ChromeTestCaseAppInterface : NSObject
// Sets up mock authentication and the mock account reconcilor.
+ (void)setUpMockAuthentication;
// Tears down mock authentication and the mock account reconcilor.
+ (void)tearDownMockAuthentication;
// Resets mock authentication and signin promo settings.
+ (void)resetAuthentication;
// Removes all infobars and clears any presented state.
+ (void)removeInfoBarsAndPresentedState;
@end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_TEST_CASE_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/test/earl_grey/chrome_test_case_app_interface.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#include "ios/chrome/test/app/signin_test_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ChromeTestCaseAppInterface
+ (void)setUpMockAuthentication {
chrome_test_util::SetUpMockAuthentication();
chrome_test_util::SetUpMockAccountReconcilor();
}
+ (void)tearDownMockAuthentication {
chrome_test_util::TearDownMockAccountReconcilor();
chrome_test_util::TearDownMockAuthentication();
}
+ (void)resetAuthentication {
chrome_test_util::ResetSigninPromoPreferences();
chrome_test_util::ResetMockAuthentication();
}
+ (void)removeInfoBarsAndPresentedState {
chrome_test_util::RemoveAllInfoBars();
chrome_test_util::ClearPresentedState();
}
@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