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(StartsWithASCII(model_
->GetRemoteId(node
), "ebc_", true));
374 // Getting the remote id for nodes that don't have them should return the
376 const BookmarkNode
* existing_node
=
377 bookmark_model_
->AddURL(bookmark_model_
->other_node(),
379 base::ASCIIToUTF16("Title"),
380 GURL(GURL(BOOKMARK_URL
)));
381 EXPECT_TRUE(model_
->GetRemoteId(existing_node
).empty());
383 // Folder nodes should not have a remote id set on creation.
384 const BookmarkNode
* folder_node
= AddFolder();
385 EXPECT_TRUE(model_
->GetRemoteId(folder_node
).empty());
388 TEST_F(EnhancedBookmarkModelTest
, TestEmptyDescription
) {
389 const BookmarkNode
* node
= AddBookmark();
391 std::string
description(model_
->GetDescription(node
));
392 EXPECT_EQ(description
, "");
395 TEST_F(EnhancedBookmarkModelTest
, TestDescription
) {
396 const BookmarkNode
* node
= AddBookmark();
397 const std::string
description("This is the most useful description of all.");
399 // Set the description.
400 model_
->SetDescription(node
, description
);
402 // Check the description is the one that was set.
403 EXPECT_EQ(model_
->GetDescription(node
), description
);
404 EXPECT_EQ("v1.0", GetVersion(node
));
407 // If there is no notes field, the description should fall back on the snippet.
408 TEST_F(EnhancedBookmarkModelTest
, TestDescriptionFallback
) {
409 const BookmarkNode
* node
= AddBookmark();
411 // Binary serialize the protobuf.
412 image::collections::PageData data
;
413 data
.set_snippet("Joe Bar Team");
414 ASSERT_TRUE(data
.IsInitialized());
416 bool result
= data
.SerializeToString(&output
);
419 // base64 encode the output.
421 base::Base64Encode(output
, &encoded
);
422 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", encoded
);
424 // The snippet is used as the description.
425 std::string
snippet(model_
->GetSnippet(node
));
426 EXPECT_EQ("Joe Bar Team", model_
->GetDescription(node
));
428 // Set the description.
429 const std::string
description("This is the most useful description of all.");
430 model_
->SetDescription(node
, description
);
432 // Check the description is the one that was set.
433 EXPECT_EQ(model_
->GetDescription(node
), description
);
436 // Makes sure that the stars.version field is set every time
437 // EnhancedBookmarkModel makes a change to a node.
438 TEST_F(EnhancedBookmarkModelTest
, TestVersionField
) {
439 const BookmarkNode
* node
=
440 bookmark_model_
->AddURL(bookmark_model_
->other_node(), 0,
441 base::ASCIIToUTF16("Title"), GURL(BOOKMARK_URL
));
442 EXPECT_EQ("", GetVersion(node
));
444 model_
->SetDescription(node
, "foo");
445 EXPECT_EQ("v1.0", GetVersion(node
));
447 // Add a suffix to the version to set.
448 model_
->SetVersionSuffix("alpha");
450 model_
->SetDescription(node
, "foo");
451 // Since the description didn't actually change, the version field should
453 EXPECT_EQ("v1.0", GetVersion(node
));
455 model_
->SetDescription(node
, "bar");
456 EXPECT_EQ("v1.0/alpha", GetVersion(node
));
459 // Verifies that duplicate nodes are reset when the model is created.
460 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateNodesOnInitialization
) {
463 const BookmarkNode
* parent
= bookmark_model_
->other_node();
464 const BookmarkNode
* node1
= bookmark_model_
->AddURL(
465 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
466 const BookmarkNode
* node2
= bookmark_model_
->AddURL(
467 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
468 const BookmarkNode
* node3
= bookmark_model_
->AddURL(
469 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
470 const BookmarkNode
* node4
= bookmark_model_
->AddURL(
471 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
473 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
474 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_2");
475 bookmark_model_
->SetNodeMetaInfo(node3
, "stars.id", "c_1");
476 bookmark_model_
->SetNodeMetaInfo(node4
, "stars.id", "c_1");
477 EXPECT_EQ("c_1", GetId(node1
));
478 EXPECT_EQ("c_2", GetId(node2
));
479 EXPECT_EQ("c_1", GetId(node3
));
480 EXPECT_EQ("c_1", GetId(node4
));
482 model_
.reset(new EnhancedBookmarkModel(bookmark_model_
.get(), "v2.0"));
483 base::RunLoop().RunUntilIdle();
484 EXPECT_EQ("c_2", GetId(node2
));
485 EXPECT_EQ("", GetId(node1
));
486 EXPECT_EQ("", GetId(node3
));
487 EXPECT_EQ("", GetId(node4
));
488 EXPECT_EQ("c_1", GetOldId(node1
));
489 EXPECT_EQ("c_1", GetOldId(node3
));
490 EXPECT_EQ("c_1", GetOldId(node4
));
491 EXPECT_EQ("v2.0", GetVersion(node1
));
492 EXPECT_EQ("v2.0", GetVersion(node3
));
493 EXPECT_EQ("v2.0", GetVersion(node4
));
496 // Verifies that duplicate nodes are reset if one is created.
497 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateAddedNodes
) {
498 BookmarkNode::MetaInfoMap meta_info
;
499 meta_info
["stars.id"] = "c_1";
500 const BookmarkNode
* parent
= bookmark_model_
->other_node();
502 const BookmarkNode
* node1
=
503 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
506 base::ASCIIToUTF16("Some title"),
510 EXPECT_EQ("c_1", GetId(node1
));
512 const BookmarkNode
* node2
=
513 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
516 base::ASCIIToUTF16("Some title"),
521 base::RunLoop().RunUntilIdle();
522 EXPECT_EQ("", GetId(node1
));
523 EXPECT_EQ("", GetId(node2
));
524 EXPECT_EQ("c_1", GetOldId(node1
));
525 EXPECT_EQ("c_1", GetOldId(node2
));
526 EXPECT_EQ("v1.0", GetVersion(node1
));
527 EXPECT_EQ("v1.0", GetVersion(node2
));
530 // Verifies that duplicate nodes are reset if an id is changed to a duplicate
532 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateChangedNodes
) {
533 const BookmarkNode
* node1
= AddBookmark();
534 const BookmarkNode
* node2
= AddBookmark();
536 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
537 EXPECT_EQ("c_1", GetId(node1
));
539 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
540 base::RunLoop().RunUntilIdle();
541 EXPECT_EQ("", GetId(node1
));
542 EXPECT_EQ("", GetId(node2
));
543 EXPECT_EQ("c_1", GetOldId(node1
));
544 EXPECT_EQ("c_1", GetOldId(node2
));
545 EXPECT_EQ("v1.0", GetVersion(node1
));
546 EXPECT_EQ("v1.0", GetVersion(node2
));
549 TEST_F(EnhancedBookmarkModelTest
, SetMultipleMetaInfo
) {
550 const BookmarkNode
* node
= AddBookmark();
551 BookmarkNode::MetaInfoMap meta_info
;
552 meta_info
["a"] = "aa";
553 meta_info
["b"] = "bb";
555 model_
->SetVersionSuffix("1");
556 model_
->SetMultipleMetaInfo(node
, meta_info
);
557 EXPECT_EQ("aa", GetMetaInfoField(node
, "a"));
558 EXPECT_EQ("bb", GetMetaInfoField(node
, "b"));
559 EXPECT_EQ("v1.0/1", GetVersion(node
));
561 // Not present fields does not erase the fields already set on the node.
562 meta_info
["a"] = "aaa";
563 model_
->SetVersionSuffix("2");
564 model_
->SetMultipleMetaInfo(node
, meta_info
);
565 EXPECT_EQ("aaa", GetMetaInfoField(node
, "a"));
566 EXPECT_EQ("bb", GetMetaInfoField(node
, "b"));
567 EXPECT_EQ("v1.0/2", GetVersion(node
));
569 // Not actually changing any values should not set the version field.
570 model_
->SetVersionSuffix("3");
571 model_
->SetMultipleMetaInfo(node
, meta_info
);
572 EXPECT_EQ("v1.0/2", GetVersion(node
));
575 TEST_F(EnhancedBookmarkModelTest
, ObserverShuttingDownEvent
) {
576 EXPECT_EQ(0, shutting_down_calls_
);
578 EXPECT_EQ(1, shutting_down_calls_
);
582 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeAddedEvent
) {
583 EXPECT_EQ(0, added_calls_
);
584 const BookmarkNode
* node
= AddBookmark();
585 EXPECT_EQ(1, added_calls_
);
586 EXPECT_EQ(node
, last_added_
);
588 const BookmarkNode
* folder
= AddFolder();
589 EXPECT_EQ(2, added_calls_
);
590 EXPECT_EQ(folder
, last_added_
);
593 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeRemovedEvent
) {
594 const BookmarkNode
* node
= AddBookmark();
595 const BookmarkNode
* folder
= AddFolder();
597 EXPECT_EQ(0, removed_calls_
);
598 bookmark_model_
->Remove(node
);
599 EXPECT_EQ(1, removed_calls_
);
600 EXPECT_EQ(node
, last_removed_
);
602 bookmark_model_
->Remove(folder
);
603 EXPECT_EQ(2, removed_calls_
);
604 EXPECT_EQ(folder
, last_removed_
);
607 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeChangedEvent
) {
608 const BookmarkNode
* node
= AddBookmark();
610 EXPECT_EQ(0, changed_calls_
);
611 bookmark_model_
->SetTitle(node
, base::ASCIIToUTF16("New Title"));
612 EXPECT_EQ(1, changed_calls_
);
613 EXPECT_EQ(node
, last_changed_
);
616 TEST_F(EnhancedBookmarkModelTest
, ObserverAllUserNodesRemovedEvent
) {
619 EXPECT_EQ(0, all_user_nodes_removed_calls_
);
620 bookmark_model_
->RemoveAllUserBookmarks();
621 EXPECT_EQ(0, removed_calls_
);
622 EXPECT_EQ(1, all_user_nodes_removed_calls_
);
625 TEST_F(EnhancedBookmarkModelTest
, ObserverRemoteIdChangedEvent
) {
626 const BookmarkNode
* node1
= AddFolder();
627 const BookmarkNode
* node2
= AddFolder();
629 EXPECT_EQ(0, remote_id_changed_calls_
);
630 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
631 base::RunLoop().RunUntilIdle();
632 EXPECT_EQ(1, remote_id_changed_calls_
);
633 EXPECT_EQ(node1
, last_remote_id_node_
);
634 EXPECT_EQ("", last_old_remote_id_
);
635 EXPECT_EQ("c_1", last_remote_id_
);
637 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_2");
638 base::RunLoop().RunUntilIdle();
639 EXPECT_EQ(2, remote_id_changed_calls_
);
640 EXPECT_EQ(node2
, last_remote_id_node_
);
641 EXPECT_EQ("", last_old_remote_id_
);
642 EXPECT_EQ("c_2", last_remote_id_
);
644 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_3");
645 base::RunLoop().RunUntilIdle();
646 EXPECT_EQ(3, remote_id_changed_calls_
);
647 EXPECT_EQ(node1
, last_remote_id_node_
);
648 EXPECT_EQ("c_1", last_old_remote_id_
);
649 EXPECT_EQ("c_3", last_remote_id_
);
651 // Set to duplicate ids.
652 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_3");
653 EXPECT_EQ(4, remote_id_changed_calls_
);
654 EXPECT_EQ(node2
, last_remote_id_node_
);
655 EXPECT_EQ("c_2", last_old_remote_id_
);
656 EXPECT_EQ("c_3", last_remote_id_
);
657 base::RunLoop().RunUntilIdle();
658 EXPECT_EQ(6, remote_id_changed_calls_
);
659 EXPECT_EQ("", last_remote_id_
);
662 TEST_F(EnhancedBookmarkModelTest
, ShutDownWhileResetDuplicationScheduled
) {
663 const BookmarkNode
* node1
= AddBookmark();
664 const BookmarkNode
* node2
= AddBookmark();
665 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
666 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
669 base::RunLoop().RunUntilIdle();
672 TEST_F(EnhancedBookmarkModelTest
, NodeRemovedWhileResetDuplicationScheduled
) {
673 const BookmarkNode
* node1
= AddBookmark();
674 const BookmarkNode
* node2
= AddBookmark();
675 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
676 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
677 bookmark_model_
->Remove(node1
);
678 base::RunLoop().RunUntilIdle();
681 TEST_F(EnhancedBookmarkModelTest
,
682 RemoveParentShouldRemoveChildrenFromMaps
) {
683 const BookmarkNode
* parent
= AddFolder();
684 const BookmarkNode
* node
= AddBookmark("Title", parent
);
685 std::string remote_id
= GetId(node
);
686 EXPECT_EQ(node
, model_
->BookmarkForRemoteId(remote_id
));
688 bookmark_model_
->Remove(parent
);
689 EXPECT_FALSE(model_
->BookmarkForRemoteId(remote_id
));
692 TEST_F(EnhancedBookmarkModelTest
, AddsRemoteIdToNonClonedKeys
) {
693 const std::set
<std::string
>& non_cloned_keys
=
694 bookmark_model_
->non_cloned_keys();
695 EXPECT_TRUE(non_cloned_keys
.find("stars.id") != non_cloned_keys
.end());
698 TEST_F(EnhancedBookmarkModelTest
, RemoveImageData
) {
699 const BookmarkNode
* node
= AddBookmark();
700 model_
->SetAllImages(node
, GURL(IMAGE_URL
), 64, 64, GURL(IMAGE_URL
), 16, 16);
704 EXPECT_TRUE(model_
->GetOriginalImage(node
, &url
, &width
, &height
));
705 EXPECT_TRUE(model_
->GetThumbnailImage(node
, &url
, &width
, &height
));
707 model_
->RemoveImageData(node
);
708 EXPECT_FALSE(model_
->GetOriginalImage(node
, &url
, &width
, &height
));
709 EXPECT_FALSE(model_
->GetThumbnailImage(node
, &url
, &width
, &height
));
711 std::string meta_info
= GetMetaInfoField(node
, "stars.imageData");
713 ASSERT_TRUE(base::Base64Decode(meta_info
, &decoded
));
714 image::collections::ImageData data
;
715 ASSERT_TRUE(data
.ParseFromString(decoded
));
716 EXPECT_TRUE(data
.user_removed_image());