| Index: content/browser/quota/quota_temporary_storage_evictor_unittest.cc
|
| diff --git a/content/browser/quota/quota_temporary_storage_evictor_unittest.cc b/content/browser/quota/quota_temporary_storage_evictor_unittest.cc
|
| index 989c63df3d64f962a8c9d495f8992f6d9a2c42cc..ef417c7080d36cd4837fdf23bda53f64cf6227f6 100644
|
| --- a/content/browser/quota/quota_temporary_storage_evictor_unittest.cc
|
| +++ b/content/browser/quota/quota_temporary_storage_evictor_unittest.cc
|
| @@ -21,7 +21,6 @@
|
|
|
| using storage::QuotaTemporaryStorageEvictor;
|
| using storage::StorageType;
|
| -using storage::UsageAndQuota;
|
|
|
| namespace content {
|
|
|
| @@ -31,15 +30,14 @@ namespace {
|
|
|
| class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler {
|
| public:
|
| - explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest *test)
|
| - : quota_(0),
|
| - available_space_(0),
|
| + explicit MockQuotaEvictionHandler(QuotaTemporaryStorageEvictorTest* test)
|
| + : available_space_(0),
|
| error_on_evict_origin_data_(false),
|
| error_on_get_usage_and_quota_(false) {}
|
|
|
| void EvictOriginData(const GURL& origin,
|
| StorageType type,
|
| - const EvictOriginDataCallback& callback) override {
|
| + const storage::StatusCallback& callback) override {
|
| if (error_on_evict_origin_data_) {
|
| callback.Run(storage::kQuotaErrorInvalidModification);
|
| return;
|
| @@ -50,22 +48,17 @@ class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler {
|
| callback.Run(storage::kQuotaStatusOk);
|
| }
|
|
|
| - void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) override {
|
| - uint64_t available = static_cast<uint64_t>(available_space_);
|
| - uint64_t total = (1024 * 1024 * 1024) + (2 * available); // 1G plus some.
|
| - callback.Run(true, available, total);
|
| - }
|
| -
|
| - void GetUsageAndQuotaForEviction(
|
| - const UsageAndQuotaCallback& callback) override {
|
| + void GetEvictionRoundInfo(
|
| + const EvictionRoundInfoCallback& callback) override {
|
| if (error_on_get_usage_and_quota_) {
|
| - callback.Run(storage::kQuotaErrorInvalidAccess, UsageAndQuota());
|
| + callback.Run(storage::kQuotaErrorAbort, storage::QuotaSettings(), 0, 0, 0,
|
| + false);
|
| return;
|
| }
|
| if (!task_for_get_usage_and_quota_.is_null())
|
| task_for_get_usage_and_quota_.Run();
|
| - UsageAndQuota quota_and_usage(-1, GetUsage(), quota_, available_space_);
|
| - callback.Run(storage::kQuotaStatusOk, quota_and_usage);
|
| + callback.Run(storage::kQuotaStatusOk, settings_, available_space_,
|
| + available_space_ * 2, GetUsage(), true);
|
| }
|
|
|
| void GetEvictionOrigin(StorageType type,
|
| @@ -86,7 +79,13 @@ class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler {
|
| return total_usage;
|
| }
|
|
|
| - void set_quota(int64_t quota) { quota_ = quota; }
|
| + const storage::QuotaSettings& settings() const { return settings_; }
|
| + void SetPoolSize(int64_t pool_size) {
|
| + settings_.pool_size = pool_size;
|
| + settings_.per_host_quota = pool_size / 5;
|
| + settings_.must_remain_available = pool_size / 5;
|
| + settings_.refresh_interval = base::TimeDelta::Max();
|
| + }
|
| void set_available_space(int64_t available_space) {
|
| available_space_ = available_space;
|
| }
|
| @@ -130,7 +129,7 @@ class MockQuotaEvictionHandler : public storage::QuotaEvictionHandler {
|
| return origin_usage;
|
| }
|
|
|
| - int64_t quota_;
|
| + storage::QuotaSettings settings_;
|
| int64_t available_space_;
|
| std::list<GURL> origin_order_;
|
| std::map<GURL, int64_t> origins_;
|
| @@ -169,20 +168,20 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
|
| int expected_usage_after_second) {
|
| EXPECT_GE(4, num_get_usage_and_quota_for_eviction_);
|
| switch (num_get_usage_and_quota_for_eviction_) {
|
| - case 2:
|
| - EXPECT_EQ(expected_usage_after_first,
|
| - quota_eviction_handler()->GetUsage());
|
| - if (!origin_to_be_added.first.is_empty())
|
| - quota_eviction_handler()->AddOrigin(origin_to_be_added.first,
|
| - origin_to_be_added.second);
|
| - if (!origin_to_be_accessed.is_empty())
|
| - quota_eviction_handler()->AccessOrigin(origin_to_be_accessed);
|
| - break;
|
| - case 3:
|
| - EXPECT_EQ(expected_usage_after_second,
|
| - quota_eviction_handler()->GetUsage());
|
| - temporary_storage_evictor()->set_repeated_eviction(false);
|
| - break;
|
| + case 2:
|
| + EXPECT_EQ(expected_usage_after_first,
|
| + quota_eviction_handler()->GetUsage());
|
| + if (!origin_to_be_added.first.is_empty())
|
| + quota_eviction_handler()->AddOrigin(origin_to_be_added.first,
|
| + origin_to_be_added.second);
|
| + if (!origin_to_be_accessed.is_empty())
|
| + quota_eviction_handler()->AccessOrigin(origin_to_be_accessed);
|
| + break;
|
| + case 3:
|
| + EXPECT_EQ(expected_usage_after_second,
|
| + quota_eviction_handler()->GetUsage());
|
| + temporary_storage_evictor()->timer_disabled_for_testing_ = true;
|
| + break;
|
| }
|
| ++num_get_usage_and_quota_for_eviction_;
|
| }
|
| @@ -201,36 +200,19 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test {
|
| return temporary_storage_evictor()->statistics_;
|
| }
|
|
|
| - void set_repeated_eviction(bool repeated_eviction) const {
|
| - return temporary_storage_evictor_->set_repeated_eviction(repeated_eviction);
|
| + void disable_timer_for_testing() const {
|
| + temporary_storage_evictor_->timer_disabled_for_testing_ = true;
|
| }
|
|
|
| int num_get_usage_and_quota_for_eviction() const {
|
| return num_get_usage_and_quota_for_eviction_;
|
| }
|
|
|
| - int64_t default_min_available_disk_space_to_start_eviction() const {
|
| - return 1000 * 1000 * 500;
|
| - }
|
| -
|
| - void set_min_available_disk_space_to_start_eviction(int64_t value) const {
|
| - temporary_storage_evictor_->set_min_available_disk_space_to_start_eviction(
|
| - value);
|
| - }
|
| -
|
| - void reset_min_available_disk_space_to_start_eviction() const {
|
| - temporary_storage_evictor_->
|
| - reset_min_available_disk_space_to_start_eviction();
|
| - }
|
| -
|
| base::MessageLoop message_loop_;
|
| std::unique_ptr<MockQuotaEvictionHandler> quota_eviction_handler_;
|
| std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_;
|
| -
|
| int num_get_usage_and_quota_for_eviction_;
|
| -
|
| base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest);
|
| };
|
|
|
| @@ -238,10 +220,10 @@ TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) {
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 3000);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 200);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 500);
|
| - quota_eviction_handler()->set_quota(4000);
|
| + quota_eviction_handler()->SetPoolSize(4000);
|
| quota_eviction_handler()->set_available_space(1000000000);
|
| EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage());
|
| - set_repeated_eviction(false);
|
| + disable_timer_for_testing();
|
| temporary_storage_evictor()->Start();
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(200 + 500, quota_eviction_handler()->GetUsage());
|
| @@ -258,10 +240,10 @@ TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) {
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 2900);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 400);
|
| - quota_eviction_handler()->set_quota(4000);
|
| + quota_eviction_handler()->SetPoolSize(4000);
|
| quota_eviction_handler()->set_available_space(1000000000);
|
| EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage());
|
| - set_repeated_eviction(false);
|
| + disable_timer_for_testing();
|
| temporary_storage_evictor()->Start();
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(450 + 400, quota_eviction_handler()->GetUsage());
|
| @@ -285,7 +267,7 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) {
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
|
| - quota_eviction_handler()->set_quota(1000);
|
| + quota_eviction_handler()->SetPoolSize(1000);
|
| quota_eviction_handler()->set_available_space(1000000000);
|
| quota_eviction_handler()->set_task_for_get_usage_and_quota(
|
| base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
|
| @@ -318,14 +300,14 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionSkippedTest) {
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
|
| - quota_eviction_handler()->set_quota(1000);
|
| + quota_eviction_handler()->SetPoolSize(1000);
|
| quota_eviction_handler()->set_available_space(1000000000);
|
| quota_eviction_handler()->set_task_for_get_usage_and_quota(
|
| base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
|
| weak_factory_.GetWeakPtr(), std::make_pair(GURL(), 0), GURL(),
|
| initial_total_size - d_size, initial_total_size - d_size));
|
| EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage());
|
| - set_repeated_eviction(true);
|
| + // disable_timer_for_testing();
|
| temporary_storage_evictor()->Start();
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(initial_total_size - d_size, quota_eviction_handler()->GetUsage());
|
| @@ -350,7 +332,7 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.c.com"), c_size);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.b.com"), b_size);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.a.com"), a_size);
|
| - quota_eviction_handler()->set_quota(1000);
|
| + quota_eviction_handler()->SetPoolSize(1000);
|
| quota_eviction_handler()->set_available_space(1000000000);
|
| quota_eviction_handler()->set_task_for_get_usage_and_quota(
|
| base::Bind(&QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest,
|
| @@ -374,17 +356,18 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessOriginTest) {
|
| }
|
|
|
| TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) {
|
| - quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 414);
|
| - quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 450);
|
| - quota_eviction_handler()->set_quota(10000);
|
| + // If we're using so little that evicting all of it wouldn't
|
| + // do enough to alleviate a diskspace shortage, we don't evict.
|
| + quota_eviction_handler()->AddOrigin(GURL("http://www.z.com"), 10);
|
| + quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 20);
|
| + quota_eviction_handler()->SetPoolSize(10000);
|
| quota_eviction_handler()->set_available_space(
|
| - default_min_available_disk_space_to_start_eviction() - 350);
|
| - EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage());
|
| - reset_min_available_disk_space_to_start_eviction();
|
| - set_repeated_eviction(false);
|
| + quota_eviction_handler()->settings().must_remain_available - 350);
|
| + EXPECT_EQ(10 + 20, quota_eviction_handler()->GetUsage());
|
| + disable_timer_for_testing();
|
| temporary_storage_evictor()->Start();
|
| base::RunLoop().RunUntilIdle();
|
| - EXPECT_EQ(414 + 450, quota_eviction_handler()->GetUsage());
|
| + EXPECT_EQ(10 + 20, quota_eviction_handler()->GetUsage());
|
|
|
| EXPECT_EQ(0, statistics().num_errors_on_evicting_origin);
|
| EXPECT_EQ(0, statistics().num_errors_on_getting_usage_and_quota);
|
| @@ -398,13 +381,11 @@ TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) {
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.y.com"), 120);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.x.com"), 150);
|
| quota_eviction_handler()->AddOrigin(GURL("http://www.w.com"), 300);
|
| - quota_eviction_handler()->set_quota(10000);
|
| + quota_eviction_handler()->SetPoolSize(10000);
|
| quota_eviction_handler()->set_available_space(
|
| - default_min_available_disk_space_to_start_eviction() - 350);
|
| + quota_eviction_handler()->settings().must_remain_available - 350);
|
| EXPECT_EQ(294 + 120 + 150 + 300, quota_eviction_handler()->GetUsage());
|
| - set_min_available_disk_space_to_start_eviction(
|
| - default_min_available_disk_space_to_start_eviction());
|
| - set_repeated_eviction(false);
|
| + disable_timer_for_testing();
|
| temporary_storage_evictor()->Start();
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_EQ(150 + 300, quota_eviction_handler()->GetUsage());
|
|
|