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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "components/bookmarks/browser/bookmark_node.h" | 16 #include "components/bookmarks/browser/bookmark_node.h" |
17 #include "components/bookmarks/test/test_bookmark_client.h" | 17 #include "components/bookmarks/test/test_bookmark_client.h" |
18 #include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h" | 18 #include "components/enhanced_bookmarks/enhanced_bookmark_model_observer.h" |
19 #include "components/enhanced_bookmarks/proto/metadata.pb.h" | 19 #include "components/enhanced_bookmarks/proto/metadata.pb.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 using bookmarks::BookmarkModel; | 23 using bookmarks::BookmarkModel; |
24 using enhanced_bookmarks::EnhancedBookmarkModel; | 24 using enhanced_bookmarks::EnhancedBookmarkModel; |
25 | 25 |
26 namespace { | 26 namespace { |
27 const std::string BOOKMARK_URL("http://example.com/index.html"); | 27 const std::string BOOKMARK_URL("http://example.com/index.html"); |
| 28 const std::string IMAGE_URL("http://example.com/image.jpg"); |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 class EnhancedBookmarkModelTest | 31 class EnhancedBookmarkModelTest |
31 : public testing::Test, | 32 : public testing::Test, |
32 public enhanced_bookmarks::EnhancedBookmarkModelObserver { | 33 public enhanced_bookmarks::EnhancedBookmarkModelObserver { |
33 public: | 34 public: |
34 EnhancedBookmarkModelTest() | 35 EnhancedBookmarkModelTest() |
35 : loaded_calls_(0), | 36 : loaded_calls_(0), |
36 shutting_down_calls_(0), | 37 shutting_down_calls_(0), |
37 added_calls_(0), | 38 added_calls_(0), |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 const BookmarkNode* gp = parent->parent(); | 767 const BookmarkNode* gp = parent->parent(); |
767 bookmark_model_->Remove(gp, gp->GetIndexOf(parent)); | 768 bookmark_model_->Remove(gp, gp->GetIndexOf(parent)); |
768 EXPECT_FALSE(model_->BookmarkForRemoteId(remote_id)); | 769 EXPECT_FALSE(model_->BookmarkForRemoteId(remote_id)); |
769 } | 770 } |
770 | 771 |
771 TEST_F(EnhancedBookmarkModelTest, AddsRemoteIdToNonClonedKeys) { | 772 TEST_F(EnhancedBookmarkModelTest, AddsRemoteIdToNonClonedKeys) { |
772 const std::set<std::string>& non_cloned_keys = | 773 const std::set<std::string>& non_cloned_keys = |
773 bookmark_model_->non_cloned_keys(); | 774 bookmark_model_->non_cloned_keys(); |
774 EXPECT_TRUE(non_cloned_keys.find("stars.id") != non_cloned_keys.end()); | 775 EXPECT_TRUE(non_cloned_keys.find("stars.id") != non_cloned_keys.end()); |
775 } | 776 } |
| 777 |
| 778 TEST_F(EnhancedBookmarkModelTest, RemoveImageData) { |
| 779 const BookmarkNode* node = AddBookmark(); |
| 780 model_->SetAllImages(node, GURL(IMAGE_URL), 64, 64, GURL(IMAGE_URL), 16, 16); |
| 781 |
| 782 GURL url; |
| 783 int width, height; |
| 784 EXPECT_TRUE(model_->GetOriginalImage(node, &url, &width, &height)); |
| 785 EXPECT_TRUE(model_->GetThumbnailImage(node, &url, &width, &height)); |
| 786 |
| 787 model_->RemoveImageData(node); |
| 788 EXPECT_FALSE(model_->GetOriginalImage(node, &url, &width, &height)); |
| 789 EXPECT_FALSE(model_->GetThumbnailImage(node, &url, &width, &height)); |
| 790 |
| 791 std::string meta_info = GetMetaInfoField(node, "stars.imageData"); |
| 792 std::string decoded; |
| 793 ASSERT_TRUE(base::Base64Decode(meta_info, &decoded)); |
| 794 image::collections::ImageData data; |
| 795 ASSERT_TRUE(data.ParseFromString(decoded)); |
| 796 EXPECT_TRUE(data.user_removed_image()); |
| 797 } |
OLD | NEW |