OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 TEST_F(HistoryBackendTest, DeleteAll) { | 210 TEST_F(HistoryBackendTest, DeleteAll) { |
211 ASSERT_TRUE(backend_.get()); | 211 ASSERT_TRUE(backend_.get()); |
212 | 212 |
213 // Add two favicons, use the characters '1' and '2' for the image data. Note | 213 // Add two favicons, use the characters '1' and '2' for the image data. Note |
214 // that we do these in the opposite order. This is so the first one gets ID | 214 // that we do these in the opposite order. This is so the first one gets ID |
215 // 2 autoassigned to the database, which will change when the other one is | 215 // 2 autoassigned to the database, which will change when the other one is |
216 // deleted. This way we can test that updating works properly. | 216 // deleted. This way we can test that updating works properly. |
217 GURL favicon_url1("http://www.google.com/favicon.ico"); | 217 GURL favicon_url1("http://www.google.com/favicon.ico"); |
218 GURL favicon_url2("http://news.google.com/favicon.ico"); | 218 GURL favicon_url2("http://news.google.com/favicon.ico"); |
219 FavIconID favicon2 = backend_->thumbnail_db_->AddFavIcon(favicon_url2, | 219 FavIconID favicon2 = backend_->thumbnail_db_->AddFavIcon(favicon_url2, |
220 FAV_ICON); | 220 FAVICON); |
221 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, | 221 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, |
222 FAV_ICON); | 222 FAVICON); |
223 | 223 |
224 std::vector<unsigned char> data; | 224 std::vector<unsigned char> data; |
225 data.push_back('1'); | 225 data.push_back('1'); |
226 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, | 226 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, |
227 new RefCountedBytes(data), Time::Now())); | 227 new RefCountedBytes(data), Time::Now())); |
228 | 228 |
229 data[0] = '2'; | 229 data[0] = '2'; |
230 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 230 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( |
231 favicon2, new RefCountedBytes(data), Time::Now())); | 231 favicon2, new RefCountedBytes(data), Time::Now())); |
232 | 232 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 316 |
317 // All thumbnails should be deleted. | 317 // All thumbnails should be deleted. |
318 std::vector<unsigned char> out_data; | 318 std::vector<unsigned char> out_data; |
319 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), | 319 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), |
320 &out_data)); | 320 &out_data)); |
321 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); | 321 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); |
322 | 322 |
323 // We should have a favicon for the first URL only. We look them up by favicon | 323 // We should have a favicon for the first URL only. We look them up by favicon |
324 // URL since the IDs may hav changed. | 324 // URL since the IDs may hav changed. |
325 FavIconID out_favicon1 = backend_->thumbnail_db_-> | 325 FavIconID out_favicon1 = backend_->thumbnail_db_-> |
326 GetFavIconIDForFavIconURL(favicon_url1, FAV_ICON, NULL); | 326 GetFavIconIDForFavIconURL(favicon_url1, FAVICON, NULL); |
327 EXPECT_TRUE(out_favicon1); | 327 EXPECT_TRUE(out_favicon1); |
328 FavIconID out_favicon2 = backend_->thumbnail_db_-> | 328 FavIconID out_favicon2 = backend_->thumbnail_db_-> |
329 GetFavIconIDForFavIconURL(favicon_url2, FAV_ICON, NULL); | 329 GetFavIconIDForFavIconURL(favicon_url2, FAVICON, NULL); |
330 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; | 330 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; |
331 | 331 |
332 // The remaining URL should still reference the same favicon, even if its | 332 // The remaining URL should still reference the same favicon, even if its |
333 // ID has changed. | 333 // ID has changed. |
334 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAV_ICON)); | 334 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); |
335 | 335 |
336 // The first URL should still be bookmarked. | 336 // The first URL should still be bookmarked. |
337 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); | 337 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); |
338 | 338 |
339 // The full text database should have no data. | 339 // The full text database should have no data. |
340 std::vector<TextDatabase::Match> text_matches; | 340 std::vector<TextDatabase::Match> text_matches; |
341 Time first_time_searched; | 341 Time first_time_searched; |
342 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), | 342 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), |
343 QueryOptions(), | 343 QueryOptions(), |
344 &text_matches, | 344 &text_matches, |
345 &first_time_searched); | 345 &first_time_searched); |
346 EXPECT_EQ(0U, text_matches.size()); | 346 EXPECT_EQ(0U, text_matches.size()); |
347 } | 347 } |
348 | 348 |
349 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { | 349 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
350 GURL favicon_url1("http://www.google.com/favicon.ico"); | 350 GURL favicon_url1("http://www.google.com/favicon.ico"); |
351 GURL favicon_url2("http://news.google.com/favicon.ico"); | 351 GURL favicon_url2("http://news.google.com/favicon.ico"); |
352 FavIconID favicon2 = backend_->thumbnail_db_->AddFavIcon(favicon_url2, | 352 FavIconID favicon2 = backend_->thumbnail_db_->AddFavIcon(favicon_url2, |
353 FAV_ICON); | 353 FAVICON); |
354 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, | 354 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, |
355 FAV_ICON); | 355 FAVICON); |
356 | 356 |
357 std::vector<unsigned char> data; | 357 std::vector<unsigned char> data; |
358 data.push_back('1'); | 358 data.push_back('1'); |
359 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 359 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( |
360 favicon1, new RefCountedBytes(data), Time::Now())); | 360 favicon1, new RefCountedBytes(data), Time::Now())); |
361 | 361 |
362 data[0] = '2'; | 362 data[0] = '2'; |
363 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 363 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( |
364 favicon2, new RefCountedBytes(data), Time::Now())); | 364 favicon2, new RefCountedBytes(data), Time::Now())); |
365 | 365 |
(...skipping 27 matching lines...) Expand all Loading... |
393 | 393 |
394 // Make sure url 2 is still valid, but has no visits. | 394 // Make sure url 2 is still valid, but has no visits. |
395 URLRow tmp_url_row; | 395 URLRow tmp_url_row; |
396 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); | 396 EXPECT_EQ(row2_id, backend_->db_->GetRowForURL(row2.url(), NULL)); |
397 VisitVector visits; | 397 VisitVector visits; |
398 backend_->db_->GetVisitsForURL(row2_id, &visits); | 398 backend_->db_->GetVisitsForURL(row2_id, &visits); |
399 EXPECT_EQ(0U, visits.size()); | 399 EXPECT_EQ(0U, visits.size()); |
400 // The favicon should still be valid. | 400 // The favicon should still be valid. |
401 EXPECT_EQ(favicon2, | 401 EXPECT_EQ(favicon2, |
402 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url2, | 402 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url2, |
403 FAV_ICON, | 403 FAVICON, |
404 NULL)); | 404 NULL)); |
405 | 405 |
406 // Unstar row2. | 406 // Unstar row2. |
407 bookmark_model_.SetURLStarred(row2.url(), string16(), false); | 407 bookmark_model_.SetURLStarred(row2.url(), string16(), false); |
408 // Tell the backend it was unstarred. We have to explicitly do this as | 408 // Tell the backend it was unstarred. We have to explicitly do this as |
409 // BookmarkModel isn't wired up to the backend during testing. | 409 // BookmarkModel isn't wired up to the backend during testing. |
410 std::set<GURL> unstarred_urls; | 410 std::set<GURL> unstarred_urls; |
411 unstarred_urls.insert(row2.url()); | 411 unstarred_urls.insert(row2.url()); |
412 backend_->URLsNoLongerBookmarked(unstarred_urls); | 412 backend_->URLsNoLongerBookmarked(unstarred_urls); |
413 | 413 |
414 // The URL should no longer exist. | 414 // The URL should no longer exist. |
415 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); | 415 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &tmp_url_row)); |
416 // And the favicon should be deleted. | 416 // And the favicon should be deleted. |
417 EXPECT_EQ(0, | 417 EXPECT_EQ(0, |
418 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url2, | 418 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url2, |
419 FAV_ICON, | 419 FAVICON, |
420 NULL)); | 420 NULL)); |
421 | 421 |
422 // Unstar row 1. | 422 // Unstar row 1. |
423 bookmark_model_.SetURLStarred(row1.url(), string16(), false); | 423 bookmark_model_.SetURLStarred(row1.url(), string16(), false); |
424 // Tell the backend it was unstarred. We have to explicitly do this as | 424 // Tell the backend it was unstarred. We have to explicitly do this as |
425 // BookmarkModel isn't wired up to the backend during testing. | 425 // BookmarkModel isn't wired up to the backend during testing. |
426 unstarred_urls.clear(); | 426 unstarred_urls.clear(); |
427 unstarred_urls.insert(row1.url()); | 427 unstarred_urls.insert(row1.url()); |
428 backend_->URLsNoLongerBookmarked(unstarred_urls); | 428 backend_->URLsNoLongerBookmarked(unstarred_urls); |
429 | 429 |
430 // The URL should still exist (because there were visits). | 430 // The URL should still exist (because there were visits). |
431 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); | 431 EXPECT_EQ(row1_id, backend_->db_->GetRowForURL(row1.url(), NULL)); |
432 | 432 |
433 // There should still be visits. | 433 // There should still be visits. |
434 visits.clear(); | 434 visits.clear(); |
435 backend_->db_->GetVisitsForURL(row1_id, &visits); | 435 backend_->db_->GetVisitsForURL(row1_id, &visits); |
436 EXPECT_EQ(1U, visits.size()); | 436 EXPECT_EQ(1U, visits.size()); |
437 | 437 |
438 // The favicon should still be valid. | 438 // The favicon should still be valid. |
439 EXPECT_EQ(favicon1, | 439 EXPECT_EQ(favicon1, |
440 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url1, | 440 backend_->thumbnail_db_->GetFavIconIDForFavIconURL(favicon_url1, |
441 FAV_ICON, | 441 FAVICON, |
442 NULL)); | 442 NULL)); |
443 } | 443 } |
444 | 444 |
445 // Tests a handful of assertions for a navigation with a type of | 445 // Tests a handful of assertions for a navigation with a type of |
446 // KEYWORD_GENERATED. | 446 // KEYWORD_GENERATED. |
447 TEST_F(HistoryBackendTest, KeywordGenerated) { | 447 TEST_F(HistoryBackendTest, KeywordGenerated) { |
448 ASSERT_TRUE(backend_.get()); | 448 ASSERT_TRUE(backend_.get()); |
449 | 449 |
450 GURL url("http://google.com"); | 450 GURL url("http://google.com"); |
451 | 451 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 AddClientRedirect(url_b, url_c, true, &transition1, &transition2); | 516 AddClientRedirect(url_b, url_c, true, &transition1, &transition2); |
517 EXPECT_FALSE(transition1 & PageTransition::CHAIN_END); | 517 EXPECT_FALSE(transition1 & PageTransition::CHAIN_END); |
518 EXPECT_TRUE(transition2 & PageTransition::CHAIN_END); | 518 EXPECT_TRUE(transition2 & PageTransition::CHAIN_END); |
519 } | 519 } |
520 | 520 |
521 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { | 521 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { |
522 // Setup test data - two Urls in the history, one with favicon assigned and | 522 // Setup test data - two Urls in the history, one with favicon assigned and |
523 // one without. | 523 // one without. |
524 GURL favicon_url1("http://www.google.com/favicon.ico"); | 524 GURL favicon_url1("http://www.google.com/favicon.ico"); |
525 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, | 525 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, |
526 FAV_ICON); | 526 FAVICON); |
527 std::vector<unsigned char> data; | 527 std::vector<unsigned char> data; |
528 data.push_back('1'); | 528 data.push_back('1'); |
529 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, | 529 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, |
530 RefCountedBytes::TakeVector(&data), Time::Now())); | 530 RefCountedBytes::TakeVector(&data), Time::Now())); |
531 URLRow row1(GURL("http://www.google.com/")); | 531 URLRow row1(GURL("http://www.google.com/")); |
532 row1.set_visit_count(1); | 532 row1.set_visit_count(1); |
533 row1.set_last_visit(Time::Now()); | 533 row1.set_last_visit(Time::Now()); |
534 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); | 534 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); |
535 | 535 |
536 URLRow row2(GURL("http://news.google.com/")); | 536 URLRow row2(GURL("http://news.google.com/")); |
537 row2.set_visit_count(1); | 537 row2.set_visit_count(1); |
538 row2.set_last_visit(Time::Now()); | 538 row2.set_last_visit(Time::Now()); |
539 std::vector<URLRow> rows; | 539 std::vector<URLRow> rows; |
540 rows.push_back(row1); | 540 rows.push_back(row1); |
541 rows.push_back(row2); | 541 rows.push_back(row2); |
542 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); | 542 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); |
543 URLRow url_row1, url_row2; | 543 URLRow url_row1, url_row2; |
544 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); | 544 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); |
545 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); | 545 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); |
546 EXPECT_FALSE(GetFavicon(row1.url(), FAV_ICON) == 0); | 546 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); |
547 EXPECT_TRUE(GetFavicon(row2.url(), FAV_ICON) == 0); | 547 EXPECT_TRUE(GetFavicon(row2.url(), FAVICON) == 0); |
548 | 548 |
549 // Now provide one imported favicon for both URLs already in the registry. | 549 // Now provide one imported favicon for both URLs already in the registry. |
550 // The new favicon should only be used with the URL that doesn't already have | 550 // The new favicon should only be used with the URL that doesn't already have |
551 // a favicon. | 551 // a favicon. |
552 std::vector<history::ImportedFavIconUsage> favicons; | 552 std::vector<history::ImportedFavIconUsage> favicons; |
553 history::ImportedFavIconUsage favicon; | 553 history::ImportedFavIconUsage favicon; |
554 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); | 554 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); |
555 favicon.png_data.push_back('2'); | 555 favicon.png_data.push_back('2'); |
556 favicon.urls.insert(row1.url()); | 556 favicon.urls.insert(row1.url()); |
557 favicon.urls.insert(row2.url()); | 557 favicon.urls.insert(row2.url()); |
558 favicons.push_back(favicon); | 558 favicons.push_back(favicon); |
559 backend_->SetImportedFavicons(favicons); | 559 backend_->SetImportedFavicons(favicons); |
560 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); | 560 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); |
561 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); | 561 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); |
562 EXPECT_FALSE(GetFavicon(row1.url(), FAV_ICON) == 0); | 562 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); |
563 EXPECT_FALSE(GetFavicon(row2.url(), FAV_ICON) == 0); | 563 EXPECT_FALSE(GetFavicon(row2.url(), FAVICON) == 0); |
564 EXPECT_FALSE(GetFavicon(row1.url(), FAV_ICON) == | 564 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == |
565 GetFavicon(row2.url(), FAV_ICON)); | 565 GetFavicon(row2.url(), FAVICON)); |
566 | 566 |
567 // A URL should not be added to history (to store favicon), if | 567 // A URL should not be added to history (to store favicon), if |
568 // the URL is not bookmarked. | 568 // the URL is not bookmarked. |
569 GURL url3("http://mail.google.com"); | 569 GURL url3("http://mail.google.com"); |
570 favicons.clear(); | 570 favicons.clear(); |
571 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); | 571 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); |
572 favicon.png_data.push_back('3'); | 572 favicon.png_data.push_back('3'); |
573 favicon.urls.insert(url3); | 573 favicon.urls.insert(url3); |
574 favicons.push_back(favicon); | 574 favicons.push_back(favicon); |
575 backend_->SetImportedFavicons(favicons); | 575 backend_->SetImportedFavicons(favicons); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 | 840 |
841 history::RedirectList redirects; | 841 history::RedirectList redirects; |
842 redirects.push_back(url2); | 842 redirects.push_back(url2); |
843 redirects.push_back(url1); | 843 redirects.push_back(url1); |
844 backend_->recent_redirects_.Put(url1, redirects); | 844 backend_->recent_redirects_.Put(url1, redirects); |
845 | 845 |
846 const GURL icon_url("http://www.google.com/icon"); | 846 const GURL icon_url("http://www.google.com/icon"); |
847 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 847 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
848 // Add a favicon | 848 // Add a favicon |
849 backend_->SetFavicon( | 849 backend_->SetFavicon( |
850 url1, icon_url, RefCountedBytes::TakeVector(&data), FAV_ICON); | 850 url1, icon_url, RefCountedBytes::TakeVector(&data), FAVICON); |
851 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 851 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
852 url1, FAV_ICON, NULL)); | 852 url1, FAVICON, NULL)); |
853 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 853 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
854 url2, FAV_ICON, NULL)); | 854 url2, FAVICON, NULL)); |
855 | 855 |
856 // Add a touch_icon | 856 // Add a touch_icon |
857 backend_->SetFavicon( | 857 backend_->SetFavicon( |
858 url1, icon_url, RefCountedBytes::TakeVector(&data), TOUCH_ICON); | 858 url1, icon_url, RefCountedBytes::TakeVector(&data), TOUCH_ICON); |
859 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 859 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
860 url1, TOUCH_ICON, NULL)); | 860 url1, TOUCH_ICON, NULL)); |
861 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 861 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
862 url2, TOUCH_ICON, NULL)); | 862 url2, TOUCH_ICON, NULL)); |
863 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 863 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
864 url1, FAV_ICON, NULL)); | 864 url1, FAVICON, NULL)); |
865 | 865 |
866 // Add a TOUCH_PRECOMPOSED_ICON | 866 // Add a TOUCH_PRECOMPOSED_ICON |
867 backend_->SetFavicon(url1, | 867 backend_->SetFavicon(url1, |
868 icon_url, | 868 icon_url, |
869 RefCountedBytes::TakeVector(&data), | 869 RefCountedBytes::TakeVector(&data), |
870 TOUCH_PRECOMPOSED_ICON); | 870 TOUCH_PRECOMPOSED_ICON); |
871 // The touch_icon was replaced. | 871 // The touch_icon was replaced. |
872 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 872 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
873 url1, TOUCH_ICON, NULL)); | 873 url1, TOUCH_ICON, NULL)); |
874 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 874 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
875 url1, FAV_ICON, NULL)); | 875 url1, FAVICON, NULL)); |
876 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 876 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
877 url1, TOUCH_PRECOMPOSED_ICON, NULL)); | 877 url1, TOUCH_PRECOMPOSED_ICON, NULL)); |
878 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 878 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
879 url2, TOUCH_PRECOMPOSED_ICON, NULL)); | 879 url2, TOUCH_PRECOMPOSED_ICON, NULL)); |
880 | 880 |
881 // Add a touch_icon | 881 // Add a touch_icon |
882 backend_->SetFavicon( | 882 backend_->SetFavicon( |
883 url1, icon_url, RefCountedBytes::TakeVector(&data), TOUCH_ICON); | 883 url1, icon_url, RefCountedBytes::TakeVector(&data), TOUCH_ICON); |
884 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 884 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
885 url1, TOUCH_ICON, NULL)); | 885 url1, TOUCH_ICON, NULL)); |
886 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 886 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
887 url1, FAV_ICON, NULL)); | 887 url1, FAVICON, NULL)); |
888 // The TOUCH_PRECOMPOSED_ICON was replaced. | 888 // The TOUCH_PRECOMPOSED_ICON was replaced. |
889 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( | 889 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingForPageURL( |
890 url1, TOUCH_PRECOMPOSED_ICON, NULL)); | 890 url1, TOUCH_PRECOMPOSED_ICON, NULL)); |
891 | 891 |
892 // Add a fav_icon | 892 // Add a favicon |
893 const GURL icon_url2("http://www.google.com/icon2"); | 893 const GURL icon_url2("http://www.google.com/icon2"); |
894 backend_->SetFavicon( | 894 backend_->SetFavicon( |
895 url1, icon_url2, RefCountedBytes::TakeVector(&data), FAV_ICON); | 895 url1, icon_url2, RefCountedBytes::TakeVector(&data), FAVICON); |
896 FavIconID icon_id = backend_->thumbnail_db_->GetFavIconIDForFavIconURL( | 896 FavIconID icon_id = backend_->thumbnail_db_->GetFavIconIDForFavIconURL( |
897 icon_url2, FAV_ICON, NULL); | 897 icon_url2, FAVICON, NULL); |
898 EXPECT_NE(0, icon_id); | 898 EXPECT_NE(0, icon_id); |
899 std::vector<IconMapping> icon_mapping; | 899 std::vector<IconMapping> icon_mapping; |
900 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 900 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
901 url1, &icon_mapping)); | 901 url1, &icon_mapping)); |
902 // The old icon was replaced. | 902 // The old icon was replaced. |
903 EXPECT_TRUE(icon_mapping.size() > 1); | 903 EXPECT_TRUE(icon_mapping.size() > 1); |
904 EXPECT_EQ(icon_id, icon_mapping[1].icon_id); | 904 EXPECT_EQ(icon_id, icon_mapping[1].icon_id); |
905 } | 905 } |
906 | 906 |
907 TEST_F(HistoryBackendTest, AddOrUpdateIconMapping) { | 907 TEST_F(HistoryBackendTest, AddOrUpdateIconMapping) { |
908 // Test the same icon and page mapping will not be added twice. other case | 908 // Test the same icon and page mapping will not be added twice. other case |
909 // should be covered in TEST_F(HistoryBackendTest, SetFaviconMapping) | 909 // should be covered in TEST_F(HistoryBackendTest, SetFaviconMapping) |
910 const GURL url("http://www.google.com/"); | 910 const GURL url("http://www.google.com/"); |
911 const GURL icon_url("http://www.google.com/icon"); | 911 const GURL icon_url("http://www.google.com/icon"); |
912 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); | 912 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); |
913 | 913 |
914 backend_->SetFavicon( | 914 backend_->SetFavicon( |
915 url, icon_url, RefCountedBytes::TakeVector(&data), FAV_ICON); | 915 url, icon_url, RefCountedBytes::TakeVector(&data), FAVICON); |
916 FavIconID icon_id = backend_->thumbnail_db_->GetFavIconIDForFavIconURL( | 916 FavIconID icon_id = backend_->thumbnail_db_->GetFavIconIDForFavIconURL( |
917 icon_url, FAV_ICON, NULL); | 917 icon_url, FAVICON, NULL); |
918 | 918 |
919 // Add the same mapping | 919 // Add the same mapping |
920 FavIconID replaced; | 920 FavIconID replaced; |
921 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( | 921 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( |
922 url, icon_id, FAV_ICON, &replaced)); | 922 url, icon_id, FAVICON, &replaced)); |
923 EXPECT_EQ(0, replaced); | 923 EXPECT_EQ(0, replaced); |
924 | 924 |
925 std::vector<IconMapping> icon_mapping; | 925 std::vector<IconMapping> icon_mapping; |
926 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( | 926 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( |
927 url, &icon_mapping)); | 927 url, &icon_mapping)); |
928 EXPECT_EQ(1u, icon_mapping.size()); | 928 EXPECT_EQ(1u, icon_mapping.size()); |
929 } | 929 } |
930 | 930 |
931 } // namespace history | 931 } // namespace history |
OLD | NEW |