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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/message_loop/message_loop.h" | |
16 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
17 #include "components/policy/core/common/external_data_fetcher.h" | 16 #include "components/policy/core/common/external_data_fetcher.h" |
18 #include "components/policy/core/common/policy_map.h" | 17 #include "components/policy/core/common/policy_map.h" |
19 #include "components/policy/core/common/policy_types.h" | 18 #include "components/policy/core/common/policy_types.h" |
20 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "extensions/browser/api/storage/settings_observer.h" | 20 #include "extensions/browser/api/storage/settings_observer.h" |
22 #include "extensions/browser/value_store/leveldb_value_store.h" | 21 #include "extensions/browser/value_store/leveldb_value_store.h" |
23 #include "extensions/browser/value_store/value_store_unittest.h" | 22 #include "extensions/browser/value_store/value_store_unittest.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 | 25 |
27 using testing::_; | 26 using testing::_; |
28 using testing::Mock; | 27 using testing::Mock; |
29 | 28 |
30 namespace extensions { | 29 namespace extensions { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 85 |
87 } // namespace | 86 } // namespace |
88 | 87 |
89 INSTANTIATE_TEST_CASE_P( | 88 INSTANTIATE_TEST_CASE_P( |
90 PolicyValueStoreTest, | 89 PolicyValueStoreTest, |
91 ValueStoreTest, | 90 ValueStoreTest, |
92 testing::Values(&Param)); | 91 testing::Values(&Param)); |
93 | 92 |
94 class PolicyValueStoreTest : public testing::Test { | 93 class PolicyValueStoreTest : public testing::Test { |
95 public: | 94 public: |
96 PolicyValueStoreTest() | 95 PolicyValueStoreTest() = default; |
97 : file_thread_(content::BrowserThread::FILE, &loop_) {} | |
98 ~PolicyValueStoreTest() override {} | 96 ~PolicyValueStoreTest() override {} |
99 | 97 |
100 void SetUp() override { | 98 void SetUp() override { |
101 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 99 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
102 observers_ = new SettingsObserverList(); | 100 observers_ = new SettingsObserverList(); |
103 observers_->AddObserver(&observer_); | 101 observers_->AddObserver(&observer_); |
104 store_.reset(new PolicyValueStore( | 102 store_.reset(new PolicyValueStore( |
105 kTestExtensionId, observers_, | 103 kTestExtensionId, observers_, |
106 base::MakeUnique<LeveldbValueStore>(kDatabaseUMAClientName, | 104 base::MakeUnique<LeveldbValueStore>(kDatabaseUMAClientName, |
107 scoped_temp_dir_.GetPath()))); | 105 scoped_temp_dir_.GetPath()))); |
108 } | 106 } |
109 | 107 |
110 void TearDown() override { | 108 void TearDown() override { |
111 observers_->RemoveObserver(&observer_); | 109 observers_->RemoveObserver(&observer_); |
112 store_.reset(); | 110 store_.reset(); |
113 } | 111 } |
114 | 112 |
115 protected: | 113 protected: |
116 base::ScopedTempDir scoped_temp_dir_; | 114 base::ScopedTempDir scoped_temp_dir_; |
117 base::MessageLoop loop_; | 115 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
118 content::TestBrowserThread file_thread_; | |
119 std::unique_ptr<PolicyValueStore> store_; | 116 std::unique_ptr<PolicyValueStore> store_; |
120 MockSettingsObserver observer_; | 117 MockSettingsObserver observer_; |
121 scoped_refptr<SettingsObserverList> observers_; | 118 scoped_refptr<SettingsObserverList> observers_; |
122 }; | 119 }; |
123 | 120 |
124 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { | 121 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { |
125 policy::PolicyMap policies; | 122 policy::PolicyMap policies; |
126 base::Value expected(123); | 123 base::Value expected(123); |
127 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, | 124 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, |
128 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 125 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 Mock::VerifyAndClearExpectations(&observer_); | 225 Mock::VerifyAndClearExpectations(&observer_); |
229 | 226 |
230 // Don't notify when there aren't any changes. | 227 // Don't notify when there aren't any changes. |
231 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 228 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
232 store_->SetCurrentPolicy(policies); | 229 store_->SetCurrentPolicy(policies); |
233 base::RunLoop().RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
234 Mock::VerifyAndClearExpectations(&observer_); | 231 Mock::VerifyAndClearExpectations(&observer_); |
235 } | 232 } |
236 | 233 |
237 } // namespace extensions | 234 } // namespace extensions |
OLD | NEW |