From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Mon, 8 Aug 2022 02:35:35 +0200
Subject: Re-introduce modal dialog flag to close all tabs

Revert "[Tab Management] Cleanup close all tabs modal dialog flags"

This reverts commit 614a998c5af5dcd36baffa6d65090c0b8decb03f.

License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
 .../tab_management/CloseAllTabsDialog.java    |  6 +++++
 .../CloseAllTabsDialogTest.java               |  3 +++
 .../CloseAllTabsDialogUnitTest.java           | 23 +++++++++++++++++++
 chrome/browser/about_flags.cc                 |  7 ++++++
 chrome/browser/flag_descriptions.cc           |  5 ++++
 chrome/browser/flag_descriptions.h            |  3 +++
 .../flags/android/chrome_feature_list.cc      |  9 ++++++--
 .../flags/android/chrome_feature_list.h       |  1 +
 .../browser/flags/ChromeFeatureList.java      |  1 +
 9 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialog.java b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialog.java
--- a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialog.java
+++ b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialog.java
@@ -9,6 +9,7 @@ import android.content.Context;
 import org.chromium.base.metrics.RecordHistogram;
 import org.chromium.base.metrics.RecordUserAction;
 import org.chromium.base.supplier.Supplier;
+import org.chromium.chrome.browser.flags.ChromeFeatureList;
 import org.chromium.chrome.tab_ui.R;
 import org.chromium.ui.modaldialog.DialogDismissalCause;
 import org.chromium.ui.modaldialog.ModalDialogManager;
@@ -30,6 +31,11 @@ public class CloseAllTabsDialog {
     public static void show(Context context,
             Supplier<ModalDialogManager> modalDialogManagerSupplier, Runnable onCloseAll,
             boolean isIncognito) {
+        if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CLOSE_ALL_TABS_MODAL_DIALOG)) {
+            onCloseAll.run();
+            return;
+        }
+
         assert modalDialogManagerSupplier.hasValue();
         final ModalDialogManager manager = modalDialogManagerSupplier.get();
 
diff --git a/chrome/android/features/tab_ui/javatests/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogTest.java b/chrome/android/features/tab_ui/javatests/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogTest.java
--- a/chrome/android/features/tab_ui/javatests/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogTest.java
+++ b/chrome/android/features/tab_ui/javatests/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogTest.java
@@ -28,11 +28,13 @@ import org.chromium.base.test.params.ParameterSet;
 import org.chromium.base.test.params.ParameterizedRunner;
 import org.chromium.base.test.util.CommandLineFlags;
 import org.chromium.base.test.util.Restriction;
+import org.chromium.chrome.browser.flags.ChromeFeatureList;
 import org.chromium.chrome.browser.flags.ChromeSwitches;
 import org.chromium.chrome.browser.tabmodel.TabModelSelector;
 import org.chromium.chrome.browser.ui.appmenu.AppMenuTestSupport;
 import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
 import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
+import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
 import org.chromium.content_public.browser.test.util.TestThreadUtils;
 import org.chromium.ui.test.util.UiRestriction;
 
@@ -44,6 +46,7 @@ import java.util.List;
  */
 @RunWith(ParameterizedRunner.class)
 @UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class)
