chromium/chrome/browser/ui/extensions/extension_action_view_controller_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/ui/extensions/extension_action_view_controller.h"

#include <stddef.h>

#include <memory>

#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/api/side_panel/side_panel_service.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_action_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/load_error_reporter.h"
#include "chrome/browser/extensions/permissions/scripting_permissions_modifier.h"
#include "chrome/browser/extensions/permissions/site_permissions_helper.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/extensions/user_script_listener.h"
#include "chrome/browser/ui/extensions/extension_action_test_helper.h"
#include "chrome/browser/ui/extensions/extensions_container.h"
#include "chrome/browser/ui/extensions/icon_with_badge_image_source.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/common/extensions/api/side_panel.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "components/sessions/content/session_tab_helper.h"
#include "extensions/browser/extension_action.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/api/extension_action/action_info.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/mojom/run_location.mojom-shared.h"
#include "extensions/test/test_extension_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/native_theme/native_theme.h"

ManifestLocation;
SiteInteraction;
UserSiteSetting;
HoverCardState;

namespace {

std::unique_ptr<KeyedService> BuildSidePanelService(
    content::BrowserContext* context) {}

}  // namespace

class ExtensionActionViewControllerUnitTest : public BrowserWithTestWindowTest {};

// Tests the icon appearance of extension actions in the toolbar.
// Extensions that don't want to run should have their icons grayscaled.
TEST_F(ExtensionActionViewControllerUnitTest,
       ExtensionActionWantsToRunAppearance) {}

// Tests the appearance of browser actions with blocked script actions.
TEST_F(ExtensionActionViewControllerUnitTest, BrowserActionBlockedActions) {}

// Tests the appearance of page actions with blocked script actions.
TEST_F(ExtensionActionViewControllerUnitTest, PageActionBlockedActions) {}

// Tests the appearance of extension actions for extensions without a browser or
// page action defined in their manifest, but with host permissions on a page.
TEST_F(ExtensionActionViewControllerUnitTest, OnlyHostPermissionsAppearance) {}

TEST_F(ExtensionActionViewControllerUnitTest,
       ExtensionActionContextMenuVisibility) {}

// TODO(devlin): Now that this is only parameterized in one way, it could be a
// TestWithParamInterface<PermissionType>.
class ExtensionActionViewControllerGrayscaleTest
    : public ExtensionActionViewControllerUnitTest {};

void ExtensionActionViewControllerGrayscaleTest::RunGrayscaleTest(
    PermissionType permission_type) {}

scoped_refptr<const extensions::Extension>
ExtensionActionViewControllerGrayscaleTest::CreateExtension(
    PermissionType permission_type) {}

extensions::PermissionsData::PageAccess
ExtensionActionViewControllerGrayscaleTest::GetPageAccess(
    content::WebContents* web_contents,
    scoped_refptr<const extensions::Extension> extension,
    PermissionType permission_type) {}

// Tests the behavior for icon grayscaling. Ideally, these would be a single
// parameterized test, but toolbar tests are already parameterized with the UI
// mode.
TEST_F(ExtensionActionViewControllerGrayscaleTest,
       GrayscaleIcon_ExplicitHosts) {}
TEST_F(ExtensionActionViewControllerGrayscaleTest,
       GrayscaleIcon_ScriptableHosts) {}

TEST_F(ExtensionActionViewControllerUnitTest, RuntimeHostsTooltip) {}

// Tests the appearance of extension actions for an extension with the activeTab
// permission and no browser or page action defined in their manifest.
TEST_F(ExtensionActionViewControllerUnitTest, ActiveTabIconAppearance) {}

// Tests that an extension with the activeTab permission has active tab site
// interaction except for restricted URLs.
TEST_F(ExtensionActionViewControllerUnitTest, GetSiteInteractionWithActiveTab) {}

// Tests that file URLs only have active tab site interaction if the extension
// has active tab permission and file URL access.
TEST_F(ExtensionActionViewControllerUnitTest,
       GetSiteInteractionActiveTabWithFileURL) {}

// ExtensionActionViewController::GetIcon() can potentially be called with a
// null web contents if the tab strip model doesn't know of an active tab
// (though it's a bit unclear when this is the case).
// See https://crbug.com/888121
TEST_F(ExtensionActionViewControllerUnitTest, TestGetIconWithNullWebContents) {}

class ExtensionActionViewControllerFeatureUnitTest
    : public ExtensionActionViewControllerUnitTest {};

// Tests hover card status after changing user site settings and site access.
TEST_F(ExtensionActionViewControllerFeatureUnitTest, GetHoverCardStatus) {}

// Tests correct tooltip text after changing user site settings and site access.
TEST_F(ExtensionActionViewControllerFeatureUnitTest, GetTooltip) {}

class ExtensionActionViewControllerFeatureWithPermittedSitesUnitTest
    : public ExtensionActionViewControllerFeatureUnitTest {};

// Tests hover card status after changing user site settings and site access.
TEST_F(ExtensionActionViewControllerFeatureWithPermittedSitesUnitTest,
       GetHoverCardStatus) {}

class ExtensionActionViewControllerWithSidePanelUnitTest
    : public ExtensionActionViewControllerUnitTest {};

// Test that the extension action is enabled if opening the side panel on icon
// click is enabled and the extension has a side panel for the current tab.
TEST_F(ExtensionActionViewControllerWithSidePanelUnitTest,
       ActionEnabledIfSidePanelPresent) {}