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

Side by Side Diff: components/history/core/browser/history_backend_unittest.cc

Issue 2856873002: [Thumbnails DB] Allow setting last_requested time when accessing favicons. (Closed)
Patch Set: Splitting off clearing Created 3 years, 7 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
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 "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/history_backend.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 page_url2, &icon_mappings)); 2055 page_url2, &icon_mappings));
2056 EXPECT_EQ(1u, icon_mappings.size()); 2056 EXPECT_EQ(1u, icon_mappings.size());
2057 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 2057 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
2058 2058
2059 favicon_bitmaps.clear(); 2059 favicon_bitmaps.clear();
2060 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, 2060 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
2061 &favicon_bitmaps)); 2061 &favicon_bitmaps));
2062 EXPECT_EQ(2u, favicon_bitmaps.size()); 2062 EXPECT_EQ(2u, favicon_bitmaps.size());
2063 } 2063 }
2064 2064
2065 // Tests calling SetLastResortFavicons(). Neither |page_url| nor |icon_url| are 2065 // Tests calling SetOnDemandFavicons(). Neither |page_url| nor |icon_url| are
2066 // known to the database. 2066 // known to the database.
2067 TEST_F(HistoryBackendTest, SetLastResortFaviconsForEmptyDB) { 2067 TEST_F(HistoryBackendTest, SetOnDemandFaviconsForEmptyDB) {
2068 GURL page_url("http://www.google.com"); 2068 GURL page_url("http://www.google.com");
2069 GURL icon_url("http:/www.google.com/favicon.ico"); 2069 GURL icon_url("http:/www.google.com/favicon.ico");
2070 2070
2071 std::vector<SkBitmap> bitmaps; 2071 std::vector<SkBitmap> bitmaps;
2072 bitmaps.push_back(CreateBitmap(SK_ColorRED, kSmallEdgeSize)); 2072 bitmaps.push_back(CreateBitmap(SK_ColorRED, kSmallEdgeSize));
2073 2073
2074 // Call SetLastResortFavicons() with a different icon URL and bitmap data. 2074 // Call SetOnDemandFavicons() with a different icon URL and bitmap data.
2075 EXPECT_TRUE(backend_->SetLastResortFavicons(page_url, favicon_base::FAVICON, 2075 EXPECT_TRUE(backend_->SetOnDemandFavicons(page_url, favicon_base::FAVICON,
2076 icon_url, bitmaps)); 2076 icon_url, bitmaps));
2077 2077
2078 favicon_base::FaviconID favicon_id = 2078 favicon_base::FaviconID favicon_id =
2079 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, 2079 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url,
2080 favicon_base::FAVICON); 2080 favicon_base::FAVICON);
2081 EXPECT_NE(0, favicon_id); 2081 EXPECT_NE(0, favicon_id);
2082 2082
2083 FaviconBitmap favicon_bitmap; 2083 FaviconBitmap favicon_bitmap;
2084 ASSERT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap)); 2084 ASSERT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap));
2085 // The original bitmap should have been retrieved. 2085 // The original bitmap should have been retrieved.
2086 EXPECT_TRUE(BitmapColorEqual(SK_ColorRED, favicon_bitmap.bitmap_data)); 2086 EXPECT_TRUE(BitmapColorEqual(SK_ColorRED, favicon_bitmap.bitmap_data));
2087 // The favicon should not be marked as expired. 2087 // The favicon should not be marked as expired.
2088 EXPECT_EQ(base::Time(), favicon_bitmap.last_updated); 2088 EXPECT_EQ(base::Time(), favicon_bitmap.last_updated);
2089 } 2089 }
2090 2090
2091 // Tests calling SetLastResortFavicons(). |page_url| is known to the database 2091 // Tests calling SetOnDemandFavicons(). |page_url| is known to the database
2092 // but |icon_url| is not (the second should be irrelevant though). 2092 // but |icon_url| is not (the second should be irrelevant though).
2093 TEST_F(HistoryBackendTest, SetLastResortFaviconsForPageInDB) { 2093 TEST_F(HistoryBackendTest, SetOnDemandFaviconsForPageInDB) {
2094 GURL page_url("http://www.google.com"); 2094 GURL page_url("http://www.google.com");
2095 GURL icon_url1("http:/www.google.com/favicon1.ico"); 2095 GURL icon_url1("http:/www.google.com/favicon1.ico");
2096 GURL icon_url2("http:/www.google.com/favicon2.ico"); 2096 GURL icon_url2("http:/www.google.com/favicon2.ico");
2097 std::vector<SkBitmap> bitmaps; 2097 std::vector<SkBitmap> bitmaps;
2098 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); 2098 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
2099 2099
2100 // Add bitmap to the database. 2100 // Add bitmap to the database.
2101 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url1, bitmaps); 2101 backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url1, bitmaps);
2102 favicon_base::FaviconID original_favicon_id = 2102 favicon_base::FaviconID original_favicon_id =
2103 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url1, 2103 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url1,
2104 favicon_base::FAVICON); 2104 favicon_base::FAVICON);
2105 ASSERT_NE(0, original_favicon_id); 2105 ASSERT_NE(0, original_favicon_id);
2106 2106
2107 // Call SetLastResortFavicons() with a different icon URL and bitmap data. 2107 // Call SetOnDemandFavicons() with a different icon URL and bitmap data.
2108 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize); 2108 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize);
2109 EXPECT_FALSE(backend_->SetLastResortFavicons(page_url, favicon_base::FAVICON, 2109 EXPECT_FALSE(backend_->SetOnDemandFavicons(page_url, favicon_base::FAVICON,
2110 icon_url2, bitmaps)); 2110 icon_url2, bitmaps));
2111 EXPECT_EQ(0, backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 2111 EXPECT_EQ(0, backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
2112 icon_url2, favicon_base::FAVICON)); 2112 icon_url2, favicon_base::FAVICON));
2113 2113
2114 FaviconBitmap favicon_bitmap; 2114 FaviconBitmap favicon_bitmap;
2115 ASSERT_TRUE(GetOnlyFaviconBitmap(original_favicon_id, &favicon_bitmap)); 2115 ASSERT_TRUE(GetOnlyFaviconBitmap(original_favicon_id, &favicon_bitmap));
2116 // The original bitmap should have been retrieved. 2116 // The original bitmap should have been retrieved.
2117 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); 2117 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data));
2118 // The favicon should not be marked as expired. 2118 // The favicon should not be marked as expired.
2119 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 2119 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
2120 } 2120 }
2121 2121
2122 // Tests calling SetLastResortFavicons(). |page_url| is not known to the 2122 // Tests calling SetOnDemandFavicons(). |page_url| is not known to the
2123 // database but |icon_url| is. 2123 // database but |icon_url| is.
2124 TEST_F(HistoryBackendTest, SetLastResortFaviconsForIconInDB) { 2124 TEST_F(HistoryBackendTest, SetOnDemandFaviconsForIconInDB) {
2125 const GURL old_page_url("http://www.google.com/old"); 2125 const GURL old_page_url("http://www.google.com/old");
2126 const GURL page_url("http://www.google.com/"); 2126 const GURL page_url("http://www.google.com/");
2127 const GURL icon_url("http://www.google.com/icon"); 2127 const GURL icon_url("http://www.google.com/icon");
2128 std::vector<SkBitmap> bitmaps; 2128 std::vector<SkBitmap> bitmaps;
2129 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize)); 2129 bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
2130 2130
2131 // Add bitmap to the database. 2131 // Add bitmap to the database.
2132 backend_->SetFavicons(old_page_url, favicon_base::FAVICON, icon_url, bitmaps); 2132 backend_->SetFavicons(old_page_url, favicon_base::FAVICON, icon_url, bitmaps);
2133 favicon_base::FaviconID original_favicon_id = 2133 favicon_base::FaviconID original_favicon_id =
2134 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, 2134 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(icon_url,
2135 favicon_base::FAVICON); 2135 favicon_base::FAVICON);
2136 ASSERT_NE(0, original_favicon_id); 2136 ASSERT_NE(0, original_favicon_id);
2137 2137
2138 // Call SetLastResortFavicons() with a different bitmap. 2138 // Call SetOnDemandFavicons() with a different bitmap.
2139 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize); 2139 bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize);
2140 EXPECT_FALSE(backend_->SetLastResortFavicons(page_url, favicon_base::FAVICON, 2140 EXPECT_FALSE(backend_->SetOnDemandFavicons(page_url, favicon_base::FAVICON,
2141 icon_url, bitmaps)); 2141 icon_url, bitmaps));
2142 2142
2143 EXPECT_EQ(original_favicon_id, 2143 EXPECT_EQ(original_favicon_id,
2144 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 2144 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
2145 icon_url, favicon_base::FAVICON)); 2145 icon_url, favicon_base::FAVICON));
2146 2146
2147 FaviconBitmap favicon_bitmap; 2147 FaviconBitmap favicon_bitmap;
2148 ASSERT_TRUE(GetOnlyFaviconBitmap(original_favicon_id, &favicon_bitmap)); 2148 ASSERT_TRUE(GetOnlyFaviconBitmap(original_favicon_id, &favicon_bitmap));
2149 // The original bitmap should have been retrieved. 2149 // The original bitmap should have been retrieved.
2150 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data)); 2150 EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data));
2151 // The favicon should not be marked as expired. 2151 // The favicon should not be marked as expired.
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 backend_->QueryMostVisitedURLs(100, 100, &most_visited); 3881 backend_->QueryMostVisitedURLs(100, 100, &most_visited);
3882 3882
3883 const base::string16 kSomeTitle; // Ignored by equality operator. 3883 const base::string16 kSomeTitle; // Ignored by equality operator.
3884 EXPECT_THAT( 3884 EXPECT_THAT(
3885 most_visited, 3885 most_visited,
3886 ElementsAre(MostVisitedURL(GURL("http://example1.com"), kSomeTitle), 3886 ElementsAre(MostVisitedURL(GURL("http://example1.com"), kSomeTitle),
3887 MostVisitedURL(GURL("http://example5.com"), kSomeTitle))); 3887 MostVisitedURL(GURL("http://example5.com"), kSomeTitle)));
3888 } 3888 }
3889 3889
3890 } // namespace history 3890 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698