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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // data we'll put into the thumbnail database | 44 // data we'll put into the thumbnail database |
45 static const unsigned char blob1[] = | 45 static const unsigned char blob1[] = |
46 "12346102356120394751634516591348710478123649165419234519234512349134"; | 46 "12346102356120394751634516591348710478123649165419234519234512349134"; |
47 | 47 |
48 static const gfx::Size kSmallSize = gfx::Size(16, 16); | 48 static const gfx::Size kSmallSize = gfx::Size(16, 16); |
49 static const gfx::Size kLargeSize = gfx::Size(48, 48); | 49 static const gfx::Size kLargeSize = gfx::Size(48, 48); |
50 | 50 |
| 51 //const FaviconSizes kSizesSmall(1, kSmallSize); |
| 52 //const FaviconSizes kSizesSmallAndLarge = |
| 53 // ThumbnailDatabase::DatabaseStringToFaviconSizes("16 16 48 48"); |
| 54 |
51 } // namepace | 55 } // namepace |
52 | 56 |
53 namespace history { | 57 namespace history { |
54 | 58 |
55 class HistoryBackendTest; | 59 class HistoryBackendTest; |
56 | 60 |
57 // This must be a separate object since HistoryBackend manages its lifetime. | 61 // This must be a separate object since HistoryBackend manages its lifetime. |
58 // This just forwards the messages we're interested in to the test object. | 62 // This just forwards the messages we're interested in to the test object. |
59 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { | 63 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { |
60 public: | 64 public: |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 URLID id = backend_->db()->GetRowForURL(url, &row); | 198 URLID id = backend_->db()->GetRowForURL(url, &row); |
195 VisitVector visits; | 199 VisitVector visits; |
196 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); | 200 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); |
197 return visits[0].transition; | 201 return visits[0].transition; |
198 } | 202 } |
199 | 203 |
200 FilePath getTestDir() { | 204 FilePath getTestDir() { |
201 return test_dir_; | 205 return test_dir_; |
202 } | 206 } |
203 | 207 |
204 FaviconID GetFavicon(const GURL& url, IconType icon_type) { | 208 // Returns the number of icon mappings of |icon_type| to |page_url|. |
205 IconMapping icon_mapping; | 209 size_t NumIconMappingsForPageURL(const GURL& page_url, IconType icon_type) { |
206 if (backend_->thumbnail_db_->GetIconMappingForPageURL(url, icon_type, | 210 std::vector<IconMapping> icon_mappings; |
207 &icon_mapping)) | 211 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, |
208 return icon_mapping.icon_id; | 212 &icon_mappings)) { |
209 else | 213 return icon_mappings.size(); |
210 return 0; | 214 } |
| 215 return 0u; |
| 216 } |
| 217 |
| 218 // Returns true if there is exactly one favicon bitmap associated to |
| 219 // |icon_url|. If true, returns favicon bitmap in output parameter. |
| 220 bool GetOnlyFaviconBitmapForIconURL(const GURL& icon_url, |
| 221 IconType icon_type, |
| 222 FaviconBitmap* favicon_bitmap) { |
| 223 FaviconID id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
| 224 icon_url, icon_type); |
| 225 if (!id) |
| 226 return false; |
| 227 std::vector<FaviconBitmap> favicon_bitmaps; |
| 228 if (!backend_->thumbnail_db_->GetFaviconBitmaps(id, &favicon_bitmaps)) |
| 229 return false; |
| 230 if (favicon_bitmaps.size() != 1) |
| 231 return false; |
| 232 *favicon_bitmap = favicon_bitmaps[0]; |
| 233 return true; |
| 234 } |
| 235 |
| 236 /* |
| 237 // Deletes favicons and favicon bitmaps for |page_url| and |icon_type|. |
| 238 bool DeleteFaviconsAndFaviconBitmaps(const GURL& page_url, |
| 239 IconType icon_type) { |
| 240 backend_->SetFavicons(page_url, |
| 241 icon_type, |
| 242 std::vector<FaviconDataElement>(), |
| 243 IconURLSizesMap()); |
| 244 return !backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
| 245 icon_type, NULL); |
| 246 } |
| 247 |
| 248 // Sets the favicons for |page_url| and |icon_type|. This is very similar to |
| 249 // HistoryBackend::SetFavicons except that this call will delete favicon |
| 250 // bitmaps which are not in |elements|. This allows setting a favicon state |
| 251 // where a favicon bitmap can be guaranteed to be only specified via sizes and |
| 252 // not have any associated bitmap data in the favicon_bitmaps table. |
| 253 void SetFaviconsState(const GURL& page_url, |
| 254 IconType icon_type, |
| 255 const std::vector<FaviconDataElement>& elements, |
| 256 const IconURLSizesMap& icon_url_sizes) { |
| 257 EXPECT_TRUE(DeleteFaviconsAndFaviconBitmaps(page_url, icon_type)); |
| 258 backend_->SetFavicons(page_url, icon_type, elements, icon_url_sizes); |
| 259 } |
| 260 |
| 261 // Sets |elements| to have entries for the icon_urls and sizes specified. |
| 262 // The bitmap_data for entries are lowercase letters of the alphabet starting |
| 263 // at 'a' for the entry at index 0. |
| 264 void SetFaviconDataElements(const GURL& icon_url1, |
| 265 const FaviconSizes& icon_url1_sizes, |
| 266 std::vector<FaviconDataElement>* elements) { |
| 267 SetFaviconDataElements(icon_url1, icon_url1_sizes, GURL(), FaviconSizes(), |
| 268 elements); |
| 269 } |
| 270 |
| 271 void SetFaviconDataElements(const GURL& icon_url1, |
| 272 const FaviconSizes& icon_url1_sizes, |
| 273 const GURL& icon_url2, |
| 274 const FaviconSizes& icon_url2_sizes, |
| 275 std::vector<FaviconDataElement>* elements) { |
| 276 elements->clear(); |
| 277 |
| 278 char bitmap_char = 'a'; |
| 279 std::vector<gfx::Size> icon_url1_sizes_vector = icon_url1_sizes.ToVector(); |
| 280 for (size_t i = 0; i < icon_url1_sizes_vector.size(); ++i) { |
| 281 std::vector<unsigned char> data; |
| 282 data.push_back(bitmap_char); |
| 283 FaviconDataElement element; |
| 284 element.bitmap_data = base::RefCountedBytes::TakeVector(&data); |
| 285 element.pixel_size = icon_url1_sizes_vector[i]; |
| 286 element.icon_url = icon_url1; |
| 287 elements->push_back(element); |
| 288 |
| 289 ++bitmap_char; |
| 290 } |
| 291 |
| 292 std::vector<gfx::Size> icon_url2_sizes_vector = icon_url2_sizes.ToVector(); |
| 293 for (size_t i = 0; i < icon_url2_sizes_vector.size(); ++i) { |
| 294 std::vector<unsigned char> data; |
| 295 data.push_back(bitmap_char); |
| 296 FaviconDataElement element; |
| 297 element.bitmap_data = base::RefCountedBytes::TakeVector(&data); |
| 298 element.pixel_size = icon_url2_sizes_vector[i]; |
| 299 element.icon_url = icon_url2; |
| 300 elements->push_back(element); |
| 301 |
| 302 ++bitmap_char; |
| 303 } |
| 304 } |
| 305 */ |
| 306 // Returns true if |bitmap_data| is equal to |expected_data|. |
| 307 bool BitmapDataEqual(char expected_data, |
| 308 scoped_refptr<base::RefCountedMemory> bitmap_data) { |
| 309 return bitmap_data.get() && |
| 310 bitmap_data->size() == 1u && |
| 311 *bitmap_data->front() == expected_data; |
211 } | 312 } |
212 | 313 |
213 BookmarkModel bookmark_model_; | 314 BookmarkModel bookmark_model_; |
214 | 315 |
215 protected: | 316 protected: |
216 bool loaded_; | 317 bool loaded_; |
217 | 318 |
218 private: | 319 private: |
219 friend class HistoryBackendTestDelegate; | 320 friend class HistoryBackendTestDelegate; |
220 | 321 |
221 // testing::Test | 322 // testing::Test |
222 virtual void SetUp() { | 323 virtual void SetUp() { |
223 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), | 324 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), |
224 &test_dir_)) | 325 &test_dir_)) |
225 return; | 326 return; |
226 backend_ = new HistoryBackend(test_dir_, | 327 backend_ = new HistoryBackend(test_dir_, |
227 0, | 328 0, |
228 new HistoryBackendTestDelegate(this), | 329 new HistoryBackendTestDelegate(this), |
229 &bookmark_model_); | 330 &bookmark_model_); |
230 backend_->Init(std::string(), false); | 331 backend_->Init(std::string(), false); |
| 332 backend_->set_single_favicon_bitmap_per_icon_type(false); |
231 } | 333 } |
| 334 |
232 virtual void TearDown() { | 335 virtual void TearDown() { |
233 if (backend_.get()) | 336 if (backend_.get()) |
234 backend_->Closing(); | 337 backend_->Closing(); |
235 backend_ = NULL; | 338 backend_ = NULL; |
236 mem_backend_.reset(); | 339 mem_backend_.reset(); |
237 file_util::Delete(test_dir_, true); | 340 file_util::Delete(test_dir_, true); |
238 } | 341 } |
239 | 342 |
240 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) { | 343 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) { |
241 mem_backend_.reset(backend); | 344 mem_backend_.reset(backend); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 509 |
407 // All thumbnails should be deleted. | 510 // All thumbnails should be deleted. |
408 std::vector<unsigned char> out_data; | 511 std::vector<unsigned char> out_data; |
409 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), | 512 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), |
410 &out_data)); | 513 &out_data)); |
411 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); | 514 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); |
412 | 515 |
413 // We should have a favicon and favicon bitmaps for the first URL only. We | 516 // We should have a favicon and favicon bitmaps for the first URL only. We |
414 // look them up by favicon URL since the IDs may have changed. | 517 // look them up by favicon URL since the IDs may have changed. |
415 FaviconID out_favicon1 = backend_->thumbnail_db_-> | 518 FaviconID out_favicon1 = backend_->thumbnail_db_-> |
416 GetFaviconIDForFaviconURL(favicon_url1, FAVICON, NULL); | 519 GetFaviconIDForFaviconURL(favicon_url1, FAVICON); |
417 EXPECT_TRUE(out_favicon1); | 520 EXPECT_TRUE(out_favicon1); |
418 | 521 |
419 std::vector<FaviconBitmap> favicon_bitmaps; | 522 std::vector<FaviconBitmap> favicon_bitmaps; |
420 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( | 523 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( |
421 out_favicon1, &favicon_bitmaps)); | 524 out_favicon1, &favicon_bitmaps)); |
422 ASSERT_EQ(2u, favicon_bitmaps.size()); | 525 ASSERT_EQ(2u, favicon_bitmaps.size()); |
423 | 526 |
424 FaviconBitmap favicon_bitmap1 = favicon_bitmaps[0]; | 527 FaviconBitmap favicon_bitmap1 = favicon_bitmaps[0]; |
425 FaviconBitmap favicon_bitmap2 = favicon_bitmaps[1]; | 528 FaviconBitmap favicon_bitmap2 = favicon_bitmaps[1]; |
426 | 529 |
427 // Bitmaps do not need to be in particular order. | 530 // Favicon bitmaps do not need to be in particular order. |
428 if (favicon_bitmap1.pixel_size == kLargeSize) { | 531 if (favicon_bitmap1.pixel_size == kLargeSize) { |
429 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; | 532 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; |
430 favicon_bitmap1 = favicon_bitmap2; | 533 favicon_bitmap1 = favicon_bitmap2; |
431 favicon_bitmap2 = tmp_favicon_bitmap; | 534 favicon_bitmap2 = tmp_favicon_bitmap; |
432 } | 535 } |
433 | 536 |
434 EXPECT_EQ('a', *favicon_bitmap1.bitmap_data->front()); | 537 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap1.bitmap_data)); |
435 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size); | 538 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size); |
436 | 539 |
437 EXPECT_EQ('b', *favicon_bitmap2.bitmap_data->front()); | 540 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap2.bitmap_data)); |
438 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size); | 541 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size); |
439 | 542 |
440 FaviconID out_favicon2 = backend_->thumbnail_db_-> | 543 FaviconID out_favicon2 = backend_->thumbnail_db_-> |
441 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL); | 544 GetFaviconIDForFaviconURL(favicon_url2, FAVICON); |
442 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; | 545 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; |
443 | 546 |
444 // The remaining URL should still reference the same favicon, even if its | 547 // The remaining URL should still reference the same favicon, even if its |
445 // ID has changed. | 548 // ID has changed. |
446 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); | 549 std::vector<IconMapping> mappings; |
| 550 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 551 outrow1.url(), FAVICON, &mappings)); |
| 552 EXPECT_EQ(1u, mappings.size()); |
| 553 EXPECT_EQ(out_favicon1, mappings[0].icon_id); |
447 | 554 |
448 // The first URL should still be bookmarked. | 555 // The first URL should still be bookmarked. |
449 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); | 556 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); |
450 | 557 |
451 // The full text database should have no data. | 558 // The full text database should have no data. |
452 std::vector<TextDatabase::Match> text_matches; | 559 std::vector<TextDatabase::Match> text_matches; |
453 Time first_time_searched; | 560 Time first_time_searched; |
454 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), | 561 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), |
455 QueryOptions(), | 562 QueryOptions(), |
456 &text_matches, | 563 &text_matches, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 622 |
516 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { | 623 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
517 GURL favicon_url1("http://www.google.com/favicon.ico"); | 624 GURL favicon_url1("http://www.google.com/favicon.ico"); |
518 GURL favicon_url2("http://news.google.com/favicon.ico"); | 625 GURL favicon_url2("http://news.google.com/favicon.ico"); |
519 | 626 |
520 std::vector<unsigned char> data; | 627 std::vector<unsigned char> data; |
521 data.push_back('1'); | 628 data.push_back('1'); |
522 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( | 629 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
523 favicon_url1, | 630 favicon_url1, |
524 FAVICON, | 631 FAVICON, |
525 "0 0", | 632 kDefaultFaviconSizes, |
526 new base::RefCountedBytes(data), | 633 new base::RefCountedBytes(data), |
527 Time::Now(), | 634 Time::Now(), |
528 gfx::Size()); | 635 gfx::Size()); |
529 | 636 |
530 data[0] = '2'; | 637 data[0] = '2'; |
531 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon( | 638 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon( |
532 favicon_url2, | 639 favicon_url2, |
533 FAVICON, | 640 FAVICON, |
534 "0 0", | 641 kDefaultFaviconSizes, |
535 new base::RefCountedBytes(data), | 642 new base::RefCountedBytes(data), |
536 Time::Now(), | 643 Time::Now(), |
537 gfx::Size()); | 644 gfx::Size()); |
538 | 645 |
539 // First visit two URLs. | 646 // First visit two URLs. |
540 URLRow row1(GURL("http://www.google.com/")); | 647 URLRow row1(GURL("http://www.google.com/")); |
541 row1.set_visit_count(2); | 648 row1.set_visit_count(2); |
542 row1.set_typed_count(1); | 649 row1.set_typed_count(1); |
543 row1.set_last_visit(Time::Now()); | 650 row1.set_last_visit(Time::Now()); |
544 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); | 651 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); |
(...skipping 21 matching lines...) Expand all Loading... |
566 | 673 |
567 // Make sure url 2 is still valid, but has no visits. | 674 // Make sure url 2 is still valid, but has no visits. |
568 URLRow tmp_url_row; | 675 URLRow tmp_url_row; |
569 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); | 676 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); |
570 VisitVector visits; | 677 VisitVector visits; |
571 backend_->db_->GetVisitsForURL(row2_id, &visits); | 678 backend_->db_->GetVisitsForURL(row2_id, &visits); |
572 EXPECT_EQ(0U, visits.size()); | 679 EXPECT_EQ(0U, visits.size()); |
573 // The favicon should still be valid. | 680 // The favicon should still be valid. |
574 EXPECT_EQ(favicon2, | 681 EXPECT_EQ(favicon2, |
575 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2, | 682 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2, |
576 FAVICON, | 683 FAVICON)); |
577 NULL)); | |
578 | 684 |
579 // Unstar row2. | 685 // Unstar row2. |
580 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row2.url()); | 686 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row2.url()); |
581 | 687 |
582 // Tell the backend it was unstarred. We have to explicitly do this as | 688 // Tell the backend it was unstarred. We have to explicitly do this as |
583 // BookmarkModel isn't wired up to the backend during testing. | 689 // BookmarkModel isn't wired up to the backend during testing. |
584 std::set<GURL> unstarred_urls; | 690 std::set<GURL> unstarred_urls; |
585 unstarred_urls.insert(row2.url()); | 691 unstarred_urls.insert(row2.url()); |
586 backend_->URLsNoLongerBookmarked(unstarred_urls); | 692 backend_->URLsNoLongerBookmarked(unstarred_urls); |
587 | 693 |
588 // The URL should no longer exist. | 694 // The URL should no longer exist. |
589 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); | 695 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); |
590 // And the favicon should be deleted. | 696 // And the favicon should be deleted. |
591 EXPECT_EQ(0, | 697 EXPECT_EQ(0, |
592 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2, | 698 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url2, |
593 FAVICON, | 699 FAVICON)); |
594 NULL)); | |
595 | 700 |
596 // Unstar row 1. | 701 // Unstar row 1. |
597 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row1.url()); | 702 bookmark_utils::RemoveAllBookmarks(&bookmark_model_, row1.url()); |
598 // Tell the backend it was unstarred. We have to explicitly do this as | 703 // Tell the backend it was unstarred. We have to explicitly do this as |
599 // BookmarkModel isn't wired up to the backend during testing. | 704 // BookmarkModel isn't wired up to the backend during testing. |
600 unstarred_urls.clear(); | 705 unstarred_urls.clear(); |
601 unstarred_urls.insert(row1.url()); | 706 unstarred_urls.insert(row1.url()); |
602 backend_->URLsNoLongerBookmarked(unstarred_urls); | 707 backend_->URLsNoLongerBookmarked(unstarred_urls); |
603 | 708 |
604 // The URL should still exist (because there were visits). | 709 // The URL should still exist (because there were visits). |
605 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); | 710 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); |
606 | 711 |
607 // There should still be visits. | 712 // There should still be visits. |
608 visits.clear(); | 713 visits.clear(); |
609 backend_->db_->GetVisitsForURL(row1_id, &visits); | 714 backend_->db_->GetVisitsForURL(row1_id, &visits); |
610 EXPECT_EQ(1U, visits.size()); | 715 EXPECT_EQ(1U, visits.size()); |
611 | 716 |
612 // The favicon should still be valid. | 717 // The favicon should still be valid. |
613 EXPECT_EQ(favicon1, | 718 EXPECT_EQ(favicon1, |
614 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url1, | 719 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(favicon_url1, |
615 FAVICON, | 720 FAVICON)); |
616 NULL)); | |
617 } | 721 } |
618 | 722 |
619 // Tests a handful of assertions for a navigation with a type of | 723 // Tests a handful of assertions for a navigation with a type of |
620 // KEYWORD_GENERATED. | 724 // KEYWORD_GENERATED. |
621 TEST_F(HistoryBackendTest, KeywordGenerated) { | 725 TEST_F(HistoryBackendTest, KeywordGenerated) { |
622 ASSERT_TRUE(backend_.get()); | 726 ASSERT_TRUE(backend_.get()); |
623 | 727 |
624 GURL url("http://google.com"); | 728 GURL url("http://google.com"); |
625 | 729 |
626 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); | 730 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 | 801 |
698 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { | 802 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { |
699 // Setup test data - two Urls in the history, one with favicon assigned and | 803 // Setup test data - two Urls in the history, one with favicon assigned and |
700 // one without. | 804 // one without. |
701 GURL favicon_url1("http://www.google.com/favicon.ico"); | 805 GURL favicon_url1("http://www.google.com/favicon.ico"); |
702 std::vector<unsigned char> data; | 806 std::vector<unsigned char> data; |
703 data.push_back('1'); | 807 data.push_back('1'); |
704 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( | 808 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
705 favicon_url1, | 809 favicon_url1, |
706 FAVICON, | 810 FAVICON, |
707 "0 0", | 811 kDefaultFaviconSizes, |
708 base::RefCountedBytes::TakeVector(&data), | 812 base::RefCountedBytes::TakeVector(&data), |
709 Time::Now(), | 813 Time::Now(), |
710 gfx::Size()); | 814 gfx::Size()); |
711 URLRow row1(GURL("http://www.google.com/")); | 815 URLRow row1(GURL("http://www.google.com/")); |
712 row1.set_visit_count(1); | 816 row1.set_visit_count(1); |
713 row1.set_last_visit(Time::Now()); | 817 row1.set_last_visit(Time::Now()); |
714 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); | 818 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); |
715 | 819 |
716 URLRow row2(GURL("http://news.google.com/")); | 820 URLRow row2(GURL("http://news.google.com/")); |
717 row2.set_visit_count(1); | 821 row2.set_visit_count(1); |
718 row2.set_last_visit(Time::Now()); | 822 row2.set_last_visit(Time::Now()); |
719 URLRows rows; | 823 URLRows rows; |
720 rows.push_back(row1); | 824 rows.push_back(row1); |
721 rows.push_back(row2); | 825 rows.push_back(row2); |
722 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); | 826 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); |
723 URLRow url_row1, url_row2; | 827 URLRow url_row1, url_row2; |
724 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); | 828 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); |
725 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); | 829 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); |
726 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); | 830 EXPECT_EQ(1u, NumIconMappingsForPageURL(row1.url(), FAVICON)); |
727 EXPECT_TRUE(GetFavicon(row2.url(), FAVICON) == 0); | 831 EXPECT_EQ(0u, NumIconMappingsForPageURL(row2.url(), FAVICON)); |
728 | 832 |
729 // Now provide one imported favicon for both URLs already in the registry. | 833 // Now provide one imported favicon for both URLs already in the registry. |
730 // The new favicon should only be used with the URL that doesn't already have | 834 // The new favicon should only be used with the URL that doesn't already have |
731 // a favicon. | 835 // a favicon. |
732 std::vector<history::ImportedFaviconUsage> favicons; | 836 std::vector<history::ImportedFaviconUsage> favicons; |
733 history::ImportedFaviconUsage favicon; | 837 history::ImportedFaviconUsage favicon; |
734 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); | 838 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); |
735 favicon.png_data.push_back('2'); | 839 favicon.png_data.push_back('2'); |
736 favicon.urls.insert(row1.url()); | 840 favicon.urls.insert(row1.url()); |
737 favicon.urls.insert(row2.url()); | 841 favicon.urls.insert(row2.url()); |
738 favicons.push_back(favicon); | 842 favicons.push_back(favicon); |
739 backend_->SetImportedFavicons(favicons); | 843 backend_->SetImportedFavicons(favicons); |
740 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); | 844 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); |
741 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); | 845 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); |
742 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); | 846 |
743 EXPECT_FALSE(GetFavicon(row2.url(), FAVICON) == 0); | 847 std::vector<IconMapping> mappings; |
744 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == | 848 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
745 GetFavicon(row2.url(), FAVICON)); | 849 row1.url(), FAVICON, &mappings)); |
| 850 EXPECT_EQ(1u, mappings.size()); |
| 851 EXPECT_EQ(favicon1, mappings[0].icon_id); |
| 852 EXPECT_EQ(favicon_url1, mappings[0].icon_url); |
| 853 |
| 854 mappings.clear(); |
| 855 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 856 row2.url(), FAVICON, &mappings)); |
| 857 EXPECT_EQ(1u, mappings.size()); |
| 858 EXPECT_EQ(favicon.favicon_url, mappings[0].icon_url); |
746 | 859 |
747 // A URL should not be added to history (to store favicon), if | 860 // A URL should not be added to history (to store favicon), if |
748 // the URL is not bookmarked. | 861 // the URL is not bookmarked. |
749 GURL url3("http://mail.google.com"); | 862 GURL url3("http://mail.google.com"); |
750 favicons.clear(); | 863 favicons.clear(); |
751 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); | 864 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); |
752 favicon.png_data.push_back('3'); | 865 favicon.png_data.push_back('3'); |
753 favicon.urls.insert(url3); | 866 favicon.urls.insert(url3); |
754 favicons.push_back(favicon); | 867 favicons.push_back(favicon); |
755 backend_->SetImportedFavicons(favicons); | 868 backend_->SetImportedFavicons(favicons); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 EXPECT_EQ(cur_version, file_version); | 1205 EXPECT_EQ(cur_version, file_version); |
1093 | 1206 |
1094 // Check visit_source table is created and empty. | 1207 // Check visit_source table is created and empty. |
1095 s.Assign(db.GetUniqueStatement( | 1208 s.Assign(db.GetUniqueStatement( |
1096 "SELECT name FROM sqlite_master WHERE name=\"visit_source\"")); | 1209 "SELECT name FROM sqlite_master WHERE name=\"visit_source\"")); |
1097 ASSERT_TRUE(s.Step()); | 1210 ASSERT_TRUE(s.Step()); |
1098 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10")); | 1211 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10")); |
1099 EXPECT_FALSE(s.Step()); | 1212 EXPECT_FALSE(s.Step()); |
1100 } | 1213 } |
1101 | 1214 |
1102 TEST_F(HistoryBackendTest, SetFaviconMapping) { | 1215 /* |
| 1216 // Test that SetFaviconMappingsForPageAndRedirects correctly updates icon |
| 1217 // mappings based on redirects, icon URLs and icon types. |
| 1218 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageAndRedirects) { |
1103 // Init recent_redirects_ | 1219 // Init recent_redirects_ |
1104 const GURL url1("http://www.google.com"); | 1220 const GURL url1("http://www.google.com"); |
1105 const GURL url2("http://www.google.com/m"); | 1221 const GURL url2("http://www.google.com/m"); |
1106 URLRow url_info1(url1); | 1222 URLRow url_info1(url1); |
1107 url_info1.set_visit_count(0); | 1223 url_info1.set_visit_count(0); |
1108 url_info1.set_typed_count(0); | 1224 url_info1.set_typed_count(0); |
1109 url_info1.set_last_visit(base::Time()); | 1225 url_info1.set_last_visit(base::Time()); |
1110 url_info1.set_hidden(false); | 1226 url_info1.set_hidden(false); |
1111 backend_->db_->AddURL(url_info1); | 1227 backend_->db_->AddURL(url_info1); |
1112 | 1228 |
1113 URLRow url_info2(url2); | 1229 URLRow url_info2(url2); |
1114 url_info2.set_visit_count(0); | 1230 url_info2.set_visit_count(0); |
1115 url_info2.set_typed_count(0); | 1231 url_info2.set_typed_count(0); |
1116 url_info2.set_last_visit(base::Time()); | 1232 url_info2.set_last_visit(base::Time()); |
1117 url_info2.set_hidden(false); | 1233 url_info2.set_hidden(false); |
1118 backend_->db_->AddURL(url_info2); | 1234 backend_->db_->AddURL(url_info2); |
1119 | 1235 |
1120 history::RedirectList redirects; | 1236 history::RedirectList redirects; |
1121 redirects.push_back(url2); | 1237 redirects.push_back(url2); |
1122 redirects.push_back(url1); | 1238 redirects.push_back(url1); |
1123 backend_->recent_redirects_.Put(url1, redirects); | 1239 backend_->recent_redirects_.Put(url1, redirects); |
1124 | 1240 |
1125 const GURL icon_url("http://www.google.com/icon"); | 1241 const GURL icon_url1("http://www.google.com/icon"); |
1126 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1242 const GURL icon_url2("http://www.google.com/icon2"); |
1127 // Add a favicon | 1243 |
1128 backend_->SetFavicon( | 1244 // Create mapping for a page with two favicons. |
1129 url1, icon_url, base::RefCountedBytes::TakeVector(&data), FAVICON); | 1245 IconURLSizesMap two_icon_url_sizes; |
1130 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1246 two_icon_url_sizes[icon_url1] = FaviconSizes(kSizesSmallAndLarge); |
1131 url1, FAVICON, NULL)); | 1247 two_icon_url_sizes[icon_url2] = FaviconSizes(kSizesSmallAndLarge); |
1132 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1248 |
1133 url2, FAVICON, NULL)); | 1249 // Create a mapping for a page with a single favicon. |
1134 | 1250 IconURLSizesMap one_icon_url_sizes; |
1135 // Add a touch_icon | 1251 one_icon_url_sizes[icon_url1] = FaviconSizes(kSizesSmallAndLarge); |
1136 backend_->SetFavicon( | 1252 |
1137 url1, icon_url, base::RefCountedBytes::TakeVector(&data), TOUCH_ICON); | 1253 std::vector<FaviconDataElement> elements; |
1138 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1254 |
1139 url1, TOUCH_ICON, NULL)); | 1255 // Add two favicons |
1140 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1256 backend_->SetFavicons(url1, FAVICON, elements, two_icon_url_sizes); |
1141 url2, TOUCH_ICON, NULL)); | 1257 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON)); |
1142 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1258 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, FAVICON)); |
1143 url1, FAVICON, NULL)); | 1259 |
1144 | 1260 // Add one touch_icon |
1145 // Add a TOUCH_PRECOMPOSED_ICON | 1261 backend_->SetFavicons(url1, TOUCH_ICON, elements, one_icon_url_sizes); |
1146 backend_->SetFavicon(url1, | 1262 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON)); |
1147 icon_url, | 1263 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, TOUCH_ICON)); |
1148 base::RefCountedBytes::TakeVector(&data), | 1264 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON)); |
1149 TOUCH_PRECOMPOSED_ICON); | 1265 |
| 1266 // Add one TOUCH_PRECOMPOSED_ICON |
| 1267 backend_->SetFavicons(url1, TOUCH_PRECOMPOSED_ICON, elements, |
| 1268 one_icon_url_sizes); |
1150 // The touch_icon was replaced. | 1269 // The touch_icon was replaced. |
1151 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1270 EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, TOUCH_ICON)); |
1152 url1, TOUCH_ICON, NULL)); | 1271 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON)); |
1153 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1272 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_PRECOMPOSED_ICON)); |
1154 url1, FAVICON, NULL)); | 1273 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, TOUCH_PRECOMPOSED_ICON)); |
1155 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1274 |
1156 url1, TOUCH_PRECOMPOSED_ICON, NULL)); | 1275 // Add a touch_icon. |
1157 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1276 backend_->SetFavicons(url1, TOUCH_ICON, elements, one_icon_url_sizes); |
1158 url2, TOUCH_PRECOMPOSED_ICON, NULL)); | 1277 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON)); |
1159 | 1278 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON)); |
1160 // Add a touch_icon | |
1161 backend_->SetFavicon( | |
1162 url1, icon_url, base::RefCountedBytes::TakeVector(&data), TOUCH_ICON); | |
1163 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | |
1164 url1, TOUCH_ICON, NULL)); | |
1165 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | |
1166 url1, FAVICON, NULL)); | |
1167 // The TOUCH_PRECOMPOSED_ICON was replaced. | 1279 // The TOUCH_PRECOMPOSED_ICON was replaced. |
1168 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1280 EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, TOUCH_PRECOMPOSED_ICON)); |
1169 url1, TOUCH_PRECOMPOSED_ICON, NULL)); | 1281 |
1170 | 1282 // Add a single favicon. |
1171 // Add a favicon | 1283 backend_->SetFavicons(url1, FAVICON, elements, one_icon_url_sizes); |
1172 const GURL icon_url2("http://www.google.com/icon2"); | 1284 // The favicon of type FAVICON for |icon_url2| should have no more mappings |
1173 backend_->SetFavicon( | 1285 // and should have been deleted. |
1174 url1, icon_url2, base::RefCountedBytes::TakeVector(&data), FAVICON); | 1286 EXPECT_EQ(0, backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url2, |
1175 FaviconID icon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1287 FAVICON)); |
1176 icon_url2, FAVICON, NULL); | 1288 // The remaining mapping should be |icon_url1|. |
1177 EXPECT_NE(0, icon_id); | 1289 std::vector<IconMapping> icon_mappings; |
1178 std::vector<IconMapping> icon_mapping; | |
1179 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1290 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1180 url1, &icon_mapping)); | 1291 url1, FAVICON, &icon_mappings)); |
1181 // The old icon was replaced. | 1292 EXPECT_EQ(1u, icon_mappings.size()); |
1182 EXPECT_TRUE(icon_mapping.size() > 1); | 1293 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); |
1183 EXPECT_EQ(icon_id, icon_mapping[1].icon_id); | 1294 |
1184 } | 1295 // Add two favicons. |
1185 | 1296 backend_->SetFavicons(url1, FAVICON, elements, two_icon_url_sizes); |
1186 TEST_F(HistoryBackendTest, AddOrUpdateIconMapping) { | 1297 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON)); |
1187 // Test the same icon and page mapping will not be added twice. other case | 1298 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON)); |
1188 // should be covered in TEST_F(HistoryBackendTest, SetFaviconMapping) | 1299 } |
| 1300 |
| 1301 // Test that there is no churn in icon mappings from calling |
| 1302 // SetFaviconMappingsForPage() with icon mappings which are already in the |
| 1303 // database. |
| 1304 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) { |
1189 const GURL url("http://www.google.com/"); | 1305 const GURL url("http://www.google.com/"); |
1190 const GURL icon_url("http://www.google.com/icon"); | 1306 const GURL icon_url("http://www.google.com/icon"); |
1191 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1307 std::vector<FaviconDataElement> elements; |
1192 | 1308 |
1193 backend_->SetFavicon( | 1309 IconURLSizesMap icon_url_sizes; |
1194 url, icon_url, base::RefCountedBytes::TakeVector(&data), FAVICON); | 1310 icon_url_sizes[icon_url] = FaviconSizes(kSizesSmallAndLarge); |
1195 FaviconID icon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( | 1311 |
1196 icon_url, FAVICON, NULL); | 1312 backend_->SetFavicons(url, FAVICON, elements, icon_url_sizes); |
1197 | 1313 |
1198 // Add the same mapping | 1314 std::vector<IconMapping> icon_mappings; |
1199 FaviconID replaced; | |
1200 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( | |
1201 url, icon_id, FAVICON, &replaced)); | |
1202 EXPECT_EQ(0, replaced); | |
1203 | |
1204 std::vector<IconMapping> icon_mapping; | |
1205 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 1315 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
1206 url, &icon_mapping)); | 1316 url, FAVICON, &icon_mappings)); |
1207 EXPECT_EQ(1u, icon_mapping.size()); | 1317 EXPECT_EQ(1u, icon_mappings.size()); |
1208 } | 1318 IconMappingID mapping_id = icon_mappings[0].mapping_id; |
1209 | 1319 GURL favicon_url = icon_mappings[0].icon_url; |
1210 TEST_F(HistoryBackendTest, GetFaviconForURL) { | 1320 FaviconID favicon_id = icon_mappings[0].icon_id; |
1211 // This test will add a fav icon and touch icon for the same URL | 1321 |
1212 // and check the behaviour of backend's GetFaviconForURL implementation. | 1322 HistoryBackend::IconURLFaviconIDMap icon_url_ids; |
1213 const GURL url("http://www.google.com/"); | 1323 icon_url_ids[favicon_url] = favicon_id; |
| 1324 |
| 1325 // False should be returned as no mappings should have changed. |
| 1326 EXPECT_FALSE(backend_->SetFaviconMappingsForPage(url, FAVICON, icon_url_ids)); |
| 1327 |
| 1328 icon_mappings.clear(); |
| 1329 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1330 url, FAVICON, &icon_mappings)); |
| 1331 EXPECT_EQ(1u, icon_mappings.size()); |
| 1332 |
| 1333 // The same row in the icon_mapping table should be used for the mapping as |
| 1334 // before. |
| 1335 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id); |
| 1336 } |
| 1337 |
| 1338 // Test that setting favicons for a page which already has data does the |
| 1339 // right thing. |
| 1340 TEST_F(HistoryBackendTest, SetFavicons) { |
| 1341 const GURL page_url("http://www.google.com/"); |
| 1342 std::vector<FaviconDataElement> elements; |
| 1343 IconURLSizesMap icon_url_sizes; |
| 1344 |
| 1345 EXPECT_TRUE(DeleteFaviconsAndFaviconBitmaps(page_url, FAVICON)); |
| 1346 |
| 1347 // Set |page_url| as having two favicons each available from the web at two |
| 1348 // sizes. |
| 1349 const GURL icon_url1("http://www.google.com/icon1"); |
| 1350 const GURL icon_url2("http://www.google.com/icon2"); |
| 1351 |
| 1352 icon_url_sizes[icon_url1] = FaviconSizes(kSizesSmallAndLarge); |
| 1353 icon_url_sizes[icon_url2] = FaviconSizes(kSizesSmallAndLarge); |
| 1354 |
| 1355 // Set only sizes info for the favicons. |
| 1356 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
| 1357 |
| 1358 std::vector<IconMapping> icon_mappings; |
| 1359 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1360 page_url, &icon_mappings)); |
| 1361 EXPECT_EQ(2u, icon_mappings.size()); |
| 1362 for (size_t i = 0; i < icon_mappings.size(); ++i) { |
| 1363 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmaps( |
| 1364 icon_mappings[i].icon_id, NULL)); |
| 1365 } |
| 1366 |
| 1367 // Add bitmap data to the favicons. |
| 1368 SetFaviconDataElements(icon_url1, |
| 1369 FaviconSizes(kSizesSmall), |
| 1370 icon_url2, |
| 1371 FaviconSizes(kSizesSmallAndLarge), |
| 1372 &elements); |
| 1373 |
| 1374 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
| 1375 |
| 1376 icon_mappings.clear(); |
| 1377 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1378 page_url, &icon_mappings)); |
| 1379 EXPECT_EQ(2u, icon_mappings.size()); |
| 1380 IconMapping mapping1 = icon_mappings[0]; |
| 1381 IconMapping mapping2 = icon_mappings[1]; |
| 1382 |
| 1383 // Icon mappings do not need to be returned in particular order from database |
| 1384 // with respect to icon url. |
| 1385 if (mapping1.icon_url == icon_url2) { |
| 1386 IconMapping tmp_mapping = mapping1; |
| 1387 mapping1 = mapping2; |
| 1388 mapping2 = tmp_mapping; |
| 1389 } |
| 1390 |
| 1391 GURL icon_url; |
| 1392 IconType icon_type; |
| 1393 std::string sizes; |
| 1394 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(mapping1.icon_id, |
| 1395 &icon_url, &icon_type, &sizes)); |
| 1396 EXPECT_EQ(icon_url1, icon_url); |
| 1397 EXPECT_EQ(FAVICON, icon_type); |
| 1398 EXPECT_EQ(kSizesSmallAndLarge, sizes); |
| 1399 |
| 1400 std::vector<FaviconBitmap> favicon_bitmaps; |
| 1401 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(mapping1.icon_id, |
| 1402 &favicon_bitmaps)); |
| 1403 EXPECT_EQ(1u, favicon_bitmaps.size()); |
| 1404 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data)); |
| 1405 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); |
| 1406 |
| 1407 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(mapping2.icon_id, |
| 1408 &icon_url, &icon_type, &sizes)); |
| 1409 EXPECT_EQ(icon_url2, icon_url); |
| 1410 EXPECT_EQ(FAVICON, icon_type); |
| 1411 EXPECT_EQ(kSizesSmallAndLarge, sizes); |
| 1412 |
| 1413 favicon_bitmaps.clear(); |
| 1414 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(mapping2.icon_id, |
| 1415 &favicon_bitmaps)); |
| 1416 |
| 1417 EXPECT_EQ(2u, favicon_bitmaps.size()); |
| 1418 |
| 1419 // Favicon bitmaps do not need to be in particular order. |
| 1420 if (favicon_bitmaps[0].pixel_size == kSmallSize) { |
| 1421 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[0].bitmap_data)); |
| 1422 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size); |
| 1423 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[1].bitmap_data)); |
| 1424 } else { |
| 1425 EXPECT_EQ(kLargeSize, favicon_bitmaps[0].pixel_size); |
| 1426 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); |
| 1427 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); |
| 1428 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[1].bitmap_data)); |
| 1429 } |
| 1430 |
| 1431 // Change the sizes for which the favicon at icon_url1 is available at from |
| 1432 // the web. Verify that all the data remains valid. |
| 1433 const std::string kSizesTinySmallAndLarge = "10 10 " + kSizesSmallAndLarge; |
| 1434 icon_url_sizes[icon_url1] = FaviconSizes(kSizesTinySmallAndLarge); |
| 1435 elements.clear(); |
| 1436 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
| 1437 |
| 1438 icon_mappings.clear(); |
| 1439 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
| 1440 page_url, &icon_mappings)); |
| 1441 EXPECT_EQ(2u, icon_mappings.size()); |
| 1442 mapping1 = icon_mappings[0]; |
| 1443 mapping2 = icon_mappings[1]; |
| 1444 |
| 1445 // Icon mappings do not need to be returned in particular order from database |
| 1446 // with respect to icon urls. |
| 1447 if (mapping1.icon_url == icon_url2) { |
| 1448 IconMapping tmp_mapping = mapping1; |
| 1449 mapping1 = mapping2; |
| 1450 mapping2 = tmp_mapping; |
| 1451 } |
| 1452 |
| 1453 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(mapping1.icon_id, |
| 1454 &icon_url, &icon_type, &sizes)); |
| 1455 EXPECT_EQ(icon_url1, icon_url); |
| 1456 EXPECT_EQ(FAVICON, icon_type); |
| 1457 EXPECT_EQ(kSizesTinySmallAndLarge, sizes); |
| 1458 |
| 1459 favicon_bitmaps.clear(); |
| 1460 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(mapping1.icon_id, |
| 1461 &favicon_bitmaps)); |
| 1462 EXPECT_EQ(1u, favicon_bitmaps.size()); |
| 1463 |
| 1464 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(mapping2.icon_id, |
| 1465 &icon_url, &icon_type, &sizes)); |
| 1466 EXPECT_EQ(icon_url2, icon_url); |
| 1467 EXPECT_EQ(FAVICON, icon_type); |
| 1468 EXPECT_EQ(kSizesSmallAndLarge, sizes); |
| 1469 |
| 1470 favicon_bitmaps.clear(); |
| 1471 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(mapping2.icon_id, |
| 1472 &favicon_bitmaps)); |
| 1473 EXPECT_EQ(2u, favicon_bitmaps.size()); |
| 1474 } |
| 1475 |
| 1476 // Test that changing the sizes that a favicon is available at from the web |
| 1477 // deletes stale favicon bitmaps. |
| 1478 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) { |
| 1479 const GURL page_url("http://www.google.com/"); |
1214 const GURL icon_url("http://www.google.com/icon"); | 1480 const GURL icon_url("http://www.google.com/icon"); |
1215 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1481 |
1216 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 1482 // Set |page_url| as having one favicon with two different sizes. |
1217 // Used for testing the icon data after getting from DB | 1483 IconURLSizesMap icon_url_sizes; |
1218 std::string blob_data(bytes->front(), | 1484 icon_url_sizes[icon_url] = FaviconSizes(kSizesSmallAndLarge); |
1219 bytes->front() + bytes->size()); | 1485 |
1220 | 1486 std::vector<FaviconDataElement> elements; |
1221 // Add a favicon | 1487 SetFaviconDataElements(icon_url, FaviconSizes(kSizesSmallAndLarge), |
1222 backend_->SetFavicon( | 1488 &elements); |
1223 url, icon_url, bytes.get(), FAVICON); | 1489 |
1224 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1490 // Add bitmap data and sizes information to the database. |
1225 url, FAVICON, NULL)); | 1491 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
1226 | 1492 |
1227 // Add a touch_icon | 1493 FaviconID favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( |
1228 backend_->SetFavicon( | 1494 icon_url, FAVICON); |
1229 url, icon_url, bytes.get(), TOUCH_ICON); | 1495 EXPECT_NE(0, favicon_id); |
1230 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1496 |
1231 url, TOUCH_ICON, NULL)); | 1497 std::vector<FaviconBitmap> favicon_bitmaps; |
1232 | 1498 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, |
1233 // Test the Fav icon for this URL. | 1499 &favicon_bitmaps)); |
1234 FaviconData favicon; | 1500 EXPECT_EQ(2u, favicon_bitmaps.size()); |
1235 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1501 |
1236 std::string favicon_data( | 1502 // Change the bitmap sizes avaible from the web only to the small size only. |
1237 favicon.first_bitmap()->front(), | 1503 icon_url_sizes[icon_url] = FaviconSizes(kSizesSmall); |
1238 favicon.first_bitmap()->front() + favicon.first_bitmap()->size()); | 1504 elements.clear(); |
1239 | 1505 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
1240 EXPECT_EQ(FAVICON, favicon.icon_type); | 1506 |
1241 EXPECT_EQ(icon_url, favicon.icon_url); | 1507 favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, |
1242 EXPECT_EQ(blob_data, favicon_data); | 1508 FAVICON); |
1243 | 1509 EXPECT_NE(0, favicon_id); |
1244 // Test the touch icon for this URL. | 1510 |
1245 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, &favicon)); | 1511 favicon_bitmaps.clear(); |
1246 std::string touchicon_data( | 1512 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, |
1247 favicon.first_bitmap()->front(), | 1513 &favicon_bitmaps)); |
1248 favicon.first_bitmap()->front() + favicon.first_bitmap()->size()); | 1514 EXPECT_EQ(1u, favicon_bitmaps.size()); |
1249 | 1515 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size); |
1250 EXPECT_EQ(TOUCH_ICON, favicon.icon_type); | 1516 } |
1251 EXPECT_EQ(icon_url, favicon.icon_url); | 1517 |
1252 EXPECT_EQ(blob_data, touchicon_data); | 1518 // Test updating a single favicon bitmap's data via SetFavicons. |
| 1519 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { |
| 1520 |
| 1521 const GURL page_url("http://www.google.com/"); |
| 1522 const GURL icon_url("http://www.google.com/icon"); |
| 1523 IconURLSizesMap icon_url_sizes; |
| 1524 icon_url_sizes[icon_url] = FaviconSizes(kSizesSmall); |
| 1525 |
| 1526 std::vector<unsigned char> data_initial; |
| 1527 data_initial.push_back('a'); |
| 1528 |
| 1529 FaviconDataElement element; |
| 1530 element.bitmap_data = base::RefCountedBytes::TakeVector(&data_initial); |
| 1531 element.pixel_size = kSmallSize; |
| 1532 element.icon_url = icon_url; |
| 1533 std::vector<FaviconDataElement> elements; |
| 1534 elements.push_back(element); |
| 1535 |
| 1536 // Add bitmap to the database. |
| 1537 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
| 1538 |
| 1539 FaviconBitmap favicon_bitmap; |
| 1540 EXPECT_TRUE(GetOnlyFaviconBitmapForIconURL(icon_url, FAVICON, |
| 1541 &favicon_bitmap)); |
| 1542 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); |
| 1543 |
| 1544 // SetFavicons with identical data but a different bitmap. |
| 1545 std::vector<unsigned char> updated_data; |
| 1546 updated_data.push_back('b'); |
| 1547 elements[0].bitmap_data = base::RefCountedBytes::TakeVector(&updated_data); |
| 1548 backend_->SetFavicons(page_url, FAVICON, elements, icon_url_sizes); |
| 1549 |
| 1550 EXPECT_TRUE(GetOnlyFaviconBitmapForIconURL(icon_url, FAVICON, |
| 1551 &favicon_bitmap)); |
| 1552 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap.bitmap_data)); |
| 1553 } |
| 1554 |
| 1555 // Test GetFaviconsFromDB returns expected data in FaviconData. |
| 1556 TEST_F(HistoryBackendTest, GetFaviconsFromDB) { |
| 1557 const GURL page_url("http://www.google.com/"); |
| 1558 |
| 1559 // |page_url| has favicons at two different icon URLs on the web. Each icon |
| 1560 // is a .ico file with two bitmaps. |
| 1561 const GURL icon_url1("http://www.google.com/icon1.ico"); |
| 1562 const GURL icon_url2("http://www.google.com/icon2.ico"); |
| 1563 |
| 1564 IconURLSizesMap icon_url_sizes; |
| 1565 icon_url_sizes[icon_url1] = FaviconSizes(kSizesSmallAndLarge); |
| 1566 icon_url_sizes[icon_url2] = FaviconSizes(kSizesSmallAndLarge); |
| 1567 |
| 1568 // The thumbnail database has stored bitmap data only for the favicon at |
| 1569 // |icon_url1|. |
| 1570 std::vector<FaviconDataElement> elements; |
| 1571 SetFaviconDataElements(icon_url1, FaviconSizes(kSizesSmallAndLarge), |
| 1572 &elements); |
| 1573 |
| 1574 SetFaviconsState(page_url, FAVICON, elements, icon_url_sizes); |
| 1575 |
| 1576 FaviconData favicon_data; |
| 1577 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON, &favicon_data)); |
| 1578 |
| 1579 EXPECT_TRUE(favicon_data.known_icon); |
| 1580 EXPECT_FALSE(favicon_data.expired); |
| 1581 EXPECT_EQ(FAVICON, favicon_data.icon_type); |
| 1582 |
| 1583 EXPECT_EQ(2u, favicon_data.elements.size()); |
| 1584 FaviconDataElement element1 = favicon_data.elements[0]; |
| 1585 FaviconDataElement element2 = favicon_data.elements[1]; |
| 1586 |
| 1587 // No required order for FaviconDataElements. |
| 1588 if (element1.pixel_size == kLargeSize) { |
| 1589 FaviconDataElement tmp_element = element1; |
| 1590 element1 = element2; |
| 1591 element2 = tmp_element; |
| 1592 } |
| 1593 |
| 1594 EXPECT_TRUE(BitmapDataEqual('a', element1.bitmap_data)); |
| 1595 EXPECT_EQ(kSmallSize, element1.pixel_size); |
| 1596 EXPECT_EQ(icon_url1, element1.icon_url); |
| 1597 |
| 1598 EXPECT_TRUE(BitmapDataEqual('b', element2.bitmap_data)); |
| 1599 EXPECT_EQ(kLargeSize, element2.pixel_size); |
| 1600 EXPECT_EQ(icon_url1, element2.icon_url); |
| 1601 |
| 1602 EXPECT_EQ(2u, favicon_data.icon_url_sizes.size()); |
| 1603 EXPECT_TRUE(favicon_data.icon_url_sizes.count(icon_url1)); |
| 1604 EXPECT_EQ(kSizesSmallAndLarge, |
| 1605 favicon_data.icon_url_sizes[icon_url1].ToString()); |
| 1606 EXPECT_TRUE(favicon_data.icon_url_sizes.count(icon_url2)); |
| 1607 EXPECT_EQ(kSizesSmallAndLarge, |
| 1608 favicon_data.icon_url_sizes[icon_url2].ToString()); |
| 1609 } |
| 1610 |
| 1611 // Tests that |expired| == true in FaviconData returned by GetFaviconsFromDB |
| 1612 // when one of the favicons are out of date. |
| 1613 TEST_F(HistoryBackendTest, GetFaviconsFromDBExpired) { |
| 1614 const GURL page_url("http://www.google.com/"); |
| 1615 |
| 1616 // |page_url| has favicons at two different icon URLs on the web. Each icon |
| 1617 // is a .png with a single bitmap. |
| 1618 const GURL icon_url1("http://www.google.com/icon1.png"); |
| 1619 const GURL icon_url2("http://www.google.com/icon2.png"); |
| 1620 |
| 1621 IconURLSizesMap icon_url_sizes; |
| 1622 icon_url_sizes[icon_url1] = FaviconSizes(kSizesSmall); |
| 1623 icon_url_sizes[icon_url2] = FaviconSizes(kSizesSmall); |
| 1624 |
| 1625 std::vector<FaviconDataElement> elements; |
| 1626 SetFaviconDataElements(icon_url1, FaviconSizes(kSizesSmall), icon_url2, |
| 1627 FaviconSizes(kSizesSmall), &elements); |
| 1628 |
| 1629 SetFaviconsState(page_url, FAVICON, elements, icon_url_sizes); |
| 1630 |
| 1631 // Set the favicon for |icon_url1| as out of date. |
| 1632 FaviconID favicon_id1 = |
| 1633 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url1, FAVICON); |
| 1634 EXPECT_NE(0, favicon_id1); |
| 1635 EXPECT_TRUE(backend_->thumbnail_db_->SetFaviconOutOfDate(favicon_id1)); |
| 1636 |
| 1637 FaviconData favicon_data; |
| 1638 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON, &favicon_data)); |
| 1639 // Favicon should be expired. |
| 1640 EXPECT_TRUE(favicon_data.expired); |
| 1641 } |
| 1642 |
| 1643 // Test FaviconData returned by GetFaviconsFromDB for different IconTypes. |
| 1644 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) { |
| 1645 const GURL page_url("http://www.google.com/"); |
| 1646 const GURL icon_url1("http://www.google.com/icon1.png"); |
| 1647 const GURL icon_url2("http://www.google.com/icon2.png"); |
| 1648 |
| 1649 IconURLSizesMap icon_url_sizes; |
| 1650 icon_url_sizes[icon_url1] = FaviconSizes(kSizesSmall); |
| 1651 icon_url_sizes[icon_url2] = FaviconSizes(kSizesSmall); |
| 1652 |
| 1653 std::vector<FaviconDataElement> elements; |
| 1654 SetFaviconDataElements(icon_url1, FaviconSizes(kSizesSmall), &elements); |
| 1655 SetFaviconsState(page_url, FAVICON, elements, icon_url_sizes); |
| 1656 |
| 1657 SetFaviconDataElements(icon_url2, FaviconSizes(kSizesSmall), &elements); |
| 1658 std::vector<unsigned char> touch_bitmap_data; |
| 1659 touch_bitmap_data.push_back('b'); |
| 1660 elements[0].bitmap_data = base::RefCountedBytes::TakeVector( |
| 1661 &touch_bitmap_data); |
| 1662 backend_->SetFavicons(page_url, TOUCH_ICON, elements, icon_url_sizes); |
| 1663 |
| 1664 // Test favicon of type FAVICON for this URL. |
| 1665 FaviconData favicon_data; |
| 1666 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON, &favicon_data)); |
| 1667 |
| 1668 EXPECT_TRUE(favicon_data.known_icon); |
| 1669 EXPECT_FALSE(favicon_data.expired); |
| 1670 EXPECT_EQ(FAVICON, favicon_data.icon_type); |
| 1671 EXPECT_EQ(1u, favicon_data.elements.size()); |
| 1672 EXPECT_TRUE(BitmapDataEqual('a', favicon_data.elements[0].bitmap_data)); |
| 1673 EXPECT_EQ(kSmallSize, favicon_data.elements[0].pixel_size); |
| 1674 EXPECT_EQ(icon_url1, favicon_data.elements[0].icon_url); |
| 1675 |
| 1676 // Test favicon of type TOUCH_ICON for this URL. |
| 1677 FaviconData touchicon_data; |
| 1678 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, TOUCH_ICON, |
| 1679 &touchicon_data)); |
| 1680 |
| 1681 EXPECT_TRUE(touchicon_data.known_icon); |
| 1682 EXPECT_FALSE(touchicon_data.expired); |
| 1683 EXPECT_EQ(TOUCH_ICON, touchicon_data.icon_type); |
| 1684 EXPECT_EQ(1u, touchicon_data.elements.size()); |
| 1685 EXPECT_TRUE(BitmapDataEqual('b', touchicon_data.elements[0].bitmap_data)); |
| 1686 EXPECT_EQ(kSmallSize, touchicon_data.elements[0].pixel_size); |
| 1687 EXPECT_EQ(icon_url2, touchicon_data.elements[0].icon_url); |
| 1688 } |
| 1689 |
| 1690 // Test FaviconData returned by GetFaviconsFromDB when there are no found |
| 1691 // favicons. |
| 1692 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) { |
| 1693 const GURL page_url("http://www.google.com/"); |
| 1694 |
| 1695 EXPECT_TRUE(DeleteFaviconsAndFaviconBitmaps(page_url, FAVICON)); |
| 1696 |
| 1697 FaviconData favicon_data; |
| 1698 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, FAVICON, &favicon_data)); |
| 1699 EXPECT_FALSE(favicon_data.known_icon); |
1253 } | 1700 } |
1254 | 1701 |
1255 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { | 1702 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { |
1256 const GURL url("http://www.google.com/"); | 1703 const GURL url("http://www.google.com/"); |
1257 const GURL icon_url("http://www.google.com/icon"); | |
1258 const GURL same_domain_url("http://www.google.com/subdir/index.html"); | 1704 const GURL same_domain_url("http://www.google.com/subdir/index.html"); |
1259 const GURL foreign_domain_url("http://www.not-google.com/"); | 1705 const GURL foreign_domain_url("http://www.not-google.com/"); |
1260 | 1706 const GURL icon_url("http://www.google.com/icon.png"); |
1261 // Add a favicon | 1707 |
1262 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 1708 // Add a favicon. |
1263 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 1709 IconURLSizesMap icon_url_sizes; |
1264 backend_->SetFavicon( | 1710 icon_url_sizes[icon_url] = FaviconSizes(kSizesSmall); |
1265 url, icon_url, bytes.get(), FAVICON); | 1711 std::vector<FaviconDataElement> elements; |
1266 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 1712 SetFaviconDataElements(icon_url, FaviconSizes(kSizesSmall), &elements); |
1267 url, FAVICON, NULL)); | 1713 SetFaviconsState(url, FAVICON, elements, icon_url_sizes); |
1268 | 1714 |
1269 // Validate starting state. | 1715 // Validate starting state. |
1270 FaviconData favicon; | 1716 FaviconData favicon_data; |
1271 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, &favicon)); | 1717 EXPECT_TRUE(backend_->GetFaviconsFromDB(url, FAVICON, &favicon_data)); |
1272 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1718 FaviconData favicon_data_same_domain; |
1273 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1719 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, FAVICON, |
1274 FAVICON, &favicon)); | 1720 &favicon_data_same_domain)); |
| 1721 FaviconData favicon_data_foreign_domain; |
| 1722 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, FAVICON, |
| 1723 &favicon_data_foreign_domain)); |
1275 | 1724 |
1276 // Same-domain cloning should work. | 1725 // Same-domain cloning should work. |
1277 backend_->CloneFavicon(url, same_domain_url); | 1726 backend_->CloneFavicons(url, same_domain_url); |
1278 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, &favicon)); | 1727 FaviconData favicon_data_cloned_same_domain; |
| 1728 EXPECT_TRUE(backend_->GetFaviconsFromDB(same_domain_url, FAVICON, |
| 1729 &favicon_data_cloned_same_domain)); |
1279 | 1730 |
1280 // Foreign-domain cloning is forbidden. | 1731 // Foreign-domain cloning is forbidden. |
1281 backend_->CloneFavicon(url, foreign_domain_url); | 1732 backend_->CloneFavicons(url, foreign_domain_url); |
1282 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, | 1733 FaviconData favicon_data_cloned_foreign_domain; |
1283 FAVICON, &favicon)); | 1734 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, FAVICON, |
1284 } | 1735 &favicon_data_cloned_foreign_domain)); |
| 1736 } |
| 1737 */ |
1285 | 1738 |
1286 TEST_F(HistoryBackendTest, QueryFilteredURLs) { | 1739 TEST_F(HistoryBackendTest, QueryFilteredURLs) { |
1287 const char* google = "http://www.google.com/"; | 1740 const char* google = "http://www.google.com/"; |
1288 const char* yahoo = "http://www.yahoo.com/"; | 1741 const char* yahoo = "http://www.yahoo.com/"; |
1289 const char* yahoo_sports = "http://sports.yahoo.com/"; | 1742 const char* yahoo_sports = "http://sports.yahoo.com/"; |
1290 const char* yahoo_sports_with_article1 = | 1743 const char* yahoo_sports_with_article1 = |
1291 "http://sports.yahoo.com/article1.htm"; | 1744 "http://sports.yahoo.com/article1.htm"; |
1292 const char* yahoo_sports_with_article2 = | 1745 const char* yahoo_sports_with_article2 = |
1293 "http://sports.yahoo.com/article2.htm"; | 1746 "http://sports.yahoo.com/article2.htm"; |
1294 const char* yahoo_sports_soccer = "http://sports.yahoo.com/soccer"; | 1747 const char* yahoo_sports_soccer = "http://sports.yahoo.com/soccer"; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 | 2060 |
1608 backend_->DeleteURL(url); | 2061 backend_->DeleteURL(url); |
1609 backend_->AddPageNoVisitForBookmark(url, string16()); | 2062 backend_->AddPageNoVisitForBookmark(url, string16()); |
1610 backend_->GetURL(url, &row); | 2063 backend_->GetURL(url, &row); |
1611 EXPECT_EQ(url, row.url()); | 2064 EXPECT_EQ(url, row.url()); |
1612 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); | 2065 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); |
1613 EXPECT_EQ(0, row.visit_count()); | 2066 EXPECT_EQ(0, row.visit_count()); |
1614 } | 2067 } |
1615 | 2068 |
1616 } // namespace history | 2069 } // namespace history |
OLD | NEW |