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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/bookmarks/browser/bookmark_codec.h" 5 #include "components/bookmarks/browser/bookmark_codec.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 182 }
183 183
184 BookmarkModel* DecodeHelper(const base::Value& value, 184 BookmarkModel* DecodeHelper(const base::Value& value,
185 const std::string& expected_stored_checksum, 185 const std::string& expected_stored_checksum,
186 std::string* computed_checksum, 186 std::string* computed_checksum,
187 bool expected_changes) { 187 bool expected_changes) {
188 BookmarkCodec decoder; 188 BookmarkCodec decoder;
189 // Computed and stored checksums should be empty. 189 // Computed and stored checksums should be empty.
190 EXPECT_EQ("", decoder.computed_checksum()); 190 EXPECT_EQ("", decoder.computed_checksum());
191 EXPECT_EQ("", decoder.stored_checksum()); 191 EXPECT_EQ("", decoder.stored_checksum());
192 return DecodeHelper(&decoder, value, expected_stored_checksum,
193 computed_checksum, expected_changes);
194 }
192 195
196 BookmarkModel* DecodeHelper(BookmarkCodec* decoder,
197 const base::Value& value,
198 const std::string& expected_stored_checksum,
199 std::string* computed_checksum,
200 bool expected_changes) {
193 std::unique_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel()); 201 std::unique_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel());
194 EXPECT_TRUE(Decode(&decoder, model.get(), value)); 202 EXPECT_TRUE(Decode(decoder, model.get(), value));
195 203
196 *computed_checksum = decoder.computed_checksum(); 204 *computed_checksum = decoder->computed_checksum();
197 const std::string& stored_checksum = decoder.stored_checksum(); 205 const std::string& stored_checksum = decoder->stored_checksum();
198 206
199 // Computed and stored checksums should not be empty. 207 // Computed and stored checksums should not be empty.
200 EXPECT_FALSE(computed_checksum->empty()); 208 EXPECT_FALSE(computed_checksum->empty());
201 EXPECT_FALSE(stored_checksum.empty()); 209 EXPECT_FALSE(stored_checksum.empty());
202 210
203 // Stored checksum should be as expected. 211 // Stored checksum should be as expected.
204 EXPECT_EQ(expected_stored_checksum, stored_checksum); 212 EXPECT_EQ(expected_stored_checksum, stored_checksum);
205 213
206 // The two checksums should be equal if expected_changes is true; otherwise 214 // The two checksums should be equal if expected_changes is true; otherwise
207 // they should be different. 215 // they should be different.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 EXPECT_EQ("value1", meta_value); 428 EXPECT_EQ("value1", meta_value);
421 EXPECT_FALSE(model->root_node()->GetMetaInfo("other_key", &meta_value)); 429 EXPECT_FALSE(model->root_node()->GetMetaInfo("other_key", &meta_value));
422 const BookmarkNode* bbn = model->bookmark_bar_node(); 430 const BookmarkNode* bbn = model->bookmark_bar_node();
423 ASSERT_EQ(1, bbn->child_count()); 431 ASSERT_EQ(1, bbn->child_count());
424 const BookmarkNode* child = bbn->GetChild(0); 432 const BookmarkNode* child = bbn->GetChild(0);
425 EXPECT_TRUE(child->GetMetaInfo("node_info", &meta_value)); 433 EXPECT_TRUE(child->GetMetaInfo("node_info", &meta_value));
426 EXPECT_EQ("value2", meta_value); 434 EXPECT_EQ("value2", meta_value);
427 EXPECT_FALSE(child->GetMetaInfo("other_key", &meta_value)); 435 EXPECT_FALSE(child->GetMetaInfo("other_key", &meta_value));
428 } 436 }
429 437
438 TEST_F(BookmarkCodecTest, ExcludeMetaKeysOnDecode) {
439 // Add meta info and encode.
440 std::unique_ptr<BookmarkModel> model(CreateTestModel1());
441 model->SetNodeMetaInfo(model->root_node(), "model_info", "value1");
442 model->SetNodeMetaInfo(model->root_node(), "excluded", "value1");
443 model->SetNodeMetaInfo(model->bookmark_bar_node()->GetChild(0),
444 "not_included", "value2");
445 model->SetNodeMetaInfo(model->bookmark_bar_node()->GetChild(0), "node_info",
446 "value2");
447 std::string checksum;
448 std::unique_ptr<base::Value> value(EncodeHelper(model.get(), &checksum));
449 ASSERT_TRUE(value.get() != NULL);
450
451 BookmarkCodec decoder;
452 const char* const kExcludedList[] = {"excluded", "not_included"};
453 std::vector<std::string> list(std::begin(kExcludedList),
454 std::end(kExcludedList));
455 decoder.set_excluded_meta_info_keys(list);
456
457 // Decode and check for meta info with exclusion.
458 model.reset(DecodeHelper(&decoder, *value, checksum, &checksum, false));
459
460 std::string meta_value;
461 EXPECT_TRUE(model->root_node()->GetMetaInfo("model_info", &meta_value));
462 EXPECT_EQ("value1", meta_value);
463 EXPECT_FALSE(model->root_node()->GetMetaInfo("excluded", &meta_value));
464 const BookmarkNode* bbn = model->bookmark_bar_node();
465 ASSERT_EQ(1, bbn->child_count());
466 const BookmarkNode* child = bbn->GetChild(0);
467 EXPECT_TRUE(child->GetMetaInfo("node_info", &meta_value));
468 EXPECT_EQ("value2", meta_value);
469 EXPECT_FALSE(child->GetMetaInfo("not_included", &meta_value));
470 }
471
430 TEST_F(BookmarkCodecTest, EncodeAndDecodeSyncTransactionVersion) { 472 TEST_F(BookmarkCodecTest, EncodeAndDecodeSyncTransactionVersion) {
431 // Add sync transaction version and encode. 473 // Add sync transaction version and encode.
432 std::unique_ptr<BookmarkModel> model(CreateTestModel2()); 474 std::unique_ptr<BookmarkModel> model(CreateTestModel2());
433 model->SetNodeSyncTransactionVersion(model->root_node(), 1); 475 model->SetNodeSyncTransactionVersion(model->root_node(), 1);
434 const BookmarkNode* bbn = model->bookmark_bar_node(); 476 const BookmarkNode* bbn = model->bookmark_bar_node();
435 model->SetNodeSyncTransactionVersion(bbn->GetChild(1), 42); 477 model->SetNodeSyncTransactionVersion(bbn->GetChild(1), 42);
436 478
437 std::string checksum; 479 std::string checksum;
438 std::unique_ptr<base::Value> value(EncodeHelper(model.get(), &checksum)); 480 std::unique_ptr<base::Value> value(EncodeHelper(model.get(), &checksum));
439 ASSERT_TRUE(value.get() != NULL); 481 ASSERT_TRUE(value.get() != NULL);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value)); 519 bbn->GetChild(1)->GetMetaInfo(kSyncTransactionVersionKey, &meta_value));
478 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value)); 520 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNormalKey, &meta_value));
479 EXPECT_EQ("value", meta_value); 521 EXPECT_EQ("value", meta_value);
480 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value)); 522 EXPECT_TRUE(bbn->GetChild(1)->GetMetaInfo(kNormalKey, &meta_value));
481 EXPECT_EQ("value2", meta_value); 523 EXPECT_EQ("value2", meta_value);
482 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value)); 524 EXPECT_TRUE(bbn->GetChild(0)->GetMetaInfo(kNestedKey, &meta_value));
483 EXPECT_EQ("value3", meta_value); 525 EXPECT_EQ("value3", meta_value);
484 } 526 }
485 527
486 } // namespace bookmarks 528 } // namespace bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698