| 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/metadata_accessor.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/bookmarks/browser/bookmark_model.h" | 9 #include "components/bookmarks/browser/bookmark_model.h" |
| 10 #include "components/bookmarks/test/test_bookmark_client.h" | 10 #include "components/bookmarks/test/test_bookmark_client.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 GURL url; | 196 GURL url; |
| 197 int width; | 197 int width; |
| 198 int height; | 198 int height; |
| 199 result = enhanced_bookmarks::OriginalImageFromBookmark( | 199 result = enhanced_bookmarks::OriginalImageFromBookmark( |
| 200 node.get(), &url, &width, &height); | 200 node.get(), &url, &width, &height); |
| 201 ASSERT_FALSE(result); | 201 ASSERT_FALSE(result); |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 TEST_F(MetadataAccessorTest, TestEncodeDecode) { | 204 TEST_F(MetadataAccessorTest, TestEncodeDecode) { |
| 205 test::TestBookmarkClient bookmark_client; | 205 test::TestBookmarkClient bookmark_client; |
| 206 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel(false)); | 206 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); |
| 207 const BookmarkNode* node = | 207 const BookmarkNode* node = |
| 208 bookmark_model->AddURL(bookmark_model->other_node(), | 208 bookmark_model->AddURL(bookmark_model->other_node(), |
| 209 0, // index. | 209 0, // index. |
| 210 base::ASCIIToUTF16("whatever"), | 210 base::ASCIIToUTF16("whatever"), |
| 211 GURL(BOOKMARK_URL)); | 211 GURL(BOOKMARK_URL)); |
| 212 | 212 |
| 213 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( | 213 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( |
| 214 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); | 214 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); |
| 215 ASSERT_TRUE(result); | 215 ASSERT_TRUE(result); |
| 216 | 216 |
| 217 GURL url; | 217 GURL url; |
| 218 int width; | 218 int width; |
| 219 int height; | 219 int height; |
| 220 result = enhanced_bookmarks::OriginalImageFromBookmark( | 220 result = enhanced_bookmarks::OriginalImageFromBookmark( |
| 221 node, &url, &width, &height); | 221 node, &url, &width, &height); |
| 222 ASSERT_TRUE(result); | 222 ASSERT_TRUE(result); |
| 223 CHECK_EQ(url, GURL("http://example.com/i.jpg")); | 223 CHECK_EQ(url, GURL("http://example.com/i.jpg")); |
| 224 CHECK_EQ(width, 22); | 224 CHECK_EQ(width, 22); |
| 225 CHECK_EQ(height, 33); | 225 CHECK_EQ(height, 33); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 TEST_F(MetadataAccessorTest, TestDoubleEncodeDecode) { | 228 TEST_F(MetadataAccessorTest, TestDoubleEncodeDecode) { |
| 229 test::TestBookmarkClient bookmark_client; | 229 test::TestBookmarkClient bookmark_client; |
| 230 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel(false)); | 230 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); |
| 231 const BookmarkNode* node = | 231 const BookmarkNode* node = |
| 232 bookmark_model->AddURL(bookmark_model->other_node(), | 232 bookmark_model->AddURL(bookmark_model->other_node(), |
| 233 0, // index. | 233 0, // index. |
| 234 base::ASCIIToUTF16("whatever"), | 234 base::ASCIIToUTF16("whatever"), |
| 235 GURL(BOOKMARK_URL)); | 235 GURL(BOOKMARK_URL)); |
| 236 | 236 |
| 237 // Encode some information. | 237 // Encode some information. |
| 238 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( | 238 bool result = enhanced_bookmarks::SetOriginalImageForBookmark( |
| 239 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); | 239 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 22, 33); |
| 240 ASSERT_TRUE(result); | 240 ASSERT_TRUE(result); |
| 241 // Encode some different information. | 241 // Encode some different information. |
| 242 result = enhanced_bookmarks::SetOriginalImageForBookmark( | 242 result = enhanced_bookmarks::SetOriginalImageForBookmark( |
| 243 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 33, 44); | 243 bookmark_model.get(), node, GURL("http://example.com/i.jpg"), 33, 44); |
| 244 ASSERT_TRUE(result); | 244 ASSERT_TRUE(result); |
| 245 | 245 |
| 246 GURL url; | 246 GURL url; |
| 247 int width; | 247 int width; |
| 248 int height; | 248 int height; |
| 249 result = enhanced_bookmarks::OriginalImageFromBookmark( | 249 result = enhanced_bookmarks::OriginalImageFromBookmark( |
| 250 node, &url, &width, &height); | 250 node, &url, &width, &height); |
| 251 ASSERT_TRUE(result); | 251 ASSERT_TRUE(result); |
| 252 CHECK_EQ(url, GURL("http://example.com/i.jpg")); | 252 CHECK_EQ(url, GURL("http://example.com/i.jpg")); |
| 253 CHECK_EQ(width, 33); | 253 CHECK_EQ(width, 33); |
| 254 CHECK_EQ(height, 44); | 254 CHECK_EQ(height, 44); |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 TEST_F(MetadataAccessorTest, TestThumbnail) { | 257 TEST_F(MetadataAccessorTest, TestThumbnail) { |
| 258 test::TestBookmarkClient bookmark_client; | 258 test::TestBookmarkClient bookmark_client; |
| 259 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel(false)); | 259 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); |
| 260 const BookmarkNode* node = | 260 const BookmarkNode* node = |
| 261 bookmark_model->AddURL(bookmark_model->other_node(), | 261 bookmark_model->AddURL(bookmark_model->other_node(), |
| 262 0, // index. | 262 0, // index. |
| 263 base::ASCIIToUTF16("whatever"), | 263 base::ASCIIToUTF16("whatever"), |
| 264 GURL(BOOKMARK_URL)); | 264 GURL(BOOKMARK_URL)); |
| 265 | 265 |
| 266 // Encode some information. | 266 // Encode some information. |
| 267 ASSERT_TRUE(enhanced_bookmarks::SetAllImagesForBookmark( | 267 ASSERT_TRUE(enhanced_bookmarks::SetAllImagesForBookmark( |
| 268 bookmark_model.get(), | 268 bookmark_model.get(), |
| 269 node, | 269 node, |
| 270 GURL(), | 270 GURL(), |
| 271 0, | 271 0, |
| 272 0, | 272 0, |
| 273 GURL("http://google.com/img/thumb.jpg"), | 273 GURL("http://google.com/img/thumb.jpg"), |
| 274 33, | 274 33, |
| 275 44)); | 275 44)); |
| 276 GURL url; | 276 GURL url; |
| 277 int width; | 277 int width; |
| 278 int height; | 278 int height; |
| 279 bool result = enhanced_bookmarks::ThumbnailImageFromBookmark( | 279 bool result = enhanced_bookmarks::ThumbnailImageFromBookmark( |
| 280 node, &url, &width, &height); | 280 node, &url, &width, &height); |
| 281 ASSERT_TRUE(result); | 281 ASSERT_TRUE(result); |
| 282 CHECK_EQ(url, GURL("http://google.com/img/thumb.jpg")); | 282 CHECK_EQ(url, GURL("http://google.com/img/thumb.jpg")); |
| 283 CHECK_EQ(width, 33); | 283 CHECK_EQ(width, 33); |
| 284 CHECK_EQ(height, 44); | 284 CHECK_EQ(height, 44); |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 TEST_F(MetadataAccessorTest, TestRemoteId) { | 287 TEST_F(MetadataAccessorTest, TestRemoteId) { |
| 288 test::TestBookmarkClient bookmark_client; | 288 test::TestBookmarkClient bookmark_client; |
| 289 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel(false)); | 289 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); |
| 290 const BookmarkNode* node = AddBookmark(bookmark_model.get(), "Aga Khan"); | 290 const BookmarkNode* node = AddBookmark(bookmark_model.get(), "Aga Khan"); |
| 291 | 291 |
| 292 // First call creates the UUID, second call should return the same. | 292 // First call creates the UUID, second call should return the same. |
| 293 ASSERT_EQ( | 293 ASSERT_EQ( |
| 294 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node), | 294 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node), |
| 295 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node)); | 295 enhanced_bookmarks::RemoteIdFromBookmark(bookmark_model.get(), node)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(MetadataAccessorTest, TestEmptyDescription) { | 298 TEST_F(MetadataAccessorTest, TestEmptyDescription) { |
| 299 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 299 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); |
| 300 | 300 |
| 301 std::string description( | 301 std::string description( |
| 302 enhanced_bookmarks::DescriptionFromBookmark(node.get())); | 302 enhanced_bookmarks::DescriptionFromBookmark(node.get())); |
| 303 CHECK_EQ(description, ""); | 303 CHECK_EQ(description, ""); |
| 304 } | 304 } |
| 305 | 305 |
| 306 TEST_F(MetadataAccessorTest, TestDescription) { | 306 TEST_F(MetadataAccessorTest, TestDescription) { |
| 307 test::TestBookmarkClient bookmark_client; | 307 test::TestBookmarkClient bookmark_client; |
| 308 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel(false)); | 308 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); |
| 309 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 309 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); |
| 310 const std::string description("This is the most useful description of all."); | 310 const std::string description("This is the most useful description of all."); |
| 311 | 311 |
| 312 // Set the description. | 312 // Set the description. |
| 313 enhanced_bookmarks::SetDescriptionForBookmark( | 313 enhanced_bookmarks::SetDescriptionForBookmark( |
| 314 bookmark_model.get(), node.get(), description); | 314 bookmark_model.get(), node.get(), description); |
| 315 | 315 |
| 316 // Check the description is the one that was set. | 316 // Check the description is the one that was set. |
| 317 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), | 317 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), |
| 318 description); | 318 description); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // If there is no notes field, the description should fall back on the snippet. | 321 // If there is no notes field, the description should fall back on the snippet. |
| 322 TEST_F(MetadataAccessorTest, TestDescriptionFallback) { | 322 TEST_F(MetadataAccessorTest, TestDescriptionFallback) { |
| 323 test::TestBookmarkClient bookmark_client; | 323 test::TestBookmarkClient bookmark_client; |
| 324 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel(false)); | 324 scoped_ptr<BookmarkModel> bookmark_model(bookmark_client.CreateModel()); |
| 325 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); | 325 scoped_ptr<BookmarkNode> node(new BookmarkNode(GURL(BOOKMARK_URL))); |
| 326 | 326 |
| 327 // Binary serialize the protobuf. | 327 // Binary serialize the protobuf. |
| 328 PageData data; | 328 PageData data; |
| 329 data.set_snippet("Joe Bar Team"); | 329 data.set_snippet("Joe Bar Team"); |
| 330 ASSERT_TRUE(data.IsInitialized()); | 330 ASSERT_TRUE(data.IsInitialized()); |
| 331 std::string output; | 331 std::string output; |
| 332 bool result = data.SerializeToString(&output); | 332 bool result = data.SerializeToString(&output); |
| 333 ASSERT_TRUE(result); | 333 ASSERT_TRUE(result); |
| 334 | 334 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 345 // Set the description. | 345 // Set the description. |
| 346 const std::string description("This is the most useful description of all."); | 346 const std::string description("This is the most useful description of all."); |
| 347 enhanced_bookmarks::SetDescriptionForBookmark( | 347 enhanced_bookmarks::SetDescriptionForBookmark( |
| 348 bookmark_model.get(), node.get(), description); | 348 bookmark_model.get(), node.get(), description); |
| 349 | 349 |
| 350 // Check the description is the one that was set. | 350 // Check the description is the one that was set. |
| 351 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), | 351 CHECK_EQ(enhanced_bookmarks::DescriptionFromBookmark(node.get()), |
| 352 description); | 352 description); |
| 353 } | 353 } |
| 354 } // namespace | 354 } // namespace |
| OLD | NEW |