#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/bookmarks/browser/bookmark_model.h"
#include <stddef.h>
#include <stdint.h>
#include <optional>
#include <set>
#include <string>
#include <unordered_set>
#include <utility>
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_model_observer.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/bookmark_undo_provider.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/browser/bookmark_uuids.h"
#include "components/bookmarks/browser/titled_url_match.h"
#include "components/bookmarks/browser/url_and_title.h"
#include "components/bookmarks/common/bookmark_features.h"
#include "components/bookmarks/common/bookmark_metrics.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/bookmarks/test/mock_bookmark_model_observer.h"
#include "components/bookmarks/test/test_bookmark_client.h"
#include "components/favicon_base/favicon_callback.h"
#include "components/favicon_base/favicon_types.h"
#include "components/query_parser/query_parser.h"
#include "components/sync/base/features.h"
#include "testing/gmock/include/gmock/gmock.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/base/models/tree_node_model.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
namespace bookmarks {
namespace {
NodeTypeForUuidLookup;
ASCIIToUTF16;
Time;
ElementsAre;
Invoke;
WithArg;
static struct { … } url_whitespace_test_cases[] = …;
static struct { … } title_whitespace_test_cases[] = …;
class TestBookmarkClientWithUndo : public TestBookmarkClient { … };
BookmarkNode* AsMutable(const BookmarkNode* node) { … }
void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) { … }
void SwapDateUsed(BookmarkNode* n1, BookmarkNode* n2) { … }
TestNode;
void PopulateNodeImpl(const std::vector<std::string>& description,
size_t* index,
TestNode* parent) { … }
void PopulateNodeFromString(const std::string& description, TestNode* parent) { … }
void PopulateBookmarkNode(TestNode* parent,
BookmarkModel* model,
const BookmarkNode* bb_node) { … }
void VerifyModelMatchesNode(TestNode* expected, const BookmarkNode* actual) { … }
void VerifyNoDuplicateIDs(BookmarkModel* model) { … }
class BookmarkModelTest : public testing::Test, public BookmarkModelObserver { … };
TEST_F(BookmarkModelTest, InitialState) { … }
TEST_F(BookmarkModelTest, AddURL) { … }
TEST_F(BookmarkModelTest, AddNewURL) { … }
TEST_F(BookmarkModelTest,
AddNewURLAccountStorageOnSharedBookmarkModelInstance) { … }
TEST_F(BookmarkModelTest, AddNewURLLocalStorageNotSyncing) { … }
TEST_F(BookmarkModelTest, AddNewURLLocalStorageSyncing) { … }
TEST_F(BookmarkModelTest, AddNewFolderAccountStorage) { … }
TEST_F(BookmarkModelTest, AddNewFolderLocalStorageNotSyncing) { … }
TEST_F(BookmarkModelTest, AddNewFolderLocalStorageSyncing) { … }
TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { … }
TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { … }
TEST_F(BookmarkModelTest, AddURLWithCreationTimeAndMetaInfo) { … }
TEST_F(BookmarkModelTest, AddURLWithGUID) { … }
TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { … }
TEST_F(BookmarkModelTest, AddFolder) { … }
TEST_F(BookmarkModelTest, AddFolderWithCreationTime) { … }
TEST_F(BookmarkModelTest, AddFolderWithGUID) { … }
TEST_F(BookmarkModelTest, AddFolderWithWhitespaceTitle) { … }
TEST_F(BookmarkModelTest, RemoveURL) { … }
TEST_F(BookmarkModelTest, RemoveFolder) { … }
TEST_F(BookmarkModelTest, RemoveAllUserBookmarks) { … }
TEST_F(BookmarkModelTest, UpdateLastUsedTimeInRange) { … }
TEST_F(BookmarkModelTest, ClearLastUsedTimeInRange) { … }
TEST_F(BookmarkModelTest, ClearLastUsedTimeInRangeForAllTime) { … }
TEST_F(BookmarkModelTest, SetTitle) { … }
TEST_F(BookmarkModelTest, SetTitleWithWhitespace) { … }
TEST_F(BookmarkModelTest, SetFolderTitle) { … }
TEST_F(BookmarkModelTest, SetURL) { … }
TEST_F(BookmarkModelTest, SetDateAdded) { … }
TEST_F(BookmarkModelTest, Move) { … }
TEST_F(BookmarkModelTest, NonMovingMoveCall) { … }
TEST_F(BookmarkModelTest, MoveURLFromFolder) { … }
TEST_F(BookmarkModelTest, MoveFolder) { … }
TEST_F(BookmarkModelTest, MoveWithUuidCollision) { … }
TEST_F(BookmarkModelTest, Copy) { … }
TEST_F(BookmarkModelTest, ParentForNewNodesWithEmptyModel) { … }
#if BUILDFLAG(IS_ANDROID)
TEST_F(BookmarkModelTest, ParentCanBeBookmarkBarOnAndroid) {
const std::u16string title(u"foo");
const GURL url("http://foo.com");
model_->AddURL(model_->bookmark_bar_node(), 0, title, url);
ASSERT_EQ(model_->bookmark_bar_node(), GetParentForNewNodes(model_.get()));
}
#endif
TEST_F(BookmarkModelTest, ParentForNewNodes) { … }
TEST_F(BookmarkModelTest, ParentForNewMobileNodes) { … }
TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { … }
TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { … }
TEST_F(BookmarkModelTest, GetMostRecentlyUsedEntries) { … }
TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { … }
TEST_F(BookmarkModelTest, GetUniqueUrlsWithDups) { … }
TEST_F(BookmarkModelTest, HasBookmarks) { … }
TEST_F(BookmarkModelTest, Sort) { … }
TEST_F(BookmarkModelTest, Reorder) { … }
TEST_F(BookmarkModelTest, NodeVisibility) { … }
TEST_F(BookmarkModelTest, NodeVisibility_AllBookmarksPhase0) { … }
TEST_F(BookmarkModelTest, MobileNodeVisibleWithChildren) { … }
TEST_F(BookmarkModelTest, ExtensiveChangesObserver) { … }
TEST_F(BookmarkModelTest, MultipleExtensiveChangesObserver) { … }
TEST_F(BookmarkModelTest, IsBookmarked) { … }
TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) { … }
TEST_F(BookmarkModelTest, RenamedFolderNodeExcludedFromIndex) { … }
TEST_F(BookmarkModelTest, GetBookmarksMatching) { … }
TEST_F(BookmarkModelTest, TitledUrlIndexUpdatedOnRemove) { … }
TEST_F(BookmarkModelTest, TitledUrlIndexUpdatedOnChangeTitle) { … }
TEST_F(BookmarkModelTest, TitledUrlIndexUpdatedOnChangeURL) { … }
TEST_F(BookmarkModelTest, GetNodeByUuid) { … }
TEST_F(BookmarkModelTest, GetAccountNodeByUuid) { … }
TEST_F(BookmarkModelTest, GetPermanentNodeByUuid) { … }
TEST_F(BookmarkModelTest, GetAccountPermanentNodeByUuid) { … }
TEST_F(BookmarkModelTest, GetNodeByUuidAfterRemove) { … }
TEST_F(BookmarkModelTest, GetNodeByUuidAfterRemoveAllUserBookmarks) { … }
TEST(BookmarkModelLoadTest, NodesPopulatedOnLoad) { … }
TEST(BookmarkModelLoadTest, NodesPopulatedIncludingAccountNodesOnLoad) { … }
TEST(BookmarkModelLoadTest, AccountSyncMetadataPopulatedWithoutNodesOnLoad) { … }
TEST(BookmarkModelLoadTest, TitledUrlIndexPopulatedOnLoad) { … }
TEST(BookmarkModelLoadTest, TitledUrlIndexPopulatedForAccountNodesOnLoad) { … }
TEST(BookmarkModelLoadTest, UuidIndexPopulatedOnLoad) { … }
TEST(BookmarkModelLoadTest, UuidIndexPopulatedForAccountNodesOnLoad) { … }
TEST(BookmarkModelStorageTest, SaveExactlyOneFile) { … }
TEST(BookmarkNodeTest, NodeMetaInfo) { … }
TEST(BookmarkModelTest2, CreateAndRestore) { … }
TEST_F(BookmarkModelTest, CreateAccountPermanentFolders) { … }
TEST_F(BookmarkModelTest, RemoveAccountPermanentFolders) { … }
TEST_F(BookmarkModelTest, IsLocalOnlyNodeWithSyncFeatureOff) { … }
TEST_F(BookmarkModelTest, IsLocalOnlyNodeWithSyncFeatureOn) { … }
TEST_F(BookmarkModelTest, IsLocalOnlyNodeWithSyncFeatureOnAndDettachedNode) { … }
}
class BookmarkModelFaviconTest : public testing::Test,
public BookmarkModelObserver { … };
TEST_F(BookmarkModelFaviconTest, FaviconsChangedObserver) { … }
TEST_F(BookmarkModelFaviconTest, ShouldResetFaviconStatusAfterRestore) { … }
}