| 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" |
| 14 #import "ios/chrome/browser/ui/history/history_entry_item.h" | 15 #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" | 16 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont
roller.h" |
| 17 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" |
| 18 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" |
| 19 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 20 #import "ios/chrome/browser/ui/util/transparent_link_button.h" |
| 21 #include "ios/chrome/common/string_util.h" |
| 16 #include "ios/chrome/grit/ios_strings.h" | 22 #include "ios/chrome/grit/ios_strings.h" |
| 17 #import "ios/chrome/test/app/chrome_test_util.h" | 23 #import "ios/chrome/test/app/chrome_test_util.h" |
| 18 #import "ios/chrome/test/earl_grey/accessibility_util.h" | 24 #import "ios/chrome/test/earl_grey/accessibility_util.h" |
| 19 #import "ios/chrome/test/earl_grey/chrome_assertions.h" | 25 #import "ios/chrome/test/earl_grey/chrome_assertions.h" |
| 20 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 26 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 21 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 27 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 23 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 30 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
| 31 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
| 32 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
| 24 #import "ios/testing/wait_util.h" | 33 #import "ios/testing/wait_util.h" |
| 25 #import "ios/web/public/test/http_server.h" | 34 #import "ios/web/public/test/http_server.h" |
| 26 #import "ios/web/public/test/http_server_util.h" | 35 #import "ios/web/public/test/http_server_util.h" |
| 27 #import "net/base/mac/url_conversions.h" | 36 #import "net/base/mac/url_conversions.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 29 | 38 |
| 30 using chrome_test_util::buttonWithAccessibilityLabelId; | 39 using chrome_test_util::buttonWithAccessibilityLabelId; |
| 31 | 40 |
| 32 namespace { | 41 namespace { |
| 33 char kURL1[] = "http://firstURL"; | 42 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. | 109 // Matcher for the clear cache cell on the clear browsing data panel. |
| 101 id<GREYMatcher> clearCacheButton() { | 110 id<GREYMatcher> clearCacheButton() { |
| 102 return grey_allOf(grey_accessibilityID(kClearCacheCellId), | 111 return grey_allOf(grey_accessibilityID(kClearCacheCellId), |
| 103 grey_sufficientlyVisible(), nil); | 112 grey_sufficientlyVisible(), nil); |
| 104 } | 113 } |
| 105 // Matcher for the clear browsing data button on the clear browsing data panel. | 114 // Matcher for the clear browsing data button on the clear browsing data panel. |
| 106 id<GREYMatcher> clearBrowsingDataButton() { | 115 id<GREYMatcher> clearBrowsingDataButton() { |
| 107 return buttonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); | 116 return buttonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON); |
| 108 } | 117 } |
| 109 | 118 |
| 119 // Sign in with a mock identity. |
| 120 void MockSignIn() { |
| 121 // Set up a mock 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 [ChromeEarlGreyUI openToolsMenu]; |
| 130 [[[EarlGrey |
| 131 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] |
| 132 usingSearchAction:grey_scrollToContentEdge(kGREYContentEdgeBottom) |
| 133 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] |
| 134 performAction:grey_tap()]; |
| 135 |
| 136 [[EarlGrey |
| 137 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] |
| 138 performAction:grey_tap()]; |
| 139 [[EarlGrey |
| 140 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabel( |
| 141 identity.userEmail)] |
| 142 performAction:grey_tap()]; |
| 143 [[EarlGrey selectElementWithMatcher: |
| 144 chrome_test_util::buttonWithAccessibilityLabelId( |
| 145 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON)] |
| 146 performAction:grey_tap()]; |
| 147 [[EarlGrey selectElementWithMatcher: |
| 148 chrome_test_util::buttonWithAccessibilityLabelId( |
| 149 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON)] |
| 150 performAction:grey_tap()]; |
| 151 [[EarlGrey |
| 152 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( |
| 153 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] |
| 154 performAction:grey_tap()]; |
| 155 } |
| 110 } // namespace | 156 } // namespace |
| 111 | 157 |
| 112 // History UI tests. | 158 // History UI tests. |
| 113 @interface HistoryUITestCase : ChromeTestCase { | 159 @interface HistoryUITestCase : ChromeTestCase { |
| 114 GURL _URL1; | 160 GURL _URL1; |
| 115 GURL _URL2; | 161 GURL _URL2; |
| 116 GURL _URL3; | 162 GURL _URL3; |
| 117 } | 163 } |
| 118 | 164 |
| 119 // Loads three test URLs. | 165 // Loads three test URLs. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 237 |
| 192 // Tap a history entry and assert that navigation to that entry's URL occurs. | 238 // Tap a history entry and assert that navigation to that entry's URL occurs. |
| 193 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] | 239 [[EarlGrey selectElementWithMatcher:historyEntryWithURL(_URL1)] |
| 194 performAction:grey_tap()]; | 240 performAction:grey_tap()]; |
| 195 id<GREYMatcher> webViewMatcher = | 241 id<GREYMatcher> webViewMatcher = |
| 196 chrome_test_util::webViewContainingText(kResponse1); | 242 chrome_test_util::webViewContainingText(kResponse1); |
| 197 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 243 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 198 assertWithMatcher:grey_notNil()]; | 244 assertWithMatcher:grey_notNil()]; |
| 199 } | 245 } |
| 200 | 246 |
| 247 // Test that history displays a message about entries only if the user is logged |
| 248 // in, and that tapping on the link in the message opens a new tab with the sync |
| 249 // help page. |
| 250 - (void)testHistoryEntriesStatusCell { |
| 251 [self loadTestURLs]; |
| 252 [self openHistoryPanel]; |
| 253 // Assert that no message is shown when the user is not signed in. |
| 254 NSRange range; |
| 255 NSString* entriesMessage = ParseStringWithLink( |
| 256 l10n_util::GetNSString(IDS_IOS_HISTORY_NO_SYNCED_RESULTS), &range); |
| 257 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)] |
| 258 assertWithMatcher:grey_nil()]; |
| 259 [[EarlGrey selectElementWithMatcher:navigationDoneButton()] |
| 260 performAction:grey_tap()]; |
| 261 |
| 262 // Sign in and assert that the page indicates what type of history entries |
| 263 // are shown. |
| 264 MockSignIn(); |
| 265 [self openHistoryPanel]; |
| 266 // Assert that message about entries is shown. The "history is showing local |
| 267 // entries" message will be shown because sync is not set up for this test. |
| 268 [[EarlGrey selectElementWithMatcher:grey_text(entriesMessage)] |
| 269 assertWithMatcher:grey_notNil()]; |
| 270 |
| 271 // Tap on "Learn more" link and assert that new tab with the link is opened. |
| 272 [[EarlGrey |
| 273 selectElementWithMatcher:grey_kindOfClass([TransparentLinkButton class])] |
| 274 performAction:grey_tap()]; |
| 275 chrome_test_util::AssertMainTabCount(2); |
| 276 id<GREYMatcher> webViewMatcher = chrome_test_util::webViewContainingText( |
| 277 "Sync and view tabs and history across devices"); |
| 278 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 279 assertWithMatcher:grey_notNil()]; |
| 280 } |
| 281 |
| 201 // Tests that searching history displays only entries matching the search term. | 282 // Tests that searching history displays only entries matching the search term. |
| 202 - (void)testSearchHistory { | 283 - (void)testSearchHistory { |
| 203 [self loadTestURLs]; | 284 [self loadTestURLs]; |
| 204 [self openHistoryPanel]; | 285 [self openHistoryPanel]; |
| 205 [[EarlGrey selectElementWithMatcher:searchIconButton()] | 286 [[EarlGrey selectElementWithMatcher:searchIconButton()] |
| 206 performAction:grey_tap()]; | 287 performAction:grey_tap()]; |
| 207 | 288 |
| 208 NSString* searchString = | 289 NSString* searchString = |
| 209 [NSString stringWithFormat:@"%s", _URL1.path().c_str()]; | 290 [NSString stringWithFormat:@"%s", _URL1.path().c_str()]; |
| 210 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] | 291 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 - (void)resetBrowsingDataPrefs { | 497 - (void)resetBrowsingDataPrefs { |
| 417 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); | 498 PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs(); |
| 418 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); | 499 prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory); |
| 419 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); | 500 prefs->ClearPref(browsing_data::prefs::kDeleteCookies); |
| 420 prefs->ClearPref(browsing_data::prefs::kDeleteCache); | 501 prefs->ClearPref(browsing_data::prefs::kDeleteCache); |
| 421 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); | 502 prefs->ClearPref(browsing_data::prefs::kDeletePasswords); |
| 422 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); | 503 prefs->ClearPref(browsing_data::prefs::kDeleteFormData); |
| 423 } | 504 } |
| 424 | 505 |
| 425 @end | 506 @end |
| OLD | NEW |