chromium/components/saved_tab_groups/saved_tab_group_model_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/saved_tab_groups/saved_tab_group_model.h"

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/rand_util.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/token.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/saved_tab_groups/features.h"
#include "components/saved_tab_groups/saved_tab_group.h"
#include "components/saved_tab_groups/saved_tab_group_model_observer.h"
#include "components/saved_tab_groups/saved_tab_group_sync_bridge.h"
#include "components/saved_tab_groups/saved_tab_group_tab.h"
#include "components/saved_tab_groups/saved_tab_group_test_utils.h"
#include "components/saved_tab_groups/types.h"
#include "components/sync/protocol/saved_tab_group_specifics.pb.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
#include "url/url_constants.h"

namespace tab_groups {

namespace {

IsEmpty;
Not;
Pointee;
UnorderedElementsAre;

MATCHER_P(HasGroupId, guid, "") {}

// Serves to test the functions in SavedTabGroupModelObserver.
class SavedTabGroupModelObserverTest
    : public ::testing::Test,
      public SavedTabGroupModelObserver,
      public ::testing::WithParamInterface<bool> {};

// Serves to test the functions in SavedTabGroupModel.
class SavedTabGroupModelTest : public ::testing::Test,
                               public ::testing::WithParamInterface<bool> {};

// Tests that SavedTabGroupModel::Count holds 3 elements initially.
TEST_P(SavedTabGroupModelTest, InitialCountThree) {}

// Tests that SavedTabGroupModel::Contains returns the 3, the number of starting
// ids added to the model.
TEST_P(SavedTabGroupModelTest, InitialGroupsAreSaved) {}

// Tests that the SavedTabGroupModel::GetIndexOf preserves the order the
// SavedTabGroups were inserted into.
TEST_P(SavedTabGroupModelTest, InitialOrderAdded) {}

// Tests that the SavedTabGroupModel::IsEmpty has elements and once all elements
// are removed is empty.
TEST_P(SavedTabGroupModelTest, ContainsNoElementsOnRemoval) {}

// Tests that the SavedTabGroupModel::Remove removes the correct element given
// an id.
TEST_P(SavedTabGroupModelTest, RemovesCorrectElements) {}

// Tests that the SavedTabGroupModel only adds unique TabGroupIds.
TEST_P(SavedTabGroupModelTest, OnlyAddUniqueElements) {}

// Tests that SavedTabGroupModel::Add adds an extra element into the model and
// keeps the data.
TEST_P(SavedTabGroupModelTest, AddNewElement) {}

// Tests that SavedTabGroupModel::Update updates the correct element if the
// title or color are different.
TEST_P(SavedTabGroupModelTest, UpdateElement) {}

TEST_P(SavedTabGroupModelTest, MakeTabGroupShared) {}

// Tests that the correct tabs are added to the correct position in group 1.
TEST_P(SavedTabGroupModelTest, AddTabToGroup) {}

// Tests that the correct tabs are removed from the correct position in group 1.
TEST_P(SavedTabGroupModelTest, RemoveTabFromGroup) {}

// Tests that a group is removed from the model when the last tab is removed
// from it.
TEST_P(SavedTabGroupModelTest, RemoveLastTabFromGroup) {}

// Tests updating a tab in a saved group.
TEST_P(SavedTabGroupModelTest, UpdateTabInGroup) {}

// Tests that the correct tabs are moved in group 1.
TEST_P(SavedTabGroupModelTest, MoveTabInGroup) {}

TEST_P(SavedTabGroupModelTest, MoveElement) {}

TEST_P(SavedTabGroupModelTest, ShouldDistinguishSavedAndSharedGroups) {}

TEST_P(SavedTabGroupModelTest, LoadStoredEntriesPopulatesModel) {}

// Tests that merging a group with the same group_id changes the state of the
// object correctly.
TEST_P(SavedTabGroupModelTest, MergeGroupsFromModel) {}

TEST_P(SavedTabGroupModelTest, MergePinnedGroupRetainPosition) {}

TEST_P(SavedTabGroupModelTest, MergeUnpinnedGroupRetainUnpinned) {}

// Tests that merging a tab with the same tab_id changes the state of the object
// correctly.
TEST_P(SavedTabGroupModelTest, MergeTabsFromModel) {}

// Tests that groups inserted in the model are in order stay inserted in sorted
// order.
TEST_P(SavedTabGroupModelTest, GroupsSortedWithInOrderPositions) {}

// Tests that groups inserted in the model out of order are still inserted in
// sorted order.
TEST_P(SavedTabGroupModelTest, GroupsSortedWithOutOfOrderPositions) {}

// Tests that groups inserted in the model with gaps between the positions are
// still inserted in sorted order.
TEST_P(SavedTabGroupModelTest, GroupsSortedWithGapsInPositions) {}

// Tests that groups inserted in the model with gaps and in decreasing order
// between the positions are still inserted in increasing sorted order.
TEST_P(SavedTabGroupModelTest, GroupsSortedWithDecreasingPositions) {}

// Tests that groups inserted in the model with a more recent update time take
// precedence over groups with the same position.
TEST_P(SavedTabGroupModelTest, GroupWithSamePositionSortedByUpdateTime) {}

// Tests that groups inserted in the model with no position are inserted at the
// back of the model and have their position set to the last index at the time
// they were inserted.
TEST_P(SavedTabGroupModelTest, GroupsWithNoPositionInsertedAtEnd) {}

// Expect the pinned group is added to the front of the list.
TEST_P(SavedTabGroupModelTest, AddPinnedGroup) {}

// Expect pin group to move the 2nd group to the front of the list.
TEST_P(SavedTabGroupModelTest, PinGroup) {}

// Expect unpin group to move the front group to the 2nd of the list.
TEST_P(SavedTabGroupModelTest, UnpinGroup) {}

TEST_P(SavedTabGroupModelTest, MigrateSavedTabGroup2FromV1) {}

// Tests that SavedTabGroupModelObserver::Added passes the correct element from
// the model.
TEST_P(SavedTabGroupModelObserverTest, AddElement) {}

// Tests that SavedTabGroupModelObserver::Removed passes the correct
// element from the model.
TEST_P(SavedTabGroupModelObserverTest, RemovedElement) {}

// Tests that SavedTabGroupModelObserver::Updated passes the correct
// element from the model.
TEST_P(SavedTabGroupModelObserverTest, UpdatedElement) {}

TEST_P(SavedTabGroupModelObserverTest, MakeTabGroupShared) {}

// Tests that SavedTabGroupModelObserver::AddedFromSync passes the correct
// element from the model.
TEST_P(SavedTabGroupModelObserverTest, AddElementFromSync) {}

// Tests that SavedTabGroupModelObserver::RemovedFromSync passes the correct
// element from the model.
TEST_P(SavedTabGroupModelObserverTest, RemovedElementFromSync) {}

// Tests that SavedTabGroupModelObserver::UpdatedFromSync passes the correct
// element from the model.
TEST_P(SavedTabGroupModelObserverTest, UpdatedElementFromSync) {}

// Verify that SavedTabGroupModel::OnGroupClosedInTabStrip passes the correct
// index.
TEST_P(SavedTabGroupModelObserverTest, OnGroupClosedInTabStrip) {}

// Tests that SavedTabGroupModelObserver::Moved passes the correct
// element from the model.
TEST_P(SavedTabGroupModelObserverTest, MoveElement) {}

TEST_P(SavedTabGroupModelObserverTest, ReordedTabsUpdatePositions) {}

TEST_P(SavedTabGroupModelObserverTest, GetGroupContainingTab) {}

// Toggle pin state should trigger SavedTabGroupUpdatedLocally.
TEST_P(SavedTabGroupModelObserverTest, TogglePinState) {}

TEST_P(SavedTabGroupModelObserverTest, MigrateSavedTabGroupsFromV1) {}

TEST_P(SavedTabGroupModelObserverTest, UpdateLocalCacheGuid) {}

TEST_P(SavedTabGroupModelObserverTest, UpdateLocalCacheGuidForTabs) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

}  // namespace

}  // namespace tab_groups