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

Side by Side Diff: content/browser/quota/quota_manager_unittest.cc

Issue 1424653002: Add access count and time-since-accessed histograms to temp storage eviction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quota_uma
Patch Set: fix test Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <set> 6 #include <set>
7 #include <sstream> 7 #include <sstream>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 GetHostUsage("foo.com", kTemp); 1354 GetHostUsage("foo.com", kTemp);
1355 base::RunLoop().RunUntilIdle(); 1355 base::RunLoop().RunUntilIdle();
1356 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); 1356 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage());
1357 1357
1358 GetHostUsage("foo.com", kPerm); 1358 GetHostUsage("foo.com", kPerm);
1359 base::RunLoop().RunUntilIdle(); 1359 base::RunLoop().RunUntilIdle();
1360 EXPECT_EQ(predelete_host_pers, usage()); 1360 EXPECT_EQ(predelete_host_pers, usage());
1361 } 1361 }
1362 1362
1363 TEST_F(QuotaManagerTest, EvictOriginDataHistogram) { 1363 TEST_F(QuotaManagerTest, EvictOriginDataHistogram) {
1364 const GURL kOrigin = GURL("http://foo.com"); 1364 const GURL kOrigin = GURL("http://foo.com/");
1365 static const MockOriginData kData[] = { 1365 static const MockOriginData kData[] = {
1366 {"http://foo.com/", kTemp, 1}, 1366 {"http://foo.com/", kTemp, 1},
1367 }; 1367 };
1368 1368
1369 base::HistogramTester histograms; 1369 base::HistogramTester histograms;
1370 MockStorageClient* client = 1370 MockStorageClient* client =
1371 CreateClient(kData, arraysize(kData), QuotaClient::kFileSystem); 1371 CreateClient(kData, arraysize(kData), QuotaClient::kFileSystem);
1372 RegisterClient(client); 1372 RegisterClient(client);
1373 1373
1374 GetGlobalUsage(kTemp); 1374 GetGlobalUsage(kTemp);
1375 base::RunLoop().RunUntilIdle(); 1375 base::RunLoop().RunUntilIdle();
1376 1376
1377 EvictOriginData(GURL("http://foo.com/"), kTemp); 1377 EvictOriginData(kOrigin, kTemp);
1378 base::RunLoop().RunUntilIdle(); 1378 base::RunLoop().RunUntilIdle();
1379 1379
1380 // Ensure used count and time since access are recorded.
1381 histograms.ExpectTotalCount(
1382 QuotaManager::kEvictedOriginAccessedCountHistogram, 1);
1383 histograms.ExpectBucketCount(
1384 QuotaManager::kEvictedOriginAccessedCountHistogram, 0, 1);
1385 histograms.ExpectTotalCount(
1386 QuotaManager::kEvictedOriginTimeSinceAccessHistogram, 1);
1387
1380 // First eviction has no 'last' time to compare to. 1388 // First eviction has no 'last' time to compare to.
1381 histograms.ExpectTotalCount( 1389 histograms.ExpectTotalCount(
1382 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 0); 1390 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 0);
1383 1391
1384 client->AddOriginAndNotify(GURL("http://foo.com"), kTemp, 100); 1392 client->AddOriginAndNotify(kOrigin, kTemp, 100);
1393
1394 // Change the used count of the origin.
1395 quota_manager()->NotifyStorageAccessed(QuotaClient::kUnknown, GURL(kOrigin),
1396 kTemp);
1397 base::RunLoop().RunUntilIdle();
1385 1398
1386 GetGlobalUsage(kTemp); 1399 GetGlobalUsage(kTemp);
1387 base::RunLoop().RunUntilIdle(); 1400 base::RunLoop().RunUntilIdle();
1388 1401
1389 EvictOriginData(GURL("http://foo.com/"), kTemp); 1402 EvictOriginData(kOrigin, kTemp);
1390 base::RunLoop().RunUntilIdle(); 1403 base::RunLoop().RunUntilIdle();
1391 1404
1392 // Second eviction should log a histogram sample. 1405 // The new used count should be logged.
1406 histograms.ExpectTotalCount(
1407 QuotaManager::kEvictedOriginAccessedCountHistogram, 2);
1408 histograms.ExpectBucketCount(
1409 QuotaManager::kEvictedOriginAccessedCountHistogram, 1, 1);
1410 histograms.ExpectTotalCount(
1411 QuotaManager::kEvictedOriginTimeSinceAccessHistogram, 2);
1412
1413 // Second eviction should log a 'time between repeated eviction' sample.
1393 histograms.ExpectTotalCount( 1414 histograms.ExpectTotalCount(
1394 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1); 1415 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1);
1395 1416
1396 client->AddOriginAndNotify(GURL("http://foo.com"), kTemp, 100); 1417 client->AddOriginAndNotify(kOrigin, kTemp, 100);
1397 1418
1398 GetGlobalUsage(kTemp); 1419 GetGlobalUsage(kTemp);
1399 base::RunLoop().RunUntilIdle(); 1420 base::RunLoop().RunUntilIdle();
1400 1421
1401 DeleteOriginFromDatabase(GURL("http://foo.com"), kTemp); 1422 DeleteOriginFromDatabase(kOrigin, kTemp);
1402 1423
1403 // Deletion from non-eviction source should not log a histogram sample. 1424 // Deletion from non-eviction source should not log a histogram sample.
1404 histograms.ExpectTotalCount( 1425 histograms.ExpectTotalCount(
1405 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1); 1426 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1);
1406 } 1427 }
1407 1428
1408 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { 1429 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) {
1409 static const MockOriginData kData[] = { 1430 static const MockOriginData kData[] = {
1410 { "http://foo.com/", kTemp, 1 }, 1431 { "http://foo.com/", kTemp, 1 },
1411 { "http://foo.com:1/", kTemp, 20 }, 1432 { "http://foo.com:1/", kTemp, 20 },
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); 2272 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota());
2252 2273
2253 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 2274 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2254 base::RunLoop().RunUntilIdle(); 2275 base::RunLoop().RunUntilIdle();
2255 EXPECT_EQ(kQuotaStatusOk, status()); 2276 EXPECT_EQ(kQuotaStatusOk, status());
2256 EXPECT_EQ(10, usage()); 2277 EXPECT_EQ(10, usage());
2257 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); 2278 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota());
2258 } 2279 }
2259 2280
2260 } // namespace content 2281 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/quota/quota_database_unittest.cc ('k') | storage/browser/quota/quota_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698