chromium/chrome/browser/ui/views/side_panel/side_panel_coordinator_unittest.cc

// Copyright 2022 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/side_panel/side_panel_coordinator.h"

#include <memory>
#include <string>

#include "base/files/file_path.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/icu_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/extensions/api/side_panel/side_panel_api.h"
#include "chrome/browser/extensions/api/side_panel/side_panel_service.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/tabs/public/tab_features.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model_factory.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/browser/ui/ui_features.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/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/side_panel/side_panel.h"
#include "chrome/browser/ui/views/side_panel/side_panel_content_proxy.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_id.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_observer.h"
#include "chrome/browser/ui/views/side_panel/side_panel_registry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_util.h"
#include "chrome/browser/ui/views/side_panel/side_panel_view_state_observer.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/crx_file/id_util.h"
#include "components/lens/lens_features.h"
#include "components/strings/grit/components_strings.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_builder.h"
#include "extensions/test/test_extension_dir.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/views/layout/animating_layout_manager_test_util.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/test/views_test_utils.h"

_;

namespace {

// Creates a basic SidePanelEntry for the given `key` that returns an empty view
// when shown.
std::unique_ptr<SidePanelEntry> CreateEntry(const SidePanelEntry::Key& key) {}

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

}  // namespace

class SidePanelCoordinatorTest : public TestWithBrowserView {};

class MockSidePanelViewStateObserver : public SidePanelViewStateObserver {};

TEST_F(SidePanelCoordinatorTest, ToggleSidePanel) {}

TEST_F(SidePanelCoordinatorTest, ChangeSidePanelWidth) {}

TEST_F(SidePanelCoordinatorTest, ChangeSidePanelWidthMaxMin) {}

TEST_F(SidePanelCoordinatorTest, ChangeSidePanelWidthRTL) {}

TEST_F(SidePanelCoordinatorTest, ChangeSidePanelWidthWindowResize) {}

TEST_F(SidePanelCoordinatorTest, ChangeSidePanelAlignment) {}

// Verify that right and left alignment works the same as when in LTR mode.
TEST_F(SidePanelCoordinatorTest, ChangeSidePanelAlignmentRTL) {}

TEST_F(SidePanelCoordinatorTest, DontNotifySidePanelObserverOfChangingContent) {}

TEST_F(SidePanelCoordinatorTest, NotifyingSidePanelObservers) {}

TEST_F(SidePanelCoordinatorTest, RemovingObserverDoesNotIncrementCount) {}

TEST_F(SidePanelCoordinatorTest, SidePanelToggleWithEntriesTest) {}

TEST_F(SidePanelCoordinatorTest, ShowOpensSidePanel) {}

TEST_F(SidePanelCoordinatorTest, SwapBetweenTabsWithBookmarksOpen) {}

TEST_F(SidePanelCoordinatorTest, SwapBetweenTabsWithReadingListOpen) {}

TEST_F(SidePanelCoordinatorTest, ContextualEntryDeregistered) {}

TEST_F(SidePanelCoordinatorTest, ContextualEntryDeregisteredWhileVisible) {}

// Test that the side panel closes if a contextual entry is deregistered while
// visible when no global entries have been shown since the panel was opened.
TEST_F(
    SidePanelCoordinatorTest,
    ContextualEntryDeregisteredWhileVisibleClosesPanelIfNoLastSeenGlobalEntryExists) {}

TEST_F(SidePanelCoordinatorTest, ShowContextualEntry) {}

TEST_F(SidePanelCoordinatorTest, SwapBetweenTwoContextualEntryWithTheSameId) {}

TEST_F(SidePanelCoordinatorTest,
       SwapBetweenTabsAfterNavigatingToContextualEntry) {}

TEST_F(SidePanelCoordinatorTest, TogglePanelWithContextualEntryShowing) {}

TEST_F(SidePanelCoordinatorTest,
       TogglePanelWithGlobalEntryShowingWithTabSwitch) {}

TEST_F(SidePanelCoordinatorTest,
       TogglePanelWithContextualEntryShowingWithTabSwitch) {}

TEST_F(SidePanelCoordinatorTest,
       SwitchBetweenTabWithGlobalEntryAndTabWithLastActiveContextualEntry) {}

TEST_F(SidePanelCoordinatorTest,
       SwitchBetweenTabWithContextualEntryAndTabWithNoEntry) {}

TEST_F(
    SidePanelCoordinatorTest,
    SwitchBetweenTabWithContextualEntryAndTabWithNoEntryWhenThereIsALastActiveGlobalEntry) {}

