#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 {
const char kBookmarkBarId[] = …;
const char kBookmarkBarTag[] = …;
const char kMobileBookmarksId[] = …;
const char kMobileBookmarksTag[] = …;
const char kOtherBookmarksId[] = …;
const char kOtherBookmarksTag[] = …;
enum class ExpectedRemoteBookmarkUpdateError { … };
syncer::UniquePosition RandomUniquePosition() { … }
std::string GetFakeServerIdFromGUID(const base::Uuid& guid) { … }
sync_pb::BookmarkMetadata CreateNodeMetadata(
const bookmarks::BookmarkNode* node,
const syncer::UniquePosition& unique_position) { … }
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) { … }
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) { … }
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
ShouldUpdateSyncIdWhenRecevingUpdateForNewlyCreatedLocalNode) { … }
TEST_F(
BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
ShouldUpdateSyncIdWhenRecevingUpdateForNewlyCreatedLocalNodeWithClientTag) { … }
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
ShouldRecommitWhenEncryptionIsOutOfDate) { … }
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) { … }
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
ShouldReuploadBookmarkOnEmptyUniquePositionForReflection) { … }
TEST_F(BookmarkRemoteUpdatesHandlerWithInitialMergeTest,
ShouldProcessDifferentEntitiesWithSameGuid) { … }
TEST(BookmarkRemoteUpdatesHandlerTest,
ShouldComputeRightChildNodeIndexForEmptyParent) { … }
TEST(BookmarkRemoteUpdatesHandlerTest, ShouldComputeRightChildNodeIndex) { … }
}
}