chromium/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/test/os_integration_test_override_impl.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_urls.h"
#include "ui/views/layout/animating_layout_manager_test_util.h"
#include "ui/views/test/widget_test.h"

namespace {

const char kUninstallUrl[] =;

const char kReferrerId[] =;

// A preference key storing the url loaded when an extension is uninstalled.
const char kUninstallUrlPrefKey[] =;

scoped_refptr<const extensions::Extension> BuildTestExtension(
    const char* extension_name = "foo") {}

std::string GetActiveUrl(Browser* browser) {}

void SetUninstallURL(extensions::ExtensionPrefs* prefs,
                     const std::string& extension_id) {}

void CloseUninstallDialog(views::Widget* const bubble_widget) {}

class TestExtensionUninstallDialogDelegate
    : public extensions::ExtensionUninstallDialog::Delegate {};

}  // namespace

ExtensionUninstallDialogViewBrowserTest;

// Test that ExtensionUninstallDialog cancels the uninstall if the Window which
// is passed to ExtensionUninstallDialog::Create() is destroyed before
// ExtensionUninstallDialogDelegateView is created.
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
                       TrackParentWindowDestruction) {}

// Test that ExtensionUninstallDialog cancels the uninstall if the Window which
// is passed to ExtensionUninstallDialog::Create() is destroyed after
// ExtensionUninstallDialogDelegateView is created.
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
                       TrackParentWindowDestructionAfterViewCreation) {}

// Tests uninstalling the extension while the dialog is active.
// Regression test for https://1200679.
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
                       ExtensionUninstalledWhileDialogIsActive) {}

// Test that we don't crash when uninstalling an extension from a web app
// window in Ash. Context: crbug.com/825554
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
                       WebAppWindowAshCrash) {}

class ParameterizedExtensionUninstallDialogViewBrowserTest
    : public InProcessBrowserTest,
      public testing::WithParamInterface<extensions::UninstallReason> {};

// Test that when the user clicks Uninstall on the ExtensionUninstallDialog the
// extension's uninstall url (when it is specified) should open and be the
// active tab.
IN_PROC_BROWSER_TEST_P(ParameterizedExtensionUninstallDialogViewBrowserTest,
                       EnsureExtensionUninstallURLIsActiveTabAfterUninstall) {}

// Test that when the user clicks the Report Abuse checkbox and clicks Uninstall
// on the ExtensionUninstallDialog, the extension's uninstall url (when it is
// specified) and the CWS Report Abuse survey are opened in the browser, also
// testing that the CWS survey is the active tab.
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
                       EnsureCWSReportAbusePageIsActiveTabAfterUninstall) {}

// Tests the dialog is anchored in the correct place based on whether the
// extensions container is visible.
// Regression test for crbug.com/133249.
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
                       DialogAnchoredInCorrectPlace) {}

class ExtensionUninstallDialogViewInteractiveBrowserTest
    : public DialogBrowserTest {};

#if BUILDFLAG(IS_WIN)
// TODO(crbug.com/40069124): Enable the test again.
#define MAYBE_InvokeUi_ManualUninstall
#else
#define MAYBE_InvokeUi_ManualUninstall
#endif
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_ManualUninstall) {}

// TODO(crbug.com/40926539): Re-enable this test
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvokeUi_ManualUninstallShowReportAbuse
#else
#define MAYBE_InvokeUi_ManualUninstallShowReportAbuse
#endif
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_ManualUninstallShowReportAbuse) {}

#if BUILDFLAG(IS_WIN)
// TODO(crbug.com/40069124): Enable the test again.
#define MAYBE_InvokeUi_UninstallByExtension
#else
#define MAYBE_InvokeUi_UninstallByExtension
#endif
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_UninstallByExtension) {}

// TODO(crbug.com/40926539): Fix flakiness and re-enable this test.
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvokeUi_UninstallByExtensionShowReportAbuse
#else
#define MAYBE_InvokeUi_UninstallByExtensionShowReportAbuse
#endif
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_UninstallByExtensionShowReportAbuse) {}

INSTANTIATE_TEST_SUITE_P();