Skip to content

Commit

Permalink
[ios] Compiles ChromeTestCase under EG2.
Browse files Browse the repository at this point in the history
BUG=922813

Change-Id: Ie9545589a8f99ff3ef7652ce06d3ab117fe2499e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1628049
Reviewed-by: Eugene But <eugenebut@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663131}
  • Loading branch information
Rohit Rao authored and Commit Bot committed May 24, 2019
1 parent e61302d commit ee8d0c6
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 25 deletions.
9 changes: 9 additions & 0 deletions ios/chrome/test/earl_grey/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ source_set("test_support") {
"chrome_matchers_app_interface.mm",
"chrome_test_case.h",
"chrome_test_case.mm",
"chrome_test_case_app_interface.h",
"chrome_test_case_app_interface.mm",
]

deps = [
Expand Down Expand Up @@ -332,6 +334,8 @@ source_set("eg_app_support+eg2") {
"chrome_earl_grey_app_interface.mm",
"chrome_matchers_app_interface.h",
"chrome_matchers_app_interface.mm",
"chrome_test_case_app_interface.h",
"chrome_test_case_app_interface.mm",
]

deps = [
Expand Down Expand Up @@ -392,6 +396,9 @@ source_set("eg_test_support+eg2") {
"chrome_matchers.h",
"chrome_matchers.mm",
"chrome_matchers_app_interface.h",
"chrome_test_case.h",
"chrome_test_case.mm",
"chrome_test_case_app_interface.h",
]

deps = [
Expand All @@ -406,6 +413,8 @@ source_set("eg_test_support+eg2") {
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server",
"//net:test_support",
"//ui/base",
"//url",
]
Expand Down
73 changes: 48 additions & 25 deletions ios/chrome/test/earl_grey/chrome_test_case.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
// found in the LICENSE file.

#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 <EarlGrey/EarlGrey.h>

#include <memory>

#include "base/command_line.h"
#include "base/mac/scoped_block.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_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/earl_grey_test.h"
#import "ios/web/public/test/http_server/http_server.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand Down Expand Up @@ -81,8 +77,36 @@

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

#if defined(CHROME_EARL_GREY_2)
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
#endif

@interface ChromeTestCase () {
// Block to be executed during object tearDown.
ProceduralBlock _tearDownHandler;
Expand Down Expand Up @@ -165,8 +189,7 @@ + (void)setUp {
// ensure the UI is in a clean state.
[self removeAnyOpenMenusAndInfoBars];
[self closeAllTabs];
CHROME_EG_ASSERT_NO_ERROR(
[ChromeEarlGrey setContentSettings:CONTENT_SETTING_DEFAULT]);
[ChromeEarlGrey setContentSettings:CONTENT_SETTING_DEFAULT];

[CoverageUtils configureCoverageReportPath];
}
Expand Down Expand Up @@ -194,16 +217,13 @@ - (void)setUp {
_isHTTPServerStopped = NO;
_isMockAuthenticationDisabled = NO;
_tearDownHandler = nil;
_originalOrientation = [[UIDevice currentDevice] orientation];
_originalOrientation = GetCurrentDeviceOrientation();

chrome_test_util::ResetSigninPromoPreferences();
chrome_test_util::ResetMockAuthentication();
ResetAuthentication();

// Reset any remaining sign-in state from previous tests.
GREYAssert(chrome_test_util::SignOutAndClearAccounts(),
@"Failed to clean up the sign-in state before starting the test.");

CHROME_EG_ASSERT_NO_ERROR([ChromeEarlGrey openNewTab]);
[ChromeEarlGrey signOutAndClearAccounts];
[ChromeEarlGrey openNewTab];
}

// Tear down called once per test, to close all tabs and menus, and clear the
Expand All @@ -215,7 +235,7 @@ - (void)tearDown {
}

// 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
// next test starts.
Expand All @@ -233,10 +253,16 @@ - (void)tearDown {
[[self class] removeAnyOpenMenusAndInfoBars];
[[self class] closeAllTabs];

if ([[UIDevice currentDevice] orientation] != _originalOrientation) {
if (GetCurrentDeviceOrientation() != _originalOrientation) {
// Rotate the device back to the original orientation, since some tests
// attempt to run in other orientations.
#if defined(CHROME_EARL_GREY_1)
[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];
}
Expand All @@ -250,8 +276,7 @@ - (void)setTearDownHandler:(ProceduralBlock)tearDownHandler {
}

+ (void)removeAnyOpenMenusAndInfoBars {
chrome_test_util::RemoveAllInfoBars();
chrome_test_util::ClearPresentedState();
RemoveInfoBarsAndPresentedState();
// After programatically removing UI elements, allow Earl Grey's
// UI synchronization to become idle, so subsequent steps won't start before
// the UI is in a good state.
Expand Down Expand Up @@ -285,15 +310,13 @@ - (void)stopHTTPServer {
+ (void)disableMockAuthentication {
// Make sure local data is cleared, before disabling mock authentication,
// where data may be sent to real servers.
chrome_test_util::SignOutAndClearAccounts();
[ChromeEarlGrey signOutAndClearAccounts];
[ChromeEarlGrey tearDownFakeSyncServer];
chrome_test_util::TearDownMockAccountReconcilor();
chrome_test_util::TearDownMockAuthentication();
TearDownMockAuthentication();
}

+ (void)enableMockAuthentication {
chrome_test_util::SetUpMockAuthentication();
chrome_test_util::SetUpMockAccountReconcilor();
SetUpMockAuthentication();
[ChromeEarlGrey setUpFakeSyncServer];
}

Expand Down
26 changes: 26 additions & 0 deletions ios/chrome/test/earl_grey/chrome_test_case_app_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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_
36 changes: 36 additions & 0 deletions ios/chrome/test/earl_grey/chrome_test_case_app_interface.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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

0 comments on commit ee8d0c6

Please sign in to comment.