| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (iter == icon_mappings.end()) { | 119 if (iter == icon_mappings.end()) { |
| 120 ADD_FAILURE() << "failed to find |expected_icon_type|"; | 120 ADD_FAILURE() << "failed to find |expected_icon_type|"; |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (expected_icon_url != iter->icon_url) { | 124 if (expected_icon_url != iter->icon_url) { |
| 125 EXPECT_EQ(expected_icon_url, iter->icon_url); | 125 EXPECT_EQ(expected_icon_url, iter->icon_url); |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 std::vector<FaviconBitmap> favicon_bitmaps; | 129 std::vector<FaviconRawBitmap> favicon_bitmaps; |
| 130 if (!db->GetFaviconBitmaps(iter->icon_id, &favicon_bitmaps)) { | 130 if (!db->GetFaviconRawBitmaps(iter->icon_id, &favicon_bitmaps)) { |
| 131 ADD_FAILURE() << "failed GetFaviconBitmaps()"; | 131 ADD_FAILURE() << "failed GetFaviconRawBitmaps()"; |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 | 134 |
| 135 if (1 != favicon_bitmaps.size()) { | 135 if (1 != favicon_bitmaps.size()) { |
| 136 EXPECT_EQ(1u, favicon_bitmaps.size()); | 136 EXPECT_EQ(1u, favicon_bitmaps.size()); |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 if (expected_icon_size != favicon_bitmaps[0].pixel_size) { | 140 if (expected_icon_size != favicon_bitmaps[0].pixel_size) { |
| 141 EXPECT_EQ(expected_icon_size, favicon_bitmaps[0].pixel_size); | 141 EXPECT_EQ(expected_icon_size, favicon_bitmaps[0].pixel_size); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ThumbnailDatabase db; | 246 ThumbnailDatabase db; |
| 247 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 247 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
| 248 db.BeginTransaction(); | 248 db.BeginTransaction(); |
| 249 | 249 |
| 250 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 250 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
| 251 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 251 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 252 | 252 |
| 253 GURL url("http://google.com"); | 253 GURL url("http://google.com"); |
| 254 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); | 254 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::TOUCH_ICON); |
| 255 base::Time time = base::Time::Now(); | 255 base::Time time = base::Time::Now(); |
| 256 db.AddFaviconBitmap(id, favicon, time, gfx::Size()); | 256 db.AddFaviconRawBitmap(id, favicon, time, gfx::Size()); |
| 257 EXPECT_LT(0, db.AddIconMapping(url, id)); | 257 EXPECT_LT(0, db.AddIconMapping(url, id)); |
| 258 | 258 |
| 259 favicon_base::FaviconID id2 = db.AddFavicon(url, favicon_base::FAVICON); | 259 favicon_base::FaviconID id2 = db.AddFavicon(url, favicon_base::FAVICON); |
| 260 EXPECT_LT(0, db.AddIconMapping(url, id2)); | 260 EXPECT_LT(0, db.AddIconMapping(url, id2)); |
| 261 ASSERT_NE(id, id2); | 261 ASSERT_NE(id, id2); |
| 262 | 262 |
| 263 std::vector<IconMapping> icon_mapping; | 263 std::vector<IconMapping> icon_mapping; |
| 264 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); | 264 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mapping)); |
| 265 ASSERT_EQ(2u, icon_mapping.size()); | 265 ASSERT_EQ(2u, icon_mapping.size()); |
| 266 EXPECT_EQ(icon_mapping.front().icon_type, favicon_base::TOUCH_ICON); | 266 EXPECT_EQ(icon_mapping.front().icon_type, favicon_base::TOUCH_ICON); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 277 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 277 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
| 278 db.BeginTransaction(); | 278 db.BeginTransaction(); |
| 279 | 279 |
| 280 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 280 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
| 281 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 281 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 282 | 282 |
| 283 GURL url("http://google.com"); | 283 GURL url("http://google.com"); |
| 284 | 284 |
| 285 favicon_base::FaviconID id1 = db.AddFavicon(url, favicon_base::TOUCH_ICON); | 285 favicon_base::FaviconID id1 = db.AddFavicon(url, favicon_base::TOUCH_ICON); |
| 286 base::Time time = base::Time::Now(); | 286 base::Time time = base::Time::Now(); |
| 287 db.AddFaviconBitmap(id1, favicon, time, kSmallSize); | 287 db.AddFaviconRawBitmap(id1, favicon, time, kSmallSize); |
| 288 db.AddFaviconBitmap(id1, favicon, time, kLargeSize); | 288 db.AddFaviconRawBitmap(id1, favicon, time, kLargeSize); |
| 289 EXPECT_LT(0, db.AddIconMapping(url, id1)); | 289 EXPECT_LT(0, db.AddIconMapping(url, id1)); |
| 290 | 290 |
| 291 favicon_base::FaviconID id2 = db.AddFavicon(url, favicon_base::FAVICON); | 291 favicon_base::FaviconID id2 = db.AddFavicon(url, favicon_base::FAVICON); |
| 292 EXPECT_NE(id1, id2); | 292 EXPECT_NE(id1, id2); |
| 293 db.AddFaviconBitmap(id2, favicon, time, kSmallSize); | 293 db.AddFaviconRawBitmap(id2, favicon, time, kSmallSize); |
| 294 EXPECT_LT(0, db.AddIconMapping(url, id2)); | 294 EXPECT_LT(0, db.AddIconMapping(url, id2)); |
| 295 | 295 |
| 296 std::vector<IconMapping> icon_mappings; | 296 std::vector<IconMapping> icon_mappings; |
| 297 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings)); | 297 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings)); |
| 298 ASSERT_EQ(2u, icon_mappings.size()); | 298 ASSERT_EQ(2u, icon_mappings.size()); |
| 299 EXPECT_EQ(id1, icon_mappings[0].icon_id); | 299 EXPECT_EQ(id1, icon_mappings[0].icon_id); |
| 300 EXPECT_EQ(id2, icon_mappings[1].icon_id); | 300 EXPECT_EQ(id2, icon_mappings[1].icon_id); |
| 301 } | 301 } |
| 302 | 302 |
| 303 TEST_F(ThumbnailDatabaseTest, RetainDataForPageUrls) { | 303 TEST_F(ThumbnailDatabaseTest, RetainDataForPageUrls) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 314 | 314 |
| 315 // TODO(shess): This would probably make sense as a golden file. | 315 // TODO(shess): This would probably make sense as a golden file. |
| 316 | 316 |
| 317 scoped_refptr<base::RefCountedStaticMemory> favicon1( | 317 scoped_refptr<base::RefCountedStaticMemory> favicon1( |
| 318 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1))); | 318 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1))); |
| 319 scoped_refptr<base::RefCountedStaticMemory> favicon2( | 319 scoped_refptr<base::RefCountedStaticMemory> favicon2( |
| 320 new base::RefCountedStaticMemory(kBlob2, sizeof(kBlob2))); | 320 new base::RefCountedStaticMemory(kBlob2, sizeof(kBlob2))); |
| 321 | 321 |
| 322 favicon_base::FaviconID kept_id1 = | 322 favicon_base::FaviconID kept_id1 = |
| 323 db.AddFavicon(kIconUrl1, favicon_base::FAVICON); | 323 db.AddFavicon(kIconUrl1, favicon_base::FAVICON); |
| 324 db.AddFaviconBitmap(kept_id1, favicon1, base::Time::Now(), kLargeSize); | 324 db.AddFaviconRawBitmap(kept_id1, favicon1, base::Time::Now(), kLargeSize); |
| 325 db.AddIconMapping(kPageUrl1, kept_id1); | 325 db.AddIconMapping(kPageUrl1, kept_id1); |
| 326 db.AddIconMapping(kPageUrl3, kept_id1); | 326 db.AddIconMapping(kPageUrl3, kept_id1); |
| 327 | 327 |
| 328 favicon_base::FaviconID unkept_id = | 328 favicon_base::FaviconID unkept_id = |
| 329 db.AddFavicon(kIconUrl2, favicon_base::FAVICON); | 329 db.AddFavicon(kIconUrl2, favicon_base::FAVICON); |
| 330 db.AddFaviconBitmap(unkept_id, favicon1, base::Time::Now(), kLargeSize); | 330 db.AddFaviconRawBitmap(unkept_id, favicon1, base::Time::Now(), kLargeSize); |
| 331 db.AddIconMapping(kPageUrl2, unkept_id); | 331 db.AddIconMapping(kPageUrl2, unkept_id); |
| 332 | 332 |
| 333 favicon_base::FaviconID kept_id2 = | 333 favicon_base::FaviconID kept_id2 = |
| 334 db.AddFavicon(kIconUrl5, favicon_base::FAVICON); | 334 db.AddFavicon(kIconUrl5, favicon_base::FAVICON); |
| 335 db.AddFaviconBitmap(kept_id2, favicon2, base::Time::Now(), kLargeSize); | 335 db.AddFaviconRawBitmap(kept_id2, favicon2, base::Time::Now(), kLargeSize); |
| 336 db.AddIconMapping(kPageUrl5, kept_id2); | 336 db.AddIconMapping(kPageUrl5, kept_id2); |
| 337 | 337 |
| 338 // RetainDataForPageUrls() uses schema manipulations for efficiency. | 338 // RetainDataForPageUrls() uses schema manipulations for efficiency. |
| 339 // Grab a copy of the schema to make sure the final schema matches. | 339 // Grab a copy of the schema to make sure the final schema matches. |
| 340 const std::string original_schema = db.db_.GetSchema(); | 340 const std::string original_schema = db.db_.GetSchema(); |
| 341 | 341 |
| 342 std::vector<GURL> pages_to_keep; | 342 std::vector<GURL> pages_to_keep; |
| 343 pages_to_keep.push_back(kPageUrl1); | 343 pages_to_keep.push_back(kPageUrl1); |
| 344 pages_to_keep.push_back(kPageUrl3); | 344 pages_to_keep.push_back(kPageUrl3); |
| 345 pages_to_keep.push_back(kPageUrl5); | 345 pages_to_keep.push_back(kPageUrl5); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 std::vector<unsigned char> data1(kBlob1, kBlob1 + sizeof(kBlob1)); | 385 std::vector<unsigned char> data1(kBlob1, kBlob1 + sizeof(kBlob1)); |
| 386 scoped_refptr<base::RefCountedBytes> favicon1( | 386 scoped_refptr<base::RefCountedBytes> favicon1( |
| 387 new base::RefCountedBytes(data1)); | 387 new base::RefCountedBytes(data1)); |
| 388 std::vector<unsigned char> data2(kBlob2, kBlob2 + sizeof(kBlob2)); | 388 std::vector<unsigned char> data2(kBlob2, kBlob2 + sizeof(kBlob2)); |
| 389 scoped_refptr<base::RefCountedBytes> favicon2( | 389 scoped_refptr<base::RefCountedBytes> favicon2( |
| 390 new base::RefCountedBytes(data2)); | 390 new base::RefCountedBytes(data2)); |
| 391 | 391 |
| 392 GURL url("http://google.com"); | 392 GURL url("http://google.com"); |
| 393 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::FAVICON); | 393 favicon_base::FaviconID id = db.AddFavicon(url, favicon_base::FAVICON); |
| 394 base::Time last_updated = base::Time::Now(); | 394 base::Time last_updated = base::Time::Now(); |
| 395 db.AddFaviconBitmap(id, favicon1, last_updated, kSmallSize); | 395 db.AddFaviconRawBitmap(id, favicon1, last_updated, kSmallSize); |
| 396 db.AddFaviconBitmap(id, favicon2, last_updated, kLargeSize); | 396 db.AddFaviconRawBitmap(id, favicon2, last_updated, kLargeSize); |
| 397 | 397 |
| 398 EXPECT_TRUE(db.GetFaviconBitmaps(id, NULL)); | 398 EXPECT_TRUE(db.GetFaviconRawBitmaps(id, NULL)); |
| 399 | 399 |
| 400 EXPECT_TRUE(db.DeleteFavicon(id)); | 400 EXPECT_TRUE(db.DeleteFavicon(id)); |
| 401 EXPECT_FALSE(db.GetFaviconBitmaps(id, NULL)); | 401 EXPECT_FALSE(db.GetFaviconRawBitmaps(id, NULL)); |
| 402 } | 402 } |
| 403 | 403 |
| 404 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { | 404 TEST_F(ThumbnailDatabaseTest, GetIconMappingsForPageURLForReturnOrder) { |
| 405 ThumbnailDatabase db; | 405 ThumbnailDatabase db; |
| 406 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 406 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
| 407 db.BeginTransaction(); | 407 db.BeginTransaction(); |
| 408 | 408 |
| 409 // Add a favicon | 409 // Add a favicon |
| 410 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 410 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
| 411 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 411 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 db.BeginTransaction(); | 580 db.BeginTransaction(); |
| 581 | 581 |
| 582 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); | 582 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
| 583 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); | 583 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| 584 | 584 |
| 585 // Add a favicon which will have icon_mappings | 585 // Add a favicon which will have icon_mappings |
| 586 favicon_base::FaviconID id1 = | 586 favicon_base::FaviconID id1 = |
| 587 db.AddFavicon(GURL("http://google.com"), favicon_base::FAVICON); | 587 db.AddFavicon(GURL("http://google.com"), favicon_base::FAVICON); |
| 588 EXPECT_NE(0, id1); | 588 EXPECT_NE(0, id1); |
| 589 base::Time time = base::Time::Now(); | 589 base::Time time = base::Time::Now(); |
| 590 db.AddFaviconBitmap(id1, favicon, time, gfx::Size()); | 590 db.AddFaviconRawBitmap(id1, favicon, time, gfx::Size()); |
| 591 | 591 |
| 592 // Add another type of favicon | 592 // Add another type of favicon |
| 593 favicon_base::FaviconID id2 = db.AddFavicon( | 593 favicon_base::FaviconID id2 = db.AddFavicon( |
| 594 GURL("http://www.google.com/icon"), favicon_base::TOUCH_ICON); | 594 GURL("http://www.google.com/icon"), favicon_base::TOUCH_ICON); |
| 595 EXPECT_NE(0, id2); | 595 EXPECT_NE(0, id2); |
| 596 time = base::Time::Now(); | 596 time = base::Time::Now(); |
| 597 db.AddFaviconBitmap(id2, favicon, time, gfx::Size()); | 597 db.AddFaviconRawBitmap(id2, favicon, time, gfx::Size()); |
| 598 | 598 |
| 599 // Add 3rd favicon | 599 // Add 3rd favicon |
| 600 favicon_base::FaviconID id3 = db.AddFavicon( | 600 favicon_base::FaviconID id3 = db.AddFavicon( |
| 601 GURL("http://www.google.com/icon"), favicon_base::TOUCH_ICON); | 601 GURL("http://www.google.com/icon"), favicon_base::TOUCH_ICON); |
| 602 EXPECT_NE(0, id3); | 602 EXPECT_NE(0, id3); |
| 603 time = base::Time::Now(); | 603 time = base::Time::Now(); |
| 604 db.AddFaviconBitmap(id3, favicon, time, gfx::Size()); | 604 db.AddFaviconRawBitmap(id3, favicon, time, gfx::Size()); |
| 605 | 605 |
| 606 GURL page1_url("http://page1.com"); | 606 GURL page1_url("http://page1.com"); |
| 607 EXPECT_TRUE(db.AddIconMapping(page1_url, id1)); | 607 EXPECT_TRUE(db.AddIconMapping(page1_url, id1)); |
| 608 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); | 608 EXPECT_TRUE(db.AddIconMapping(page1_url, id2)); |
| 609 | 609 |
| 610 GURL page2_url("http://page2.com"); | 610 GURL page2_url("http://page2.com"); |
| 611 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); | 611 EXPECT_TRUE(db.AddIconMapping(page2_url, id3)); |
| 612 | 612 |
| 613 // Test we do nothing with existing mappings. | 613 // Test we do nothing with existing mappings. |
| 614 std::vector<IconMapping> icon_mapping; | 614 std::vector<IconMapping> icon_mapping; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 ThumbnailDatabase db; | 1023 ThumbnailDatabase db; |
| 1024 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); | 1024 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); |
| 1025 | 1025 |
| 1026 // Verify that the resulting schema is correct, whether it | 1026 // Verify that the resulting schema is correct, whether it |
| 1027 // involved razing the file or fixing things in place. | 1027 // involved razing the file or fixing things in place. |
| 1028 VerifyTablesAndColumns(&db.db_); | 1028 VerifyTablesAndColumns(&db.db_); |
| 1029 } | 1029 } |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 } // namespace history | 1032 } // namespace history |
| OLD | NEW |