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

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_controller_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 10 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 <EarlGrey/EarlGrey.h> 5 #import <EarlGrey/EarlGrey.h>
6 #import <UIKit/UIKit.h> 6 #import <UIKit/UIKit.h>
7 #import <XCTest/XCTest.h> 7 #import <XCTest/XCTest.h>
8 8
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/test/scoped_command_line.h" 10 #include "base/test/scoped_command_line.h"
11 #import "ios/chrome/app/main_controller_private.h" 11 #import "ios/chrome/app/main_controller_private.h"
12 #include "ios/chrome/browser/chrome_switches.h" 12 #include "ios/chrome/browser/chrome_switches.h"
13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
15 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" 15 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
16 #import "ios/chrome/browser/ui/ui_util.h" 16 #import "ios/chrome/browser/ui/ui_util.h"
17 #include "ios/chrome/grit/ios_strings.h" 17 #include "ios/chrome/grit/ios_strings.h"
18 #import "ios/chrome/test/app/chrome_test_util.h" 18 #import "ios/chrome/test/app/chrome_test_util.h"
19 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" 19 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
20 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 20 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
21 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 21 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 23
24 using chrome_test_util::buttonWithAccessibilityLabel; 24 using chrome_test_util::ButtonWithAccessibilityLabel;
25 using chrome_test_util::buttonWithAccessibilityLabelId; 25 using chrome_test_util::ButtonWithAccessibilityLabelId;
26 using chrome_test_util::staticTextWithAccessibilityLabelId; 26 using chrome_test_util::StaticTextWithAccessibilityLabelId;
27 27
28 namespace { 28 namespace {
29 29
30 // Returns the GREYMatcher for the button that closes the tab switcher. 30 // Returns the GREYMatcher for the button that closes the tab switcher.
31 id<GREYMatcher> tabSwitcherCloseButton() { 31 id<GREYMatcher> TabSwitcherCloseButton() {
32 return buttonWithAccessibilityLabelId(IDS_IOS_TAB_STRIP_LEAVE_TAB_SWITCHER); 32 return ButtonWithAccessibilityLabelId(IDS_IOS_TAB_STRIP_LEAVE_TAB_SWITCHER);
33 } 33 }
34 34
35 // Returns the GREYMatcher for the button that creates new non incognito tabs 35 // Returns the GREYMatcher for the button that creates new non incognito tabs
36 // from within the tab switcher. 36 // from within the tab switcher.
37 id<GREYMatcher> tabSwitcherNewTabButton() { 37 id<GREYMatcher> TabSwitcherNewTabButton() {
38 return grey_allOf( 38 return grey_allOf(
39 buttonWithAccessibilityLabelId(IDS_IOS_TAB_SWITCHER_CREATE_NEW_TAB), 39 ButtonWithAccessibilityLabelId(IDS_IOS_TAB_SWITCHER_CREATE_NEW_TAB),
40 grey_sufficientlyVisible(), nil); 40 grey_sufficientlyVisible(), nil);
41 } 41 }
42 42
43 // Returns the GREYMatcher for the button that creates new incognito tabs from 43 // Returns the GREYMatcher for the button that creates new incognito tabs from
44 // within the tab switcher. 44 // within the tab switcher.
45 id<GREYMatcher> tabSwitcherNewIncognitoTabButton() { 45 id<GREYMatcher> TabSwitcherNewIncognitoTabButton() {
46 return grey_allOf(buttonWithAccessibilityLabelId( 46 return grey_allOf(ButtonWithAccessibilityLabelId(
47 IDS_IOS_TAB_SWITCHER_CREATE_NEW_INCOGNITO_TAB), 47 IDS_IOS_TAB_SWITCHER_CREATE_NEW_INCOGNITO_TAB),
48 grey_sufficientlyVisible(), nil); 48 grey_sufficientlyVisible(), nil);
49 } 49 }
50 50
51 // Returns the GREYMatcher for the button to go to the non incognito panel in 51 // Returns the GREYMatcher for the button to go to the non incognito panel in
52 // the tab switcher. 52 // the tab switcher.
53 id<GREYMatcher> tabSwitcherHeaderPanelButton() { 53 id<GREYMatcher> TabSwitcherHeaderPanelButton() {
54 NSString* accessibility_label = l10n_util::GetNSStringWithFixup( 54 NSString* accessibility_label = l10n_util::GetNSStringWithFixup(
55 IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS); 55 IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS);
56 return grey_accessibilityLabel(accessibility_label); 56 return grey_accessibilityLabel(accessibility_label);
57 } 57 }
58 58
59 // Returns the GREYMatcher for the button that closes tabs on iPad. 59 // Returns the GREYMatcher for the button that closes tabs on iPad.
60 id<GREYMatcher> closeTabButton() { 60 id<GREYMatcher> CloseTabButton() {
61 return buttonWithAccessibilityLabelId(IDS_IOS_TOOLS_MENU_CLOSE_TAB); 61 return ButtonWithAccessibilityLabelId(IDS_IOS_TOOLS_MENU_CLOSE_TAB);
62 } 62 }
63 63
64 // Opens a new incognito tabs using the tools menu. 64 // Opens a new incognito tabs using the tools menu.
65 void openNewIncognitoTabUsingUI() { 65 void OpenNewIncognitoTabUsingUI() {
66 [ChromeEarlGreyUI openToolsMenu]; 66 [ChromeEarlGreyUI openToolsMenu];
67 id<GREYMatcher> newIncognitoTabButtonMatcher = 67 id<GREYMatcher> newIncognitoTabButtonMatcher =
68 grey_accessibilityID(kToolsMenuNewIncognitoTabId); 68 grey_accessibilityID(kToolsMenuNewIncognitoTabId);
69 [[EarlGrey selectElementWithMatcher:newIncognitoTabButtonMatcher] 69 [[EarlGrey selectElementWithMatcher:newIncognitoTabButtonMatcher]
70 performAction:grey_tap()]; 70 performAction:grey_tap()];
71 } 71 }
72 72
73 // Triggers the opening of the tab switcher by launching a command. Should be 73 // Triggers the opening of the tab switcher by launching a command. Should be
74 // called only when the tab switcher is not presented. 74 // called only when the tab switcher is not presented.
75 void enterTabSwitcherWithCommand() { 75 void EnterTabSwitcherWithCommand() {
76 base::scoped_nsobject<GenericChromeCommand> command( 76 base::scoped_nsobject<GenericChromeCommand> command(
77 [[GenericChromeCommand alloc] initWithTag:IDC_TOGGLE_TAB_SWITCHER]); 77 [[GenericChromeCommand alloc] initWithTag:IDC_TOGGLE_TAB_SWITCHER]);
78 chrome_test_util::RunCommandWithActiveViewController(command); 78 chrome_test_util::RunCommandWithActiveViewController(command);
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 @interface TabSwitcherControllerTestCase : ChromeTestCase 83 @interface TabSwitcherControllerTestCase : ChromeTestCase
84 @end 84 @end
85 85
(...skipping 20 matching lines...) Expand all
106 - (void)assertTabSwitcherIsActive { 106 - (void)assertTabSwitcherIsActive {
107 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 107 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
108 MainController* main_controller = chrome_test_util::GetMainController(); 108 MainController* main_controller = chrome_test_util::GetMainController();
109 GREYAssertTrue([main_controller isTabSwitcherActive], 109 GREYAssertTrue([main_controller isTabSwitcherActive],
110 @"Tab Switcher should be active"); 110 @"Tab Switcher should be active");
111 } 111 }
112 112
113 // Checks that the text associated with |messageId| is somewhere on screen. 113 // Checks that the text associated with |messageId| is somewhere on screen.
114 - (void)assertMessageIsVisible:(int)messageId { 114 - (void)assertMessageIsVisible:(int)messageId {
115 id<GREYMatcher> messageMatcher = 115 id<GREYMatcher> messageMatcher =
116 grey_allOf(staticTextWithAccessibilityLabelId(messageId), 116 grey_allOf(StaticTextWithAccessibilityLabelId(messageId),
117 grey_sufficientlyVisible(), nil); 117 grey_sufficientlyVisible(), nil);
118 [[EarlGrey selectElementWithMatcher:messageMatcher] 118 [[EarlGrey selectElementWithMatcher:messageMatcher]
119 assertWithMatcher:grey_notNil()]; 119 assertWithMatcher:grey_notNil()];
120 } 120 }
121 121
122 // Checks that the text associated with |messageId| is not visible. 122 // Checks that the text associated with |messageId| is not visible.
123 - (void)assertMessageIsNotVisible:(int)messageId { 123 - (void)assertMessageIsNotVisible:(int)messageId {
124 id<GREYMatcher> messageMatcher = 124 id<GREYMatcher> messageMatcher =
125 grey_allOf(staticTextWithAccessibilityLabelId(messageId), 125 grey_allOf(StaticTextWithAccessibilityLabelId(messageId),
126 grey_sufficientlyVisible(), nil); 126 grey_sufficientlyVisible(), nil);
127 [[EarlGrey selectElementWithMatcher:messageMatcher] 127 [[EarlGrey selectElementWithMatcher:messageMatcher]
128 assertWithMatcher:grey_nil()]; 128 assertWithMatcher:grey_nil()];
129 } 129 }
130 130
131 // Tests entering and leaving the tab switcher. 131 // Tests entering and leaving the tab switcher.
132 - (void)testEnteringTabSwitcher { 132 - (void)testEnteringTabSwitcher {
133 if (!IsIPadIdiom()) 133 if (!IsIPadIdiom())
134 return; 134 return;
135 135
136 [self assertTabSwitcherIsInactive]; 136 [self assertTabSwitcherIsInactive];
137 137
138 enterTabSwitcherWithCommand(); 138 EnterTabSwitcherWithCommand();
139 [self assertTabSwitcherIsActive]; 139 [self assertTabSwitcherIsActive];
140 140
141 // Check that the "No Open Tabs" message is not displayed. 141 // Check that the "No Open Tabs" message is not displayed.
142 [self assertMessageIsNotVisible: 142 [self assertMessageIsNotVisible:
143 IDS_IOS_TAB_SWITCHER_NO_LOCAL_NON_INCOGNITO_TABS_TITLE]; 143 IDS_IOS_TAB_SWITCHER_NO_LOCAL_NON_INCOGNITO_TABS_TITLE];
144 144
145 // Press the :: icon to exit the tab switcher. 145 // Press the :: icon to exit the tab switcher.
146 [[EarlGrey selectElementWithMatcher:tabSwitcherCloseButton()] 146 [[EarlGrey selectElementWithMatcher:TabSwitcherCloseButton()]
147 performAction:grey_tap()]; 147 performAction:grey_tap()];
148 148
149 [self assertTabSwitcherIsInactive]; 149 [self assertTabSwitcherIsInactive];
150 } 150 }
151 151
152 // Tests entering tab switcher by closing all tabs, and leaving the tab switcher 152 // Tests entering tab switcher by closing all tabs, and leaving the tab switcher
153 // by creating a new tab. 153 // by creating a new tab.
154 - (void)testClosingAllTabsAndCreatingNewTab { 154 - (void)testClosingAllTabsAndCreatingNewTab {
155 if (!IsIPadIdiom()) 155 if (!IsIPadIdiom())
156 return; 156 return;
157 157
158 [self assertTabSwitcherIsInactive]; 158 [self assertTabSwitcherIsInactive];
159 159
160 // Close the tab. 160 // Close the tab.
161 [[EarlGrey selectElementWithMatcher:closeTabButton()] 161 [[EarlGrey selectElementWithMatcher:CloseTabButton()]
162 performAction:grey_tap()]; 162 performAction:grey_tap()];
163 163
164 [self assertTabSwitcherIsActive]; 164 [self assertTabSwitcherIsActive];
165 165
166 // Check that the "No Open Tabs" message is displayed. 166 // Check that the "No Open Tabs" message is displayed.
167 [self assertMessageIsVisible: 167 [self assertMessageIsVisible:
168 IDS_IOS_TAB_SWITCHER_NO_LOCAL_NON_INCOGNITO_TABS_TITLE]; 168 IDS_IOS_TAB_SWITCHER_NO_LOCAL_NON_INCOGNITO_TABS_TITLE];
169 169
170 // Create a new tab. 170 // Create a new tab.
171 [[EarlGrey selectElementWithMatcher:tabSwitcherNewTabButton()] 171 [[EarlGrey selectElementWithMatcher:TabSwitcherNewTabButton()]
172 performAction:grey_tap()]; 172 performAction:grey_tap()];
173 173
174 [self assertTabSwitcherIsInactive]; 174 [self assertTabSwitcherIsInactive];
175 } 175 }
176 176
177 // Tests entering tab switcher from incognito mode. 177 // Tests entering tab switcher from incognito mode.
178 - (void)testIncognitoTabs { 178 - (void)testIncognitoTabs {
179 if (!IsIPadIdiom()) 179 if (!IsIPadIdiom())
180 return; 180 return;
181 181
182 [self assertTabSwitcherIsInactive]; 182 [self assertTabSwitcherIsInactive];
183 183
184 // Create new incognito tab from tools menu. 184 // Create new incognito tab from tools menu.
185 openNewIncognitoTabUsingUI(); 185 OpenNewIncognitoTabUsingUI();
186 186
187 // Close the incognito tab and check that the we are entering the tab 187 // Close the incognito tab and check that the we are entering the tab
188 // switcher. 188 // switcher.
189 [[EarlGrey selectElementWithMatcher:closeTabButton()] 189 [[EarlGrey selectElementWithMatcher:CloseTabButton()]
190 performAction:grey_tap()]; 190 performAction:grey_tap()];
191 [self assertTabSwitcherIsActive]; 191 [self assertTabSwitcherIsActive];
192 192
193 // Check that the "No Incognito Tabs" message is shown. 193 // Check that the "No Incognito Tabs" message is shown.
194 [self assertMessageIsVisible: 194 [self assertMessageIsVisible:
195 IDS_IOS_TAB_SWITCHER_NO_LOCAL_INCOGNITO_TABS_PROMO]; 195 IDS_IOS_TAB_SWITCHER_NO_LOCAL_INCOGNITO_TABS_PROMO];
196 196
197 // Create new incognito tab. 197 // Create new incognito tab.
198 [[EarlGrey selectElementWithMatcher:tabSwitcherNewIncognitoTabButton()] 198 [[EarlGrey selectElementWithMatcher:TabSwitcherNewIncognitoTabButton()]
199 performAction:grey_tap()]; 199 performAction:grey_tap()];
200 200
201 // Verify that we've left the tab switcher. 201 // Verify that we've left the tab switcher.
202 [self assertTabSwitcherIsInactive]; 202 [self assertTabSwitcherIsInactive];
203 203
204 // Close tab and verify we've entered the tab switcher again. 204 // Close tab and verify we've entered the tab switcher again.
205 [[EarlGrey selectElementWithMatcher:closeTabButton()] 205 [[EarlGrey selectElementWithMatcher:CloseTabButton()]
206 performAction:grey_tap()]; 206 performAction:grey_tap()];
207 [self assertTabSwitcherIsActive]; 207 [self assertTabSwitcherIsActive];
208 208
209 // Switch to the non incognito panel. 209 // Switch to the non incognito panel.
210 [[EarlGrey selectElementWithMatcher:tabSwitcherHeaderPanelButton()] 210 [[EarlGrey selectElementWithMatcher:TabSwitcherHeaderPanelButton()]
211 performAction:grey_tap()]; 211 performAction:grey_tap()];
212 212
213 // Press the :: icon to exit the tab switcher. 213 // Press the :: icon to exit the tab switcher.
214 [[EarlGrey selectElementWithMatcher:tabSwitcherCloseButton()] 214 [[EarlGrey selectElementWithMatcher:TabSwitcherCloseButton()]
215 performAction:grey_tap()]; 215 performAction:grey_tap()];
216 216
217 // Verify that we've left the tab switcher. 217 // Verify that we've left the tab switcher.
218 [self assertTabSwitcherIsInactive]; 218 [self assertTabSwitcherIsInactive];
219 } 219 }
220 220
221 @end 221 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/sync/sync_fake_server_egtest.mm ('k') | ios/chrome/browser/ui/toolbar/toolbar_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698