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