OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "net/base/net_util.h" | 7 #include "net/base/net_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "webkit/quota/mock_special_storage_policy.h" | 9 #include "webkit/quota/mock_special_storage_policy.h" |
10 #include "webkit/quota/usage_tracker.h" | 10 #include "webkit/quota/usage_tracker.h" |
11 | 11 |
12 namespace quota { | 12 namespace quota { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 void DidGetGlobalUsage(bool* done, | 16 void DidGetGlobalUsage(bool* done, |
17 StorageType* type_out, | |
18 int64* usage_out, | 17 int64* usage_out, |
19 int64* unlimited_usage_out, | 18 int64* unlimited_usage_out, |
20 StorageType type, | |
21 int64 usage, | 19 int64 usage, |
22 int64 unlimited_usage) { | 20 int64 unlimited_usage) { |
23 EXPECT_FALSE(*done); | 21 EXPECT_FALSE(*done); |
24 *done = true; | 22 *done = true; |
25 *type_out = type; | |
26 *usage_out = usage; | 23 *usage_out = usage; |
27 *unlimited_usage_out = unlimited_usage; | 24 *unlimited_usage_out = unlimited_usage; |
28 } | 25 } |
29 | 26 |
30 void DidGetUsage(bool* done, | 27 void DidGetUsage(bool* done, |
31 int64* usage_out, | 28 int64* usage_out, |
32 int64 usage) { | 29 int64 usage) { |
33 EXPECT_FALSE(*done); | 30 EXPECT_FALSE(*done); |
34 *done = true; | 31 *done = true; |
35 *usage_out = usage; | 32 *usage_out = usage; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 usage_tracker_.UpdateUsageCache(quota_client_.id(), origin, delta); | 131 usage_tracker_.UpdateUsageCache(quota_client_.id(), origin, delta); |
135 message_loop_.RunUntilIdle(); | 132 message_loop_.RunUntilIdle(); |
136 } | 133 } |
137 | 134 |
138 void UpdateUsageWithoutNotification(const GURL& origin, int64 delta) { | 135 void UpdateUsageWithoutNotification(const GURL& origin, int64 delta) { |
139 quota_client_.UpdateUsage(origin, delta); | 136 quota_client_.UpdateUsage(origin, delta); |
140 } | 137 } |
141 | 138 |
142 void GetGlobalUsage(int64* usage, int64* unlimited_usage) { | 139 void GetGlobalUsage(int64* usage, int64* unlimited_usage) { |
143 bool done = false; | 140 bool done = false; |
144 StorageType type = kStorageTypeUnknown; | |
145 usage_tracker_.GetGlobalUsage(base::Bind( | 141 usage_tracker_.GetGlobalUsage(base::Bind( |
146 &DidGetGlobalUsage, | 142 &DidGetGlobalUsage, |
147 &done, &type, usage, unlimited_usage)); | 143 &done, usage, unlimited_usage)); |
148 message_loop_.RunUntilIdle(); | 144 message_loop_.RunUntilIdle(); |
149 | 145 |
150 EXPECT_TRUE(done); | 146 EXPECT_TRUE(done); |
151 EXPECT_EQ(kStorageTypeTemporary, type); | |
152 } | 147 } |
153 | 148 |
154 void GetHostUsage(const std::string& host, int64* usage) { | 149 void GetHostUsage(const std::string& host, int64* usage) { |
155 bool done = false; | 150 bool done = false; |
156 usage_tracker_.GetHostUsage(host, base::Bind(&DidGetUsage, &done, usage)); | 151 usage_tracker_.GetHostUsage(host, base::Bind(&DidGetUsage, &done, usage)); |
157 message_loop_.RunUntilIdle(); | 152 message_loop_.RunUntilIdle(); |
158 | 153 |
159 EXPECT_TRUE(done); | 154 EXPECT_TRUE(done); |
160 } | 155 } |
161 | 156 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 UpdateUsage(origin, 100); | 268 UpdateUsage(origin, 100); |
274 | 269 |
275 GetGlobalUsage(&usage, &unlimited_usage); | 270 GetGlobalUsage(&usage, &unlimited_usage); |
276 GetHostUsage(host, &host_usage); | 271 GetHostUsage(host, &host_usage); |
277 EXPECT_EQ(500, usage); | 272 EXPECT_EQ(500, usage); |
278 EXPECT_EQ(0, unlimited_usage); | 273 EXPECT_EQ(0, unlimited_usage); |
279 EXPECT_EQ(500, host_usage); | 274 EXPECT_EQ(500, host_usage); |
280 } | 275 } |
281 | 276 |
282 } // namespace quota | 277 } // namespace quota |
OLD | NEW |