chromium/components/sync_bookmarks/bookmark_remote_updates_handler_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_remote_updates_handler.h"

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

#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.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_uuids.h"
#include "components/bookmarks/common/bookmark_metrics.h"
#include "components/favicon/core/test/mock_favicon_service.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/hash_util.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/model/conflict_resolution.h"
#include "components/sync/protocol/bookmark_model_metadata.pb.h"
#include "components/sync/protocol/bookmark_specifics.pb.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/unique_position.pb.h"
#include "components/sync_bookmarks/bookmark_model_merger.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_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"

ASCIIToUTF16;
_;
AnyOf;
ElementsAre;
Eq;
IsNull;
NotNull;

namespace sync_bookmarks {

namespace {

// The parent tag for children of the root entity. Entities with this parent are
// referred to as top level entities.
const char kBookmarkBarId[] =;
const char kBookmarkBarTag[] =;
const char kMobileBookmarksId[] =;
const char kMobileBookmarksTag[] =;
const char kOtherBookmarksId[] =;
const char kOtherBookmarksTag[] =;

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

syncer::UniquePosition RandomUniquePosition() {}

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

// |node| must not be nullptr.
sync_pb::BookmarkMetadata CreateNodeMetadata(
    const bookmarks::BookmarkNode* node,
    const syncer::UniquePosition& unique_position) {}

// |node| must not be nullptr.
sync_pb::BookmarkMetadata CreatePermanentNodeMetadata(
    const bookmarks::BookmarkNode* node,
    const std::string& server_id) {}

sync_pb::BookmarkModelMetadata CreateMetadataForPermanentNodes(
    const BookmarkModelView* bookmark_model) {}

syncer::UpdateResponseData CreateTombstoneResponseData(const base::Uuid& guid,
                                                       int version) {}

syncer::UpdateResponseData CreateUpdateResponseData(
    const base::Uuid& guid,
    const base::Uuid& parent_guid,
    const std::string& title,
    int version,
    const syncer::UniquePosition& unique_position) {}

// Overload that assign a random position. Should only be used when the title,
// version and position are irrelevant.
syncer::UpdateResponseData CreateUpdateResponseData(
    const base::Uuid& guid,
    const base::Uuid& parent_guid) {}

syncer::UpdateResponseData CreateBookmarkRootUpdateData() {}

syncer::UpdateResponseData CreatePermanentFolderUpdateData(
    const std::string& id,
    const std::string& tag) {}

syncer::UpdateResponseDataList CreatePermanentFoldersUpdateData() {}

class BookmarkRemoteUpdatesHandlerWithInitialMergeTest : public testing::Test {};

TEST(BookmarkRemoteUpdatesHandlerReorderUpdatesTest, ShouldIgnoreRootNode) {}

TEST(BookmarkRemoteUpdatesHandlerReorderUpdatesTest,
     ShouldIgnorePermanentNodes) {}

TEST(BookmarkRemoteUpdatesHandlerReorderUpdatesTest,
     ShouldIgnoreInvalidSpecifics) {}

TEST(BookmarkRemoteUpdatesHandlerReorderUpdatesTest,
     ShouldReorderParentsUpdateBeforeChildrenAndBothBeforeDeletions) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldProcessRandomlyOrderedCreations) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldLogFreshnessToUma) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldProcessRandomlyOrderedDeletions) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldProcessDeletionWithServerIdOnly) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIgnoreRemoteCreationWithInvalidGuidInSpecifics) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIgnoreRemoteCreationWithUnexpectedGuidInSpecifics) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIgnoreMisbehavingServerWithRemoteGuidUpdate) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIgnoreMisbehavingServerWithPermanentNodeUpdateWithoutServerTag) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldPositionRemoteCreations) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldPositionRemoteMovesToTheLeft) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldPositionRemoteMovesToTheRight) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldPositionRemoteReparenting) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIgnoreNodeIfMissingParentNode) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIgnoreNodeIfParentIsNotFolder) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldMergeFaviconUponRemoteCreationsWithFavicon) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldDeleteFaviconUponRemoteCreationsWithoutFavicon) {}

// This tests the case when a local creation is successfully committed to the
// server but the commit respone isn't received for some reason. Further updates
// to that entity should update the sync id in the tracker.
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldUpdateSyncIdWhenRecevingUpdateForNewlyCreatedLocalNode) {}

// Same as above for bookmarks created with client tags.
TEST_F(
    BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
    ShouldUpdateSyncIdWhenRecevingUpdateForNewlyCreatedLocalNodeWithClientTag) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldRecommitWhenEncryptionIsOutOfDate) {}

// Tests that recommit will be initiated in case when there is a local tombstone
// and server's update has out of date encryption.
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldRecommitWhenEncryptionIsOutOfDateOnConflict) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldRecommitWhenGotNewEncryptionRequirements) {}

TEST_F(
    BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
    ShouldNotRecommitWhenEncryptionKeyNameMistmatchWithConflictWithDeletions) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldNotRecommitUptoDateEntitiesWhenGotNewEncryptionRequirements) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldResolveConflictBetweenLocalAndRemoteDeletionsByMatchingThem) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldResolveConflictBetweenLocalUpdateAndRemoteDeletionWithLocal) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldResolveConflictBetweenLocalDeletionAndRemoteUpdateByRemote) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldResolveConflictBetweenLocalAndRemoteUpdatesWithMatchingThem) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldResolveConflictBetweenLocalAndRemoteUpdatesWithRemote) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldReuploadOnEmptyUniquePositionOnUpdateWithSameSpecifics) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIncrementSequenceNumberOnConflict) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldIncrementSequenceNumberOnUpdate) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldReuploadBookmarkOnEmptyUniquePosition) {}

// Tests that the reflection which doesn't have |unique_position| in specifics
// will be reuploaded.
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldReuploadBookmarkOnEmptyUniquePositionForReflection) {}

TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
       ShouldProcessDifferentEntitiesWithSameGuid) {}

TEST(BookmarkRemoteUpdatesHandlerTest,
     ShouldComputeRightChildNodeIndexForEmptyParent) {}

TEST(BookmarkRemoteUpdatesHandlerTest, ShouldComputeRightChildNodeIndex) {}

}  // namespace

}  // namespace sync_bookmarks