+@EnableFeatures({ChromeFeatureList.CLOSE_ALL_TABS_MODAL_DIALOG})
 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
 public class CloseAllTabsDialogTest {
     @ParameterAnnotations.ClassParameter
diff --git a/chrome/android/features/tab_ui/junit/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogUnitTest.java b/chrome/android/features/tab_ui/junit/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogUnitTest.java
--- a/chrome/android/features/tab_ui/junit/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogUnitTest.java
+++ b/chrome/android/features/tab_ui/junit/src/org/chromium/chrome/browser/tasks/tab_management/CloseAllTabsDialogUnitTest.java
@@ -25,9 +25,11 @@ import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
 
+import org.chromium.base.FeatureList;
 import org.chromium.base.metrics.UmaRecorder;
 import org.chromium.base.metrics.UmaRecorderHolder;
 import org.chromium.base.test.BaseRobolectricTestRunner;
+import org.chromium.chrome.browser.flags.ChromeFeatureList;
 import org.chromium.chrome.tab_ui.R;
 import org.chromium.ui.modaldialog.DialogDismissalCause;
 import org.chromium.ui.modaldialog.ModalDialogManager;
@@ -135,6 +137,7 @@ public class CloseAllTabsDialogUnitTest {
     @Test
     @SmallTest
     public void testDialog() {
+        enableFeature(true);
         final boolean isIncognito = false;
         CloseAllTabsDialog.show(mContext, this::getModalDialogManager,
                 () -> { mRunnableCalled = true; }, isIncognito);
@@ -148,6 +151,7 @@ public class CloseAllTabsDialogUnitTest {
     @Test
     @SmallTest
     public void testDismissButton() {
+        enableFeature(true);
         final boolean isIncognito = true;
         CloseAllTabsDialog.show(mContext, this::getModalDialogManager,
                 () -> { mRunnableCalled = true; }, isIncognito);
@@ -161,6 +165,7 @@ public class CloseAllTabsDialogUnitTest {
     @Test
     @SmallTest
     public void testDismissNoButton() {
+        enableFeature(true);
         final boolean isIncognito = false;
         CloseAllTabsDialog.show(mContext, this::getModalDialogManager,
                 () -> { mRunnableCalled = true; }, isIncognito);
@@ -171,4 +176,22 @@ public class CloseAllTabsDialogUnitTest {
         assertFalse(mRunnableCalled);
         verifyDismissed(false, isIncognito);
     }
+
+    @Test
+    @SmallTest
+    public void testDialogInactive() {
+        enableFeature(false);
+        final boolean isIncognito = false;
+        CloseAllTabsDialog.show(mContext, this::getModalDialogManager,
+                () -> { mRunnableCalled = true; }, isIncognito);
+
+        assertNull(mMockModalDialogManager.getDialogModel());
+        assertTrue(mRunnableCalled);
+    }
+
+    private void enableFeature(boolean enable) {
+        FeatureList.TestValues values = new FeatureList.TestValues();
+        values.addFeatureFlagOverride(ChromeFeatureList.CLOSE_ALL_TABS_MODAL_DIALOG, enable);
+        FeatureList.setTestValues(values);
+    }
 }
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -9161,6 +9161,13 @@ const FeatureEntry kFeatureEntries[] = {
      FEATURE_VALUE_TYPE(features::kWaylandScreenCoordinatesEnabled)},
 #endif
 
+#if BUILDFLAG(IS_ANDROID)
+    {"close-all-tabs-modal-dialog",
+     flag_descriptions::kCloseAllTabsModalDialogName,
+     flag_descriptions::kCloseAllTabsModalDialogDescription, kOsAndroid,
+     FEATURE_VALUE_TYPE(chrome::android::kCloseAllTabsModalDialog)},
+#endif  // BUILDFLAG(IS_ANDROID)
+
 #if !BUILDFLAG(IS_ANDROID)
     {"enable-tailored-security-desktop-notice",
      flag_descriptions::kTailoredSecurityDesktopNoticeName,
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -3631,6 +3631,11 @@ const char kEnableCbdSignOutDescription[] =
     "Enable additional affordance to sign out when clearing browsing data and "
     "ensure consistent behavior for all signed-in users.";
 
+const char kCloseAllTabsModalDialogName[] = "Close all tabs modal dialog";
+const char kCloseAllTabsModalDialogDescription[] =
+    "Shows a confirmation modal dialog when clicking 'Close all tabs' in the"
+    "app menu.";
+
 const char kCloseTabSuggestionsName[] = "Suggest to close Tabs";
 const char kCloseTabSuggestionsDescription[] =
     "Suggests to the user to close Tabs that haven't been used beyond a "
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -385,6 +385,9 @@ extern const char kContextMenuSearchWithGoogleLensDescription[];
 extern const char kClientStorageAccessContextAuditingName[];
 extern const char kClientStorageAccessContextAuditingDescription[];
 
+extern const char kCloseAllTabsModalDialogName[];
+extern const char kCloseAllTabsModalDialogDescription[];
+
 extern const char kClosedTabCacheName[];
 extern const char kClosedTabCacheDescription[];
 
diff --git a/chrome/browser/flags/android/chrome_feature_list.cc b/chrome/browser/flags/android/chrome_feature_list.cc
--- a/chrome/browser/flags/android/chrome_feature_list.cc
+++ b/chrome/browser/flags/android/chrome_feature_list.cc
@@ -176,6 +176,7 @@ const base::Feature* const kFeaturesExposedToJava[] = {
     &kAssistantNonPersonalizedVoiceSearch,
     &kAppLaunchpad,
     &kAppMenuMobileSiteOption,
+    &kCloseAllTabsModalDialog,
     &kAppToWebAttribution,
     &kBackgroundThreadPool,
     &kCastDeviceFilter,
@@ -525,6 +526,10 @@ BASE_FEATURE(kConditionalTabStripAndroid,
              "ConditionalTabStripAndroid",
              base::FEATURE_DISABLED_BY_DEFAULT);
 
+BASE_FEATURE(kCloseAllTabsModalDialog,
+             "CloseAllTabsModalDialog",
+             base::FEATURE_ENABLED_BY_DEFAULT);
+
 // Used in downstream code.
 BASE_FEATURE(kCastDeviceFilter,
              "CastDeviceFilter",
@@ -535,8 +540,8 @@ BASE_FEATURE(kClearOmniboxFocusAfterNavigation,
              base::FEATURE_DISABLED_BY_DEFAULT);
 
 BASE_FEATURE(kCloseTabSuggestions,
-             "CloseTabSuggestions",
-             base::FEATURE_DISABLED_BY_DEFAULT);
+             "CloseTabSuggestions",               // must be enabled
+             base::FEATURE_ENABLED_BY_DEFAULT);   // in Bromite
 
 BASE_FEATURE(kCriticalPersistedTabData,
              "CriticalPersistedTabData",
diff --git a/chrome/browser/flags/android/chrome_feature_list.h b/chrome/browser/flags/android/chrome_feature_list.h
--- a/chrome/browser/flags/android/chrome_feature_list.h
+++ b/chrome/browser/flags/android/chrome_feature_list.h
@@ -31,6 +31,7 @@ BASE_DECLARE_FEATURE(kAppMenuMobileSiteOption);
 BASE_DECLARE_FEATURE(kAppToWebAttribution);
 BASE_DECLARE_FEATURE(kBackgroundThreadPool);
 BASE_DECLARE_FEATURE(kClearOmniboxFocusAfterNavigation);
+BASE_DECLARE_FEATURE(kCloseAllTabsModalDialog);
 BASE_DECLARE_FEATURE(kCloseTabSuggestions);
 BASE_DECLARE_FEATURE(kCriticalPersistedTabData);
 BASE_DECLARE_FEATURE(kCommerceCoupons);
diff --git a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java
--- a/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java
+++ b/chrome/browser/flags/android/java/src/org/chromium/chrome/browser/flags/ChromeFeatureList.java
@@ -263,6 +263,7 @@ public abstract class ChromeFeatureList {
     public static final String CCT_RESIZABLE_ALWAYS_SHOW_NAVBAR_BUTTONS =
             "CCTResizableAlwaysShowNavBarButtons";
     public static final String CCT_RESIZABLE_FOR_FIRST_PARTIES = "CCTResizableForFirstParties";
+    public static final String CLOSE_ALL_TABS_MODAL_DIALOG = "CloseAllTabsModalDialog";
     public static final String CCT_RESIZABLE_FOR_THIRD_PARTIES = "CCTResizableForThirdParties";
     public static final String CCT_RESIZABLE_WINDOW_ABOVE_NAVBAR = "CCTResizableWindowAboveNavbar";
     public static final String CCT_RESOURCE_PREFETCH = "CCTResourcePrefetch";
--
2.25.1
