| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <list> | 5 #include <list> | 
| 6 #include <map> | 6 #include <map> | 
| 7 #include <utility> | 7 #include <utility> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 31  public: | 31  public: | 
| 32   explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test) | 32   explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test) | 
| 33       : quota_(0), | 33       : quota_(0), | 
| 34         available_space_(0), | 34         available_space_(0), | 
| 35         error_on_evict_origin_data_(false), | 35         error_on_evict_origin_data_(false), | 
| 36         error_on_get_usage_and_quota_(false) {} | 36         error_on_get_usage_and_quota_(false) {} | 
| 37 | 37 | 
| 38   virtual void EvictOriginData( | 38   virtual void EvictOriginData( | 
| 39       const GURL& origin, | 39       const GURL& origin, | 
| 40       StorageType type, | 40       StorageType type, | 
| 41       const EvictOriginDataCallback& callback) OVERRIDE { | 41       const EvictOriginDataCallback& callback) override { | 
| 42     if (error_on_evict_origin_data_) { | 42     if (error_on_evict_origin_data_) { | 
| 43       callback.Run(storage::kQuotaErrorInvalidModification); | 43       callback.Run(storage::kQuotaErrorInvalidModification); | 
| 44       return; | 44       return; | 
| 45     } | 45     } | 
| 46     int64 origin_usage = EnsureOriginRemoved(origin); | 46     int64 origin_usage = EnsureOriginRemoved(origin); | 
| 47     if (origin_usage >= 0) | 47     if (origin_usage >= 0) | 
| 48       available_space_ += origin_usage; | 48       available_space_ += origin_usage; | 
| 49     callback.Run(storage::kQuotaStatusOk); | 49     callback.Run(storage::kQuotaStatusOk); | 
| 50   } | 50   } | 
| 51 | 51 | 
| 52   virtual void GetUsageAndQuotaForEviction( | 52   virtual void GetUsageAndQuotaForEviction( | 
| 53       const UsageAndQuotaCallback& callback) OVERRIDE { | 53       const UsageAndQuotaCallback& callback) override { | 
| 54     if (error_on_get_usage_and_quota_) { | 54     if (error_on_get_usage_and_quota_) { | 
| 55       callback.Run(storage::kQuotaErrorInvalidAccess, UsageAndQuota()); | 55       callback.Run(storage::kQuotaErrorInvalidAccess, UsageAndQuota()); | 
| 56       return; | 56       return; | 
| 57     } | 57     } | 
| 58     if (!task_for_get_usage_and_quota_.is_null()) | 58     if (!task_for_get_usage_and_quota_.is_null()) | 
| 59       task_for_get_usage_and_quota_.Run(); | 59       task_for_get_usage_and_quota_.Run(); | 
| 60     UsageAndQuota quota_and_usage(-1, GetUsage(), quota_, available_space_); | 60     UsageAndQuota quota_and_usage(-1, GetUsage(), quota_, available_space_); | 
| 61     callback.Run(storage::kQuotaStatusOk, quota_and_usage); | 61     callback.Run(storage::kQuotaStatusOk, quota_and_usage); | 
| 62   } | 62   } | 
| 63 | 63 | 
| 64   virtual void GetLRUOrigin( | 64   virtual void GetLRUOrigin( | 
| 65       StorageType type, | 65       StorageType type, | 
| 66       const GetLRUOriginCallback& callback) OVERRIDE { | 66       const GetLRUOriginCallback& callback) override { | 
| 67     if (origin_order_.empty()) | 67     if (origin_order_.empty()) | 
| 68       callback.Run(GURL()); | 68       callback.Run(GURL()); | 
| 69     else | 69     else | 
| 70       callback.Run(GURL(origin_order_.front())); | 70       callback.Run(GURL(origin_order_.front())); | 
| 71   } | 71   } | 
| 72 | 72 | 
| 73   int64 GetUsage() const { | 73   int64 GetUsage() const { | 
| 74     int64 total_usage = 0; | 74     int64 total_usage = 0; | 
| 75     for (std::map<GURL, int64>::const_iterator p = origins_.begin(); | 75     for (std::map<GURL, int64>::const_iterator p = origins_.begin(); | 
| 76          p != origins_.end(); | 76          p != origins_.end(); | 
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 405   EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage()); | 405   EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage()); | 
| 406 | 406 | 
| 407   EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); | 407   EXPECT_EQ(0, statistics().num_errors_on_evicting_origin); | 
| 408   EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); | 408   EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota); | 
| 409   EXPECT_EQ(2, statistics().num_evicted_origins); | 409   EXPECT_EQ(2, statistics().num_evicted_origins); | 
| 410   EXPECT_EQ(1, statistics().num_eviction_rounds); | 410   EXPECT_EQ(1, statistics().num_eviction_rounds); | 
| 411   EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); | 411   EXPECT_EQ(0, statistics().num_skipped_eviction_rounds); | 
| 412 } | 412 } | 
| 413 | 413 | 
| 414 }  // namespace content | 414 }  // namespace content | 
| OLD | NEW | 
|---|