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 "chrome/browser/extensions/api/storage/policy_value_store.h" | 5 #include "chrome/browser/extensions/api/storage/policy_value_store.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 public: | 43 public: |
44 explicit MutablePolicyValueStore(const base::FilePath& path) | 44 explicit MutablePolicyValueStore(const base::FilePath& path) |
45 : PolicyValueStore(kTestExtensionId, | 45 : PolicyValueStore(kTestExtensionId, |
46 make_scoped_refptr(new SettingsObserverList()), | 46 make_scoped_refptr(new SettingsObserverList()), |
47 scoped_ptr<ValueStore>(new LeveldbValueStore(path))) {} | 47 scoped_ptr<ValueStore>(new LeveldbValueStore(path))) {} |
48 virtual ~MutablePolicyValueStore() {} | 48 virtual ~MutablePolicyValueStore() {} |
49 | 49 |
50 virtual WriteResult Set( | 50 virtual WriteResult Set( |
51 WriteOptions options, | 51 WriteOptions options, |
52 const std::string& key, | 52 const std::string& key, |
53 const base::Value& value) OVERRIDE { | 53 const base::Value& value) override { |
54 return delegate()->Set(options, key, value); | 54 return delegate()->Set(options, key, value); |
55 } | 55 } |
56 | 56 |
57 virtual WriteResult Set( | 57 virtual WriteResult Set( |
58 WriteOptions options, const base::DictionaryValue& values) OVERRIDE { | 58 WriteOptions options, const base::DictionaryValue& values) override { |
59 return delegate()->Set(options, values); | 59 return delegate()->Set(options, values); |
60 } | 60 } |
61 | 61 |
62 virtual WriteResult Remove(const std::string& key) OVERRIDE { | 62 virtual WriteResult Remove(const std::string& key) override { |
63 return delegate()->Remove(key); | 63 return delegate()->Remove(key); |
64 } | 64 } |
65 | 65 |
66 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE { | 66 virtual WriteResult Remove(const std::vector<std::string>& keys) override { |
67 return delegate()->Remove(keys); | 67 return delegate()->Remove(keys); |
68 } | 68 } |
69 | 69 |
70 virtual WriteResult Clear() OVERRIDE { | 70 virtual WriteResult Clear() override { |
71 return delegate()->Clear(); | 71 return delegate()->Clear(); |
72 } | 72 } |
73 | 73 |
74 private: | 74 private: |
75 DISALLOW_COPY_AND_ASSIGN(MutablePolicyValueStore); | 75 DISALLOW_COPY_AND_ASSIGN(MutablePolicyValueStore); |
76 }; | 76 }; |
77 | 77 |
78 ValueStore* Param(const base::FilePath& file_path) { | 78 ValueStore* Param(const base::FilePath& file_path) { |
79 return new MutablePolicyValueStore(file_path); | 79 return new MutablePolicyValueStore(file_path); |
80 } | 80 } |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 INSTANTIATE_TEST_CASE_P( | 84 INSTANTIATE_TEST_CASE_P( |
85 PolicyValueStoreTest, | 85 PolicyValueStoreTest, |
86 ValueStoreTest, | 86 ValueStoreTest, |
87 testing::Values(&Param)); | 87 testing::Values(&Param)); |
88 | 88 |
89 class PolicyValueStoreTest : public testing::Test { | 89 class PolicyValueStoreTest : public testing::Test { |
90 public: | 90 public: |
91 PolicyValueStoreTest() | 91 PolicyValueStoreTest() |
92 : file_thread_(content::BrowserThread::FILE, &loop_) {} | 92 : file_thread_(content::BrowserThread::FILE, &loop_) {} |
93 virtual ~PolicyValueStoreTest() {} | 93 virtual ~PolicyValueStoreTest() {} |
94 | 94 |
95 virtual void SetUp() OVERRIDE { | 95 virtual void SetUp() override { |
96 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 96 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
97 observers_ = new SettingsObserverList(); | 97 observers_ = new SettingsObserverList(); |
98 observers_->AddObserver(&observer_); | 98 observers_->AddObserver(&observer_); |
99 store_.reset(new PolicyValueStore( | 99 store_.reset(new PolicyValueStore( |
100 kTestExtensionId, | 100 kTestExtensionId, |
101 observers_, | 101 observers_, |
102 scoped_ptr<ValueStore>( | 102 scoped_ptr<ValueStore>( |
103 new LeveldbValueStore(scoped_temp_dir_.path())))); | 103 new LeveldbValueStore(scoped_temp_dir_.path())))); |
104 } | 104 } |
105 | 105 |
106 virtual void TearDown() OVERRIDE { | 106 virtual void TearDown() override { |
107 observers_->RemoveObserver(&observer_); | 107 observers_->RemoveObserver(&observer_); |
108 store_.reset(); | 108 store_.reset(); |
109 } | 109 } |
110 | 110 |
111 protected: | 111 protected: |
112 base::ScopedTempDir scoped_temp_dir_; | 112 base::ScopedTempDir scoped_temp_dir_; |
113 base::MessageLoop loop_; | 113 base::MessageLoop loop_; |
114 content::TestBrowserThread file_thread_; | 114 content::TestBrowserThread file_thread_; |
115 scoped_ptr<PolicyValueStore> store_; | 115 scoped_ptr<PolicyValueStore> store_; |
116 MockSettingsObserver observer_; | 116 MockSettingsObserver observer_; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Mock::VerifyAndClearExpectations(&observer_); | 221 Mock::VerifyAndClearExpectations(&observer_); |
222 | 222 |
223 // Don't notify when there aren't any changes. | 223 // Don't notify when there aren't any changes. |
224 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 224 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
225 store_->SetCurrentPolicy(policies); | 225 store_->SetCurrentPolicy(policies); |
226 loop_.RunUntilIdle(); | 226 loop_.RunUntilIdle(); |
227 Mock::VerifyAndClearExpectations(&observer_); | 227 Mock::VerifyAndClearExpectations(&observer_); |
228 } | 228 } |
229 | 229 |
230 } // namespace extensions | 230 } // namespace extensions |
OLD | NEW |