| OLD | NEW |
| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 285 |
| 285 void NotifyStorageAccessed(QuotaClient* client, | 286 void NotifyStorageAccessed(QuotaClient* client, |
| 286 const GURL& origin, | 287 const GURL& origin, |
| 287 StorageType type) { | 288 StorageType type) { |
| 288 DCHECK(client); | 289 DCHECK(client); |
| 289 quota_manager_->NotifyStorageAccessedInternal( | 290 quota_manager_->NotifyStorageAccessedInternal( |
| 290 client->id(), origin, type, IncrementMockTime()); | 291 client->id(), origin, type, IncrementMockTime()); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { | 294 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { |
| 294 quota_manager_->DeleteOriginFromDatabase(origin, type); | 295 quota_manager_->DeleteOriginFromDatabase(origin, type, false); |
| 295 } | 296 } |
| 296 | 297 |
| 297 void GetEvictionOrigin(StorageType type) { | 298 void GetEvictionOrigin(StorageType type) { |
| 298 eviction_origin_ = GURL(); | 299 eviction_origin_ = GURL(); |
| 299 // The quota manager's default eviction policy is to use an LRU eviction | 300 // The quota manager's default eviction policy is to use an LRU eviction |
| 300 // policy. | 301 // policy. |
| 301 quota_manager_->GetEvictionOrigin( | 302 quota_manager_->GetEvictionOrigin( |
| 302 type, 0, base::Bind(&QuotaManagerTest::DidGetEvictionOrigin, | 303 type, 0, base::Bind(&QuotaManagerTest::DidGetEvictionOrigin, |
| 303 weak_factory_.GetWeakPtr())); | 304 weak_factory_.GetWeakPtr())); |
| 304 } | 305 } |
| (...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 | 1352 |
| 1352 GetHostUsage("foo.com", kTemp); | 1353 GetHostUsage("foo.com", kTemp); |
| 1353 base::RunLoop().RunUntilIdle(); | 1354 base::RunLoop().RunUntilIdle(); |
| 1354 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); | 1355 EXPECT_EQ(predelete_host_tmp - (1 + 50000), usage()); |
| 1355 | 1356 |
| 1356 GetHostUsage("foo.com", kPerm); | 1357 GetHostUsage("foo.com", kPerm); |
| 1357 base::RunLoop().RunUntilIdle(); | 1358 base::RunLoop().RunUntilIdle(); |
| 1358 EXPECT_EQ(predelete_host_pers, usage()); | 1359 EXPECT_EQ(predelete_host_pers, usage()); |
| 1359 } | 1360 } |
| 1360 | 1361 |
| 1362 TEST_F(QuotaManagerTest, EvictOriginDataHistogram) { |
| 1363 const GURL kOrigin = GURL("http://foo.com"); |
| 1364 static const MockOriginData kData[] = { |
| 1365 {"http://foo.com/", kTemp, 1}, |
| 1366 }; |
| 1367 |
| 1368 base::HistogramTester histograms; |
| 1369 MockStorageClient* client = |
| 1370 CreateClient(kData, arraysize(kData), QuotaClient::kFileSystem); |
| 1371 RegisterClient(client); |
| 1372 |
| 1373 GetGlobalUsage(kTemp); |
| 1374 base::RunLoop().RunUntilIdle(); |
| 1375 |
| 1376 EvictOriginData(GURL("http://foo.com/"), kTemp); |
| 1377 base::RunLoop().RunUntilIdle(); |
| 1378 |
| 1379 // First eviction has no 'last' time to compare to. |
| 1380 histograms.ExpectTotalCount( |
| 1381 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 0); |
| 1382 |
| 1383 client->AddOriginAndNotify(GURL("http://foo.com"), kTemp, 100); |
| 1384 |
| 1385 GetGlobalUsage(kTemp); |
| 1386 base::RunLoop().RunUntilIdle(); |
| 1387 |
| 1388 EvictOriginData(GURL("http://foo.com/"), kTemp); |
| 1389 base::RunLoop().RunUntilIdle(); |
| 1390 |
| 1391 // Second eviction should log a histogram sample. |
| 1392 histograms.ExpectTotalCount( |
| 1393 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1); |
| 1394 |
| 1395 client->AddOriginAndNotify(GURL("http://foo.com"), kTemp, 100); |
| 1396 |
| 1397 GetGlobalUsage(kTemp); |
| 1398 base::RunLoop().RunUntilIdle(); |
| 1399 |
| 1400 DeleteOriginFromDatabase(GURL("http://foo.com"), kTemp); |
| 1401 |
| 1402 // Deletion from non-eviction source should not log a histogram sample. |
| 1403 histograms.ExpectTotalCount( |
| 1404 QuotaManager::kTimeBetweenRepeatedOriginEvictionsHistogram, 1); |
| 1405 } |
| 1406 |
| 1361 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { | 1407 TEST_F(QuotaManagerTest, EvictOriginDataWithDeletionError) { |
| 1362 static const MockOriginData kData[] = { | 1408 static const MockOriginData kData[] = { |
| 1363 { "http://foo.com/", kTemp, 1 }, | 1409 { "http://foo.com/", kTemp, 1 }, |
| 1364 { "http://foo.com:1/", kTemp, 20 }, | 1410 { "http://foo.com:1/", kTemp, 20 }, |
| 1365 { "http://foo.com/", kPerm, 300 }, | 1411 { "http://foo.com/", kPerm, 300 }, |
| 1366 { "http://bar.com/", kTemp, 4000 }, | 1412 { "http://bar.com/", kTemp, 4000 }, |
| 1367 }; | 1413 }; |
| 1368 static const int kNumberOfTemporaryOrigins = 3; | 1414 static const int kNumberOfTemporaryOrigins = 3; |
| 1369 MockStorageClient* client = CreateClient(kData, arraysize(kData), | 1415 MockStorageClient* client = CreateClient(kData, arraysize(kData), |
| 1370 QuotaClient::kFileSystem); | 1416 QuotaClient::kFileSystem); |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2204 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2250 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2205 | 2251 |
| 2206 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2252 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
| 2207 base::RunLoop().RunUntilIdle(); | 2253 base::RunLoop().RunUntilIdle(); |
| 2208 EXPECT_EQ(kQuotaStatusOk, status()); | 2254 EXPECT_EQ(kQuotaStatusOk, status()); |
| 2209 EXPECT_EQ(10, usage()); | 2255 EXPECT_EQ(10, usage()); |
| 2210 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2256 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2211 } | 2257 } |
| 2212 | 2258 |
| 2213 } // namespace content | 2259 } // namespace content |
| OLD | NEW |