chromium/chrome/browser/ui/views/extensions/extension_install_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 "chrome/browser/ui/views/extensions/extension_install_dialog_view.h"

#include <string>
#include <utility>

#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/message_formatter.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
#include "chrome/browser/extensions/extension_install_prompt_test_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_test_util.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_icon_manager.h"
#include "extensions/browser/extension_registry.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_features.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/permissions/permission_message_provider.h"
#include "extensions/common/permissions/permissions_data.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"

PermissionIDSet;
PermissionMessage;
PermissionMessages;
PermissionSet;

namespace {

void CloseAndWait(views::Widget* widget) {}

}  // namespace

class ExtensionInstallDialogViewTestBase
    : public extensions::ExtensionBrowserTest {};

ExtensionInstallDialogViewTestBase::ExtensionInstallDialogViewTestBase()
    :{}

void ExtensionInstallDialogViewTestBase::SetUpOnMainThread() {}

std::unique_ptr<ExtensionInstallPrompt::Prompt>
ExtensionInstallDialogViewTestBase::CreatePrompt(
    ExtensionInstallPrompt::PromptType prompt_type) {}

std::unique_ptr<ExtensionInstallPrompt::Prompt>
ExtensionInstallDialogViewTestBase::CreatePrompt(
    ExtensionInstallPrompt::PromptType prompt_type,
    const extensions::Extension* extension) {}

class ScrollbarTest : public ExtensionInstallDialogViewTestBase {};

bool ScrollbarTest::IsScrollbarVisible(
    std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) {}

// Tests that a scrollbar _is_ shown for an excessively long extension
// install prompt.
IN_PROC_BROWSER_TEST_F(ScrollbarTest, LongPromptScrollbar) {}

// Tests that a scrollbar isn't shown for this regression case.
// See crbug.com/385570 for details.
// TODO(http://crbug.com/988934): Flaky on some Mac release bots.
#if BUILDFLAG(IS_MAC) && defined(NDEBUG)
#define MAYBE_ScrollbarRegression
#else
#define MAYBE_ScrollbarRegression
#endif
IN_PROC_BROWSER_TEST_F(ScrollbarTest, MAYBE_ScrollbarRegression) {}

class ExtensionInstallDialogViewTest
    : public ExtensionInstallDialogViewTestBase {};

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, NotifyDelegate) {}

// Regression test for crbug.com/40059470. Tests that the originating web
// contents are activated and the installation prompt is shown there, if the
// user switches the tab after starting the installation.
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest,
                       ActivateWebContentsOnTabChange) {}

// Verifies that the "Add extension" button is disabled initially, but
// re-enabled after a short time delay.
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest, InstallButtonDelay) {}

// Regression test for https://crbug.com/1201031: Ensures that while an
// ExtensionInstallDialogView is visible, it does not (and cannot) refer to its
// originator tab/WebContents after the tab's closure.
//
// Note that the tab's closure is not typically possible by user interaction.
// However, it can occur by other means:
//   a) chrome.tabs.remove() or
//   b) window.close() from devtools (See repro in crbug).
// This test uses CloseWebContentsAt to mimic that behavior.
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewTest,
                       TabClosureClearsWebContentsFromDialogView) {}

class ExtensionInstallDialogViewInteractiveBrowserTest
    : public DialogBrowserTest {};

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       InvokeUi_Simple) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       InvokeUi_External) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       InvokeUi_ExternalWithPermission) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       InvokeUi_ReEnable) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       InvokeUi_MultilinePermission) {}

// crbug.com/1166152
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvokeUi_ManyPermissions
#else
#define MAYBE_InvokeUi_ManyPermissions
#endif
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_ManyPermissions) {}

// TODO(crbug.com/40718668): Flaky on Win10.
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvokeUi_DetailedPermission
#else
#define MAYBE_InvokeUi_DetailedPermission
#endif
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_DetailedPermission) {}

// TODO(crbug.com/40718673): Flaky on Win10.
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvokeUi_WithWithholdingOption
#else
#define MAYBE_InvokeUi_WithWithholdingOption
#endif
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_WithWithholdingOption) {}

// TODO(crbug.com/40912720): Flaky on Win10.
#if BUILDFLAG(IS_WIN)
#define MAYBE_InvokeUi_AllInfoTypes
#else
#define MAYBE_InvokeUi_AllInfoTypes
#endif
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
                       MAYBE_InvokeUi_AllInfoTypes) {}

class ExtensionInstallDialogViewOnUninstallationTest
    : public ExtensionInstallDialogViewTest {};

void ExtensionInstallDialogViewOnUninstallationTest::UninstallExtension(
    const std::string& extension_id) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewOnUninstallationTest,
                       UninstallingExtensionClosesDialog) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewOnUninstallationTest,
                       UninstallingOtherExtensionDoesNotCloseDialog) {}

class ExtensionInstallDialogRatingsSectionTest
    : public ExtensionInstallDialogViewTest {};

void ExtensionInstallDialogRatingsSectionTest::TestRatingsSectionA11y(
    int num_ratings,
    double average_rating,
    const std::string& expected_text) {}

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogRatingsSectionTest,
                       RatingsSectionA11y) {}

class ExtensionInstallDialogWithWithholdPermissionsUI
    : public ExtensionInstallDialogViewTestBase {};

// Verifies that some UI is displayed in the extra view when withholding
// permissions on installation.
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogWithWithholdPermissionsUI,
                       ShowsWithholdUI) {}

class ExtensionInstallDialogViewRequestTest
    : public ExtensionInstallDialogViewTestBase {};

IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewRequestTest, NotifyDelegate) {}

// Verifies that the "Send" button is disabled initially, but re-enabled after a
// short time delay.
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewRequestTest,
                       RequestButtonDelay) {}

// Verifies that the "Send" button is disabled when the justification text
// exceeds the limit.
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewRequestTest,
                       SendButtonDisabledWhenJustificationExceedsLimit) {}