chromium/chrome/browser/ui/webui/side_panel/customize_chrome/customize_toolbar/customize_toolbar_handler_unittest.cc

// Copyright 2024 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/webui/side_panel/customize_chrome/customize_toolbar/customize_toolbar_handler.h"

#include "base/memory/raw_ptr.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/mock_callback.h"
#include "chrome/browser/companion/core/features.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser_actions.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model_factory.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/customize_toolbar/customize_toolbar.mojom.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/lens/lens_features.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {
class BrowserContext;
}  // namespace content

namespace {

_;
DoAll;
SaveArg;

class MockPage
    : public side_panel::customize_chrome::mojom::CustomizeToolbarClient {};

class MockPinnedToolbarActionsModel : public PinnedToolbarActionsModel {};

}  // namespace

class CustomizeToolbarHandlerTest : public BrowserWithTestWindowTest {};

TEST_F(CustomizeToolbarHandlerTest, ListCategories) {}

TEST_F(CustomizeToolbarHandlerTest, ListActions) {}

TEST_F(CustomizeToolbarHandlerTest, PinAction) {}

TEST_F(CustomizeToolbarHandlerTest, PinHome) {}

TEST_F(CustomizeToolbarHandlerTest, PinForward) {}

TEST_F(CustomizeToolbarHandlerTest, ActionsChanged) {}

TEST_F(CustomizeToolbarHandlerTest, HomePrefUpdated) {}

TEST_F(CustomizeToolbarHandlerTest, ForwardPrefUpdated) {}

TEST_F(CustomizeToolbarHandlerTest, ResetToDefault) {}

TEST_F(CustomizeToolbarHandlerTest, ActionsUpdatedOnVisibilityChange) {}

class CustomizeToolbarHandlerCompanionTest
    : public CustomizeToolbarHandlerTest {};

#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_CHROMEOS)
TEST_F(CustomizeToolbarHandlerCompanionTest, ListActionsContainsCompanion) {
  std::vector<side_panel::customize_chrome::mojom::ActionPtr> actions;
  base::MockCallback<CustomizeToolbarHandler::ListActionsCallback> callback;
  EXPECT_CALL(callback, Run(_)).Times(1).WillOnce(MoveArg(&actions));
  handler().ListActions(callback.Get());

  const auto contains_action =
      [&actions](side_panel::customize_chrome::mojom::ActionId id) -> bool {
    return std::find_if(
               actions.begin(), actions.end(),
               [id](side_panel::customize_chrome::mojom::ActionPtr& action) {
                 return action->id == id;
               }) != actions.end();
  };

  EXPECT_TRUE(contains_action(
      side_panel::customize_chrome::mojom::ActionId::kShowSearchCompanion));
}
#endif  // BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_CHROMEOS)