Commit e30dc321 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: Ib41116bb8df8c8383ad8a76460d5643560983716
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1732157
Commit-Queue: Maksym Onufriienko <monufriienko@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683767}
parent 529c3c87
...@@ -514,6 +514,7 @@ source_set("eg_tests") { ...@@ -514,6 +514,7 @@ source_set("eg_tests") {
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/autofill:autofill_shared", "//ios/chrome/browser/autofill:autofill_shared",
"//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/testing/earl_grey:earl_grey_support", "//ios/testing/earl_grey:earl_grey_support",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#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_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/deprecated/crw_js_injection_receiver.h" #import "ios/web/public/deprecated/crw_js_injection_receiver.h"
#import "ios/web/public/test/earl_grey/web_view_actions.h" #import "ios/web/public/test/earl_grey/web_view_actions.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h" #import "ios/web/public/test/earl_grey/web_view_matchers.h"
...@@ -27,6 +28,9 @@ ...@@ -27,6 +28,9 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
using chrome_test_util::WebViewMatcher; using chrome_test_util::WebViewMatcher;
namespace { namespace {
...@@ -55,8 +59,7 @@ void AssertElementIsFocused(const std::string& element_id) { ...@@ -55,8 +59,7 @@ void AssertElementIsFocused(const std::string& element_id) {
ConditionBlock condition = ^{ ConditionBlock condition = ^{
return base::SysNSStringToUTF8(GetFocusedElementId()) == element_id; return base::SysNSStringToUTF8(GetFocusedElementId()) == element_id;
}; };
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(10, condition), GREYAssert(WaitUntilConditionOrTimeout(10, condition), description);
description);
} }
} // namespace } // namespace
...@@ -68,12 +71,6 @@ void AssertElementIsFocused(const std::string& element_id) { ...@@ -68,12 +71,6 @@ void AssertElementIsFocused(const std::string& element_id) {
@implementation FormInputTestCase @implementation FormInputTestCase
- (void)tearDown { - (void)tearDown {
// |testFindDefaultFormAssistControls| disables synchronization.
// This makes sure it is enabled if that test has failed and did not enable it
// back.
[[GREYConfiguration sharedInstance]
setValue:@YES
forConfigKey:kGREYConfigKeySynchronizationEnabled];
[super tearDown]; [super tearDown];
} }
...@@ -96,61 +93,57 @@ void AssertElementIsFocused(const std::string& element_id) { ...@@ -96,61 +93,57 @@ void AssertElementIsFocused(const std::string& element_id) {
[ChromeEarlGrey waitForWebStateContainingText:"hello!"]; [ChromeEarlGrey waitForWebStateContainingText:"hello!"];
// Opening the keyboard from a webview blocks EarlGrey's synchronization. // Opening the keyboard from a webview blocks EarlGrey's synchronization.
[[GREYConfiguration sharedInstance] {
setValue:@NO ScopedSynchronizationDisabler disabler;
forConfigKey:kGREYConfigKeySynchronizationEnabled];
// Brings up the keyboard by tapping on one of the form's field.
// Brings up the keyboard by tapping on one of the form's field. [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
[[EarlGrey selectElementWithMatcher:WebViewMatcher()] performAction:web::WebViewTapElement(
performAction:web::WebViewTapElement( chrome_test_util::GetCurrentWebState(),
chrome_test_util::GetCurrentWebState(), [ElementSelector
[ElementSelector selectorWithElementID:kFormElementId1])];
selectorWithElementID:kFormElementId1])];
id<GREYMatcher> nextButtonMatcher =
id<GREYMatcher> nextButtonMatcher = chrome_test_util::ButtonWithAccessibilityLabelId(
chrome_test_util::ButtonWithAccessibilityLabelId( IDS_IOS_AUTOFILL_ACCNAME_NEXT_FIELD);
IDS_IOS_AUTOFILL_ACCNAME_NEXT_FIELD); id<GREYMatcher> previousButtonMatcher =
id<GREYMatcher> previousButtonMatcher = chrome_test_util::ButtonWithAccessibilityLabelId(
chrome_test_util::ButtonWithAccessibilityLabelId( IDS_IOS_AUTOFILL_ACCNAME_PREVIOUS_FIELD);
IDS_IOS_AUTOFILL_ACCNAME_PREVIOUS_FIELD); id<GREYMatcher> closeButtonMatcher =
id<GREYMatcher> closeButtonMatcher = chrome_test_util::ButtonWithAccessibilityLabelId(
chrome_test_util::ButtonWithAccessibilityLabelId( IDS_IOS_AUTOFILL_ACCNAME_HIDE_KEYBOARD);
IDS_IOS_AUTOFILL_ACCNAME_HIDE_KEYBOARD);
// Wait until the keyboard's "Next" button appeared.
// Wait until the keyboard's "Next" button appeared. NSString* description =
NSString* description = @"Wait for the keyboard's \"Next\" button to appear."; @"Wait for the keyboard's \"Next\" button to appear.";
ConditionBlock condition = ^{ ConditionBlock condition = ^{
NSError* error = nil; NSError* error = nil;
[[EarlGrey selectElementWithMatcher:nextButtonMatcher]
assertWithMatcher:grey_notNil()
error:&error];
return (error == nil);
};
GREYAssert(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, condition),
description);
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSeconds(1));
// Verifies that the taped element is focused.
AssertElementIsFocused(kFormElementId1);
// Tap the "Next" button.
[[EarlGrey selectElementWithMatcher:nextButtonMatcher] [[EarlGrey selectElementWithMatcher:nextButtonMatcher]
assertWithMatcher:grey_notNil() performAction:grey_tap()];
error:&error]; AssertElementIsFocused(kFormElementId2);
return (error == nil);
}; // Tap the "Previous" button.
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout( [[EarlGrey selectElementWithMatcher:previousButtonMatcher]
base::test::ios::kWaitForUIElementTimeout, condition), performAction:grey_tap()];
description); AssertElementIsFocused(kFormElementId1);
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSeconds(1));
// Tap the "Close" button.
// Verifies that the taped element is focused. [[EarlGrey selectElementWithMatcher:closeButtonMatcher]
AssertElementIsFocused(kFormElementId1); performAction:grey_tap()];
}
// Tap the "Next" button.
[[EarlGrey selectElementWithMatcher:nextButtonMatcher]
performAction:grey_tap()];
AssertElementIsFocused(kFormElementId2);
// Tap the "Previous" button.
[[EarlGrey selectElementWithMatcher:previousButtonMatcher]
performAction:grey_tap()];
AssertElementIsFocused(kFormElementId1);
// Tap the "Close" button.
[[EarlGrey selectElementWithMatcher:closeButtonMatcher]
performAction:grey_tap()];
[[GREYConfiguration sharedInstance]
setValue:@YES
forConfigKey:kGREYConfigKeySynchronizationEnabled];
} }
// Tests that trying to programmatically dismiss the keyboard when it isn't // Tests that trying to programmatically dismiss the keyboard when it isn't
......
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