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

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

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/history/thumbnail_database.h" 25 #include "chrome/browser/history/thumbnail_database.h"
26 #include "chrome/browser/history/top_sites.h" 26 #include "chrome/browser/history/top_sites.h"
27 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/thumbnail_score.h" 28 #include "chrome/common/thumbnail_score.h"
29 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
30 #include "chrome/tools/profiles/thumbnail-inl.h" 30 #include "chrome/tools/profiles/thumbnail-inl.h"
31 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "ui/gfx/codec/jpeg_codec.h" 34 #include "ui/gfx/codec/jpeg_codec.h"
35 #include "ui/gfx/favicon_size.h"
35 36
36 using base::Time; 37 using base::Time;
37 using base::TimeDelta; 38 using base::TimeDelta;
38 using base::TimeTicks; 39 using base::TimeTicks;
39 using content::BrowserThread; 40 using content::BrowserThread;
40 41
41 // Filename constants. 42 // Filename constants.
42 static const FilePath::CharType kHistoryFile[] = FILE_PATH_LITERAL("History"); 43 static const FilePath::CharType kHistoryFile[] = FILE_PATH_LITERAL("History");
43 static const FilePath::CharType kArchivedHistoryFile[] = 44 static const FilePath::CharType kArchivedHistoryFile[] =
44 FILE_PATH_LITERAL("Archived History"); 45 FILE_PATH_LITERAL("Archived History");
45 static const FilePath::CharType kThumbnailFile[] = 46 static const FilePath::CharType kThumbnailFile[] =
46 FILE_PATH_LITERAL("Thumbnails"); 47 FILE_PATH_LITERAL("Thumbnails");
47 48
49 static const gfx::Size kFaviconRegularSize =
50 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize);
51
48 // The test must be in the history namespace for the gtest forward declarations 52 // The test must be in the history namespace for the gtest forward declarations
49 // to work. It also eliminates a bunch of ugly "history::". 53 // to work. It also eliminates a bunch of ugly "history::".
50 namespace history { 54 namespace history {
51 55
52 // ExpireHistoryTest ----------------------------------------------------------- 56 // ExpireHistoryTest -----------------------------------------------------------
53 57
54 class ExpireHistoryTest : public testing::Test, 58 class ExpireHistoryTest : public testing::Test,
55 public BroadcastNotificationDelegate { 59 public BroadcastNotificationDelegate {
56 public: 60 public:
57 ExpireHistoryTest() 61 ExpireHistoryTest()
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 202
199 // Four times for each visit. 203 // Four times for each visit.
200 visit_times[3] = Time::Now(); 204 visit_times[3] = Time::Now();
201 visit_times[2] = visit_times[3] - TimeDelta::FromDays(1); 205 visit_times[2] = visit_times[3] - TimeDelta::FromDays(1);
202 visit_times[1] = visit_times[3] - TimeDelta::FromDays(2); 206 visit_times[1] = visit_times[3] - TimeDelta::FromDays(2);
203 visit_times[0] = visit_times[3] - TimeDelta::FromDays(3); 207 visit_times[0] = visit_times[3] - TimeDelta::FromDays(3);
204 208
205 // Two favicons. The first two URLs will share the same one, while the last 209 // Two favicons. The first two URLs will share the same one, while the last
206 // one will have a unique favicon. 210 // one will have a unique favicon.
207 FaviconID favicon1 = thumb_db_->AddFavicon(GURL("http://favicon/url1"), 211 FaviconID favicon1 = thumb_db_->AddFavicon(GURL("http://favicon/url1"),
208 FAVICON); 212 kFaviconRegularSize, FAVICON);
209 FaviconID favicon2 = thumb_db_->AddFavicon(GURL("http://favicon/url2"), 213 FaviconID favicon2 = thumb_db_->AddFavicon(GURL("http://favicon/url2"),
210 FAVICON); 214 kFaviconRegularSize, FAVICON);
211 215
212 // Three URLs. 216 // Three URLs.
213 URLRow url_row1(GURL("http://www.google.com/1")); 217 URLRow url_row1(GURL("http://www.google.com/1"));
214 url_row1.set_last_visit(visit_times[0]); 218 url_row1.set_last_visit(visit_times[0]);
215 url_row1.set_visit_count(1); 219 url_row1.set_visit_count(1);
216 url_ids[0] = main_db_->AddURL(url_row1); 220 url_ids[0] = main_db_->AddURL(url_row1);
217 thumb_db_->AddIconMapping(url_row1.url(), favicon1); 221 thumb_db_->AddIconMapping(url_row1.url(), favicon1);
218 222
219 URLRow url_row2(GURL("http://www.google.com/2")); 223 URLRow url_row2(GURL("http://www.google.com/2"));
220 url_row2.set_last_visit(visit_times[2]); 224 url_row2.set_last_visit(visit_times[2]);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 main_db_->AddVisit(&visit_row4, SOURCE_FIREFOX_IMPORTED); 320 main_db_->AddVisit(&visit_row4, SOURCE_FIREFOX_IMPORTED);
317 } 321 }
318 322
319 bool ExpireHistoryTest::HasFavicon(FaviconID favicon_id) { 323 bool ExpireHistoryTest::HasFavicon(FaviconID favicon_id) {
320 if (!thumb_db_.get() || favicon_id == 0) 324 if (!thumb_db_.get() || favicon_id == 0)
321 return false; 325 return false;
322 Time last_updated; 326 Time last_updated;
323 std::vector<unsigned char> icon_data_unused; 327 std::vector<unsigned char> icon_data_unused;
324 GURL icon_url; 328 GURL icon_url;
325 return thumb_db_->GetFavicon(favicon_id, &last_updated, &icon_data_unused, 329 return thumb_db_->GetFavicon(favicon_id, &last_updated, &icon_data_unused,
326 &icon_url, NULL); 330 &icon_url, NULL, NULL);
327 } 331 }
328 332
329 FaviconID ExpireHistoryTest::GetFavicon(const GURL& page_url, 333 FaviconID ExpireHistoryTest::GetFavicon(const GURL& page_url,
330 IconType icon_type) { 334 IconType icon_type) {
331 IconMapping icon_mapping; 335 std::vector<IconMapping> icon_mappings;
332 thumb_db_->GetIconMappingForPageURL(page_url, icon_type, &icon_mapping); 336 thumb_db_->GetIconMappingsForPageURL(page_url, icon_type, &icon_mappings);
333 return icon_mapping.icon_id; 337
338 if (icon_mappings.empty())
339 return 0;
340
341 return icon_mappings[0].icon_id;
334 } 342 }
335 343
336 bool ExpireHistoryTest::HasThumbnail(URLID url_id) { 344 bool ExpireHistoryTest::HasThumbnail(URLID url_id) {
337 // TODO(sky): fix this. This test isn't really valid for TopSites. For 345 // TODO(sky): fix this. This test isn't really valid for TopSites. For
338 // TopSites we should be checking URL always, not the id. 346 // TopSites we should be checking URL always, not the id.
339 URLRow info; 347 URLRow info;
340 if (!main_db_->GetURLRow(url_id, &info)) 348 if (!main_db_->GetURLRow(url_id, &info))
341 return false; 349 return false;
342 GURL url = info.url(); 350 GURL url = info.url();
343 scoped_refptr<base::RefCountedMemory> data; 351 scoped_refptr<base::RefCountedMemory> data;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 EXPECT_NE(notifications_[i].first, 405 EXPECT_NE(notifications_[i].first,
398 chrome::NOTIFICATION_HISTORY_URLS_MODIFIED); 406 chrome::NOTIFICATION_HISTORY_URLS_MODIFIED);
399 } 407 }
400 } 408 }
401 EXPECT_TRUE(found_delete_notification); 409 EXPECT_TRUE(found_delete_notification);
402 } 410 }
403 411
404 TEST_F(ExpireHistoryTest, DeleteFaviconsIfPossible) { 412 TEST_F(ExpireHistoryTest, DeleteFaviconsIfPossible) {
405 // Add a favicon record. 413 // Add a favicon record.
406 const GURL favicon_url("http://www.google.com/favicon.ico"); 414 const GURL favicon_url("http://www.google.com/favicon.ico");
407 FaviconID icon_id = thumb_db_->AddFavicon(favicon_url, FAVICON); 415 FaviconID icon_id = thumb_db_->AddFavicon(favicon_url, kFaviconRegularSize,
416 FAVICON);
408 EXPECT_TRUE(icon_id); 417 EXPECT_TRUE(icon_id);
409 EXPECT_TRUE(HasFavicon(icon_id)); 418 EXPECT_TRUE(HasFavicon(icon_id));
410 419
411 // The favicon should be deletable with no users. 420 // The favicon should be deletable with no users.
412 std::set<FaviconID> favicon_set; 421 std::set<FaviconID> favicon_set;
413 favicon_set.insert(icon_id); 422 favicon_set.insert(icon_id);
414 expirer_.DeleteFaviconsIfPossible(favicon_set); 423 expirer_.DeleteFaviconsIfPossible(favicon_set);
415 EXPECT_FALSE(HasFavicon(icon_id)); 424 EXPECT_FALSE(HasFavicon(icon_id));
416 425
417 // Add back the favicon. 426 // Add back the favicon.
418 icon_id = thumb_db_->AddFavicon(favicon_url, TOUCH_ICON); 427 icon_id = thumb_db_->AddFavicon(favicon_url, kFaviconRegularSize,
428 TOUCH_ICON);
419 EXPECT_TRUE(icon_id); 429 EXPECT_TRUE(icon_id);
420 EXPECT_TRUE(HasFavicon(icon_id)); 430 EXPECT_TRUE(HasFavicon(icon_id));
421 431
422 // Add a page that references the favicon. 432 // Add a page that references the favicon.
423 URLRow row(GURL("http://www.google.com/2")); 433 URLRow row(GURL("http://www.google.com/2"));
424 row.set_visit_count(1); 434 row.set_visit_count(1);
425 EXPECT_TRUE(main_db_->AddURL(row)); 435 EXPECT_TRUE(main_db_->AddURL(row));
426 thumb_db_->AddIconMapping(row.url(), icon_id); 436 thumb_db_->AddIconMapping(row.url(), icon_id);
427 437
428 // Favicon should not be deletable. 438 // Favicon should not be deletable.
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 main_db_->GetVisitsForURL(url_id, &archived_visits); 966 main_db_->GetVisitsForURL(url_id, &archived_visits);
957 EXPECT_EQ(0U, archived_visits.size()); 967 EXPECT_EQ(0U, archived_visits.size());
958 } 968 }
959 969
960 // TODO(brettw) add some visits with no URL to make sure everything is updated 970 // TODO(brettw) add some visits with no URL to make sure everything is updated
961 // properly. Have the visits also refer to nonexistent FTS rows. 971 // properly. Have the visits also refer to nonexistent FTS rows.
962 // 972 //
963 // Maybe also refer to invalid favicons. 973 // Maybe also refer to invalid favicons.
964 974
965 } // namespace history 975 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698