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

Side by Side Diff: chrome/browser/extensions/api/storage/policy_value_store_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header 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 (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 "chrome/browser/extensions/api/storage/policy_value_store.h" 5 #include "chrome/browser/extensions/api/storage/policy_value_store.h"
6 6
7 #include <memory>
8
7 #include "base/callback.h" 9 #include "base/callback.h"
8 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
10 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
11 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "components/policy/core/common/external_data_fetcher.h" 16 #include "components/policy/core/common/external_data_fetcher.h"
15 #include "components/policy/core/common/policy_map.h" 17 #include "components/policy/core/common/policy_map.h"
16 #include "components/policy/core/common/policy_types.h" 18 #include "components/policy/core/common/policy_types.h"
17 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
18 #include "extensions/browser/api/storage/settings_observer.h" 20 #include "extensions/browser/api/storage/settings_observer.h"
19 #include "extensions/browser/value_store/leveldb_value_store.h" 21 #include "extensions/browser/value_store/leveldb_value_store.h"
20 #include "extensions/browser/value_store/value_store_unittest.h" 22 #include "extensions/browser/value_store/value_store_unittest.h"
21 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 18 matching lines...) Expand all
41 43
42 // Extends PolicyValueStore by overriding the mutating methods, so that the 44 // Extends PolicyValueStore by overriding the mutating methods, so that the
43 // Get() base implementation can be tested with the ValueStoreTest parameterized 45 // Get() base implementation can be tested with the ValueStoreTest parameterized
44 // tests. 46 // tests.
45 class MutablePolicyValueStore : public PolicyValueStore { 47 class MutablePolicyValueStore : public PolicyValueStore {
46 public: 48 public:
47 explicit MutablePolicyValueStore(const base::FilePath& path) 49 explicit MutablePolicyValueStore(const base::FilePath& path)
48 : PolicyValueStore( 50 : PolicyValueStore(
49 kTestExtensionId, 51 kTestExtensionId,
50 make_scoped_refptr(new SettingsObserverList()), 52 make_scoped_refptr(new SettingsObserverList()),
51 make_scoped_ptr( 53 base::WrapUnique(
52 new LeveldbValueStore(kDatabaseUMAClientName, path))) {} 54 new LeveldbValueStore(kDatabaseUMAClientName, path))) {}
53 ~MutablePolicyValueStore() override {} 55 ~MutablePolicyValueStore() override {}
54 56
55 WriteResult Set(WriteOptions options, 57 WriteResult Set(WriteOptions options,
56 const std::string& key, 58 const std::string& key,
57 const base::Value& value) override { 59 const base::Value& value) override {
58 return delegate()->Set(options, key, value); 60 return delegate()->Set(options, key, value);
59 } 61 }
60 62
61 WriteResult Set(WriteOptions options, 63 WriteResult Set(WriteOptions options,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 PolicyValueStoreTest() 95 PolicyValueStoreTest()
94 : file_thread_(content::BrowserThread::FILE, &loop_) {} 96 : file_thread_(content::BrowserThread::FILE, &loop_) {}
95 ~PolicyValueStoreTest() override {} 97 ~PolicyValueStoreTest() override {}
96 98
97 void SetUp() override { 99 void SetUp() override {
98 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 100 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
99 observers_ = new SettingsObserverList(); 101 observers_ = new SettingsObserverList();
100 observers_->AddObserver(&observer_); 102 observers_->AddObserver(&observer_);
101 store_.reset(new PolicyValueStore( 103 store_.reset(new PolicyValueStore(
102 kTestExtensionId, observers_, 104 kTestExtensionId, observers_,
103 make_scoped_ptr(new LeveldbValueStore(kDatabaseUMAClientName, 105 base::WrapUnique(new LeveldbValueStore(kDatabaseUMAClientName,
104 scoped_temp_dir_.path())))); 106 scoped_temp_dir_.path()))));
105 } 107 }
106 108
107 void TearDown() override { 109 void TearDown() override {
108 observers_->RemoveObserver(&observer_); 110 observers_->RemoveObserver(&observer_);
109 store_.reset(); 111 store_.reset();
110 } 112 }
111 113
112 protected: 114 protected:
113 base::ScopedTempDir scoped_temp_dir_; 115 base::ScopedTempDir scoped_temp_dir_;
114 base::MessageLoop loop_; 116 base::MessageLoop loop_;
115 content::TestBrowserThread file_thread_; 117 content::TestBrowserThread file_thread_;
116 scoped_ptr<PolicyValueStore> store_; 118 std::unique_ptr<PolicyValueStore> store_;
117 MockSettingsObserver observer_; 119 MockSettingsObserver observer_;
118 scoped_refptr<SettingsObserverList> observers_; 120 scoped_refptr<SettingsObserverList> observers_;
119 }; 121 };
120 122
121 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { 123 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) {
122 policy::PolicyMap policies; 124 policy::PolicyMap policies;
123 base::FundamentalValue expected(123); 125 base::FundamentalValue expected(123);
124 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, 126 policies.Set("must", policy::POLICY_LEVEL_MANDATORY,
125 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, 127 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
126 expected.DeepCopy(), nullptr); 128 expected.DeepCopy(), nullptr);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 Mock::VerifyAndClearExpectations(&observer_); 225 Mock::VerifyAndClearExpectations(&observer_);
224 226
225 // Don't notify when there aren't any changes. 227 // Don't notify when there aren't any changes.
226 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); 228 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0);
227 store_->SetCurrentPolicy(policies); 229 store_->SetCurrentPolicy(policies);
228 loop_.RunUntilIdle(); 230 loop_.RunUntilIdle();
229 Mock::VerifyAndClearExpectations(&observer_); 231 Mock::VerifyAndClearExpectations(&observer_);
230 } 232 }
231 233
232 } // namespace extensions 234 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/storage/policy_value_store.cc ('k') | chrome/browser/extensions/api/storage/setting_sync_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698