| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 EXPECT_EQ(id2, icon_mappings[1].icon_id); | 299 EXPECT_EQ(id2, icon_mappings[1].icon_id); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(ThumbnailDatabaseTest, RetainDataForPageUrls) { | 302 TEST_F(ThumbnailDatabaseTest, RetainDataForPageUrls) { |
| 303 ThumbnailDatabase db(NULL); | 303 ThumbnailDatabase db(NULL); |
| 304 | 304 |
| 305 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 305 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
| 306 | 306 |
| 307 db.BeginTransaction(); | 307 db.BeginTransaction(); |
| 308 | 308 |
| 309 // Build a database mapping kPageUrl1 -> kIconUrl1, kPageUrl2 -> | 309 // Build a database mapping |
| 310 // kIconUrl2, kPageUrl3 -> kIconUrl1, and kPageUrl5 -> kIconUrl5. | 310 // kPageUrl1 -> kIconUrl1 |
| 311 // Then retain kPageUrl1, kPageUrl3, and kPageUrl5. kPageUrl2 | 311 // kPageUrl2 -> kIconUrl2 |
| 312 // should go away, but the others should be retained correctly. | 312 // kPageUrl3 -> kIconUrl1 |
| 313 // kPageUrl4 -> kIconUrl1 |
| 314 // kPageUrl5 -> kIconUrl5 |
| 315 // Then retain kPageUrl1, kPageUrl3, and kPageUrl5. kPageUrl2 |
| 316 // and kPageUrl4 should go away, but the others should be retained |
| 317 // correctly. |
| 313 | 318 |
| 314 // TODO(shess): This would probably make sense as a golden file. | 319 // TODO(shess): This would probably make sense as a golden file. |
| 315 | 320 |
| 316 scoped_refptr<base::RefCountedStaticMemory> favicon1( | 321 scoped_refptr<base::RefCountedStaticMemory> favicon1( |
| 317 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1))); | 322 new base::RefCountedStaticMemory(kBlob1, sizeof(kBlob1))); |
| 318 scoped_refptr<base::RefCountedStaticMemory> favicon2( | 323 scoped_refptr<base::RefCountedStaticMemory> favicon2( |
| 319 new base::RefCountedStaticMemory(kBlob2, sizeof(kBlob2))); | 324 new base::RefCountedStaticMemory(kBlob2, sizeof(kBlob2))); |
| 320 | 325 |
| 321 favicon_base::FaviconID kept_id1 = | 326 favicon_base::FaviconID kept_id1 = |
| 322 db.AddFavicon(kIconUrl1, favicon_base::FAVICON); | 327 db.AddFavicon(kIconUrl1, favicon_base::FAVICON); |
| 323 db.AddFaviconBitmap(kept_id1, favicon1, base::Time::Now(), kLargeSize); | 328 db.AddFaviconBitmap(kept_id1, favicon1, base::Time::Now(), kLargeSize); |
| 324 db.AddIconMapping(kPageUrl1, kept_id1); | 329 db.AddIconMapping(kPageUrl1, kept_id1); |
| 325 db.AddIconMapping(kPageUrl3, kept_id1); | 330 db.AddIconMapping(kPageUrl3, kept_id1); |
| 331 db.AddIconMapping(kPageUrl4, kept_id1); |
| 326 | 332 |
| 327 favicon_base::FaviconID unkept_id = | 333 favicon_base::FaviconID unkept_id = |
| 328 db.AddFavicon(kIconUrl2, favicon_base::FAVICON); | 334 db.AddFavicon(kIconUrl2, favicon_base::FAVICON); |
| 329 db.AddFaviconBitmap(unkept_id, favicon1, base::Time::Now(), kLargeSize); | 335 db.AddFaviconBitmap(unkept_id, favicon1, base::Time::Now(), kLargeSize); |
| 330 db.AddIconMapping(kPageUrl2, unkept_id); | 336 db.AddIconMapping(kPageUrl2, unkept_id); |
| 331 | 337 |
| 332 favicon_base::FaviconID kept_id2 = | 338 favicon_base::FaviconID kept_id2 = |
| 333 db.AddFavicon(kIconUrl5, favicon_base::FAVICON); | 339 db.AddFavicon(kIconUrl5, favicon_base::FAVICON); |
| 334 db.AddFaviconBitmap(kept_id2, favicon2, base::Time::Now(), kLargeSize); | 340 db.AddFaviconBitmap(kept_id2, favicon2, base::Time::Now(), kLargeSize); |
| 335 db.AddIconMapping(kPageUrl5, kept_id2); | 341 db.AddIconMapping(kPageUrl5, kept_id2); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 360 sizeof(kBlob1), | 366 sizeof(kBlob1), |
| 361 kBlob1)); | 367 kBlob1)); |
| 362 EXPECT_TRUE(CheckPageHasIcon(&db, | 368 EXPECT_TRUE(CheckPageHasIcon(&db, |
| 363 kPageUrl5, | 369 kPageUrl5, |
| 364 favicon_base::FAVICON, | 370 favicon_base::FAVICON, |
| 365 kIconUrl5, | 371 kIconUrl5, |
| 366 kLargeSize, | 372 kLargeSize, |
| 367 sizeof(kBlob2), | 373 sizeof(kBlob2), |
| 368 kBlob2)); | 374 kBlob2)); |
| 369 | 375 |
| 370 // The one not retained should be missing. | 376 // The ones not retained should be missing. |
| 371 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(kPageUrl2, false, NULL)); | 377 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(kPageUrl2, false, NULL)); |
| 378 EXPECT_FALSE(db.GetFaviconIDForFaviconURL(kPageUrl4, false, NULL)); |
| 372 | 379 |
| 373 // Schema should be the same. | 380 // Schema should be the same. |
| 374 EXPECT_EQ(original_schema, db.db_.GetSchema()); | 381 EXPECT_EQ(original_schema, db.db_.GetSchema()); |
| 375 } | 382 } |
| 376 | 383 |
| 377 // Tests that deleting a favicon deletes the favicon row and favicon bitmap | 384 // Tests that deleting a favicon deletes the favicon row and favicon bitmap |
| 378 // rows from the database. | 385 // rows from the database. |
| 379 TEST_F(ThumbnailDatabaseTest, DeleteFavicon) { | 386 TEST_F(ThumbnailDatabaseTest, DeleteFavicon) { |
| 380 ThumbnailDatabase db(NULL); | 387 ThumbnailDatabase db(NULL); |
| 381 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); | 388 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 ThumbnailDatabase db(NULL); | 1029 ThumbnailDatabase db(NULL); |
| 1023 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); | 1030 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); |
| 1024 | 1031 |
| 1025 // Verify that the resulting schema is correct, whether it | 1032 // Verify that the resulting schema is correct, whether it |
| 1026 // involved razing the file or fixing things in place. | 1033 // involved razing the file or fixing things in place. |
| 1027 VerifyTablesAndColumns(&db.db_); | 1034 VerifyTablesAndColumns(&db.db_); |
| 1028 } | 1035 } |
| 1029 } | 1036 } |
| 1030 | 1037 |
| 1031 } // namespace history | 1038 } // namespace history |
| OLD | NEW |