Commit 6d0700c2 authored by vabr's avatar vabr Committed by Commit bot

Fix PasswordsSettingsTestCase.testCopyPasswordToast

The tested settings have a button just at the bottom end of the screen on small devices. Tapping the button results in showing a snackbar, which covers the button on small devices. testCopyPasswordToast in particular needs to tap the copy button twice. The second tap was impossible on small devices because the snackbar was still around, blocking the button.

This CL adds two actions to prevent this issue:

(1) While checking for the snackbar, the test also taps it, causing it to close. The test waits for the fade-out animation to finish.

(2) The test also uses usingSearchAction:grey_scrollInDirection to ask EarlGrey to scroll until the control is clickable.

Even though either single option from the above would fix the current issue, the CL contains both: (2) because it will also be useful on smaller devices, e.g., should we start testing in landscape mode (see https://crbug.com/717548 and also https://crbug.com/717163 for another blocker for landscape mode), where the buttons will be off the screen instead of just being covered. It also includes (1), because cleaning up the snackbar explicitly seems like a reasonable thing to do. Speaking of cleaning up, the CL also:

(3) Forcibly closes all passwords-related snackbars on teardown. This will be useful when the test fails in the middle, leaving a snackbar up. If not foce-closed, such snackbar would remain visible for (currently) 4 seconds, which might be enough to interfere with the next test.

The CL also applied (1) and (2) to two other tests in the same suite as well. Those deal with similar buttons, which are currently high enough not to experience the problem with being blocked. This secures them in case that, e.g., the layout changes in the future.

Note that while (2) is clearly beneficial, it also has a drawback: the search action takes a considerable amount of time (about 2 seconds per one scrolling step on my computer). With it, the tests are more likely to time out. If there is an issue with timing out in the future, we should increase kScrollAmount to speed up the scrolling, or split long tests (testCopyPasswordToast is a particular candidate).

BUG=718043

Review-Url: https://codereview.chromium.org/2860453004
Cr-Commit-Position: refs/heads/master@{#469361}
parent 69b6c44a
......@@ -97,6 +97,8 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule
_site = base::SysUTF8ToNSString(_passwordForm.origin.spec());
self.title =
[PasswordDetailsCollectionViewController simplifyOrigin:origin];
self.collectionViewAccessibilityIdentifier =
@"PasswordDetailsCollectionViewController";
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(hidePassword)
......@@ -377,6 +379,7 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule
// to mock it in the unittest, and avoid having an EGTest just for that?
MDCSnackbarMessage* copyPasswordResultMessage =
[MDCSnackbarMessage messageWithText:message];
copyPasswordResultMessage.category = @"PasswordsSnackbarCategory";
[MDCSnackbarManager showMessage:copyPasswordResultMessage];
}
......
......@@ -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/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
......@@ -48,6 +49,11 @@ using chrome_test_util::NavigationBarDoneButton;
namespace {
// How many points to scroll at a time when searching for an element. Setting it
// too low means searching takes too long and the test might time out. Setting
// it too high could result in scrolling way past the searched element.
constexpr int kScrollAmount = 150;
// Matcher for the Settings button in the tools menu.
id<GREYMatcher> SettingsButton() {
return grey_accessibilityID(kToolsMenuSettingsId);
......@@ -121,6 +127,7 @@ GREYLayoutConstraint* Below() {
// Matcher for the Copy site button in Password Details view.
id<GREYMatcher> CopySiteButton() {
return grey_allOf(
grey_interactable(),
ButtonWithAccessibilityLabel(
[NSString stringWithFormat:@"%@: %@",
l10n_util::GetNSString(
......@@ -135,6 +142,7 @@ id<GREYMatcher> CopySiteButton() {
// Matcher for the Copy username button in Password Details view.
id<GREYMatcher> CopyUsernameButton() {
return grey_allOf(
grey_interactable(),
ButtonWithAccessibilityLabel([NSString
stringWithFormat:@"%@: %@",
l10n_util::GetNSString(
......@@ -149,6 +157,7 @@ id<GREYMatcher> CopyUsernameButton() {
// Matcher for the Copy password button in Password Details view.
id<GREYMatcher> CopyPasswordButton() {
return grey_allOf(
grey_interactable(),
ButtonWithAccessibilityLabel([NSString
stringWithFormat:@"%@: %@",
l10n_util::GetNSString(
......@@ -190,6 +199,15 @@ id<GREYMatcher> CopyPasswordButton() {
@implementation PasswordsSettingsTestCase
- (void)tearDown {
// Snackbars triggered by tests stay up for a limited time even if the
// settings get closed. Ensure that they are closed to avoid interference with
// other tests.
[MDCSnackbarManager
dismissAndCallCompletionBlocksWithCategory:@"PasswordsSnackbarCategory"];
[super tearDown];
}
// Return pref for saving passwords back to the passed value and restores the
// experimental flag for viewing passwords.
- (void)passwordsTearDown:(BOOL)defaultPasswordManagementSetting
......@@ -339,8 +357,7 @@ id<GREYMatcher> CopyPasswordButton() {
// Checks that attempts to copy a password provide appropriate feedback,
// both when reauthentication succeeds and when it fails.
// TODO(crbug.com/718043): Re-enable test.
- (void)DISABLED_testCopyPasswordToast {
- (void)testCopyPasswordToast {
[self scopedEnablePasswordManagementAndViewingUI];
// Saving a form is needed for using the "password details" view.
......@@ -368,23 +385,37 @@ id<GREYMatcher> CopyPasswordButton() {
// Check the snackbar in case of successful reauthentication.
mock_reauthentication_module.shouldSucceed = YES;
[[EarlGrey selectElementWithMatcher:CopyPasswordButton()]
[[[EarlGrey selectElementWithMatcher:CopyPasswordButton()]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
kScrollAmount)
onElementWithMatcher:grey_accessibilityID(
@"PasswordDetailsCollectionViewController")]
performAction:grey_tap()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
NSString* snackbarLabel =
l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE);
// The tap checks the existence of the snackbar and also closes it.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)]
assertWithMatcher:grey_notNil()];
performAction:grey_tap()];
// Wait until the fade-out animation completes.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Check the snackbar in case of failed reauthentication.
mock_reauthentication_module.shouldSucceed = NO;
[[EarlGrey selectElementWithMatcher:CopyPasswordButton()]
[[[EarlGrey selectElementWithMatcher:CopyPasswordButton()]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
kScrollAmount)
onElementWithMatcher:grey_accessibilityID(
@"PasswordDetailsCollectionViewController")]
performAction:grey_tap()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
snackbarLabel =
l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE);
// The tap checks the existence of the snackbar and also closes it.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)]
assertWithMatcher:grey_notNil()];
performAction:grey_tap()];
// Wait until the fade-out animation completes.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
[self tapBackArrow];
[self tapBackArrow];
......@@ -405,13 +436,20 @@ id<GREYMatcher> CopyPasswordButton() {
performAction:grey_tap()];
// Check the snackbar.
[[EarlGrey selectElementWithMatcher:CopyUsernameButton()]
[[[EarlGrey selectElementWithMatcher:CopyUsernameButton()]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
kScrollAmount)
onElementWithMatcher:grey_accessibilityID(
@"PasswordDetailsCollectionViewController")]
performAction:grey_tap()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
NSString* snackbarLabel =
l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE);
// The tap checks the existence of the snackbar and also closes it.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)]
assertWithMatcher:grey_notNil()];
performAction:grey_tap()];
// Wait until the fade-out animation completes.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
[self tapBackArrow];
[self tapBackArrow];
......@@ -432,13 +470,20 @@ id<GREYMatcher> CopyPasswordButton() {
performAction:grey_tap()];
// Check the snackbar.
[[EarlGrey selectElementWithMatcher:CopySiteButton()]
[[[EarlGrey selectElementWithMatcher:CopySiteButton()]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
kScrollAmount)
onElementWithMatcher:grey_accessibilityID(
@"PasswordDetailsCollectionViewController")]
performAction:grey_tap()];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
NSString* snackbarLabel =
l10n_util::GetNSString(IDS_IOS_SETTINGS_SITE_WAS_COPIED_MESSAGE);
// The tap checks the existence of the snackbar and also closes it.
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)]
assertWithMatcher:grey_notNil()];
performAction:grey_tap()];
// Wait until the fade-out animation completes.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
[self tapBackArrow];
[self tapBackArrow];
......
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