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

Side by Side Diff: webkit/quota/usage_tracker_unittest.cc

Issue 15950004: [Quota] Wire up limited origin usage retrieving. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test expectation Created 7 years, 6 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 | Annotate | Revision Log
« webkit/quota/usage_tracker.cc ('K') | « webkit/quota/usage_tracker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void UpdateUsage(const GURL& origin, int64 delta) { 129 void UpdateUsage(const GURL& origin, int64 delta) {
130 quota_client_.UpdateUsage(origin, delta); 130 quota_client_.UpdateUsage(origin, delta);
131 usage_tracker_.UpdateUsageCache(quota_client_.id(), origin, delta); 131 usage_tracker_.UpdateUsageCache(quota_client_.id(), origin, delta);
132 message_loop_.RunUntilIdle(); 132 message_loop_.RunUntilIdle();
133 } 133 }
134 134
135 void UpdateUsageWithoutNotification(const GURL& origin, int64 delta) { 135 void UpdateUsageWithoutNotification(const GURL& origin, int64 delta) {
136 quota_client_.UpdateUsage(origin, delta); 136 quota_client_.UpdateUsage(origin, delta);
137 } 137 }
138 138
139 void GetGlobalLimitedUsage(int64* limited_usage) {
140 bool done = false;
141 usage_tracker_.GetGlobalLimitedUsage(base::Bind(
142 &DidGetUsage, &done, limited_usage));
143 message_loop_.RunUntilIdle();
144
145 EXPECT_TRUE(done);
146 }
147
139 void GetGlobalUsage(int64* usage, int64* unlimited_usage) { 148 void GetGlobalUsage(int64* usage, int64* unlimited_usage) {
140 bool done = false; 149 bool done = false;
141 usage_tracker_.GetGlobalUsage(base::Bind( 150 usage_tracker_.GetGlobalUsage(base::Bind(
142 &DidGetGlobalUsage, 151 &DidGetGlobalUsage,
143 &done, usage, unlimited_usage)); 152 &done, usage, unlimited_usage));
144 message_loop_.RunUntilIdle(); 153 message_loop_.RunUntilIdle();
145 154
146 EXPECT_TRUE(done); 155 EXPECT_TRUE(done);
147 } 156 }
148 157
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 GetGlobalUsage(&usage, &unlimited_usage); 263 GetGlobalUsage(&usage, &unlimited_usage);
255 GetHostUsage(host, &host_usage); 264 GetHostUsage(host, &host_usage);
256 EXPECT_EQ(400, usage); 265 EXPECT_EQ(400, usage);
257 EXPECT_EQ(400, unlimited_usage); 266 EXPECT_EQ(400, unlimited_usage);
258 EXPECT_EQ(400, host_usage); 267 EXPECT_EQ(400, host_usage);
259 268
260 RevokeUnlimitedStoragePolicy(origin); 269 RevokeUnlimitedStoragePolicy(origin);
261 GetGlobalUsage(&usage, &unlimited_usage); 270 GetGlobalUsage(&usage, &unlimited_usage);
262 GetHostUsage(host, &host_usage); 271 GetHostUsage(host, &host_usage);
263 EXPECT_EQ(400, usage); 272 EXPECT_EQ(400, usage);
264 EXPECT_EQ(400, unlimited_usage); 273 EXPECT_EQ(0, unlimited_usage);
265 EXPECT_EQ(400, host_usage); 274 EXPECT_EQ(400, host_usage);
266 275
267 SetUsageCacheEnabled(origin, true); 276 SetUsageCacheEnabled(origin, true);
268 UpdateUsage(origin, 100); 277 UpdateUsage(origin, 100);
269 278
270 GetGlobalUsage(&usage, &unlimited_usage); 279 GetGlobalUsage(&usage, &unlimited_usage);
271 GetHostUsage(host, &host_usage); 280 GetHostUsage(host, &host_usage);
272 EXPECT_EQ(500, usage); 281 EXPECT_EQ(500, usage);
273 EXPECT_EQ(0, unlimited_usage); 282 EXPECT_EQ(0, unlimited_usage);
274 EXPECT_EQ(500, host_usage); 283 EXPECT_EQ(500, host_usage);
275 } 284 }
276 285
286 TEST_F(UsageTrackerTest, LimitedGlobalUsageTest) {
287 const GURL kNormal("http://normal");
288 const GURL kUnlimited("http://unlimited");
289 const GURL kNonCached("http://non_cached");
290 const GURL kNonCachedUnlimited("http://non_cached-unlimited");
291
292 GrantUnlimitedStoragePolicy(kUnlimited);
293 GrantUnlimitedStoragePolicy(kNonCachedUnlimited);
294
295 SetUsageCacheEnabled(kNonCached, false);
296 SetUsageCacheEnabled(kNonCachedUnlimited, false);
297
298 UpdateUsageWithoutNotification(kNormal, 1);
299 UpdateUsageWithoutNotification(kUnlimited, 2);
300 UpdateUsageWithoutNotification(kNonCached, 4);
301 UpdateUsageWithoutNotification(kNonCachedUnlimited, 8);
302
303 int64 limited_usage = 0;
304 int64 total_usage = 0;
305 int64 unlimited_usage = 0;
306
307 GetGlobalLimitedUsage(&limited_usage);
308 GetGlobalUsage(&total_usage, &unlimited_usage);
309 EXPECT_EQ(1 + 4, limited_usage);
310 EXPECT_EQ(1 + 2 + 4 + 8, total_usage);
311 EXPECT_EQ(2 + 8, unlimited_usage);
312
313 UpdateUsageWithoutNotification(kNonCached, 16 - 2);
314 UpdateUsageWithoutNotification(kNonCachedUnlimited, 32 - 8);
315
316 GetGlobalLimitedUsage(&limited_usage);
317 GetGlobalUsage(&total_usage, &unlimited_usage);
318 EXPECT_EQ(1 + 16, limited_usage);
319 EXPECT_EQ(1 + 16 + 4 + 32, total_usage);
320 EXPECT_EQ(2 + 32, unlimited_usage);
321 }
322
323
277 } // namespace quota 324 } // namespace quota
OLDNEW
« webkit/quota/usage_tracker.cc ('K') | « webkit/quota/usage_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698