| 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 <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_callback_factory.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 14 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 15 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 16 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
| 17 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 18 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 19 #include "base/time.h" | 18 #include "base/time.h" |
| 20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 const StorageType kPerm = kStorageTypePersistent; | 32 const StorageType kPerm = kStorageTypePersistent; |
| 34 | 33 |
| 35 class QuotaManagerTest : public testing::Test { | 34 class QuotaManagerTest : public testing::Test { |
| 36 protected: | 35 protected: |
| 37 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; | 36 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; |
| 38 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; | 37 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; |
| 39 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; | 38 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; |
| 40 | 39 |
| 41 public: | 40 public: |
| 42 QuotaManagerTest() | 41 QuotaManagerTest() |
| 43 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 42 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 44 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
| 45 mock_time_counter_(0) { | 43 mock_time_counter_(0) { |
| 46 } | 44 } |
| 47 | 45 |
| 48 void SetUp() { | 46 void SetUp() { |
| 49 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 47 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 50 mock_special_storage_policy_ = new MockSpecialStoragePolicy; | 48 mock_special_storage_policy_ = new MockSpecialStoragePolicy; |
| 51 quota_manager_ = new QuotaManager( | 49 quota_manager_ = new QuotaManager( |
| 52 false /* is_incognito */, | 50 false /* is_incognito */, |
| 53 data_dir_.path(), | 51 data_dir_.path(), |
| 54 MessageLoopProxy::current(), | 52 MessageLoopProxy::current(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 return new MockStorageClient(quota_manager_->proxy(), | 69 return new MockStorageClient(quota_manager_->proxy(), |
| 72 mock_data, mock_data_size); | 70 mock_data, mock_data_size); |
| 73 } | 71 } |
| 74 | 72 |
| 75 void RegisterClient(MockStorageClient* client) { | 73 void RegisterClient(MockStorageClient* client) { |
| 76 quota_manager_->proxy()->RegisterClient(client); | 74 quota_manager_->proxy()->RegisterClient(client); |
| 77 } | 75 } |
| 78 | 76 |
| 79 void GetUsageInfo() { | 77 void GetUsageInfo() { |
| 80 usage_info_.clear(); | 78 usage_info_.clear(); |
| 81 quota_manager_->GetUsageInfo(callback_factory_.NewCallback( | 79 quota_manager_->GetUsageInfo( |
| 82 &QuotaManagerTest::DidGetUsageInfo)); | 80 base::Bind(&QuotaManagerTest::DidGetUsageInfo, |
| 81 weak_factory_.GetWeakPtr())); |
| 83 } | 82 } |
| 84 | 83 |
| 85 void GetUsageAndQuota(const GURL& origin, StorageType type) { | 84 void GetUsageAndQuota(const GURL& origin, StorageType type) { |
| 86 quota_status_ = kQuotaStatusUnknown; | 85 quota_status_ = kQuotaStatusUnknown; |
| 87 usage_ = -1; | 86 usage_ = -1; |
| 88 quota_ = -1; | 87 quota_ = -1; |
| 89 quota_manager_->GetUsageAndQuota(origin, type, | 88 quota_manager_->GetUsageAndQuota( |
| 90 callback_factory_.NewCallback( | 89 origin, type, |
| 91 &QuotaManagerTest::DidGetUsageAndQuota)); | 90 base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, |
| 91 weak_factory_.GetWeakPtr())); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void GetTemporaryGlobalQuota() { | 94 void GetTemporaryGlobalQuota() { |
| 95 quota_status_ = kQuotaStatusUnknown; | 95 quota_status_ = kQuotaStatusUnknown; |
| 96 quota_ = -1; | 96 quota_ = -1; |
| 97 quota_manager_->GetTemporaryGlobalQuota( | 97 quota_manager_->GetTemporaryGlobalQuota( |
| 98 callback_factory_.NewCallback( | 98 base::Bind(&QuotaManagerTest::DidGetQuota, |
| 99 &QuotaManagerTest::DidGetQuota)); | 99 weak_factory_.GetWeakPtr())); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void SetTemporaryGlobalQuota(int64 new_quota) { | 102 void SetTemporaryGlobalQuota(int64 new_quota) { |
| 103 quota_status_ = kQuotaStatusUnknown; | 103 quota_status_ = kQuotaStatusUnknown; |
| 104 quota_ = -1; | 104 quota_ = -1; |
| 105 quota_manager_->SetTemporaryGlobalOverrideQuota( | 105 quota_manager_->SetTemporaryGlobalOverrideQuota( |
| 106 new_quota, | 106 new_quota, |
| 107 callback_factory_.NewCallback( | 107 base::Bind(&QuotaManagerTest::DidGetQuota, |
| 108 &QuotaManagerTest::DidGetQuota)); | 108 weak_factory_.GetWeakPtr())); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void GetPersistentHostQuota(const std::string& host) { | 111 void GetPersistentHostQuota(const std::string& host) { |
| 112 quota_status_ = kQuotaStatusUnknown; | 112 quota_status_ = kQuotaStatusUnknown; |
| 113 host_.clear(); | 113 host_.clear(); |
| 114 type_ = kStorageTypeUnknown; | 114 type_ = kStorageTypeUnknown; |
| 115 quota_ = -1; | 115 quota_ = -1; |
| 116 quota_manager_->GetPersistentHostQuota(host, | 116 quota_manager_->GetPersistentHostQuota( |
| 117 callback_factory_.NewCallback( | 117 host, |
| 118 &QuotaManagerTest::DidGetHostQuota)); | 118 base::Bind(&QuotaManagerTest::DidGetHostQuota, |
| 119 weak_factory_.GetWeakPtr())); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void SetPersistentHostQuota(const std::string& host, int64 new_quota) { | 122 void SetPersistentHostQuota(const std::string& host, int64 new_quota) { |
| 122 quota_status_ = kQuotaStatusUnknown; | 123 quota_status_ = kQuotaStatusUnknown; |
| 123 host_.clear(); | 124 host_.clear(); |
| 124 type_ = kStorageTypeUnknown; | 125 type_ = kStorageTypeUnknown; |
| 125 quota_ = -1; | 126 quota_ = -1; |
| 126 quota_manager_->SetPersistentHostQuota(host, new_quota, | 127 quota_manager_->SetPersistentHostQuota( |
| 127 callback_factory_.NewCallback( | 128 host, new_quota, |
| 128 &QuotaManagerTest::DidGetHostQuota)); | 129 base::Bind(&QuotaManagerTest::DidGetHostQuota, |
| 130 weak_factory_.GetWeakPtr())); |
| 129 } | 131 } |
| 130 | 132 |
| 131 void GetGlobalUsage(StorageType type) { | 133 void GetGlobalUsage(StorageType type) { |
| 132 type_ = kStorageTypeUnknown; | 134 type_ = kStorageTypeUnknown; |
| 133 usage_ = -1; | 135 usage_ = -1; |
| 134 unlimited_usage_ = -1; | 136 unlimited_usage_ = -1; |
| 135 quota_manager_->GetGlobalUsage(type, | 137 quota_manager_->GetGlobalUsage( |
| 136 callback_factory_.NewCallback( | 138 type, |
| 137 &QuotaManagerTest::DidGetGlobalUsage)); | 139 base::Bind(&QuotaManagerTest::DidGetGlobalUsage, |
| 140 weak_factory_.GetWeakPtr())); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void GetHostUsage(const std::string& host, StorageType type) { | 143 void GetHostUsage(const std::string& host, StorageType type) { |
| 141 host_.clear(); | 144 host_.clear(); |
| 142 type_ = kStorageTypeUnknown; | 145 type_ = kStorageTypeUnknown; |
| 143 usage_ = -1; | 146 usage_ = -1; |
| 144 quota_manager_->GetHostUsage(host, type, | 147 quota_manager_->GetHostUsage( |
| 145 callback_factory_.NewCallback( | 148 host, type, |
| 146 &QuotaManagerTest::DidGetHostUsage)); | 149 base::Bind(&QuotaManagerTest::DidGetHostUsage, |
| 150 weak_factory_.GetWeakPtr())); |
| 147 } | 151 } |
| 148 | 152 |
| 149 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { | 153 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { |
| 150 quota_manager_->GetUsageAndQuota(origin, type, | 154 quota_manager_->GetUsageAndQuota( |
| 151 callback_factory_.NewCallback( | 155 origin, type, |
| 152 &QuotaManagerTest::DidGetUsageAndQuotaAdditional)); | 156 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional, |
| 157 weak_factory_.GetWeakPtr())); |
| 153 } | 158 } |
| 154 | 159 |
| 155 void DeleteClientOriginData(QuotaClient* client, | 160 void DeleteClientOriginData(QuotaClient* client, |
| 156 const GURL& origin, | 161 const GURL& origin, |
| 157 StorageType type) { | 162 StorageType type) { |
| 158 DCHECK(client); | 163 DCHECK(client); |
| 159 quota_status_ = kQuotaStatusUnknown; | 164 quota_status_ = kQuotaStatusUnknown; |
| 160 client->DeleteOriginData(origin, type, | 165 client->DeleteOriginData( |
| 161 callback_factory_.NewCallback( | 166 origin, type, |
| 162 &QuotaManagerTest::StatusCallback)); | 167 base::Bind(&QuotaManagerTest::StatusCallback, |
| 168 weak_factory_.GetWeakPtr())); |
| 163 } | 169 } |
| 164 | 170 |
| 165 void EvictOriginData(const GURL& origin, | 171 void EvictOriginData(const GURL& origin, |
| 166 StorageType type) { | 172 StorageType type) { |
| 167 quota_status_ = kQuotaStatusUnknown; | 173 quota_status_ = kQuotaStatusUnknown; |
| 168 quota_manager_->EvictOriginData(origin, type, | 174 quota_manager_->EvictOriginData( |
| 169 callback_factory_.NewCallback( | 175 origin, type, |
| 170 &QuotaManagerTest::StatusCallback)); | 176 base::Bind(&QuotaManagerTest::StatusCallback, |
| 177 weak_factory_.GetWeakPtr())); |
| 171 } | 178 } |
| 172 | 179 |
| 173 void DeleteOriginData(const GURL& origin, | 180 void DeleteOriginData(const GURL& origin, |
| 174 StorageType type) { | 181 StorageType type) { |
| 175 quota_status_ = kQuotaStatusUnknown; | 182 quota_status_ = kQuotaStatusUnknown; |
| 176 quota_manager_->DeleteOriginData(origin, type, | 183 quota_manager_->DeleteOriginData( |
| 177 callback_factory_.NewCallback( | 184 origin, type, |
| 178 &QuotaManagerTest::StatusCallback)); | 185 base::Bind(&QuotaManagerTest::StatusCallback, |
| 186 weak_factory_.GetWeakPtr())); |
| 179 } | 187 } |
| 180 | 188 |
| 181 void GetAvailableSpace() { | 189 void GetAvailableSpace() { |
| 182 quota_status_ = kQuotaStatusUnknown; | 190 quota_status_ = kQuotaStatusUnknown; |
| 183 available_space_ = -1; | 191 available_space_ = -1; |
| 184 quota_manager_->GetAvailableSpace( | 192 quota_manager_->GetAvailableSpace( |
| 185 callback_factory_.NewCallback( | 193 base::Bind(&QuotaManagerTest::DidGetAvailableSpace, |
| 186 &QuotaManagerTest::DidGetAvailableSpace)); | 194 weak_factory_.GetWeakPtr())); |
| 187 } | 195 } |
| 188 | 196 |
| 189 void GetUsageAndQuotaForEviction() { | 197 void GetUsageAndQuotaForEviction() { |
| 190 quota_status_ = kQuotaStatusUnknown; | 198 quota_status_ = kQuotaStatusUnknown; |
| 191 usage_ = -1; | 199 usage_ = -1; |
| 192 unlimited_usage_ = -1; | 200 unlimited_usage_ = -1; |
| 193 quota_ = -1; | 201 quota_ = -1; |
| 194 available_space_ = -1; | 202 available_space_ = -1; |
| 195 quota_manager_->GetUsageAndQuotaForEviction( | 203 quota_manager_->GetUsageAndQuotaForEviction( |
| 196 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction, | 204 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaForEviction, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 227 quota_manager_->NotifyOriginInUse(origin); | 235 quota_manager_->NotifyOriginInUse(origin); |
| 228 } | 236 } |
| 229 | 237 |
| 230 void NotifyOriginNoLongerInUse(const GURL& origin) { | 238 void NotifyOriginNoLongerInUse(const GURL& origin) { |
| 231 quota_manager_->NotifyOriginNoLongerInUse(origin); | 239 quota_manager_->NotifyOriginNoLongerInUse(origin); |
| 232 } | 240 } |
| 233 | 241 |
| 234 void GetOriginsModifiedSince(StorageType type, base::Time modified_since) { | 242 void GetOriginsModifiedSince(StorageType type, base::Time modified_since) { |
| 235 modified_origins_.clear(); | 243 modified_origins_.clear(); |
| 236 modified_origins_type_ = kStorageTypeUnknown; | 244 modified_origins_type_ = kStorageTypeUnknown; |
| 237 quota_manager_->GetOriginsModifiedSince(type, modified_since, | 245 quota_manager_->GetOriginsModifiedSince( |
| 238 callback_factory_.NewCallback( | 246 type, modified_since, |
| 239 &QuotaManagerTest::DidGetModifiedOrigins)); | 247 base::Bind(&QuotaManagerTest::DidGetModifiedOrigins, |
| 248 weak_factory_.GetWeakPtr())); |
| 240 } | 249 } |
| 241 | 250 |
| 242 void DumpQuotaTable() { | 251 void DumpQuotaTable() { |
| 243 quota_entries_.clear(); | 252 quota_entries_.clear(); |
| 244 quota_manager_->DumpQuotaTable( | 253 quota_manager_->DumpQuotaTable( |
| 245 callback_factory_.NewCallback( | 254 base::Bind(&QuotaManagerTest::DidDumpQuotaTable, |
| 246 &QuotaManagerTest::DidDumpQuotaTable)); | 255 weak_factory_.GetWeakPtr())); |
| 247 } | 256 } |
| 248 | 257 |
| 249 void DumpOriginInfoTable() { | 258 void DumpOriginInfoTable() { |
| 250 origin_info_entries_.clear(); | 259 origin_info_entries_.clear(); |
| 251 quota_manager_->DumpOriginInfoTable( | 260 quota_manager_->DumpOriginInfoTable( |
| 252 callback_factory_.NewCallback( | 261 base::Bind(&QuotaManagerTest::DidDumpOriginInfoTable, |
| 253 &QuotaManagerTest::DidDumpOriginInfoTable)); | 262 weak_factory_.GetWeakPtr())); |
| 254 } | 263 } |
| 255 | 264 |
| 256 void DidGetUsageInfo(const UsageInfoEntries& entries) { | 265 void DidGetUsageInfo(const UsageInfoEntries& entries) { |
| 257 usage_info_.insert(usage_info_.begin(), entries.begin(), entries.end()); | 266 usage_info_.insert(usage_info_.begin(), entries.begin(), entries.end()); |
| 258 } | 267 } |
| 259 | 268 |
| 260 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 269 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
| 261 quota_status_ = status; | 270 quota_status_ = status; |
| 262 usage_ = usage; | 271 usage_ = usage; |
| 263 quota_ = quota; | 272 quota_ = quota; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 int status_callback_count() const { return status_callback_count_; } | 378 int status_callback_count() const { return status_callback_count_; } |
| 370 void reset_status_callback_count() { status_callback_count_ = 0; } | 379 void reset_status_callback_count() { status_callback_count_ = 0; } |
| 371 | 380 |
| 372 private: | 381 private: |
| 373 base::Time IncrementMockTime() { | 382 base::Time IncrementMockTime() { |
| 374 ++mock_time_counter_; | 383 ++mock_time_counter_; |
| 375 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); | 384 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); |
| 376 } | 385 } |
| 377 | 386 |
| 378 ScopedTempDir data_dir_; | 387 ScopedTempDir data_dir_; |
| 379 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; | |
| 380 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; | 388 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; |
| 381 | 389 |
| 382 scoped_refptr<QuotaManager> quota_manager_; | 390 scoped_refptr<QuotaManager> quota_manager_; |
| 383 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; | 391 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; |
| 384 | 392 |
| 385 QuotaStatusCode quota_status_; | 393 QuotaStatusCode quota_status_; |
| 386 UsageInfoEntries usage_info_; | 394 UsageInfoEntries usage_info_; |
| 387 std::string host_; | 395 std::string host_; |
| 388 StorageType type_; | 396 StorageType type_; |
| 389 int64 usage_; | 397 int64 usage_; |
| (...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 GetPersistentHostQuota(std::string()); | 1645 GetPersistentHostQuota(std::string()); |
| 1638 MessageLoop::current()->RunAllPending(); | 1646 MessageLoop::current()->RunAllPending(); |
| 1639 EXPECT_EQ(kQuotaStatusOk, status()); | 1647 EXPECT_EQ(kQuotaStatusOk, status()); |
| 1640 EXPECT_EQ(0, quota()); | 1648 EXPECT_EQ(0, quota()); |
| 1641 | 1649 |
| 1642 SetPersistentHostQuota(std::string(), 10); | 1650 SetPersistentHostQuota(std::string(), 10); |
| 1643 MessageLoop::current()->RunAllPending(); | 1651 MessageLoop::current()->RunAllPending(); |
| 1644 EXPECT_EQ(kQuotaErrorNotSupported, status()); | 1652 EXPECT_EQ(kQuotaErrorNotSupported, status()); |
| 1645 } | 1653 } |
| 1646 } // namespace quota | 1654 } // namespace quota |
| OLD | NEW |