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

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

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting Created 3 years, 8 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 23 matching lines...) Expand all
34 #import "ios/testing/wait_util.h" 34 #import "ios/testing/wait_util.h"
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 base::SysUTF8ToNSString;
44 using chrome_test_util::ButtonWithAccessibilityLabelId; 45 using chrome_test_util::ButtonWithAccessibilityLabelId;
45 using chrome_test_util::NavigationBarDoneButton; 46 using chrome_test_util::NavigationBarDoneButton;
46 using chrome_test_util::OpenLinkInNewTabButton; 47 using chrome_test_util::OpenLinkInNewTabButton;
47 using chrome_test_util::WebViewContainingText;
48 48
49 namespace { 49 namespace {
50 char kURL1[] = "http://firstURL"; 50 char kURL1[] = "http://firstURL";
51 char kURL2[] = "http://secondURL"; 51 char kURL2[] = "http://secondURL";
52 char kURL3[] = "http://thirdURL"; 52 char kURL3[] = "http://thirdURL";
53 char kTitle1[] = "Page 1"; 53 char kTitle1[] = "Page 1";
54 char kTitle2[] = "Page 2"; 54 char kTitle2[] = "Page 2";
55 char kResponse1[] = "Test Page 1 content"; 55 char kResponse1[] = "Test Page 1 content";
56 char kResponse2[] = "Test Page 2 content"; 56 char kResponse2[] = "Test Page 2 content";
57 char kResponse3[] = "Test Page 3 content"; 57 char kResponse3[] = "Test Page 3 content";
58 58
59 // Matcher for entry in history for URL and title. 59 // Matcher for entry in history for URL and title.
60 id<GREYMatcher> HistoryEntry(const GURL& url, const std::string& title) { 60 id<GREYMatcher> HistoryEntry(const GURL& url, const std::string& title) {
61 NSString* url_spec_text = base::SysUTF8ToNSString(url.spec()); 61 NSString* url_spec_text = SysUTF8ToNSString(url.spec());
62 NSString* title_text = base::SysUTF8ToNSString(title); 62 NSString* title_text = SysUTF8ToNSString(title);
63 63
64 MatchesBlock matches = ^BOOL(HistoryEntryCell* cell) { 64 MatchesBlock matches = ^BOOL(HistoryEntryCell* cell) {
65 return [cell.textLabel.text isEqual:title_text] && 65 return [cell.textLabel.text isEqual:title_text] &&
66 [cell.detailTextLabel.text isEqual:url_spec_text]; 66 [cell.detailTextLabel.text isEqual:url_spec_text];
67 }; 67 };
68 68
69 DescribeToBlock describe = ^(id<GREYDescription> description) { 69 DescribeToBlock describe = ^(id<GREYDescription> description) {
70 [description appendText:@"view containing URL text: "]; 70 [description appendText:@"view containing URL text: "];
71 [description appendText:url_spec_text]; 71 [description appendText:url_spec_text];
72 [description appendText:@" title text: "]; 72 [description appendText:@" title text: "];
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] 252 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)]
253 assertWithMatcher:grey_notNil()]; 253 assertWithMatcher:grey_notNil()];
254 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] 254 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)]
255 assertWithMatcher:grey_notNil()]; 255 assertWithMatcher:grey_notNil()];
256 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] 256 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())]
257 assertWithMatcher:grey_notNil()]; 257 assertWithMatcher:grey_notNil()];
258 258
259 // Tap a history entry and assert that navigation to that entry's URL occurs. 259 // Tap a history entry and assert that navigation to that entry's URL occurs.
260 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] 260 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)]
261 performAction:grey_tap()]; 261 performAction:grey_tap()];
262 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] 262 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse1)];
263 assertWithMatcher:grey_notNil()];
264 } 263 }
265 264
266 // Tests that history is not changed after performing back navigation. 265 // Tests that history is not changed after performing back navigation.
267 - (void)testHistoryUpdateAfterBackNavigation { 266 - (void)testHistoryUpdateAfterBackNavigation {
268 [ChromeEarlGrey loadURL:_URL1]; 267 [ChromeEarlGrey loadURL:_URL1];
269 [ChromeEarlGrey loadURL:_URL2]; 268 [ChromeEarlGrey loadURL:_URL2];
270 269
271 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] 270 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()]
272 performAction:grey_tap()]; 271 performAction:grey_tap()];
273 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] 272 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse1)];
274 assertWithMatcher:grey_notNil()];
275 273
276 [self openHistoryPanel]; 274 [self openHistoryPanel];
277 275
278 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] 276 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)]
279 assertWithMatcher:grey_notNil()]; 277 assertWithMatcher:grey_notNil()];
280 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] 278 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)]
281 assertWithMatcher:grey_notNil()]; 279 assertWithMatcher:grey_notNil()];
282 } 280 }
283 281
284 // Test that history displays a message about entries only if the user is logged 282 // Test that history displays a message about entries only if the user is logged
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 479 chrome_test_util::VerifyAccessibilityForCurrentScreen();
482 // Close history. 480 // Close history.
483 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] 481 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
484 performAction:grey_tap()]; 482 performAction:grey_tap()];
485 } 483 }
486 484
487 #pragma mark Helper Methods 485 #pragma mark Helper Methods
488 486
489 - (void)loadTestURLs { 487 - (void)loadTestURLs {
490 [ChromeEarlGrey loadURL:_URL1]; 488 [ChromeEarlGrey loadURL:_URL1];
491 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] 489 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse1)];
492 assertWithMatcher:grey_notNil()];
493 490
494 [ChromeEarlGrey loadURL:_URL2]; 491 [ChromeEarlGrey loadURL:_URL2];
495 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse2)] 492 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse2)];
496 assertWithMatcher:grey_notNil()];
497 493
498 [ChromeEarlGrey loadURL:_URL3]; 494 [ChromeEarlGrey loadURL:_URL3];
499 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse3)] 495 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse3)];
500 assertWithMatcher:grey_notNil()];
501 } 496 }
502 497
503 - (void)openHistoryPanel { 498 - (void)openHistoryPanel {
504 [ChromeEarlGreyUI openToolsMenu]; 499 [ChromeEarlGreyUI openToolsMenu];
505 [[EarlGrey selectElementWithMatcher:HistoryButton()] 500 [[EarlGrey selectElementWithMatcher:HistoryButton()]
506 performAction:grey_tap()]; 501 performAction:grey_tap()];
507 } 502 }
508 503
509 - (void)assertNoHistoryShown { 504 - (void)assertNoHistoryShown {
510 id<GREYMatcher> noHistoryMessageMatcher = 505 id<GREYMatcher> noHistoryMessageMatcher =
(...skipping 12 matching lines...) Expand all
523 - (void)resetBrowsingDataPrefs { 518 - (void)resetBrowsingDataPrefs {
524 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); 519 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs();
525 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); 520 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory);
526 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); 521 prefs->ClearPref(browsing_data::prefs::kDeleteCookies);
527 prefs->ClearPref(browsing_data::prefs::kDeleteCache); 522 prefs->ClearPref(browsing_data::prefs::kDeleteCache);
528 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); 523 prefs->ClearPref(browsing_data::prefs::kDeletePasswords);
529 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); 524 prefs->ClearPref(browsing_data::prefs::kDeleteFormData);
530 } 525 }
531 526
532 @end 527 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698