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

Side by Side Diff: extensions/browser/api/storage/settings_quota_unittest.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory>
8
7 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/ptr_util.h"
8 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" 13 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h"
12 #include "extensions/browser/value_store/testing_value_store.h" 14 #include "extensions/browser/value_store/testing_value_store.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 using base::DictionaryValue; 17 using base::DictionaryValue;
16 using base::ListValue; 18 using base::ListValue;
17 using base::Value; 19 using base::Value;
18 20
19 namespace extensions { 21 namespace extensions {
(...skipping 28 matching lines...) Expand all
48 void TearDown() override { ASSERT_TRUE(storage_.get() != NULL); } 50 void TearDown() override { ASSERT_TRUE(storage_.get() != NULL); }
49 51
50 protected: 52 protected:
51 // Creates |storage_|. Must only be called once. 53 // Creates |storage_|. Must only be called once.
52 void CreateStorage( 54 void CreateStorage(
53 size_t quota_bytes, size_t quota_bytes_per_item, size_t max_items) { 55 size_t quota_bytes, size_t quota_bytes_per_item, size_t max_items) {
54 ASSERT_TRUE(storage_.get() == NULL); 56 ASSERT_TRUE(storage_.get() == NULL);
55 SettingsStorageQuotaEnforcer::Limits limits = 57 SettingsStorageQuotaEnforcer::Limits limits =
56 { quota_bytes, quota_bytes_per_item, max_items }; 58 { quota_bytes, quota_bytes_per_item, max_items };
57 storage_.reset( 59 storage_.reset(
58 new SettingsStorageQuotaEnforcer(limits, make_scoped_ptr(delegate_))); 60 new SettingsStorageQuotaEnforcer(limits, base::WrapUnique(delegate_)));
59 } 61 }
60 62
61 // Returns whether the settings in |storage_| and |delegate_| are the same as 63 // Returns whether the settings in |storage_| and |delegate_| are the same as
62 // |settings|. 64 // |settings|.
63 bool SettingsEqual(const base::DictionaryValue& settings) { 65 bool SettingsEqual(const base::DictionaryValue& settings) {
64 return settings.Equals(&storage_->Get()->settings()) && 66 return settings.Equals(&storage_->Get()->settings()) &&
65 settings.Equals(&delegate_->Get()->settings()); 67 settings.Equals(&delegate_->Get()->settings());
66 } 68 }
67 69
68 // Values with different serialized sizes. 70 // Values with different serialized sizes.
69 base::FundamentalValue byte_value_1_; 71 base::FundamentalValue byte_value_1_;
70 base::StringValue byte_value_16_; 72 base::StringValue byte_value_16_;
71 base::ListValue byte_value_256_; 73 base::ListValue byte_value_256_;
72 74
73 // Quota enforcing storage area being tested. 75 // Quota enforcing storage area being tested.
74 scoped_ptr<SettingsStorageQuotaEnforcer> storage_; 76 std::unique_ptr<SettingsStorageQuotaEnforcer> storage_;
75 77
76 // In-memory storage area being delegated to. Always owned by |storage_|. 78 // In-memory storage area being delegated to. Always owned by |storage_|.
77 TestingValueStore* delegate_; 79 TestingValueStore* delegate_;
78 }; 80 };
79 81
80 TEST_F(ExtensionSettingsQuotaTest, ZeroQuotaBytes) { 82 TEST_F(ExtensionSettingsQuotaTest, ZeroQuotaBytes) {
81 base::DictionaryValue empty; 83 base::DictionaryValue empty;
82 CreateStorage(0, UINT_MAX, UINT_MAX); 84 CreateStorage(0, UINT_MAX, UINT_MAX);
83 85
84 EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->status().ok()); 86 EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->status().ok());
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 590
589 storage_->Set(DEFAULTS, "c", byte_value_1_); 591 storage_->Set(DEFAULTS, "c", byte_value_1_);
590 592
591 EXPECT_EQ(6u, storage_->GetBytesInUse()); 593 EXPECT_EQ(6u, storage_->GetBytesInUse());
592 EXPECT_EQ(2u, storage_->GetBytesInUse("a")); 594 EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
593 EXPECT_EQ(2u, storage_->GetBytesInUse("b")); 595 EXPECT_EQ(2u, storage_->GetBytesInUse("b"));
594 EXPECT_EQ(4u, storage_->GetBytesInUse(ab)); 596 EXPECT_EQ(4u, storage_->GetBytesInUse(ab));
595 } 597 }
596 598
597 } // namespace extensions 599 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698