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

// Copyright 2023 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/extensions_menu_main_page_view.h"

#include "base/containers/to_vector.h"
#include "base/feature_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/user_action_tester.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/permissions/active_tab_permission_granter.h"
#include "chrome/browser/extensions/permissions/site_permissions_helper.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/views/controls/hover_button.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_button.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_coordinator.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_item_view.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_site_permissions_page_view.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_view_controller.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_unittest.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/extension_features.h"
#include "extensions/test/permissions_manager_waiter.h"
#include "extensions/test/test_extension_dir.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/vector_icons.h"
#include "ui/views/view_utils.h"

namespace {

PermissionsManager;
SitePermissionsHelper;

// Returns the extension names from the given `menu_items`.
std::vector<std::string> GetNamesFromMenuItems(
    std::vector<ExtensionMenuItemView*> menu_items) {}

}  // namespace

class ExtensionsMenuMainPageViewUnitTest : public ExtensionsToolbarUnitTest {};

ExtensionsMenuMainPageViewUnitTest::ExtensionsMenuMainPageViewUnitTest() {}

void ExtensionsMenuMainPageViewUnitTest::ShowMenu() {}

ExtensionMenuItemView* ExtensionsMenuMainPageViewUnitTest::GetOnlyMenuItem() {}

std::vector<extensions::ExtensionId>
ExtensionsMenuMainPageViewUnitTest::GetExtensionsInRequestAccessSection() {}

std::vector<extensions::ExtensionId>
ExtensionsMenuMainPageViewUnitTest::GetExtensionsInRequestAccessButton() {}

void ExtensionsMenuMainPageViewUnitTest::LayoutMenuIfNecessary() {}

void ExtensionsMenuMainPageViewUnitTest::ClickSitePermissionsButton(
    ExtensionMenuItemView* menu_item) {}

void ExtensionsMenuMainPageViewUnitTest::ClickSiteAccessToggle(
    ExtensionMenuItemView* menu_item,
    bool active_tab_only) {}

ExtensionsMenuMainPageView* ExtensionsMenuMainPageViewUnitTest::main_page() {}

ExtensionsMenuSitePermissionsPageView*
ExtensionsMenuMainPageViewUnitTest::site_permissions_page() {}

std::vector<ExtensionMenuItemView*>
ExtensionsMenuMainPageViewUnitTest::menu_items() {}

void ExtensionsMenuMainPageViewUnitTest::SetUp() {}

TEST_F(ExtensionsMenuMainPageViewUnitTest, ExtensionsAreSorted) {}

// Verifies the site access toggle and site permissions button properties for an
// extension that doesn't request site access.
TEST_F(ExtensionsMenuMainPageViewUnitTest, NoSiteAccessRequested) {}

// Verifies the site access toggle and site permissions button properties for an
// enterprise extension that doesn't request host permissions.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       NoSiteAccessRequested_EnterpriseExtension) {}

// Verifies the site access toggle and site permissions button properties when
// toggling site access for an extension that requests host permissions for a
// specific site.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       HostPermissionsRequested_ToggleSiteAccess_OnSite) {}

// Verifies the site access toggle and site permissions button properties when
// toggling site access for an extension that requests host permissions for all
// sites.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       HostPermissionsRequested_ToggleSiteAccess_OnAllSites) {}

// Verifies the site access toggle and site permissions button properties for an
// extension that requests host permissions when host permission change with the
// menu open.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       HostPermissionsRequested_DynamicUpdates) {}

// Verifies the site access toggle persists its previous state when toggling
// site access on.
TEST_F(
    ExtensionsMenuMainPageViewUnitTest,
    HostPermissionsRequested_DynamicUpdates_TogglePersistsPreviousSiteAccess) {}

// Verifies the site access toggle and site permissions button properties for an
// extension that requests host permissions.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       HostPermissionsRequested_EnterpriseExtension) {}

// Verifies the site access toggle and site permissions button properties when
// toggling site access for an extension that only requests active tab.
// TODO(crbug.com/40268140): Flaky on various builders.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       DISABLED_ActiveTabRequested_ToggleSiteAccess) {}

// Verifies the site access toggle and site permissions button properties when
// toggling an extension off that has "on click" site access and granted tab
// permissions (meaning it has access to the current site).
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       ActiveTabRequested_ToggleSiteAccess_UngrantTabPermissions) {}

