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

Side by Side Diff: ios/chrome/browser/ui/history/history_ui_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 <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/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "components/browsing_data/core/pref_names.h" 10 #include "components/browsing_data/core/pref_names.h"
(...skipping 18 matching lines...) Expand all
29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 29 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
30 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" 30 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
31 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" 31 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
32 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" 32 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h"
33 #import "ios/testing/wait_util.h" 33 #import "ios/testing/wait_util.h"
34 #import "ios/web/public/test/http_server.h" 34 #import "ios/web/public/test/http_server.h"
35 #import "ios/web/public/test/http_server_util.h" 35 #import "ios/web/public/test/http_server_util.h"
36 #import "net/base/mac/url_conversions.h" 36 #import "net/base/mac/url_conversions.h"
37 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 38
39 using chrome_test_util::buttonWithAccessibilityLabelId; 39 using chrome_test_util::ButtonWithAccessibilityLabelId;
40 40
41 namespace { 41 namespace {
42 char kURL1[] = "http://firstURL"; 42 char kURL1[] = "http://firstURL";
43 char kURL2[] = "http://secondURL"; 43 char kURL2[] = "http://secondURL";
44 char kURL3[] = "http://thirdURL"; 44 char kURL3[] = "http://thirdURL";
45 char kResponse1[] = "Test Page 1"; 45 char kResponse1[] = "Test Page 1";
46 char kResponse2[] = "Test Page 2"; 46 char kResponse2[] = "Test Page 2";
47 char kResponse3[] = "Test Page 3"; 47 char kResponse3[] = "Test Page 3";
48 48
49 // Matcher for entry in history for URL. 49 // Matcher for entry in history for URL.
50 id<GREYMatcher> historyEntryWithURL(const GURL& url) { 50 id<GREYMatcher> HistoryEntryWithUrl(const GURL& url) {
51 NSString* url_spec = base::SysUTF8ToNSString(url.spec()); 51 NSString* url_spec = base::SysUTF8ToNSString(url.spec());
52 return grey_allOf(grey_text(url_spec), grey_sufficientlyVisible(), nil); 52 return grey_allOf(grey_text(url_spec), grey_sufficientlyVisible(), nil);
53 } 53 }
54 // Matcher for the history button in the tools menu. 54 // Matcher for the history button in the tools menu.
55 id<GREYMatcher> historyButton() { 55 id<GREYMatcher> HistoryButton() {
56 return buttonWithAccessibilityLabelId(IDS_HISTORY_SHOW_HISTORY); 56 return ButtonWithAccessibilityLabelId(IDS_HISTORY_SHOW_HISTORY);
57 } 57 }
58 // Matcher for the done button in the navigation bar. 58 // Matcher for the done button in the navigation bar.
59 id<GREYMatcher> navigationDoneButton() { 59 id<GREYMatcher> NavigationDoneButton() {
60 // Include sufficientlyVisible condition for the case of the clear browsing 60 // Include sufficientlyVisible condition for the case of the clear browsing
61 // dialog, which also has a "Done" button and is displayed over the history 61 // dialog, which also has a "Done" button and is displayed over the history
62 // panel. 62 // panel.
63 return grey_allOf( 63 return grey_allOf(
64 buttonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON), 64 ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON),
65 grey_sufficientlyVisible(), nil); 65 grey_sufficientlyVisible(), nil);
66 } 66 }
67 // Matcher for the edit button in the navigation bar. 67 // Matcher for the edit button in the navigation bar.
68 id<GREYMatcher> navigationEditButton() { 68 id<GREYMatcher> NavigationEditButton() {
69 return buttonWithAccessibilityLabelId(IDS_HISTORY_START_EDITING_BUTTON); 69 return ButtonWithAccessibilityLabelId(IDS_HISTORY_START_EDITING_BUTTON);
70 } 70 }
71 // Matcher for the delete button. 71 // Matcher for the delete button.
72 id<GREYMatcher> deleteHistoryEntriesButton() { 72 id<GREYMatcher> DeleteHistoryEntriesButton() {
73 // Include class restriction to exclude MDCCollectionViewInfoBar, which is 73 // Include class restriction to exclude MDCCollectionViewInfoBar, which is
74 // hidden. 74 // hidden.
75 return grey_allOf(buttonWithAccessibilityLabelId( 75 return grey_allOf(ButtonWithAccessibilityLabelId(
76 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON), 76 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON),
77 grey_kindOfClass([UIButton class]), nil); 77 grey_kindOfClass([UIButton class]), nil);
78 } 78 }
79 // Matcher for the search button. 79 // Matcher for the search button.
80 id<GREYMatcher> searchIconButton() { 80 id<GREYMatcher> SearchIconButton() {
81 return buttonWithAccessibilityLabelId(IDS_IOS_ICON_SEARCH); 81 return ButtonWithAccessibilityLabelId(IDS_IOS_ICON_SEARCH);
82 } 82 }
83 // Matcher for the cancel button. 83 // Matcher for the cancel button.
84 id<GREYMatcher> cancelButton() { 84 id<GREYMatcher> CancelButton() {
85 return buttonWithAccessibilityLabelId(IDS_HISTORY_CANCEL_EDITING_BUTTON); 85 return ButtonWithAccessibilityLabelId(IDS_HISTORY_CANCEL_EDITING_BUTTON);
86 } 86 }
87 // Matcher for the button to open the clear browsing data panel. 87 // Matcher for the button to open the clear browsing data panel.
88 id<GREYMatcher> openClearBrowsingDataButton() { 88 id<GREYMatcher> OpenClearBrowsingDataButton() {
89 return buttonWithAccessibilityLabelId( 89 return ButtonWithAccessibilityLabelId(
90 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG); 90 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG);
91 } 91 }
92 // Matcher for the Open in New Tab option in the context menu. 92 // Matcher for the Open in New Tab option in the context menu.
93 id<GREYMatcher> openInNewTabButton() { 93 id<GREYMatcher> OpenInNewTabButton() {
94 return buttonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); 94 return ButtonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB);
95 } 95 }
96 // Matcher for the Open in New Incognito Tab option in the context menu. 96 // Matcher for the Open in New Incognito Tab option in the context menu.
97 id<GREYMatcher> openInNewIncognitoTabButton() { 97 id<GREYMatcher> OpenInNewIncognitoTabButton() {
98 return buttonWithAccessibilityLabelId( 98 return ButtonWithAccessibilityLabelId(
99 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB); 99 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB);
100 } 100 }
101 // Matcher for the Copy URL option in the context menu. 101 // Matcher for the Copy URL option in the context menu.
102 id<GREYMatcher> copyUrlButton() { 102 id<GREYMatcher> CopyUrlButton() {
103 return buttonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_COPY); 103 return ButtonWithAccessibilityLabelId(IDS_IOS_CONTENT_CONTEXT_COPY);
104 } 104 }
105 // Matcher for the clear cookies cell on the clear browsing data panel. 105 // Matcher for the clear cookies cell on the clear browsing data panel.
106 id<GREYMatcher> clearCookiesButton() { 106 id<GREYMatcher> ClearCookiesButton() {
107 return grey_accessibilityID(kClearCookiesCellId); 107 return grey_accessibilityID(kClearCookiesCellId);
108 } 108 }
109 // Matcher for the clear cache cell on the clear browsing data panel. 109 // Matcher for the clear cache cell on the clear browsing data panel.
110 id<GREYMatcher> clearCacheButton() { 110 id<GREYMatcher> ClearCacheButton() {
111 return grey_allOf(grey_accessibilityID(kClearCacheCellId), 111 return grey_allOf(grey_accessibilityID(kClearCacheCellId),
112 grey_sufficientlyVisible(), nil); 112 grey_sufficientlyVisible(), nil);
113 } 113 }
114 // Matcher for the clear browsing data button on the clear browsing data panel. 114 // Matcher for the clear browsing data button on the clear browsing data panel.
115 id<GREYMatcher> clearBrowsingDataButton() { 115 id<GREYMatcher> ClearBrowsingDataButton() {
116 return buttonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); 116 return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON);
117 } 117 }
118 118
119 // Sign in with a mock identity. 119 // Sign in with a mock identity.
120 void MockSignIn() { 120 void MockSignIn() {
121 // Set up a mock identity. 121 // Set up a mock identity.
122 ChromeIdentity* identity = 122 ChromeIdentity* identity =
123 [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" 123 [FakeChromeIdentity identityWithEmail:@"foo@gmail.com"
124 gaiaID:@"fooID" 124 gaiaID:@"fooID"
125 name:@"Fake Foo"]; 125 name:@"Fake Foo"];
126 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( 126 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
127 identity); 127 identity);
128 128
129 [ChromeEarlGreyUI openToolsMenu]; 129 [ChromeEarlGreyUI openToolsMenu];
130 [[[EarlGrey 130 [[[EarlGrey
131 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] 131 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
132 usingSearchAction:grey_scrollToContentEdge(kGREYContentEdgeBottom) 132 usingSearchAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)
133 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] 133 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)]
134 performAction:grey_tap()]; 134 performAction:grey_tap()];
135 135
136 [[EarlGrey 136 [[EarlGrey
137 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] 137 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)]
138 performAction:grey_tap()]; 138 performAction:grey_tap()];
139 [[EarlGrey 139 [[EarlGrey
140 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabel( 140 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
141 identity.userEmail)] 141 identity.userEmail)]
142 performAction:grey_tap()]; 142 performAction:grey_tap()];
143 [[EarlGrey selectElementWithMatcher: 143 [[EarlGrey selectElementWithMatcher:
144 chrome_test_util::buttonWithAccessibilityLabelId( 144 chrome_test_util::ButtonWithAccessibilityLabelId(
145 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON)] 145 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON)]
146 performAction:grey_tap()]; 146 performAction:grey_tap()];
147 [[EarlGrey selectElementWithMatcher: 147 [[EarlGrey selectElementWithMatcher:
148 chrome_test_util::buttonWithAccessibilityLabelId( 148 chrome_test_util::ButtonWithAccessibilityLabelId(
149 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON)] 149 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON)]
150 performAction:grey_tap()]; 150 performAction:grey_tap()];
151 [[EarlGrey 151 [[EarlGrey
152 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( 152 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
153 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] 153 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
154 performAction:grey_tap()]; 154 performAction:grey_tap()];
155 } 155 }
156 } // namespace 156 } // namespace
157 157
158 // History UI tests. 158 // History UI tests.
159 @interface HistoryUITestCase : ChromeTestCase { 159 @interface HistoryUITestCase : ChromeTestCase {
160 GURL _URL1; 160 GURL _URL1;
161 GURL _URL2; 161 GURL _URL2;
162 GURL _URL3; 162 GURL _URL3;
(...skipping 30 matching lines...) Expand all
193 [ChromeEarlGrey clearBrowsingHistory]; 193 [ChromeEarlGrey clearBrowsingHistory];
194 // Some tests rely on a clean state for the "Clear Browsing Data" settings 194 // Some tests rely on a clean state for the "Clear Browsing Data" settings
195 // screen. 195 // screen.
196 [self resetBrowsingDataPrefs]; 196 [self resetBrowsingDataPrefs];
197 } 197 }
198 198
199 - (void)tearDown { 199 - (void)tearDown {
200 NSError* error = nil; 200 NSError* error = nil;
201 // Dismiss search bar by pressing cancel, if present. Passing error prevents 201 // Dismiss search bar by pressing cancel, if present. Passing error prevents
202 // failure if the element is not found. 202 // failure if the element is not found.
203 [[EarlGrey selectElementWithMatcher:cancelButton()] performAction:grey_tap() 203 [[EarlGrey selectElementWithMatcher:CancelButton()] performAction:grey_tap()
204 error:&error]; 204 error:&error];
205 // Dismiss history panel by pressing done, if present. Passing error prevents 205 // Dismiss history panel by pressing done, if present. Passing error prevents
206 // failure if the element is not found. 206 // failure if the element is not found.
207 [[EarlGrey selectElementWithMatcher:navigationDoneButton()] 207 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()]
208 performAction:grey_tap() 208 performAction:grey_tap()
209 error:&error]; 209 error:&error];
210 210
211 // Some tests change the default values for the "Clear Browsing Data" settings 211 // Some tests change the default values for the "Clear Browsing Data" settings
212 // screen. 212 // screen.
213 [self resetBrowsingDataPrefs]; 213 [self resetBrowsingDataPrefs];
214 [super tearDown]; 214 [super tearDown];
215 } 215 }
216 216
217 #pragma mark Tests 217 #pragma mark Tests
218 218
219 // Tests that no history is shown if there has been no navigation. 219 // Tests that no history is shown if there has been no navigation.
220 - (void)testDisplayNoHistory { 220 - (void)testDisplayNoHistory {
221 [self openHistoryPanel]; 221 [self openHistoryPanel];
222 [self assertNoHistoryShown]; 222 [self assertNoHistoryShown];
223 } 223 }
224 224
225 // Tests that the history panel displays navigation history. 225 // Tests that the history panel displays navigation history.
226 - (void)testDisplayHistory { 226 - (void)testDisplayHistory {
227 [self loadTestURLs]; 227 [self loadTestURLs];
228 [self openHistoryPanel]; 228 [self openHistoryPanel];
229 229
230 // Assert that history displays three entries. 230 // Assert that history displays three entries.
231 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 231 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
232 assertWithMatcher:grey_notNil()]; 232 assertWithMatcher:grey_notNil()];
233 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL2)] 233 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)]
234 assertWithMatcher:grey_notNil()]; 234 assertWithMatcher:grey_notNil()];
235 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL3)] 235 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)]
236 assertWithMatcher:grey_notNil()]; 236 assertWithMatcher:grey_notNil()];
237 237
238 // Tap a history entry and assert that navigation to that entry's URL occurs. 238 // Tap a history entry and assert that navigation to that entry's URL occurs.
239 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 239 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
240 performAction:grey_tap()]; 240 performAction:grey_tap()];
241 id<GREYMatcher> webViewMatcher = 241 id<GREYMatcher> webViewMatcher =
242 chrome_test_util::webViewContainingText(kResponse1); 242 chrome_test_util::WebViewContainingText(kResponse1);
243 [[EarlGrey selectElementWithMatcher:webViewMatcher] 243 [[EarlGrey selectElementWithMatcher:webViewMatcher]
244 assertWithMatcher:grey_notNil()]; 244 assertWithMatcher:grey_notNil()];
245 } 245 }
246 246
247 // Test that history displays a message about entries only if the user is logged 247 // Test that history displays a message about entries only if the user is logged
248 // in, and that tapping on the link in the message opens a new tab with the sync 248 // in, and that tapping on the link in the message opens a new tab with the sync
249 // help page. 249 // help page.
250 - (void)testHistoryEntriesStatusCell { 250 - (void)testHistoryEntriesStatusCell {
251 [self loadTestURLs]; 251 [self loadTestURLs];
252 [self openHistoryPanel]; 252 [self openHistoryPanel];
253 // Assert that no message is shown when the user is not signed in. 253 // Assert that no message is shown when the user is not signed in.
254 NSRange range; 254 NSRange range;
255 NSString* entriesMessage = ParseStringWithLink( 255 NSString* entriesMessage = ParseStringWithLink(
256 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS), &range); 256 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS), &range);
257 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)] 257 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)]
258 assertWithMatcher:grey_nil()]; 258 assertWithMatcher:grey_nil()];
259 [[EarlGrey selectElementWithMatcher:navigationDoneButton()] 259 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()]
260 performAction:grey_tap()]; 260 performAction:grey_tap()];
261 261
262 // Sign in and assert that the page indicates what type of history entries 262 // Sign in and assert that the page indicates what type of history entries
263 // are shown. 263 // are shown.
264 MockSignIn(); 264 MockSignIn();
265 [self openHistoryPanel]; 265 [self openHistoryPanel];
266 // Assert that message about entries is shown. The "history is showing local 266 // Assert that message about entries is shown. The "history is showing local
267 // entries" message will be shown because sync is not set up for this test. 267 // entries" message will be shown because sync is not set up for this test.
268 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)] 268 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)]
269 assertWithMatcher:grey_notNil()]; 269 assertWithMatcher:grey_notNil()];
270 270
271 // Tap on "Learn more" link and assert that new tab with the link is opened. 271 // Tap on "Learn more" link and assert that new tab with the link is opened.
272 [[EarlGrey 272 [[EarlGrey
273 selectElementWithMatcher:grey_kindOfClass([TransparentLinkButton class])] 273 selectElementWithMatcher:grey_kindOfClass([TransparentLinkButton class])]
274 performAction:grey_tap()]; 274 performAction:grey_tap()];
275 chrome_test_util::AssertMainTabCount(2); 275 chrome_test_util::AssertMainTabCount(2);
276 id<GREYMatcher> webViewMatcher = chrome_test_util::webViewContainingText( 276 id<GREYMatcher> webViewMatcher = chrome_test_util::WebViewContainingText(
277 "Sync and view tabs and history across devices"); 277 "Sync and view tabs and history across devices");
278 [[EarlGrey selectElementWithMatcher:webViewMatcher] 278 [[EarlGrey selectElementWithMatcher:webViewMatcher]
279 assertWithMatcher:grey_notNil()]; 279 assertWithMatcher:grey_notNil()];
280 } 280 }
281 281
282 // Tests that searching history displays only entries matching the search term. 282 // Tests that searching history displays only entries matching the search term.
283 - (void)testSearchHistory { 283 - (void)testSearchHistory {
284 [self loadTestURLs]; 284 [self loadTestURLs];
285 [self openHistoryPanel]; 285 [self openHistoryPanel];
286 [[EarlGrey selectElementWithMatcher:searchIconButton()] 286 [[EarlGrey selectElementWithMatcher:SearchIconButton()]
287 performAction:grey_tap()]; 287 performAction:grey_tap()];
288 288
289 NSString* searchString = 289 NSString* searchString =
290 [NSString stringWithFormat:@"%s", _URL1.path().c_str()]; 290 [NSString stringWithFormat:@"%s", _URL1.path().c_str()];
291 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] 291 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]
292 performAction:grey_typeText(searchString)]; 292 performAction:grey_typeText(searchString)];
293 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 293 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
294 assertWithMatcher:grey_notNil()]; 294 assertWithMatcher:grey_notNil()];
295 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL2)] 295 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)]
296 assertWithMatcher:grey_nil()]; 296 assertWithMatcher:grey_nil()];
297 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL3)] 297 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)]
298 assertWithMatcher:grey_nil()]; 298 assertWithMatcher:grey_nil()];
299 } 299 }
300 300
301 // Tests deletion of history entries. 301 // Tests deletion of history entries.
302 - (void)testDeleteHistory { 302 - (void)testDeleteHistory {
303 [self loadTestURLs]; 303 [self loadTestURLs];
304 [self openHistoryPanel]; 304 [self openHistoryPanel];
305 305
306 // Assert that three history elements are present. 306 // Assert that three history elements are present.
307 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 307 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
308 assertWithMatcher:grey_notNil()]; 308 assertWithMatcher:grey_notNil()];
309 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL2)] 309 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)]
310 assertWithMatcher:grey_notNil()]; 310 assertWithMatcher:grey_notNil()];
311 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL3)] 311 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)]
312 assertWithMatcher:grey_notNil()]; 312 assertWithMatcher:grey_notNil()];
313 313
314 // Enter edit mode, select a history element, and press delete. 314 // Enter edit mode, select a history element, and press delete.
315 [[EarlGrey selectElementWithMatcher:navigationEditButton()] 315 [[EarlGrey selectElementWithMatcher:NavigationEditButton()]
316 performAction:grey_tap()]; 316 performAction:grey_tap()];
317 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 317 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
318 performAction:grey_tap()]; 318 performAction:grey_tap()];
319 [[EarlGrey selectElementWithMatcher:deleteHistoryEntriesButton()] 319 [[EarlGrey selectElementWithMatcher:DeleteHistoryEntriesButton()]
320 performAction:grey_tap()]; 320 performAction:grey_tap()];
321 321
322 // Assert that the deleted entry is gone and the other two remain. 322 // Assert that the deleted entry is gone and the other two remain.
323 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 323 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
324 assertWithMatcher:grey_nil()]; 324 assertWithMatcher:grey_nil()];
325 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL2)] 325 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)]
326 assertWithMatcher:grey_notNil()]; 326 assertWithMatcher:grey_notNil()];
327 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL3)] 327 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)]
328 assertWithMatcher:grey_notNil()]; 328 assertWithMatcher:grey_notNil()];
329 329
330 // Enter edit mode, select both remaining entries, and press delete. 330 // Enter edit mode, select both remaining entries, and press delete.
331 [[EarlGrey selectElementWithMatcher:navigationEditButton()] 331 [[EarlGrey selectElementWithMatcher:NavigationEditButton()]
332 performAction:grey_tap()]; 332 performAction:grey_tap()];
333 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL2)] 333 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)]
334 performAction:grey_tap()]; 334 performAction:grey_tap()];
335 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL3)] 335 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)]
336 performAction:grey_tap()]; 336 performAction:grey_tap()];
337 [[EarlGrey selectElementWithMatcher:deleteHistoryEntriesButton()] 337 [[EarlGrey selectElementWithMatcher:DeleteHistoryEntriesButton()]
338 performAction:grey_tap()]; 338 performAction:grey_tap()];
339 339
340 [self assertNoHistoryShown]; 340 [self assertNoHistoryShown];
341 } 341 }
342 342
343 // Tests clear browsing history. 343 // Tests clear browsing history.
344 - (void)testClearBrowsingHistory { 344 - (void)testClearBrowsingHistory {
345 [self loadTestURLs]; 345 [self loadTestURLs];
346 [self openHistoryPanel]; 346 [self openHistoryPanel];
347 347
348 // Open the Clear Browsing Data dialog. 348 // Open the Clear Browsing Data dialog.
349 [[EarlGrey selectElementWithMatcher:openClearBrowsingDataButton()] 349 [[EarlGrey selectElementWithMatcher:OpenClearBrowsingDataButton()]
350 performAction:grey_tap()]; 350 performAction:grey_tap()];
351 351
352 // Uncheck "Cookies, Site Data" and "Cached Images and Files," which are 352 // Uncheck "Cookies, Site Data" and "Cached Images and Files," which are
353 // checked by default, and press "Clear Browsing Data" 353 // checked by default, and press "Clear Browsing Data"
354 [[EarlGrey selectElementWithMatcher:clearCookiesButton()] 354 [[EarlGrey selectElementWithMatcher:ClearCookiesButton()]
355 performAction:grey_tap()]; 355 performAction:grey_tap()];
356 [[EarlGrey selectElementWithMatcher:clearCacheButton()] 356 [[EarlGrey selectElementWithMatcher:ClearCacheButton()]
357 performAction:grey_tap()]; 357 performAction:grey_tap()];
358 [[EarlGrey selectElementWithMatcher:clearBrowsingDataButton()] 358 [[EarlGrey selectElementWithMatcher:ClearBrowsingDataButton()]
359 performAction:grey_tap()]; 359 performAction:grey_tap()];
360 360
361 // There is not currently a matcher for acessibilityElementIsFocused or 361 // There is not currently a matcher for acessibilityElementIsFocused or
362 // userInteractionEnabled which could be used here instead of checking that 362 // userInteractionEnabled which could be used here instead of checking that
363 // the button is not a MDCCollectionViewTextCell. Use when available. 363 // the button is not a MDCCollectionViewTextCell. Use when available.
364 // TODO(crbug.com/638674): Evaluate if this can move to shared code. 364 // TODO(crbug.com/638674): Evaluate if this can move to shared code.
365 id<GREYMatcher> confirmClear = grey_allOf( 365 id<GREYMatcher> confirmClear = grey_allOf(
366 clearBrowsingDataButton(), 366 ClearBrowsingDataButton(),
367 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil); 367 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil);
368 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()]; 368 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()];
369 [[EarlGrey selectElementWithMatcher:navigationDoneButton()] 369 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()]
370 performAction:grey_tap()]; 370 performAction:grey_tap()];
371 371
372 [self assertNoHistoryShown]; 372 [self assertNoHistoryShown];
373 } 373 }
374 374
375 // Tests display and selection of 'Open in New Tab' in a context menu on a 375 // Tests display and selection of 'Open in New Tab' in a context menu on a
376 // history entry. 376 // history entry.
377 - (void)testContextMenuOpenInNewTab { 377 - (void)testContextMenuOpenInNewTab {
378 [self loadTestURLs]; 378 [self loadTestURLs];
379 [self openHistoryPanel]; 379 [self openHistoryPanel];
380 380
381 // Long press on the history element. 381 // Long press on the history element.
382 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 382 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
383 performAction:grey_longPress()]; 383 performAction:grey_longPress()];
384 384
385 // Select "Open in New Tab" and confirm that new tab is opened with selected 385 // Select "Open in New Tab" and confirm that new tab is opened with selected
386 // URL. 386 // URL.
387 [[EarlGrey selectElementWithMatcher:openInNewTabButton()] 387 [[EarlGrey selectElementWithMatcher:OpenInNewTabButton()]
388 performAction:grey_tap()]; 388 performAction:grey_tap()];
389 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( 389 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
390 _URL1.GetContent())] 390 _URL1.GetContent())]
391 assertWithMatcher:grey_notNil()]; 391 assertWithMatcher:grey_notNil()];
392 chrome_test_util::AssertMainTabCount(2); 392 chrome_test_util::AssertMainTabCount(2);
393 } 393 }
394 394
395 // Tests display and selection of 'Open in New Incognito Tab' in a context menu 395 // Tests display and selection of 'Open in New Incognito Tab' in a context menu
396 // on a history entry. 396 // on a history entry.
397 - (void)testContextMenuOpenInNewIncognitoTab { 397 - (void)testContextMenuOpenInNewIncognitoTab {
398 [self loadTestURLs]; 398 [self loadTestURLs];
399 [self openHistoryPanel]; 399 [self openHistoryPanel];
400 400
401 // Long press on the history element. 401 // Long press on the history element.
402 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 402 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
403 performAction:grey_longPress()]; 403 performAction:grey_longPress()];
404 404
405 // Select "Open in New Incognito Tab" and confirm that new tab is opened in 405 // Select "Open in New Incognito Tab" and confirm that new tab is opened in
406 // incognito with the selected URL. 406 // incognito with the selected URL.
407 [[EarlGrey selectElementWithMatcher:openInNewIncognitoTabButton()] 407 [[EarlGrey selectElementWithMatcher:OpenInNewIncognitoTabButton()]
408 performAction:grey_tap()]; 408 performAction:grey_tap()];
409 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( 409 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
410 _URL1.GetContent())] 410 _URL1.GetContent())]
411 assertWithMatcher:grey_notNil()]; 411 assertWithMatcher:grey_notNil()];
412 chrome_test_util::AssertMainTabCount(1); 412 chrome_test_util::AssertMainTabCount(1);
413 chrome_test_util::AssertIncognitoTabCount(1); 413 chrome_test_util::AssertIncognitoTabCount(1);
414 } 414 }
415 415
416 // Tests display and selection of 'Copy URL' in a context menu on a history 416 // Tests display and selection of 'Copy URL' in a context menu on a history
417 // entry. 417 // entry.
418 - (void)testContextMenuCopy { 418 - (void)testContextMenuCopy {
419 ProceduralBlock clearPasteboard = ^{ 419 ProceduralBlock clearPasteboard = ^{
420 [[UIPasteboard generalPasteboard] setURLs:nil]; 420 [[UIPasteboard generalPasteboard] setURLs:nil];
421 }; 421 };
422 [self setTearDownHandler:clearPasteboard]; 422 [self setTearDownHandler:clearPasteboard];
423 clearPasteboard(); 423 clearPasteboard();
424 424
425 [self loadTestURLs]; 425 [self loadTestURLs];
426 [self openHistoryPanel]; 426 [self openHistoryPanel];
427 427
428 // Long press on the history element. 428 // Long press on the history element.
429 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] 429 [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)]
430 performAction:grey_longPress()]; 430 performAction:grey_longPress()];
431 431
432 // Tap "Copy URL" and wait for the URL to be copied to the pasteboard. 432 // Tap "Copy URL" and wait for the URL to be copied to the pasteboard.
433 [[EarlGrey selectElementWithMatcher:copyUrlButton()] 433 [[EarlGrey selectElementWithMatcher:CopyUrlButton()]
434 performAction:grey_tap()]; 434 performAction:grey_tap()];
435 bool success = 435 bool success =
436 testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{ 436 testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{
437 return _URL1 == 437 return _URL1 ==
438 net::GURLWithNSURL([UIPasteboard generalPasteboard].URL); 438 net::GURLWithNSURL([UIPasteboard generalPasteboard].URL);
439 }); 439 });
440 GREYAssertTrue(success, @"Pasteboard URL was not set to %s", 440 GREYAssertTrue(success, @"Pasteboard URL was not set to %s",
441 _URL1.spec().c_str()); 441 _URL1.spec().c_str());
442 } 442 }
443 443
444 // Navigates to history and checks elements for accessibility. 444 // Navigates to history and checks elements for accessibility.
445 - (void)testAccessibilityOnHistory { 445 - (void)testAccessibilityOnHistory {
446 [self openHistoryPanel]; 446 [self openHistoryPanel];
447 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 447 chrome_test_util::VerifyAccessibilityForCurrentScreen();
448 // Close history. 448 // Close history.
449 [[EarlGrey 449 [[EarlGrey
450 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( 450 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
451 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] 451 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
452 performAction:grey_tap()]; 452 performAction:grey_tap()];
453 } 453 }
454 454
455 #pragma mark Helper Methods 455 #pragma mark Helper Methods
456 456
457 - (void)loadTestURLs { 457 - (void)loadTestURLs {
458 [ChromeEarlGrey loadURL:_URL1]; 458 [ChromeEarlGrey loadURL:_URL1];
459 id<GREYMatcher> response1Matcher = 459 id<GREYMatcher> response1Matcher =
460 chrome_test_util::webViewContainingText(kResponse1); 460 chrome_test_util::WebViewContainingText(kResponse1);
461 [[EarlGrey selectElementWithMatcher:response1Matcher] 461 [[EarlGrey selectElementWithMatcher:response1Matcher]
462 assertWithMatcher:grey_notNil()]; 462 assertWithMatcher:grey_notNil()];
463 463
464 [ChromeEarlGrey loadURL:_URL2]; 464 [ChromeEarlGrey loadURL:_URL2];
465 id<GREYMatcher> response2Matcher = 465 id<GREYMatcher> response2Matcher =
466 chrome_test_util::webViewContainingText(kResponse2); 466 chrome_test_util::WebViewContainingText(kResponse2);
467 [[EarlGrey selectElementWithMatcher:response2Matcher] 467 [[EarlGrey selectElementWithMatcher:response2Matcher]
468 assertWithMatcher:grey_notNil()]; 468 assertWithMatcher:grey_notNil()];
469 469
470 [ChromeEarlGrey loadURL:_URL3]; 470 [ChromeEarlGrey loadURL:_URL3];
471 id<GREYMatcher> response3Matcher = 471 id<GREYMatcher> response3Matcher =
472 chrome_test_util::webViewContainingText(kResponse3); 472 chrome_test_util::WebViewContainingText(kResponse3);
473 [[EarlGrey selectElementWithMatcher:response3Matcher] 473 [[EarlGrey selectElementWithMatcher:response3Matcher]
474 assertWithMatcher:grey_notNil()]; 474 assertWithMatcher:grey_notNil()];
475 } 475 }
476 476
477 - (void)openHistoryPanel { 477 - (void)openHistoryPanel {
478 [ChromeEarlGreyUI openToolsMenu]; 478 [ChromeEarlGreyUI openToolsMenu];
479 [[EarlGrey selectElementWithMatcher:historyButton()] 479 [[EarlGrey selectElementWithMatcher:HistoryButton()]
480 performAction:grey_tap()]; 480 performAction:grey_tap()];
481 } 481 }
482 482
483 - (void)assertNoHistoryShown { 483 - (void)assertNoHistoryShown {
484 id<GREYMatcher> noHistoryMessageMatcher = 484 id<GREYMatcher> noHistoryMessageMatcher =
485 grey_allOf(grey_text(l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS)), 485 grey_allOf(grey_text(l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS)),
486 grey_sufficientlyVisible(), nil); 486 grey_sufficientlyVisible(), nil);
487 [[EarlGrey selectElementWithMatcher:noHistoryMessageMatcher] 487 [[EarlGrey selectElementWithMatcher:noHistoryMessageMatcher]
488 assertWithMatcher:grey_notNil()]; 488 assertWithMatcher:grey_notNil()];
489 489
490 id<GREYMatcher> historyEntryMatcher = 490 id<GREYMatcher> historyEntryMatcher =
491 grey_allOf(grey_kindOfClass([HistoryEntryCell class]), 491 grey_allOf(grey_kindOfClass([HistoryEntryCell class]),
492 grey_sufficientlyVisible(), nil); 492 grey_sufficientlyVisible(), nil);
493 [[EarlGrey selectElementWithMatcher:historyEntryMatcher] 493 [[EarlGrey selectElementWithMatcher:historyEntryMatcher]
494 assertWithMatcher:grey_nil()]; 494 assertWithMatcher:grey_nil()];
495 } 495 }
496 496
497 - (void)resetBrowsingDataPrefs { 497 - (void)resetBrowsingDataPrefs {
498 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); 498 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs();
499 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); 499 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory);
500 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); 500 prefs->ClearPref(browsing_data::prefs::kDeleteCookies);
501 prefs->ClearPref(browsing_data::prefs::kDeleteCache); 501 prefs->ClearPref(browsing_data::prefs::kDeleteCache);
502 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); 502 prefs->ClearPref(browsing_data::prefs::kDeletePasswords);
503 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); 503 prefs->ClearPref(browsing_data::prefs::kDeleteFormData);
504 } 504 }
505 505
506 @end 506 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/fullscreen_egtest.mm ('k') | ios/chrome/browser/ui/history/tab_history_popup_controller_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698