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

Side by Side Diff: components/history/core/browser/thumbnail_database_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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 EXPECT_NE(0, id); 217 EXPECT_NE(0, id);
218 218
219 EXPECT_NE(0, db.AddIconMapping(url, id)); 219 EXPECT_NE(0, db.AddIconMapping(url, id));
220 std::vector<IconMapping> icon_mappings; 220 std::vector<IconMapping> icon_mappings;
221 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings)); 221 EXPECT_TRUE(db.GetIconMappingsForPageURL(url, &icon_mappings));
222 EXPECT_EQ(1u, icon_mappings.size()); 222 EXPECT_EQ(1u, icon_mappings.size());
223 EXPECT_EQ(url, icon_mappings.front().page_url); 223 EXPECT_EQ(url, icon_mappings.front().page_url);
224 EXPECT_EQ(id, icon_mappings.front().icon_id); 224 EXPECT_EQ(id, icon_mappings.front().icon_id);
225 } 225 }
226 226
227 TEST_F(ThumbnailDatabaseTest, LastRequestedTime) { 227 TEST_F(ThumbnailDatabaseTest,
228 AddOnDemandFaviconBitmapCreatesCorrectTimestamps) {
228 ThumbnailDatabase db(NULL); 229 ThumbnailDatabase db(NULL);
229 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 230 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
230 db.BeginTransaction(); 231 db.BeginTransaction();
231 232
233 base::Time time;
234 ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &time));
232 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); 235 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
233 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); 236 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
234 237
235 GURL url("http://google.com"); 238 GURL url("http://google.com");
236 base::Time now = base::Time::Now(); 239 favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON);
237 favicon_base::FaviconID id = 240 ASSERT_NE(0, icon);
238 db.AddFavicon(url, favicon_base::TOUCH_ICON, favicon, now, gfx::Size()); 241 FaviconBitmapID bitmap =
239 ASSERT_NE(0, id); 242 db.AddOnDemandFaviconBitmap(icon, favicon, time, gfx::Size());
243 ASSERT_NE(0, bitmap);
240 244
241 // Fetching the last requested time of a non-existent bitmap should fail. 245 base::Time last_updated;
242 base::Time last_requested = base::Time::UnixEpoch(); 246 base::Time last_requested;
243 EXPECT_FALSE(db.GetFaviconBitmap(id + 1, NULL, &last_requested, NULL, NULL)); 247 ASSERT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested,
244 EXPECT_EQ(last_requested, base::Time::UnixEpoch()); // Remains unchanged. 248 nullptr, nullptr));
249 EXPECT_EQ(base::Time(), last_updated);
250 EXPECT_EQ(time, last_requested);
251 }
245 252
246 // Fetching the last requested time of a bitmap that has no last request 253 TEST_F(ThumbnailDatabaseTest, AddFaviconBitmapCreatesCorrectTimestamps) {
247 // should return a null timestamp. 254 ThumbnailDatabase db(NULL);
248 last_requested = base::Time::UnixEpoch(); 255 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
249 EXPECT_TRUE(db.GetFaviconBitmap(id, NULL, &last_requested, NULL, NULL)); 256 db.BeginTransaction();
250 EXPECT_TRUE(last_requested.is_null());
251 257
252 // Setting the last requested time of an existing bitmap should succeed, and 258 base::Time time;
253 // the set time should be returned by the corresponding "Get". 259 ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &time));
254 last_requested = base::Time::UnixEpoch(); 260 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
255 EXPECT_TRUE(db.SetFaviconBitmapLastRequestedTime(id, now)); 261 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
256 EXPECT_TRUE(db.GetFaviconBitmap(id, NULL, &last_requested, NULL, NULL)); 262
257 EXPECT_EQ(last_requested, now); 263 GURL url("http://google.com");
264 favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON);
265 ASSERT_NE(0, icon);
266 FaviconBitmapID bitmap =
267 db.AddFaviconBitmap(icon, favicon, time, gfx::Size());
268 ASSERT_NE(0, bitmap);
269
270 base::Time last_updated;
271 base::Time last_requested;
272 ASSERT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested,
273 nullptr, nullptr));
274 EXPECT_EQ(time, last_updated);
275 EXPECT_EQ(base::Time(), last_requested);
276 }
277
278 TEST_F(ThumbnailDatabaseTest, TouchUpdatesOnDemandFavicons) {
279 ThumbnailDatabase db(NULL);
280 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
281 db.BeginTransaction();
282
283 base::Time start;
284 ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &start));
285 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
286 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
287
288 // Create an on-demand favicon.
289 GURL url("http://google.com");
290 favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON);
291 ASSERT_NE(0, icon);
292 FaviconBitmapID bitmap =
293 db.AddOnDemandFaviconBitmap(icon, favicon, start, gfx::Size());
294 ASSERT_NE(0, bitmap);
295
296 base::Time end = start + base::TimeDelta::FromDays(14);
297 EXPECT_TRUE(db.TouchOnDemandFavicon(url, end));
298
299 base::Time last_updated;
300 base::Time last_requested;
301 EXPECT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested,
302 nullptr, nullptr));
303 // Does not mess up with the last_updated field.
304 EXPECT_EQ(base::Time(), last_updated);
305 EXPECT_EQ(end, last_requested); // Updates the last_requested field.
306 }
307
308 TEST_F(ThumbnailDatabaseTest, TouchUpdatesOnlyInfrequently) {
309 ThumbnailDatabase db(NULL);
310 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
311 db.BeginTransaction();
312
313 base::Time start;
314 ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &start));
315 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
316 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
317
318 // Create an on-demand favicon.
319 GURL url("http://google.com");
320 favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON);
321 ASSERT_NE(0, icon);
322 FaviconBitmapID bitmap =
323 db.AddOnDemandFaviconBitmap(icon, favicon, start, gfx::Size());
324 ASSERT_NE(0, bitmap);
325
326 base::Time end = start + base::TimeDelta::FromMinutes(1);
327 EXPECT_TRUE(db.TouchOnDemandFavicon(url, end));
328
329 base::Time last_requested;
330 EXPECT_TRUE(
331 db.GetFaviconBitmap(bitmap, nullptr, &last_requested, nullptr, nullptr));
332 EXPECT_EQ(start, last_requested); // No update.
333 }
334
335 TEST_F(ThumbnailDatabaseTest, TouchDoesNotUpdateStandardFavicons) {
336 ThumbnailDatabase db(NULL);
337 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
338 db.BeginTransaction();
339
340 base::Time start;
341 ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &start));
342 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
343 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
344
345 // Create a standard favicon.
346 GURL url("http://google.com");
347 favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON);
348 EXPECT_NE(0, icon);
349 FaviconBitmapID bitmap =
350 db.AddFaviconBitmap(icon, favicon, start, gfx::Size());
351 EXPECT_NE(0, bitmap);
352
353 base::Time end = start + base::TimeDelta::FromDays(14);
354 db.TouchOnDemandFavicon(url, end);
355
356 base::Time last_updated;
357 base::Time last_requested;
358 EXPECT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested,
359 nullptr, nullptr));
360 EXPECT_EQ(start, last_updated); // Does not mess up with last_updates.
361 EXPECT_EQ(base::Time(), last_requested); // No update.
258 } 362 }
259 363
260 TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { 364 TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) {
261 ThumbnailDatabase db(NULL); 365 ThumbnailDatabase db(NULL);
262 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); 366 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
263 db.BeginTransaction(); 367 db.BeginTransaction();
264 368
265 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); 369 std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1));
266 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); 370 scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data));
267 371
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 ThumbnailDatabase db(NULL); 1175 ThumbnailDatabase db(NULL);
1072 ASSERT_EQ(sql::INIT_OK, db.Init(db_path)); 1176 ASSERT_EQ(sql::INIT_OK, db.Init(db_path));
1073 1177
1074 // Verify that the resulting schema is correct, whether it 1178 // Verify that the resulting schema is correct, whether it
1075 // involved razing the file or fixing things in place. 1179 // involved razing the file or fixing things in place.
1076 VerifyTablesAndColumns(&db.db_); 1180 VerifyTablesAndColumns(&db.db_);
1077 } 1181 }
1078 } 1182 }
1079 1183
1080 } // namespace history 1184 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698