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

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

Issue 1403673002: Add Quota.TimeSinceOriginEvicted UMA histogram. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 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 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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/sys_info.h" 17 #include "base/sys_info.h"
18 #include "base/test/histogram_tester.h"
18 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 #include "content/public/test/mock_special_storage_policy.h" 21 #include "content/public/test/mock_special_storage_policy.h"
21 #include "content/public/test/mock_storage_client.h" 22 #include "content/public/test/mock_storage_client.h"
22 #include "storage/browser/quota/quota_database.h" 23 #include "storage/browser/quota/quota_database.h"
23 #include "storage/browser/quota/quota_manager.h" 24 #include "storage/browser/quota/quota_manager.h"
24 #include "storage/browser/quota/quota_manager_proxy.h" 25 #include "storage/browser/quota/quota_manager_proxy.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 268
268 void NotifyStorageAccessed(QuotaClient* client, 269 void NotifyStorageAccessed(QuotaClient* client,
269 const GURL& origin, 270 const GURL& origin,
270 StorageType type) { 271 StorageType type) {
271 DCHECK(client); 272 DCHECK(client);
272 quota_manager_->NotifyStorageAccessedInternal( 273 quota_manager_->NotifyStorageAccessedInternal(
273 client->id(), origin, type, IncrementMockTime()); 274 client->id(), origin, type, IncrementMockTime());
274 } 275 }
275 276
276 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { 277 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) {
277 quota_manager_->DeleteOriginFromDatabase(origin, type); 278 quota_manager_->DeleteOriginFromDatabase(origin, type, false);
278 } 279 }
279 280
280 void GetLRUOrigin(StorageType type) { 281 void GetLRUOrigin(StorageType type) {
281 lru_origin_ = GURL(); 282 lru_origin_ = GURL();
282 quota_manager_->GetLRUOrigin( 283 quota_manager_->GetLRUOrigin(
283 type, 284 type,
284 base::Bind(&QuotaManagerTest::DidGetLRUOrigin, 285 base::Bind(&QuotaManagerTest::DidGetLRUOrigin,
285 weak_factory_.GetWeakPtr())); 286 weak_factory_.GetWeakPtr()));
286 } 287 }
287 288
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 1325
1325 GetHostUsage("foo.com", kTemp); 1326 GetHostUsage("foo.com", kTemp);
1326 base::RunLoop().RunUntilIdle(); 1327 base::RunLoop().RunUntilIdle();
1327 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); 1328 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage());
1328 1329
1329 GetHostUsage("foo.com", kPerm); 1330 GetHostUsage("foo.com", kPerm);
1330 base::RunLoop().RunUntilIdle(); 1331 base::RunLoop().RunUntilIdle();
1331 EXPECT_EQ(predelete_host_pers, usage()); 1332 EXPECT_EQ(predelete_host_pers, usage());
1332 } 1333 }
1333 1334
1335 TEST_F(QuotaManagerTest, EvictOriginDataHistogram) {
1336 const GURL kOrigin = GURL("http://foo.com");
1337 static const MockOriginData kData[] = {
1338 {"http://foo.com/", kTemp, 1},
1339 };
1340
1341 base::HistogramTester histograms;
1342 MockStorageClient* client =
1343 CreateClient(kData, arraysize(kData), QuotaClient::kFileSystem);
1344 RegisterClient(client);
1345
1346 GetGlobalUsage(kTemp);
1347 base::RunLoop().RunUntilIdle();
1348
1349 EvictOriginData(GURL("http://foo.com/"), kTemp);
1350 base::RunLoop().RunUntilIdle();
1351
1352 // First eviction has no 'last' time to compare to.
1353 histograms.ExpectTotalCount(
1354 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 0);
1355
1356 client->AddOriginAndNotify(GURL("http://foo.com"), kTemp, 100);
1357
1358 GetGlobalUsage(kTemp);
1359 base::RunLoop().RunUntilIdle();
1360
1361 EvictOriginData(GURL("http://foo.com/"), kTemp);
1362 base::RunLoop().RunUntilIdle();
1363
1364 // Second eviction should log a histogram sample.
1365 histograms.ExpectTotalCount(
1366 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1);
1367
1368 client->AddOriginAndNotify(GURL("http://foo.com"), kTemp, 100);
1369
1370 GetGlobalUsage(kTemp);
1371 base::RunLoop().RunUntilIdle();
1372
1373 DeleteOriginFromDatabase(GURL("http://foo.com"), kTemp);
1374
1375 // Deletion from non-eviction source should not log a histogram sample.
1376 histograms.ExpectTotalCount(
1377 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1);
1378 }
1379
1334 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { 1380 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) {
1335 static const MockOriginData kData[] = { 1381 static const MockOriginData kData[] = {
1336 { "http://foo.com/", kTemp, 1 }, 1382 { "http://foo.com/", kTemp, 1 },
1337 { "http://foo.com:1/", kTemp, 20 }, 1383 { "http://foo.com:1/", kTemp, 20 },
1338 { "http://foo.com/", kPerm, 300 }, 1384 { "http://foo.com/", kPerm, 300 },
1339 { "http://bar.com/", kTemp, 4000 }, 1385 { "http://bar.com/", kTemp, 4000 },
1340 }; 1386 };
1341 static const int kNumberOfTemporaryOrigins = 3; 1387 static const int kNumberOfTemporaryOrigins = 3;
1342 MockStorageClient* client = CreateClient(kData, arraysize(kData), 1388 MockStorageClient* client = CreateClient(kData, arraysize(kData),
1343 QuotaClient::kFileSystem); 1389 QuotaClient::kFileSystem);
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2177 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); 2223 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota());
2178 2224
2179 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); 2225 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp);
2180 base::RunLoop().RunUntilIdle(); 2226 base::RunLoop().RunUntilIdle();
2181 EXPECT_EQ(kQuotaStatusOk, status()); 2227 EXPECT_EQ(kQuotaStatusOk, status());
2182 EXPECT_EQ(10, usage()); 2228 EXPECT_EQ(10, usage());
2183 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); 2229 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota());
2184 } 2230 }
2185 2231
2186 } // namespace content 2232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698