Turned on closing window dialog by default

fix https://github.com/brave/brave-browser/issues/23056
This commit is contained in:
Simon Hong
2022-06-02 22:43:10 +09:00
parent f52c657e58
commit d18b611d89
6 changed files with 40 additions and 7 deletions
+1 -1
View File
@@ -431,7 +431,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// We can turn customization mode on when we have add-shortcut feature.
registry->SetDefaultPrefValue(ntp_prefs::kNtpUseMostVisitedTiles,
base::Value(true));
registry->RegisterBooleanPref(kEnableWindowClosingConfirm, false);
registry->RegisterBooleanPref(kEnableWindowClosingConfirm, true);
RegisterDefaultBraveBrowserPromptPrefs(registry);
#endif
+14
View File
@@ -24,6 +24,17 @@
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#endif
namespace {
bool g_suppress_dialog_for_testing = false;
} // namespace
// static
void BraveBrowser::SuppressBrowserWindowClosingDialogForTesting(bool suppress) {
g_suppress_dialog_for_testing = suppress;
}
BraveBrowser::BraveBrowser(const CreateParams& params) : Browser(params) {
#if BUILDFLAG(ENABLE_SIDEBAR)
if (!sidebar::CanUseSidebar(this))
@@ -138,6 +149,9 @@ void BraveBrowser::ResetTryToCloseWindow() {
}
bool BraveBrowser::ShouldAskForBrowserClosingBeforeHandlers() {
if (g_suppress_dialog_for_testing)
return false;
// Don't need to ask when application closing is in-progress.
if (BrowserCloseManager::BrowserClosingStarted())
return false;
+6
View File
@@ -63,6 +63,12 @@ class BraveBrowser : public Browser {
void set_confirmed_to_close(bool close) { confirmed_to_close_ = close; }
private:
friend class BraveTestLauncherDelegate;
friend class WindowClosingConfirmBrowserTest;
// static
static void SuppressBrowserWindowClosingDialogForTesting(bool suppress);
#if BUILDFLAG(ENABLE_SIDEBAR)
std::unique_ptr<sidebar::SidebarController> sidebar_controller_;
#endif
@@ -53,18 +53,23 @@ void CancelClose() {
class WindowClosingConfirmBrowserTest : public InProcessBrowserTest {
public:
void SetUpOnMainThread() override {
BraveBrowser::SuppressBrowserWindowClosingDialogForTesting(false);
InProcessBrowserTest::SetUpOnMainThread();
PrefService* prefs = browser()->profile()->GetPrefs();
// Disabled by default.
EXPECT_FALSE(prefs->GetBoolean(kEnableWindowClosingConfirm));
// Enable for testing.
prefs->SetBoolean(kEnableWindowClosingConfirm, true);
// Enabled by default.
EXPECT_TRUE(prefs->GetBoolean(kEnableWindowClosingConfirm));
SetDialogCreationCallback();
}
void TearDownOnMainThread() override {
BraveBrowser::SuppressBrowserWindowClosingDialogForTesting(true);
InProcessBrowserTest::TearDownOnMainThread();
}
void SetDialogCreationCallback() {
WindowClosingConfirmDialogView::SetCreationCallbackForTesting(
base::BindRepeating(&WindowClosingConfirmBrowserTest::
+4 -1
View File
@@ -593,7 +593,10 @@ static_library("browser_test_support") {
"base/brave_test_launcher_delegate.h",
]
deps = [ "//chrome/browser" ]
deps = [
"//brave/browser/ui",
"//chrome/browser",
]
}
static_library("browser_tests_runner") {
@@ -6,6 +6,7 @@
#include "brave/test/base/brave_test_launcher_delegate.h"
#include "brave/app/brave_main_delegate.h"
#include "brave/browser/ui/brave_browser.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
@@ -20,6 +21,10 @@ BraveTestLauncherDelegate::BraveTestLauncherDelegate(
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
first_run::internal::ForceFirstRunDialogShownForTesting(false);
#endif
// Suppress browser window closing dialog during the test.
// It can cause some tests timeout.
BraveBrowser::SuppressBrowserWindowClosingDialogForTesting(true);
}
BraveTestLauncherDelegate::~BraveTestLauncherDelegate() = default;