Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Unified Diff: components/bookmarks/browser/bookmark_codec_unittest.cc

Issue 2883523002: Reduce the memory usage of bookmarks storage (Closed)
Patch Set: remove client interface Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/bookmarks/browser/bookmark_codec_unittest.cc
diff --git a/components/bookmarks/browser/bookmark_codec_unittest.cc b/components/bookmarks/browser/bookmark_codec_unittest.cc
index a9d8523658af4b1be46f21c10d379bb6aecca74d..8c4d2a74bfa96642f3d084f6f7747f2c5558d5f5 100644
--- a/components/bookmarks/browser/bookmark_codec_unittest.cc
+++ b/components/bookmarks/browser/bookmark_codec_unittest.cc
@@ -189,12 +189,20 @@ class BookmarkCodecTest : public testing::Test {
// Computed and stored checksums should be empty.
EXPECT_EQ("", decoder.computed_checksum());
EXPECT_EQ("", decoder.stored_checksum());
+ return DecodeHelper(&decoder, value, expected_stored_checksum,
+ computed_checksum, expected_changes);
+ }
+ BookmarkModel* DecodeHelper(BookmarkCodec* decoder,
+ const base::Value& value,
+ const std::string& expected_stored_checksum,
+ std::string* computed_checksum,
+ bool expected_changes) {
std::unique_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel());
- EXPECT_TRUE(Decode(&decoder, model.get(), value));
+ EXPECT_TRUE(Decode(decoder, model.get(), value));
- *computed_checksum = decoder.computed_checksum();
- const std::string& stored_checksum = decoder.stored_checksum();
+ *computed_checksum = decoder->computed_checksum();
+ const std::string& stored_checksum = decoder->stored_checksum();
// Computed and stored checksums should not be empty.
EXPECT_FALSE(computed_checksum->empty());
@@ -427,6 +435,40 @@ TEST_F(BookmarkCodecTest, EncodeAndDecodeMetaInfo) {
EXPECT_FALSE(child->GetMetaInfo("other_key", &meta_value));
}
+TEST_F(BookmarkCodecTest, ExcludeMetaKeysOnDecode) {
+ // Add meta info and encode.
+ std::unique_ptr<BookmarkModel> model(CreateTestModel1());
+ model->SetNodeMetaInfo(model->root_node(), "model_info", "value1");
+ model->SetNodeMetaInfo(model->root_node(), "excluded", "value1");
+ model->SetNodeMetaInfo(model->bookmark_bar_node()->GetChild(0),
+ "not_included", "value2");
+ model->SetNodeMetaInfo(model->bookmark_bar_node()->GetChild(0), "node_info",
+ "value2");
+ std::string checksum;
+ std::unique_ptr<base::Value> value(EncodeHelper(model.get(), &checksum));
+ ASSERT_TRUE(value.get() != NULL);
+
+ BookmarkCodec decoder;
+ const char* const kExcludedList[] = {"excluded", "not_included"};
+ std::vector<std::string> list(std::begin(kExcludedList),
+ std::end(kExcludedList));
+ decoder.set_excluded_meta_info_keys(list);
+
+ // Decode and check for meta info with exclusion.
+ model.reset(DecodeHelper(&decoder, *value, checksum, &checksum, false));
+
+ std::string meta_value;
+ EXPECT_TRUE(model->root_node()->GetMetaInfo("model_info", &meta_value));
+ EXPECT_EQ("value1", meta_value);
+ EXPECT_FALSE(model->root_node()->GetMetaInfo("excluded", &meta_value));
+ const BookmarkNode* bbn = model->bookmark_bar_node();
+ ASSERT_EQ(1, bbn->child_count());
+ const BookmarkNode* child = bbn->GetChild(0);
+ EXPECT_TRUE(child->GetMetaInfo("node_info", &meta_value));
+ EXPECT_EQ("value2", meta_value);
+ EXPECT_FALSE(child->GetMetaInfo("not_included", &meta_value));
+}
+
TEST_F(BookmarkCodecTest, EncodeAndDecodeSyncTransactionVersion) {
// Add sync transaction version and encode.
std::unique_ptr<BookmarkModel> model(CreateTestModel2());

Powered by Google App Engine
This is Rietveld 408576698