| 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 "base/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/storage/settings_backend.h" | 9 #include "chrome/browser/extensions/api/storage/settings_backend.h" |
| 10 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.
h" | 10 #include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.
h" |
| 11 #include "chrome/browser/value_store/testing_value_store.h" | 11 #include "chrome/browser/value_store/testing_value_store.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using base::DictionaryValue; | 14 using base::DictionaryValue; |
| 15 using base::ListValue; | 15 using base::ListValue; |
| 16 using base::Value; | 16 using base::Value; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 // To save typing ValueStore::DEFAULTS/IGNORE_QUOTA everywhere. | 20 // To save typing ValueStore::DEFAULTS/IGNORE_QUOTA everywhere. |
| 21 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; | 21 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; |
| 22 const ValueStore::WriteOptions IGNORE_QUOTA = | 22 const ValueStore::WriteOptions IGNORE_QUOTA = |
| 23 ValueStore::IGNORE_QUOTA; | 23 ValueStore::IGNORE_QUOTA; |
| 24 | 24 |
| 25 class ExtensionSettingsQuotaTest : public testing::Test { | 25 class ExtensionSettingsQuotaTest : public testing::Test { |
| 26 public: | 26 public: |
| 27 ExtensionSettingsQuotaTest() | 27 ExtensionSettingsQuotaTest() |
| 28 : byte_value_1_(Value::CreateIntegerValue(1)), | 28 : byte_value_1_(new base::FundamentalValue(1)), |
| 29 byte_value_16_(Value::CreateStringValue("sixteen bytes.")), | 29 byte_value_16_(new base::StringValue("sixteen bytes.")), |
| 30 byte_value_256_(new ListValue()), | 30 byte_value_256_(new ListValue()), |
| 31 delegate_(new TestingValueStore()) { | 31 delegate_(new TestingValueStore()) { |
| 32 for (int i = 1; i < 89; ++i) { | 32 for (int i = 1; i < 89; ++i) { |
| 33 byte_value_256_->Append(Value::CreateIntegerValue(i)); | 33 byte_value_256_->Append(new base::FundamentalValue(i)); |
| 34 } | 34 } |
| 35 ValidateByteValues(); | 35 ValidateByteValues(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ValidateByteValues() { | 38 void ValidateByteValues() { |
| 39 std::string validate_sizes; | 39 std::string validate_sizes; |
| 40 base::JSONWriter::Write(byte_value_1_.get(), &validate_sizes); | 40 base::JSONWriter::Write(byte_value_1_.get(), &validate_sizes); |
| 41 ASSERT_EQ(1u, validate_sizes.size()); | 41 ASSERT_EQ(1u, validate_sizes.size()); |
| 42 base::JSONWriter::Write(byte_value_16_.get(), &validate_sizes); | 42 base::JSONWriter::Write(byte_value_16_.get(), &validate_sizes); |
| 43 ASSERT_EQ(16u, validate_sizes.size()); | 43 ASSERT_EQ(16u, validate_sizes.size()); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 589 |
| 590 storage_->Set(DEFAULTS, "c", *byte_value_1_); | 590 storage_->Set(DEFAULTS, "c", *byte_value_1_); |
| 591 | 591 |
| 592 EXPECT_EQ(6u, storage_->GetBytesInUse()); | 592 EXPECT_EQ(6u, storage_->GetBytesInUse()); |
| 593 EXPECT_EQ(2u, storage_->GetBytesInUse("a")); | 593 EXPECT_EQ(2u, storage_->GetBytesInUse("a")); |
| 594 EXPECT_EQ(2u, storage_->GetBytesInUse("b")); | 594 EXPECT_EQ(2u, storage_->GetBytesInUse("b")); |
| 595 EXPECT_EQ(4u, storage_->GetBytesInUse(ab)); | 595 EXPECT_EQ(4u, storage_->GetBytesInUse(ab)); |
| 596 } | 596 } |
| 597 | 597 |
| 598 } // namespace extensions | 598 } // namespace extensions |
| OLD | NEW |