Commit 24a54bf4 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Move Clear Browsing EGTest logic to ChromeEarlGreyUI so it can be shared

Change-Id: Iccb6078d9dba025791424a6fe1c49e1cc98c7652
Reviewed-on: https://chromium-review.googlesource.com/1171787
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582604}
parent cd0fab86
......@@ -129,19 +129,11 @@ id<GREYMatcher> SearchIconButton() {
id<GREYMatcher> CancelButton() {
return grey_accessibilityID(kHistoryToolbarCancelButtonIdentifier);
}
// Matcher for the button to open the clear browsing data panel.
id<GREYMatcher> OpenClearBrowsingDataButton() {
return grey_accessibilityID(kHistoryToolbarClearBrowsingButtonIdentifier);
}
// Matcher for the Open in New Incognito Tab option in the context menu.
id<GREYMatcher> OpenInNewIncognitoTabButton() {
return ButtonWithAccessibilityLabelId(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB);
}
// Matcher for the clear browsing data button on the clear browsing data panel.
id<GREYMatcher> ClearBrowsingDataButton() {
return ButtonWithAccessibilityLabelId(IDS_IOS_CLEAR_BUTTON);
}
} // namespace
......@@ -156,8 +148,6 @@ id<GREYMatcher> ClearBrowsingDataButton() {
- (void)loadTestURLs;
// Displays the history UI.
- (void)openHistoryPanel;
// Asserts that the history UI displays no history entries.
- (void)assertNoHistoryShown;
// Resets which data is selected in the Clear Browsing Data UI.
- (void)resetBrowsingDataPrefs;
......@@ -213,7 +203,7 @@ id<GREYMatcher> ClearBrowsingDataButton() {
// Tests that no history is shown if there has been no navigation.
- (void)testDisplayNoHistory {
[self openHistoryPanel];
[self assertNoHistoryShown];
[ChromeEarlGreyUI assertHistoryHasNoEntries];
}
// Tests that the history panel displays navigation history.
......@@ -321,7 +311,7 @@ id<GREYMatcher> ClearBrowsingDataButton() {
[[EarlGrey selectElementWithMatcher:DeleteHistoryEntriesButton()]
performAction:grey_tap()];
[self assertNoHistoryShown];
[ChromeEarlGreyUI assertHistoryHasNoEntries];
}
// Tests clear browsing history.
......@@ -329,31 +319,8 @@ id<GREYMatcher> ClearBrowsingDataButton() {
[self loadTestURLs];
[self openHistoryPanel];
// Open the Clear Browsing Data dialog.
[[EarlGrey selectElementWithMatcher:OpenClearBrowsingDataButton()]
performAction:grey_tap()];
// Uncheck "Cookies, Site Data" and "Cached Images and Files," which are
// checked by default, and press "Clear Browsing Data"
[[EarlGrey selectElementWithMatcher:chrome_test_util::ClearCookiesButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::ClearCacheButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:ClearBrowsingDataButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
ConfirmClearBrowsingDataButton()]
performAction:grey_tap()];
// Include sufficientlyVisible condition for the case of the clear browsing
// dialog, which also has a "Done" button and is displayed over the history
// panel.
id<GREYMatcher> visibleDoneButton = grey_allOf(
chrome_test_util::SettingsDoneButton(), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:visibleDoneButton]
performAction:grey_tap()];
[self assertNoHistoryShown];
[ChromeEarlGreyUI openAndClearBrowsingDataFromHistory];
[ChromeEarlGreyUI assertHistoryHasNoEntries];
}
// Tests display and selection of 'Open in New Tab' in a context menu on a
......@@ -459,28 +426,6 @@ id<GREYMatcher> ClearBrowsingDataButton() {
[ChromeEarlGreyUI tapToolsMenuButton:HistoryButton()];
}
- (void)assertNoHistoryShown {
id<GREYMatcher> noHistoryMessageMatcher =
grey_allOf(grey_text(l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS)),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:noHistoryMessageMatcher]
assertWithMatcher:grey_notNil()];
if (IsUIRefreshPhase1Enabled()) {
id<GREYMatcher> historyEntryMatcher =
grey_allOf(grey_kindOfClass([TableViewURLCell class]),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:historyEntryMatcher]
assertWithMatcher:grey_nil()];
} else {
id<GREYMatcher> historyEntryMatcher =
grey_allOf(grey_kindOfClass([LegacyHistoryEntryCell class]),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:historyEntryMatcher]
assertWithMatcher:grey_nil()];
}
}
- (void)resetBrowsingDataPrefs {
PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs();
prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory);
......
......@@ -243,6 +243,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/commands:commands",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
"//ios/chrome/browser/ui/history:history_ui",
"//ios/chrome/browser/ui/location_bar:location_bar",
"//ios/chrome/browser/ui/omnibox:omnibox_internal",
"//ios/chrome/browser/ui/payments:payments_ui",
......@@ -250,6 +251,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/settings:settings",
"//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/static_content",
"//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/ui/toolbar/buttons",
"//ios/chrome/browser/ui/toolbar/legacy",
"//ios/chrome/browser/ui/toolbar/public",
......
......@@ -58,6 +58,12 @@
// Open a new incognito tab via the tools menu.
+ (void)openNewIncognitoTab;
// Open and clear browsing data from history.
+ (void)openAndClearBrowsingDataFromHistory;
// Assert that history is empty.
+ (void)assertHistoryHasNoEntries;
// Reloads the page via the reload button, and does not wait for the page to
// finish loading.
+ (void)reload;
......
......@@ -6,9 +6,12 @@
#import "base/test/ios/wait_util.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/history/history_ui_constants.h"
#import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_ui_constants.h"
#import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_url_item.h"
#import "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h"
#import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
......@@ -18,6 +21,7 @@
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/web/public/test/earl_grey/js_test_util.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -88,6 +92,49 @@ id<GREYAction> ScrollDown() {
performAction:grey_tap()];
}
+ (void)openAndClearBrowsingDataFromHistory {
// Open Clear Browsing Data Button
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kHistoryToolbarClearBrowsingButtonIdentifier)]
performAction:grey_tap()];
// Uncheck "Cookies, Site Data" and "Cached Images and Files," which are
// checked by default, and press "Clear Browsing Data"
[[EarlGrey selectElementWithMatcher:chrome_test_util::ClearCookiesButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::ClearCacheButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kClearBrowsingDataButtonIdentifier)]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
ConfirmClearBrowsingDataButton()]
performAction:grey_tap()];
// Include sufficientlyVisible condition for the case of the clear browsing
// dialog, which also has a "Done" button and is displayed over the history
// panel.
id<GREYMatcher> visibleDoneButton = grey_allOf(
chrome_test_util::SettingsDoneButton(), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:visibleDoneButton]
performAction:grey_tap()];
}
+ (void)assertHistoryHasNoEntries {
id<GREYMatcher> noHistoryMessageMatcher =
grey_allOf(grey_text(l10n_util::GetNSString(IDS_HISTORY_NO_RESULTS)),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:noHistoryMessageMatcher]
assertWithMatcher:grey_notNil()];
id<GREYMatcher> historyEntryMatcher =
grey_allOf(grey_kindOfClass([TableViewURLCell class]),
grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:historyEntryMatcher]
assertWithMatcher:grey_nil()];
}
+ (void)tapPrivacyMenuButton:(id<GREYMatcher>)buttonMatcher {
id<GREYMatcher> interactableButtonMatcher =
grey_allOf(buttonMatcher, grey_interactable(), nil);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment