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 enhanced_bookmarks::EnhancedBookmarkModel
;
26 const std::string
BOOKMARK_URL("http://example.com/index.html");
29 class EnhancedBookmarkModelTest
30 : public testing::Test
,
31 public enhanced_bookmarks::EnhancedBookmarkModelObserver
{
33 EnhancedBookmarkModelTest()
35 shutting_down_calls_(0),
38 all_user_nodes_removed_calls_(0),
39 remote_id_changed_calls_(0),
42 last_remote_id_node_(NULL
) {}
43 ~EnhancedBookmarkModelTest() override
{}
45 void SetUp() override
{
46 message_loop_
.reset(new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT
));
47 bookmark_client_
.reset(new bookmarks::TestBookmarkClient());
48 bookmark_model_
.reset(bookmark_client_
->CreateModel().release());
49 model_
.reset(new EnhancedBookmarkModel(bookmark_model_
.get(), "v1.0"));
50 model_
->AddObserver(this);
53 void TearDown() override
{
57 bookmark_model_
.reset();
58 bookmark_client_
.reset();
59 message_loop_
.reset();
63 const BookmarkNode
* AddBookmark() {
64 return AddBookmark("Some title", bookmark_model_
->other_node());
67 const BookmarkNode
* AddFolder() {
68 return AddFolder("Some title", bookmark_model_
->other_node());
71 const BookmarkNode
* AddBookmark(const std::string
& name
,
72 const BookmarkNode
* parent
) {
73 return model_
->AddURL(parent
,
75 base::ASCIIToUTF16(name
),
80 const BookmarkNode
* AddFolder(const std::string
& name
,
81 const BookmarkNode
* parent
) {
82 return model_
->AddFolder(parent
, 0, base::ASCIIToUTF16(name
));
85 std::string
GetVersion(const BookmarkNode
* node
) {
86 return GetMetaInfoField(node
, "stars.version");
89 std::string
GetId(const BookmarkNode
* node
) {
90 return GetMetaInfoField(node
, "stars.id");
93 std::string
GetOldId(const BookmarkNode
* node
) {
94 return GetMetaInfoField(node
, "stars.oldId");
97 std::string
GetMetaInfoField(const BookmarkNode
* node
,
98 const std::string
& name
) {
100 if (!node
->GetMetaInfo(name
, &value
))
101 return std::string();
105 scoped_ptr
<base::MessageLoop
> message_loop_
;
106 scoped_ptr
<bookmarks::TestBookmarkClient
> bookmark_client_
;
107 scoped_ptr
<BookmarkModel
> bookmark_model_
;
108 scoped_ptr
<EnhancedBookmarkModel
> model_
;
110 // EnhancedBookmarkModelObserver implementation:
111 void EnhancedBookmarkModelLoaded() override
{ loaded_calls_
++; }
112 void EnhancedBookmarkModelShuttingDown() override
{ shutting_down_calls_
++; }
113 void EnhancedBookmarkAdded(const BookmarkNode
* node
) override
{
117 void EnhancedBookmarkRemoved(const BookmarkNode
* node
) override
{
119 last_removed_
= node
;
121 void EnhancedBookmarkAllUserNodesRemoved() override
{
122 all_user_nodes_removed_calls_
++;
124 void EnhancedBookmarkRemoteIdChanged(const BookmarkNode
* node
,
125 const std::string
& old_remote_id
,
126 const std::string
& remote_id
) override
{
127 remote_id_changed_calls_
++;
128 last_remote_id_node_
= node
;
129 last_old_remote_id_
= old_remote_id
;
130 last_remote_id_
= remote_id
;
133 // Observer call counters:
135 int shutting_down_calls_
;
138 int all_user_nodes_removed_calls_
;
139 int remote_id_changed_calls_
;
141 // Observer parameter cache:
142 const BookmarkNode
* last_added_
;
143 const BookmarkNode
* last_removed_
;
144 const BookmarkNode
* last_remote_id_node_
;
145 std::string last_old_remote_id_
;
146 std::string last_remote_id_
;
149 DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarkModelTest
);
152 TEST_F(EnhancedBookmarkModelTest
, TestEmptySnippet
) {
153 const BookmarkNode
* node
= AddBookmark();
155 std::string
snippet(model_
->GetSnippet(node
));
156 EXPECT_EQ(snippet
, "");
159 TEST_F(EnhancedBookmarkModelTest
, TestSnippet
) {
160 const BookmarkNode
* node
= AddBookmark();
162 // Binary serialize the protobuf.
163 image::collections::PageData data
;
164 data
.set_snippet("I'm happy!");
165 ASSERT_TRUE(data
.IsInitialized());
167 bool result
= data
.SerializeToString(&output
);
170 // base64 encode the output.
172 base::Base64Encode(output
, &encoded
);
173 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", encoded
);
175 std::string
snippet(model_
->GetSnippet(node
));
176 EXPECT_EQ(snippet
, "I'm happy!");
179 TEST_F(EnhancedBookmarkModelTest
, TestBadEncodingSnippet
) {
180 const BookmarkNode
* node
= AddBookmark();
182 // Binary serialize the protobuf.
183 image::collections::PageData data
;
184 data
.set_snippet("You are happy!");
185 ASSERT_TRUE(data
.IsInitialized());
187 bool result
= data
.SerializeToString(&output
);
190 // don't base 64 encode the output.
191 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", output
);
193 std::string
snippet(model_
->GetSnippet(node
));
194 EXPECT_EQ(snippet
, "");
197 TEST_F(EnhancedBookmarkModelTest
, TestOriginalImage
) {
198 const BookmarkNode
* node
= AddBookmark();
200 image::collections::ImageData data
;
201 // Intentionally make raw pointer.
202 image::collections::ImageData_ImageInfo
* info
=
203 new image::collections::ImageData_ImageInfo
;
204 info
->set_url("http://example.com/foobar");
206 info
->set_height(55);
207 // This method consumes the pointer.
208 data
.set_allocated_original_info(info
);
211 bool result
= data
.SerializePartialToString(&output
);
214 // base64 encode the output.
216 base::Base64Encode(output
, &encoded
);
217 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
222 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
224 EXPECT_EQ(url
, GURL("http://example.com/foobar"));
225 EXPECT_EQ(width
, 15);
226 EXPECT_EQ(height
, 55);
229 TEST_F(EnhancedBookmarkModelTest
, TestThumbnailImage
) {
230 const BookmarkNode
* node
= AddBookmark();
232 image::collections::ImageData data
;
233 // Intentionally make raw pointer.
234 image::collections::ImageData_ImageInfo
* info
=
235 new image::collections::ImageData_ImageInfo
;
236 info
->set_url("http://example.com/foobar");
238 info
->set_height(55);
239 // This method consumes the pointer.
240 data
.set_allocated_thumbnail_info(info
);
243 bool result
= data
.SerializePartialToString(&output
);
246 // base64 encode the output.
248 base::Base64Encode(output
, &encoded
);
249 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
254 result
= model_
->GetThumbnailImage(node
, &url
, &width
, &height
);
256 EXPECT_EQ(url
, GURL("http://example.com/foobar"));
257 EXPECT_EQ(width
, 15);
258 EXPECT_EQ(height
, 55);
261 TEST_F(EnhancedBookmarkModelTest
, TestOriginalImageMissingDimensions
) {
262 const BookmarkNode
* node
= AddBookmark();
264 image::collections::ImageData data
;
265 // Intentionally make raw pointer.
266 image::collections::ImageData_ImageInfo
* info
=
267 new image::collections::ImageData_ImageInfo
;
268 info
->set_url("http://example.com/foobar");
269 // This method consumes the pointer.
270 data
.set_allocated_original_info(info
);
273 bool result
= data
.SerializePartialToString(&output
);
276 // base64 encode the output.
278 base::Base64Encode(output
, &encoded
);
279 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
284 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
285 ASSERT_FALSE(result
);
288 TEST_F(EnhancedBookmarkModelTest
, TestOriginalImageBadUrl
) {
289 const BookmarkNode
* node
= AddBookmark();
291 image::collections::ImageData data
;
292 // Intentionally make raw pointer.
293 image::collections::ImageData_ImageInfo
* info
=
294 new image::collections::ImageData_ImageInfo
;
295 info
->set_url("asdf. 13r");
297 info
->set_height(55);
298 // This method consumes the pointer.
299 data
.set_allocated_original_info(info
);
302 bool result
= data
.SerializePartialToString(&output
);
305 // base64 encode the output.
307 base::Base64Encode(output
, &encoded
);
308 bookmark_model_
->SetNodeMetaInfo(node
, "stars.imageData", encoded
);
313 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
314 ASSERT_FALSE(result
);
317 TEST_F(EnhancedBookmarkModelTest
, TestEncodeDecode
) {
318 const BookmarkNode
* node
= AddBookmark();
321 model_
->SetOriginalImage(node
, GURL("http://example.com/i.jpg"), 22, 33);
327 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
329 EXPECT_EQ(url
, GURL("http://example.com/i.jpg"));
330 EXPECT_EQ(width
, 22);
331 EXPECT_EQ(height
, 33);
332 EXPECT_EQ("v1.0", GetVersion(node
));
335 TEST_F(EnhancedBookmarkModelTest
, TestDoubleEncodeDecode
) {
336 const BookmarkNode
* node
= AddBookmark();
338 // Encode some information.
340 model_
->SetOriginalImage(node
, GURL("http://example.com/i.jpg"), 22, 33);
342 // Encode some different information.
344 model_
->SetOriginalImage(node
, GURL("http://example.com/i.jpg"), 33, 44);
350 result
= model_
->GetOriginalImage(node
, &url
, &width
, &height
);
352 EXPECT_EQ(url
, GURL("http://example.com/i.jpg"));
353 EXPECT_EQ(width
, 33);
354 EXPECT_EQ(height
, 44);
355 EXPECT_EQ("v1.0", GetVersion(node
));
358 TEST_F(EnhancedBookmarkModelTest
, TestRemoteId
) {
359 const BookmarkNode
* node
= AddBookmark();
360 // Verify that the remote id starts with the correct prefix.
361 EXPECT_TRUE(StartsWithASCII(model_
->GetRemoteId(node
), "ebc_", true));
363 // Getting the remote id for nodes that don't have them should return the
365 const BookmarkNode
* existing_node
=
366 bookmark_model_
->AddURL(bookmark_model_
->other_node(),
368 base::ASCIIToUTF16("Title"),
369 GURL(GURL(BOOKMARK_URL
)));
370 EXPECT_TRUE(model_
->GetRemoteId(existing_node
).empty());
372 // Folder nodes should not have a remote id set on creation.
373 const BookmarkNode
* folder_node
= AddFolder();
374 EXPECT_TRUE(model_
->GetRemoteId(folder_node
).empty());
377 TEST_F(EnhancedBookmarkModelTest
, TestEmptyDescription
) {
378 const BookmarkNode
* node
= AddBookmark();
380 std::string
description(model_
->GetDescription(node
));
381 EXPECT_EQ(description
, "");
384 TEST_F(EnhancedBookmarkModelTest
, TestDescription
) {
385 const BookmarkNode
* node
= AddBookmark();
386 const std::string
description("This is the most useful description of all.");
388 // Set the description.
389 model_
->SetDescription(node
, description
);
391 // Check the description is the one that was set.
392 EXPECT_EQ(model_
->GetDescription(node
), description
);
393 EXPECT_EQ("v1.0", GetVersion(node
));
396 // If there is no notes field, the description should fall back on the snippet.
397 TEST_F(EnhancedBookmarkModelTest
, TestDescriptionFallback
) {
398 const BookmarkNode
* node
= AddBookmark();
400 // Binary serialize the protobuf.
401 image::collections::PageData data
;
402 data
.set_snippet("Joe Bar Team");
403 ASSERT_TRUE(data
.IsInitialized());
405 bool result
= data
.SerializeToString(&output
);
408 // base64 encode the output.
410 base::Base64Encode(output
, &encoded
);
411 bookmark_model_
->SetNodeMetaInfo(node
, "stars.pageData", encoded
);
413 // The snippet is used as the description.
414 std::string
snippet(model_
->GetSnippet(node
));
415 EXPECT_EQ("Joe Bar Team", model_
->GetDescription(node
));
417 // Set the description.
418 const std::string
description("This is the most useful description of all.");
419 model_
->SetDescription(node
, description
);
421 // Check the description is the one that was set.
422 EXPECT_EQ(model_
->GetDescription(node
), description
);
425 // Makes sure that the stars.version field is set every time
426 // EnhancedBookmarkModel makes a change to a node.
427 TEST_F(EnhancedBookmarkModelTest
, TestVersionField
) {
428 const BookmarkNode
* node
= AddBookmark();
429 EXPECT_EQ("", GetVersion(node
));
431 model_
->SetDescription(node
, "foo");
432 EXPECT_EQ("v1.0", GetVersion(node
));
434 // Add a suffix to the version to set.
435 model_
->SetVersionSuffix("alpha");
437 model_
->SetDescription(node
, "foo");
438 // Since the description didn't actually change, the version field should
440 EXPECT_EQ("v1.0", GetVersion(node
));
442 model_
->SetDescription(node
, "bar");
443 EXPECT_EQ("v1.0/alpha", GetVersion(node
));
446 // Verifies that duplicate nodes are reset when the model is created.
447 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateNodesOnInitialization
) {
450 const BookmarkNode
* parent
= bookmark_model_
->other_node();
451 const BookmarkNode
* node1
= bookmark_model_
->AddURL(
452 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
453 const BookmarkNode
* node2
= bookmark_model_
->AddURL(
454 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
455 const BookmarkNode
* node3
= bookmark_model_
->AddURL(
456 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
457 const BookmarkNode
* node4
= bookmark_model_
->AddURL(
458 parent
, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL
));
460 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
461 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_2");
462 bookmark_model_
->SetNodeMetaInfo(node3
, "stars.id", "c_1");
463 bookmark_model_
->SetNodeMetaInfo(node4
, "stars.id", "c_1");
464 EXPECT_EQ("c_1", GetId(node1
));
465 EXPECT_EQ("c_2", GetId(node2
));
466 EXPECT_EQ("c_1", GetId(node3
));
467 EXPECT_EQ("c_1", GetId(node4
));
469 model_
.reset(new EnhancedBookmarkModel(bookmark_model_
.get(), "v2.0"));
470 base::RunLoop().RunUntilIdle();
471 EXPECT_EQ("c_2", GetId(node2
));
472 EXPECT_EQ("", GetId(node1
));
473 EXPECT_EQ("", GetId(node3
));
474 EXPECT_EQ("", GetId(node4
));
475 EXPECT_EQ("c_1", GetOldId(node1
));
476 EXPECT_EQ("c_1", GetOldId(node3
));
477 EXPECT_EQ("c_1", GetOldId(node4
));
478 EXPECT_EQ("v2.0", GetVersion(node1
));
479 EXPECT_EQ("v2.0", GetVersion(node3
));
480 EXPECT_EQ("v2.0", GetVersion(node4
));
483 // Verifies that duplicate nodes are reset if one is created.
484 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateAddedNodes
) {
485 BookmarkNode::MetaInfoMap meta_info
;
486 meta_info
["stars.id"] = "c_1";
487 const BookmarkNode
* parent
= bookmark_model_
->other_node();
489 const BookmarkNode
* node1
=
490 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
493 base::ASCIIToUTF16("Some title"),
497 EXPECT_EQ("c_1", GetId(node1
));
499 const BookmarkNode
* node2
=
500 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
503 base::ASCIIToUTF16("Some title"),
508 base::RunLoop().RunUntilIdle();
509 EXPECT_EQ("", GetId(node1
));
510 EXPECT_EQ("", GetId(node2
));
511 EXPECT_EQ("c_1", GetOldId(node1
));
512 EXPECT_EQ("c_1", GetOldId(node2
));
513 EXPECT_EQ("v1.0", GetVersion(node1
));
514 EXPECT_EQ("v1.0", GetVersion(node2
));
517 // Verifies that duplicate nodes are reset if an id is changed to a duplicate
519 TEST_F(EnhancedBookmarkModelTest
, ResetDuplicateChangedNodes
) {
520 const BookmarkNode
* node1
= AddBookmark();
521 const BookmarkNode
* node2
= AddBookmark();
523 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
524 EXPECT_EQ("c_1", GetId(node1
));
526 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
527 base::RunLoop().RunUntilIdle();
528 EXPECT_EQ("", GetId(node1
));
529 EXPECT_EQ("", GetId(node2
));
530 EXPECT_EQ("c_1", GetOldId(node1
));
531 EXPECT_EQ("c_1", GetOldId(node2
));
532 EXPECT_EQ("v1.0", GetVersion(node1
));
533 EXPECT_EQ("v1.0", GetVersion(node2
));
536 TEST_F(EnhancedBookmarkModelTest
, SetMultipleMetaInfo
) {
537 const BookmarkNode
* node
= AddBookmark();
538 BookmarkNode::MetaInfoMap meta_info
;
539 meta_info
["a"] = "aa";
540 meta_info
["b"] = "bb";
542 model_
->SetVersionSuffix("1");
543 model_
->SetMultipleMetaInfo(node
, meta_info
);
544 EXPECT_EQ("aa", GetMetaInfoField(node
, "a"));
545 EXPECT_EQ("bb", GetMetaInfoField(node
, "b"));
546 EXPECT_EQ("v1.0/1", GetVersion(node
));
548 // Not present fields does not erase the fields already set on the node.
549 meta_info
["a"] = "aaa";
550 model_
->SetVersionSuffix("2");
551 model_
->SetMultipleMetaInfo(node
, meta_info
);
552 EXPECT_EQ("aaa", GetMetaInfoField(node
, "a"));
553 EXPECT_EQ("bb", GetMetaInfoField(node
, "b"));
554 EXPECT_EQ("v1.0/2", GetVersion(node
));
556 // Not actually changing any values should not set the version field.
557 model_
->SetVersionSuffix("3");
558 model_
->SetMultipleMetaInfo(node
, meta_info
);
559 EXPECT_EQ("v1.0/2", GetVersion(node
));
562 TEST_F(EnhancedBookmarkModelTest
, ObserverShuttingDownEvent
) {
563 EXPECT_EQ(0, shutting_down_calls_
);
565 EXPECT_EQ(1, shutting_down_calls_
);
569 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeAddedEvent
) {
570 EXPECT_EQ(0, added_calls_
);
571 const BookmarkNode
* node
= AddBookmark();
572 EXPECT_EQ(1, added_calls_
);
573 EXPECT_EQ(node
, last_added_
);
575 const BookmarkNode
* folder
= AddFolder();
576 EXPECT_EQ(2, added_calls_
);
577 EXPECT_EQ(folder
, last_added_
);
580 TEST_F(EnhancedBookmarkModelTest
, ObserverNodeRemovedEvent
) {
581 const BookmarkNode
* node
= AddBookmark();
582 const BookmarkNode
* folder
= AddFolder();
584 EXPECT_EQ(0, removed_calls_
);
585 bookmark_model_
->Remove(node
->parent(), node
->parent()->GetIndexOf(node
));
586 EXPECT_EQ(1, removed_calls_
);
587 EXPECT_EQ(node
, last_removed_
);
589 bookmark_model_
->Remove(folder
->parent(),
590 folder
->parent()->GetIndexOf(folder
));
591 EXPECT_EQ(2, removed_calls_
);
592 EXPECT_EQ(folder
, last_removed_
);
595 TEST_F(EnhancedBookmarkModelTest
, ObserverAllUserNodesRemovedEvent
) {
598 EXPECT_EQ(0, all_user_nodes_removed_calls_
);
599 bookmark_model_
->RemoveAllUserBookmarks();
600 EXPECT_EQ(0, removed_calls_
);
601 EXPECT_EQ(1, all_user_nodes_removed_calls_
);
604 TEST_F(EnhancedBookmarkModelTest
, ObserverRemoteIdChangedEvent
) {
605 const BookmarkNode
* node1
= AddFolder();
606 const BookmarkNode
* node2
= AddFolder();
608 EXPECT_EQ(0, remote_id_changed_calls_
);
609 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
610 base::RunLoop().RunUntilIdle();
611 EXPECT_EQ(1, remote_id_changed_calls_
);
612 EXPECT_EQ(node1
, last_remote_id_node_
);
613 EXPECT_EQ("", last_old_remote_id_
);
614 EXPECT_EQ("c_1", last_remote_id_
);
616 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_2");
617 base::RunLoop().RunUntilIdle();
618 EXPECT_EQ(2, remote_id_changed_calls_
);
619 EXPECT_EQ(node2
, last_remote_id_node_
);
620 EXPECT_EQ("", last_old_remote_id_
);
621 EXPECT_EQ("c_2", last_remote_id_
);
623 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_3");
624 base::RunLoop().RunUntilIdle();
625 EXPECT_EQ(3, remote_id_changed_calls_
);
626 EXPECT_EQ(node1
, last_remote_id_node_
);
627 EXPECT_EQ("c_1", last_old_remote_id_
);
628 EXPECT_EQ("c_3", last_remote_id_
);
630 // Set to duplicate ids.
631 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_3");
632 EXPECT_EQ(4, remote_id_changed_calls_
);
633 EXPECT_EQ(node2
, last_remote_id_node_
);
634 EXPECT_EQ("c_2", last_old_remote_id_
);
635 EXPECT_EQ("c_3", last_remote_id_
);
636 base::RunLoop().RunUntilIdle();
637 EXPECT_EQ(6, remote_id_changed_calls_
);
638 EXPECT_EQ("", last_remote_id_
);
641 TEST_F(EnhancedBookmarkModelTest
, ShutDownWhileResetDuplicationScheduled
) {
642 const BookmarkNode
* node1
= AddBookmark();
643 const BookmarkNode
* node2
= AddBookmark();
644 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
645 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
648 base::RunLoop().RunUntilIdle();
651 TEST_F(EnhancedBookmarkModelTest
, NodeRemovedWhileResetDuplicationScheduled
) {
652 const BookmarkNode
* node1
= AddBookmark();
653 const BookmarkNode
* node2
= AddBookmark();
654 bookmark_model_
->SetNodeMetaInfo(node1
, "stars.id", "c_1");
655 bookmark_model_
->SetNodeMetaInfo(node2
, "stars.id", "c_1");
656 bookmark_model_
->Remove(node1
->parent(), node1
->parent()->GetIndexOf(node1
));
657 base::RunLoop().RunUntilIdle();
660 // Verifies that the NEEDS_OFFLINE_PROCESSING flag is set for nodes added
661 // with no remote id.
662 TEST_F(EnhancedBookmarkModelTest
, BookmarkAddedSetsOfflineProcessingFlag
) {
663 const BookmarkNode
* node
=
664 bookmark_model_
->AddURL(bookmark_model_
->other_node(),
666 base::ASCIIToUTF16("Some title"),
668 std::string flags_str
;
669 EXPECT_FALSE(node
->GetMetaInfo("stars.flags", &flags_str
));
670 base::RunLoop().RunUntilIdle();
671 ASSERT_TRUE(node
->GetMetaInfo("stars.flags", &flags_str
));
673 ASSERT_TRUE(base::StringToInt(flags_str
, &flags
));
674 EXPECT_EQ(1, (flags
& 1));
677 // Verifies that the NEEDS_OFFLINE_PROCESSING_FLAG is not set for added folders.
678 TEST_F(EnhancedBookmarkModelTest
, FolderAddedDoesNotSetOfflineProcessingFlag
) {
679 const BookmarkNode
* node
= AddFolder();
680 base::RunLoop().RunUntilIdle();
682 std::string flags_str
;
683 if (node
->GetMetaInfo("stars.flags", &flags_str
)) {
685 ASSERT_TRUE(base::StringToInt(flags_str
, &flags
));
686 EXPECT_EQ(0, (flags
& 1));
690 // Verifies that when a bookmark is added that has a remote id, the status of
691 // the NEEDS_OFFLINE_PROCESSING flag doesn't change.
692 TEST_F(EnhancedBookmarkModelTest
,
693 BookmarkAddedWithIdKeepsOfflineProcessingFlag
) {
694 BookmarkNode::MetaInfoMap meta_info
;
695 meta_info
["stars.id"] = "some_id";
696 meta_info
["stars.flags"] = "1";
698 const BookmarkNode
* node1
=
699 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
700 bookmark_model_
->other_node(),
702 base::ASCIIToUTF16("Some title"),
706 base::RunLoop().RunUntilIdle();
707 std::string flags_str
;
708 ASSERT_TRUE(node1
->GetMetaInfo("stars.flags", &flags_str
));
710 ASSERT_TRUE(base::StringToInt(flags_str
, &flags
));
711 EXPECT_EQ(1, (flags
& 1));
713 meta_info
["stars.flags"] = "0";
714 const BookmarkNode
* node2
=
715 bookmark_model_
->AddURLWithCreationTimeAndMetaInfo(
716 bookmark_model_
->other_node(),
718 base::ASCIIToUTF16("Some title"),
722 base::RunLoop().RunUntilIdle();
723 ASSERT_TRUE(node2
->GetMetaInfo("stars.flags", &flags_str
));
724 ASSERT_TRUE(base::StringToInt(flags_str
, &flags
));
725 EXPECT_EQ(0, (flags
& 1));
728 TEST_F(EnhancedBookmarkModelTest
,
729 NodeRemovedWhileSetNeedsOfflineProcessingIsScheduled
) {
730 const BookmarkNode
* node
=
731 bookmark_model_
->AddURL(bookmark_model_
->other_node(),
733 base::ASCIIToUTF16("Some title"),
735 bookmark_model_
->Remove(node
->parent(), node
->parent()->GetIndexOf(node
));
736 base::RunLoop().RunUntilIdle();