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/metadata_accessor.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" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
9 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
| 13 #include "components/bookmarks/browser/bookmark_node.h" |
10 #include "components/bookmarks/test/test_bookmark_client.h" | 14 #include "components/bookmarks/test/test_bookmark_client.h" |
11 #include "components/enhanced_bookmarks/proto/metadata.pb.h" | 15 #include "components/enhanced_bookmarks/proto/metadata.pb.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" |
13 | 18 |
14 namespace { | 19 namespace { |
15 | 20 |
16 using namespace image::collections; | |
17 | |
18 const std::string BOOKMARK_URL("http://example.com/index.html"); | 21 const std::string BOOKMARK_URL("http://example.com/index.html"); |
19 | 22 |
20 class MetadataAccessorTest : public testing::Test { | 23 class EnhancedBookmarkModelTest : public testing::Test { |
21 public: | 24 public: |
22 MetadataAccessorTest() {} | 25 EnhancedBookmarkModelTest() {} |
23 virtual ~MetadataAccessorTest() {} | 26 virtual ~EnhancedBookmarkModelTest() {} |
| 27 |
| 28 virtual void SetUp() OVERRIDE { |
| 29 test::TestBookmarkClient bookmark_client; |
| 30 bookmark_model_.reset(bookmark_client.CreateModel().release()); |
| 31 model_.reset( |
| 32 new enhanced_bookmarks::EnhancedBookmarkModel(bookmark_model_.get())); |
| 33 model_->Initialize("v1.0"); |
| 34 } |
| 35 |
| 36 virtual void TearDown() OVERRIDE { |
| 37 model_.reset(); |
| 38 bookmark_model_.reset(); |
| 39 } |
24 | 40 |
25 protected: | 41 protected: |
26 DISALLOW_COPY_AND_ASSIGN(MetadataAccessorTest); | 42 const BookmarkNode* AddBookmark() { |
| 43 return AddBookmark("Some title", bookmark_model_->other_node()); |
| 44 } |
27 | 45 |
28 // Adds a bookmark as the subnode at index 0 to other_node. | 46 const BookmarkNode* AddFolder() { |
29 // |name| should be ASCII encoded. | 47 return AddFolder("Some title", bookmark_model_->other_node()); |
30 // Returns the newly added bookmark. | |
31 const BookmarkNode* AddBookmark(BookmarkModel* model, std::string name) { | |
32 return model->AddURL(model->other_node(), | |
33 0, // index. | |
34 base::ASCIIToUTF16(name), | |
35 GURL(BOOKMARK_URL)); | |
36 } | 48 } |
| 49 |
| 50 const BookmarkNode* AddBookmark(const std::string& name, |
| 51 const BookmarkNode* parent) { |
| 52 return bookmark_model_->AddURL(parent, |
| 53 0, // index. |
| 54 base::ASCIIToUTF16(name), |
| 55 GURL(BOOKMARK_URL)); |
| 56 } |
| 57 |
| 58 const BookmarkNode* AddFolder(const std::string& name, |
| 59 const BookmarkNode* parent) { |
| 60 return bookmark_model_->AddFolder(parent, 0, base::ASCIIToUTF16(name)); |
| 61 } |
| 62 |
| 63 scoped_ptr<BookmarkModel> bookmark_model_; |
| 64 scoped_ptr<enhanced_bookmarks::EnhancedBookmarkModel> model_; |
| 65 |
| 66 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(EnhancedBookmarkModelTest); |
37 }; | 68 }; |
38 | 69 |
39 TEST_F(MetadataAccessorTest, TestEmptySnippet) { | 70 TEST_F(EnhancedBookmarkModelTest, TestEmptySnippet) { |
40 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 71 const BookmarkNode* node = AddBookmark(); |
41 | 72 |
42 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 73 std::string snippet(model_->GetSnippetForNode(node)); |
43 CHECK_EQ(snippet, ""); | 74 EXPECT_EQ(snippet, ""); |
44 }; | 75 }; |
45 | 76 |
46 TEST_F(MetadataAccessorTest, TestSnippet) { | 77 TEST_F(EnhancedBookmarkModelTest, TestSnippet) { |
47 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 78 const BookmarkNode* node = AddBookmark(); |
48 | 79 |
49 // Binary serialize the protobuf. | 80 // Binary serialize the protobuf. |
50 PageData data; | 81 image::collections::PageData data; |
51 data.set_snippet("I'm happy!"); | 82 data.set_snippet("I'm happy!"); |
52 ASSERT_TRUE(data.IsInitialized()); | 83 ASSERT_TRUE(data.IsInitialized()); |
53 std::string output; | 84 std::string output; |
54 bool result = data.SerializeToString(&output); | 85 bool result = data.SerializeToString(&output); |
55 ASSERT_TRUE(result); | 86 ASSERT_TRUE(result); |
56 | 87 |
57 // base64 encode the output. | 88 // base64 encode the output. |
58 std::string encoded; | 89 std::string encoded; |
59 base::Base64Encode(output, &encoded); | 90 base::Base64Encode(output, &encoded); |
60 node->SetMetaInfo(enhanced_bookmarks::kPageDataKey, encoded); | 91 bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", encoded); |
61 | 92 |
62 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 93 std::string snippet(model_->GetSnippetForNode(node)); |
63 CHECK_EQ(snippet, "I'm happy!"); | 94 EXPECT_EQ(snippet, "I'm happy!"); |
64 }; | 95 } |
65 | 96 |
66 TEST_F(MetadataAccessorTest, TestBadEncodingSnippet) { | 97 TEST_F(EnhancedBookmarkModelTest, TestBadEncodingSnippet) { |
67 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 98 const BookmarkNode* node = AddBookmark(); |
68 | 99 |
69 // Binary serialize the protobuf. | 100 // Binary serialize the protobuf. |
70 PageData data; | 101 image::collections::PageData data; |
71 data.set_snippet("You are happy!"); | 102 data.set_snippet("You are happy!"); |
72 ASSERT_TRUE(data.IsInitialized()); | 103 ASSERT_TRUE(data.IsInitialized()); |
73 std::string output; | 104 std::string output; |
74 bool result = data.SerializeToString(&output); | 105 bool result = data.SerializeToString(&output); |
75 ASSERT_TRUE(result); | 106 ASSERT_TRUE(result); |
76 | 107 |
77 // don't base 64 encode the output. | 108 // don't base 64 encode the output. |
78 node->SetMetaInfo(enhanced_bookmarks::kPageDataKey, output); | 109 bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", output); |
79 | 110 |
80 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 111 std::string snippet(model_->GetSnippetForNode(node)); |
81 CHECK_EQ(snippet, ""); | 112 EXPECT_EQ(snippet, ""); |
82 }; | 113 } |
83 | 114 |
84 TEST_F(MetadataAccessorTest, TestOriginalImage) { | 115 TEST_F(EnhancedBookmarkModelTest, TestOriginalImage) { |
85 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 116 const BookmarkNode* node = AddBookmark(); |
86 | 117 |
87 ImageData data; | 118 image::collections::ImageData data; |
88 // Intentionally make raw pointer. | 119 // Intentionally make raw pointer. |
89 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 120 image::collections::ImageData_ImageInfo* info = |
| 121 new image::collections::ImageData_ImageInfo; |
90 info->set_url("http://example.com/foobar"); | 122 info->set_url("http://example.com/foobar"); |
91 info->set_width(15); | 123 info->set_width(15); |
92 info->set_height(55); | 124 info->set_height(55); |
93 // This method consumes the pointer. | 125 // This method consumes the pointer. |
94 data.set_allocated_original_info(info); | 126 data.set_allocated_original_info(info); |
95 | 127 |
96 std::string output; | 128 std::string output; |
97 bool result = data.SerializePartialToString(&output); | 129 bool result = data.SerializePartialToString(&output); |
98 ASSERT_TRUE(result); | 130 ASSERT_TRUE(result); |
99 | 131 |
100 // base64 encode the output. | 132 // base64 encode the output. |
101 std::string encoded; | 133 std::string encoded; |
102 base::Base64Encode(output, &encoded); | 134 base::Base64Encode(output, &encoded); |
103 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 135 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
104 | 136 |
105 GURL url; | 137 GURL url; |
106 int width; | 138 int width; |
107 int height; | 139 int height; |
108 result = enhanced_bookmarks::OriginalImageFromBookmark( | 140 result = model_->GetOriginalImageForNode(node, &url, &width, &height); |
109 node.get(), &url, &width, &height); | |
110 ASSERT_TRUE(result); | 141 ASSERT_TRUE(result); |
111 CHECK_EQ(url, GURL("http://example.com/foobar")); | 142 EXPECT_EQ(url, GURL("http://example.com/foobar")); |
112 CHECK_EQ(width, 15); | 143 EXPECT_EQ(width, 15); |
113 CHECK_EQ(height, 55); | 144 EXPECT_EQ(height, 55); |
114 }; | 145 } |
115 | 146 |
116 TEST_F(MetadataAccessorTest, TestThumbnailImage) { | 147 TEST_F(EnhancedBookmarkModelTest, TestThumbnailImage) { |
117 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 148 const BookmarkNode* node = AddBookmark(); |
118 | 149 |
119 ImageData data; | 150 image::collections::ImageData data; |
120 // Intentionally make raw pointer. | 151 // Intentionally make raw pointer. |
121 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 152 image::collections::ImageData_ImageInfo* info = |
| 153 new image::collections::ImageData_ImageInfo; |
122 info->set_url("http://example.com/foobar"); | 154 info->set_url("http://example.com/foobar"); |
123 info->set_width(15); | 155 info->set_width(15); |
124 info->set_height(55); | 156 info->set_height(55); |
125 // This method consumes the pointer. | 157 // This method consumes the pointer. |
126 data.set_allocated_thumbnail_info(info); | 158 data.set_allocated_thumbnail_info(info); |
127 | 159 |
128 std::string output; | 160 std::string output; |
129 bool result = data.SerializePartialToString(&output); | 161 bool result = data.SerializePartialToString(&output); |
130 ASSERT_TRUE(result); | 162 ASSERT_TRUE(result); |
131 | 163 |
132 // base64 encode the output. | 164 // base64 encode the output. |
133 std::string encoded; | 165 std::string encoded; |
134 base::Base64Encode(output, &encoded); | 166 base::Base64Encode(output, &encoded); |
135 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 167 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
136 | 168 |
137 GURL url; | 169 GURL url; |
138 int width; | 170 int width; |
139 int height; | 171 int height; |
140 result = enhanced_bookmarks::ThumbnailImageFromBookmark( | 172 result = model_->GetThumbnailImageForNode(node, &url, &width, &height); |
141 node.get(), &url, &width, &height); | |
142 ASSERT_TRUE(result); | 173 ASSERT_TRUE(result); |
143 CHECK_EQ(url, GURL("http://example.com/foobar")); | 174 EXPECT_EQ(url, GURL("http://example.com/foobar")); |
144 CHECK_EQ(width, 15); | 175 EXPECT_EQ(width, 15); |
145 CHECK_EQ(height, 55); | 176 EXPECT_EQ(height, 55); |
146 }; | 177 } |
147 | 178 |
148 TEST_F(MetadataAccessorTest, TestOriginalImageMissingDimensions) { | 179 TEST_F(EnhancedBookmarkModelTest, TestOriginalImageMissingDimensions) { |
149 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 180 const BookmarkNode* node = AddBookmark(); |
150 | 181 |
151 ImageData data; | 182 image::collections::ImageData data; |
152 // Intentionally make raw pointer. | 183 // Intentionally make raw pointer. |
153 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 184 image::collections::ImageData_ImageInfo* info = |
| 185 new image::collections::ImageData_ImageInfo; |
154 info->set_url("http://example.com/foobar"); | 186 info->set_url("http://example.com/foobar"); |
155 // This method consumes the pointer. | 187 // This method consumes the pointer. |
156 data.set_allocated_original_info(info); | 188 data.set_allocated_original_info(info); |
157 | 189 |
158 std::string output; | 190 std::string output; |
159 bool result = data.SerializePartialToString(&output); | 191 bool result = data.SerializePartialToString(&output); |
160 ASSERT_TRUE(result); | 192 ASSERT_TRUE(result); |
161 | 193 |
162 // base64 encode the output. | 194 // base64 encode the output. |
163 std::string encoded; | 195 std::string encoded; |
164 base::Base64Encode(output, &encoded); | 196 base::Base64Encode(output, &encoded); |
165 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 197 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
166 | 198 |
167 GURL url; | 199 GURL url; |
168 int width; | 200 int width; |
169 int height; | 201 int height; |
170 result = enhanced_bookmarks::OriginalImageFromBookmark( | 202 result = model_->GetOriginalImageForNode(node, &url, &width, &height); |
171 node.get(), &url, &width, &height); | |
172 ASSERT_FALSE(result); | 203 ASSERT_FALSE(result); |
173 }; | 204 } |
174 | 205 |
175 TEST_F(MetadataAccessorTest, TestOriginalImageBadUrl) { | 206 TEST_F(EnhancedBookmarkModelTest, TestOriginalImageBadUrl) { |
176 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 207 const BookmarkNode* node = AddBookmark(); |
177 | 208 |
178 ImageData data; | 209 image::collections::ImageData data; |
179 // Intentionally make raw pointer. | 210 // Intentionally make raw pointer. |
180 ImageData_ImageInfo* info = new ImageData_ImageInfo; | 211 image::collections::ImageData_ImageInfo* info = |
| 212 new image::collections::ImageData_ImageInfo; |
181 info->set_url("asdf. 13r"); | 213 info->set_url("asdf. 13r"); |
182 info->set_width(15); | 214 info->set_width(15); |
183 info->set_height(55); | 215 info->set_height(55); |
184 // This method consumes the pointer. | 216 // This method consumes the pointer. |
185 data.set_allocated_original_info(info); | 217 data.set_allocated_original_info(info); |
186 | 218 |
187 std::string output; | 219 std::string output; |
188 bool result = data.SerializePartialToString(&output); | 220 bool result = data.SerializePartialToString(&output); |
189 ASSERT_TRUE(result); | 221 ASSERT_TRUE(result); |
190 | 222 |
191 // base64 encode the output. | 223 // base64 encode the output. |
192 std::string encoded; | 224 std::string encoded; |
193 base::Base64Encode(output, &encoded); | 225 base::Base64Encode(output, &encoded); |
194 node->SetMetaInfo(enhanced_bookmarks::kImageDataKey, encoded); | 226 bookmark_model_->SetNodeMetaInfo(node, "stars.imageData", encoded); |
195 | 227 |
196 GURL url; | 228 GURL url; |
197 int width; | 229 int width; |
198 int height; | 230 int height; |
199 result = enhanced_bookmarks::OriginalImageFromBookmark( | 231 result = model_->GetOriginalImageForNode(node, &url, &width, &height); |
200 node.get(), &url, &width, &height); | |
201 ASSERT_FALSE(result); | 232 ASSERT_FALSE(result); |
202 }; | 233 } |
203 | 234 |
204 TEST_F(MetadataAccessorTest, TestEncodeDecode) { | 235 TEST_F(EnhancedBookmarkModelTest, TestEncodeDecode) { |
205 test::TestBookmarkClient bookmark_client; | 236 const BookmarkNode* node = AddBookmark(); |
206 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
207 const BookmarkNode* node = | |
208 bookmark_model->AddURL(bookmark_model->other_node(), | |
209 0, // index. | |
210 base::ASCIIToUTF16("whatever"), | |
211 GURL(BOOKMARK_URL)); | |
212 | 237 |
213 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( | 238 bool result = model_->SetOriginalImageForNode( |
214 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); | 239 node, GURL("http://example.com/i.jpg"), 22, 33); |
215 ASSERT_TRUE(result); | 240 ASSERT_TRUE(result); |
216 | 241 |
217 GURL url; | 242 GURL url; |
218 int width; | 243 int width; |
219 int height; | 244 int height; |
220 result = enhanced_bookmarks::OriginalImageFromBookmark( | 245 result = model_->GetOriginalImageForNode(node, &url, &width, &height); |
221 node, &url, &width, &height); | |
222 ASSERT_TRUE(result); | 246 ASSERT_TRUE(result); |
223 CHECK_EQ(url, GURL("http://example.com/i.jpg")); | 247 EXPECT_EQ(url, GURL("http://example.com/i.jpg")); |
224 CHECK_EQ(width, 22); | 248 EXPECT_EQ(width, 22); |
225 CHECK_EQ(height, 33); | 249 EXPECT_EQ(height, 33); |
226 }; | 250 EXPECT_EQ("v1.0", model_->GetVersionForNode(node)); |
| 251 } |
227 | 252 |
228 TEST_F(MetadataAccessorTest, TestDoubleEncodeDecode) { | 253 TEST_F(EnhancedBookmarkModelTest, TestDoubleEncodeDecode) { |
229 test::TestBookmarkClient bookmark_client; | 254 const BookmarkNode* node = AddBookmark(); |
230 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
231 const BookmarkNode* node = | |
232 bookmark_model->AddURL(bookmark_model->other_node(), | |
233 0, // index. | |
234 base::ASCIIToUTF16("whatever"), | |
235 GURL(BOOKMARK_URL)); | |
236 | 255 |
237 // Encode some information. | 256 // Encode some information. |
238 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( | 257 bool result = model_->SetOriginalImageForNode( |
239 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); | 258 node, GURL("http://example.com/i.jpg"), 22, 33); |
240 ASSERT_TRUE(result); | 259 ASSERT_TRUE(result); |
241 // Encode some different information. | 260 // Encode some different information. |
242 result = enhanced_bookmarks::SetOriginalImageForBookmark( | 261 result = model_->SetOriginalImageForNode( |
243 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 33, 44); | 262 node, GURL("http://example.com/i.jpg"), 33, 44); |
244 ASSERT_TRUE(result); | 263 ASSERT_TRUE(result); |
245 | 264 |
246 GURL url; | 265 GURL url; |
247 int width; | 266 int width; |
248 int height; | 267 int height; |
249 result = enhanced_bookmarks::OriginalImageFromBookmark( | 268 result = model_->GetOriginalImageForNode(node, &url, &width, &height); |
250 node, &url, &width, &height); | |
251 ASSERT_TRUE(result); | 269 ASSERT_TRUE(result); |
252 CHECK_EQ(url, GURL("http://example.com/i.jpg")); | 270 EXPECT_EQ(url, GURL("http://example.com/i.jpg")); |
253 CHECK_EQ(width, 33); | 271 EXPECT_EQ(width, 33); |
254 CHECK_EQ(height, 44); | 272 EXPECT_EQ(height, 44); |
255 }; | 273 EXPECT_EQ("v1.0", model_->GetVersionForNode(node)); |
256 | |
257 TEST_F(MetadataAccessorTest, TestThumbnail) { | |
258 test::TestBookmarkClient bookmark_client; | |
259 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
260 const BookmarkNode* node = | |
261 bookmark_model->AddURL(bookmark_model->other_node(), | |
262 0, // index. | |
263 base::ASCIIToUTF16("whatever"), | |
264 GURL(BOOKMARK_URL)); | |
265 | |
266 // Encode some information. | |
267 ASSERT_TRUE(enhanced_bookmarks::SetAllImagesForBookmark( | |
268 bookmark_model.get(), | |
269 node, | |
270 GURL(), | |
271 0, | |
272 0, | |
273 GURL("http://google.com/img/thumb.jpg"), | |
274 33, | |
275 44)); | |
276 GURL url; | |
277 int width; | |
278 int height; | |
279 bool result = enhanced_bookmarks::ThumbnailImageFromBookmark( | |
280 node, &url, &width, &height); | |
281 ASSERT_TRUE(result); | |
282 CHECK_EQ(url, GURL("http://google.com/img/thumb.jpg")); | |
283 CHECK_EQ(width, 33); | |
284 CHECK_EQ(height, 44); | |
285 }; | |
286 | |
287 TEST_F(MetadataAccessorTest, TestRemoteId) { | |
288 test::TestBookmarkClient bookmark_client; | |
289 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
290 const BookmarkNode* node = AddBookmark(bookmark_model.get(), "Aga Khan"); | |
291 | |
292 // First call creates the UUID, second call should return the same. | |
293 ASSERT_EQ( | |
294 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node), | |
295 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node)); | |
296 } | 274 } |
297 | 275 |
298 TEST_F(MetadataAccessorTest, TestEmptyDescription) { | 276 TEST_F(EnhancedBookmarkModelTest, TestRemoteId) { |
299 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 277 const BookmarkNode* node = AddBookmark(); |
| 278 const BookmarkNode* folder_node = AddFolder(); |
300 | 279 |
301 std::string description( | 280 std::string remote_id = model_->GetRemoteIdForNode(node); |
302 enhanced_bookmarks::DescriptionFromBookmark(node.get())); | 281 // First call creates the UUID, second call should return the same. |
303 CHECK_EQ(description, ""); | 282 EXPECT_EQ(remote_id, model_->GetRemoteIdForNode(node)); |
| 283 |
| 284 // Verify that the remote id starts with the correct prefix. |
| 285 EXPECT_TRUE(StartsWithASCII(remote_id, "ebc_", true)); |
| 286 std::string folder_remote_id = model_->GetRemoteIdForNode(folder_node); |
| 287 EXPECT_TRUE(StartsWithASCII(folder_remote_id, "ebf_", true)); |
| 288 |
| 289 // Verifiy version field was set. |
| 290 EXPECT_EQ("v1.0", model_->GetVersionForNode(node)); |
| 291 EXPECT_EQ("v1.0", model_->GetVersionForNode(folder_node)); |
304 } | 292 } |
305 | 293 |
306 TEST_F(MetadataAccessorTest, TestDescription) { | 294 TEST_F(EnhancedBookmarkModelTest, TestEmptyDescription) { |
307 test::TestBookmarkClient bookmark_client; | 295 const BookmarkNode* node = AddBookmark(); |
308 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | 296 |
309 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 297 std::string description(model_->GetDescriptionForNode(node)); |
| 298 EXPECT_EQ(description, ""); |
| 299 } |
| 300 |
| 301 TEST_F(EnhancedBookmarkModelTest, TestDescription) { |
| 302 const BookmarkNode* node = AddBookmark(); |
310 const std::string description("This is the most useful description of all."); | 303 const std::string description("This is the most useful description of all."); |
311 | 304 |
312 // Set the description. | 305 // Set the description. |
313 enhanced_bookmarks::SetDescriptionForBookmark( | 306 model_->SetDescriptionForNode(node, description); |
314 bookmark_model.get(), node.get(), description); | |
315 | 307 |
316 // Check the description is the one that was set. | 308 // Check the description is the one that was set. |
317 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), | 309 EXPECT_EQ(model_->GetDescriptionForNode(node), description); |
318 description); | 310 EXPECT_EQ("v1.0", model_->GetVersionForNode(node)); |
319 } | 311 } |
320 | 312 |
321 // If there is no notes field, the description should fall back on the snippet. | 313 // If there is no notes field, the description should fall back on the snippet. |
322 TEST_F(MetadataAccessorTest, TestDescriptionFallback) { | 314 TEST_F(EnhancedBookmarkModelTest, TestDescriptionFallback) { |
323 test::TestBookmarkClient bookmark_client; | 315 const BookmarkNode* node = AddBookmark(); |
324 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); | |
325 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | |
326 | 316 |
327 // Binary serialize the protobuf. | 317 // Binary serialize the protobuf. |
328 PageData data; | 318 image::collections::PageData data; |
329 data.set_snippet("Joe Bar Team"); | 319 data.set_snippet("Joe Bar Team"); |
330 ASSERT_TRUE(data.IsInitialized()); | 320 ASSERT_TRUE(data.IsInitialized()); |
331 std::string output; | 321 std::string output; |
332 bool result = data.SerializeToString(&output); | 322 bool result = data.SerializeToString(&output); |
333 ASSERT_TRUE(result); | 323 ASSERT_TRUE(result); |
334 | 324 |
335 // base64 encode the output. | 325 // base64 encode the output. |
336 std::string encoded; | 326 std::string encoded; |
337 base::Base64Encode(output, &encoded); | 327 base::Base64Encode(output, &encoded); |
338 node->SetMetaInfo(enhanced_bookmarks::kPageDataKey, encoded); | 328 bookmark_model_->SetNodeMetaInfo(node, "stars.pageData", encoded); |
339 | 329 |
340 // The snippet is used as the description. | 330 // The snippet is used as the description. |
341 std::string snippet(enhanced_bookmarks::SnippetFromBookmark(node.get())); | 331 std::string snippet(model_->GetSnippetForNode(node)); |
342 CHECK_EQ("Joe Bar Team", | 332 EXPECT_EQ("Joe Bar Team", model_->GetDescriptionForNode(node)); |
343 enhanced_bookmarks::DescriptionFromBookmark(node.get())); | |
344 | 333 |
345 // Set the description. | 334 // Set the description. |
346 const std::string description("This is the most useful description of all."); | 335 const std::string description("This is the most useful description of all."); |
347 enhanced_bookmarks::SetDescriptionForBookmark( | 336 model_->SetDescriptionForNode(node, description); |
348 bookmark_model.get(), node.get(), description); | |
349 | 337 |
350 // Check the description is the one that was set. | 338 // Check the description is the one that was set. |
351 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), | 339 EXPECT_EQ(model_->GetDescriptionForNode(node), description); |
352 description); | |
353 } | 340 } |
| 341 |
| 342 // Makes sure that the stars.version field is set every time |
| 343 // EnhancedBookmarkModel makes a change to a node. |
| 344 TEST_F(EnhancedBookmarkModelTest, TestVersionField) { |
| 345 const BookmarkNode* node = AddBookmark(); |
| 346 EXPECT_EQ("", model_->GetVersionForNode(node)); |
| 347 |
| 348 model_->SetDescriptionForNode(node, "foo"); |
| 349 EXPECT_EQ("v1.0", model_->GetVersionForNode(node)); |
| 350 |
| 351 // Change the version to set. |
| 352 model_->Initialize("v1.1"); |
| 353 |
| 354 model_->SetDescriptionForNode(node, "foo"); |
| 355 // Since the description didn't actually change, the version field should |
| 356 // not either. |
| 357 EXPECT_EQ("v1.0", model_->GetVersionForNode(node)); |
| 358 |
| 359 model_->SetDescriptionForNode(node, "bar"); |
| 360 EXPECT_EQ("v1.1", model_->GetVersionForNode(node)); |
| 361 } |
| 362 |
354 } // namespace | 363 } // namespace |
OLD | NEW |