Commit b13e6391 authored by Maksym Onufriienko's avatar Maksym Onufriienko Committed by Commit Bot

Replace [GREYConfiguration sharedInstance] with ScopedSynchronizationDisabler.

This is part of EG1 to EG2 migration, which involves moving
EarlGrey code from app-side helpers into test code.
EarlGrey2 has multiprocess architecture,
where Chrome Test and Chrome App are separate processes

Change-Id: If2dc2115f5c11c906806edacef567bc6f1d02204
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733891
Commit-Queue: Maksym Onufriienko <monufriienko@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684118}
parent 64bec395
......@@ -242,6 +242,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/toolbar/buttons",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test:eg_test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:test_support",
......
......@@ -26,6 +26,7 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.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/http_server/delayed_response_provider.h"
......@@ -115,13 +116,6 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
@implementation TabUsageRecorderTestCase
- (void)tearDown {
[[GREYConfiguration sharedInstance]
setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
[super tearDown];
}
// Tests that the recorder actual recorde tab state.
// TODO(crbug.com/934228) The test is flaky.
- (void)DISABLED_testTabSwitchRecorder {
......@@ -391,20 +385,16 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
std::make_unique<HtmlResponseProvider>(responses), kSlowURLDelay));
SwitchToNormalMode();
// Turn off synchronization of GREYAssert to test the pending states.
[[GREYConfiguration sharedInstance]
setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
GREYAssert(
[[GREYCondition conditionWithName:@"Wait for tab to restart loading."
block:^BOOL() {
return [ChromeEarlGrey isLoading];
}] waitWithTimeout:kWaitElementTimeout],
@"Tab did not start loading.");
[[GREYConfiguration sharedInstance]
setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
{
// Turn off synchronization of GREYAssert to test the pending states.
ScopedSynchronizationDisabler disabler;
GREYAssert(
[[GREYCondition conditionWithName:@"Wait for tab to restart loading."
block:^BOOL() {
return [ChromeEarlGrey isLoading];
}] waitWithTimeout:kWaitElementTimeout],
@"Tab did not start loading.");
}
// This method is not synced on EarlGrey.
[ChromeEarlGrey selectTabAtIndex:0];
......@@ -445,19 +435,16 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
// TODO(crbug.com/640977): EarlGrey synchronize on some animations when a
// page is loading. Need to handle synchronization manually for this test.
[[GREYConfiguration sharedInstance]
setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
// Make sure the button is here and displayed before tapping it.
id<GREYMatcher> toolMenuMatcher =
grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu");
{
ScopedSynchronizationDisabler disabler;
// Make sure the button is here and displayed before tapping it.
id<GREYMatcher> toolMenuMatcher =
grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu");
[ChromeEarlGrey openNewTab];
[[GREYConfiguration sharedInstance]
setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
[ChromeEarlGrey openNewTab];
}
histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload,
TabUsageRecorder::USER_DID_NOT_WAIT, 1,
failureBlock);
......@@ -522,18 +509,15 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
// TODO(crbug.com/640977): EarlGrey synchronize on some animations when a
// page is loading. Need to handle synchronization manually for this test.
[[GREYConfiguration sharedInstance]
setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
id<GREYMatcher> toolMenuMatcher =
grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu");
[ChromeEarlGrey simulateTabsBackgrounding];
[[GREYConfiguration sharedInstance]
setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
{
ScopedSynchronizationDisabler disabler;
id<GREYMatcher> toolMenuMatcher =
grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier),
grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu");
[ChromeEarlGrey simulateTabsBackgrounding];
}
FailureBlock failureBlock = ^(NSString* error) {
GREYFail(error);
......@@ -557,17 +541,14 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
// We need two tabs to be able to switch.
[ChromeEarlGrey openNewTab];
[[GREYConfiguration sharedInstance]
setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
[ChromeEarlGrey loadURL:slowURL waitForCompletion:NO];
{
ScopedSynchronizationDisabler disabler;
[ChromeEarlGrey loadURL:slowURL waitForCompletion:NO];
// Ensure loading starts but is not finished.
base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSeconds(1));
[ChromeEarlGrey selectTabAtIndex:0];
[[GREYConfiguration sharedInstance]
setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
// Ensure loading starts but is not finished.
base::test::ios::SpinRunLoopWithMaxDelay(base::TimeDelta::FromSeconds(1));
[ChromeEarlGrey selectTabAtIndex:0];
}
FailureBlock failureBlock = ^(NSString* error) {
GREYFail(error);
......
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