| OLD | NEW |
| 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/enhanced_bookmarks/enhanced_bookmark_model.h" | 5 #include "components/enhanced_bookmarks/enhanced_bookmark_model.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
| 45 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT)); | 45 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_DEFAULT)); |
| 46 bookmark_client_.reset(new bookmarks::TestBookmarkClient()); | 46 bookmark_client_.reset(new bookmarks::TestBookmarkClient()); |
| 47 bookmark_model_.reset(bookmark_client_->CreateModel().release()); | 47 bookmark_model_.reset(bookmark_client_->CreateModel().release()); |
| 48 model_.reset(new EnhancedBookmarkModel(bookmark_model_.get(), "v1.0")); | 48 model_.reset(new EnhancedBookmarkModel(bookmark_model_.get(), "v1.0")); |
| 49 model_->AddObserver(this); | 49 model_->AddObserver(this); |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual void TearDown() OVERRIDE { | 52 virtual void TearDown() OVERRIDE { |
| 53 if (model_) | 53 if (model_) |
| 54 model_->ShutDown(); | 54 model_->Shutdown(); |
| 55 model_.reset(); | 55 model_.reset(); |
| 56 bookmark_model_.reset(); | 56 bookmark_model_.reset(); |
| 57 bookmark_client_.reset(); | 57 bookmark_client_.reset(); |
| 58 message_loop_.reset(); | 58 message_loop_.reset(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 const BookmarkNode* AddBookmark() { | 62 const BookmarkNode* AddBookmark() { |
| 63 return AddBookmark("Some title", bookmark_model_->other_node()); | 63 return AddBookmark("Some title", bookmark_model_->other_node()); |
| 64 } | 64 } |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // Since the description didn't actually change, the version field should | 440 // Since the description didn't actually change, the version field should |
| 441 // not either. | 441 // not either. |
| 442 EXPECT_EQ("v1.0", GetVersion(node)); | 442 EXPECT_EQ("v1.0", GetVersion(node)); |
| 443 | 443 |
| 444 model_->SetDescription(node, "bar"); | 444 model_->SetDescription(node, "bar"); |
| 445 EXPECT_EQ("v1.0/alpha", GetVersion(node)); | 445 EXPECT_EQ("v1.0/alpha", GetVersion(node)); |
| 446 } | 446 } |
| 447 | 447 |
| 448 // Verifies that duplicate nodes are reset when the model is created. | 448 // Verifies that duplicate nodes are reset when the model is created. |
| 449 TEST_F(EnhancedBookmarkModelTest, ResetDuplicateNodesOnInitialization) { | 449 TEST_F(EnhancedBookmarkModelTest, ResetDuplicateNodesOnInitialization) { |
| 450 model_->ShutDown(); | 450 model_->Shutdown(); |
| 451 | 451 |
| 452 const BookmarkNode* parent = bookmark_model_->other_node(); | 452 const BookmarkNode* parent = bookmark_model_->other_node(); |
| 453 const BookmarkNode* node1 = bookmark_model_->AddURL( | 453 const BookmarkNode* node1 = bookmark_model_->AddURL( |
| 454 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); | 454 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); |
| 455 const BookmarkNode* node2 = bookmark_model_->AddURL( | 455 const BookmarkNode* node2 = bookmark_model_->AddURL( |
| 456 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); | 456 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); |
| 457 const BookmarkNode* node3 = bookmark_model_->AddURL( | 457 const BookmarkNode* node3 = bookmark_model_->AddURL( |
| 458 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); | 458 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); |
| 459 const BookmarkNode* node4 = bookmark_model_->AddURL( | 459 const BookmarkNode* node4 = bookmark_model_->AddURL( |
| 460 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); | 460 parent, 0, base::ASCIIToUTF16("Some title"), GURL(BOOKMARK_URL)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 EXPECT_EQ("v1.0/2", GetVersion(node)); | 556 EXPECT_EQ("v1.0/2", GetVersion(node)); |
| 557 | 557 |
| 558 // Not actually changing any values should not set the version field. | 558 // Not actually changing any values should not set the version field. |
| 559 model_->SetVersionSuffix("3"); | 559 model_->SetVersionSuffix("3"); |
| 560 model_->SetMultipleMetaInfo(node, meta_info); | 560 model_->SetMultipleMetaInfo(node, meta_info); |
| 561 EXPECT_EQ("v1.0/2", GetVersion(node)); | 561 EXPECT_EQ("v1.0/2", GetVersion(node)); |
| 562 } | 562 } |
| 563 | 563 |
| 564 TEST_F(EnhancedBookmarkModelTest, ObserverShuttingDownEvent) { | 564 TEST_F(EnhancedBookmarkModelTest, ObserverShuttingDownEvent) { |
| 565 EXPECT_EQ(0, shutting_down_calls_); | 565 EXPECT_EQ(0, shutting_down_calls_); |
| 566 model_->ShutDown(); | 566 model_->Shutdown(); |
| 567 EXPECT_EQ(1, shutting_down_calls_); | 567 EXPECT_EQ(1, shutting_down_calls_); |
| 568 model_.reset(); | 568 model_.reset(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 TEST_F(EnhancedBookmarkModelTest, ObserverNodeAddedEvent) { | 571 TEST_F(EnhancedBookmarkModelTest, ObserverNodeAddedEvent) { |
| 572 EXPECT_EQ(0, added_calls_); | 572 EXPECT_EQ(0, added_calls_); |
| 573 const BookmarkNode* node = AddBookmark(); | 573 const BookmarkNode* node = AddBookmark(); |
| 574 EXPECT_EQ(1, added_calls_); | 574 EXPECT_EQ(1, added_calls_); |
| 575 EXPECT_EQ(node, last_added_); | 575 EXPECT_EQ(node, last_added_); |
| 576 | 576 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 base::RunLoop().RunUntilIdle(); | 638 base::RunLoop().RunUntilIdle(); |
| 639 EXPECT_EQ(6, remote_id_changed_calls_); | 639 EXPECT_EQ(6, remote_id_changed_calls_); |
| 640 EXPECT_EQ("", last_remote_id_); | 640 EXPECT_EQ("", last_remote_id_); |
| 641 } | 641 } |
| 642 | 642 |
| 643 TEST_F(EnhancedBookmarkModelTest, ShutDownWhileResetDuplicationScheduled) { | 643 TEST_F(EnhancedBookmarkModelTest, ShutDownWhileResetDuplicationScheduled) { |
| 644 const BookmarkNode* node1 = AddBookmark(); | 644 const BookmarkNode* node1 = AddBookmark(); |
| 645 const BookmarkNode* node2 = AddBookmark(); | 645 const BookmarkNode* node2 = AddBookmark(); |
| 646 bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1"); | 646 bookmark_model_->SetNodeMetaInfo(node1, "stars.id", "c_1"); |
| 647 bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1"); | 647 bookmark_model_->SetNodeMetaInfo(node2, "stars.id", "c_1"); |
| 648 model_->ShutDown(); | 648 model_->Shutdown(); |
| 649 model_.reset(); | 649 model_.reset(); |
| 650 base::RunLoop().RunUntilIdle(); | 650 base::RunLoop().RunUntilIdle(); |
| 651 } | 651 } |
| OLD | NEW |