OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/mac/foundation_util.h" | 6 #include "base/mac/foundation_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "components/autofill/core/common/password_form.h" | 10 #include "components/autofill/core/common/password_form.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Matcher for a password entry for |username|. | 61 // Matcher for a password entry for |username|. |
62 id<GREYMatcher> Entry(NSString* username) { | 62 id<GREYMatcher> Entry(NSString* username) { |
63 return ButtonWithAccessibilityLabel(username); | 63 return ButtonWithAccessibilityLabel(username); |
64 } | 64 } |
65 | 65 |
66 // Matcher for the Edit button in Save Passwords view. | 66 // Matcher for the Edit button in Save Passwords view. |
67 id<GREYMatcher> EditButton() { | 67 id<GREYMatcher> EditButton() { |
68 return ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON); | 68 return ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON); |
69 } | 69 } |
70 | 70 |
71 // Matcher for the Copy password button in Password Details view. | 71 // Copy buttons have unique accessibility labels, but the visible text is the |
| 72 // same for multiple types of copied items (just "Copy"). Therefore the |
| 73 // matchers here check the relative position of the Copy buttons to their |
| 74 // respective section headers as well. The scheme of the vertical order is: |
| 75 // Username header |
| 76 // Copy (username) button |
| 77 // Password header |
| 78 // Copy (password) button |
| 79 |
| 80 id<GREYMatcher> PasswordHeader() { |
| 81 return grey_allOf( |
| 82 grey_accessibilityLabel( |
| 83 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD)), |
| 84 grey_accessibilityTrait(UIAccessibilityTraitHeader), nullptr); |
| 85 } |
| 86 |
| 87 // Matcher for the Copy username button in Password Details view. This is the |
| 88 // button above the Password section header. |
| 89 id<GREYMatcher> CopyUsernameButton() { |
| 90 GREYLayoutConstraint* above = [GREYLayoutConstraint |
| 91 layoutConstraintWithAttribute:kGREYLayoutAttributeBottom |
| 92 relatedBy:kGREYLayoutRelationLessThanOrEqual |
| 93 toReferenceAttribute:kGREYLayoutAttributeTop |
| 94 multiplier:1.0 |
| 95 constant:0.0]; |
| 96 return grey_allOf( |
| 97 ButtonWithAccessibilityLabel([NSString |
| 98 stringWithFormat:@"%@: %@", |
| 99 l10n_util::GetNSString( |
| 100 IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME), |
| 101 l10n_util::GetNSString( |
| 102 IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON)]), |
| 103 grey_layout(@[ above ], PasswordHeader()), nullptr); |
| 104 } |
| 105 |
| 106 // Matcher for the Copy password button in Password Details view. This is the |
| 107 // button below the Password section header. |
72 id<GREYMatcher> CopyPasswordButton() { | 108 id<GREYMatcher> CopyPasswordButton() { |
73 return ButtonWithAccessibilityLabelId(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON); | 109 GREYLayoutConstraint* below = [GREYLayoutConstraint |
| 110 layoutConstraintWithAttribute:kGREYLayoutAttributeTop |
| 111 relatedBy:kGREYLayoutRelationGreaterThanOrEqual |
| 112 toReferenceAttribute:kGREYLayoutAttributeBottom |
| 113 multiplier:1.0 |
| 114 constant:0.0]; |
| 115 return grey_allOf( |
| 116 ButtonWithAccessibilityLabel([NSString |
| 117 stringWithFormat:@"%@: %@", |
| 118 l10n_util::GetNSString( |
| 119 IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD), |
| 120 l10n_util::GetNSString( |
| 121 IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON)]), |
| 122 grey_layout(@[ below ], PasswordHeader()), nullptr); |
74 } | 123 } |
75 | 124 |
76 } // namespace | 125 } // namespace |
77 | 126 |
78 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> | 127 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> |
79 | 128 |
80 @property(nonatomic, assign) BOOL shouldSucceed; | 129 @property(nonatomic, assign) BOOL shouldSucceed; |
81 | 130 |
82 @end | 131 @end |
83 | 132 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE); | 346 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE); |
298 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] | 347 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] |
299 assertWithMatcher:grey_notNil()]; | 348 assertWithMatcher:grey_notNil()]; |
300 | 349 |
301 [self tapBackArrow]; | 350 [self tapBackArrow]; |
302 [self tapBackArrow]; | 351 [self tapBackArrow]; |
303 [self tapDone]; | 352 [self tapDone]; |
304 [self clearPasswordStore]; | 353 [self clearPasswordStore]; |
305 } | 354 } |
306 | 355 |
| 356 // Checks that attempts to copy a username provide appropriate feedback. |
| 357 - (void)testCopyUsernameToast { |
| 358 [self scopedEnablePasswordManagementAndViewingUI]; |
| 359 |
| 360 // Saving a form is needed for using the "password details" view. |
| 361 [self saveExamplePasswordForm]; |
| 362 |
| 363 [self openPasswordSettings]; |
| 364 |
| 365 [[EarlGrey selectElementWithMatcher:Entry(@"https://example.com, user")] |
| 366 performAction:grey_tap()]; |
| 367 |
| 368 // Check the snackbar. |
| 369 [[EarlGrey selectElementWithMatcher:CopyUsernameButton()] |
| 370 performAction:grey_tap()]; |
| 371 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 372 NSString* snackbarLabel = |
| 373 l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE); |
| 374 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] |
| 375 assertWithMatcher:grey_notNil()]; |
| 376 |
| 377 [self tapBackArrow]; |
| 378 [self tapBackArrow]; |
| 379 [self tapDone]; |
| 380 [self clearPasswordStore]; |
| 381 } |
| 382 |
307 @end | 383 @end |
OLD | NEW |