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

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

Issue 7839029: QuotaManager::DeleteOriginData now allows deletion of specific QuotaClients (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Back from the dead! Created 8 years, 11 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/quota_manager.cc ('K') | « webkit/quota/quota_manager.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 5 #include <set>
6 #include <sstream> 6 #include <sstream>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
(...skipping 12 matching lines...) Expand all
24 #include "webkit/quota/quota_manager.h" 24 #include "webkit/quota/quota_manager.h"
25 25
26 using base::MessageLoopProxy; 26 using base::MessageLoopProxy;
27 27
28 namespace quota { 28 namespace quota {
29 29
30 // For shorter names. 30 // For shorter names.
31 const StorageType kTemp = kStorageTypeTemporary; 31 const StorageType kTemp = kStorageTypeTemporary;
32 const StorageType kPerm = kStorageTypePersistent; 32 const StorageType kPerm = kStorageTypePersistent;
33 33
34 const int kAllClients = QuotaClient::kAllClientsMask;
35
34 class QuotaManagerTest : public testing::Test { 36 class QuotaManagerTest : public testing::Test {
35 protected: 37 protected:
36 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; 38 typedef QuotaManager::QuotaTableEntry QuotaTableEntry;
37 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; 39 typedef QuotaManager::QuotaTableEntries QuotaTableEntries;
38 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; 40 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries;
39 41
40 public: 42 public:
41 QuotaManagerTest() 43 QuotaManagerTest()
42 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 44 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
43 mock_time_counter_(0) { 45 mock_time_counter_(0) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void EvictOriginData(const GURL& origin, 173 void EvictOriginData(const GURL& origin,
172 StorageType type) { 174 StorageType type) {
173 quota_status_ = kQuotaStatusUnknown; 175 quota_status_ = kQuotaStatusUnknown;
174 quota_manager_->EvictOriginData( 176 quota_manager_->EvictOriginData(
175 origin, type, 177 origin, type,
176 base::Bind(&QuotaManagerTest::StatusCallback, 178 base::Bind(&QuotaManagerTest::StatusCallback,
177 weak_factory_.GetWeakPtr())); 179 weak_factory_.GetWeakPtr()));
178 } 180 }
179 181
180 void DeleteOriginData(const GURL& origin, 182 void DeleteOriginData(const GURL& origin,
181 StorageType type) { 183 StorageType type,
184 int quota_client_mask) {
182 quota_status_ = kQuotaStatusUnknown; 185 quota_status_ = kQuotaStatusUnknown;
183 quota_manager_->DeleteOriginData( 186 quota_manager_->DeleteOriginData(
184 origin, type, 187 origin, type, quota_client_mask,
185 base::Bind(&QuotaManagerTest::StatusCallback, 188 base::Bind(&QuotaManagerTest::StatusCallback,
186 weak_factory_.GetWeakPtr())); 189 weak_factory_.GetWeakPtr()));
187 } 190 }
188 191
189 void DeleteHostData(const std::string& host, 192 void DeleteHostData(const std::string& host,
190 StorageType type) { 193 StorageType type,
194 int quota_client_mask) {
191 quota_status_ = kQuotaStatusUnknown; 195 quota_status_ = kQuotaStatusUnknown;
192 quota_manager_->DeleteHostData( 196 quota_manager_->DeleteHostData(
193 host, type, 197 host, type, quota_client_mask,
194 base::Bind(&QuotaManagerTest::StatusCallback, 198 base::Bind(&QuotaManagerTest::StatusCallback,
195 weak_factory_.GetWeakPtr())); 199 weak_factory_.GetWeakPtr()));
196 } 200 }
197 201
198 void GetAvailableSpace() { 202 void GetAvailableSpace() {
199 quota_status_ = kQuotaStatusUnknown; 203 quota_status_ = kQuotaStatusUnknown;
200 available_space_ = -1; 204 available_space_ = -1;
201 quota_manager_->GetAvailableSpace( 205 quota_manager_->GetAvailableSpace(
202 base::Bind(&QuotaManagerTest::DidGetAvailableSpace, 206 base::Bind(&QuotaManagerTest::DidGetAvailableSpace,
203 weak_factory_.GetWeakPtr())); 207 weak_factory_.GetWeakPtr()));
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 SetTemporaryGlobalQuota(100); 721 SetTemporaryGlobalQuota(100);
718 MessageLoop::current()->RunAllPending(); 722 MessageLoop::current()->RunAllPending();
719 723
720 set_additional_callback_count(0); 724 set_additional_callback_count(0);
721 GetUsageAndQuota(GURL("http://foo.com/"), kTemp); 725 GetUsageAndQuota(GURL("http://foo.com/"), kTemp);
722 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"), 726 RunAdditionalUsageAndQuotaTask(GURL("http://foo.com/"),
723 kTemp); 727 kTemp);
724 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"), 728 RunAdditionalUsageAndQuotaTask(GURL("http://bar.com/"),
725 kTemp); 729 kTemp);
726 730
727 DeleteOriginData(GURL("http://foo.com/"), kTemp); 731 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
728 DeleteOriginData(GURL("http://bar.com/"), kTemp); 732 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients);
729 733
730 // Nuke before waiting for callbacks. 734 // Nuke before waiting for callbacks.
731 set_quota_manager(NULL); 735 set_quota_manager(NULL);
732 MessageLoop::current()->RunAllPending(); 736 MessageLoop::current()->RunAllPending();
733 EXPECT_EQ(kQuotaErrorAbort, status()); 737 EXPECT_EQ(kQuotaErrorAbort, status());
734 } 738 }
735 739
736 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) { 740 TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Overbudget) {
737 static const MockOriginData kData[] = { 741 static const MockOriginData kData[] = {
738 { "http://usage1/", kTemp, 1 }, 742 { "http://usage1/", kTemp, 1 },
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 const int64 predelete_global_tmp = usage(); 1316 const int64 predelete_global_tmp = usage();
1313 1317
1314 GetHostUsage("foo.com", kTemp); 1318 GetHostUsage("foo.com", kTemp);
1315 MessageLoop::current()->RunAllPending(); 1319 MessageLoop::current()->RunAllPending();
1316 int64 predelete_host_tmp = usage(); 1320 int64 predelete_host_tmp = usage();
1317 1321
1318 GetHostUsage("foo.com", kPerm); 1322 GetHostUsage("foo.com", kPerm);
1319 MessageLoop::current()->RunAllPending(); 1323 MessageLoop::current()->RunAllPending();
1320 int64 predelete_host_pers = usage(); 1324 int64 predelete_host_pers = usage();
1321 1325
1322 DeleteHostData("", kTemp); 1326 DeleteHostData("", kTemp, kAllClients);
1323 MessageLoop::current()->RunAllPending(); 1327 MessageLoop::current()->RunAllPending();
1324 EXPECT_EQ(kQuotaStatusOk, status()); 1328 EXPECT_EQ(kQuotaStatusOk, status());
1325 1329
1326 GetGlobalUsage(kTemp); 1330 GetGlobalUsage(kTemp);
1327 MessageLoop::current()->RunAllPending(); 1331 MessageLoop::current()->RunAllPending();
1328 EXPECT_EQ(predelete_global_tmp, usage()); 1332 EXPECT_EQ(predelete_global_tmp, usage());
1329 1333
1330 GetHostUsage("foo.com", kTemp); 1334 GetHostUsage("foo.com", kTemp);
1331 MessageLoop::current()->RunAllPending(); 1335 MessageLoop::current()->RunAllPending();
1332 EXPECT_EQ(predelete_host_tmp, usage()); 1336 EXPECT_EQ(predelete_host_tmp, usage());
1333 1337
1334 GetHostUsage("foo.com", kPerm); 1338 GetHostUsage("foo.com", kPerm);
1335 MessageLoop::current()->RunAllPending(); 1339 MessageLoop::current()->RunAllPending();
1336 EXPECT_EQ(predelete_host_pers, usage()); 1340 EXPECT_EQ(predelete_host_pers, usage());
1337 1341
1338 DeleteHostData("foo.com", kTemp); 1342 DeleteHostData("foo.com", kTemp, kAllClients);
1339 MessageLoop::current()->RunAllPending(); 1343 MessageLoop::current()->RunAllPending();
1340 EXPECT_EQ(kQuotaStatusOk, status()); 1344 EXPECT_EQ(kQuotaStatusOk, status());
1341 1345
1342 GetGlobalUsage(kTemp); 1346 GetGlobalUsage(kTemp);
1343 MessageLoop::current()->RunAllPending(); 1347 MessageLoop::current()->RunAllPending();
1344 EXPECT_EQ(predelete_global_tmp - 1, usage()); 1348 EXPECT_EQ(predelete_global_tmp - 1, usage());
1345 1349
1346 GetHostUsage("foo.com", kTemp); 1350 GetHostUsage("foo.com", kTemp);
1347 MessageLoop::current()->RunAllPending(); 1351 MessageLoop::current()->RunAllPending();
1348 EXPECT_EQ(predelete_host_tmp - 1, usage()); 1352 EXPECT_EQ(predelete_host_tmp - 1, usage());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1389
1386 GetHostUsage("foo.com", kPerm); 1390 GetHostUsage("foo.com", kPerm);
1387 MessageLoop::current()->RunAllPending(); 1391 MessageLoop::current()->RunAllPending();
1388 const int64 predelete_foo_pers = usage(); 1392 const int64 predelete_foo_pers = usage();
1389 1393
1390 GetHostUsage("bar.com", kPerm); 1394 GetHostUsage("bar.com", kPerm);
1391 MessageLoop::current()->RunAllPending(); 1395 MessageLoop::current()->RunAllPending();
1392 const int64 predelete_bar_pers = usage(); 1396 const int64 predelete_bar_pers = usage();
1393 1397
1394 reset_status_callback_count(); 1398 reset_status_callback_count();
1395 DeleteHostData("foo.com", kTemp); 1399 DeleteHostData("foo.com", kTemp, kAllClients);
1396 DeleteHostData("bar.com", kTemp); 1400 DeleteHostData("bar.com", kTemp, kAllClients);
1397 DeleteHostData("foo.com", kTemp); 1401 DeleteHostData("foo.com", kTemp, kAllClients);
1398 MessageLoop::current()->RunAllPending(); 1402 MessageLoop::current()->RunAllPending();
1399 1403
1400 EXPECT_EQ(3, status_callback_count()); 1404 EXPECT_EQ(3, status_callback_count());
1401 1405
1402 DumpOriginInfoTable(); 1406 DumpOriginInfoTable();
1403 MessageLoop::current()->RunAllPending(); 1407 MessageLoop::current()->RunAllPending();
1404 1408
1405 typedef OriginInfoTableEntries::const_iterator iterator; 1409 typedef OriginInfoTableEntries::const_iterator iterator;
1406 for (iterator itr(origin_info_entries().begin()), 1410 for (iterator itr(origin_info_entries().begin()),
1407 end(origin_info_entries().end()); 1411 end(origin_info_entries().end());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 1483
1480 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i) 1484 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData1); ++i)
1481 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart, 1485 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart,
1482 GURL(kData1[i].origin), kData1[i].type); 1486 GURL(kData1[i].origin), kData1[i].type);
1483 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) 1487 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i)
1484 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart, 1488 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart,
1485 GURL(kData2[i].origin), kData2[i].type); 1489 GURL(kData2[i].origin), kData2[i].type);
1486 MessageLoop::current()->RunAllPending(); 1490 MessageLoop::current()->RunAllPending();
1487 1491
1488 reset_status_callback_count(); 1492 reset_status_callback_count();
1489 DeleteOriginData(GURL("http://foo.com/"), kTemp); 1493 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
1490 DeleteOriginData(GURL("http://bar.com/"), kTemp); 1494 DeleteOriginData(GURL("http://bar.com/"), kTemp, kAllClients);
1491 DeleteOriginData(GURL("http://foo.com/"), kTemp); 1495 DeleteOriginData(GURL("http://foo.com/"), kTemp, kAllClients);
1492 MessageLoop::current()->RunAllPending(); 1496 MessageLoop::current()->RunAllPending();
1493 1497
1494 EXPECT_EQ(3, status_callback_count()); 1498 EXPECT_EQ(3, status_callback_count());
1495 1499
1496 DumpOriginInfoTable(); 1500 DumpOriginInfoTable();
1497 MessageLoop::current()->RunAllPending(); 1501 MessageLoop::current()->RunAllPending();
1498 1502
1499 typedef OriginInfoTableEntries::const_iterator iterator; 1503 typedef OriginInfoTableEntries::const_iterator iterator;
1500 for (iterator itr(origin_info_entries().begin()), 1504 for (iterator itr(origin_info_entries().begin()),
1501 end(origin_info_entries().end()); 1505 end(origin_info_entries().end());
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 GetPersistentHostQuota(std::string()); 1794 GetPersistentHostQuota(std::string());
1791 MessageLoop::current()->RunAllPending(); 1795 MessageLoop::current()->RunAllPending();
1792 EXPECT_EQ(kQuotaStatusOk, status()); 1796 EXPECT_EQ(kQuotaStatusOk, status());
1793 EXPECT_EQ(0, quota()); 1797 EXPECT_EQ(0, quota());
1794 1798
1795 SetPersistentHostQuota(std::string(), 10); 1799 SetPersistentHostQuota(std::string(), 10);
1796 MessageLoop::current()->RunAllPending(); 1800 MessageLoop::current()->RunAllPending();
1797 EXPECT_EQ(kQuotaErrorNotSupported, status()); 1801 EXPECT_EQ(kQuotaErrorNotSupported, status());
1798 } 1802 }
1799 } // namespace quota 1803 } // namespace quota
OLDNEW
« webkit/quota/quota_manager.cc ('K') | « webkit/quota/quota_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698