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

Side by Side Diff: components/precache/core/precache_database_unittest.cc

Issue 2364873004: Add Precache.CacheStatus.NonPrefetch.FromPrecache. (Closed)
Patch Set: Add const. Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/precache/core/precache_database.h" 5 #include "components/precache/core/precache_database.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 protected: 94 protected:
95 void SetUp() override { 95 void SetUp() override {
96 precache_database_.reset(new PrecacheDatabase()); 96 precache_database_.reset(new PrecacheDatabase());
97 97
98 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 98 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
99 base::FilePath db_path = scoped_temp_dir_.GetPath().Append( 99 base::FilePath db_path = scoped_temp_dir_.GetPath().Append(
100 base::FilePath(FILE_PATH_LITERAL("precache_database"))); 100 base::FilePath(FILE_PATH_LITERAL("precache_database")));
101 ASSERT_TRUE(precache_database_->Init(db_path)); 101 ASSERT_TRUE(precache_database_->Init(db_path));
102 } 102 }
103 103
104 void TearDown() override { precache_url_table()->DeleteAll(); }
105
104 std::map<GURL, base::Time> GetActualURLTableMap() { 106 std::map<GURL, base::Time> GetActualURLTableMap() {
105 // Flush any buffered writes so that the URL table will be up to date. 107 // Flush any buffered writes so that the URL table will be up to date.
106 precache_database_->Flush(); 108 precache_database_->Flush();
107 109
108 std::map<GURL, base::Time> url_table_map; 110 std::map<GURL, base::Time> url_table_map;
109 precache_url_table()->GetAllDataForTesting(&url_table_map); 111 precache_url_table()->GetAllDataForTesting(&url_table_map);
110 return url_table_map; 112 return url_table_map;
111 } 113 }
112 114
113 PrecacheURLTable* precache_url_table() { 115 PrecacheURLTable* precache_url_table() {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 RecordFetchFromNetwork(kURL, kLatency, kFetchTime, kSize); 330 RecordFetchFromNetwork(kURL, kLatency, kFetchTime, kSize);
329 331
330 // The URL table entry should have been deleted. 332 // The URL table entry should have been deleted.
331 EXPECT_TRUE(GetActualURLTableMap().empty()); 333 EXPECT_TRUE(GetActualURLTableMap().empty());
332 334
333 ExpectNewSample("Precache.DownloadedNonPrecache", kSize); 335 ExpectNewSample("Precache.DownloadedNonPrecache", kSize);
334 ExpectNewSample("Precache.Latency.NonPrefetch", kLatency.InMilliseconds()); 336 ExpectNewSample("Precache.Latency.NonPrefetch", kLatency.InMilliseconds());
335 ExpectNewSample("Precache.Latency.NonPrefetch.NonTopHosts", 337 ExpectNewSample("Precache.Latency.NonPrefetch.NonTopHosts",
336 kLatency.InMilliseconds()); 338 kLatency.InMilliseconds());
337 ExpectNewSample("Precache.CacheStatus.NonPrefetch", kFromNetwork); 339 ExpectNewSample("Precache.CacheStatus.NonPrefetch", kFromNetwork);
340 ExpectNewSample("Precache.CacheStatus.NonPrefetch.FromPrecache",
341 kFromNetwork);
338 ExpectNoOtherSamples(); 342 ExpectNoOtherSamples();
339 } 343 }
340 344
341 TEST_F(PrecacheDatabaseTest, FetchFromCacheWithURLTableEntry_NonCellular) { 345 TEST_F(PrecacheDatabaseTest, FetchFromCacheWithURLTableEntry_NonCellular) {
342 precache_url_table()->AddURL(kURL, kReferrerID, true, kOldFetchTime); 346 precache_url_table()->AddURL(kURL, kReferrerID, true, kOldFetchTime);
343 RecordFetchFromCache(kURL, kFetchTime, kSize); 347 RecordFetchFromCache(kURL, kFetchTime, kSize);
344 348
345 // The URL table entry should have been deleted. 349 // The URL table entry should have been deleted.
346 EXPECT_TRUE(GetActualURLTableMap().empty()); 350 EXPECT_TRUE(GetActualURLTableMap().empty());
347 351
348 ExpectNewSample("Precache.Latency.NonPrefetch", 0); 352 ExpectNewSample("Precache.Latency.NonPrefetch", 0);
349 ExpectNewSample("Precache.Latency.NonPrefetch.NonTopHosts", 0); 353 ExpectNewSample("Precache.Latency.NonPrefetch.NonTopHosts", 0);
350 ExpectNewSample("Precache.CacheStatus.NonPrefetch", 354 ExpectNewSample("Precache.CacheStatus.NonPrefetch",
351 HttpResponseInfo::CacheEntryStatus::ENTRY_USED); 355 HttpResponseInfo::CacheEntryStatus::ENTRY_USED);
356 ExpectNewSample("Precache.CacheStatus.NonPrefetch.FromPrecache",
357 HttpResponseInfo::CacheEntryStatus::ENTRY_USED);
352 ExpectNewSample("Precache.Saved", kSize); 358 ExpectNewSample("Precache.Saved", kSize);
353 ExpectNewSample("Precache.Saved.Freshness", kFreshnessBucket10K); 359 ExpectNewSample("Precache.Saved.Freshness", kFreshnessBucket10K);
354 ExpectNoOtherSamples(); 360 ExpectNoOtherSamples();
355 } 361 }
356 362
357 TEST_F(PrecacheDatabaseTest, FetchFromCacheWithURLTableEntry_Cellular) { 363 TEST_F(PrecacheDatabaseTest, FetchFromCacheWithURLTableEntry_Cellular) {
358 precache_url_table()->AddURL(kURL, kReferrerID, true, kOldFetchTime); 364 precache_url_table()->AddURL(kURL, kReferrerID, true, kOldFetchTime);
359 RecordFetchFromCacheCellular(kURL, kFetchTime, kSize); 365 RecordFetchFromCacheCellular(kURL, kFetchTime, kSize);
360 366
361 // The URL table entry should have been deleted. 367 // The URL table entry should have been deleted.
362 EXPECT_TRUE(GetActualURLTableMap().empty()); 368 EXPECT_TRUE(GetActualURLTableMap().empty());
363 369
364 ExpectNewSample("Precache.Latency.NonPrefetch", 0); 370 ExpectNewSample("Precache.Latency.NonPrefetch", 0);
365 ExpectNewSample("Precache.Latency.NonPrefetch.NonTopHosts", 0); 371 ExpectNewSample("Precache.Latency.NonPrefetch.NonTopHosts", 0);
366 ExpectNewSample("Precache.CacheStatus.NonPrefetch", 372 ExpectNewSample("Precache.CacheStatus.NonPrefetch",
367 HttpResponseInfo::CacheEntryStatus::ENTRY_USED); 373 HttpResponseInfo::CacheEntryStatus::ENTRY_USED);
374 ExpectNewSample("Precache.CacheStatus.NonPrefetch.FromPrecache",
375 HttpResponseInfo::CacheEntryStatus::ENTRY_USED);
368 ExpectNewSample("Precache.Saved", kSize); 376 ExpectNewSample("Precache.Saved", kSize);
369 ExpectNewSample("Precache.Saved.Cellular", kSize); 377 ExpectNewSample("Precache.Saved.Cellular", kSize);
370 ExpectNewSample("Precache.Saved.Freshness", kFreshnessBucket10K); 378 ExpectNewSample("Precache.Saved.Freshness", kFreshnessBucket10K);
371 ExpectNoOtherSamples(); 379 ExpectNoOtherSamples();
372 } 380 }
373 381
374 TEST_F(PrecacheDatabaseTest, FetchFromCacheWithoutURLTableEntry) { 382 TEST_F(PrecacheDatabaseTest, FetchFromCacheWithoutURLTableEntry) {
375 RecordFetchFromCache(kURL, kFetchTime, kSize); 383 RecordFetchFromCache(kURL, kFetchTime, kSize);
376 384
377 EXPECT_TRUE(GetActualURLTableMap().empty()); 385 EXPECT_TRUE(GetActualURLTableMap().empty());
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (!resource.is_user_browsed) 639 if (!resource.is_user_browsed)
632 expected_url_table_map[GURL(resource.url)] = kPrecacheTime; 640 expected_url_table_map[GURL(resource.url)] = kPrecacheTime;
633 } 641 }
634 } 642 }
635 EXPECT_EQ(expected_url_table_map, GetActualURLTableMap()); 643 EXPECT_EQ(expected_url_table_map, GetActualURLTableMap());
636 } 644 }
637 645
638 } // namespace 646 } // namespace
639 647
640 } // namespace precache 648 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/core/precache_database.cc ('k') | components/precache/core/precache_url_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698