#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model.h"
#include <memory>
#include "build/chromeos_buildflags.h"
#include "chrome/browser/companion/core/features.h"
#include "chrome/browser/ui/actions/chrome_action_id.h"
#include "chrome/browser/ui/views/side_panel/companion/companion_utils.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model_factory.h"
#include "chrome/browser/ui/toolbar/toolbar_pref_names.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/actions/action_id.h"
#include "ui/actions/actions.h"
#include "ui/base/ui_base_features.h"
namespace {
class PinnedToolbarActionsModelTestObserver
: public PinnedToolbarActionsModel::Observer { … };
}
class PinnedToolbarActionsModelBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest, PinActions) { … }
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest, UnpinActions) { … }
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest,
MovePinnedActions) { … }
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest,
MovePinnedActionsOutOfBoundsDoesNothing) { … }
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest,
MoveUnpinnedActionDoesNothing) { … }
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest,
MovePinnedActionToSameIndexDoesNothing) { … }
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest,
ResetToDefaultResetsToDefault) { … }
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(PinnedToolbarActionsModelBrowserTest,
MigratingSearchCompanionUpdatesModel) {
{
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kPinnedSearchCompanionMigrationComplete, true);
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSidePanelCompanionEntryPinnedToToolbar, true);
EXPECT_EQ(0, observer()->removed_count());
EXPECT_EQ(0, observer()->inserted_count());
EXPECT_EQ(-1, observer()->moved_to_index());
companion::UpdateCompanionDefaultPinnedToToolbarState(browser()->profile());
const base::Value::List& list_1 =
browser()->profile()->GetPrefs()->GetList(prefs::kPinnedActions);
EXPECT_EQ(1u, list_1.size());
}
{
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kPinnedSearchCompanionMigrationComplete, false);
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSidePanelCompanionEntryPinnedToToolbar, false);
EXPECT_EQ(0, observer()->removed_count());
EXPECT_EQ(0, observer()->inserted_count());
EXPECT_EQ(-1, observer()->moved_to_index());
companion::UpdateCompanionDefaultPinnedToToolbarState(browser()->profile());
const base::Value::List& list_1 =
browser()->profile()->GetPrefs()->GetList(prefs::kPinnedActions);
EXPECT_EQ(1u, list_1.size());
}
{
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kPinnedSearchCompanionMigrationComplete, false);
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSidePanelCompanionEntryPinnedToToolbar, true);
EXPECT_EQ(0, observer()->removed_count());
EXPECT_EQ(0, observer()->inserted_count());
EXPECT_EQ(-1, observer()->moved_to_index());
companion::UpdateCompanionDefaultPinnedToToolbarState(browser()->profile());
const base::Value::List& list_1 =
browser()->profile()->GetPrefs()->GetList(prefs::kPinnedActions);
ASSERT_EQ(2u, list_1.size());
EXPECT_EQ(1, observer()->inserted_count());
const std::optional<std::string>& search_companion_string =
actions::ActionIdMap::ActionIdToString(
kActionSidePanelShowSearchCompanion);
ASSERT_EQ("kActionShowChromeLabs", list_1[0].GetString());
EXPECT_EQ(search_companion_string, list_1[1].GetString());
}
}
#endif