Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: ios/chrome/browser/ui/stack_view/stack_view_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <XCTest/XCTest.h> 5 #import <XCTest/XCTest.h>
6 6
7 #include "base/ios/block_types.h" 7 #include "base/ios/block_types.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #import "base/test/ios/wait_util.h" 10 #import "base/test/ios/wait_util.h"
(...skipping 10 matching lines...) Expand all
21 #import "ios/chrome/test/app/stack_view_test_util.h" 21 #import "ios/chrome/test/app/stack_view_test_util.h"
22 #import "ios/chrome/test/app/tab_test_util.h" 22 #import "ios/chrome/test/app/tab_test_util.h"
23 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 23 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
24 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 24 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
25 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 25 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
26 #include "ios/testing/earl_grey/disabled_test_macros.h" 26 #include "ios/testing/earl_grey/disabled_test_macros.h"
27 27
28 namespace { 28 namespace {
29 // Returns a GREYMatcher that matches |view|. 29 // Returns a GREYMatcher that matches |view|.
30 // TODO(crbug.com/642619): Evaluate whether this should be shared code. 30 // TODO(crbug.com/642619): Evaluate whether this should be shared code.
31 id<GREYMatcher> viewMatchingView(UIView* view) { 31 id<GREYMatcher> ViewMatchingView(UIView* view) {
32 MatchesBlock matches = ^BOOL(UIView* viewToMatch) { 32 MatchesBlock matches = ^BOOL(UIView* viewToMatch) {
33 return viewToMatch == view; 33 return viewToMatch == view;
34 }; 34 };
35 DescribeToBlock describe = ^void(id<GREYDescription> description) { 35 DescribeToBlock describe = ^void(id<GREYDescription> description) {
36 NSString* matcherDescription = 36 NSString* matcherDescription =
37 [NSString stringWithFormat:@"View matching %@", view]; 37 [NSString stringWithFormat:@"View matching %@", view];
38 [description appendText:matcherDescription]; 38 [description appendText:matcherDescription];
39 }; 39 };
40 return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 40 return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
41 descriptionBlock:describe]; 41 descriptionBlock:describe];
42 } 42 }
43 43
44 // Returns a matcher for the StackViewController's view. 44 // Returns a matcher for the StackViewController's view.
45 id<GREYMatcher> stackView() { 45 id<GREYMatcher> StackView() {
46 return viewMatchingView([chrome_test_util::GetStackViewController() view]); 46 return ViewMatchingView([chrome_test_util::GetStackViewController() view]);
47 } 47 }
48 48
49 // Waits for the Stack View to be visible/hidden. 49 // Waits for the Stack View to be visible/hidden.
50 void CheckForStackViewVisibility(bool visible) { 50 void CheckForStackViewVisibility(bool visible) {
51 id<GREYMatcher> visibilityMatcher = 51 id<GREYMatcher> visibilityMatcher =
52 grey_allOf(visible ? grey_sufficientlyVisible() : grey_notVisible(), 52 grey_allOf(visible ? grey_sufficientlyVisible() : grey_notVisible(),
53 visible ? grey_notNil() : grey_nil(), nil); 53 visible ? grey_notNil() : grey_nil(), nil);
54 [[EarlGrey selectElementWithMatcher:stackView()] 54 [[EarlGrey selectElementWithMatcher:StackView()]
55 assertWithMatcher:visibilityMatcher]; 55 assertWithMatcher:visibilityMatcher];
56 } 56 }
57 57
58 // Opens the StackViewController. 58 // Opens the StackViewController.
59 void OpenStackView() { 59 void OpenStackView() {
60 if (chrome_test_util::IsTabSwitcherActive()) 60 if (chrome_test_util::IsTabSwitcherActive())
61 return; 61 return;
62 // Tap on the toolbar's tab switcher button. 62 // Tap on the toolbar's tab switcher button.
63 id<GREYMatcher> stackButtonMatcher = 63 id<GREYMatcher> stackButtonMatcher =
64 grey_allOf(grey_accessibilityID(kToolbarStackButtonIdentifier), 64 grey_allOf(grey_accessibilityID(kToolbarStackButtonIdentifier),
(...skipping 17 matching lines...) Expand all
82 [activeDisplayView convertRect:[stackViewController inactiveDeckRegion] 82 [activeDisplayView convertRect:[stackViewController inactiveDeckRegion]
83 fromView:stackViewController.scrollView]; 83 fromView:stackViewController.scrollView];
84 bool showIncognito = type == DeckType::INCOGNITO; 84 bool showIncognito = type == DeckType::INCOGNITO;
85 if (showIncognito) { 85 if (showIncognito) {
86 GREYAssert(!CGRectIsEmpty(inactiveDeckRegion), 86 GREYAssert(!CGRectIsEmpty(inactiveDeckRegion),
87 @"Cannot show Incognito deck if no Incognito tabs are open"); 87 @"Cannot show Incognito deck if no Incognito tabs are open");
88 } 88 }
89 if (showIncognito != [stackViewController isCurrentSetIncognito]) { 89 if (showIncognito != [stackViewController isCurrentSetIncognito]) {
90 CGPoint tapPoint = CGPointMake(CGRectGetMidX(inactiveDeckRegion), 90 CGPoint tapPoint = CGPointMake(CGRectGetMidX(inactiveDeckRegion),
91 CGRectGetMidY(inactiveDeckRegion)); 91 CGRectGetMidY(inactiveDeckRegion));
92 [[EarlGrey selectElementWithMatcher:viewMatchingView(activeDisplayView)] 92 [[EarlGrey selectElementWithMatcher:ViewMatchingView(activeDisplayView)]
93 performAction:grey_tapAtPoint(tapPoint)]; 93 performAction:grey_tapAtPoint(tapPoint)];
94 } 94 }
95 } 95 }
96 96
97 // Opens a new tab using the stack view button. 97 // Opens a new tab using the stack view button.
98 void OpenNewTabUsingStackView() { 98 void OpenNewTabUsingStackView() {
99 // Open the stack view, tap the New Tab button, and wait for the animation to 99 // Open the stack view, tap the New Tab button, and wait for the animation to
100 // finish. 100 // finish.
101 ShowDeckWithType(DeckType::NORMAL); 101 ShowDeckWithType(DeckType::NORMAL);
102 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"New Tab")] 102 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"New Tab")]
103 performAction:grey_tap()]; 103 performAction:grey_tap()];
104 CheckForStackViewVisibility(false); 104 CheckForStackViewVisibility(false);
105 } 105 }
106 106
107 // Opens the tools menu from the stack view. 107 // Opens the tools menu from the stack view.
108 void OpenToolsMenu() { 108 void OpenToolsMenu() {
109 OpenStackView(); 109 OpenStackView();
110 [[EarlGrey selectElementWithMatcher:chrome_test_util::toolsMenuButton()] 110 [[EarlGrey selectElementWithMatcher:chrome_test_util::ToolsMenuButton()]
111 performAction:grey_tap()]; 111 performAction:grey_tap()];
112 } 112 }
113 113
114 // Opens a new Incognito Tab using the stack view button. 114 // Opens a new Incognito Tab using the stack view button.
115 void OpenNewIncognitoTabUsingStackView() { 115 void OpenNewIncognitoTabUsingStackView() {
116 OpenToolsMenu(); 116 OpenToolsMenu();
117 NSString* newIncognitoTabID = kToolsMenuNewIncognitoTabId; 117 NSString* newIncognitoTabID = kToolsMenuNewIncognitoTabId;
118 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(newIncognitoTabID)] 118 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(newIncognitoTabID)]
119 performAction:grey_tap()]; 119 performAction:grey_tap()];
120 CheckForStackViewVisibility(false); 120 CheckForStackViewVisibility(false);
121 } 121 }
122 122
123 // Taps the CardView associated with |tab|. 123 // Taps the CardView associated with |tab|.
124 void SelectTabUsingStackView(Tab* tab) { 124 void SelectTabUsingStackView(Tab* tab) {
125 DCHECK(tab); 125 DCHECK(tab);
126 // Present the StackViewController. 126 // Present the StackViewController.
127 OpenStackView(); 127 OpenStackView();
128 // Get the StackCard associated with |tab|. 128 // Get the StackCard associated with |tab|.
129 StackViewController* stackViewController = 129 StackViewController* stackViewController =
130 chrome_test_util::GetStackViewController(); 130 chrome_test_util::GetStackViewController();
131 StackCard* nextCard = [[stackViewController activeCardSet] cardForTab:tab]; 131 StackCard* nextCard = [[stackViewController activeCardSet] cardForTab:tab];
132 UIView* card_title_label = static_cast<UIView*>([[nextCard view] titleLabel]); 132 UIView* card_title_label = static_cast<UIView*>([[nextCard view] titleLabel]);
133 [[EarlGrey selectElementWithMatcher:viewMatchingView(card_title_label)] 133 [[EarlGrey selectElementWithMatcher:ViewMatchingView(card_title_label)]
134 performAction:grey_tap()]; 134 performAction:grey_tap()];
135 // Wait for the StackViewController to be dismissed. 135 // Wait for the StackViewController to be dismissed.
136 CheckForStackViewVisibility(false); 136 CheckForStackViewVisibility(false);
137 // Checks that the next Tab has been selected. 137 // Checks that the next Tab has been selected.
138 GREYAssertEqual(tab, chrome_test_util::GetCurrentTab(), 138 GREYAssertEqual(tab, chrome_test_util::GetCurrentTab(),
139 @"The next Tab was not selected"); 139 @"The next Tab was not selected");
140 } 140 }
141 } 141 }
142 142
143 // Tests for interacting with the StackViewController. 143 // Tests for interacting with the StackViewController.
(...skipping 25 matching lines...) Expand all
169 OpenStackView(); 169 OpenStackView();
170 StackViewController* stackViewController = 170 StackViewController* stackViewController =
171 chrome_test_util::GetStackViewController(); 171 chrome_test_util::GetStackViewController();
172 Tab* currentTab = chrome_test_util::GetCurrentTab(); 172 Tab* currentTab = chrome_test_util::GetCurrentTab();
173 StackCard* card = [[stackViewController activeCardSet] cardForTab:currentTab]; 173 StackCard* card = [[stackViewController activeCardSet] cardForTab:currentTab];
174 CardView* cardView = card.view; 174 CardView* cardView = card.view;
175 NSString* identifier = card.view.closeButtonId; 175 NSString* identifier = card.view.closeButtonId;
176 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(identifier)] 176 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(identifier)]
177 performAction:grey_tap()]; 177 performAction:grey_tap()];
178 // Verify that the CardView and its associated Tab were removed. 178 // Verify that the CardView and its associated Tab were removed.
179 [[EarlGrey selectElementWithMatcher:viewMatchingView(cardView)] 179 [[EarlGrey selectElementWithMatcher:ViewMatchingView(cardView)]
180 assertWithMatcher:grey_notVisible()]; 180 assertWithMatcher:grey_notVisible()];
181 GREYAssertEqual(chrome_test_util::GetMainTabCount(), 0, 181 GREYAssertEqual(chrome_test_util::GetMainTabCount(), 0,
182 @"All Tabs should be closed."); 182 @"All Tabs should be closed.");
183 } 183 }
184 184
185 // Tests closing all Tabs in the stack view. 185 // Tests closing all Tabs in the stack view.
186 - (void)testCloseAllTabs { 186 - (void)testCloseAllTabs {
187 // The StackViewController is only used on iPhones. 187 // The StackViewController is only used on iPhones.
188 if (IsIPadIdiom()) 188 if (IsIPadIdiom())
189 EARL_GREY_TEST_SKIPPED(@"Stack view is not used on iPads."); 189 EARL_GREY_TEST_SKIPPED(@"Stack view is not used on iPads.");
(...skipping 20 matching lines...) Expand all
210 if (card.viewIsLive) 210 if (card.viewIsLive)
211 [cardViews addObject:card.view]; 211 [cardViews addObject:card.view];
212 } 212 }
213 // Open the tools menu and select "Close all tabs". 213 // Open the tools menu and select "Close all tabs".
214 OpenToolsMenu(); 214 OpenToolsMenu();
215 NSString* closeAllTabsID = kToolsMenuCloseAllTabsId; 215 NSString* closeAllTabsID = kToolsMenuCloseAllTabsId;
216 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(closeAllTabsID)] 216 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(closeAllTabsID)]
217 performAction:grey_tap()]; 217 performAction:grey_tap()];
218 // Wait for CardViews to be dismissed. 218 // Wait for CardViews to be dismissed.
219 for (CardView* cardView in cardViews) { 219 for (CardView* cardView in cardViews) {
220 [[EarlGrey selectElementWithMatcher:viewMatchingView(cardView)] 220 [[EarlGrey selectElementWithMatcher:ViewMatchingView(cardView)]
221 assertWithMatcher:grey_notVisible()]; 221 assertWithMatcher:grey_notVisible()];
222 } 222 }
223 // Check that all Tabs were closed. 223 // Check that all Tabs were closed.
224 GREYAssertEqual(chrome_test_util::GetMainTabCount(), 0, 224 GREYAssertEqual(chrome_test_util::GetMainTabCount(), 0,
225 @"Tabs were not closed."); 225 @"Tabs were not closed.");
226 GREYAssertEqual(chrome_test_util::GetIncognitoTabCount(), 0, 226 GREYAssertEqual(chrome_test_util::GetIncognitoTabCount(), 0,
227 @"Incognito Tab was not closed."); 227 @"Incognito Tab was not closed.");
228 } 228 }
229 229
230 // Tests that tapping on the inactive deck region switches modes. 230 // Tests that tapping on the inactive deck region switches modes.
231 - (void)testSwitchingModes { 231 - (void)testSwitchingModes {
232 // The StackViewController is only used on iPhones. 232 // The StackViewController is only used on iPhones.
233 if (IsIPadIdiom()) 233 if (IsIPadIdiom())
234 EARL_GREY_TEST_SKIPPED(@"Stack view is not used on iPads."); 234 EARL_GREY_TEST_SKIPPED(@"Stack view is not used on iPads.");
235 // Open an Incognito Tab then switch decks. 235 // Open an Incognito Tab then switch decks.
236 OpenNewIncognitoTabUsingStackView(); 236 OpenNewIncognitoTabUsingStackView();
237 ShowDeckWithType(DeckType::INCOGNITO); 237 ShowDeckWithType(DeckType::INCOGNITO);
238 // Verify that the current CardSet is the incognito set. 238 // Verify that the current CardSet is the incognito set.
239 StackViewController* stackViewController = 239 StackViewController* stackViewController =
240 chrome_test_util::GetStackViewController(); 240 chrome_test_util::GetStackViewController();
241 GREYAssert([stackViewController isCurrentSetIncognito], 241 GREYAssert([stackViewController isCurrentSetIncognito],
242 @"Incognito deck not selected."); 242 @"Incognito deck not selected.");
243 // Switch back to the main CardSet and verify that is selected. 243 // Switch back to the main CardSet and verify that is selected.
244 ShowDeckWithType(DeckType::NORMAL); 244 ShowDeckWithType(DeckType::NORMAL);
245 GREYAssert(![stackViewController isCurrentSetIncognito], 245 GREYAssert(![stackViewController isCurrentSetIncognito],
246 @"Normal deck not selected."); 246 @"Normal deck not selected.");
247 } 247 }
248 248
249 @end 249 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/settings/translate_ui_egtest.mm ('k') | ios/chrome/browser/ui/sync/sync_fake_server_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698