TEST_F(SidePanelCoordinatorTest,
       SwitchBackToTabWithPreviouslyVisibleContextualEntry) {}

TEST_F(SidePanelCoordinatorTest,
       SwitchBackToTabWithContextualEntryAfterClosingGlobal) {}

// Verify that side panels maintain individual widths when the
// #side-panel-resizing flag is enabled. In this case, the bookmarks and reading
// list side panels should be able to have independent widths.
TEST_F(SidePanelCoordinatorTest, SidePanelWidthPreference) {}

class TestSidePanelObserver : public SidePanelEntryObserver {};

TEST_F(SidePanelCoordinatorTest,
       EntryDeregistersOnBeingHiddenFromSwitchToOtherEntry) {}

TEST_F(SidePanelCoordinatorTest,
       EntryDeregistersOnBeingHiddenFromSidePanelClose) {}

TEST_F(SidePanelCoordinatorTest, ShouldNotRecreateTheSameEntry) {}

// Side panel closes if the active entry is de-registered when open.
TEST_F(SidePanelCoordinatorTest, GlobalEntryDeregisteredWhenVisible) {}

// Test that a crash does not occur when the browser is closed when the side
// panel view is shown but before the entry to be displayed has finished
// loading. Regression for crbug.com/1408947.
TEST_F(SidePanelCoordinatorTest, BrowserClosedBeforeEntryLoaded) {}

// Test that Show() shows the contextual extension entry if available for the
// current tab. Otherwise it shows the global extension entry. Note: only
// extensions will be able to have their entries exist in both the global and
// contextual registries.
TEST_F(SidePanelCoordinatorTest, ShowGlobalAndContextualExtensionEntries) {}

// Test that a new contextual extension entry gets shown if it's registered for
// the active tab and the global extension entry is showing.
TEST_F(SidePanelCoordinatorTest, RegisterExtensionEntries) {}

// Test that if global or contextual entries are deregistered, and if it exists,
// the global extension entry is shown if the active tab's extension entry is
// deregistered.
TEST_F(SidePanelCoordinatorTest, DeregisterExtensionEntries) {}

// Test that an extension with only contextual entries should behave like other
// contextual entry types when switching tabs.
TEST_F(SidePanelCoordinatorTest, ExtensionEntriesTabSwitchNoGlobalEntry) {}

// Test that an extension with both contextual and global entries should behave
// like global entries when switching tabs and its entries take precedence over
// all other entries except active contextual entries (this case is covered in
// ExtensionEntriesTabSwitchWithActiveContextualEntry).
TEST_F(SidePanelCoordinatorTest, ExtensionEntriesTabSwitchGlobalEntry) {}

// Test that when switching tabs while an extension's entry is showing, the new
// tab's active contextual entry should still take precedence over the
// extensions' entries.
TEST_F(SidePanelCoordinatorTest,
       ExtensionEntriesTabSwitchWithActiveContextualEntry) {}

// Tests that DeregisterAndReturnView returns the deregistered entry's view if
// it exists, whether or not the entry is showing.
TEST_F(SidePanelCoordinatorTest, DeregisterAndReturnView) {}

TEST_F(SidePanelCoordinatorTest, SidePanelTitleUpdates) {}

TEST_F(SidePanelCoordinatorTest, SidePanelPinButtonsHideInGuestMode) {}

// Verifies that clicking the pin button on an extensions side panel, pins the
// extension in ToolbarActionModel.
TEST_F(SidePanelCoordinatorTest, ExtensionSidePanelHasPinButton) {}

class SidePanelCoordinatorLensOverlayTest : public SidePanelCoordinatorTest {};

TEST_F(SidePanelCoordinatorLensOverlayTest,
       ShowMoreInfoButtonWhenCallbackProvided) {}

TEST_F(SidePanelCoordinatorLensOverlayTest,
       HideMoreInfoButtonWhenNoCallbackProvided) {}

// Test that the SidePanelCoordinator behaves and updates corrected when dealing
// with entries that load/display asynchronously.
class SidePanelCoordinatorLoadingContentTest : public SidePanelCoordinatorTest {};

TEST_F(SidePanelCoordinatorLoadingContentTest, ContentDelaysForLoadingContent) {}

TEST_F(SidePanelCoordinatorLoadingContentTest,
       TriggerSwitchToNewEntryDuringContentLoad) {}

TEST_F(SidePanelCoordinatorLoadingContentTest,
       TriggerSwitchToCurrentVisibleEntryDuringContentLoad) {}