| OLD | NEW |
| 1 // Copyright (c) 2012 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" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 quota_manager_->GetUsageAndQuota( | 124 quota_manager_->GetUsageAndQuota( |
| 125 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, | 125 origin, type, base::Bind(&QuotaManagerTest::DidGetUsageAndQuota, |
| 126 weak_factory_.GetWeakPtr())); | 126 weak_factory_.GetWeakPtr())); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void GetTemporaryGlobalQuota() { | 129 void GetTemporaryGlobalQuota() { |
| 130 quota_status_ = kQuotaStatusUnknown; | 130 quota_status_ = kQuotaStatusUnknown; |
| 131 quota_ = -1; | 131 quota_ = -1; |
| 132 quota_manager_->GetTemporaryGlobalQuota( | 132 quota_manager_->GetTemporaryGlobalQuota( |
| 133 base::Bind(&QuotaManagerTest::DidGetQuota, | 133 base::Bind(&QuotaManagerTest::DidGetQuota, |
| 134 weak_factory_.GetWeakPtr(), quota::kStorageTypeTemporary)); | 134 weak_factory_.GetWeakPtr())); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void SetTemporaryGlobalQuota(int64 new_quota) { | 137 void SetTemporaryGlobalQuota(int64 new_quota) { |
| 138 quota_status_ = kQuotaStatusUnknown; | 138 quota_status_ = kQuotaStatusUnknown; |
| 139 quota_ = -1; | 139 quota_ = -1; |
| 140 quota_manager_->SetTemporaryGlobalOverrideQuota( | 140 quota_manager_->SetTemporaryGlobalOverrideQuota( |
| 141 new_quota, | 141 new_quota, |
| 142 base::Bind(&QuotaManagerTest::DidGetQuota, | 142 base::Bind(&QuotaManagerTest::DidGetQuota, |
| 143 weak_factory_.GetWeakPtr(), quota::kStorageTypeTemporary)); | 143 weak_factory_.GetWeakPtr())); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void GetPersistentHostQuota(const std::string& host) { | 146 void GetPersistentHostQuota(const std::string& host) { |
| 147 quota_status_ = kQuotaStatusUnknown; | 147 quota_status_ = kQuotaStatusUnknown; |
| 148 host_.clear(); | |
| 149 type_ = kStorageTypeUnknown; | |
| 150 quota_ = -1; | 148 quota_ = -1; |
| 151 quota_manager_->GetPersistentHostQuota( | 149 quota_manager_->GetPersistentHostQuota( |
| 152 host, | 150 host, |
| 153 base::Bind(&QuotaManagerTest::DidGetHostQuota, | 151 base::Bind(&QuotaManagerTest::DidGetHostQuota, |
| 154 weak_factory_.GetWeakPtr())); | 152 weak_factory_.GetWeakPtr())); |
| 155 } | 153 } |
| 156 | 154 |
| 157 void SetPersistentHostQuota(const std::string& host, int64 new_quota) { | 155 void SetPersistentHostQuota(const std::string& host, int64 new_quota) { |
| 158 quota_status_ = kQuotaStatusUnknown; | 156 quota_status_ = kQuotaStatusUnknown; |
| 159 host_.clear(); | |
| 160 type_ = kStorageTypeUnknown; | |
| 161 quota_ = -1; | 157 quota_ = -1; |
| 162 quota_manager_->SetPersistentHostQuota( | 158 quota_manager_->SetPersistentHostQuota( |
| 163 host, new_quota, | 159 host, new_quota, |
| 164 base::Bind(&QuotaManagerTest::DidGetHostQuota, | 160 base::Bind(&QuotaManagerTest::DidGetHostQuota, |
| 165 weak_factory_.GetWeakPtr())); | 161 weak_factory_.GetWeakPtr())); |
| 166 } | 162 } |
| 167 | 163 |
| 168 void GetGlobalUsage(StorageType type) { | 164 void GetGlobalUsage(StorageType type) { |
| 169 type_ = kStorageTypeUnknown; | |
| 170 usage_ = -1; | 165 usage_ = -1; |
| 171 unlimited_usage_ = -1; | 166 unlimited_usage_ = -1; |
| 172 quota_manager_->GetGlobalUsage( | 167 quota_manager_->GetGlobalUsage( |
| 173 type, | 168 type, |
| 174 base::Bind(&QuotaManagerTest::DidGetGlobalUsage, | 169 base::Bind(&QuotaManagerTest::DidGetGlobalUsage, |
| 175 weak_factory_.GetWeakPtr())); | 170 weak_factory_.GetWeakPtr())); |
| 176 } | 171 } |
| 177 | 172 |
| 178 void GetHostUsage(const std::string& host, StorageType type) { | 173 void GetHostUsage(const std::string& host, StorageType type) { |
| 179 host_.clear(); | |
| 180 type_ = kStorageTypeUnknown; | |
| 181 usage_ = -1; | 174 usage_ = -1; |
| 182 quota_manager_->GetHostUsage( | 175 quota_manager_->GetHostUsage( |
| 183 host, type, | 176 host, type, |
| 184 base::Bind(&QuotaManagerTest::DidGetHostUsage, | 177 base::Bind(&QuotaManagerTest::DidGetHostUsage, |
| 185 weak_factory_.GetWeakPtr(), host, type)); | 178 weak_factory_.GetWeakPtr())); |
| 186 } | 179 } |
| 187 | 180 |
| 188 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { | 181 void RunAdditionalUsageAndQuotaTask(const GURL& origin, StorageType type) { |
| 189 quota_manager_->GetUsageAndQuota( | 182 quota_manager_->GetUsageAndQuota( |
| 190 origin, type, | 183 origin, type, |
| 191 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional, | 184 base::Bind(&QuotaManagerTest::DidGetUsageAndQuotaAdditional, |
| 192 weak_factory_.GetWeakPtr())); | 185 weak_factory_.GetWeakPtr())); |
| 193 } | 186 } |
| 194 | 187 |
| 195 void DeleteClientOriginData(QuotaClient* client, | 188 void DeleteClientOriginData(QuotaClient* client, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 void DidGetUsageInfo(const UsageInfoEntries& entries) { | 304 void DidGetUsageInfo(const UsageInfoEntries& entries) { |
| 312 usage_info_.insert(usage_info_.begin(), entries.begin(), entries.end()); | 305 usage_info_.insert(usage_info_.begin(), entries.begin(), entries.end()); |
| 313 } | 306 } |
| 314 | 307 |
| 315 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 308 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
| 316 quota_status_ = status; | 309 quota_status_ = status; |
| 317 usage_ = usage; | 310 usage_ = usage; |
| 318 quota_ = quota; | 311 quota_ = quota; |
| 319 } | 312 } |
| 320 | 313 |
| 321 void DidGetQuota(StorageType type, | 314 void DidGetQuota(QuotaStatusCode status, |
| 322 QuotaStatusCode status, | |
| 323 int64 quota) { | 315 int64 quota) { |
| 324 quota_status_ = status; | 316 quota_status_ = status; |
| 325 type_ = type; | |
| 326 quota_ = quota; | 317 quota_ = quota; |
| 327 } | 318 } |
| 328 | 319 |
| 329 void DidGetAvailableSpace(QuotaStatusCode status, int64 available_space) { | 320 void DidGetAvailableSpace(QuotaStatusCode status, int64 available_space) { |
| 330 quota_status_ = status; | 321 quota_status_ = status; |
| 331 available_space_ = available_space; | 322 available_space_ = available_space; |
| 332 } | 323 } |
| 333 | 324 |
| 334 void DidGetHostQuota(QuotaStatusCode status, | 325 void DidGetHostQuota(QuotaStatusCode status, |
| 335 int64 quota) { | 326 int64 quota) { |
| 336 quota_status_ = status; | 327 quota_status_ = status; |
| 337 quota_ = quota; | 328 quota_ = quota; |
| 338 } | 329 } |
| 339 | 330 |
| 340 void DidGetGlobalUsage(StorageType type, int64 usage, | 331 void DidGetGlobalUsage(int64 usage, |
| 341 int64 unlimited_usage) { | 332 int64 unlimited_usage) { |
| 342 type_ = type; | |
| 343 usage_ = usage; | 333 usage_ = usage; |
| 344 unlimited_usage_ = unlimited_usage; | 334 unlimited_usage_ = unlimited_usage; |
| 345 } | 335 } |
| 346 | 336 |
| 347 void DidGetHostUsage(const std::string& host, | 337 void DidGetHostUsage(int64 usage) { |
| 348 StorageType type, | |
| 349 int64 usage) { | |
| 350 host_ = host; | |
| 351 type_ = type; | |
| 352 usage_ = usage; | 338 usage_ = usage; |
| 353 } | 339 } |
| 354 | 340 |
| 355 void StatusCallback(QuotaStatusCode status) { | 341 void StatusCallback(QuotaStatusCode status) { |
| 356 ++status_callback_count_; | 342 ++status_callback_count_; |
| 357 quota_status_ = status; | 343 quota_status_ = status; |
| 358 } | 344 } |
| 359 | 345 |
| 360 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, | 346 void DidGetUsageAndQuotaForEviction(QuotaStatusCode status, |
| 361 const UsageAndQuota& usage_and_quota) { | 347 const UsageAndQuota& usage_and_quota) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 void set_quota_manager(QuotaManager* quota_manager) { | 382 void set_quota_manager(QuotaManager* quota_manager) { |
| 397 quota_manager_ = quota_manager; | 383 quota_manager_ = quota_manager; |
| 398 } | 384 } |
| 399 | 385 |
| 400 MockSpecialStoragePolicy* mock_special_storage_policy() const { | 386 MockSpecialStoragePolicy* mock_special_storage_policy() const { |
| 401 return mock_special_storage_policy_.get(); | 387 return mock_special_storage_policy_.get(); |
| 402 } | 388 } |
| 403 | 389 |
| 404 QuotaStatusCode status() const { return quota_status_; } | 390 QuotaStatusCode status() const { return quota_status_; } |
| 405 const UsageInfoEntries& usage_info() const { return usage_info_; } | 391 const UsageInfoEntries& usage_info() const { return usage_info_; } |
| 406 const std::string& host() const { return host_; } | |
| 407 StorageType type() const { return type_; } | |
| 408 int64 usage() const { return usage_; } | 392 int64 usage() const { return usage_; } |
| 409 int64 unlimited_usage() const { return unlimited_usage_; } | 393 int64 unlimited_usage() const { return unlimited_usage_; } |
| 410 int64 quota() const { return quota_; } | 394 int64 quota() const { return quota_; } |
| 411 int64 available_space() const { return available_space_; } | 395 int64 available_space() const { return available_space_; } |
| 412 const GURL& lru_origin() const { return lru_origin_; } | 396 const GURL& lru_origin() const { return lru_origin_; } |
| 413 const std::set<GURL>& modified_origins() const { return modified_origins_; } | 397 const std::set<GURL>& modified_origins() const { return modified_origins_; } |
| 414 StorageType modified_origins_type() const { return modified_origins_type_; } | 398 StorageType modified_origins_type() const { return modified_origins_type_; } |
| 415 const QuotaTableEntries& quota_entries() const { return quota_entries_; } | 399 const QuotaTableEntries& quota_entries() const { return quota_entries_; } |
| 416 const OriginInfoTableEntries& origin_info_entries() const { | 400 const OriginInfoTableEntries& origin_info_entries() const { |
| 417 return origin_info_entries_; | 401 return origin_info_entries_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 428 | 412 |
| 429 base::MessageLoop message_loop_; | 413 base::MessageLoop message_loop_; |
| 430 base::ScopedTempDir data_dir_; | 414 base::ScopedTempDir data_dir_; |
| 431 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; | 415 base::WeakPtrFactory<QuotaManagerTest> weak_factory_; |
| 432 | 416 |
| 433 scoped_refptr<QuotaManager> quota_manager_; | 417 scoped_refptr<QuotaManager> quota_manager_; |
| 434 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; | 418 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; |
| 435 | 419 |
| 436 QuotaStatusCode quota_status_; | 420 QuotaStatusCode quota_status_; |
| 437 UsageInfoEntries usage_info_; | 421 UsageInfoEntries usage_info_; |
| 438 std::string host_; | |
| 439 StorageType type_; | |
| 440 int64 usage_; | 422 int64 usage_; |
| 441 int64 unlimited_usage_; | 423 int64 unlimited_usage_; |
| 442 int64 quota_; | 424 int64 quota_; |
| 443 int64 available_space_; | 425 int64 available_space_; |
| 444 GURL lru_origin_; | 426 GURL lru_origin_; |
| 445 std::set<GURL> modified_origins_; | 427 std::set<GURL> modified_origins_; |
| 446 StorageType modified_origins_type_; | 428 StorageType modified_origins_type_; |
| 447 QuotaTableEntries quota_entries_; | 429 QuotaTableEntries quota_entries_; |
| 448 OriginInfoTableEntries origin_info_entries_; | 430 OriginInfoTableEntries origin_info_entries_; |
| 449 int status_callback_count_; | 431 int status_callback_count_; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 { "https://bar.com/", kTemp, 7 }, | 573 { "https://bar.com/", kTemp, 7 }, |
| 592 { "http://baz.com/", kTemp, 30 }, | 574 { "http://baz.com/", kTemp, 30 }, |
| 593 { "http://foo.com/", kPerm, 40 }, | 575 { "http://foo.com/", kPerm, 40 }, |
| 594 }; | 576 }; |
| 595 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), | 577 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData), |
| 596 QuotaClient::kFileSystem)); | 578 QuotaClient::kFileSystem)); |
| 597 | 579 |
| 598 // This time explicitly sets a temporary global quota. | 580 // This time explicitly sets a temporary global quota. |
| 599 SetTemporaryGlobalQuota(100); | 581 SetTemporaryGlobalQuota(100); |
| 600 base::MessageLoop::current()->RunUntilIdle(); | 582 base::MessageLoop::current()->RunUntilIdle(); |
| 601 EXPECT_EQ(kTemp, type()); | |
| 602 EXPECT_EQ(kQuotaStatusOk, status()); | 583 EXPECT_EQ(kQuotaStatusOk, status()); |
| 603 EXPECT_EQ(100, quota()); | 584 EXPECT_EQ(100, quota()); |
| 604 | 585 |
| 605 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 586 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
| 606 base::MessageLoop::current()->RunUntilIdle(); | 587 base::MessageLoop::current()->RunUntilIdle(); |
| 607 EXPECT_EQ(kQuotaStatusOk, status()); | 588 EXPECT_EQ(kQuotaStatusOk, status()); |
| 608 EXPECT_EQ(10 + 20, usage()); | 589 EXPECT_EQ(10 + 20, usage()); |
| 609 | 590 |
| 610 const int kPerHostQuota = 100 / kPerHostTemporaryPortion; | 591 const int kPerHostQuota = 100 / kPerHostTemporaryPortion; |
| 611 | 592 |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2175 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2156 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2176 | 2157 |
| 2177 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); | 2158 GetUsageAndQuotaForWebApps(GURL("http://foo.com/"), kTemp); |
| 2178 base::MessageLoop::current()->RunUntilIdle(); | 2159 base::MessageLoop::current()->RunUntilIdle(); |
| 2179 EXPECT_EQ(kQuotaStatusOk, status()); | 2160 EXPECT_EQ(kQuotaStatusOk, status()); |
| 2180 EXPECT_EQ(10, usage()); | 2161 EXPECT_EQ(10, usage()); |
| 2181 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); | 2162 EXPECT_EQ(QuotaManager::kIncognitoDefaultQuotaLimit, quota()); |
| 2182 } | 2163 } |
| 2183 | 2164 |
| 2184 } // namespace quota | 2165 } // namespace quota |
| OLD | NEW |