#include "components/sync_bookmarks/bookmark_data_type_processor.h"
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/uuid.h"
#include "components/bookmarks/test/test_bookmark_client.h"
#include "components/favicon/core/test/mock_favicon_service.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/features.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/type_entities_count.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/test/mock_commit_queue.h"
#include "components/sync_bookmarks/bookmark_model_view.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 "components/undo/bookmark_undo_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/tree_node_iterator.h"
namespace sync_bookmarks {
namespace {
ASCIIToUTF16;
ElementsAre;
Eq;
IsEmpty;
IsNull;
NiceMock;
NotNull;
Pointer;
SizeIs;
UnorderedElementsAre;
const char kBookmarkBarTag[] = …;
const char kOtherBookmarksTag[] = …;
const char kMobileBookmarksTag[] = …;
const char kBookmarkBarId[] = …;
const char kOtherBookmarksId[] = …;
const char kMobileBookmarksId[] = …;
const char kBookmarksRootId[] = …;
const char kCacheGuid[] = …;
const char kPersistentDataTypeConfigurationTimeMetricName[] = …;
struct BookmarkInfo { … };
MATCHER_P(CommitRequestDataMatchesGuid, uuid, "") { … }
MATCHER_P(TrackedEntityCorrespondsToBookmarkNode, bookmark_node, "") { … }
syncer::UpdateResponseData CreateUpdateResponseData(
const BookmarkInfo& bookmark_info,
const syncer::UniquePosition& unique_position,
int response_version,
const base::Uuid& uuid) { … }
syncer::UpdateResponseData CreateUpdateResponseData(
const BookmarkInfo& bookmark_info,
const syncer::UniquePosition& unique_position,
int response_version) { … }
sync_pb::DataTypeState CreateDataTypeState() { … }
sync_pb::BookmarkMetadata CreateNodeMetadata(
const bookmarks::BookmarkNode* node,
const std::string& server_id,
const syncer::UniquePosition& unique_position =
syncer::UniquePosition::InitialPosition(
syncer::UniquePosition::RandomSuffix())) { … }
sync_pb::BookmarkMetadata CreateUnsyncedNodeMetadata(
const bookmarks::BookmarkNode* node,
const std::string& server_id) { … }
sync_pb::BookmarkModelMetadata CreateMetadataForPermanentNodes(
const BookmarkModelView* bookmark_model) { … }
syncer::UpdateResponseDataList CreateUpdateResponseDataListForPermanentNodes() { … }
void AssertState(const BookmarkDataTypeProcessor* processor,
const std::vector<BookmarkInfo>& bookmarks) { … }
class ProxyCommitQueue : public syncer::CommitQueue { … };
class BookmarkDataTypeProcessorTest : public testing::Test { … };
TEST_F(BookmarkDataTypeProcessorTest, ShouldDoInitialMergeWithZeroBookmarks) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldDoInitialMergeWithOneBookmark) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldFailInitialMergeIfServerPermanentNodeMissing) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldFailInitialMergeAndAvoidPartialDataIfServerPermanentNodeMissing) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldUpdateModelAfterRemoteCreation) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldUpdateModelAfterRemoteUpdate) { … }
TEST_F(
BookmarkDataTypeProcessorTest,
ShouldScheduleSaveAfterRemoteUpdateWithOnlyMetadataChangeAndReflections) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldDecodeSyncMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldDecodeEncodedSyncMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldDecodeEmptyMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldIgnoreNonEmptyMetadataWhileSyncNotDone) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldIgnoreMetadataNotMatchingTheModel) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldIgnoreMetadataIfCacheGuidMismatch) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldUpdateDataTypeStateUponHandlingRemoteUpdates) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldUpdateDataTypeStateUponHandlingInvalidations) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotRecommitEntitiesWhenEncryptionIsUpToDate) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldStopBeforeReceivingRemoteUpdates) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldStopAfterReceivingRemoteUpdates) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldReportNoCountersWhenModelIsNotLoaded) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotCommitEntitiesWithoutLoadedFavicons) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldCommitEntitiesWhileOtherFaviconsLoading) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldReuploadLegacyBookmarksOnStart) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldReportErrorIfIncrementalLocalCreationCrossesMaxCountLimit) { … }
TEST_F(
BookmarkDataTypeProcessorTest,
ShouldReportErrorIfBookmarksCountExceedsLimitOnStartupWhenMetadataMatchesModel) { … }
TEST_F(
BookmarkDataTypeProcessorTest,
ShouldReportErrorIfBookmarksCountExceedsLimitOnStartupWhenMetadataDoesNotMatchModel) { … }
TEST_F(
BookmarkDataTypeProcessorTest,
BookmarkModelShouldWorkNormallyEvenAfterSyncReportedErrorDueToMaxLimitCrossed) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldReportErrorIfBookmarksCountExceedsLimitAfterInitialUpdate) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldReportErrorIfBookmarksCountExceedsLimitAfterIncrementalUpdate) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldReportErrorIfInitialUpdatesCrossMaxCountLimit) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldSaveRemoteUpdatesCountExceedingLimitResultDuringInitialMerge) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldReportErrorIfRemoteBookmarksCountExceededLimitOnLastTry) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldPersistRemoteBookmarksCountExceedingLimitAcrossBrowserRestarts) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldClearMetadataIfStopped) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldClearMetadataIfStoppedUponModelReadyToSync) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldNotClearMetadataIfNotStopped) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotClearMetadataIfStoppedIfPreviouslyStoppedWithClearMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldWipeBookmarksRepeatedlyIfStoppedWithClearMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldWipeBookmarksOnceIfStoppedWithClearMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotWipeBookmarksIfStoppedWithClearMetadataWithoutInitialSyncDone) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotWipeBookmarksIfStoppedWithClearMetadataIfInitialSyncDoneLater) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotWipeBookmarksIfStoppedWithKeepMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotClearMetadataIfStoppedWithoutMetadataInitially) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldNotClearMetadataIfStoppedUponModelReadyToSyncWithoutMetadata) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldWipeBookmarksIfMetadataClearedWhileStopped) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldWipeBookmarksIfMetadataClearedWhileStoppedUponModelReadyToSync) { … }
TEST_F(BookmarkDataTypeProcessorTest, ShouldWipeBookmarksIfCacheGuidMismatch) { … }
TEST_F(BookmarkDataTypeProcessorTest,
ShouldRecordNumUnsyncedEntitiesOnModelReady) { … }
}
}