#include "chrome/browser/sync/test/integration/bookmarks_helper.h"
#include <stddef.h>
#include <functional>
#include <memory>
#include <optional>
#include <set>
#include <vector>
#include "base/containers/stack.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/types/optional_util.h"
#include "base/uuid.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/fake_server_match_status_checker.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/undo/bookmark_undo_service_factory.h"
#include "chrome/common/chrome_paths.h"
#include "components/bookmarks/browser/bookmark_client.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/common/bookmark_metrics.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_util.h"
#include "components/sync/base/unique_position.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/protocol/unique_position.pb.h"
#include "components/sync/service/sync_service_impl.h"
#include "components/sync/test/entity_builder_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/models/tree_node_iterator.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep.h"
BookmarkModel;
BookmarkNode;
namespace bookmarks_helper {
namespace {
const char kBookmarkBarTag[] = …;
const char kSyncedBookmarksTag[] = …;
const char kOtherBookmarksTag[] = …;
const BookmarkNode* GetPermanentNodeForServerTag(
int profile_index,
const std::string& server_defined_unique_tag) { … }
void ApplyBookmarkFavicon(
const BookmarkNode* bookmark_node,
favicon::FaviconService* favicon_service,
const GURL& icon_url,
const scoped_refptr<base::RefCountedMemory>& bitmap_data) { … }
class FaviconChangeObserver : public bookmarks::BookmarkModelObserver { … };
size_t CountNodesWithTitlesMatching(BookmarkModel* model,
BookmarkNode::Type node_type,
const std::u16string& title) { … }
size_t CountNodes(BookmarkModel* model, BookmarkNode::Type node_type) { … }
bool FaviconRawBitmapsMatch(const SkBitmap& bitmap_a,
const SkBitmap& bitmap_b) { … }
struct FaviconData { … };
std::optional<FaviconData> GetFaviconData(BookmarkModel* model,
const BookmarkNode* node) { … }
void SetFaviconImpl(Profile* profile,
const BookmarkNode* node,
const GURL& icon_url,
const gfx::Image& image,
FaviconSource favicon_source) { … }
void ExpireFaviconImpl(Profile* profile, const BookmarkNode* node) { … }
void OnGotFaviconData(
base::OnceClosure callback,
favicon_base::FaviconRawBitmapResult* output_bitmap_result,
const favicon_base::FaviconRawBitmapResult& bitmap_result) { … }
void DeleteFaviconMappingsImpl(Profile* profile,
const BookmarkNode* node,
FaviconSource favicon_source) { … }
bool FaviconsMatch(BookmarkModel* model_a,
BookmarkModel* model_b,
const BookmarkNode* node_a,
const BookmarkNode* node_b) { … }
bool NodesMatch(const BookmarkNode* node_a, const BookmarkNode* node_b) { … }
bool BookmarkModelsMatch(BookmarkModel* model_a, BookmarkModel* model_b) { … }
std::vector<const BookmarkNode*> GetAllBookmarkNodes(
const BookmarkModel* model) { … }
void TriggerAllFaviconLoading(BookmarkModel* model) { … }
}
testing::Matcher<std::unique_ptr<bookmarks::BookmarkNode>>
IsFolderWithTitleAndChildren(
const std::string& title,
testing::Matcher<BookmarkNode::TreeNodes> children_matcher) { … }
BookmarkUndoService* GetBookmarkUndoService(int index) { … }
BookmarkModel* GetBookmarkModel(int index) { … }
const BookmarkNode* GetBookmarkBarNode(int index) { … }
const BookmarkNode* GetOtherNode(int index) { … }
const BookmarkNode* GetSyncedBookmarksNode(int index) { … }
const BookmarkNode* GetManagedNode(int index) { … }
const BookmarkNode* AddURL(int profile,
const std::string& title,
const GURL& url) { … }
const BookmarkNode* AddURL(int profile,
size_t index,
const std::string& title,
const GURL& url) { … }
const BookmarkNode* AddURL(int profile,
const BookmarkNode* parent,
size_t index,
const std::string& title,
const GURL& url) { … }
const BookmarkNode* AddFolder(int profile, const std::string& title) { … }
const BookmarkNode* AddFolder(int profile,
size_t index,
const std::string& title) { … }
const BookmarkNode* AddFolder(int profile,
const BookmarkNode* parent,
size_t index,
const std::string& title) { … }
void SetTitle(int profile,
const BookmarkNode* node,
const std::string& new_title) { … }
void SetFavicon(int profile,
const BookmarkNode* node,
const GURL& icon_url,
const gfx::Image& image,
FaviconSource favicon_source) { … }
void ExpireFavicon(int profile, const BookmarkNode* node) { … }
void CheckFaviconExpired(int profile, const GURL& icon_url) { … }
void CheckHasNoFavicon(int profile, const GURL& page_url) { … }
void DeleteFaviconMappings(int profile,
const BookmarkNode* node,
FaviconSource favicon_source) { … }
const BookmarkNode* SetURL(int profile,
const BookmarkNode* node,
const GURL& new_url) { … }
void Move(int profile,
const BookmarkNode* node,
const BookmarkNode* new_parent,
size_t index) { … }
void Remove(int profile, const BookmarkNode* parent, size_t index) { … }
void SortChildren(int profile, const BookmarkNode* parent) { … }
void ReverseChildOrder(int profile, const BookmarkNode* parent) { … }
bool ModelsMatch(int profile_a, int profile_b) { … }
bool AllModelsMatch() { … }
bool ContainsDuplicateBookmarks(int profile) { … }
bool HasNodeWithURL(int profile, const GURL& url) { … }
const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) { … }
size_t CountAllBookmarks(int profile) { … }
size_t CountBookmarksWithTitlesMatching(int profile, const std::string& title) { … }
size_t CountBookmarksWithUrlsMatching(int profile, const GURL& url) { … }
size_t CountFoldersWithTitlesMatching(int profile, const std::string& title) { … }
bool ContainsBookmarkNodeWithUuid(int profile, const base::Uuid& uuid) { … }
gfx::Image CreateFavicon(SkColor color) { … }
gfx::Image Create1xFaviconFromPNGFile(const std::string& path) { … }
std::string IndexedURL(size_t i) { … }
std::string IndexedURLTitle(size_t i) { … }
std::string IndexedFolderName(size_t i) { … }
std::string IndexedSubfolderName(size_t i) { … }
std::string IndexedSubsubfolderName(size_t i) { … }
std::unique_ptr<syncer::LoopbackServerEntity> CreateBookmarkServerEntity(
const std::string& title,
const GURL& url) { … }
AnyBookmarkChangeObserver::AnyBookmarkChangeObserver(
const base::RepeatingClosure& cb)
: … { … }
AnyBookmarkChangeObserver::~AnyBookmarkChangeObserver() = default;
void AnyBookmarkChangeObserver::BookmarkModelChanged() { … }
void AnyBookmarkChangeObserver::BookmarkNodeFaviconChanged(
const bookmarks::BookmarkNode* node) { … }
BookmarkModelStatusChangeChecker::BookmarkModelStatusChangeChecker() = default;
BookmarkModelStatusChangeChecker::~BookmarkModelStatusChangeChecker() { … }
void BookmarkModelStatusChangeChecker::Observe(
bookmarks::BookmarkModel* model) { … }
void BookmarkModelStatusChangeChecker::CheckExitCondition() { … }
void BookmarkModelStatusChangeChecker::PostCheckExitCondition() { … }
BookmarksMatchChecker::BookmarksMatchChecker() { … }
bool BookmarksMatchChecker::IsExitConditionSatisfied(std::ostream* os) { … }
bool BookmarksMatchChecker::Wait() { … }
SingleBookmarkModelStatusChangeChecker::SingleBookmarkModelStatusChangeChecker(
int profile_index)
: … { … }
SingleBookmarkModelStatusChangeChecker::
~SingleBookmarkModelStatusChangeChecker() = default;
int SingleBookmarkModelStatusChangeChecker::profile_index() const { … }
BookmarkModel* SingleBookmarkModelStatusChangeChecker::bookmark_model() const { … }
SingleBookmarksModelMatcherChecker::SingleBookmarksModelMatcherChecker(
int profile_index,
const Matcher& matcher)
: … { … }
SingleBookmarksModelMatcherChecker::~SingleBookmarksModelMatcherChecker() =
default;
bool SingleBookmarksModelMatcherChecker::IsExitConditionSatisfied(
std::ostream* os) { … }
BookmarksTitleChecker::BookmarksTitleChecker(int profile_index,
const std::string& title,
int expected_count)
: … { … }
bool BookmarksTitleChecker::IsExitConditionSatisfied(std::ostream* os) { … }
BookmarkFaviconLoadedChecker::BookmarkFaviconLoadedChecker(int profile_index,
const GURL& page_url)
: … { … }
bool BookmarkFaviconLoadedChecker::IsExitConditionSatisfied(std::ostream* os) { … }
ServerBookmarksEqualityChecker::ServerBookmarksEqualityChecker(
std::vector<ExpectedBookmark> expected_bookmarks,
syncer::Cryptographer* cryptographer)
: … { … }
bool ServerBookmarksEqualityChecker::IsExitConditionSatisfied(
std::ostream* os) { … }
ServerBookmarksEqualityChecker::~ServerBookmarksEqualityChecker() = default;
BookmarksUrlChecker::BookmarksUrlChecker(int profile,
const GURL& url,
int expected_count)
: … { … }
bool BookmarksUrlChecker::IsExitConditionSatisfied(std::ostream* os) { … }
BookmarksUuidChecker::BookmarksUuidChecker(int profile, const base::Uuid& uuid)
: … { … }
BookmarksUuidChecker::~BookmarksUuidChecker() = default;
BookmarkModelMatchesFakeServerChecker::BookmarkModelMatchesFakeServerChecker(
int profile,
syncer::SyncServiceImpl* service,
fake_server::FakeServer* fake_server)
: … { … }
bool BookmarkModelMatchesFakeServerChecker::IsExitConditionSatisfied(
std::ostream* os) { … }
bool BookmarkModelMatchesFakeServerChecker::CheckPermanentParentNode(
const bookmarks::BookmarkNode* node,
const sync_pb::SyncEntity& server_entity,
std::ostream* os) const { … }
bool BookmarkModelMatchesFakeServerChecker::CheckParentNode(
const bookmarks::BookmarkNode* node,
const std::map<base::Uuid, sync_pb::SyncEntity>& server_bookmarks_by_uuid,
std::ostream* os) const { … }
std::map<std::string, sync_pb::SyncEntity>
BookmarkModelMatchesFakeServerChecker::
GetServerPermanentBookmarksGroupedBySyncId() const { … }
bool BookmarkModelMatchesFakeServerChecker::GetServerBookmarksByUniqueUuid(
std::map<base::Uuid, sync_pb::SyncEntity>* server_bookmarks_by_uuid) const { … }
std::map<std::string, std::vector<base::Uuid>>
BookmarkModelMatchesFakeServerChecker::GetServerUuidsGroupedByParentSyncId(
const std::map<base::Uuid, sync_pb::SyncEntity>& server_bookmarks_by_uuid)
const { … }
}