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 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
6 | 6 |
7 #import "ios/chrome/browser/payments/payment_request_selector_view_controller.h" | 7 #import "ios/chrome/browser/payments/payment_request_selector_view_controller.h" |
8 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 8 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
9 #import "ios/showcase/test/showcase_eg_utils.h" | 9 #import "ios/showcase/test/showcase_eg_utils.h" |
10 #import "ios/showcase/test/showcase_test_case.h" | 10 #import "ios/showcase/test/showcase_test_case.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 return matcher; | 37 return matcher; |
38 } | 38 } |
39 | 39 |
40 // Returns the GREYMatcher for the "Add" button. | 40 // Returns the GREYMatcher for the "Add" button. |
41 id<GREYMatcher> AddButton() { | 41 id<GREYMatcher> AddButton() { |
42 return grey_allOf(ButtonWithAccessibilityLabel(@"Add an item"), | 42 return grey_allOf(ButtonWithAccessibilityLabel(@"Add an item"), |
43 grey_sufficientlyVisible(), nil); | 43 grey_sufficientlyVisible(), nil); |
44 } | 44 } |
45 | 45 |
| 46 // Returns the GREYMatcher for the UIAlertView's message displayed for a call |
| 47 // that notifies the delegate of a selection. |
| 48 id<GREYMatcher> UIAlertViewMessageForDelegateCallForSelectionWithArgument( |
| 49 NSString* argument) { |
| 50 return grey_allOf( |
| 51 grey_text( |
| 52 [NSString stringWithFormat: |
| 53 @"paymentRequestSelectorViewController:" |
| 54 @"kPaymentRequestSelectorCollectionViewAccessibilityID " |
| 55 @"didSelectItemAtIndex:%@", |
| 56 argument]), |
| 57 grey_sufficientlyVisible(), nil); |
| 58 } |
| 59 |
| 60 // Returns the GREYMatcher for the UIAlertView's message displayed for a call |
| 61 // that notifies the delegate of adding an item. |
| 62 id<GREYMatcher> UIAlertViewMessageForDelegateCallForAddingItem() { |
| 63 return grey_allOf( |
| 64 grey_text(@"paymentRequestSelectorViewControllerDidSelectAddItem:" |
| 65 @"kPaymentRequestSelectorCollectionViewAccessibilityID"), |
| 66 grey_sufficientlyVisible(), nil); |
| 67 } |
| 68 |
46 } // namespace | 69 } // namespace |
47 | 70 |
48 // Tests for the payment request selector view controller. | 71 // Tests for the payment request selector view controller. |
49 @interface SCPaymentsSelectorTestCase : ShowcaseTestCase | 72 @interface SCPaymentsSelectorTestCase : ShowcaseTestCase |
50 @end | 73 @end |
51 | 74 |
52 @implementation SCPaymentsSelectorTestCase | 75 @implementation SCPaymentsSelectorTestCase |
53 | 76 |
54 - (void)setUp { | 77 - (void)setUp { |
55 [super setUp]; | 78 [super setUp]; |
(...skipping 28 matching lines...) Expand all Loading... |
84 } | 107 } |
85 | 108 |
86 // Tests that selectable items can be selected. | 109 // Tests that selectable items can be selected. |
87 - (void)testCanSelectItems { | 110 - (void)testCanSelectItems { |
88 // Tap the first selectable item which is currently not selected. | 111 // Tap the first selectable item which is currently not selected. |
89 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( | 112 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( |
90 @"First selectable item", NO)] | 113 @"First selectable item", NO)] |
91 performAction:grey_tap()]; | 114 performAction:grey_tap()]; |
92 | 115 |
93 // Confirm the delegate is informed. | 116 // Confirm the delegate is informed. |
| 117 [[EarlGrey selectElementWithMatcher: |
| 118 UIAlertViewMessageForDelegateCallForSelectionWithArgument( |
| 119 @"0")] assertWithMatcher:grey_notNil()]; |
94 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( | 120 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
95 @"protocol_alerter_done")] | 121 @"protocol_alerter_done")] |
96 performAction:grey_tap()]; | 122 performAction:grey_tap()]; |
97 | 123 |
98 // Confirm the first selectable item is now selected. Tap it again. | 124 // Confirm the first selectable item is now selected. Tap it again. |
99 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( | 125 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( |
100 @"First selectable item", YES)] | 126 @"First selectable item", YES)] |
101 performAction:grey_tap()]; | 127 performAction:grey_tap()]; |
102 | 128 |
103 // Confirm the delegate is informed. | 129 // Confirm the delegate is informed. |
| 130 [[EarlGrey selectElementWithMatcher: |
| 131 UIAlertViewMessageForDelegateCallForSelectionWithArgument( |
| 132 @"0")] assertWithMatcher:grey_notNil()]; |
104 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( | 133 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
105 @"protocol_alerter_done")] | 134 @"protocol_alerter_done")] |
106 performAction:grey_tap()]; | 135 performAction:grey_tap()]; |
107 | 136 |
108 // Confirm the first selectable item is still selected. | 137 // Confirm the first selectable item is still selected. |
109 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( | 138 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( |
110 @"First selectable item", YES)] | 139 @"First selectable item", YES)] |
111 assertWithMatcher:grey_notNil()]; | 140 assertWithMatcher:grey_notNil()]; |
112 | 141 |
113 // Tap the second selectable item which is currently not selected. | 142 // Tap the second selectable item which is currently not selected. |
114 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( | 143 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( |
115 @"Second selectable item", NO)] | 144 @"Second selectable item", NO)] |
116 performAction:grey_tap()]; | 145 performAction:grey_tap()]; |
117 | 146 |
118 // Confirm the delegate is informed. | 147 // Confirm the delegate is informed. |
| 148 [[EarlGrey selectElementWithMatcher: |
| 149 UIAlertViewMessageForDelegateCallForSelectionWithArgument( |
| 150 @"1")] assertWithMatcher:grey_notNil()]; |
119 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( | 151 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
120 @"protocol_alerter_done")] | 152 @"protocol_alerter_done")] |
121 performAction:grey_tap()]; | 153 performAction:grey_tap()]; |
122 | 154 |
123 // Confirm the second selectable item is now selected. | 155 // Confirm the second selectable item is now selected. |
124 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( | 156 [[EarlGrey selectElementWithMatcher:SelectableItemWithLabel( |
125 @"Second selectable item", YES)] | 157 @"Second selectable item", YES)] |
126 assertWithMatcher:grey_notNil()]; | 158 assertWithMatcher:grey_notNil()]; |
127 } | 159 } |
128 | 160 |
129 // Tests that item can be added. | 161 // Tests that item can be added. |
130 - (void)testCanAddItem { | 162 - (void)testCanAddItem { |
131 // Tap the add button. | 163 // Tap the add button. |
132 [[EarlGrey selectElementWithMatcher:AddButton()] performAction:grey_tap()]; | 164 [[EarlGrey selectElementWithMatcher:AddButton()] performAction:grey_tap()]; |
133 | 165 |
134 // Confirm the delegate is informed. | 166 // Confirm the delegate is informed. |
| 167 [[EarlGrey |
| 168 selectElementWithMatcher:UIAlertViewMessageForDelegateCallForAddingItem()] |
| 169 assertWithMatcher:grey_notNil()]; |
135 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( | 170 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
136 @"protocol_alerter_done")] | 171 @"protocol_alerter_done")] |
137 performAction:grey_tap()]; | 172 performAction:grey_tap()]; |
138 } | 173 } |
139 | 174 |
140 @end | 175 @end |
OLD | NEW |