chromium/chrome/browser/ui/toolbar/toolbar_actions_model_unittest.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.

#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/toolbar/toolbar_actions_model.h"

#include <stddef.h>

#include <memory>
#include <string>

#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/extension_action_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_user_test_base.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/crx_file/id_util.h"
#include "components/policy/core/common/policy_map.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/pref_names.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/api/extension_action/action_info.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/manifest.h"
#include "extensions/test/test_extension_dir.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace {

ManifestLocation;

// A simple observer that tracks the number of times certain events occur.
class ToolbarActionsModelTestObserver : public ToolbarActionsModel::Observer {};

ToolbarActionsModelTestObserver::ToolbarActionsModelTestObserver(
    ToolbarActionsModel* model)
    :{}

ToolbarActionsModelTestObserver::~ToolbarActionsModelTestObserver() {}

}  // namespace

class ToolbarActionsModelUnitTest
    : public extensions::ExtensionServiceUserTestBase {};

void ToolbarActionsModelUnitTest::Init() {}

void ToolbarActionsModelUnitTest::InitToolbarModelAndObserver() {}

void ToolbarActionsModelUnitTest::TearDown() {}

void ToolbarActionsModelUnitTest::RunEmitUserHistogramsTest(
    int incremented_histogram_count) {}

testing::AssertionResult ToolbarActionsModelUnitTest::AddExtension(
    const scoped_refptr<const extensions::Extension>& extension) {}

testing::AssertionResult ToolbarActionsModelUnitTest::RemoveExtension(
    const scoped_refptr<const extensions::Extension>& extension) {}

testing::AssertionResult ToolbarActionsModelUnitTest::AddActionExtensions() {}

testing::AssertionResult
ToolbarActionsModelUnitTest::AddBrowserActionExtensions() {}

bool ToolbarActionsModelUnitTest::ModelHasActionForId(
    const std::string& id) const {}

testing::AssertionResult ToolbarActionsModelUnitTest::AddAndVerifyExtensions(
    const extensions::ExtensionList& extensions) {}

// A basic test for extensions with browser actions showing up in the toolbar.
TEST_F(ToolbarActionsModelUnitTest, BasicToolbarActionsModelTest) {}

// Test that new extension actions are always visible on installation and
// inserted at the "end" of the visible section.
TEST_F(ToolbarActionsModelUnitTest, NewToolbarExtensionsAreUnpinned) {}

// Test that the model contains all types of extensions, except those which
// should not be displayed on the toolbar (like component extensions).
TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesEnabledSwitch) {}

TEST_F(ToolbarActionsModelUnitTest, PinnedStateIsTransferredToIncognito) {}

TEST_F(ToolbarActionsModelUnitTest,
       MovingPinnedActionsTransfersBetweenIncognito) {}

// Test that enabling extensions incognito with an active incognito profile
// works.
TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarIncognitoEnableExtension) {}

// Test that observers receive no Added notifications until after the
// ExtensionSystem has initialized.
TEST_F(ToolbarActionsModelUnitTest, ModelWaitsForExtensionSystemReady) {}

// Test that user-script extensions show up on the toolbar.
TEST_F(ToolbarActionsModelUnitTest, AddUserScriptExtension) {}

TEST_F(ToolbarActionsModelUnitTest, IsActionPinnedCorrespondsToPinningState) {}

TEST_F(ToolbarActionsModelUnitTest,
       TogglingVisibilityAppendsToPinnedExtensions) {}

TEST_F(ToolbarActionsModelUnitTest, ChangesToPinningNotifiesObserver) {}

TEST_F(ToolbarActionsModelUnitTest, ChangesToPinningSavedInExtensionPrefs) {}

TEST_F(ToolbarActionsModelUnitTest, ChangesToExtensionPrefsReflectedInModel) {}

TEST_F(ToolbarActionsModelUnitTest,
       MismatchInPinnedExtensionPreferencesNotReflectedInModel) {}

TEST_F(ToolbarActionsModelUnitTest, PinnedExtensionsFilteredOnInitialization) {}

TEST_F(ToolbarActionsModelUnitTest, ChangesToPinnedOrderSavedInExtensionPrefs) {}

TEST_F(ToolbarActionsModelUnitTest, PinStateErasedOnUninstallation) {}

TEST_F(ToolbarActionsModelUnitTest, ForcePinnedByPolicy) {}

// Tests that the pin state (and position) for extensions that are unloaded
// (but *not* uninstalled) is preserved, even if the pinning order was modified
// while they were unloaded.
// Regression test for crbug.com/1203899.
TEST_F(ToolbarActionsModelUnitTest, UnloadedExtensionsPinnedStatePreserved) {}

TEST_F(ToolbarActionsModelUnitTest, InitActionList_EmitUserHistograms) {}

TEST_F(ToolbarActionsModelUnitTest, InitActionList_NonUserEmitHistograms) {}