Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: chrome/browser/extensions/settings/settings_quota_unittest.cc

Issue 9284013: Extension Storage API: expose storage quota information to extensions, via: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with use-after-free fixed Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 ASSERT_EQ(256u, validate_sizes.size()); 42 ASSERT_EQ(256u, validate_sizes.size());
43 } 43 }
44 44
45 virtual void TearDown() OVERRIDE { 45 virtual void TearDown() OVERRIDE {
46 ASSERT_TRUE(storage_.get() != NULL); 46 ASSERT_TRUE(storage_.get() != NULL);
47 } 47 }
48 48
49 protected: 49 protected:
50 // Creates |storage_|. Must only be called once. 50 // Creates |storage_|. Must only be called once.
51 void CreateStorage( 51 void CreateStorage(
52 size_t quota_bytes, size_t quota_bytes_per_setting, size_t max_keys) { 52 size_t quota_bytes, size_t quota_bytes_per_item, size_t max_items) {
53 ASSERT_TRUE(storage_.get() == NULL); 53 ASSERT_TRUE(storage_.get() == NULL);
54 SettingsStorageQuotaEnforcer::Limits limits = 54 SettingsStorageQuotaEnforcer::Limits limits =
55 { quota_bytes, quota_bytes_per_setting, max_keys }; 55 { quota_bytes, quota_bytes_per_item, max_items };
56 storage_.reset(new SettingsStorageQuotaEnforcer(limits, delegate_)); 56 storage_.reset(new SettingsStorageQuotaEnforcer(limits, delegate_));
57 } 57 }
58 58
59 // Returns whether the settings in |storage_| and |delegate_| are the same as 59 // Returns whether the settings in |storage_| and |delegate_| are the same as
60 // |settings|. 60 // |settings|.
61 bool SettingsEqual(const DictionaryValue& settings) { 61 bool SettingsEqual(const DictionaryValue& settings) {
62 return settings.Equals(&storage_->Get().settings()) && 62 return settings.Equals(&storage_->Get().settings()) &&
63 settings.Equals(&delegate_->Get().settings()); 63 settings.Equals(&delegate_->Get().settings());
64 } 64 }
65 65
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", *byte_value_1_).HasError()); 550 EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", *byte_value_1_).HasError());
551 EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", *byte_value_16_).HasError()); 551 EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", *byte_value_16_).HasError());
552 settings.Set("c", byte_value_16_->DeepCopy()); 552 settings.Set("c", byte_value_16_->DeepCopy());
553 553
554 // ... except the last. Make sure it can still fail. 554 // ... except the last. Make sure it can still fail.
555 EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_).HasError()); 555 EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_).HasError());
556 556
557 EXPECT_TRUE(SettingsEqual(settings)); 557 EXPECT_TRUE(SettingsEqual(settings));
558 } 558 }
559 559
560 TEST_F(ExtensionSettingsQuotaTest, GetBytesInUse) {
561 // Just testing GetBytesInUse, no need for a quota.
562 CreateStorage(UINT_MAX, UINT_MAX, UINT_MAX);
563
564 std::vector<std::string> ab;
565 ab.push_back("a");
566 ab.push_back("b");
567
568 EXPECT_EQ(0u, storage_->GetBytesInUse());
569 EXPECT_EQ(0u, storage_->GetBytesInUse("a"));
570 EXPECT_EQ(0u, storage_->GetBytesInUse("b"));
571 EXPECT_EQ(0u, storage_->GetBytesInUse(ab));
572
573 storage_->Set(DEFAULTS, "a", *byte_value_1_);
574
575 EXPECT_EQ(2u, storage_->GetBytesInUse());
576 EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
577 EXPECT_EQ(0u, storage_->GetBytesInUse("b"));
578 EXPECT_EQ(2u, storage_->GetBytesInUse(ab));
579
580 storage_->Set(DEFAULTS, "b", *byte_value_1_);
581
582 EXPECT_EQ(4u, storage_->GetBytesInUse());
583 EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
584 EXPECT_EQ(2u, storage_->GetBytesInUse("b"));
585 EXPECT_EQ(4u, storage_->GetBytesInUse(ab));
586
587 storage_->Set(DEFAULTS, "c", *byte_value_1_);
588
589 EXPECT_EQ(6u, storage_->GetBytesInUse());
590 EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
591 EXPECT_EQ(2u, storage_->GetBytesInUse("b"));
592 EXPECT_EQ(4u, storage_->GetBytesInUse(ab));
593 }
594
560 } // namespace extensions 595 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_leveldb_storage.cc ('k') | chrome/browser/extensions/settings/settings_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698