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 are challenging: they have both the same label ("Copy"), and |
72 // what is to be copied is indicated by which section they are in. To match the | |
73 // correct button, the relative position to the section header needs to be | |
74 // captured. The scheme of the vertical order is: | |
75 // Username header | |
76 // Copy (username) button | |
77 // Password header | |
78 // Copy (password) button | |
79 // Therefore to match the correct copy button, one needs to apply grey_layout | |
80 // to express its relative vertical position to the "Password" header. | |
lpromero
2017/05/02 15:04:52
You could also use accessibility identifiers (acce
vabr (Chromium)
2017/05/02 15:29:09
My understanding was that if I could not write a r
| |
81 | |
82 id<GREYMatcher> PasswordHeader() { | |
83 return grey_allOf( | |
84 grey_accessibilityLabel( | |
85 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD)), | |
86 grey_accessibilityTrait(UIAccessibilityTraitHeader), nullptr); | |
87 } | |
88 | |
89 // Matcher for the Copy username button in Password Details view. This is the | |
90 // button above the Password section header. | |
91 id<GREYMatcher> CopyUsernameButton() { | |
92 GREYLayoutConstraint* above = [GREYLayoutConstraint | |
93 layoutConstraintWithAttribute:kGREYLayoutAttributeBottom | |
94 relatedBy:kGREYLayoutRelationLessThanOrEqual | |
95 toReferenceAttribute:kGREYLayoutAttributeTop | |
96 multiplier:1.0 | |
97 constant:0.0]; | |
98 return grey_allOf( | |
99 ButtonWithAccessibilityLabelId(IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON), | |
100 grey_layout(@[ above ], PasswordHeader()), nullptr); | |
lpromero
2017/05/02 15:04:52
I didn't know about this feature, that's a nice on
vabr (Chromium)
2017/05/02 15:29:09
I had a lot of educational time in front of the AP
| |
101 } | |
102 | |
103 // Matcher for the Copy password button in Password Details view. This is the | |
104 // button below the Password section header. | |
72 id<GREYMatcher> CopyPasswordButton() { | 105 id<GREYMatcher> CopyPasswordButton() { |
73 return ButtonWithAccessibilityLabelId(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON); | 106 GREYLayoutConstraint* below = [GREYLayoutConstraint |
107 layoutConstraintWithAttribute:kGREYLayoutAttributeTop | |
108 relatedBy:kGREYLayoutRelationGreaterThanOrEqual | |
109 toReferenceAttribute:kGREYLayoutAttributeBottom | |
110 multiplier:1.0 | |
111 constant:0.0]; | |
112 return grey_allOf( | |
113 ButtonWithAccessibilityLabelId(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON), | |
114 grey_layout(@[ below ], PasswordHeader()), nullptr); | |
74 } | 115 } |
75 | 116 |
76 } // namespace | 117 } // namespace |
77 | 118 |
78 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> | 119 @interface MockReauthenticationModule : NSObject<ReauthenticationProtocol> |
79 | 120 |
80 @property(nonatomic, assign) BOOL shouldSucceed; | 121 @property(nonatomic, assign) BOOL shouldSucceed; |
81 | 122 |
82 @end | 123 @end |
83 | 124 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE); | 336 l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE); |
296 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] | 337 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] |
297 assertWithMatcher:grey_notNil()]; | 338 assertWithMatcher:grey_notNil()]; |
298 | 339 |
299 [self tapBackArrow]; | 340 [self tapBackArrow]; |
300 [self tapBackArrow]; | 341 [self tapBackArrow]; |
301 [self tapDone]; | 342 [self tapDone]; |
302 [self clearPasswordStore]; | 343 [self clearPasswordStore]; |
303 } | 344 } |
304 | 345 |
346 // Checks that attempts to copy a username provide appropriate feedback. | |
347 - (void)testCopyUsernameToast { | |
348 [self scopedEnablePasswordManagementAndViewingUI]; | |
349 | |
350 // Saving a form is needed for using the "password details" view. | |
351 [self saveExamplePasswordForm]; | |
352 | |
353 [self openPasswordSettings]; | |
354 | |
355 [[EarlGrey selectElementWithMatcher:Entry(@"https://example.com, user")] | |
356 performAction:grey_tap()]; | |
357 | |
358 // Check the snackbar. | |
359 [[EarlGrey selectElementWithMatcher:CopyUsernameButton()] | |
360 performAction:grey_tap()]; | |
361 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | |
362 NSString* snackbarLabel = | |
363 l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE); | |
364 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(snackbarLabel)] | |
365 assertWithMatcher:grey_notNil()]; | |
366 | |
367 [self tapBackArrow]; | |
368 [self tapBackArrow]; | |
369 [self tapDone]; | |
370 [self clearPasswordStore]; | |
371 } | |
372 | |
305 @end | 373 @end |
OLD | NEW |