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/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" |
| 11 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
| 12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
| 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 14 #include "ios/chrome/browser/chrome_url_constants.h" | |
| 15 #import "ios/chrome/browser/ui/history/history_entries_status_item.h" | |
| 14 #import "ios/chrome/browser/ui/history/history_entry_item.h" | 16 #import "ios/chrome/browser/ui/history/history_entry_item.h" |
| 15 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont roller.h" | 17 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont roller.h" |
| 18 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" | |
| 19 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" | |
| 20 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | |
| 21 #import "ios/chrome/browser/ui/util/transparent_link_button.h" | |
| 22 #include "ios/chrome/common/string_util.h" | |
| 16 #include "ios/chrome/grit/ios_strings.h" | 23 #include "ios/chrome/grit/ios_strings.h" |
| 17 #import "ios/chrome/test/app/chrome_test_util.h" | 24 #import "ios/chrome/test/app/chrome_test_util.h" |
| 18 #import "ios/chrome/test/earl_grey/accessibility_util.h" | 25 #import "ios/chrome/test/earl_grey/accessibility_util.h" |
| 19 #import "ios/chrome/test/earl_grey/chrome_assertions.h" | 26 #import "ios/chrome/test/earl_grey/chrome_assertions.h" |
| 20 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 27 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 21 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 28 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 29 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 23 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 30 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 31 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | |
| 32 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | |
| 33 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" | |
| 24 #import "ios/testing/wait_util.h" | 34 #import "ios/testing/wait_util.h" |
| 25 #import "ios/web/public/test/http_server.h" | 35 #import "ios/web/public/test/http_server.h" |
| 26 #import "ios/web/public/test/http_server_util.h" | 36 #import "ios/web/public/test/http_server_util.h" |
| 27 #import "net/base/mac/url_conversions.h" | 37 #import "net/base/mac/url_conversions.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 29 | 39 |
| 30 using chrome_test_util::buttonWithAccessibilityLabelId; | 40 using chrome_test_util::buttonWithAccessibilityLabelId; |
| 31 | 41 |
| 32 namespace { | 42 namespace { |
| 33 char kURL1[] = "http://firstURL"; | 43 char kURL1[] = "http://firstURL"; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 // Matcher for the clear cache cell on the clear browsing data panel. | 110 // Matcher for the clear cache cell on the clear browsing data panel. |
| 101 id<GREYMatcher> clearCacheButton() { | 111 id<GREYMatcher> clearCacheButton() { |
| 102 return grey_allOf(grey_accessibilityID(kClearCacheCellId), | 112 return grey_allOf(grey_accessibilityID(kClearCacheCellId), |
| 103 grey_sufficientlyVisible(), nil); | 113 grey_sufficientlyVisible(), nil); |
| 104 } | 114 } |
| 105 // Matcher for the clear browsing data button on the clear browsing data panel. | 115 // Matcher for the clear browsing data button on the clear browsing data panel. |
| 106 id<GREYMatcher> clearBrowsingDataButton() { | 116 id<GREYMatcher> clearBrowsingDataButton() { |
| 107 return buttonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); | 117 return buttonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); |
| 108 } | 118 } |
| 109 | 119 |
| 120 void SignIn() { | |
|
baxley
2016/12/22 17:58:37
Could you add a comment?
What do you think about
Jackie Quinn
2016/12/22 20:09:13
Works for me. Done.
| |
| 121 // Set up a fake identity. | |
| 122 ChromeIdentity* identity = | |
| 123 [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" | |
| 124 gaiaID:@"fooID" | |
| 125 name:@"Fake Foo"]; | |
| 126 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | |
| 127 identity); | |
| 128 | |
| 129 const CGFloat scroll_displacement = 50.0; | |
|
baxley
2016/12/22 17:58:37
Is reliable on phones and iPads?
Sergio fixed som
Jackie Quinn
2016/12/22 20:09:13
Oh yeah that seems to be a better solution! Update
| |
| 130 [ChromeEarlGreyUI openToolsMenu]; | |
| 131 [[[EarlGrey | |
| 132 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] | |
| 133 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, | |
| 134 scroll_displacement) | |
| 135 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] | |
| 136 performAction:grey_tap()]; | |
| 137 | |
| 138 [[EarlGrey | |
| 139 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] | |
| 140 performAction:grey_tap()]; | |
| 141 [[EarlGrey | |
| 142 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabel( | |
| 143 identity.userEmail)] | |
| 144 performAction:grey_tap()]; | |
| 145 [[EarlGrey selectElementWithMatcher: | |
| 146 chrome_test_util::buttonWithAccessibilityLabelId( | |
| 147 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON)] | |
| 148 performAction:grey_tap()]; | |
| 149 [[EarlGrey selectElementWithMatcher: | |
| 150 chrome_test_util::buttonWithAccessibilityLabelId( | |
| 151 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON)] | |
| 152 performAction:grey_tap()]; | |
| 153 [[EarlGrey | |
| 154 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( | |
| 155 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] | |
| 156 performAction:grey_tap()]; | |
| 157 } | |
| 110 } // namespace | 158 } // namespace |
| 111 | 159 |
| 112 // History UI tests. | 160 // History UI tests. |
| 113 @interface HistoryUITestCase : ChromeTestCase { | 161 @interface AAAHistoryUITestCase : ChromeTestCase { |
|
baxley
2016/12/22 17:58:37
What you think your special and can make your test
Jackie Quinn
2016/12/22 20:09:13
Isn't history our most important feature? Done.
baxley
2016/12/22 22:35:32
By the way, you should have totally called me out
Jackie Quinn
2016/12/22 22:45:14
Dang, missed opportunity 🙃
| |
| 114 GURL _URL1; | 162 GURL _URL1; |
| 115 GURL _URL2; | 163 GURL _URL2; |
| 116 GURL _URL3; | 164 GURL _URL3; |
| 117 } | 165 } |
| 118 | 166 |
| 119 // Loads three test URLs. | 167 // Loads three test URLs. |
| 120 - (void)loadTestURLs; | 168 - (void)loadTestURLs; |
| 121 // Displays the history UI. | 169 // Displays the history UI. |
| 122 - (void)openHistoryPanel; | 170 - (void)openHistoryPanel; |
| 123 // Asserts that the history UI displays no history entries. | 171 // Asserts that the history UI displays no history entries. |
| 124 - (void)assertNoHistoryShown; | 172 - (void)assertNoHistoryShown; |
| 125 // Resets which data is selected in the Clear Browsing Data UI. | 173 // Resets which data is selected in the Clear Browsing Data UI. |
| 126 - (void)resetBrowsingDataPrefs; | 174 - (void)resetBrowsingDataPrefs; |
| 127 | 175 |
| 128 @end | 176 @end |
| 129 | 177 |
| 130 @implementation HistoryUITestCase | 178 @implementation AAAHistoryUITestCase |
| 131 | 179 |
| 132 // Set up called once for the class. | 180 // Set up called once for the class. |
| 133 + (void)setUp { | 181 + (void)setUp { |
| 134 [super setUp]; | 182 [super setUp]; |
| 135 std::map<GURL, std::string> responses; | 183 std::map<GURL, std::string> responses; |
| 136 responses[web::test::HttpServer::MakeUrl(kURL1)] = kResponse1; | 184 responses[web::test::HttpServer::MakeUrl(kURL1)] = kResponse1; |
| 137 responses[web::test::HttpServer::MakeUrl(kURL2)] = kResponse2; | 185 responses[web::test::HttpServer::MakeUrl(kURL2)] = kResponse2; |
| 138 responses[web::test::HttpServer::MakeUrl(kURL3)] = kResponse3; | 186 responses[web::test::HttpServer::MakeUrl(kURL3)] = kResponse3; |
| 139 web::test::SetUpSimpleHttpServer(responses); | 187 web::test::SetUpSimpleHttpServer(responses); |
| 140 } | 188 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 239 |
| 192 // Tap a history entry and assert that navigation to that entry's URL occurs. | 240 // Tap a history entry and assert that navigation to that entry's URL occurs. |
| 193 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] | 241 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] |
| 194 performAction:grey_tap()]; | 242 performAction:grey_tap()]; |
| 195 id<GREYMatcher> webViewMatcher = | 243 id<GREYMatcher> webViewMatcher = |
| 196 chrome_test_util::webViewContainingText(kResponse1); | 244 chrome_test_util::webViewContainingText(kResponse1); |
| 197 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 245 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 198 assertWithMatcher:grey_notNil()]; | 246 assertWithMatcher:grey_notNil()]; |
| 199 } | 247 } |
| 200 | 248 |
| 249 // Test that history displays a message about entries only if the user is logged | |
| 250 // in, and that tapping on the link in the message opens a new tab with the sync | |
| 251 // help page. | |
| 252 - (void)testHistoryEntriesStatusCell { | |
| 253 [self loadTestURLs]; | |
| 254 [self openHistoryPanel]; | |
| 255 // Assert that no message is shown when the user is not signed in. | |
| 256 GREYElementMatcherBlock* emptyEntriesItemMatcher = | |
| 257 [GREYElementMatcherBlock matcherWithMatchesBlock:^BOOL(id element) { | |
| 258 HistoryEntriesStatusCell* cell = (HistoryEntriesStatusCell*)element; | |
|
baxley
2016/12/22 17:58:37
ObjCCast ?
Jackie Quinn
2016/12/22 20:09:13
Done.
| |
| 259 return !cell.textLabel.text; | |
| 260 } | |
| 261 descriptionBlock:^void(id<GREYDescription> description) { | |
| 262 [description | |
| 263 appendText:@"HistoryEntriesStatusCell does not display text"]; | |
| 264 }]; | |
| 265 [[EarlGrey selectElementWithMatcher:grey_kindOfClass( | |
| 266 [HistoryEntriesStatusCell class])] | |
| 267 assertWithMatcher:emptyEntriesItemMatcher]; | |
|
baxley
2016/12/22 17:58:37
Do we need to know about the class type? we can't
Jackie Quinn
2016/12/22 20:09:13
Well, I could wait for the text I look for below t
| |
| 268 [[EarlGrey selectElementWithMatcher:navigationDoneButton()] | |
| 269 performAction:grey_tap()]; | |
| 270 | |
| 271 // Sign in and assert that the page indicates what type of history entries | |
| 272 // are shown. | |
| 273 SignIn(); | |
| 274 [self openHistoryPanel]; | |
| 275 // Assert that message about entries is shown. The "history is showing local | |
| 276 // entries" message will be shown because sync is not set up for this test. | |
| 277 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS); | |
| 278 NSRange range; | |
| 279 NSString* text = ParseStringWithLink( | |
| 280 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS), &range); | |
| 281 [[EarlGrey selectElementWithMatcher:grey_text(text)] | |
| 282 assertWithMatcher:grey_notNil()]; | |
| 283 | |
| 284 // Tap on "Learn more" link and assert that new tab with the link is opened. | |
| 285 [[EarlGrey | |
| 286 selectElementWithMatcher:grey_kindOfClass([TransparentLinkButton class])] | |
|
baxley
2016/12/22 17:58:37
Is there anything we can use to match the link, ot
Jackie Quinn
2016/12/22 20:09:13
I don't think so... I could look for the first UI
| |
| 287 performAction:grey_tap()]; | |
| 288 chrome_test_util::AssertMainTabCount(2); | |
| 289 id<GREYMatcher> webViewMatcher = chrome_test_util::webViewContainingText( | |
| 290 "Sync and view tabs and history across devices"); | |
| 291 [[EarlGrey selectElementWithMatcher:webViewMatcher] | |
| 292 assertWithMatcher:grey_notNil()]; | |
|
baxley
2016/12/22 17:58:37
Are the signed in accounts removed at the end of t
Jackie Quinn
2016/12/22 20:09:13
Yes, disabling mock auth is run at the end of all
| |
| 293 } | |
| 294 | |
| 201 // Tests that searching history displays only entries matching the search term. | 295 // Tests that searching history displays only entries matching the search term. |
| 202 - (void)testSearchHistory { | 296 - (void)testSearchHistory { |
| 203 [self loadTestURLs]; | 297 [self loadTestURLs]; |
| 204 [self openHistoryPanel]; | 298 [self openHistoryPanel]; |
| 205 [[EarlGrey selectElementWithMatcher:searchIconButton()] | 299 [[EarlGrey selectElementWithMatcher:searchIconButton()] |
| 206 performAction:grey_tap()]; | 300 performAction:grey_tap()]; |
| 207 | 301 |
| 208 NSString* searchString = | 302 NSString* searchString = |
| 209 [NSString stringWithFormat:@"%s", _URL1.path().c_str()]; | 303 [NSString stringWithFormat:@"%s", _URL1.path().c_str()]; |
| 210 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] | 304 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 - (void)resetBrowsingDataPrefs { | 510 - (void)resetBrowsingDataPrefs { |
| 417 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); | 511 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); |
| 418 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); | 512 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); |
| 419 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); | 513 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); |
| 420 prefs->ClearPref(browsing_data::prefs::kDeleteCache); | 514 prefs->ClearPref(browsing_data::prefs::kDeleteCache); |
| 421 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); | 515 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); |
| 422 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); | 516 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); |
| 423 } | 517 } |
| 424 | 518 |
| 425 @end | 519 @end |
| OLD | NEW |