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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "content/public/test/mock_special_storage_policy.h" | 7 #include "content/public/test/mock_special_storage_policy.h" |
8 #include "net/base/net_util.h" | 8 #include "net/base/net_util.h" |
9 #include "storage/browser/quota/usage_tracker.h" | 9 #include "storage/browser/quota/usage_tracker.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 *usage_out = usage; | 40 *usage_out = usage; |
41 } | 41 } |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 class MockQuotaClient : public QuotaClient { | 45 class MockQuotaClient : public QuotaClient { |
46 public: | 46 public: |
47 MockQuotaClient() {} | 47 MockQuotaClient() {} |
48 virtual ~MockQuotaClient() {} | 48 virtual ~MockQuotaClient() {} |
49 | 49 |
50 virtual ID id() const OVERRIDE { | 50 virtual ID id() const override { |
51 return kFileSystem; | 51 return kFileSystem; |
52 } | 52 } |
53 | 53 |
54 virtual void OnQuotaManagerDestroyed() OVERRIDE {} | 54 virtual void OnQuotaManagerDestroyed() override {} |
55 | 55 |
56 virtual void GetOriginUsage(const GURL& origin, | 56 virtual void GetOriginUsage(const GURL& origin, |
57 StorageType type, | 57 StorageType type, |
58 const GetUsageCallback& callback) OVERRIDE { | 58 const GetUsageCallback& callback) override { |
59 EXPECT_EQ(kStorageTypeTemporary, type); | 59 EXPECT_EQ(kStorageTypeTemporary, type); |
60 int64 usage = GetUsage(origin); | 60 int64 usage = GetUsage(origin); |
61 base::MessageLoop::current()->PostTask(FROM_HERE, | 61 base::MessageLoop::current()->PostTask(FROM_HERE, |
62 base::Bind(callback, usage)); | 62 base::Bind(callback, usage)); |
63 } | 63 } |
64 | 64 |
65 virtual void GetOriginsForType(StorageType type, | 65 virtual void GetOriginsForType(StorageType type, |
66 const GetOriginsCallback& callback) OVERRIDE { | 66 const GetOriginsCallback& callback) override { |
67 EXPECT_EQ(kStorageTypeTemporary, type); | 67 EXPECT_EQ(kStorageTypeTemporary, type); |
68 std::set<GURL> origins; | 68 std::set<GURL> origins; |
69 for (UsageMap::const_iterator itr = usage_map_.begin(); | 69 for (UsageMap::const_iterator itr = usage_map_.begin(); |
70 itr != usage_map_.end(); ++itr) { | 70 itr != usage_map_.end(); ++itr) { |
71 origins.insert(itr->first); | 71 origins.insert(itr->first); |
72 } | 72 } |
73 base::MessageLoop::current()->PostTask(FROM_HERE, | 73 base::MessageLoop::current()->PostTask(FROM_HERE, |
74 base::Bind(callback, origins)); | 74 base::Bind(callback, origins)); |
75 } | 75 } |
76 | 76 |
77 virtual void GetOriginsForHost(StorageType type, | 77 virtual void GetOriginsForHost(StorageType type, |
78 const std::string& host, | 78 const std::string& host, |
79 const GetOriginsCallback& callback) OVERRIDE { | 79 const GetOriginsCallback& callback) override { |
80 EXPECT_EQ(kStorageTypeTemporary, type); | 80 EXPECT_EQ(kStorageTypeTemporary, type); |
81 std::set<GURL> origins; | 81 std::set<GURL> origins; |
82 for (UsageMap::const_iterator itr = usage_map_.begin(); | 82 for (UsageMap::const_iterator itr = usage_map_.begin(); |
83 itr != usage_map_.end(); ++itr) { | 83 itr != usage_map_.end(); ++itr) { |
84 if (net::GetHostOrSpecFromURL(itr->first) == host) | 84 if (net::GetHostOrSpecFromURL(itr->first) == host) |
85 origins.insert(itr->first); | 85 origins.insert(itr->first); |
86 } | 86 } |
87 base::MessageLoop::current()->PostTask(FROM_HERE, | 87 base::MessageLoop::current()->PostTask(FROM_HERE, |
88 base::Bind(callback, origins)); | 88 base::Bind(callback, origins)); |
89 } | 89 } |
90 | 90 |
91 virtual void DeleteOriginData(const GURL& origin, | 91 virtual void DeleteOriginData(const GURL& origin, |
92 StorageType type, | 92 StorageType type, |
93 const DeletionCallback& callback) OVERRIDE { | 93 const DeletionCallback& callback) override { |
94 EXPECT_EQ(kStorageTypeTemporary, type); | 94 EXPECT_EQ(kStorageTypeTemporary, type); |
95 usage_map_.erase(origin); | 95 usage_map_.erase(origin); |
96 base::MessageLoop::current()->PostTask( | 96 base::MessageLoop::current()->PostTask( |
97 FROM_HERE, base::Bind(callback, kQuotaStatusOk)); | 97 FROM_HERE, base::Bind(callback, kQuotaStatusOk)); |
98 } | 98 } |
99 | 99 |
100 virtual bool DoesSupport(storage::StorageType type) const OVERRIDE { | 100 virtual bool DoesSupport(storage::StorageType type) const override { |
101 return type == storage::kStorageTypeTemporary; | 101 return type == storage::kStorageTypeTemporary; |
102 } | 102 } |
103 | 103 |
104 int64 GetUsage(const GURL& origin) { | 104 int64 GetUsage(const GURL& origin) { |
105 UsageMap::const_iterator found = usage_map_.find(origin); | 105 UsageMap::const_iterator found = usage_map_.find(origin); |
106 if (found == usage_map_.end()) | 106 if (found == usage_map_.end()) |
107 return 0; | 107 return 0; |
108 return found->second; | 108 return found->second; |
109 } | 109 } |
110 | 110 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 327 |
328 GetGlobalLimitedUsage(&limited_usage); | 328 GetGlobalLimitedUsage(&limited_usage); |
329 GetGlobalUsage(&total_usage, &unlimited_usage); | 329 GetGlobalUsage(&total_usage, &unlimited_usage); |
330 EXPECT_EQ(1 + 16, limited_usage); | 330 EXPECT_EQ(1 + 16, limited_usage); |
331 EXPECT_EQ(1 + 2 + 16 + 32, total_usage); | 331 EXPECT_EQ(1 + 2 + 16 + 32, total_usage); |
332 EXPECT_EQ(2 + 32, unlimited_usage); | 332 EXPECT_EQ(2 + 32, unlimited_usage); |
333 } | 333 } |
334 | 334 |
335 | 335 |
336 } // namespace content | 336 } // namespace content |
OLD | NEW |