// Verifies the site access toggle and site permissions button properties for an
// extension that only requests active tab when site permissions change with the
// menu open.
TEST_F(ExtensionsMenuMainPageViewUnitTest, ActiveTabRequested_DynamicUpdates) {}

// Verifies the site permissions button opens the site permissions page when it
// is enabled.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       SitePermissionsButton_OpenSitePermissionsPage) {}

TEST_F(ExtensionsMenuMainPageViewUnitTest,
       AddAndRemoveExtensionWhenMainPageIsOpen) {}

// Tests that the extensions menu is dynamically updated when there is a
// navigation while the menu is opened.
TEST_F(ExtensionsMenuMainPageViewUnitTest, NavigationWhenMainPageIsOpen) {}

// Verifies the pin button appears on the menu item, in place of context menu
// button when state is normal, when an extension is pinned.
TEST_F(ExtensionsMenuMainPageViewUnitTest, PinnedExtensions) {}

TEST_F(ExtensionsMenuMainPageViewUnitTest, DisableAndEnableExtension) {}

// Tests that when an extension is reloaded it remains visible in the extensions
// menu.
// TODO(crbug.com/40879945): Verify context menu button shows the correct icon
// as pinned state is also preserved when a reload happens. Add this
// functionality when showing pin icon instead of context menu when extension is
// pinned is added.
TEST_F(ExtensionsMenuMainPageViewUnitTest, ReloadExtension) {}

// Tests that a when an extension is reloaded with manifest errors, and
// therefore fails to be loaded into Chrome, it's removed from the
// extensions menu.
TEST_F(ExtensionsMenuMainPageViewUnitTest, ReloadExtensionFailed) {}

// Tests that the site setting toggle, and extensions' site access toggle and
// site permission button are always hidden when site is restricted.
TEST_F(ExtensionsMenuMainPageViewUnitTest, RestrictedSite) {}

// Tests that the site setting toggle and extension's site access toggle is
// always hidden, and extensions' site permissions button is visible and
// disabled when site is blocked by policy.
TEST_F(ExtensionsMenuMainPageViewUnitTest, PolicyBlockedSite) {}

// Tests that the message section only displays the text container when the
// site restricts access to all extensions.
TEST_F(ExtensionsMenuMainPageViewUnitTest, MessageSection_RestrictedAccess) {}

// Tests that the message section only displays the text container when the
// site has policy-blocked access to all non-enterprise extensions.
TEST_F(ExtensionsMenuMainPageViewUnitTest, MessageSection_PolicyBlockedAccess) {}

// Tests that the message section only displays the text container when the
// user has blocked all extensions on the site.
TEST_F(ExtensionsMenuMainPageViewUnitTest, MessageSection_UserBlockedAccess) {}

// Tests that the message section only displays the text container (and the
// tooltip icon is visible since at least one extension is installed by
// enterprise) when the user has blocked all extensions on the site.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserBlockedAccess_Enterprise) {}

// Test that the message section only displays the requests access container
// when the user can customize the extensions site access and at least 1+
// extensions added a site access request.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserCustomizedAccess_Extensions) {}

// Test that the message section only displays the requests access container
// when the user can customize the extensions site access and an extension added
// a site access request with a pattern filter that matches the current site.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserCustomizedAccess_RequestsWithPattern) {}

// Test when the user can customize the extensions site access and an extension
// added a site access request with a pattern filter that matches the current
// site after same-origin navigations.
TEST_F(
    ExtensionsMenuMainPageViewUnitTest,
    MessageSection_UserCustomizedAccess_RequestsWithPattern_NavigationBetweenPages) {}

// Tests that an extension's requests access container removes an extension's
// request when the extension is granted site access.
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserCustomizedAccess_ExtensionGrantedSiteAccess) {}

TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserCustomizedAccess_AllowExtension) {}

TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserCustomizedAccess_DismissExtension) {}

// Tests that the message section displays an extension with a site access
// request even if it is not allowed to show requests on the toolbar (extensions
// menu is not considered part of the toolbar for this).
TEST_F(ExtensionsMenuMainPageViewUnitTest,
       MessageSection_UserCustomizedAccess_RequestNotAllowedOnToolbar) {}