| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Copy buttons have unique accessibility labels, but the visible text is the | 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 | 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 | 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: | 74 // respective section headers as well. The scheme of the vertical order is: |
| 75 // Site header |
| 76 // Copy (site) button |
| 75 // Username header | 77 // Username header |
| 76 // Copy (username) button | 78 // Copy (username) button |
| 77 // Password header | 79 // Password header |
| 78 // Copy (password) button | 80 // Copy (password) button |
| 79 | 81 |
| 82 id<GREYMatcher> SiteHeader() { |
| 83 return grey_allOf( |
| 84 grey_accessibilityLabel( |
| 85 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_SITE)), |
| 86 grey_accessibilityTrait(UIAccessibilityTraitHeader), nullptr); |
| 87 } |
| 88 |
| 89 id<GREYMatcher> UsernameHeader() { |
| 90 return grey_allOf( |
| 91 grey_accessibilityLabel( |
| 92 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME)), |
| 93 grey_accessibilityTrait(UIAccessibilityTraitHeader), nullptr); |
| 94 } |
| 95 |
| 80 id<GREYMatcher> PasswordHeader() { | 96 id<GREYMatcher> PasswordHeader() { |
| 81 return grey_allOf( | 97 return grey_allOf( |
| 82 grey_accessibilityLabel( | 98 grey_accessibilityLabel( |
| 83 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD)), | 99 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD)), |
| 84 grey_accessibilityTrait(UIAccessibilityTraitHeader), nullptr); | 100 grey_accessibilityTrait(UIAccessibilityTraitHeader), nullptr); |
| 85 } | 101 } |
| 86 | 102 |
| 87 // Matcher for the Copy username button in Password Details view. This is the | 103 GREYLayoutConstraint* Above() { |
| 88 // button above the Password section header. | 104 return [GREYLayoutConstraint |
| 89 id<GREYMatcher> CopyUsernameButton() { | |
| 90 GREYLayoutConstraint* above = [GREYLayoutConstraint | |
| 91 layoutConstraintWithAttribute:kGREYLayoutAttributeBottom | 105 layoutConstraintWithAttribute:kGREYLayoutAttributeBottom |
| 92 relatedBy:kGREYLayoutRelationLessThanOrEqual | 106 relatedBy:kGREYLayoutRelationLessThanOrEqual |
| 93 toReferenceAttribute:kGREYLayoutAttributeTop | 107 toReferenceAttribute:kGREYLayoutAttributeTop |
| 94 multiplier:1.0 | 108 multiplier:1.0 |
| 95 constant:0.0]; | 109 constant:0.0]; |
| 110 } |
| 111 |
| 112 GREYLayoutConstraint* Below() { |
| 113 return [GREYLayoutConstraint |
| 114 layoutConstraintWithAttribute:kGREYLayoutAttributeTop |
| 115 relatedBy:kGREYLayoutRelationGreaterThanOrEqual |
| 116 toReferenceAttribute:kGREYLayoutAttributeBottom |
| 117 multiplier:1.0 |
| 118 constant:0.0]; |
| 119 } |
| 120 |
| 121 // Matcher for the Copy site button in Password Details view. |
| 122 id<GREYMatcher> CopySiteButton() { |
| 123 return grey_allOf( |
| 124 ButtonWithAccessibilityLabel( |
| 125 [NSString stringWithFormat:@"%@: %@", |
| 126 l10n_util::GetNSString( |
| 127 IDS_IOS_SHOW_PASSWORD_VIEW_SITE), |
| 128 l10n_util::GetNSString( |
| 129 IDS_IOS_SETTINGS_SITE_COPY_BUTTON)]), |
| 130 grey_layout(@[ Below() ], SiteHeader()), |
| 131 grey_layout(@[ Above() ], UsernameHeader()), |
| 132 grey_layout(@[ Above() ], PasswordHeader()), nullptr); |
| 133 } |
| 134 |
| 135 // Matcher for the Copy username button in Password Details view. |
| 136 id<GREYMatcher> CopyUsernameButton() { |
| 96 return grey_allOf( | 137 return grey_allOf( |
| 97 ButtonWithAccessibilityLabel([NSString | 138 ButtonWithAccessibilityLabel([NSString |
| 98 stringWithFormat:@"%@: %@", | 139 stringWithFormat:@"%@: %@", |
| 99 l10n_util::GetNSString( | 140 l10n_util::GetNSString( |
| 100 IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME), | 141 IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME), |
| 101 l10n_util::GetNSString( | 142 l10n_util::GetNSString( |
| 102 IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON)]), | 143 IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON)]), |
| 103 grey_layout(@[ above ], PasswordHeader()), nullptr); | 144 grey_layout(@[ Below() ], SiteHeader()), |
| 145 grey_layout(@[ Below() ], UsernameHeader()), |
| 146 grey_layout(@[ Above() ], PasswordHeader()), nullptr); |
| 104 } | 147 } |
| 105 | 148 |
| 106 // Matcher for the Copy password button in Password Details view. This is the | 149 // Matcher for the Copy password button in Password Details view. |
| 107 // button below the Password section header. | |
| 108 id<GREYMatcher> CopyPasswordButton() { | 150 id<GREYMatcher> CopyPasswordButton() { |
| 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( | 151 return grey_allOf( |
| 116 ButtonWithAccessibilityLabel([NSString | 152 ButtonWithAccessibilityLabel([NSString |
| 117 stringWithFormat:@"%@: %@", | 153 stringWithFormat:@"%@: %@", |
| 118 l10n_util::GetNSString( | 154 l10n_util::GetNSString( |
| 119 IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD), | 155 IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD), |
| 120 l10n_util::GetNSString( | 156 l10n_util::GetNSString( |
| 121 IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON)]), | 157 IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON)]), |
| 122 grey_layout(@[ below ], PasswordHeader()), nullptr); | 158 grey_layout(@[ Below() ], SiteHeader()), |
| 159 grey_layout(@[ Below() ], UsernameHeader()), |
| 160 grey_layout(@[ Below() ], PasswordHeader()), nullptr); |
| 123 } | 161 } |
| 124 | 162 |
| 125 } // namespace | 163 } // namespace |
| 126 | 164 |
| 127 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> | 165 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> |
| 128 | 166 |
| 129 @property(nonatomic, assign) BOOL shouldSucceed; | 167 @property(nonatomic, assign) BOOL shouldSucceed; |
| 130 | 168 |
| 131 @end | 169 @end |
| 132 | 170 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE); | 411 l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE); |
| 374 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] | 412 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] |
| 375 assertWithMatcher:grey_notNil()]; | 413 assertWithMatcher:grey_notNil()]; |
| 376 | 414 |
| 377 [self tapBackArrow]; | 415 [self tapBackArrow]; |
| 378 [self tapBackArrow]; | 416 [self tapBackArrow]; |
| 379 [self tapDone]; | 417 [self tapDone]; |
| 380 [self clearPasswordStore]; | 418 [self clearPasswordStore]; |
| 381 } | 419 } |
| 382 | 420 |
| 421 // Checks that attempts to copy a site URL provide appropriate feedback. |
| 422 - (void)testCopySiteToast { |
| 423 [self scopedEnablePasswordManagementAndViewingUI]; |
| 424 |
| 425 // Saving a form is needed for using the "password details" view. |
| 426 [self saveExamplePasswordForm]; |
| 427 |
| 428 [self openPasswordSettings]; |
| 429 |
| 430 [[EarlGrey selectElementWithMatcher:Entry(@"https://example.com, user")] |
| 431 performAction:grey_tap()]; |
| 432 |
| 433 // Check the snackbar. |
| 434 [[EarlGrey selectElementWithMatcher:CopySiteButton()] |
| 435 performAction:grey_tap()]; |
| 436 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 437 NSString* snackbarLabel = |
| 438 l10n_util::GetNSString(IDS_IOS_SETTINGS_SITE_WAS_COPIED_MESSAGE); |
| 439 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] |
| 440 assertWithMatcher:grey_notNil()]; |
| 441 |
| 442 [self tapBackArrow]; |
| 443 [self tapBackArrow]; |
| 444 [self tapDone]; |
| 445 [self clearPasswordStore]; |
| 446 } |
| 447 |
| 383 @end | 448 @end |
| OLD | NEW |