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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/extensions/settings/settings_backend.h" | 11 #include "chrome/browser/extensions/settings/settings_backend.h" |
12 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h" | 12 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h" |
13 #include "chrome/browser/value_store/testing_value_store.h" | 13 #include "chrome/browser/value_store/testing_value_store.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 // To save typing ValueStore::DEFAULTS/IGNORE_QUOTA everywhere. | 17 // To save typing ValueStore::DEFAULTS/IGNORE_QUOTA everywhere. |
18 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; | 18 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; |
19 const ValueStore::WriteOptions IGNORE_QUOTA = | 19 const ValueStore::WriteOptions IGNORE_QUOTA = |
20 ValueStore::IGNORE_QUOTA; | 20 ValueStore::IGNORE_QUOTA; |
21 | 21 |
22 class ExtensionSettingsQuotaTest : public testing::Test { | 22 class ExtensionSettingsQuotaTest : public testing::Test { |
23 public: | 23 public: |
24 ExtensionSettingsQuotaTest() | 24 ExtensionSettingsQuotaTest() |
25 : byte_value_1_(Value::CreateIntegerValue(1)), | 25 : byte_value_1_(Value::CreateIntegerValue(1)), |
26 byte_value_16_(Value::CreateStringValue("sixteen bytes.")), | 26 byte_value_16_(Value::CreateStringValue("sixteen bytes.")), |
27 byte_value_256_(new ListValue()), | 27 byte_value_256_(new ListValue()), |
28 delegate_(new TestingSettingsStorage()) { | 28 delegate_(new TestingValueStore()) { |
29 for (int i = 1; i < 89; ++i) { | 29 for (int i = 1; i < 89; ++i) { |
30 byte_value_256_->Append(Value::CreateIntegerValue(i)); | 30 byte_value_256_->Append(Value::CreateIntegerValue(i)); |
31 } | 31 } |
32 ValidateByteValues(); | 32 ValidateByteValues(); |
33 } | 33 } |
34 | 34 |
35 void ValidateByteValues() { | 35 void ValidateByteValues() { |
36 std::string validate_sizes; | 36 std::string validate_sizes; |
37 base::JSONWriter::Write(byte_value_1_.get(), &validate_sizes); | 37 base::JSONWriter::Write(byte_value_1_.get(), &validate_sizes); |
38 ASSERT_EQ(1u, validate_sizes.size()); | 38 ASSERT_EQ(1u, validate_sizes.size()); |
(...skipping 26 matching lines...) Expand all Loading... |
65 | 65 |
66 // Values with different serialized sizes. | 66 // Values with different serialized sizes. |
67 scoped_ptr<Value> byte_value_1_; | 67 scoped_ptr<Value> byte_value_1_; |
68 scoped_ptr<Value> byte_value_16_; | 68 scoped_ptr<Value> byte_value_16_; |
69 scoped_ptr<ListValue> byte_value_256_; | 69 scoped_ptr<ListValue> byte_value_256_; |
70 | 70 |
71 // Quota enforcing storage area being tested. | 71 // Quota enforcing storage area being tested. |
72 scoped_ptr<SettingsStorageQuotaEnforcer> storage_; | 72 scoped_ptr<SettingsStorageQuotaEnforcer> storage_; |
73 | 73 |
74 // In-memory storage area being delegated to. Always owned by |storage_|. | 74 // In-memory storage area being delegated to. Always owned by |storage_|. |
75 TestingSettingsStorage* delegate_; | 75 TestingValueStore* delegate_; |
76 }; | 76 }; |
77 | 77 |
78 TEST_F(ExtensionSettingsQuotaTest, ZeroQuotaBytes) { | 78 TEST_F(ExtensionSettingsQuotaTest, ZeroQuotaBytes) { |
79 DictionaryValue empty; | 79 DictionaryValue empty; |
80 CreateStorage(0, UINT_MAX, UINT_MAX); | 80 CreateStorage(0, UINT_MAX, UINT_MAX); |
81 | 81 |
82 EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError()); | 82 EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError()); |
83 EXPECT_FALSE(storage_->Remove("a")->HasError()); | 83 EXPECT_FALSE(storage_->Remove("a")->HasError()); |
84 EXPECT_FALSE(storage_->Remove("b")->HasError()); | 84 EXPECT_FALSE(storage_->Remove("b")->HasError()); |
85 EXPECT_TRUE(SettingsEqual(empty)); | 85 EXPECT_TRUE(SettingsEqual(empty)); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 586 |
587 storage_->Set(DEFAULTS, "c", *byte_value_1_); | 587 storage_->Set(DEFAULTS, "c", *byte_value_1_); |
588 | 588 |
589 EXPECT_EQ(6u, storage_->GetBytesInUse()); | 589 EXPECT_EQ(6u, storage_->GetBytesInUse()); |
590 EXPECT_EQ(2u, storage_->GetBytesInUse("a")); | 590 EXPECT_EQ(2u, storage_->GetBytesInUse("a")); |
591 EXPECT_EQ(2u, storage_->GetBytesInUse("b")); | 591 EXPECT_EQ(2u, storage_->GetBytesInUse("b")); |
592 EXPECT_EQ(4u, storage_->GetBytesInUse(ab)); | 592 EXPECT_EQ(4u, storage_->GetBytesInUse(ab)); |
593 } | 593 } |
594 | 594 |
595 } // namespace extensions | 595 } // namespace extensions |
OLD | NEW |