#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/hash/hash.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/string_util.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/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/account_bookmark_sync_service_factory.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "chrome/browser/sync/local_or_syncable_bookmark_sync_service_factory.h"
#include "chrome/browser/sync/sync_invalidations_service_factory.h"
#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include "chrome/browser/sync/test/integration/committed_all_nudged_changes_checker.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/url_and_title.h"
#include "components/bookmarks/common/bookmark_metrics.h"
#include "components/browser_sync/browser_sync_switches.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/command_line_switches.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/engine/bookmark_update_preprocessing.h"
#include "components/sync/engine/cycle/entity_change_metric_recording.h"
#include "components/sync/engine/loopback_server/loopback_server_entity.h"
#include "components/sync/invalidations/interested_data_types_handler.h"
#include "components/sync/invalidations/sync_invalidations_service.h"
#include "components/sync/protocol/bookmark_specifics.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/sync_entity.pb.h"
#include "components/sync/service/sync_service_impl.h"
#include "components/sync/service/sync_user_settings.h"
#include "components/sync/test/bookmark_entity_builder.h"
#include "components/sync/test/entity_builder_factory.h"
#include "components/sync/test/fake_server.h"
#include "components/sync/test/fake_server_http_post_provider.h"
#include "components/sync/test/fake_server_verifier.h"
#include "components/sync/test/test_matchers.h"
#include "components/sync_bookmarks/bookmark_sync_service.h"
#include "components/sync_bookmarks/switches.h"
#include "components/sync_device_info/fake_device_info_sync_service.h"
#include "components/undo/bookmark_undo_service.h"
#include "components/version_info/version_info.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_launcher.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_scale_factor.h"
namespace {
BookmarkModel;
BookmarkNode;
AddFolder;
AddURL;
BookmarkFaviconLoadedChecker;
BookmarkModelMatchesFakeServerChecker;
BookmarksTitleChecker;
BookmarksUrlChecker;
BookmarksUuidChecker;
CheckHasNoFavicon;
ContainsBookmarkNodeWithUuid;
CountBookmarksWithTitlesMatching;
CountBookmarksWithUrlsMatching;
CountFoldersWithTitlesMatching;
Create1xFaviconFromPNGFile;
CreateFavicon;
GetBookmarkBarNode;
GetBookmarkModel;
GetBookmarkUndoService;
GetOtherNode;
GetUniqueNodeByURL;
IsFolderWithTitle;
IsFolderWithTitleAndChildrenAre;
IsUrlBookmarkWithTitleAndUrl;
Move;
Remove;
SetFavicon;
SetTitle;
BookmarkGeneration;
MatchesDeletionOrigin;
AllOf;
Contains;
Each;
ElementsAre;
Eq;
IsEmpty;
IsNull;
Not;
NotNull;
Pointee;
SizeIs;
const int kSingleProfileIndex = …;
#if !BUILDFLAG(IS_ANDROID)
const char kBookmarkGuid[] = …;
#endif
const char kBookmarkTitle[] = …;
const char kBookmarkPageUrl[] = …;
MATCHER(HasUniquePosition, "") { … }
class FakeDeviceInfoSyncServiceWithInvalidations
: public syncer::FakeDeviceInfoSyncService,
public syncer::InterestedDataTypesHandler { … };
std::unique_ptr<KeyedService> BuildFakeDeviceInfoSyncService(
content::BrowserContext* context) { … }
class BookmarksDataTypeErrorChecker : public SingleClientStatusChangeChecker { … };
class SingleClientBookmarksSyncTest : public SyncTest { … };
class SingleClientBookmarksSyncTestWithEnabledReuploadBookmarks
: public SyncTest { … };
class SingleClientBookmarksSyncTestWithDisabledReuploadBookmarks
: public SyncTest { … };
class SingleClientBookmarksSyncTestWithEnabledReuploadPreexistingBookmarks
: public SingleClientBookmarksSyncTest { … };
class SingleClientBookmarksThrottlingSyncTest : public SyncTest { … };
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, Sanity) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, CommitLocalCreations) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, InjectedBookmark) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
DownloadTwoPre2015BookmarksWithSameItemId) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
DownloadLegacyUppercaseGuid2016BookmarksAndCommit) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
DownloadModernBookmarkCollidingPre2015BookmarkId) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
SetFaviconHiDPIDifferentCodec) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, DeleteFaviconFromSync) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, OneFolderRemovedEvent) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
BookmarkAllNodesRemovedEvent) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, DownloadDeletedBookmark) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
DownloadModifiedBookmark) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, DownloadBookmarkFolder) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
DownloadLegacyBookmarkFolder) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldCommitBookmarksWithIllegalServerNames) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldCreateLocalBookmarksWithIllegalServerNames) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldTruncateBlanksWhenMatchingTitles) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldTruncateLongTitles) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
DownloadBookmarkFoldersWithPositions) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest, E2E_ONLY(SanitySetup)) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTest,
RemoveRightAfterAddShouldNotSendCommitRequestsOrTombstones) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
PRE_PersistProgressMarkerOnRestart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
PersistProgressMarkerOnRestart) { … }
#endif
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ApplyRemoteCreationWithValidUuid) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ApplyRemoteCreationWithoutValidGUID) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ApplyRemoteCreationWithoutValidGUIDOrOCII) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
MergeRemoteCreationWithValidUuid) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldStartTrackingRestoredBookmark) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
MergeRemoteCreationWithoutValidGUID) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
MergeRemoteCreationWithoutValidGUIDOrOCII) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
MergeRemoteUpdateWithValidGUID) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTest,
ShouldReportErrorIfIncrementalLocalCreationCrossesMaxCountLimit) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldReportErrorIfBookmarksCountExceedsLimitOnStartup) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTest,
ShouldReportErrorIfBookmarksCountExceedsLimitAfterInitialUpdate) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTest,
ShouldReportErrorIfBookmarksCountExceedsLimitAfterIncrementalUpdate) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldReportErrorIfInitialUpdatesCrossMaxCountLimit) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithDisabledReuploadBookmarks,
PRE_ShouldNotReploadUponFaviconLoad) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
PRE_ShouldUploadUnsyncedEntityAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
ShouldUploadUnsyncedEntityAfterRestart) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithDisabledReuploadBookmarks,
ShouldNotReploadUponFaviconLoad) { … }
#endif
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledReuploadBookmarks,
ShouldReuploadBookmarkAfterInitialMerge) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledReuploadPreexistingBookmarks,
PRE_ShouldReuploadForOldClients) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledReuploadPreexistingBookmarks,
ShouldReuploadForOldClients) { … }
#endif
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledReuploadBookmarks,
ShouldReuploadBookmarkWithFaviconOnInitialMerge) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledReuploadBookmarks,
ShouldReuploadUniquePositionOnIncrementalChange) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksSyncTest,
CommitLocalCreationWithClientTag) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksThrottlingSyncTest, DepleteQuota) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksThrottlingSyncTest,
DepletedQuotaDoesNotStopCommitCycle) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksThrottlingSyncTest,
DoNotDepleteQuota) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksThrottlingSyncTest,
DepleteQuotaAndRecover) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
class SingleClientBookmarksWithAccountStorageSyncTest
: public SingleClientBookmarksSyncTest { … };
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksWithAccountStorageSyncTest,
ShouldDownloadDataUponSigninAndClearUponSignout) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksWithAccountStorageSyncTest,
ShouldHandleMovesAcrossStorageBoundaries) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksWithAccountStorageSyncTest,
ShouldExposeDuplicatedBookmarksAfterTurningSyncOffAndSignIn) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksWithAccountStorageSyncTest,
PRE_PersistAccountBookmarksAcrossRestarts) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksWithAccountStorageSyncTest,
PersistAccountBookmarksAcrossRestarts) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksWithAccountStorageSyncTest,
PRE_ShouldPersistIfInitialUpdatesCrossMaxCountLimit) { … }
IN_PROC_BROWSER_TEST_F(SingleClientBookmarksWithAccountStorageSyncTest,
ShouldPersistIfInitialUpdatesCrossMaxCountLimit) { … }
#endif
#if !BUILDFLAG(IS_ANDROID)
class SingleClientBookmarksSyncTestWithEnabledMigrateSyncingUserToSignedIn
: public SingleClientBookmarksWithAccountStorageSyncTest { … };
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledMigrateSyncingUserToSignedIn,
PRE_SyncToSigninMigration) { … }
IN_PROC_BROWSER_TEST_F(
SingleClientBookmarksSyncTestWithEnabledMigrateSyncingUserToSignedIn,
SyncToSigninMigration) { … }
#endif
#endif
}