Chromium Code Reviews| Index: ios/chrome/browser/ui/history/history_ui_egtest.mm |
| diff --git a/ios/chrome/browser/ui/history/history_ui_egtest.mm b/ios/chrome/browser/ui/history/history_ui_egtest.mm |
| index 789923a87d8c4509e37650db4f6c7d855a378c30..e52fd6237e267bfc25c556b6cb2a4482478eabf3 100644 |
| --- a/ios/chrome/browser/ui/history/history_ui_egtest.mm |
| +++ b/ios/chrome/browser/ui/history/history_ui_egtest.mm |
| @@ -6,6 +6,7 @@ |
| #import <UIKit/UIKit.h> |
| #import <XCTest/XCTest.h> |
| +#include "base/strings/stringprintf.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "components/browsing_data/core/pref_names.h" |
| #include "components/prefs/pref_service.h" |
| @@ -37,19 +38,40 @@ |
| #include "ui/base/l10n/l10n_util.h" |
| using chrome_test_util::ButtonWithAccessibilityLabelId; |
| +using chrome_test_util::WebViewContainingText; |
| namespace { |
| char kURL1[] = "http://firstURL"; |
| char kURL2[] = "http://secondURL"; |
| char kURL3[] = "http://thirdURL"; |
| -char kResponse1[] = "Test Page 1"; |
| -char kResponse2[] = "Test Page 2"; |
| -char kResponse3[] = "Test Page 3"; |
| +char kTitle1[] = "Page 1"; |
| +char kTitle2[] = "Page 2"; |
| +char kResponse1[] = "Test Page 1 content"; |
| +char kResponse2[] = "Test Page 2 content"; |
| +char kResponse3[] = "Test Page 3 content"; |
| + |
| +// Matcher for entry in history for URL and title. |
| +id<GREYMatcher> HistoryEntry(const GURL& url, const std::string& title) { |
| + NSString* url_spec_text = base::SysUTF8ToNSString(url.spec()); |
| + NSString* title_text = base::SysUTF8ToNSString(title); |
| + |
| + MatchesBlock matches = ^BOOL(HistoryEntryCell* cell) { |
| + return [cell.textLabel.text isEqual:title_text] && |
| + [cell.detailTextLabel.text isEqual:url_spec_text]; |
| + }; |
| + |
| + DescribeToBlock describe = ^(id<GREYDescription> description) { |
| + [description appendText:@"view containing URL text: "]; |
| + [description appendText:url_spec_text]; |
| + [description appendText:@" title text: "]; |
| + [description appendText:title_text]; |
| + }; |
| -// Matcher for entry in history for URL. |
| -id<GREYMatcher> HistoryEntryWithUrl(const GURL& url) { |
| - NSString* url_spec = base::SysUTF8ToNSString(url.spec()); |
| - return grey_allOf(grey_text(url_spec), grey_sufficientlyVisible(), nil); |
| + return grey_allOf(grey_kindOfClass([HistoryEntryCell class]), |
| + [[[GREYElementMatcherBlock alloc] |
| + initWithMatchesBlock:matches |
| + descriptionBlock:describe] autorelease], |
|
Eugene But (OOO till 7-30)
2017/02/07 02:47:34
Mike, I tried running this on downstream bots and
stkhapugin
2017/02/07 12:35:15
Oops, I haven't spotted this one at first. Just re
|
| + grey_sufficientlyVisible(), nil); |
| } |
| // Matcher for the history button in the tools menu. |
| id<GREYMatcher> HistoryButton() { |
| @@ -179,8 +201,12 @@ void MockSignIn() { |
| + (void)setUp { |
| [super setUp]; |
| std::map<GURL, std::string> responses; |
| - responses[web::test::HttpServer::MakeUrl(kURL1)] = kResponse1; |
| - responses[web::test::HttpServer::MakeUrl(kURL2)] = kResponse2; |
| + const char kPageFormat[] = "<head><title>%s</title></head><body>%s</body>"; |
| + responses[web::test::HttpServer::MakeUrl(kURL1)] = |
| + base::StringPrintf(kPageFormat, kTitle1, kResponse1); |
| + responses[web::test::HttpServer::MakeUrl(kURL2)] = |
| + base::StringPrintf(kPageFormat, kTitle2, kResponse2); |
| + // Page 3 does not have <title> tag, so URL will be its title. |
| responses[web::test::HttpServer::MakeUrl(kURL3)] = kResponse3; |
| web::test::SetUpSimpleHttpServer(responses); |
| } |
| @@ -228,19 +254,36 @@ void MockSignIn() { |
| [self openHistoryPanel]; |
| // Assert that history displays three entries. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| assertWithMatcher:grey_notNil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] |
| assertWithMatcher:grey_notNil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] |
| assertWithMatcher:grey_notNil()]; |
| // Tap a history entry and assert that navigation to that entry's URL occurs. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| performAction:grey_tap()]; |
| - id<GREYMatcher> webViewMatcher = |
| - chrome_test_util::WebViewContainingText(kResponse1); |
| - [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| + [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests that history is not changed after performing back navigation. |
| +// TODO(crbug.com/688047): Enable this test. |
| +- (void)DISABLED_testHistoryUpdateAfterBackNavigation { |
| + [ChromeEarlGrey loadURL:_URL1]; |
| + [ChromeEarlGrey loadURL:_URL2]; |
| + |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [self openHistoryPanel]; |
| + |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| + assertWithMatcher:grey_notNil()]; |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] |
| assertWithMatcher:grey_notNil()]; |
| } |
| @@ -273,8 +316,8 @@ void MockSignIn() { |
| selectElementWithMatcher:grey_kindOfClass([TransparentLinkButton class])] |
| performAction:grey_tap()]; |
| chrome_test_util::AssertMainTabCount(2); |
| - id<GREYMatcher> webViewMatcher = chrome_test_util::WebViewContainingText( |
| - "Sync and view tabs and history across devices"); |
| + id<GREYMatcher> webViewMatcher = |
| + WebViewContainingText("Sync and view tabs and history across devices"); |
| [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| assertWithMatcher:grey_notNil()]; |
| } |
| @@ -290,11 +333,11 @@ void MockSignIn() { |
| [NSString stringWithFormat:@"%s", _URL1.path().c_str()]; |
| [[EarlGrey selectElementWithMatcher:grey_keyWindow()] |
| performAction:grey_typeText(searchString)]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| assertWithMatcher:grey_notNil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] |
| assertWithMatcher:grey_nil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] |
| assertWithMatcher:grey_nil()]; |
| } |
| @@ -304,35 +347,35 @@ void MockSignIn() { |
| [self openHistoryPanel]; |
| // Assert that three history elements are present. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| assertWithMatcher:grey_notNil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] |
| assertWithMatcher:grey_notNil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] |
| assertWithMatcher:grey_notNil()]; |
| // Enter edit mode, select a history element, and press delete. |
| [[EarlGrey selectElementWithMatcher:NavigationEditButton()] |
| performAction:grey_tap()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| performAction:grey_tap()]; |
| [[EarlGrey selectElementWithMatcher:DeleteHistoryEntriesButton()] |
| performAction:grey_tap()]; |
| // Assert that the deleted entry is gone and the other two remain. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| assertWithMatcher:grey_nil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] |
| assertWithMatcher:grey_notNil()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] |
| assertWithMatcher:grey_notNil()]; |
| // Enter edit mode, select both remaining entries, and press delete. |
| [[EarlGrey selectElementWithMatcher:NavigationEditButton()] |
| performAction:grey_tap()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL2)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL2, kTitle2)] |
| performAction:grey_tap()]; |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL3)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL3, _URL3.GetContent())] |
| performAction:grey_tap()]; |
| [[EarlGrey selectElementWithMatcher:DeleteHistoryEntriesButton()] |
| performAction:grey_tap()]; |
| @@ -379,7 +422,7 @@ void MockSignIn() { |
| [self openHistoryPanel]; |
| // Long press on the history element. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| performAction:grey_longPress()]; |
| // Select "Open in New Tab" and confirm that new tab is opened with selected |
| @@ -399,7 +442,7 @@ void MockSignIn() { |
| [self openHistoryPanel]; |
| // Long press on the history element. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| performAction:grey_longPress()]; |
| // Select "Open in New Incognito Tab" and confirm that new tab is opened in |
| @@ -426,7 +469,7 @@ void MockSignIn() { |
| [self openHistoryPanel]; |
| // Long press on the history element. |
| - [[EarlGrey selectElementWithMatcher:HistoryEntryWithUrl(_URL1)] |
| + [[EarlGrey selectElementWithMatcher:HistoryEntry(_URL1, kTitle1)] |
| performAction:grey_longPress()]; |
| // Tap "Copy URL" and wait for the URL to be copied to the pasteboard. |
| @@ -456,21 +499,15 @@ void MockSignIn() { |
| - (void)loadTestURLs { |
| [ChromeEarlGrey loadURL:_URL1]; |
| - id<GREYMatcher> response1Matcher = |
| - chrome_test_util::WebViewContainingText(kResponse1); |
| - [[EarlGrey selectElementWithMatcher:response1Matcher] |
| + [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse1)] |
| assertWithMatcher:grey_notNil()]; |
| [ChromeEarlGrey loadURL:_URL2]; |
| - id<GREYMatcher> response2Matcher = |
| - chrome_test_util::WebViewContainingText(kResponse2); |
| - [[EarlGrey selectElementWithMatcher:response2Matcher] |
| + [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse2)] |
| assertWithMatcher:grey_notNil()]; |
| [ChromeEarlGrey loadURL:_URL3]; |
| - id<GREYMatcher> response3Matcher = |
| - chrome_test_util::WebViewContainingText(kResponse3); |
| - [[EarlGrey selectElementWithMatcher:response3Matcher] |
| + [[EarlGrey selectElementWithMatcher:WebViewContainingText(kResponse3)] |
| assertWithMatcher:grey_notNil()]; |
| } |