OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 #include <list> | 5 #include <list> |
8 #include <map> | 6 #include <map> |
| 7 #include <utility> |
9 | 8 |
10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
13 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webkit/quota/mock_storage_client.h" | 14 #include "webkit/quota/mock_storage_client.h" |
15 #include "webkit/quota/quota_manager.h" | 15 #include "webkit/quota/quota_manager.h" |
16 #include "webkit/quota/quota_temporary_storage_evictor.h" | 16 #include "webkit/quota/quota_temporary_storage_evictor.h" |
17 | 17 |
18 namespace quota { | 18 namespace quota { |
19 | 19 |
20 class QuotaTemporaryStorageEvictorTest; | 20 class QuotaTemporaryStorageEvictorTest; |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler { | 24 class MockQuotaEvictionHandler : public quota::QuotaEvictionHandler { |
25 public: | 25 public: |
26 MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test) | 26 explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test) |
27 : quota_(0), | 27 : quota_(0), |
28 unlimited_usage_(0), | 28 unlimited_usage_(0), |
29 available_space_(0), | 29 available_space_(0), |
30 error_on_evict_origin_data_(false), | 30 error_on_evict_origin_data_(false), |
31 error_on_get_usage_and_quota_(false), | 31 error_on_get_usage_and_quota_(false), |
32 test_(test) {} | 32 test_(test) {} |
33 | 33 |
34 virtual void EvictOriginData( | 34 virtual void EvictOriginData( |
35 const GURL& origin, | 35 const GURL& origin, |
36 StorageType type, | 36 StorageType type, |
37 EvictOriginDataCallback* callback) OVERRIDE { | 37 EvictOriginDataCallback callback) OVERRIDE { |
38 if (error_on_evict_origin_data_) { | 38 if (error_on_evict_origin_data_) { |
39 callback->Run(quota::kQuotaErrorInvalidModification); | 39 callback.Run(quota::kQuotaErrorInvalidModification); |
40 delete callback; | |
41 return; | 40 return; |
42 } | 41 } |
43 int64 origin_usage = EnsureOriginRemoved(origin); | 42 int64 origin_usage = EnsureOriginRemoved(origin); |
44 if (origin_usage >= 0) | 43 if (origin_usage >= 0) |
45 available_space_ += origin_usage; | 44 available_space_ += origin_usage; |
46 callback->Run(quota::kQuotaStatusOk); | 45 callback.Run(quota::kQuotaStatusOk); |
47 delete callback; | |
48 } | 46 } |
49 | 47 |
50 virtual void GetUsageAndQuotaForEviction( | 48 virtual void GetUsageAndQuotaForEviction( |
51 GetUsageAndQuotaForEvictionCallback* callback) OVERRIDE { | 49 GetUsageAndQuotaForEvictionCallback callback) OVERRIDE { |
52 if (error_on_get_usage_and_quota_) { | 50 if (error_on_get_usage_and_quota_) { |
53 callback->Run(quota::kQuotaErrorInvalidAccess, 0, 0, 0, 0); | 51 callback.Run(quota::kQuotaErrorInvalidAccess, 0, 0, 0, 0); |
54 delete callback; | |
55 return; | 52 return; |
56 } | 53 } |
57 if (task_for_get_usage_and_quota_.get()) | 54 if (task_for_get_usage_and_quota_.get()) |
58 task_for_get_usage_and_quota_->Run(); | 55 task_for_get_usage_and_quota_->Run(); |
59 callback->Run(quota::kQuotaStatusOk, GetUsage(), unlimited_usage_, | 56 callback.Run(quota::kQuotaStatusOk, GetUsage(), unlimited_usage_, |
60 quota_, available_space_); | 57 quota_, available_space_); |
61 delete callback; | |
62 } | 58 } |
63 | 59 |
64 virtual void GetLRUOrigin( | 60 virtual void GetLRUOrigin( |
65 StorageType type, | 61 StorageType type, |
66 GetLRUOriginCallback* callback) OVERRIDE { | 62 GetLRUOriginCallback callback) OVERRIDE { |
67 if (origin_order_.empty()) | 63 if (origin_order_.empty()) |
68 callback->Run(GURL()); | 64 callback.Run(GURL()); |
69 else | 65 else |
70 callback->Run(GURL(origin_order_.front())); | 66 callback.Run(GURL(origin_order_.front())); |
71 delete callback; | |
72 } | 67 } |
73 | 68 |
74 int64 GetUsage() const { | 69 int64 GetUsage() const { |
75 int64 total_usage = 0; | 70 int64 total_usage = 0; |
76 for (std::map<GURL, int64>::const_iterator p = origins_.begin(); | 71 for (std::map<GURL, int64>::const_iterator p = origins_.begin(); |
77 p != origins_.end(); | 72 p != origins_.end(); |
78 ++p) | 73 ++p) |
79 total_usage += p->second; | 74 total_usage += p->second; |
80 return total_usage; | 75 return total_usage; |
81 } | 76 } |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 quota_eviction_handler()->set_available_space(1000000000); | 395 quota_eviction_handler()->set_available_space(1000000000); |
401 EXPECT_EQ(3000 + 200 + 500000, quota_eviction_handler()->GetUsage()); | 396 EXPECT_EQ(3000 + 200 + 500000, quota_eviction_handler()->GetUsage()); |
402 set_repeated_eviction(false); | 397 set_repeated_eviction(false); |
403 temporary_storage_evictor()->Start(); | 398 temporary_storage_evictor()->Start(); |
404 MessageLoop::current()->RunAllPending(); | 399 MessageLoop::current()->RunAllPending(); |
405 // Nothing should have been evicted. | 400 // Nothing should have been evicted. |
406 EXPECT_EQ(3000 + 200 + 500000, quota_eviction_handler()->GetUsage()); | 401 EXPECT_EQ(3000 + 200 + 500000, quota_eviction_handler()->GetUsage()); |
407 } | 402 } |
408 | 403 |
409 } // namespace quota | 404 } // namespace quota |
OLD | NEW |