Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: chrome/browser/history/history_backend_unittest.cc

Issue 10815068: Changes favicon database to support storing bitmaps of different sizes for the same icon_url (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as per Sky's suggestions on Aug 1 Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // deleted. This way we can test that updating works properly. 293 // deleted. This way we can test that updating works properly.
294 GURL favicon_url1("http://www.google.com/favicon.ico"); 294 GURL favicon_url1("http://www.google.com/favicon.ico");
295 GURL favicon_url2("http://news.google.com/favicon.ico"); 295 GURL favicon_url2("http://news.google.com/favicon.ico");
296 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, 296 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2,
297 FAVICON); 297 FAVICON);
298 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, 298 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1,
299 FAVICON); 299 FAVICON);
300 300
301 std::vector<unsigned char> data; 301 std::vector<unsigned char> data;
302 data.push_back('1'); 302 data.push_back('1');
303 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, 303 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconFrame(favicon1,
304 new base::RefCountedBytes(data), Time::Now())); 304 new base::RefCountedBytes(data), Time::Now()));
305 305
306 data[0] = '2'; 306 data[0] = '2';
307 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( 307 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconFrame(
308 favicon2, new base::RefCountedBytes(data), Time::Now())); 308 favicon2, new base::RefCountedBytes(data), Time::Now()));
309 309
310 // First visit two URLs. 310 // First visit two URLs.
311 URLRow row1(GURL("http://www.google.com/")); 311 URLRow row1(GURL("http://www.google.com/"));
312 row1.set_visit_count(2); 312 row1.set_visit_count(2);
313 row1.set_typed_count(1); 313 row1.set_typed_count(1);
314 row1.set_last_visit(Time::Now()); 314 row1.set_last_visit(Time::Now());
315 backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1); 315 backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1);
316 316
317 URLRow row2(GURL("http://news.google.com/")); 317 URLRow row2(GURL("http://news.google.com/"));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 VisitVector all_visits; 394 VisitVector all_visits;
395 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 395 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
396 ASSERT_EQ(0U, all_visits.size()); 396 ASSERT_EQ(0U, all_visits.size());
397 397
398 // All thumbnails should be deleted. 398 // All thumbnails should be deleted.
399 std::vector<unsigned char> out_data; 399 std::vector<unsigned char> out_data;
400 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), 400 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(),
401 &out_data)); 401 &out_data));
402 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); 402 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data));
403 403
404 // We should have a favicon for the first URL only. We look them up by favicon 404 // We should have a favicon and favicon frame for the first URL only. We
405 // URL since the IDs may hav changed. 405 // look them up by favicon URL since the IDs may hav changed.
406 FaviconID out_favicon1 = backend_->thumbnail_db_-> 406 FaviconID out_favicon1 = backend_->thumbnail_db_->
407 GetFaviconIDForFaviconURL(favicon_url1, FAVICON, NULL); 407 GetFaviconIDForFaviconURL(favicon_url1, FAVICON, NULL);
408 EXPECT_TRUE(out_favicon1); 408 EXPECT_TRUE(out_favicon1);
409 std::vector<unsigned char> result_data;
410 EXPECT_TRUE(backend_->thumbnail_db_->
411 GetFaviconFrame(out_favicon1, NULL, &result_data));
412 EXPECT_EQ(data, result_data);
409 FaviconID out_favicon2 = backend_->thumbnail_db_-> 413 FaviconID out_favicon2 = backend_->thumbnail_db_->
410 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL); 414 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL);
411 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; 415 EXPECT_FALSE(out_favicon2) << "Favicon not deleted";
412 416
413 // The remaining URL should still reference the same favicon, even if its 417 // The remaining URL should still reference the same favicon, even if its
414 // ID has changed. 418 // ID has changed.
415 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); 419 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON));
416 420
417 // The first URL should still be bookmarked. 421 // The first URL should still be bookmarked.
418 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); 422 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url()));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { 489 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
486 GURL favicon_url1("http://www.google.com/favicon.ico"); 490 GURL favicon_url1("http://www.google.com/favicon.ico");
487 GURL favicon_url2("http://news.google.com/favicon.ico"); 491 GURL favicon_url2("http://news.google.com/favicon.ico");
488 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, 492 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2,
489 FAVICON); 493 FAVICON);
490 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, 494 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1,
491 FAVICON); 495 FAVICON);
492 496
493 std::vector<unsigned char> data; 497 std::vector<unsigned char> data;
494 data.push_back('1'); 498 data.push_back('1');
495 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( 499 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconFrame(
496 favicon1, new base::RefCountedBytes(data), Time::Now())); 500 favicon1, new base::RefCountedBytes(data), Time::Now()));
497 501
498 data[0] = '2'; 502 data[0] = '2';
499 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( 503 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconFrame(
500 favicon2, new base::RefCountedBytes(data), Time::Now())); 504 favicon2, new base::RefCountedBytes(data), Time::Now()));
501 505
502 // First visit two URLs. 506 // First visit two URLs.
503 URLRow row1(GURL("http://www.google.com/")); 507 URLRow row1(GURL("http://www.google.com/"));
504 row1.set_visit_count(2); 508 row1.set_visit_count(2);
505 row1.set_typed_count(1); 509 row1.set_typed_count(1);
506 row1.set_last_visit(Time::Now()); 510 row1.set_last_visit(Time::Now());
507 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); 511 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1));
508 512
509 URLRow row2(GURL("http://news.google.com/")); 513 URLRow row2(GURL("http://news.google.com/"));
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 663 }
660 664
661 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { 665 TEST_F(HistoryBackendTest, ImportedFaviconsTest) {
662 // Setup test data - two Urls in the history, one with favicon assigned and 666 // Setup test data - two Urls in the history, one with favicon assigned and
663 // one without. 667 // one without.
664 GURL favicon_url1("http://www.google.com/favicon.ico"); 668 GURL favicon_url1("http://www.google.com/favicon.ico");
665 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, 669 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1,
666 FAVICON); 670 FAVICON);
667 std::vector<unsigned char> data; 671 std::vector<unsigned char> data;
668 data.push_back('1'); 672 data.push_back('1');
669 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, 673 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconFrame(favicon1,
670 base::RefCountedBytes::TakeVector(&data), Time::Now())); 674 base::RefCountedBytes::TakeVector(&data), Time::Now()));
671 URLRow row1(GURL("http://www.google.com/")); 675 URLRow row1(GURL("http://www.google.com/"));
672 row1.set_visit_count(1); 676 row1.set_visit_count(1);
673 row1.set_last_visit(Time::Now()); 677 row1.set_last_visit(Time::Now());
674 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); 678 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1));
675 679
676 URLRow row2(GURL("http://news.google.com/")); 680 URLRow row2(GURL("http://news.google.com/"));
677 row2.set_visit_count(1); 681 row2.set_visit_count(1);
678 row2.set_last_visit(Time::Now()); 682 row2.set_last_visit(Time::Now());
679 URLRows rows; 683 URLRows rows;
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 1571
1568 backend_->DeleteURL(url); 1572 backend_->DeleteURL(url);
1569 backend_->AddPageNoVisitForBookmark(url, string16()); 1573 backend_->AddPageNoVisitForBookmark(url, string16());
1570 backend_->GetURL(url, &row); 1574 backend_->GetURL(url, &row);
1571 EXPECT_EQ(url, row.url()); 1575 EXPECT_EQ(url, row.url());
1572 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); 1576 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title());
1573 EXPECT_EQ(0, row.visit_count()); 1577 EXPECT_EQ(0, row.visit_count());
1574 } 1578 }
1575 1579
1576 } // namespace history 1580 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698