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

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

#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/permissions/scripting_permissions_modifier.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/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_coordinator.h"
#include "chrome/browser/ui/views/extensions/extensions_request_access_button.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_interactive_uitest.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_host_test_helper.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/process_manager.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_features.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/test_extension_dir.h"
#include "net/dns/mock_host_resolver.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/bubble/bubble_dialog_model_host.h"
#include "ui/views/layout/animating_layout_manager_test_util.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"

namespace {

ScriptingPermissionsModifier;
PermissionsManager;

constexpr char kInjectionSucceededMessage[] =;

views::Widget* CreateBubble(views::View* anchor_point) {}

}  // namespace

UserSiteAccess;
SiteInteraction;

class ExtensionsToolbarContainerUITest : public ExtensionsToolbarUITest {};

// TODO(devlin): There are probably some tests from
// ExtensionsMenuViewInteractiveUITest that should move here (if they test the
// toolbar container more than the menu).

// Tests that invocation metrics are properly recorded when triggering
// extensions from the toolbar.
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest, InvocationMetrics) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       InvisibleWithoutExtension_Disable) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       InvisibleWithoutExtension_Uninstall) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       InvisibleWithoutExtension_Blocklist) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       InvisibleWithoutExtension_Terminate) {}

// Tests that clicking on a second extension action will close a first if its
// popup was open.
// TODO(crbug.com/332299695): Test failing on linux-lacros-tester-rel.
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_ClickingOnASecondActionClosesTheFirst
#else
#define MAYBE_ClickingOnASecondActionClosesTheFirst
#endif
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       MAYBE_ClickingOnASecondActionClosesTheFirst) {}

// Tests that clicking an extension toolbar icon when the popup is open closes
// the popup.
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       DoubleClickToolbarActionToClose) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       ShowWidgetForExtension_Pinned) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       ShowWidgetForExtension_Unpinned) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       ShowWidgetForExtension_NoAction) {}

IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       UninstallExtensionWithActivelyShownWidget) {}

// Verifies that dragging extension icons is disabled in incognito windows.
// https://crbug.com/1203833.
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       IncognitoDraggingIsDisabled) {}

// Tests unloading an extension while the action is being slid out prior to the
// popup being shown. Regression test for https://crbug.com/1345477.
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerUITest,
                       UnloadingExtensionWhileAboutToShowPopup) {}

namespace {

class IncognitoExtensionsToolbarContainerUITest
    : public ExtensionsToolbarContainerUITest {};

}  // namespace

// Tests that first loading an extension action in an incognito profile, then
// removing the incognito profile and using the extension action in a normal
// profile doesn't crash.
// Regression test for crbug.com/663726.
IN_PROC_BROWSER_TEST_F(IncognitoExtensionsToolbarContainerUITest,
                       TestExtensionFirstLoadedInIncognitoMode) {}

class ExtensionsToolbarRuntimeHostPermissionsBrowserTest
    : public ExtensionsToolbarContainerUITest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// Tests page access modifications through the context menu which require a page
// refresh.
IN_PROC_BROWSER_TEST_P(ExtensionsToolbarRuntimeHostPermissionsBrowserTest,
                       ContextMenuPageAccess_RefreshRequired) {}

// Tests page access modifications through the context menu which don't require
// a page refresh.
IN_PROC_BROWSER_TEST_P(ExtensionsToolbarRuntimeHostPermissionsBrowserTest,
                       ContextMenuPageAccess_RefreshNotRequired) {}

class ExtensionsToolbarContainerFeatureUITest
    : public ExtensionsToolbarContainerUITest {};

class ExtensionsToolbarContainerFeatureUIReloadBubbleAcceptanceTest
    : public ExtensionsToolbarContainerFeatureUITest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// Tests that when clicking the request access button (and a refresh should be
// required to run blocked actions) it grants one time site access to the
// extensions listed. Blocked actions are only run if the refresh is accepted.
IN_PROC_BROWSER_TEST_P(
    ExtensionsToolbarContainerFeatureUIReloadBubbleAcceptanceTest,
    ClickingRequestAccessButtonRunsAction_RefreshRequired) {}

// Tests that the extension menu (puzzle piece menu) closes alongside the
// extensions context menu (3 dot while puzzle piece menu is open) when the side
// panel context menu item is selected.
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerFeatureUITest,
                       SidePanelContextMenuItemClosesExtensionsMenu) {}

// Tests that clicking the request access button grants one time access to the
// extensions listed without needing a page refresh.
IN_PROC_BROWSER_TEST_F(
    ExtensionsToolbarContainerFeatureUITest,
    ClickingRequestAccessButtonRunsAction_RefreshNotRequired) {}

// Tests that when the user clicks on the request access button and immediately
// navigates to a different site, the confirmation text is collapsed and the
// button displays the extensions requesting access to the new site (if any).
// TODO(crbug.com/40918196): Flaky due to button's confirmation text animation.
IN_PROC_BROWSER_TEST_F(
    ExtensionsToolbarContainerFeatureUITest,
    DISABLED_ClickingRequestAccessButton_ConfirmationCollapsedOnNavigation) {}

// Verifies extensions can add site access requests on active and inactive tabs,
// but the request access button only shows extensions's requests for the
// current tab.
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerFeatureUITest,
                       SiteAccessRequestsForMultipleTabs) {}

// Tests that the container has its visible children in the correct order when
// there are dynamic updates (e.g extension is installed).
IN_PROC_BROWSER_TEST_F(ExtensionsToolbarContainerFeatureUITest,
                       CorrectReorderAfterDynamicChanges) {}