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
3 // found in the LICENSE file.
5 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h"
7 #include "base/base64.h"
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "components/bookmarks/browser/bookmark_model.h"
16 #include "components/bookmarks/browser/bookmark_node.h"
17 #include "components/bookmarks/test/test_bookmark_client.h"
18 #include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h"
19 #include "components/enhanced_bookmarks/proto/metadata.pb.h"
20 #include "testing/gtest/include/gtest/gtest.h"
23 using bookmarks::BookmarkModel
;
24 using bookmarks::BookmarkNode
;
25 using enhanced_bookmarks::EnhancedBookmarkModel
;
28 const std::string
BOOKMARK_URL("http://example.com/index.html");
29 const std::string
IMAGE_URL("http://example.com/image.jpg");
32 class EnhancedBookmarkModelTest
33 : public testing::Test
,
34 public enhanced_bookmarks::EnhancedBookmarkModelObserver
{
36 EnhancedBookmarkModelTest()
38 shutting_down_calls_(0),
42 all_user_nodes_removed_calls_(0),
43 remote_id_changed_calls_(0),
47 last_remote_id_node_(NULL
) {}
48 ~EnhancedBookmarkModelTest() override
{}
50 void SetUp() override
{
51 message_loop_
.reset(new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT
));
52 bookmark_client_
.reset(new bookmarks::TestBookmarkClient());
53 bookmark_model_
.reset(bookmark_client_
->CreateModel().release());
54 model_
.reset(new EnhancedBookmarkModel(bookmark_model_
.get(), "v1.0"));
55 model_
->AddObserver(this);
58 void TearDown() override
{
62 bookmark_model_
.reset();
63 bookmark_client_
.reset();
64 message_loop_
.reset();
68 const BookmarkNode
* AddBookmark() {
69 return AddBookmark("Some title", bookmark_model_
->other_node());
72 const BookmarkNode
* AddFolder() {
73 return AddFolder("Some title", bookmark_model_
->other_node());
76 const BookmarkNode
* AddBookmark(const std::string
& name
,
77 const BookmarkNode
* parent
) {
78 return model_
->AddURL(parent
,
80 base::ASCIIToUTF16(name
),
85 const BookmarkNode
* AddFolder(const std::string
& name
,
86 const BookmarkNode
* parent
) {
87 return model_
->AddFolder(parent
, 0, base::ASCIIToUTF16(name
));
90 std::string
GetVersion(const BookmarkNode
* node
) {
91 return GetMetaInfoField(node
, "stars.version");
94 std::string
GetId(const BookmarkNode
* node
) {
95 return GetMetaInfoField(node
, "stars.id");
98 std::string
GetOldId(const BookmarkNode
* node
) {
99 return GetMetaInfoField(node
, "stars.oldId");
102 std::string
GetMetaInfoField(const BookmarkNode
* node
,
103 const std::string
& name
) {
105 if (!node
->GetMetaInfo(name
, &value
))
106 return std::string();
110 scoped_ptr
<base::MessageLoop
> message_loop_
;
111 scoped_ptr
<bookmarks::TestBookmarkClient
> bookmark_client_
;
112 scoped_ptr
<BookmarkModel
> bookmark_model_
;
113 scoped_ptr
<EnhancedBookmarkModel
> model_
;
115 // EnhancedBookmarkModelObserver implementation:
116 void EnhancedBookmarkModelLoaded() override
{ loaded_calls_
++; }
117 void EnhancedBookmarkModelShuttingDown() override
{ shutting_down_calls_
++; }
118 void EnhancedBookmarkAdded(const BookmarkNode
* node
) override
{
122 void EnhancedBookmarkRemoved(const BookmarkNode
* node
) override
{
124 last_removed_
= node
;
126 void EnhancedBookmarkNodeChanged(const BookmarkNode
* node
) override
{
128 last_changed_
= node
;
130 void EnhancedBookmarkAllUserNodesRemoved() override
{
131 all_user_nodes_removed_calls_
++;
133 void EnhancedBookmarkRemoteIdChanged(const BookmarkNode
* node
,
134 const std::string
& old_remote_id
,
135 const std::string
& remote_id
) override
{
136 remote_id_changed_calls_
++;
137 last_remote_id_node_
= node
;
138 last_old_remote_id_
= old_remote_id
;
139 last_remote_id_
= remote_id
;
142 // Observer call counters:
144 int shutting_down_calls_
;
148 int all_user_nodes_removed_calls_
;
149 int remote_id_changed_calls_
;
151 // Observer parameter cache:
152 const BookmarkNode
* last_added_
;
153 const BookmarkNode
* last_removed_
;
154 const BookmarkNode
* last_changed_
;
155 const BookmarkNode
* last_remote_id_node_
;
156 std::string last_old_remote_id_
;
157 std::string last_remote_id_
;
160 DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarkModelTest
);
163 TEST_F(EnhancedBookmarkModelTest
, TestEmptySnippet
) {
164 const BookmarkNode
* node
= AddBookmark();
166 std::string
snippet(model_
->GetSnippet(node
));
167 EXPECT_EQ(snippet
, "");
170 TEST_F(EnhancedBookmarkModelTest
, TestSnippet
) {
171 const BookmarkNode
* node
= AddBookmark();
173 // Binary serialize the protobuf.
174 image::collections::PageData data
;
175 data
.set_snippet("I'm happy!");
176 ASSERT_TRUE(data
.IsInitialized());
178 bool result
= data
.SerializeToString(&output
);
181 // base64 encode the output.
183 base::Base64Encode(output
, &encoded
);
184 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", encoded
);
186 std::string
snippet(model_
->GetSnippet(node
));
187 EXPECT_EQ(snippet
, "I'm happy!");
190 TEST_F(EnhancedBookmarkModelTest
, TestBadEncodingSnippet
) {
191 const BookmarkNode
* node
= AddBookmark();
193 // Binary serialize the protobuf.
194 image::collections::PageData data
;
195 data
.set_snippet("You are happy!");
196 ASSERT_TRUE(data
.IsInitialized());
198 bool result
= data
.SerializeToString(&output
);
201 // don't base 64 encode the output.
202 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", output
);
204 std::string
snippet(model_
->GetSnippet(node
));
205 EXPECT_EQ(snippet
, "");
208 TEST_F(EnhancedBookmarkModelTest
, TestOriginalImage
) {
209 const BookmarkNode
* node
= AddBookmark();
211 image::collections::ImageData data
;
212 // Intentionally make raw pointer.
213 image::collections::ImageData_ImageInfo
* info
=
214 new image::collections::ImageData_ImageInfo
;
215 info
->set_url("http://example.com/foobar");
217 info
->set_height(55);
218 // This method consumes the pointer.
219 data
.set_allocated_original_info(info
);
222 bool result
= data
.SerializePartialToString(&output
);
225 // base64 encode the output.
227 base::Base64Encode(output
, &encoded
);
228 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
233 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
235 EXPECT_EQ(url
, GURL("http://example.com/foobar"));
236 EXPECT_EQ(width
, 15);
237 EXPECT_EQ(height
, 55);
240 TEST_F(EnhancedBookmarkModelTest
, TestThumbnailImage
) {
241 const BookmarkNode
* node
= AddBookmark();
243 image::collections::ImageData data
;
244 // Intentionally make raw pointer.
245 image::collections::ImageData_ImageInfo
* info
=
246 new image::collections::ImageData_ImageInfo
;
247 info
->set_url("http://example.com/foobar");
249 info
->set_height(55);
250 // This method consumes the pointer.
251 data
.set_allocated_thumbnail_info(info
);
254 bool result
= data
.SerializePartialToString(&output
);
257 // base64 encode the output.
259 base::Base64Encode(output
, &encoded
);
260 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
265 result
= model_
->GetThumbnailImage(node
, &url
, &width
, &height
);
267 EXPECT_EQ(url
, GURL("http://example.com/foobar"));
268 EXPECT_EQ(width
, 15);
269 EXPECT_EQ(height
, 55);
272 TEST_F(EnhancedBookmarkModelTest
, TestOriginalImageMissingDimensions
) {
273 const BookmarkNode
* node
= AddBookmark();
275 image::collections::ImageData data
;
276 // Intentionally make raw pointer.
277 image::collections::ImageData_ImageInfo
* info
=
278 new image::collections::ImageData_ImageInfo
;
279 info
->set_url("http://example.com/foobar");
280 // This method consumes the pointer.
281 data
.set_allocated_original_info(info
);
284 bool result
= data
.SerializePartialToString(&output
);
287 // base64 encode the output.
289 base::Base64Encode(output
, &encoded
);
290 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
295 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
296 ASSERT_FALSE(result
);
299 TEST_F(EnhancedBookmarkModelTest
, TestOriginalImageBadUrl
) {
300 const BookmarkNode
* node
= AddBookmark();
302 image::collections::ImageData data
;
303 // Intentionally make raw pointer.
304 image::collections::ImageData_ImageInfo
* info
=
305 new image::collections::ImageData_ImageInfo
;
306 info
->set_url("asdf. 13r");
308 info
->set_height(55);
309 // This method consumes the pointer.
310 data
.set_allocated_original_info(info
);
313 bool result
= data
.SerializePartialToString(&output
);
316 // base64 encode the output.
318 base::Base64Encode(output
, &encoded
);
319 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
324 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
325 ASSERT_FALSE(result
);
328 TEST_F(EnhancedBookmarkModelTest
, TestEncodeDecode
) {
329 const BookmarkNode
* node
= AddBookmark();
332 model_
->SetOriginalImage(node
, GURL("http://example.com/i.jpg"), 22, 33);
338 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
340 EXPECT_EQ(url
, GURL("http://example.com/i.jpg"));
341 EXPECT_EQ(width
, 22);
342 EXPECT_EQ(height
, 33);
343 EXPECT_EQ("v1.0", GetVersion(node
));
346 TEST_F(EnhancedBookmarkModelTest
, TestDoubleEncodeDecode
) {
347 const BookmarkNode
* node
= AddBookmark();
349 // Encode some information.
351 model_
->SetOriginalImage(node
, GURL("http://example.com/i.jpg"), 22, 33);
353 // Encode some different information.
355 model_
->SetOriginalImage(node
, GURL("http://example.com/i.jpg"), 33, 44);
361 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
363 EXPECT_EQ(url
, GURL("http://example.com/i.jpg"));
364 EXPECT_EQ(width
, 33);
365 EXPECT_EQ(height
, 44);
366 EXPECT_EQ("v1.0", GetVersion(node
));
369 TEST_F(EnhancedBookmarkModelTest
, TestRemoteId
) {
370 const BookmarkNode
* node
= AddBookmark();
371 // Verify that the remote id starts with the correct prefix.
372 EXPECT_TRUE(base::StartsWith(model_
->GetRemoteId(node
), "ebc_",
373 base::CompareCase::SENSITIVE
));
375 // Getting the remote id for nodes that don't have them should return the
377 const BookmarkNode
* existing_node
=
378 bookmark_model_
->AddURL(bookmark_model_
->other_node(),
380 base::ASCIIToUTF16("Title"),
381 GURL(GURL(BOOKMARK_URL
)));
382 EXPECT_TRUE(model_
->GetRemoteId(existing_node
).empty());
384 // Folder nodes should not have a remote id set on creation.
385 const BookmarkNode
* folder_node
= AddFolder();
386 EXPECT_TRUE(model_
->GetRemoteId(folder_node
).empty());
389 TEST_F(EnhancedBookmarkModelTest
, TestEmptyDescription
) {
390 const BookmarkNode
* node
= AddBookmark();
392 std::string
description(model_
->GetDescription(node
));
393 EXPECT_EQ(description
, "");
396 TEST_F(EnhancedBookmarkModelTest
, TestDescription
) {
397 const BookmarkNode
* node
= AddBookmark();
398 const std::string
description("This is the most useful description of all.");
400 // Set the description.
401 model_
->SetDescription(node
, description
);
403 // Check the description is the one that was set.
404 EXPECT_EQ(model_
->GetDescription(node
), description
);
405 EXPECT_EQ("v1.0", GetVersion(node
));
408 // If there is no notes field, the description should fall back on the snippet.
409 TEST_F(EnhancedBookmarkModelTest
, TestDescriptionFallback
) {
410 const BookmarkNode
* node
= AddBookmark();
412 // Binary serialize the protobuf.
413 image::collections::PageData data
;
414 data
.set_snippet("Joe Bar Team");
415 ASSERT_TRUE(data
.IsInitialized());
417 bool result
= data
.SerializeToString(&output
);
420 // base64 encode the output.
422 base::Base64Encode(output
, &encoded
);
423 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", encoded
);
425 // The snippet is used as the description.
426 std::string
snippet(model_
->GetSnippet(node
));
427 EXPECT_EQ("Joe Bar Team", model_
->GetDescription(node
));
429 // Set the description.
430 const std::string
description("This is the most useful description of all.");
431 model_
->SetDescription(node
, description
);
433 // Check the description is the one that was set.
434 EXPECT_EQ(model_
->GetDescription(node
), description
);
437 // Makes sure that the stars.version field is set every time
438 // EnhancedBookmarkModel makes a change to a node.
439 TEST_F(EnhancedBookmarkModelTest
, TestVersionField
) {
440 const BookmarkNode
* node
=
441 bookmark_model_
->AddURL(bookmark_model_
->other_node(), 0,
442 base::ASCIIToUTF16("Title"), GURL(BOOKMARK_URL
));
443 EXPECT_EQ("", GetVersion(node
));
445 model_
->SetDescription(node
, "foo");
446 EXPECT_EQ("v1.0", GetVersion(node
));
448 // Add a suffix to the version to set.
449 model_
->SetVersionSuffix("alpha");
451 model_
->SetDescription(node
, "foo");
452 // Since the description didn't actually change, the version field should
454 EXPECT_EQ("v1.0", GetVersion(node
));
456 model_
->SetDescription(node
, "bar");
457 EXPECT_EQ("v1.0/alpha", GetVersion(node
));
460 // Verifies that duplicate nodes are reset when the model is created.
461 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateNodesOnInitialization
) {
464 const BookmarkNode
* parent
= bookmark_model_
->other_node();
465 const BookmarkNode
* node1
= bookmark_model_
->AddURL(
466 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
467 const BookmarkNode
* node2
= bookmark_model_
->AddURL(
468 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
469 const BookmarkNode
* node3
= bookmark_model_
->AddURL(
470 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
471 const BookmarkNode
* node4
= bookmark_model_
->AddURL(
472 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
474 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
475 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_2");
476 bookmark_model_
->SetNodeMetaInfo(node3
, "stars.id", "c_1");
477 bookmark_model_
->SetNodeMetaInfo(node4
, "stars.id", "c_1");
478 EXPECT_EQ("c_1", GetId(node1
));
479 EXPECT_EQ("c_2", GetId(node2
));
480 EXPECT_EQ("c_1", GetId(node3
));
481 EXPECT_EQ("c_1", GetId(node4
));
483 model_
.reset(new EnhancedBookmarkModel(bookmark_model_
.get(), "v2.0"));
484 base::RunLoop().RunUntilIdle();
485 EXPECT_EQ("c_2", GetId(node2
));
486 EXPECT_EQ("", GetId(node1
));
487 EXPECT_EQ("", GetId(node3
));
488 EXPECT_EQ("", GetId(node4
));
489 EXPECT_EQ("c_1", GetOldId(node1
));
490 EXPECT_EQ("c_1", GetOldId(node3
));
491 EXPECT_EQ("c_1", GetOldId(node4
));
492 EXPECT_EQ("v2.0", GetVersion(node1
));
493 EXPECT_EQ("v2.0", GetVersion(node3
));
494 EXPECT_EQ("v2.0", GetVersion(node4
));
497 // Verifies that duplicate nodes are reset if one is created.
498 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateAddedNodes
) {
499 BookmarkNode::MetaInfoMap meta_info
;
500 meta_info
["stars.id"] = "c_1";
501 const BookmarkNode
* parent
= bookmark_model_
->other_node();
503 const BookmarkNode
* node1
=
504 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
507 base::ASCIIToUTF16("Some title"),
511 EXPECT_EQ("c_1", GetId(node1
));
513 const BookmarkNode
* node2
=
514 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
517 base::ASCIIToUTF16("Some title"),
522 base::RunLoop().RunUntilIdle();
523 EXPECT_EQ("", GetId(node1
));
524 EXPECT_EQ("", GetId(node2
));
525 EXPECT_EQ("c_1", GetOldId(node1
));
526 EXPECT_EQ("c_1", GetOldId(node2
));
527 EXPECT_EQ("v1.0", GetVersion(node1
));
528 EXPECT_EQ("v1.0", GetVersion(node2
));
531 // Verifies that duplicate nodes are reset if an id is changed to a duplicate
533 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateChangedNodes
) {
534 const BookmarkNode
* node1
= AddBookmark();
535 const BookmarkNode
* node2
= AddBookmark();
537 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
538 EXPECT_EQ("c_1", GetId(node1
));
540 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
541 base::RunLoop().RunUntilIdle();
542 EXPECT_EQ("", GetId(node1
));
543 EXPECT_EQ("", GetId(node2
));
544 EXPECT_EQ("c_1", GetOldId(node1
));
545 EXPECT_EQ("c_1", GetOldId(node2
));
546 EXPECT_EQ("v1.0", GetVersion(node1
));
547 EXPECT_EQ("v1.0", GetVersion(node2
));
550 TEST_F(EnhancedBookmarkModelTest
, SetMultipleMetaInfo
) {
551 const BookmarkNode
* node
= AddBookmark();
552 BookmarkNode::MetaInfoMap meta_info
;
553 meta_info
["a"] = "aa";
554 meta_info
["b"] = "bb";
556 model_
->SetVersionSuffix("1");
557 model_
->SetMultipleMetaInfo(node
, meta_info
);
558 EXPECT_EQ("aa", GetMetaInfoField(node
, "a"));
559 EXPECT_EQ("bb", GetMetaInfoField(node
, "b"));
560 EXPECT_EQ("v1.0/1", GetVersion(node
));
562 // Not present fields does not erase the fields already set on the node.
563 meta_info
["a"] = "aaa";
564 model_
->SetVersionSuffix("2");
565 model_
->SetMultipleMetaInfo(node
, meta_info
);
566 EXPECT_EQ("aaa", GetMetaInfoField(node
, "a"));
567 EXPECT_EQ("bb", GetMetaInfoField(node
, "b"));
568 EXPECT_EQ("v1.0/2", GetVersion(node
));
570 // Not actually changing any values should not set the version field.
571 model_
->SetVersionSuffix("3");
572 model_
->SetMultipleMetaInfo(node
, meta_info
);
573 EXPECT_EQ("v1.0/2", GetVersion(node
));
576 TEST_F(EnhancedBookmarkModelTest
, ObserverShuttingDownEvent
) {
577 EXPECT_EQ(0, shutting_down_calls_
);
579 EXPECT_EQ(1, shutting_down_calls_
);
583 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeAddedEvent
) {
584 EXPECT_EQ(0, added_calls_
);
585 const BookmarkNode
* node
= AddBookmark();
586 EXPECT_EQ(1, added_calls_
);
587 EXPECT_EQ(node
, last_added_
);
589 const BookmarkNode
* folder
= AddFolder();
590 EXPECT_EQ(2, added_calls_
);
591 EXPECT_EQ(folder
, last_added_
);
594 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeRemovedEvent
) {
595 const BookmarkNode
* node
= AddBookmark();
596 const BookmarkNode
* folder
= AddFolder();
598 EXPECT_EQ(0, removed_calls_
);
599 bookmark_model_
->Remove(node
);
600 EXPECT_EQ(1, removed_calls_
);
601 EXPECT_EQ(node
, last_removed_
);
603 bookmark_model_
->Remove(folder
);
604 EXPECT_EQ(2, removed_calls_
);
605 EXPECT_EQ(folder
, last_removed_
);
608 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeChangedEvent
) {
609 const BookmarkNode
* node
= AddBookmark();
611 EXPECT_EQ(0, changed_calls_
);
612 bookmark_model_
->SetTitle(node
, base::ASCIIToUTF16("New Title"));
613 EXPECT_EQ(1, changed_calls_
);
614 EXPECT_EQ(node
, last_changed_
);
617 TEST_F(EnhancedBookmarkModelTest
, ObserverAllUserNodesRemovedEvent
) {
620 EXPECT_EQ(0, all_user_nodes_removed_calls_
);
621 bookmark_model_
->RemoveAllUserBookmarks();
622 EXPECT_EQ(0, removed_calls_
);
623 EXPECT_EQ(1, all_user_nodes_removed_calls_
);
626 TEST_F(EnhancedBookmarkModelTest
, ObserverRemoteIdChangedEvent
) {
627 const BookmarkNode
* node1
= AddFolder();
628 const BookmarkNode
* node2
= AddFolder();
630 EXPECT_EQ(0, remote_id_changed_calls_
);
631 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
632 base::RunLoop().RunUntilIdle();
633 EXPECT_EQ(1, remote_id_changed_calls_
);
634 EXPECT_EQ(node1
, last_remote_id_node_
);
635 EXPECT_EQ("", last_old_remote_id_
);
636 EXPECT_EQ("c_1", last_remote_id_
);
638 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_2");
639 base::RunLoop().RunUntilIdle();
640 EXPECT_EQ(2, remote_id_changed_calls_
);
641 EXPECT_EQ(node2
, last_remote_id_node_
);
642 EXPECT_EQ("", last_old_remote_id_
);
643 EXPECT_EQ("c_2", last_remote_id_
);
645 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_3");
646 base::RunLoop().RunUntilIdle();
647 EXPECT_EQ(3, remote_id_changed_calls_
);
648 EXPECT_EQ(node1
, last_remote_id_node_
);
649 EXPECT_EQ("c_1", last_old_remote_id_
);
650 EXPECT_EQ("c_3", last_remote_id_
);
652 // Set to duplicate ids.
653 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_3");
654 EXPECT_EQ(4, remote_id_changed_calls_
);
655 EXPECT_EQ(node2
, last_remote_id_node_
);
656 EXPECT_EQ("c_2", last_old_remote_id_
);
657 EXPECT_EQ("c_3", last_remote_id_
);
658 base::RunLoop().RunUntilIdle();
659 EXPECT_EQ(6, remote_id_changed_calls_
);
660 EXPECT_EQ("", last_remote_id_
);
663 TEST_F(EnhancedBookmarkModelTest
, ShutDownWhileResetDuplicationScheduled
) {
664 const BookmarkNode
* node1
= AddBookmark();
665 const BookmarkNode
* node2
= AddBookmark();
666 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
667 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
670 base::RunLoop().RunUntilIdle();
673 TEST_F(EnhancedBookmarkModelTest
, NodeRemovedWhileResetDuplicationScheduled
) {
674 const BookmarkNode
* node1
= AddBookmark();
675 const BookmarkNode
* node2
= AddBookmark();
676 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
677 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
678 bookmark_model_
->Remove(node1
);
679 base::RunLoop().RunUntilIdle();
682 TEST_F(EnhancedBookmarkModelTest
,
683 RemoveParentShouldRemoveChildrenFromMaps
) {
684 const BookmarkNode
* parent
= AddFolder();
685 const BookmarkNode
* node
= AddBookmark("Title", parent
);
686 std::string remote_id
= GetId(node
);
687 EXPECT_EQ(node
, model_
->BookmarkForRemoteId(remote_id
));
689 bookmark_model_
->Remove(parent
);
690 EXPECT_FALSE(model_
->BookmarkForRemoteId(remote_id
));
693 TEST_F(EnhancedBookmarkModelTest
, AddsRemoteIdToNonClonedKeys
) {
694 const std::set
<std::string
>& non_cloned_keys
=
695 bookmark_model_
->non_cloned_keys();
696 EXPECT_TRUE(non_cloned_keys
.find("stars.id") != non_cloned_keys
.end());
699 TEST_F(EnhancedBookmarkModelTest
, RemoveImageData
) {
700 const BookmarkNode
* node
= AddBookmark();
701 model_
->SetAllImages(node
, GURL(IMAGE_URL
), 64, 64, GURL(IMAGE_URL
), 16, 16);
705 EXPECT_TRUE(model_
->GetOriginalImage(node
, &url
, &width
, &height
));
706 EXPECT_TRUE(model_
->GetThumbnailImage(node
, &url
, &width
, &height
));
708 model_
->RemoveImageData(node
);
709 EXPECT_FALSE(model_
->GetOriginalImage(node
, &url
, &width
, &height
));
710 EXPECT_FALSE(model_
->GetThumbnailImage(node
, &url
, &width
, &height
));
712 std::string meta_info
= GetMetaInfoField(node
, "stars.imageData");
714 ASSERT_TRUE(base::Base64Decode(meta_info
, &decoded
));
715 image::collections::ImageData data
;
716 ASSERT_TRUE(data
.ParseFromString(decoded
));
717 EXPECT_TRUE(data
.user_removed_image());