chromium/components/sync_bookmarks/bookmark_model_merger_unittest.cc

// Copyright 2018 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/sync_bookmarks/bookmark_model_merger.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/uuid.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/bookmark_uuids.h"
#include "components/favicon/core/test/mock_favicon_service.h"
#include "components/sync/base/features.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync_bookmarks/bookmark_model_view.h"
#include "components/sync_bookmarks/bookmark_specifics_conversions.h"
#include "components/sync_bookmarks/switches.h"
#include "components/sync_bookmarks/synced_bookmark_tracker.h"
#include "components/sync_bookmarks/synced_bookmark_tracker_entity.h"
#include "components/sync_bookmarks/test_bookmark_model_view.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
Eq;
IsEmpty;
IsNull;
NotNull;
UnorderedElementsAre;

namespace sync_bookmarks {

namespace {

MATCHER_P(HasTitle, title, "") {}

// Copy of BookmarksUuidDuplicates.
enum class ExpectedBookmarksUuidDuplicates {};

const char kBookmarkBarId[] =;
const char kBookmarkBarTag[] =;

// Fork of enum RemoteBookmarkUpdateError.
enum class ExpectedRemoteBookmarkUpdateError {};

// |*arg| must be of type std::vector<std::unique_ptr<bookmarks::BookmarkNode>>.
MATCHER_P(ElementRawPointersAre, expected_raw_ptr, "") {}

// |*arg| must be of type std::vector<std::unique_ptr<bookmarks::BookmarkNode>>.
MATCHER_P2(ElementRawPointersAre, expected_raw_ptr0, expected_raw_ptr1, "") {}

base::Uuid BookmarkBarUuid() {}

// Returns a sync ID mimic-ing what a real server could return, which means it
// generally opaque for the client but deterministic given |uuid|, because the
// sync ID is roughly a hashed UUID, at least in normal circumnstances where the
// UUID is used either as client tag hash or as originator client item ID.
std::string GetFakeServerIdFromUuid(const base::Uuid& uuid) {}

class UpdateResponseDataBuilder {};

syncer::UpdateResponseData CreateUpdateResponseData(
    const base::Uuid& uuid,
    const base::Uuid& parent_uuid,
    const std::string& title,
    const std::string& url,
    bool is_folder,
    const syncer::UniquePosition& unique_position,
    const std::string& icon_url = std::string(),
    const std::string& icon_data = std::string()) {}

syncer::UpdateResponseData CreateBookmarkBarNodeUpdateData() {}

syncer::UniquePosition PositionOf(const bookmarks::BookmarkNode* node,
                                  const SyncedBookmarkTracker& tracker) {}

bool PositionsInTrackerMatchModel(const bookmarks::BookmarkNode* node,
                                  const SyncedBookmarkTracker& tracker) {}

std::unique_ptr<SyncedBookmarkTracker> Merge(
    syncer::UpdateResponseDataList updates,
    BookmarkModelView* bookmark_model) {}

static syncer::UniquePosition MakeRandomPosition() {}

}  // namespace

TEST(BookmarkModelMergerTest, ShouldMergeLocalAndRemoteModels) {}

TEST(BookmarkModelMergerTest, ShouldMergeRemoteReorderToLocalModel) {}

TEST(BookmarkModelMergerTest, ShouldIgnoreManagedNodes) {}

TEST(BookmarkModelMergerTest, ShouldIgnoreUnsyncableNodes) {}

// Regression test for crbug.com/329278277. A UUID collision with an unsyncable
// node is a common scenario for the case where BookmarkModelMerger is being
// exercised for account bookmarks, while local unsyncable bookmarks contain an
// exact copy of the server-side updates as a result of sync-the-feature having
// been previously turned on and later off.
TEST(BookmarkModelMergerTest, ShouldIgnoreUnsyncableNodeWithCollidingUuid) {}

TEST(BookmarkModelMergerTest, ShouldMergeFaviconsForRemoteNodesOnly) {}

// This tests that canonical titles produced by legacy clients are properly
// matched. Legacy clients append blank space to empty titles.
TEST(BookmarkModelMergerTest,
     ShouldMergeLocalAndRemoteNodesWhenRemoteHasLegacyCanonicalTitle) {}

// This tests that truncated titles produced by legacy clients are properly
// matched.
TEST(BookmarkModelMergerTest,
     ShouldMergeLocalAndRemoteNodesWhenRemoteHasLegacyTruncatedTitle) {}

TEST(BookmarkModelMergerTest,
     ShouldMergeNodesWhenRemoteHasLegacyTruncatedTitleInFullTitle) {}

// This test checks that local node with truncated title will merge with remote
// node which has full title.
TEST(BookmarkModelMergerTest,
     ShouldMergeLocalAndRemoteNodesWhenLocalHasLegacyTruncatedTitle) {}

TEST(BookmarkModelMergerTest, ShouldMergeAndUseRemoteUuid) {}

TEST(BookmarkModelMergerTest,
     ShouldMergeAndKeepOldUuidWhenRemoteUuidIsInvalid) {}

TEST(BookmarkModelMergerTest, ShouldMergeBookmarkByUuid) {}

TEST(BookmarkModelMergerTest, ShouldMergeBookmarkByUuidAndReparent) {}

TEST(BookmarkModelMergerTest, ShouldMergeFolderByUuidAndNotSemantics) {}

TEST(BookmarkModelMergerTest, ShouldIgnoreChildrenForNonFolderNodes) {}

TEST(
    BookmarkModelMergerTest,
    ShouldIgnoreFolderSemanticsMatchAndLaterMatchByUuidWithSemanticsNodeFirst) {}

TEST(BookmarkModelMergerTest,
     ShouldIgnoreFolderSemanticsMatchAndLaterMatchByUuidWithUuidNodeFirst) {}

TEST(BookmarkModelMergerTest, ShouldReplaceBookmarkUuidWithConflictingURLs) {}

TEST(BookmarkModelMergerTest, ShouldReplaceBookmarkUuidWithConflictingTypes) {}

TEST(BookmarkModelMergerTest,
     ShouldReplaceBookmarkUuidWithConflictingTypesAndLocalChildren) {}

// Tests that the UUID-based matching algorithm handles well the case where a
// local bookmark matches a remote bookmark that is orphan. In this case the
// remote node should be ignored and the local bookmark included in the merged
// tree.
TEST(BookmarkModelMergerTest, ShouldIgnoreRemoteUuidIfOrphanNode) {}

// Tests that the UUID-based matching algorithm handles well the case where a
// local bookmark matches a remote bookmark that contains invalid specifics
// (e.g. invalid URL). In this case the remote node should be ignored and the
// local bookmark included in the merged tree.
TEST(BookmarkModelMergerTest, ShouldIgnoreRemoteUuidIfInvalidSpecifics) {}

// Tests that updates with a UUID that is different to originator client item ID
// are ignored.
TEST(BookmarkModelMergerTest, ShouldIgnoreRemoteUpdateWithInvalidUuid) {}

// Regression test for crbug.com/1050776. Verifies that computing the unique
// position does not crash when processing local creation of bookmark during
// initial merge.
TEST(BookmarkModelMergerTest,
     ShouldProcessLocalCreationWithUntrackedPredecessorNode) {}

TEST(BookmarkModelMergerTest, ShouldLogMetricsForInvalidSpecifics) {}

TEST(BookmarkModelMergerTest, ShouldLogMetricsForChildrenOfNonFolder) {}

TEST(BookmarkModelMergerTest, ShouldLogMetricsForChildrenOfOrphanUpdates) {}

TEST(BookmarkModelMergerTest, ShouldLogMetricsForUnsupportedServerTag) {}

TEST(BookmarkModelMergerTest, ShouldLogMetricsForkDescendantOfRootNode) {}

TEST(BookmarkModelMergerTest, ShouldRemoveMatchingDuplicatesByUuid) {}

TEST(BookmarkModelMergerTest, ShouldRemoveDifferentDuplicatesByUuid) {}

TEST(BookmarkModelMergerTest, ShouldRemoveMatchingFolderDuplicatesByUuid) {}

TEST(BookmarkModelMergerTest, ShouldRemoveDifferentFolderDuplicatesByUuid) {}

// This tests ensures maximum depth of the bookmark tree is not exceeded. This
// prevents a stack overflow.
TEST(BookmarkModelMergerTest, ShouldEnsureLimitDepthOfTree) {}

TEST(BookmarkModelMergerTest, ShouldReuploadBookmarkOnEmptyUniquePosition) {}

TEST(BookmarkModelMergerTest, ShouldRemoveDifferentTypeDuplicatesByUuid) {}

TEST(BookmarkModelMergerTest, ShouldReportTimeMetrics) {}

}  // namespace sync_bookmarks