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

Side by Side Diff: ios/chrome/browser/ui/history/history_ui_egtest.mm

Issue 2733973002: Create shared matcher for navigation bar done button. (Closed)
Patch Set: Created 3 years, 9 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/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 24 matching lines...) Expand all
35 #import "ios/web/public/test/http_server.h" 35 #import "ios/web/public/test/http_server.h"
36 #import "ios/web/public/test/http_server_util.h" 36 #import "ios/web/public/test/http_server_util.h"
37 #import "net/base/mac/url_conversions.h" 37 #import "net/base/mac/url_conversions.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 39
40 #if !defined(__has_feature) || !__has_feature(objc_arc) 40 #if !defined(__has_feature) || !__has_feature(objc_arc)
41 #error "This file requires ARC support." 41 #error "This file requires ARC support."
42 #endif 42 #endif
43 43
44 using chrome_test_util::ButtonWithAccessibilityLabelId; 44 using chrome_test_util::ButtonWithAccessibilityLabelId;
45 using chrome_test_util::NavigationBarDoneButton;
45 using chrome_test_util::OpenLinkInNewTabMenuItem; 46 using chrome_test_util::OpenLinkInNewTabMenuItem;
46 using chrome_test_util::WebViewContainingText; 47 using chrome_test_util::WebViewContainingText;
47 48
48 namespace { 49 namespace {
49 char kURL1[] = "http://firstURL"; 50 char kURL1[] = "http://firstURL";
50 char kURL2[] = "http://secondURL"; 51 char kURL2[] = "http://secondURL";
51 char kURL3[] = "http://thirdURL"; 52 char kURL3[] = "http://thirdURL";
52 char kTitle1[] = "Page 1"; 53 char kTitle1[] = "Page 1";
53 char kTitle2[] = "Page 2"; 54 char kTitle2[] = "Page 2";
54 char kResponse1[] = "Test Page 1 content"; 55 char kResponse1[] = "Test Page 1 content";
(...skipping 20 matching lines...) Expand all
75 return grey_allOf( 76 return grey_allOf(
76 grey_kindOfClass([HistoryEntryCell class]), 77 grey_kindOfClass([HistoryEntryCell class]),
77 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 78 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
78 descriptionBlock:describe], 79 descriptionBlock:describe],
79 grey_sufficientlyVisible(), nil); 80 grey_sufficientlyVisible(), nil);
80 } 81 }
81 // Matcher for the history button in the tools menu. 82 // Matcher for the history button in the tools menu.
82 id<GREYMatcher> HistoryButton() { 83 id<GREYMatcher> HistoryButton() {
83 return ButtonWithAccessibilityLabelId(IDS_HISTORY_SHOW_HISTORY); 84 return ButtonWithAccessibilityLabelId(IDS_HISTORY_SHOW_HISTORY);
84 } 85 }
85 // Matcher for the done button in the navigation bar.
86 id<GREYMatcher> NavigationDoneButton() {
87 // Include sufficientlyVisible condition for the case of the clear browsing
88 // dialog, which also has a "Done" button and is displayed over the history
89 // panel.
90 return grey_allOf(
91 ButtonWithAccessibilityLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON),
92 grey_sufficientlyVisible(), nil);
93 }
94 // Matcher for the edit button in the navigation bar. 86 // Matcher for the edit button in the navigation bar.
95 id<GREYMatcher> NavigationEditButton() { 87 id<GREYMatcher> NavigationEditButton() {
96 return ButtonWithAccessibilityLabelId(IDS_HISTORY_START_EDITING_BUTTON); 88 return ButtonWithAccessibilityLabelId(IDS_HISTORY_START_EDITING_BUTTON);
97 } 89 }
98 // Matcher for the delete button. 90 // Matcher for the delete button.
99 id<GREYMatcher> DeleteHistoryEntriesButton() { 91 id<GREYMatcher> DeleteHistoryEntriesButton() {
100 // Include class restriction to exclude MDCCollectionViewInfoBar, which is 92 // Include class restriction to exclude MDCCollectionViewInfoBar, which is
101 // hidden. 93 // hidden.
102 return grey_allOf(ButtonWithAccessibilityLabelId( 94 return grey_allOf(ButtonWithAccessibilityLabelId(
103 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON), 95 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 identity.userEmail)] 156 identity.userEmail)]
165 performAction:grey_tap()]; 157 performAction:grey_tap()];
166 [[EarlGrey selectElementWithMatcher: 158 [[EarlGrey selectElementWithMatcher:
167 chrome_test_util::ButtonWithAccessibilityLabelId( 159 chrome_test_util::ButtonWithAccessibilityLabelId(
168 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON)] 160 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON)]
169 performAction:grey_tap()]; 161 performAction:grey_tap()];
170 [[EarlGrey selectElementWithMatcher: 162 [[EarlGrey selectElementWithMatcher:
171 chrome_test_util::ButtonWithAccessibilityLabelId( 163 chrome_test_util::ButtonWithAccessibilityLabelId(
172 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON)] 164 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON)]
173 performAction:grey_tap()]; 165 performAction:grey_tap()];
174 [[EarlGrey 166 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
175 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
176 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
177 performAction:grey_tap()]; 167 performAction:grey_tap()];
178 } 168 }
179 } // namespace 169 } // namespace
180 170
181 // History UI tests. 171 // History UI tests.
182 @interface HistoryUITestCase : ChromeTestCase { 172 @interface HistoryUITestCase : ChromeTestCase {
183 GURL _URL1; 173 GURL _URL1;
184 GURL _URL2; 174 GURL _URL2;
185 GURL _URL3; 175 GURL _URL3;
186 } 176 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 214 }
225 215
226 - (void)tearDown { 216 - (void)tearDown {
227 NSError* error = nil; 217 NSError* error = nil;
228 // Dismiss search bar by pressing cancel, if present. Passing error prevents 218 // Dismiss search bar by pressing cancel, if present. Passing error prevents
229 // failure if the element is not found. 219 // failure if the element is not found.
230 [[EarlGrey selectElementWithMatcher:CancelButton()] performAction:grey_tap() 220 [[EarlGrey selectElementWithMatcher:CancelButton()] performAction:grey_tap()
231 error:&error]; 221 error:&error];
232 // Dismiss history panel by pressing done, if present. Passing error prevents 222 // Dismiss history panel by pressing done, if present. Passing error prevents
233 // failure if the element is not found. 223 // failure if the element is not found.
234 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()] 224 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
235 performAction:grey_tap() 225 performAction:grey_tap()
236 error:&error]; 226 error:&error];
237 227
238 // Some tests change the default values for the "Clear Browsing Data" settings 228 // Some tests change the default values for the "Clear Browsing Data" settings
239 // screen. 229 // screen.
240 [self resetBrowsingDataPrefs]; 230 [self resetBrowsingDataPrefs];
241 [super tearDown]; 231 [super tearDown];
242 } 232 }
243 233
244 #pragma mark Tests 234 #pragma mark Tests
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // help page. 282 // help page.
293 - (void)testHistoryEntriesStatusCell { 283 - (void)testHistoryEntriesStatusCell {
294 [self loadTestURLs]; 284 [self loadTestURLs];
295 [self openHistoryPanel]; 285 [self openHistoryPanel];
296 // Assert that no message is shown when the user is not signed in. 286 // Assert that no message is shown when the user is not signed in.
297 NSRange range; 287 NSRange range;
298 NSString* entriesMessage = ParseStringWithLink( 288 NSString* entriesMessage = ParseStringWithLink(
299 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS), &range); 289 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS), &range);
300 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)] 290 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)]
301 assertWithMatcher:grey_nil()]; 291 assertWithMatcher:grey_nil()];
302 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()] 292 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
303 performAction:grey_tap()]; 293 performAction:grey_tap()];
304 294
305 // Sign in and assert that the page indicates what type of history entries 295 // Sign in and assert that the page indicates what type of history entries
306 // are shown. 296 // are shown.
307 MockSignIn(); 297 MockSignIn();
308 [self openHistoryPanel]; 298 [self openHistoryPanel];
309 // Assert that message about entries is shown. The "history is showing local 299 // Assert that message about entries is shown. The "history is showing local
310 // entries" message will be shown because sync is not set up for this test. 300 // entries" message will be shown because sync is not set up for this test.
311 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)] 301 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)]
312 assertWithMatcher:grey_notNil()]; 302 assertWithMatcher:grey_notNil()];
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 performAction:grey_tap()]; 392 performAction:grey_tap()];
403 393
404 // There is not currently a matcher for acessibilityElementIsFocused or 394 // There is not currently a matcher for acessibilityElementIsFocused or
405 // userInteractionEnabled which could be used here instead of checking that 395 // userInteractionEnabled which could be used here instead of checking that
406 // the button is not a MDCCollectionViewTextCell. Use when available. 396 // the button is not a MDCCollectionViewTextCell. Use when available.
407 // TODO(crbug.com/638674): Evaluate if this can move to shared code. 397 // TODO(crbug.com/638674): Evaluate if this can move to shared code.
408 id<GREYMatcher> confirmClear = grey_allOf( 398 id<GREYMatcher> confirmClear = grey_allOf(
409 ClearBrowsingDataButton(), 399 ClearBrowsingDataButton(),
410 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil); 400 grey_not(grey_kindOfClass([MDCCollectionViewTextCell class])), nil);
411 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()]; 401 [[EarlGrey selectElementWithMatcher:confirmClear] performAction:grey_tap()];
412 [[EarlGrey selectElementWithMatcher:NavigationDoneButton()] 402 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
413 performAction:grey_tap()]; 403 performAction:grey_tap()];
414 404
415 [self assertNoHistoryShown]; 405 [self assertNoHistoryShown];
416 } 406 }
417 407
418 // Tests display and selection of 'Open in New Tab' in a context menu on a 408 // Tests display and selection of 'Open in New Tab' in a context menu on a
419 // history entry. 409 // history entry.
420 - (void)testContextMenuOpenInNewTab { 410 - (void)testContextMenuOpenInNewTab {
421 [self loadTestURLs]; 411 [self loadTestURLs];
422 [self openHistoryPanel]; 412 [self openHistoryPanel];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 }); 472 });
483 GREYAssertTrue(success, @"Pasteboard URL was not set to %s", 473 GREYAssertTrue(success, @"Pasteboard URL was not set to %s",
484 _URL1.spec().c_str()); 474 _URL1.spec().c_str());
485 } 475 }
486 476
487 // Navigates to history and checks elements for accessibility. 477 // Navigates to history and checks elements for accessibility.
488 - (void)testAccessibilityOnHistory { 478 - (void)testAccessibilityOnHistory {
489 [self openHistoryPanel]; 479 [self openHistoryPanel];
490 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 480 chrome_test_util::VerifyAccessibilityForCurrentScreen();
491 // Close history. 481 // Close history.
492 [[EarlGrey 482 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
493 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId(
494 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
495 performAction:grey_tap()]; 483 performAction:grey_tap()];
496 } 484 }
497 485
498 #pragma mark Helper Methods 486 #pragma mark Helper Methods
499 487
500 - (void)loadTestURLs { 488 - (void)loadTestURLs {
501 [ChromeEarlGrey loadURL:_URL1]; 489 [ChromeEarlGrey loadURL:_URL1];
502 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] 490 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)]
503 assertWithMatcher:grey_notNil()]; 491 assertWithMatcher:grey_notNil()];
504 492
(...skipping 29 matching lines...) Expand all
534 - (void)resetBrowsingDataPrefs { 522 - (void)resetBrowsingDataPrefs {
535 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); 523 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs();
536 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); 524 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory);
537 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); 525 prefs->ClearPref(browsing_data::prefs::kDeleteCookies);
538 prefs->ClearPref(browsing_data::prefs::kDeleteCache); 526 prefs->ClearPref(browsing_data::prefs::kDeleteCache);
539 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); 527 prefs->ClearPref(browsing_data::prefs::kDeletePasswords);
540 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); 528 prefs->ClearPref(browsing_data::prefs::kDeleteFormData);
541 } 529 }
542 530
543 @end 531 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698