Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 34 #import "ios/testing/wait_util.h" | 34 #import "ios/testing/wait_util.h" | 
| 35 #import "ios/web/public/test/http_server/http_server.h" | 35 #import "ios/web/public/test/http_server/http_server.h" | 
| 36 #import "ios/web/public/test/http_server/http_server_util.h" | 36 #import "ios/web/public/test/http_server/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()); | 
| 
 
Eugene But (OOO till 7-30)
2017/06/12 03:47:11
nit: Is this really necessary?
 
baxley
2017/06/12 16:41:17
Nope. This was there from when I had the API take
 
 | |
| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] | 246 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] | 
| 247 assertWithMatcher:grey_notNil()]; | 247 assertWithMatcher:grey_notNil()]; | 
| 248 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] | 248 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] | 
| 249 assertWithMatcher:grey_notNil()]; | 249 assertWithMatcher:grey_notNil()]; | 
| 250 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] | 250 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] | 
| 251 assertWithMatcher:grey_notNil()]; | 251 assertWithMatcher:grey_notNil()]; | 
| 252 | 252 | 
| 253 // Tap a history entry and assert that navigation to that entry's URL occurs. | 253 // Tap a history entry and assert that navigation to that entry's URL occurs. | 
| 254 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] | 254 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] | 
| 255 performAction:grey_tap()]; | 255 performAction:grey_tap()]; | 
| 256 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] | 256 [ChromeEarlGrey waitForWebViewContainingText:kResponse1]; | 
| 257 assertWithMatcher:grey_notNil()]; | |
| 258 } | 257 } | 
| 259 | 258 | 
| 260 // Tests that history is not changed after performing back navigation. | 259 // Tests that history is not changed after performing back navigation. | 
| 261 - (void)testHistoryUpdateAfterBackNavigation { | 260 - (void)testHistoryUpdateAfterBackNavigation { | 
| 262 [ChromeEarlGrey loadURL:_URL1]; | 261 [ChromeEarlGrey loadURL:_URL1]; | 
| 263 [ChromeEarlGrey loadURL:_URL2]; | 262 [ChromeEarlGrey loadURL:_URL2]; | 
| 264 | 263 | 
| 265 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 264 [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] | 
| 266 performAction:grey_tap()]; | 265 performAction:grey_tap()]; | 
| 267 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] | 266 [ChromeEarlGrey waitForWebViewContainingText:kResponse1]; | 
| 268 assertWithMatcher:grey_notNil()]; | |
| 269 | 267 | 
| 270 [self openHistoryPanel]; | 268 [self openHistoryPanel]; | 
| 271 | 269 | 
| 272 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] | 270 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] | 
| 273 assertWithMatcher:grey_notNil()]; | 271 assertWithMatcher:grey_notNil()]; | 
| 274 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] | 272 [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] | 
| 275 assertWithMatcher:grey_notNil()]; | 273 assertWithMatcher:grey_notNil()]; | 
| 276 } | 274 } | 
| 277 | 275 | 
| 278 // Test that history displays a message about entries only if the user is logged | 276 // 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 Loading... | |
| 475 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 473 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 
| 476 // Close history. | 474 // Close history. | 
| 477 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] | 475 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] | 
| 478 performAction:grey_tap()]; | 476 performAction:grey_tap()]; | 
| 479 } | 477 } | 
| 480 | 478 | 
| 481 #pragma mark Helper Methods | 479 #pragma mark Helper Methods | 
| 482 | 480 | 
| 483 - (void)loadTestURLs { | 481 - (void)loadTestURLs { | 
| 484 [ChromeEarlGrey loadURL:_URL1]; | 482 [ChromeEarlGrey loadURL:_URL1]; | 
| 485 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] | 483 [ChromeEarlGrey waitForWebViewContainingText:kResponse1]; | 
| 486 assertWithMatcher:grey_notNil()]; | |
| 487 | 484 | 
| 488 [ChromeEarlGrey loadURL:_URL2]; | 485 [ChromeEarlGrey loadURL:_URL2]; | 
| 489 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse2)] | 486 [ChromeEarlGrey waitForWebViewContainingText:kResponse2]; | 
| 490 assertWithMatcher:grey_notNil()]; | |
| 491 | 487 | 
| 492 [ChromeEarlGrey loadURL:_URL3]; | 488 [ChromeEarlGrey loadURL:_URL3]; | 
| 493 [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse3)] | 489 [ChromeEarlGrey waitForWebViewContainingText:kResponse3]; | 
| 494 assertWithMatcher:grey_notNil()]; | |
| 495 } | 490 } | 
| 496 | 491 | 
| 497 - (void)openHistoryPanel { | 492 - (void)openHistoryPanel { | 
| 498 [ChromeEarlGreyUI openToolsMenu]; | 493 [ChromeEarlGreyUI openToolsMenu]; | 
| 499 [[EarlGrey selectElementWithMatcher:HistoryButton()] | 494 [[EarlGrey selectElementWithMatcher:HistoryButton()] | 
| 500 performAction:grey_tap()]; | 495 performAction:grey_tap()]; | 
| 501 } | 496 } | 
| 502 | 497 | 
| 503 - (void)assertNoHistoryShown { | 498 - (void)assertNoHistoryShown { | 
| 504 id<GREYMatcher> noHistoryMessageMatcher = | 499 id<GREYMatcher> noHistoryMessageMatcher = | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 517 - (void)resetBrowsingDataPrefs { | 512 - (void)resetBrowsingDataPrefs { | 
| 518 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); | 513 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); | 
| 519 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); | 514 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); | 
| 520 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); | 515 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); | 
| 521 prefs->ClearPref(browsing_data::prefs::kDeleteCache); | 516 prefs->ClearPref(browsing_data::prefs::kDeleteCache); | 
| 522 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); | 517 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); | 
| 523 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); | 518 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); | 
| 524 } | 519 } | 
| 525 | 520 | 
| 526 @end | 521 @end | 
| OLD | NEW |