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

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

Issue 6698031: fav icon -> favicon. Pass 7: FavIconID -> FaviconID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 URLID id = backend_->db()->GetRowForURL(url, &row); 123 URLID id = backend_->db()->GetRowForURL(url, &row);
124 VisitVector visits; 124 VisitVector visits;
125 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); 125 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
126 return visits[0].transition; 126 return visits[0].transition;
127 } 127 }
128 128
129 FilePath getTestDir() { 129 FilePath getTestDir() {
130 return test_dir_; 130 return test_dir_;
131 } 131 }
132 132
133 FavIconID GetFavicon(const GURL& url, IconType icon_type) { 133 FaviconID GetFavicon(const GURL& url, IconType icon_type) {
134 IconMapping icon_mapping; 134 IconMapping icon_mapping;
135 if (backend_->thumbnail_db_->GetIconMappingForPageURL(url, icon_type, 135 if (backend_->thumbnail_db_->GetIconMappingForPageURL(url, icon_type,
136 &icon_mapping)) 136 &icon_mapping))
137 return icon_mapping.icon_id; 137 return icon_mapping.icon_id;
138 else 138 else
139 return 0; 139 return 0;
140 } 140 }
141 141
142 BookmarkModel bookmark_model_; 142 BookmarkModel bookmark_model_;
143 143
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
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 FAV_ICON);
221 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, 221 FaviconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1,
222 FAV_ICON); 222 FAV_ICON);
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()));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ASSERT_EQ(0U, all_visits.size()); 315 ASSERT_EQ(0U, all_visits.size());
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, FAV_ICON, 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, FAV_ICON, 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(), FAV_ICON));
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 FAV_ICON);
354 FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1, 354 FaviconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1,
355 FAV_ICON); 355 FAV_ICON);
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()));
(...skipping 27 matching lines...) Expand all
392 backend_->expirer_.DeleteURL(row2.url()); 392 backend_->expirer_.DeleteURL(row2.url());
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 FAV_ICON,
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 FAV_ICON,
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 FAV_ICON,
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");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 GURL url_c("http://google.com/c"); 515 GURL url_c("http://google.com/c");
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 FAV_ICON);
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
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL( 886 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingForPageURL(
887 url1, FAV_ICON, NULL)); 887 url1, FAV_ICON, 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 fav_icon
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), FAV_ICON);
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, FAV_ICON, 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), FAV_ICON);
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, FAV_ICON, 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, FAV_ICON, &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
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698