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

Side by Side Diff: chrome/browser/history/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, 3 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) 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 <set> 6 #include <set>
6 #include <vector> 7 #include <vector>
7 8
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/file_path.h" 10 #include "base/file_path.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/string16.h" 15 #include "base/string16.h"
(...skipping 23 matching lines...) Expand all
38 // backend directly. Most of the history backend functions are tested by the 39 // backend directly. Most of the history backend functions are tested by the
39 // history unit test. Because of the elaborate callbacks involved, this is no 40 // history unit test. Because of the elaborate callbacks involved, this is no
40 // harder than calling it directly for many things. 41 // harder than calling it directly for many things.
41 42
42 namespace { 43 namespace {
43 44
44 // data we'll put into the thumbnail database 45 // data we'll put into the thumbnail database
45 static const unsigned char blob1[] = 46 static const unsigned char blob1[] =
46 "12346102356120394751634516591348710478123649165419234519234512349134"; 47 "12346102356120394751634516591348710478123649165419234519234512349134";
47 48
49 static const gfx::Size kTinySize = gfx::Size(10, 10);
48 static const gfx::Size kSmallSize = gfx::Size(16, 16); 50 static const gfx::Size kSmallSize = gfx::Size(16, 16);
49 static const gfx::Size kLargeSize = gfx::Size(48, 48); 51 static const gfx::Size kLargeSize = gfx::Size(32, 32);
52
53 // Comparison functions as to make it easier to check results of
54 // GetFaviconBitmaps() and GetIconMappingsForPageURL().
55 bool IconMappingLessThan(const history::IconMapping& a,
56 const history::IconMapping& b) {
57 return a.icon_url < b.icon_url;
58 }
59
60 bool FaviconBitmapLessThan(const history::FaviconBitmap& a,
61 const history::FaviconBitmap& b) {
62 return a.pixel_size.GetArea() < b.pixel_size.GetArea();
63 }
50 64
51 } // namepace 65 } // namepace
52 66
53 namespace history { 67 namespace history {
54 68
55 class HistoryBackendTest; 69 class HistoryBackendTest;
56 70
57 // This must be a separate object since HistoryBackend manages its lifetime. 71 // 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. 72 // This just forwards the messages we're interested in to the test object.
59 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { 73 class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 URLID id = backend_->db()->GetRowForURL(url, &row); 215 URLID id = backend_->db()->GetRowForURL(url, &row);
202 VisitVector visits; 216 VisitVector visits;
203 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); 217 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
204 return visits[0].transition; 218 return visits[0].transition;
205 } 219 }
206 220
207 FilePath getTestDir() { 221 FilePath getTestDir() {
208 return test_dir_; 222 return test_dir_;
209 } 223 }
210 224
225 // Returns a gfx::Size vector with small size.
226 const std::vector<gfx::Size> GetSizesSmall() {
227 std::vector<gfx::Size> sizes_small;
228 sizes_small.push_back(kSmallSize);
229 return sizes_small;
230 }
231
232 // Returns a gfx::Size vector with large size.
233 const std::vector<gfx::Size> GetSizesLarge() {
234 std::vector<gfx::Size> sizes_large;
235 sizes_large.push_back(kLargeSize);
236 return sizes_large;
237 }
238
211 // Returns a gfx::Size vector with small and large sizes. 239 // Returns a gfx::Size vector with small and large sizes.
212 const std::vector<gfx::Size> GetSizesSmallAndLarge() { 240 const std::vector<gfx::Size> GetSizesSmallAndLarge() {
213 std::vector<gfx::Size> sizes_small_and_large; 241 std::vector<gfx::Size> sizes_small_and_large;
214 sizes_small_and_large.push_back(kSmallSize); 242 sizes_small_and_large.push_back(kSmallSize);
215 sizes_small_and_large.push_back(kLargeSize); 243 sizes_small_and_large.push_back(kLargeSize);
216 return sizes_small_and_large; 244 return sizes_small_and_large;
217 } 245 }
218 246
219 FaviconID GetFavicon(const GURL& url, IconType icon_type) { 247 // Returns a gfx::Size vector with tiny, small and large sizes.
248 const std::vector<gfx::Size> GetSizesTinySmallAndLarge() {
249 std::vector<gfx::Size> sizes_tiny_small_and_large;
250 sizes_tiny_small_and_large.push_back(kTinySize);
251 sizes_tiny_small_and_large.push_back(kSmallSize);
252 sizes_tiny_small_and_large.push_back(kLargeSize);
253 return sizes_tiny_small_and_large;
254 }
255
256 // Returns 1x and 2x scale factors.
257 const std::vector<ui::ScaleFactor> GetScaleFactors1x2x() {
258 std::vector<ui::ScaleFactor> scale_factors_1x_2x;
259 scale_factors_1x_2x.push_back(ui::SCALE_FACTOR_100P);
260 scale_factors_1x_2x.push_back(ui::SCALE_FACTOR_200P);
261 return scale_factors_1x_2x;
262 }
263
264 // Returns the number of icon mappings of |icon_type| to |page_url|.
265 size_t NumIconMappingsForPageURL(const GURL& page_url, IconType icon_type) {
220 std::vector<IconMapping> icon_mappings; 266 std::vector<IconMapping> icon_mappings;
221 if (backend_->thumbnail_db_->GetIconMappingsForPageURL(url, icon_type, 267 backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type,
222 &icon_mappings)) 268 &icon_mappings);
223 return icon_mappings[0].icon_id; 269 return icon_mappings.size();
224 else 270 }
225 return 0; 271
272 // Returns the icon mappings for |page_url| sorted alphabetically by icon
273 // URL in ascending order. Returns true if there is at least one icon
274 // mapping.
275 bool GetSortedIconMappingsForPageURL(
276 const GURL& page_url,
277 std::vector<IconMapping>* icon_mappings) {
278 if (!backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
279 icon_mappings)) {
280 return false;
281 }
282 std::sort(icon_mappings->begin(), icon_mappings->end(),
283 IconMappingLessThan);
284 return true;
285 }
286
287 // Returns the favicon bitmaps for |icon_id| sorted by pixel size in
288 // ascending order. Returns true if there is at least one favicon bitmap.
289 bool GetSortedFaviconBitmaps(FaviconID icon_id,
290 std::vector<FaviconBitmap>* favicon_bitmaps) {
291 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps))
292 return false;
293 std::sort(favicon_bitmaps->begin(), favicon_bitmaps->end(),
294 FaviconBitmapLessThan);
295 return true;
296 }
297
298 // Returns true if there is exactly one favicon bitmap associated to
299 // |icon_url|. If true, returns favicon bitmap in output parameter.
300 bool GetOnlyFaviconBitmapForIconURL(const GURL& icon_url,
301 IconType icon_type,
302 FaviconBitmap* favicon_bitmap) {
303 FaviconID id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
304 icon_url, icon_type, NULL);
305 if (!id)
306 return false;
307 std::vector<FaviconBitmap> favicon_bitmaps;
308 if (!backend_->thumbnail_db_->GetFaviconBitmaps(id, &favicon_bitmaps))
309 return false;
310 if (favicon_bitmaps.size() != 1)
311 return false;
312 *favicon_bitmap = favicon_bitmaps[0];
313 return true;
314 }
315
316 // Generates |favicon_bitmap_data| with entries for the icon_urls and sizes
317 // specified. The bitmap_data for entries are lowercase letters of the
318 // alphabet starting at 'a' for the entry at index 0.
319 void GenerateFaviconBitmapData(
320 const GURL& icon_url1,
321 const std::vector<gfx::Size>& icon_url1_sizes,
322 std::vector<FaviconBitmapData>* favicon_bitmap_data) {
323 GenerateFaviconBitmapData(icon_url1, icon_url1_sizes, GURL(),
324 std::vector<gfx::Size>(), favicon_bitmap_data);
325 }
326
327 void GenerateFaviconBitmapData(
328 const GURL& icon_url1,
329 const std::vector<gfx::Size>& icon_url1_sizes,
330 const GURL& icon_url2,
331 const std::vector<gfx::Size>& icon_url2_sizes,
332 std::vector<FaviconBitmapData>* favicon_bitmap_data) {
333 favicon_bitmap_data->clear();
334
335 char bitmap_char = 'a';
336 for (size_t i = 0; i < icon_url1_sizes.size(); ++i) {
337 std::vector<unsigned char> data;
338 data.push_back(bitmap_char);
339 FaviconBitmapData bitmap_data_element;
340 bitmap_data_element.bitmap_data =
341 base::RefCountedBytes::TakeVector(&data);
342 bitmap_data_element.pixel_size = icon_url1_sizes[i];
343 bitmap_data_element.icon_url = icon_url1;
344 favicon_bitmap_data->push_back(bitmap_data_element);
345
346 ++bitmap_char;
347 }
348
349 for (size_t i = 0; i < icon_url2_sizes.size(); ++i) {
350 std::vector<unsigned char> data;
351 data.push_back(bitmap_char);
352 FaviconBitmapData bitmap_data_element;
353 bitmap_data_element.bitmap_data =
354 base::RefCountedBytes::TakeVector(&data);
355 bitmap_data_element.pixel_size = icon_url2_sizes[i];
356 bitmap_data_element.icon_url = icon_url2;
357 favicon_bitmap_data->push_back(bitmap_data_element);
358
359 ++bitmap_char;
360 }
361 }
362
363 // Returns true if |bitmap_data| is equal to |expected_data|.
364 bool BitmapDataEqual(char expected_data,
365 scoped_refptr<base::RefCountedMemory> bitmap_data) {
366 return bitmap_data.get() &&
367 bitmap_data->size() == 1u &&
368 *bitmap_data->front() == expected_data;
226 } 369 }
227 370
228 BookmarkModel bookmark_model_; 371 BookmarkModel bookmark_model_;
229 372
230 protected: 373 protected:
231 bool loaded_; 374 bool loaded_;
232 375
233 private: 376 private:
234 friend class HistoryBackendTestDelegate; 377 friend class HistoryBackendTestDelegate;
235 378
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 EXPECT_TRUE(out_favicon1); 576 EXPECT_TRUE(out_favicon1);
434 577
435 std::vector<FaviconBitmap> favicon_bitmaps; 578 std::vector<FaviconBitmap> favicon_bitmaps;
436 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( 579 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(
437 out_favicon1, &favicon_bitmaps)); 580 out_favicon1, &favicon_bitmaps));
438 ASSERT_EQ(2u, favicon_bitmaps.size()); 581 ASSERT_EQ(2u, favicon_bitmaps.size());
439 582
440 FaviconBitmap favicon_bitmap1 = favicon_bitmaps[0]; 583 FaviconBitmap favicon_bitmap1 = favicon_bitmaps[0];
441 FaviconBitmap favicon_bitmap2 = favicon_bitmaps[1]; 584 FaviconBitmap favicon_bitmap2 = favicon_bitmaps[1];
442 585
443 // Bitmaps do not need to be in particular order. 586 // Favicon bitmaps do not need to be in particular order.
444 if (favicon_bitmap1.pixel_size == kLargeSize) { 587 if (favicon_bitmap1.pixel_size == kLargeSize) {
445 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; 588 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1;
446 favicon_bitmap1 = favicon_bitmap2; 589 favicon_bitmap1 = favicon_bitmap2;
447 favicon_bitmap2 = tmp_favicon_bitmap; 590 favicon_bitmap2 = tmp_favicon_bitmap;
448 } 591 }
449 592
450 EXPECT_EQ('a', *favicon_bitmap1.bitmap_data->front()); 593 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap1.bitmap_data));
451 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size); 594 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size);
452 595
453 EXPECT_EQ('b', *favicon_bitmap2.bitmap_data->front()); 596 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmap2.bitmap_data));
454 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size); 597 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size);
455 598
456 FaviconID out_favicon2 = backend_->thumbnail_db_-> 599 FaviconID out_favicon2 = backend_->thumbnail_db_->
457 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL); 600 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL);
458 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; 601 EXPECT_FALSE(out_favicon2) << "Favicon not deleted";
459 602
460 // The remaining URL should still reference the same favicon, even if its 603 // The remaining URL should still reference the same favicon, even if its
461 // ID has changed. 604 // ID has changed.
462 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); 605 std::vector<IconMapping> mappings;
606 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
607 outrow1.url(), FAVICON, &mappings));
608 EXPECT_EQ(1u, mappings.size());
609 EXPECT_EQ(out_favicon1, mappings[0].icon_id);
463 610
464 // The first URL should still be bookmarked. 611 // The first URL should still be bookmarked.
465 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); 612 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url()));
466 613
467 // The full text database should have no data. 614 // The full text database should have no data.
468 std::vector<TextDatabase::Match> text_matches; 615 std::vector<TextDatabase::Match> text_matches;
469 Time first_time_searched; 616 Time first_time_searched;
470 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), 617 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"),
471 QueryOptions(), 618 QueryOptions(),
472 &text_matches, 619 &text_matches,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 URLRow row2(GURL("http://news.google.com/")); 879 URLRow row2(GURL("http://news.google.com/"));
733 row2.set_visit_count(1); 880 row2.set_visit_count(1);
734 row2.set_last_visit(Time::Now()); 881 row2.set_last_visit(Time::Now());
735 URLRows rows; 882 URLRows rows;
736 rows.push_back(row1); 883 rows.push_back(row1);
737 rows.push_back(row2); 884 rows.push_back(row2);
738 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); 885 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
739 URLRow url_row1, url_row2; 886 URLRow url_row1, url_row2;
740 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); 887 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0);
741 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); 888 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0);
742 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); 889 EXPECT_EQ(1u, NumIconMappingsForPageURL(row1.url(), FAVICON));
743 EXPECT_TRUE(GetFavicon(row2.url(), FAVICON) == 0); 890 EXPECT_EQ(0u, NumIconMappingsForPageURL(row2.url(), FAVICON));
744 891
745 // Now provide one imported favicon for both URLs already in the registry. 892 // Now provide one imported favicon for both URLs already in the registry.
746 // The new favicon should only be used with the URL that doesn't already have 893 // The new favicon should only be used with the URL that doesn't already have
747 // a favicon. 894 // a favicon.
748 std::vector<history::ImportedFaviconUsage> favicons; 895 std::vector<history::ImportedFaviconUsage> favicons;
749 history::ImportedFaviconUsage favicon; 896 history::ImportedFaviconUsage favicon;
750 favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); 897 favicon.favicon_url = GURL("http://news.google.com/favicon.ico");
751 favicon.png_data.push_back('2'); 898 favicon.png_data.push_back('2');
752 favicon.urls.insert(row1.url()); 899 favicon.urls.insert(row1.url());
753 favicon.urls.insert(row2.url()); 900 favicon.urls.insert(row2.url());
754 favicons.push_back(favicon); 901 favicons.push_back(favicon);
755 backend_->SetImportedFavicons(favicons); 902 backend_->SetImportedFavicons(favicons);
756 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); 903 EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0);
757 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); 904 EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0);
758 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 0); 905
759 EXPECT_FALSE(GetFavicon(row2.url(), FAVICON) == 0); 906 std::vector<IconMapping> mappings;
760 EXPECT_FALSE(GetFavicon(row1.url(), FAVICON) == 907 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
761 GetFavicon(row2.url(), FAVICON)); 908 row1.url(), FAVICON, &mappings));
909 EXPECT_EQ(1u, mappings.size());
910 EXPECT_EQ(favicon1, mappings[0].icon_id);
911 EXPECT_EQ(favicon_url1, mappings[0].icon_url);
912
913 mappings.clear();
914 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
915 row2.url(), FAVICON, &mappings));
916 EXPECT_EQ(1u, mappings.size());
917 EXPECT_EQ(favicon.favicon_url, mappings[0].icon_url);
762 918
763 // A URL should not be added to history (to store favicon), if 919 // A URL should not be added to history (to store favicon), if
764 // the URL is not bookmarked. 920 // the URL is not bookmarked.
765 GURL url3("http://mail.google.com"); 921 GURL url3("http://mail.google.com");
766 favicons.clear(); 922 favicons.clear();
767 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); 923 favicon.favicon_url = GURL("http://mail.google.com/favicon.ico");
768 favicon.png_data.push_back('3'); 924 favicon.png_data.push_back('3');
769 favicon.urls.insert(url3); 925 favicon.urls.insert(url3);
770 favicons.push_back(favicon); 926 favicons.push_back(favicon);
771 backend_->SetImportedFavicons(favicons); 927 backend_->SetImportedFavicons(favicons);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 EXPECT_EQ(cur_version, file_version); 1264 EXPECT_EQ(cur_version, file_version);
1109 1265
1110 // Check visit_source table is created and empty. 1266 // Check visit_source table is created and empty.
1111 s.Assign(db.GetUniqueStatement( 1267 s.Assign(db.GetUniqueStatement(
1112 "SELECT name FROM sqlite_master WHERE name=\"visit_source\"")); 1268 "SELECT name FROM sqlite_master WHERE name=\"visit_source\""));
1113 ASSERT_TRUE(s.Step()); 1269 ASSERT_TRUE(s.Step());
1114 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10")); 1270 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10"));
1115 EXPECT_FALSE(s.Step()); 1271 EXPECT_FALSE(s.Step());
1116 } 1272 }
1117 1273
1118 TEST_F(HistoryBackendTest, SetFaviconMapping) { 1274 // Test that SetFaviconMappingsForPageAndRedirects correctly updates icon
1275 // mappings based on redirects, icon URLs and icon types.
1276 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageAndRedirects) {
1119 // Init recent_redirects_ 1277 // Init recent_redirects_
1120 const GURL url1("http://www.google.com"); 1278 const GURL url1("http://www.google.com");
1121 const GURL url2("http://www.google.com/m"); 1279 const GURL url2("http://www.google.com/m");
1122 URLRow url_info1(url1); 1280 URLRow url_info1(url1);
1123 url_info1.set_visit_count(0); 1281 url_info1.set_visit_count(0);
1124 url_info1.set_typed_count(0); 1282 url_info1.set_typed_count(0);
1125 url_info1.set_last_visit(base::Time()); 1283 url_info1.set_last_visit(base::Time());
1126 url_info1.set_hidden(false); 1284 url_info1.set_hidden(false);
1127 backend_->db_->AddURL(url_info1); 1285 backend_->db_->AddURL(url_info1);
1128 1286
1129 URLRow url_info2(url2); 1287 URLRow url_info2(url2);
1130 url_info2.set_visit_count(0); 1288 url_info2.set_visit_count(0);
1131 url_info2.set_typed_count(0); 1289 url_info2.set_typed_count(0);
1132 url_info2.set_last_visit(base::Time()); 1290 url_info2.set_last_visit(base::Time());
1133 url_info2.set_hidden(false); 1291 url_info2.set_hidden(false);
1134 backend_->db_->AddURL(url_info2); 1292 backend_->db_->AddURL(url_info2);
1135 1293
1136 history::RedirectList redirects; 1294 history::RedirectList redirects;
1137 redirects.push_back(url2); 1295 redirects.push_back(url2);
1138 redirects.push_back(url1); 1296 redirects.push_back(url1);
1139 backend_->recent_redirects_.Put(url1, redirects); 1297 backend_->recent_redirects_.Put(url1, redirects);
1140 1298
1141 const GURL icon_url("http://www.google.com/icon"); 1299 const GURL icon_url1("http://www.google.com/icon");
1142 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); 1300 const GURL icon_url2("http://www.google.com/icon2");
1143 // Add a favicon 1301
1144 backend_->SetFavicon( 1302 // Create mapping for a page with two favicons.
1145 url1, icon_url, base::RefCountedBytes::TakeVector(&data), FAVICON); 1303 IconURLSizesMap two_icon_url_sizes;
1146 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1304 two_icon_url_sizes[icon_url1] = GetSizesSmallAndLarge();
1147 url1, FAVICON, NULL)); 1305 two_icon_url_sizes[icon_url2] = GetSizesSmallAndLarge();
1148 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1306
1149 url2, FAVICON, NULL)); 1307 // Create a mapping for a page with a single favicon.
1150 1308 IconURLSizesMap one_icon_url_sizes;
1151 // Add a touch_icon 1309 one_icon_url_sizes[icon_url1] = GetSizesSmallAndLarge();
1152 backend_->SetFavicon( 1310
1153 url1, icon_url, base::RefCountedBytes::TakeVector(&data), TOUCH_ICON); 1311 std::vector<FaviconBitmapData> favicon_bitmap_data;
1154 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1312
1155 url1, TOUCH_ICON, NULL)); 1313 // Add two favicons
1156 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1314 backend_->SetFavicons(url1, FAVICON, favicon_bitmap_data,
1157 url2, TOUCH_ICON, NULL)); 1315 two_icon_url_sizes);
1158 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1316 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON));
1159 url1, FAVICON, NULL)); 1317 EXPECT_EQ(2u, NumIconMappingsForPageURL(url2, FAVICON));
1160 1318
1161 // Add a TOUCH_PRECOMPOSED_ICON 1319 // Add one touch_icon
1162 backend_->SetFavicon(url1, 1320 backend_->SetFavicons(url1, TOUCH_ICON, favicon_bitmap_data,
1163 icon_url, 1321 one_icon_url_sizes);
1164 base::RefCountedBytes::TakeVector(&data), 1322 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON));
1165 TOUCH_PRECOMPOSED_ICON); 1323 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, TOUCH_ICON));
1324 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON));
1325
1326 // Add one TOUCH_PRECOMPOSED_ICON
1327 backend_->SetFavicons(url1, TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data,
1328 one_icon_url_sizes);
1166 // The touch_icon was replaced. 1329 // The touch_icon was replaced.
1167 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1330 EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, TOUCH_ICON));
1168 url1, TOUCH_ICON, NULL)); 1331 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON));
1169 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1332 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_PRECOMPOSED_ICON));
1170 url1, FAVICON, NULL)); 1333 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, TOUCH_PRECOMPOSED_ICON));
1171 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1334
1172 url1, TOUCH_PRECOMPOSED_ICON, NULL)); 1335 // Add a touch_icon.
1173 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1336 backend_->SetFavicons(url1, TOUCH_ICON, favicon_bitmap_data,
1174 url2, TOUCH_PRECOMPOSED_ICON, NULL)); 1337 one_icon_url_sizes);
1175 1338 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON));
1176 // Add a touch_icon 1339 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON));
1177 backend_->SetFavicon(
1178 url1, icon_url, base::RefCountedBytes::TakeVector(&data), TOUCH_ICON);
1179 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1180 url1, TOUCH_ICON, NULL));
1181 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1182 url1, FAVICON, NULL));
1183 // The TOUCH_PRECOMPOSED_ICON was replaced. 1340 // The TOUCH_PRECOMPOSED_ICON was replaced.
1184 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1341 EXPECT_EQ(0u, NumIconMappingsForPageURL(url1, TOUCH_PRECOMPOSED_ICON));
1185 url1, TOUCH_PRECOMPOSED_ICON, NULL)); 1342
1186 1343 // Add a single favicon.
1187 // Add a favicon 1344 backend_->SetFavicons(url1, FAVICON, favicon_bitmap_data,
1188 const GURL icon_url2("http://www.google.com/icon2"); 1345 one_icon_url_sizes);
1189 backend_->SetFavicon( 1346 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON));
1190 url1, icon_url2, base::RefCountedBytes::TakeVector(&data), FAVICON); 1347 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, FAVICON));
1191 FaviconID icon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1348 EXPECT_EQ(1u, NumIconMappingsForPageURL(url2, FAVICON));
1192 icon_url2, FAVICON, NULL); 1349
1193 EXPECT_NE(0, icon_id); 1350 // Add two favicons.
1194 std::vector<IconMapping> icon_mapping; 1351 backend_->SetFavicons(url1, FAVICON, favicon_bitmap_data,
1195 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1352 two_icon_url_sizes);
1196 url1, &icon_mapping)); 1353 EXPECT_EQ(1u, NumIconMappingsForPageURL(url1, TOUCH_ICON));
1197 // The old icon was replaced. 1354 EXPECT_EQ(2u, NumIconMappingsForPageURL(url1, FAVICON));
1198 EXPECT_TRUE(icon_mapping.size() > 1); 1355 }
1199 EXPECT_EQ(icon_id, icon_mapping[1].icon_id); 1356
1200 } 1357 // Test that there is no churn in icon mappings from calling
1201 1358 // SetFavicons() twice with the same |icon_url_sizes| parameter.
1202 TEST_F(HistoryBackendTest, AddOrUpdateIconMapping) { 1359 TEST_F(HistoryBackendTest, SetFaviconMappingsForPageDuplicates) {
1203 // Test the same icon and page mapping will not be added twice. other case
1204 // should be covered in TEST_F(HistoryBackendTest, SetFaviconMapping)
1205 const GURL url("http://www.google.com/"); 1360 const GURL url("http://www.google.com/");
1206 const GURL icon_url("http://www.google.com/icon"); 1361 const GURL icon_url("http://www.google.com/icon");
1207 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); 1362 std::vector<FaviconBitmapData> favicon_bitmap_data;
1208 1363
1209 backend_->SetFavicon( 1364 IconURLSizesMap icon_url_sizes;
1210 url, icon_url, base::RefCountedBytes::TakeVector(&data), FAVICON); 1365 icon_url_sizes[icon_url] = GetSizesSmallAndLarge();
1211 FaviconID icon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1366
1367 backend_->SetFavicons(url, FAVICON, favicon_bitmap_data, icon_url_sizes);
1368
1369 std::vector<IconMapping> icon_mappings;
1370 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1371 url, FAVICON, &icon_mappings));
1372 EXPECT_EQ(1u, icon_mappings.size());
1373 IconMappingID mapping_id = icon_mappings[0].mapping_id;
1374
1375 backend_->SetFavicons(url, FAVICON, favicon_bitmap_data, icon_url_sizes);
1376
1377 icon_mappings.clear();
1378 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1379 url, FAVICON, &icon_mappings));
1380 EXPECT_EQ(1u, icon_mappings.size());
1381
1382 // The same row in the icon_mapping table should be used for the mapping as
1383 // before.
1384 EXPECT_EQ(mapping_id, icon_mappings[0].mapping_id);
1385 }
1386
1387 // Test that setting favicons for a page which already has data does the
1388 // right thing.
1389 TEST_F(HistoryBackendTest, SetFavicons) {
1390 const GURL page_url("http://www.google.com/");
1391 std::vector<FaviconBitmapData> favicon_bitmap_data;
1392 IconURLSizesMap icon_url_sizes;
1393
1394 // Set |page_url| as having two favicons each available from the web at two
1395 // sizes.
1396 const GURL icon_url1("http://www.google.com/icon1");
1397 const GURL icon_url2("http://www.google.com/icon2");
1398
1399 icon_url_sizes[icon_url1] = GetSizesSmallAndLarge();
1400 icon_url_sizes[icon_url2] = GetSizesSmallAndLarge();
1401
1402 // Set only sizes info for the favicons.
1403 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1404 icon_url_sizes);
1405
1406 std::vector<IconMapping> icon_mappings;
1407 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1408 page_url, &icon_mappings));
1409 EXPECT_EQ(2u, icon_mappings.size());
1410 for (size_t i = 0; i < icon_mappings.size(); ++i) {
1411 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmaps(
1412 icon_mappings[i].icon_id, NULL));
1413 }
1414
1415 // Add bitmap data to the favicons.
1416 GenerateFaviconBitmapData(icon_url1,
1417 GetSizesSmall(),
1418 icon_url2,
1419 GetSizesSmallAndLarge(),
1420 &favicon_bitmap_data);
1421
1422 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1423 icon_url_sizes);
1424
1425 icon_mappings.clear();
1426 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
1427 EXPECT_EQ(2u, icon_mappings.size());
1428
1429 GURL icon_url;
1430 IconType icon_type;
1431 FaviconSizes favicon_sizes;
1432 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1433 icon_mappings[0].icon_id, &icon_url, &icon_type, &favicon_sizes));
1434 EXPECT_EQ(icon_url1, icon_url);
1435 EXPECT_EQ(FAVICON, icon_type);
1436 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1437
1438 std::vector<FaviconBitmap> favicon_bitmaps;
1439 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(
1440 icon_mappings[0].icon_id, &favicon_bitmaps));
1441 EXPECT_EQ(1u, favicon_bitmaps.size());
1442 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmaps[0].bitmap_data));
1443 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size);
1444
1445 favicon_sizes.clear();
1446 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1447 icon_mappings[1].icon_id, &icon_url, &icon_type, &favicon_sizes));
1448 EXPECT_EQ(icon_url2, icon_url);
1449 EXPECT_EQ(FAVICON, icon_type);
1450 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1451
1452 favicon_bitmaps.clear();
1453 EXPECT_TRUE(GetSortedFaviconBitmaps(icon_mappings[1].icon_id,
1454 &favicon_bitmaps));
1455
1456 EXPECT_EQ(2u, favicon_bitmaps.size());
1457 EXPECT_TRUE(BitmapDataEqual('b', favicon_bitmaps[0].bitmap_data));
1458 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size);
1459 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[1].bitmap_data));
1460 EXPECT_EQ(kLargeSize, favicon_bitmaps[1].pixel_size);
1461
1462 // Change the sizes for which the favicon at icon_url1 is available at from
1463 // the web. Verify that all the data remains valid.
1464 icon_url_sizes[icon_url1] = GetSizesTinySmallAndLarge();
1465 favicon_bitmap_data.clear();
1466 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1467 icon_url_sizes);
1468
1469 icon_mappings.clear();
1470 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url, &icon_mappings));
1471 EXPECT_EQ(2u, icon_mappings.size());
1472
1473 favicon_sizes.clear();
1474 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1475 icon_mappings[0].icon_id, &icon_url, &icon_type, &favicon_sizes));
1476 EXPECT_EQ(icon_url1, icon_url);
1477 EXPECT_EQ(FAVICON, icon_type);
1478 EXPECT_EQ(GetSizesTinySmallAndLarge(), favicon_sizes);
1479
1480 favicon_bitmaps.clear();
1481 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(
1482 icon_mappings[0].icon_id, &favicon_bitmaps));
1483 EXPECT_EQ(1u, favicon_bitmaps.size());
1484
1485 favicon_sizes.clear();
1486 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconHeader(
1487 icon_mappings[1].icon_id, &icon_url, &icon_type, &favicon_sizes));
1488 EXPECT_EQ(icon_url2, icon_url);
1489 EXPECT_EQ(FAVICON, icon_type);
1490 EXPECT_EQ(GetSizesSmallAndLarge(), favicon_sizes);
1491
1492 favicon_bitmaps.clear();
1493 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(
1494 icon_mappings[1].icon_id, &favicon_bitmaps));
1495 EXPECT_EQ(2u, favicon_bitmaps.size());
1496 }
1497
1498 // Test that changing the sizes that a favicon is available at from the web
1499 // deletes stale favicons and favicon bitmaps.
1500 TEST_F(HistoryBackendTest, SetFaviconsDeleteBitmaps) {
1501 const GURL page_url("http://www.google.com/");
1502 const GURL icon_url("http://www.google.com/icon");
1503
1504 // Set |page_url| as having one favicon with two different sizes.
1505 IconURLSizesMap icon_url_sizes;
1506 icon_url_sizes[icon_url] = GetSizesSmallAndLarge();
1507
1508 std::vector<FaviconBitmapData> favicon_bitmap_data;
1509 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(),
1510 &favicon_bitmap_data);
1511
1512 // Add bitmap data and sizes information to the database.
1513 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1514 icon_url_sizes);
1515
1516 FaviconID favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1212 icon_url, FAVICON, NULL); 1517 icon_url, FAVICON, NULL);
1213 1518 EXPECT_NE(0, favicon_id);
1214 // Add the same mapping 1519
1215 FaviconID replaced; 1520 std::vector<FaviconBitmap> favicon_bitmaps;
1216 EXPECT_FALSE(backend_->AddOrUpdateIconMapping( 1521 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1217 url, icon_id, FAVICON, &replaced)); 1522 &favicon_bitmaps));
1218 EXPECT_EQ(0, replaced); 1523 EXPECT_EQ(2u, favicon_bitmaps.size());
1219 1524
1220 std::vector<IconMapping> icon_mapping; 1525 // Change the bitmap sizes available from the web only to the small size only.
1221 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1526 icon_url_sizes[icon_url] = GetSizesSmall();
1222 url, &icon_mapping)); 1527 favicon_bitmap_data.clear();
1223 EXPECT_EQ(1u, icon_mapping.size()); 1528 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1224 } 1529 icon_url_sizes);
1225 1530
1226 // Test that SetFavicon for a page which shares a FaviconID with another does 1531 favicon_id = backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1227 // the right thing. 1532 icon_url, FAVICON, NULL);
1228 TEST_F(HistoryBackendTest, SetSameFaviconURLForTwoPages) { 1533 EXPECT_NE(0, favicon_id);
1229 GURL favicon_url("http://www.google.com/favicon.ico"); 1534
1535 favicon_bitmaps.clear();
1536 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1537 &favicon_bitmaps));
1538 EXPECT_EQ(1u, favicon_bitmaps.size());
1539 EXPECT_EQ(kSmallSize, favicon_bitmaps[0].pixel_size);
1540
1541 // Clear |icon_url_sizes|. SetFavicons() should delete the remaining favicon
1542 // and its favicon bitmap.
1543 icon_url_sizes.clear();
1544 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data, icon_url_sizes);
1545 EXPECT_EQ(0, backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1546 icon_url, FAVICON, NULL));
1547 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, NULL));
1548 }
1549
1550 // Test updating a single favicon bitmap's data via SetFavicons.
1551 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
1552
1553 const GURL page_url("http://www.google.com/");
1554 const GURL icon_url("http://www.google.com/icon");
1555 IconURLSizesMap icon_url_sizes;
1556 icon_url_sizes[icon_url] = GetSizesSmall();
1557
1558 std::vector<unsigned char> data_initial;
1559 data_initial.push_back('a');
1560
1561 FaviconBitmapData bitmap_data_element;
1562 bitmap_data_element.bitmap_data =
1563 base::RefCountedBytes::TakeVector(&data_initial);
1564 bitmap_data_element.pixel_size = kSmallSize;
1565 bitmap_data_element.icon_url = icon_url;
1566 std::vector<FaviconBitmapData> favicon_bitmap_data;
1567 favicon_bitmap_data.push_back(bitmap_data_element);
1568
1569 // Add bitmap to the database.
1570 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1571 icon_url_sizes);
1572
1573 FaviconBitmap original_favicon_bitmap;
1574 EXPECT_TRUE(GetOnlyFaviconBitmapForIconURL(icon_url, FAVICON,
1575 &original_favicon_bitmap));
1576 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data));
1577
1578 // SetFavicons with identical data but a different bitmap.
1579 std::vector<unsigned char> updated_data;
1580 updated_data.push_back('b');
1581 favicon_bitmap_data[0].bitmap_data =
1582 base::RefCountedBytes::TakeVector(&updated_data);
1583 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1584 icon_url_sizes);
1585
1586 FaviconBitmap updated_favicon_bitmap;
1587 EXPECT_TRUE(GetOnlyFaviconBitmapForIconURL(icon_url, FAVICON,
1588 &updated_favicon_bitmap));
1589 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data));
1590
1591 // There should be no churn in FaviconIDs or FaviconBitmapIds.
1592 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id);
1593 EXPECT_EQ(original_favicon_bitmap.bitmap_id,
1594 updated_favicon_bitmap.bitmap_id);
1595 }
1596
1597 // Test that if two pages share the same FaviconID, changing the favicon for
1598 // one page does not affect the other.
1599 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1600 GURL icon_url("http://www.google.com/favicon.ico");
1601 GURL icon_url_new("http://www.google.com/favicon2.ico");
1230 GURL page_url1("http://www.google.com"); 1602 GURL page_url1("http://www.google.com");
1231 GURL page_url2("http://www.google.ca"); 1603 GURL page_url2("http://www.google.ca");
1232 1604
1233 scoped_refptr<base::RefCountedMemory> bitmap_data( 1605 IconURLSizesMap icon_url_sizes;
1234 new base::RefCountedBytes()); 1606 icon_url_sizes[icon_url] = GetSizesSmallAndLarge();
1235 backend_->SetFavicon(page_url1, favicon_url, bitmap_data, FAVICON); 1607
1608 std::vector<FaviconBitmapData> favicon_bitmap_data;
1609 GenerateFaviconBitmapData(icon_url, GetSizesSmallAndLarge(),
1610 &favicon_bitmap_data);
1611
1612 backend_->SetFavicons(page_url1, FAVICON, favicon_bitmap_data,
1613 icon_url_sizes);
1614
1615 std::vector<GURL> icon_urls;
1616 icon_urls.push_back(icon_url);
1236 1617
1237 scoped_refptr<GetFaviconRequest> request(new GetFaviconRequest( 1618 scoped_refptr<GetFaviconRequest> request(new GetFaviconRequest(
1238 base::Bind(&HistoryBackendTest::OnFaviconResults, 1619 base::Bind(&HistoryBackendTest::OnFaviconResults,
1239 base::Unretained(this)))); 1620 base::Unretained(this))));
1240 HistoryBackendCancelableRequest cancellable_request; 1621 HistoryBackendCancelableRequest cancellable_request;
1241 cancellable_request.MockScheduleOfRequest<GetFaviconRequest>(request); 1622 cancellable_request.MockScheduleOfRequest<GetFaviconRequest>(request);
1242 backend_->UpdateFaviconMappingAndFetch(request, page_url2, favicon_url, 1623 backend_->UpdateFaviconMappingsAndFetch(request, page_url2, icon_urls,
1243 FAVICON); 1624 FAVICON, kSmallSize.width(), GetScaleFactors1x2x());
1244 1625
1245 // Check that the same FaviconID is mapped to both page URLs. 1626 // Check that the same FaviconID is mapped to both page URLs.
1246 std::vector<IconMapping> icon_mappings1; 1627 std::vector<IconMapping> icon_mappings;
1247 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1628 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1248 page_url1, &icon_mappings1)); 1629 page_url1, &icon_mappings));
1249 EXPECT_EQ(1u, icon_mappings1.size()); 1630 EXPECT_EQ(1u, icon_mappings.size());
1250 FaviconID favicon_id = icon_mappings1[0].icon_id; 1631 FaviconID favicon_id = icon_mappings[0].icon_id;
1251 EXPECT_NE(0, favicon_id); 1632 EXPECT_NE(0, favicon_id);
1252 1633
1253 std::vector<IconMapping> icon_mappings2; 1634 icon_mappings.clear();
1254 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1635 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1255 page_url2, &icon_mappings2)); 1636 page_url2, &icon_mappings));
1256 EXPECT_EQ(1u, icon_mappings2.size()); 1637 EXPECT_EQ(1u, icon_mappings.size());
1257 EXPECT_EQ(favicon_id, icon_mappings2[0].icon_id); 1638 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1258 1639
1259 // Update the bitmap data. 1640 // Change the icon URL that |page_url1| is mapped to.
1260 backend_->SetFavicon(page_url1, favicon_url, bitmap_data, FAVICON); 1641 icon_url_sizes.clear();
1261 1642 icon_url_sizes[icon_url_new] = GetSizesSmall();
1262 // |page_url1| and |page_url2| should still map to the same FaviconID 1643 GenerateFaviconBitmapData(icon_url_new, GetSizesSmall(),
1263 // and have valid bitmap data. 1644 &favicon_bitmap_data);
1264 icon_mappings1.clear(); 1645 backend_->SetFavicons(page_url1, FAVICON, favicon_bitmap_data,
1265 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1646 icon_url_sizes);
1266 page_url1, &icon_mappings1)); 1647
1267 EXPECT_EQ(1u, icon_mappings1.size()); 1648 // |page_url1| should map to a new FaviconID and have valid bitmap data.
1268 EXPECT_EQ(favicon_id, icon_mappings1[0].icon_id); 1649 icon_mappings.clear();
1269 1650 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1270 icon_mappings2.clear(); 1651 page_url1, &icon_mappings));
1271 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1652 EXPECT_EQ(1u, icon_mappings.size());
1272 page_url2, &icon_mappings2)); 1653 EXPECT_EQ(icon_url_new, icon_mappings[0].icon_url);
1273 EXPECT_EQ(1u, icon_mappings2.size()); 1654 EXPECT_NE(favicon_id, icon_mappings[0].icon_id);
1274 EXPECT_EQ(favicon_id, icon_mappings2[0].icon_id);
1275 1655
1276 std::vector<FaviconBitmap> favicon_bitmaps; 1656 std::vector<FaviconBitmap> favicon_bitmaps;
1657 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(
1658 icon_mappings[0].icon_id, &favicon_bitmaps));
1659 EXPECT_EQ(1u, favicon_bitmaps.size());
1660
1661 // |page_url2| should still map to the same FaviconID and have valid bitmap
1662 // data.
1663 icon_mappings.clear();
1664 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1665 page_url2, &icon_mappings));
1666 EXPECT_EQ(1u, icon_mappings.size());
1667 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1668
1669 favicon_bitmaps.clear();
1277 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, 1670 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1278 &favicon_bitmaps)); 1671 &favicon_bitmaps));
1279 EXPECT_EQ(1u, favicon_bitmaps.size()); 1672 EXPECT_EQ(2u, favicon_bitmaps.size());
1280 } 1673 }
1281 1674
1282 TEST_F(HistoryBackendTest, GetFaviconForURL) { 1675 // Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
1283 // This test will add a fav icon and touch icon for the same URL 1676 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
1284 // and check the behaviour of backend's GetFaviconForURL implementation. 1677 GURL page_url1("http://www.google.com");
1285 const GURL url("http://www.google.com/"); 1678 GURL page_url2("http://news.google.com");
1286 const GURL icon_url("http://www.google.com/icon"); 1679 GURL page_url3("http://mail.google.com");
1287 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); 1680 GURL icon_urla("http://www.google.com/favicon1.ico");
1288 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); 1681 GURL icon_urlb("http://www.google.com/favicon2.ico");
1289 // Used for testing the icon data after getting from DB 1682 GURL icon_urlc("http://www.google.com/favicon3.ico");
1290 std::string blob_data(bytes->front(), 1683
1291 bytes->front() + bytes->size()); 1684 // |page_url1| is mapped to |icon_urla| which if of type TOUCH_ICON.
1292 1685 IconURLSizesMap icon_url_sizes;
1293 // Add a favicon 1686 icon_url_sizes[icon_urla] = GetSizesSmall();
1294 backend_->SetFavicon( 1687
1295 url, icon_url, bytes.get(), FAVICON); 1688 std::vector<FaviconBitmapData> favicon_bitmap_data;
1296 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1689 GenerateFaviconBitmapData(icon_urla, GetSizesSmall(), &favicon_bitmap_data);
1297 url, FAVICON, NULL)); 1690 backend_->SetFavicons(page_url1, TOUCH_ICON, favicon_bitmap_data,
1298 1691 icon_url_sizes);
1299 // Add a touch_icon 1692
1300 backend_->SetFavicon( 1693 // |page_url2| is mapped to |icon_urlb| and |icon_urlc| which are of type
1301 url, icon_url, bytes.get(), TOUCH_ICON); 1694 // TOUCH_PRECOMPOSED_ICON.
1302 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1695 icon_url_sizes.clear();
1303 url, TOUCH_ICON, NULL)); 1696 icon_url_sizes[icon_urlb] = GetSizesSmall();
1304 1697 icon_url_sizes[icon_urlc] = GetSizesSmall();
1305 // Test the Fav icon for this URL. 1698 GenerateFaviconBitmapData(icon_urlb, GetSizesSmall(), icon_urlc,
1306 std::vector<FaviconBitmapResult> favicon_bitmap_results; 1699 GetSizesSmall(), &favicon_bitmap_data);
1307 ASSERT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, 1700 backend_->SetFavicons(page_url2, TOUCH_PRECOMPOSED_ICON, favicon_bitmap_data,
1308 &favicon_bitmap_results)); 1701 icon_url_sizes);
1309 EXPECT_EQ(1u, favicon_bitmap_results.size()); 1702
1310 FaviconBitmapResult bitmap_result = favicon_bitmap_results[0]; 1703 std::vector<GURL> icon_urls;
1311 std::string favicon_data( 1704 icon_urls.push_back(icon_urla);
1312 bitmap_result.bitmap_data->front(), 1705 icon_urls.push_back(icon_urlb);
1313 bitmap_result.bitmap_data->front() + bitmap_result.bitmap_data->size()); 1706 icon_urls.push_back(icon_urlc);
1314 1707 scoped_refptr<GetFaviconRequest> request(new GetFaviconRequest(
1315 EXPECT_EQ(FAVICON, bitmap_result.icon_type); 1708 base::Bind(&HistoryBackendTest::OnFaviconResults,
1316 EXPECT_EQ(icon_url, bitmap_result.icon_url); 1709 base::Unretained(this))));
1317 EXPECT_EQ(blob_data, favicon_data); 1710 HistoryBackendCancelableRequest cancellable_request;
1318 1711 cancellable_request.MockScheduleOfRequest<GetFaviconRequest>(request);
1319 // Test the touch icon for this URL. 1712 backend_->UpdateFaviconMappingsAndFetch(request, page_url3, icon_urls,
1320 ASSERT_TRUE(backend_->GetFaviconFromDB(url, TOUCH_ICON, 1713 TOUCH_ICON | TOUCH_PRECOMPOSED_ICON, kSmallSize.width(),
1321 &favicon_bitmap_results)); 1714 GetScaleFactors1x2x());
1322 EXPECT_EQ(1u, favicon_bitmap_results.size()); 1715
1323 bitmap_result = favicon_bitmap_results[0]; 1716 // |page_url1| and |page_url2| should still be mapped to the same icon URLs.
1324 std::string touchicon_data( 1717 std::vector<IconMapping> icon_mappings;
1325 bitmap_result.bitmap_data->front(), 1718 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url1,
1326 bitmap_result.bitmap_data->front() + bitmap_result.bitmap_data->size()); 1719 &icon_mappings));
1327 1720 EXPECT_EQ(1u, icon_mappings.size());
1328 EXPECT_EQ(TOUCH_ICON, bitmap_result.icon_type); 1721 EXPECT_EQ(icon_urla, icon_mappings[0].icon_url);
1329 EXPECT_EQ(icon_url, bitmap_result.icon_url); 1722 EXPECT_EQ(TOUCH_ICON, icon_mappings[0].icon_type);
1330 EXPECT_EQ(blob_data, touchicon_data); 1723
1724 icon_mappings.clear();
1725 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url2, &icon_mappings));
1726 EXPECT_EQ(2u, icon_mappings.size());
1727 EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url);
1728 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
1729 EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url);
1730 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
1731
1732 // |page_url3| should be mapped only to |icon_urlb| and |icon_urlc| as
1733 // TOUCH_PRECOMPOSED_ICON is the largest IconType.
1734 icon_mappings.clear();
1735 EXPECT_TRUE(GetSortedIconMappingsForPageURL(page_url3, &icon_mappings));
1736 EXPECT_EQ(2u, icon_mappings.size());
1737 EXPECT_EQ(icon_urlb, icon_mappings[0].icon_url);
1738 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mappings[0].icon_type);
1739 EXPECT_EQ(icon_urlc, icon_mappings[1].icon_url);
1740 EXPECT_EQ(TOUCH_PRECOMPOSED_ICON, icon_mappings[1].icon_type);
1741 }
1742
1743 // Test the results of GetFaviconsFromDB() when there are no found
1744 // favicons.
1745 TEST_F(HistoryBackendTest, GetFaviconsFromDBEmpty) {
1746 const GURL page_url("http://www.google.com/");
1747
1748 std::vector<FaviconBitmapResult> bitmap_results;
1749 IconURLSizesMap icon_url_sizes;
1750 EXPECT_FALSE(backend_->GetFaviconsFromDB(page_url, FAVICON,
1751 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results,
1752 &icon_url_sizes));
1753 EXPECT_TRUE(bitmap_results.empty());
1754 EXPECT_TRUE(icon_url_sizes.empty());
1755 }
1756
1757 // Test the results of GetFaviconsFromDB() when there are matching favicons
1758 // but there are no associated favicon bitmaps.
1759 TEST_F(HistoryBackendTest, GetFaviconsFromDBNoFaviconBitmaps) {
1760 const GURL page_url("http://www.google.com/");
1761 const GURL icon_url("http://www.google.com/icon1");
1762
1763 IconURLSizesMap icon_url_sizes;
1764 icon_url_sizes[icon_url] = GetSizesSmallAndLarge();
1765
1766 // No favicon bitmaps.
1767 std::vector<FaviconBitmapData> favicon_bitmap_data;
1768
1769 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1770 icon_url_sizes);
1771
1772 std::vector<FaviconBitmapResult> bitmap_results_out;
1773 IconURLSizesMap icon_url_sizes_out;
1774 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON, kSmallSize.width(),
1775 GetScaleFactors1x2x(), &bitmap_results_out, &icon_url_sizes_out));
1776 EXPECT_TRUE(bitmap_results_out.empty());
1777 EXPECT_EQ(icon_url_sizes, icon_url_sizes_out);
1778 }
1779
1780 // Test that GetFaviconsFromDB() returns results for the bitmaps which most
1781 // closely match the passed in desired size and scale factors.
1782 TEST_F(HistoryBackendTest, GetFaviconsFromDBSelectClosestMatch) {
1783 const GURL page_url("http://www.google.com/");
1784
1785 const GURL icon_url("http://www.google.com/icon1");
1786 IconURLSizesMap icon_url_sizes;
1787 icon_url_sizes[icon_url] = GetSizesTinySmallAndLarge();
1788
1789 std::vector<FaviconBitmapData> favicon_bitmap_data;
1790 GenerateFaviconBitmapData(icon_url, GetSizesTinySmallAndLarge(),
1791 &favicon_bitmap_data);
1792
1793 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1794 icon_url_sizes);
1795
1796 std::vector<FaviconBitmapResult> bitmap_results_out;
1797 IconURLSizesMap icon_url_sizes_out;
1798 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON, kSmallSize.width(),
1799 GetScaleFactors1x2x(), &bitmap_results_out, &icon_url_sizes_out));
1800
1801 // The bitmap data for the 1x and 2x bitmaps should be returned as their sizes
1802 // match exactly.
1803
1804 EXPECT_EQ(2u, bitmap_results_out.size());
1805 // No required order for results.
1806 if (bitmap_results_out[0].pixel_size == kLargeSize) {
1807 FaviconBitmapResult tmp_result = bitmap_results_out[0];
1808 bitmap_results_out[0] = bitmap_results_out[1];
1809 bitmap_results_out[1] = tmp_result;
1810 }
1811
1812 EXPECT_FALSE(bitmap_results_out[0].expired);
1813 EXPECT_TRUE(BitmapDataEqual('b', bitmap_results_out[0].bitmap_data));
1814 EXPECT_EQ(kSmallSize, bitmap_results_out[0].pixel_size);
1815 EXPECT_EQ(icon_url, bitmap_results_out[0].icon_url);
1816 EXPECT_EQ(FAVICON, bitmap_results_out[0].icon_type);
1817
1818 EXPECT_FALSE(bitmap_results_out[1].expired);
1819 EXPECT_TRUE(BitmapDataEqual('c', bitmap_results_out[1].bitmap_data));
1820 EXPECT_EQ(kLargeSize, bitmap_results_out[1].pixel_size);
1821 EXPECT_EQ(icon_url, bitmap_results_out[1].icon_url);
1822 EXPECT_EQ(FAVICON, bitmap_results_out[1].icon_type);
1823
1824 EXPECT_EQ(icon_url_sizes, icon_url_sizes_out);
1825 }
1826
1827 // Test that GetFaviconsFromDB() returns results from the icon URL whose
1828 // bitmaps most closely match the passed in desired size and scale factors.
1829 TEST_F(HistoryBackendTest, GetFaviconsFromDBSingleIconURL) {
1830 const GURL page_url("http://www.google.com/");
1831
1832 const GURL icon_url1("http://www.google.com/icon1");
1833 const GURL icon_url2("http://www.google.com/icon2");
1834 IconURLSizesMap icon_url_sizes;
1835 icon_url_sizes[icon_url1] = GetSizesSmall();
1836 icon_url_sizes[icon_url2] = GetSizesSmallAndLarge();
1837
1838 std::vector<FaviconBitmapData> favicon_bitmap_data;
1839 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), icon_url2,
1840 GetSizesLarge(), &favicon_bitmap_data);
1841
1842 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1843 icon_url_sizes);
1844
1845 std::vector<FaviconBitmapResult> bitmap_results_out;
1846 IconURLSizesMap icon_url_sizes_out;
1847 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON, kSmallSize.width(),
1848 GetScaleFactors1x2x(), &bitmap_results_out, &icon_url_sizes_out));
1849
1850 // The results should have results for the icon URL with the large bitmap as
1851 // downscaling is preferred to upscaling.
1852 EXPECT_EQ(1u, bitmap_results_out.size());
1853 EXPECT_EQ(kLargeSize, bitmap_results_out[0].pixel_size);
1854 EXPECT_EQ(icon_url2, bitmap_results_out[0].icon_url);
1855
1856 EXPECT_EQ(icon_url_sizes, icon_url_sizes_out);
1857 }
1858
1859 // Test the results of GetFaviconsFromDB() when called with different
1860 // |icon_types|.
1861 TEST_F(HistoryBackendTest, GetFaviconsFromDBIconType) {
1862 const GURL page_url("http://www.google.com/");
1863 const GURL icon_url1("http://www.google.com/icon1.png");
1864 const GURL icon_url2("http://www.google.com/icon2.png");
1865
1866 IconURLSizesMap icon_url_sizes;
1867 icon_url_sizes[icon_url1] = GetSizesSmall();
1868
1869 std::vector<FaviconBitmapData> favicon_bitmap_data;
1870 GenerateFaviconBitmapData(icon_url1, GetSizesSmall(), &favicon_bitmap_data);
1871 backend_->SetFavicons(page_url, FAVICON, favicon_bitmap_data,
1872 icon_url_sizes);
1873
1874 IconURLSizesMap touch_icon_url_sizes;
1875 touch_icon_url_sizes[icon_url2] = GetSizesSmall();
1876 GenerateFaviconBitmapData(icon_url2, GetSizesSmall(), &favicon_bitmap_data);
1877 backend_->SetFavicons(page_url, TOUCH_ICON, favicon_bitmap_data,
1878 touch_icon_url_sizes);
1879
1880 std::vector<FaviconBitmapResult> bitmap_results_out;
1881 IconURLSizesMap icon_url_sizes_out;
1882 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON,
1883 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1884 &icon_url_sizes_out));
1885
1886 EXPECT_EQ(1u, bitmap_results_out.size());
1887 EXPECT_EQ(FAVICON, bitmap_results_out[0].icon_type);
1888 EXPECT_EQ(icon_url_sizes, icon_url_sizes_out);
1889
1890 bitmap_results_out.clear();
1891 icon_url_sizes_out.clear();
1892 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, TOUCH_ICON,
1893 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1894 &icon_url_sizes_out));
1895
1896 EXPECT_EQ(1u, bitmap_results_out.size());
1897 EXPECT_EQ(TOUCH_ICON, bitmap_results_out[0].icon_type);
1898 EXPECT_EQ(touch_icon_url_sizes, icon_url_sizes_out);
1899 }
1900
1901 // Test that GetFaviconsFromDB() correctly sets the expired flag for bitmap
1902 // reults.
1903 TEST_F(HistoryBackendTest, GetFaviconsFromDBExpired) {
1904 const GURL page_url("http://www.google.com/");
1905 const GURL icon_url("http://www.google.com/icon.png");
1906
1907 std::vector<unsigned char> data;
1908 data.push_back('a');
1909 scoped_refptr<base::RefCountedBytes> bitmap_data(
1910 base::RefCountedBytes::TakeVector(&data));
1911 base::Time last_updated = base::Time::FromTimeT(0);
1912 FaviconID icon_id = backend_->thumbnail_db_->AddFavicon(icon_url, FAVICON,
1913 GetSizesSmallAndLarge(), bitmap_data, last_updated, kSmallSize);
1914 EXPECT_NE(0, icon_id);
1915 EXPECT_NE(0, backend_->thumbnail_db_->AddIconMapping(page_url, icon_id));
1916
1917 std::vector<FaviconBitmapResult> bitmap_results_out;
1918 IconURLSizesMap icon_url_sizes_out;
1919 EXPECT_TRUE(backend_->GetFaviconsFromDB(page_url, FAVICON,
1920 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1921 &icon_url_sizes_out));
1922
1923 EXPECT_EQ(1u, bitmap_results_out.size());
1924 EXPECT_TRUE(bitmap_results_out[0].expired);
1331 } 1925 }
1332 1926
1333 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) { 1927 TEST_F(HistoryBackendTest, CloneFaviconIsRestrictedToSameDomain) {
1334 const GURL url("http://www.google.com/"); 1928 const GURL url("http://www.google.com/");
1335 const GURL icon_url("http://www.google.com/icon");
1336 const GURL same_domain_url("http://www.google.com/subdir/index.html"); 1929 const GURL same_domain_url("http://www.google.com/subdir/index.html");
1337 const GURL foreign_domain_url("http://www.not-google.com/"); 1930 const GURL foreign_domain_url("http://www.not-google.com/");
1931 const GURL icon_url("http://www.google.com/icon.png");
1338 1932
1339 // Add a favicon 1933 // Add a favicon
1340 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1)); 1934 IconURLSizesMap icon_url_sizes;
1341 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); 1935 icon_url_sizes[icon_url] = GetSizesSmall();
1342 backend_->SetFavicon( 1936
1343 url, icon_url, bytes.get(), FAVICON); 1937 std::vector<FaviconBitmapData> favicon_bitmap_data;
1938 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data);
1939 backend_->SetFavicons(url, FAVICON, favicon_bitmap_data, icon_url_sizes);
1344 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 1940 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
1345 url, FAVICON, NULL)); 1941 url, FAVICON, NULL));
1346 1942
1347 // Validate starting state. 1943 // Validate starting state.
1348 std::vector<FaviconBitmapResult> favicon_bitmap_results; 1944 std::vector<FaviconBitmapResult> bitmap_results_out;
1349 EXPECT_TRUE(backend_->GetFaviconFromDB(url, FAVICON, 1945 IconURLSizesMap icon_url_sizes_out;
1350 &favicon_bitmap_results)); 1946 EXPECT_TRUE(backend_->GetFaviconsFromDB(url, FAVICON,
1351 EXPECT_FALSE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, 1947 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1352 &favicon_bitmap_results)); 1948 &icon_url_sizes_out));
1353 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, FAVICON, 1949 EXPECT_FALSE(backend_->GetFaviconsFromDB(same_domain_url, FAVICON,
1354 &favicon_bitmap_results)); 1950 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1951 &icon_url_sizes_out));
1952 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, FAVICON,
1953 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1954 &icon_url_sizes_out));
1355 1955
1356 // Same-domain cloning should work. 1956 // Same-domain cloning should work.
1357 backend_->CloneFavicon(url, same_domain_url); 1957 backend_->CloneFavicons(url, same_domain_url);
1358 EXPECT_TRUE(backend_->GetFaviconFromDB(same_domain_url, FAVICON, 1958 EXPECT_TRUE(backend_->GetFaviconsFromDB(same_domain_url, FAVICON,
1359 &favicon_bitmap_results)); 1959 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1960 &icon_url_sizes_out));
1360 1961
1361 // Foreign-domain cloning is forbidden. 1962 // Foreign-domain cloning is forbidden.
1362 backend_->CloneFavicon(url, foreign_domain_url); 1963 backend_->CloneFavicons(url, foreign_domain_url);
1363 EXPECT_FALSE(backend_->GetFaviconFromDB(foreign_domain_url, FAVICON, 1964 EXPECT_FALSE(backend_->GetFaviconsFromDB(foreign_domain_url, FAVICON,
1364 &favicon_bitmap_results)); 1965 kSmallSize.width(), GetScaleFactors1x2x(), &bitmap_results_out,
1966 &icon_url_sizes_out));
1365 } 1967 }
1366 1968
1367 TEST_F(HistoryBackendTest, QueryFilteredURLs) { 1969 TEST_F(HistoryBackendTest, QueryFilteredURLs) {
1368 const char* google = "http://www.google.com/"; 1970 const char* google = "http://www.google.com/";
1369 const char* yahoo = "http://www.yahoo.com/"; 1971 const char* yahoo = "http://www.yahoo.com/";
1370 const char* yahoo_sports = "http://sports.yahoo.com/"; 1972 const char* yahoo_sports = "http://sports.yahoo.com/";
1371 const char* yahoo_sports_with_article1 = 1973 const char* yahoo_sports_with_article1 =
1372 "http://sports.yahoo.com/article1.htm"; 1974 "http://sports.yahoo.com/article1.htm";
1373 const char* yahoo_sports_with_article2 = 1975 const char* yahoo_sports_with_article2 =
1374 "http://sports.yahoo.com/article2.htm"; 1976 "http://sports.yahoo.com/article2.htm";
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 2290
1689 backend_->DeleteURL(url); 2291 backend_->DeleteURL(url);
1690 backend_->AddPageNoVisitForBookmark(url, string16()); 2292 backend_->AddPageNoVisitForBookmark(url, string16());
1691 backend_->GetURL(url, &row); 2293 backend_->GetURL(url, &row);
1692 EXPECT_EQ(url, row.url()); 2294 EXPECT_EQ(url, row.url());
1693 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); 2295 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title());
1694 EXPECT_EQ(0, row.visit_count()); 2296 EXPECT_EQ(0, row.visit_count());
1695 } 2297 }
1696 2298
1697 } // namespace history 2299 } // 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