Commit f44820a3 authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS][CloseAllTabs] Fixes EG2 tests

This CL fixes tests impacted by the EnableCloseAllTabsConfirmation
feature before submitting the config.
It also moves the Confirmation action sheet logic in the button
selector, in order to have the possibility to disable the feature
after the TabGrid initialisation.

Bug: 1119319
Change-Id: I63dc293c538efbe5a3c38c52a41db9ee1a8cde96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526345Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827259}
parent ba09493f
...@@ -98,11 +98,6 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -98,11 +98,6 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
- (AppLaunchConfiguration)appConfigurationForTestCase { - (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config; AppLaunchConfiguration config;
config.features_enabled.push_back(safe_browsing::kRealTimeUrlLookupEnabled); config.features_enabled.push_back(safe_browsing::kRealTimeUrlLookupEnabled);
// EnableCloseAllTabsConfirmation feature is disabled in order to be able to
// restore session from |triggerRestoreViaTabGridRemoveAllUndo|.
// TODO(crbug.com/1146391): Remove dependency on
// kEnableCloseAllTabsConfirmation flag.
config.features_disabled.push_back(kEnableCloseAllTabsConfirmation);
// Use commandline args to insert fake unsafe URLs into the Safe Browsing // Use commandline args to insert fake unsafe URLs into the Safe Browsing
// database. // database.
......
...@@ -123,12 +123,6 @@ class UserAgentResponseProvider : public web::DataResponseProvider { ...@@ -123,12 +123,6 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
@implementation RequestDesktopMobileSiteTestCase @implementation RequestDesktopMobileSiteTestCase
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
config.features_disabled.push_back(kEnableCloseAllTabsConfirmation);
return config;
}
#pragma mark - Helpers #pragma mark - Helpers
- (GREYElementInteraction*)defaultRequestButton { - (GREYElementInteraction*)defaultRequestButton {
...@@ -201,15 +195,7 @@ class UserAgentResponseProvider : public web::DataResponseProvider { ...@@ -201,15 +195,7 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
timeout:kWaitForUserAgentChangeTimeout]; timeout:kWaitForUserAgentChangeTimeout];
// Close all tabs and undo, trigerring a restoration. // Close all tabs and undo, trigerring a restoration.
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [ChromeEarlGrey triggerRestoreViaTabGridRemoveAllUndo];
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()]
performAction:grey_tap()];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::TabGridUndoCloseAllButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCellAtIndex(0)]
performAction:grey_tap()];
// Verify that desktop user agent propagates. // Verify that desktop user agent propagates.
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
......
...@@ -53,22 +53,6 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs( ...@@ -53,22 +53,6 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs(
@implementation TabGridTestCase @implementation TabGridTestCase
- (AppLaunchConfiguration)appConfigurationForTestCase {
AppLaunchConfiguration config;
// Features are enabled or disabled based on the name of the test that is
// running. This is done because it is inefficient to use
// ensureAppLaunchedWithConfiguration for each test.
if ([self isRunningTest:@selector(testCloseAllAndUndoCloseAll)] ||
[self isRunningTest:@selector
(testUndoCloseAllNotAvailableAfterNewTabCreation)]) {
config.features_disabled.push_back(kEnableCloseAllTabsConfirmation);
} else {
config.features_enabled.push_back(kEnableCloseAllTabsConfirmation);
}
return config;
}
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
...@@ -120,6 +104,11 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs( ...@@ -120,6 +104,11 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs(
// Tests that tapping Close All shows no tabs, shows Undo button, and displays // Tests that tapping Close All shows no tabs, shows Undo button, and displays
// the empty state. Then tests tapping Undo shows Close All button again. // the empty state. Then tests tapping Undo shows Close All button again.
- (void)testCloseAllAndUndoCloseAll { - (void)testCloseAllAndUndoCloseAll {
if ([ChromeEarlGrey isCloseAllTabsConfirmationEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Close All Tabs Confirmation feature flag is on.");
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()]
...@@ -146,6 +135,11 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs( ...@@ -146,6 +135,11 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs(
// Tests that the Undo button is no longer available after tapping Close All, // Tests that the Undo button is no longer available after tapping Close All,
// then creating a new tab, then coming back to the tab grid. // then creating a new tab, then coming back to the tab grid.
- (void)testUndoCloseAllNotAvailableAfterNewTabCreation { - (void)testUndoCloseAllNotAvailableAfterNewTabCreation {
if ([ChromeEarlGrey isCloseAllTabsConfirmationEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Close All Tabs Confirmation feature flag is on.");
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridCloseAllButton()]
...@@ -238,6 +232,11 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs( ...@@ -238,6 +232,11 @@ id<GREYMatcher> CloseAllTabsConfirmationWithNumberOfTabs(
// It also tests that tapping on "Close x Tab(s)" on the confirmation dialog // It also tests that tapping on "Close x Tab(s)" on the confirmation dialog
// displays an empty grid and tapping on "Cancel" doesn't modify the grid. // displays an empty grid and tapping on "Cancel" doesn't modify the grid.
- (void)testCloseAllTabsConfirmation { - (void)testCloseAllTabsConfirmation {
if (![ChromeEarlGrey isCloseAllTabsConfirmationEnabled]) {
EARL_GREY_TEST_SKIPPED(
@"Test disabled when Close All Tabs Confirmation feature flag is off.");
}
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
performAction:grey_tap()]; performAction:grey_tap()];
......
...@@ -870,12 +870,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -870,12 +870,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
topToolbar.leadingButton.title = topToolbar.leadingButton.title =
l10n_util::GetNSString(IDS_IOS_TAB_GRID_CLOSE_ALL_BUTTON); l10n_util::GetNSString(IDS_IOS_TAB_GRID_CLOSE_ALL_BUTTON);
topToolbar.leadingButton.target = self; topToolbar.leadingButton.target = self;
if (IsCloseAllTabsConfirmationEnabled()) { topToolbar.leadingButton.action = @selector(closeAllButtonTapped:);
topToolbar.leadingButton.action =
@selector(closeAllButtonTappedShowConfirmation);
} else {
topToolbar.leadingButton.action = @selector(closeAllButtonTapped:);
}
topToolbar.trailingButton.title = topToolbar.trailingButton.title =
l10n_util::GetNSString(IDS_IOS_TAB_GRID_DONE_BUTTON); l10n_util::GetNSString(IDS_IOS_TAB_GRID_DONE_BUTTON);
topToolbar.trailingButton.accessibilityIdentifier = topToolbar.trailingButton.accessibilityIdentifier =
...@@ -914,12 +909,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -914,12 +909,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
]]; ]];
bottomToolbar.leadingButton.target = self; bottomToolbar.leadingButton.target = self;
if (IsCloseAllTabsConfirmationEnabled()) {
bottomToolbar.leadingButton.action =
@selector(closeAllButtonTappedShowConfirmation);
} else {
bottomToolbar.leadingButton.action = @selector(closeAllButtonTapped:); bottomToolbar.leadingButton.action = @selector(closeAllButtonTapped:);
}
bottomToolbar.trailingButton.title = bottomToolbar.trailingButton.title =
l10n_util::GetNSString(IDS_IOS_TAB_GRID_DONE_BUTTON); l10n_util::GetNSString(IDS_IOS_TAB_GRID_DONE_BUTTON);
bottomToolbar.trailingButton.accessibilityIdentifier = bottomToolbar.trailingButton.accessibilityIdentifier =
...@@ -1435,6 +1425,10 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -1435,6 +1425,10 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
} }
- (void)closeAllButtonTapped:(id)sender { - (void)closeAllButtonTapped:(id)sender {
if (IsCloseAllTabsConfirmationEnabled()) {
[self closeAllButtonTappedShowConfirmation];
return;
}
switch (self.currentPage) { switch (self.currentPage) {
case TabGridPageIncognitoTabs: case TabGridPageIncognitoTabs:
[self.incognitoTabsDelegate closeAllItems]; [self.incognitoTabsDelegate closeAllItems];
......
...@@ -579,6 +579,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -579,6 +579,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
} }
- (void)triggerRestoreViaTabGridRemoveAllUndo { - (void)triggerRestoreViaTabGridRemoveAllUndo {
[ChromeEarlGreyAppInterface disableCloseAllTabsConfirmation];
[ChromeEarlGrey showTabSwitcher]; [ChromeEarlGrey showTabSwitcher];
GREYWaitForAppToIdle(@"App failed to idle"); GREYWaitForAppToIdle(@"App failed to idle");
[ChromeEarlGrey [ChromeEarlGrey
...@@ -588,6 +590,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -588,6 +590,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
[ChromeEarlGrey waitForAndTapButton:chrome_test_util::TabGridDoneButton()]; [ChromeEarlGrey waitForAndTapButton:chrome_test_util::TabGridDoneButton()];
[self waitForRestoreSessionToFinish]; [self waitForRestoreSessionToFinish];
[self waitForPageToFinishLoading]; [self waitForPageToFinishLoading];
[ChromeEarlGreyAppInterface resetCloseAllTabsConfirmation];
} }
- (BOOL)webStateWebViewUsesContentInset { - (BOOL)webStateWebViewUsesContentInset {
......
...@@ -166,6 +166,12 @@ ...@@ -166,6 +166,12 @@
// Returns the index of active tab in normal mode. // Returns the index of active tab in normal mode.
+ (NSUInteger)indexOfActiveNormalTab; + (NSUInteger)indexOfActiveNormalTab;
// Resets Close All Tabs Confirmation feature to its default value.
+ (void)resetCloseAllTabsConfirmation;
// Disables Close All Tabs Confirmation feature.
+ (void)disableCloseAllTabsConfirmation;
#pragma mark - Window utilities (EG2) #pragma mark - Window utilities (EG2)
// Returns the number of windows, including background and disconnected or // Returns the number of windows, including background and disconnected or
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/json/json_string_value_serializer.h" #include "base/json/json_string_value_serializer.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h" #include "base/values.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
...@@ -87,6 +88,10 @@ NSString* SerializedPref(const PrefService::Preference* pref) { ...@@ -87,6 +88,10 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
return base::SysUTF8ToNSString(serialized_value); return base::SysUTF8ToNSString(serialized_value);
} }
// ScopedFeatureList used to disable the kEnableCloseAllTabsConfirmation
// feature. It's kept alive to preserve the state of
// kEnableCloseAllTabsConfirmation feature during testing.
base::test::ScopedFeatureList closeAllTabsScopedFeatureList;
} }
@implementation ChromeEarlGreyAppInterface @implementation ChromeEarlGreyAppInterface
...@@ -303,6 +308,15 @@ NSString* SerializedPref(const PrefService::Preference* pref) { ...@@ -303,6 +308,15 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
return chrome_test_util::GetIndexOfActiveNormalTab(); return chrome_test_util::GetIndexOfActiveNormalTab();
} }
+ (void)resetCloseAllTabsConfirmation {
closeAllTabsScopedFeatureList.Reset();
}
+ (void)disableCloseAllTabsConfirmation {
closeAllTabsScopedFeatureList.InitAndDisableFeature(
kEnableCloseAllTabsConfirmation);
}
#pragma mark - Window utilities (EG2) #pragma mark - Window utilities (EG2)
+ (NSUInteger)windowCount WARN_UNUSED_RESULT { + (NSUInteger)windowCount WARN_UNUSED_RESULT {
......
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