#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
-#include "chrome/browser/extensions/api/storage/settings_observer.h"
-#include "chrome/browser/policy/external_data_fetcher.h"
-#include "chrome/browser/policy/policy_map.h"
-#include "chrome/browser/value_store/leveldb_value_store.h"
-#include "chrome/browser/value_store/value_store_unittest.h"
+#include "components/policy/core/common/external_data_fetcher.h"
+#include "components/policy/core/common/policy_map.h"
#include "content/public/test/test_browser_thread.h"
+#include "extensions/browser/api/storage/settings_observer.h"
+#include "extensions/browser/value_store/leveldb_value_store.h"
+#include "extensions/browser/value_store/value_store_unittest.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
: PolicyValueStore(kTestExtensionId,
make_scoped_refptr(new SettingsObserverList()),
scoped_ptr<ValueStore>(new LeveldbValueStore(path))) {}
- virtual ~MutablePolicyValueStore() {}
+ ~MutablePolicyValueStore() override {}
- virtual WriteResult Set(
- WriteOptions options,
- const std::string& key,
- const base::Value& value) OVERRIDE {
+ WriteResult Set(WriteOptions options,
+ const std::string& key,
+ const base::Value& value) override {
return delegate()->Set(options, key, value);
}
- virtual WriteResult Set(
- WriteOptions options, const base::DictionaryValue& values) OVERRIDE {
+ WriteResult Set(WriteOptions options,
+ const base::DictionaryValue& values) override {
return delegate()->Set(options, values);
}
- virtual WriteResult Remove(const std::string& key) OVERRIDE {
+ WriteResult Remove(const std::string& key) override {
return delegate()->Remove(key);
}
- virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE {
+ WriteResult Remove(const std::vector<std::string>& keys) override {
return delegate()->Remove(keys);
}
- virtual WriteResult Clear() OVERRIDE {
- return delegate()->Clear();
- }
+ WriteResult Clear() override { return delegate()->Clear(); }
private:
DISALLOW_COPY_AND_ASSIGN(MutablePolicyValueStore);
public:
PolicyValueStoreTest()
: file_thread_(content::BrowserThread::FILE, &loop_) {}
- virtual ~PolicyValueStoreTest() {}
+ ~PolicyValueStoreTest() override {}
- virtual void SetUp() OVERRIDE {
+ void SetUp() override {
ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
observers_ = new SettingsObserverList();
observers_->AddObserver(&observer_);
new LeveldbValueStore(scoped_temp_dir_.path()))));
}
- virtual void TearDown() OVERRIDE {
+ void TearDown() override {
observers_->RemoveObserver(&observer_);
store_.reset();
}
policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED,
policy::POLICY_SCOPE_USER,
new base::FundamentalValue(456), NULL);
- store_->SetCurrentPolicy(policies, false);
+ store_->SetCurrentPolicy(policies);
ValueStore::ReadResult result = store_->Get();
ASSERT_FALSE(result->HasError());
EXPECT_EQ(1u, result->settings().size());
}
TEST_F(PolicyValueStoreTest, NotifyOnChanges) {
- policy::PolicyMap policies;
- policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
- new base::StringValue("111"), NULL);
- EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0);
- // No notification when setting the initial policy.
- store_->SetCurrentPolicy(policies, false);
- loop_.RunUntilIdle();
- Mock::VerifyAndClearExpectations(&observer_);
+ // Notify when setting the initial policy.
+ const base::StringValue value("111");
+ {
+ ValueStoreChangeList changes;
+ changes.push_back(ValueStoreChange("aaa", NULL, value.DeepCopy()));
+ EXPECT_CALL(observer_,
+ OnSettingsChanged(kTestExtensionId,
+ settings_namespace::MANAGED,
+ ValueStoreChange::ToJson(changes)));
+ }
- // And no notifications on changes when not asked for.
+ policy::PolicyMap policies;
policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
- new base::StringValue("222"), NULL);
- policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
- new base::StringValue("223"), NULL);
- EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0);
- store_->SetCurrentPolicy(policies, false);
+ value.DeepCopy(), NULL);
+ store_->SetCurrentPolicy(policies);
loop_.RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer_);
// Notify when new policies are added.
- ValueStoreChangeList changes;
- base::StringValue value("333");
- changes.push_back(ValueStoreChange("ccc", NULL, value.DeepCopy()));
- policies.Set("ccc", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
+ {
+ ValueStoreChangeList changes;
+ changes.push_back(ValueStoreChange("bbb", NULL, value.DeepCopy()));
+ EXPECT_CALL(observer_,
+ OnSettingsChanged(kTestExtensionId,
+ settings_namespace::MANAGED,
+ ValueStoreChange::ToJson(changes)));
+ }
+
+ policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
value.DeepCopy(), NULL);
- EXPECT_CALL(observer_, OnSettingsChanged(kTestExtensionId,
- settings_namespace::MANAGED,
- ValueStoreChange::ToJson(changes)));
- store_->SetCurrentPolicy(policies, true);
+ store_->SetCurrentPolicy(policies);
loop_.RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer_);
// Notify when policies change.
- changes.clear();
- base::StringValue new_value("444");
- changes.push_back(
- ValueStoreChange("ccc", value.DeepCopy(), new_value.DeepCopy()));
- policies.Set("ccc", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
+ const base::StringValue new_value("222");
+ {
+ ValueStoreChangeList changes;
+ changes.push_back(
+ ValueStoreChange("bbb", value.DeepCopy(), new_value.DeepCopy()));
+ EXPECT_CALL(observer_,
+ OnSettingsChanged(kTestExtensionId,
+ settings_namespace::MANAGED,
+ ValueStoreChange::ToJson(changes)));
+ }
+
+ policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
new_value.DeepCopy(), NULL);
- EXPECT_CALL(observer_, OnSettingsChanged(kTestExtensionId,
- settings_namespace::MANAGED,
- ValueStoreChange::ToJson(changes)));
- store_->SetCurrentPolicy(policies, true);
+ store_->SetCurrentPolicy(policies);
loop_.RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer_);
// Notify when policies are removed.
- changes.clear();
- changes.push_back(ValueStoreChange("ccc", new_value.DeepCopy(), NULL));
- policies.Erase("ccc");
- EXPECT_CALL(observer_, OnSettingsChanged(kTestExtensionId,
- settings_namespace::MANAGED,
- ValueStoreChange::ToJson(changes)));
- store_->SetCurrentPolicy(policies, true);
+ {
+ ValueStoreChangeList changes;
+ changes.push_back(ValueStoreChange("bbb", new_value.DeepCopy(), NULL));
+ EXPECT_CALL(observer_,
+ OnSettingsChanged(kTestExtensionId,
+ settings_namespace::MANAGED,
+ ValueStoreChange::ToJson(changes)));
+ }
+
+ policies.Erase("bbb");
+ store_->SetCurrentPolicy(policies);
loop_.RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer_);
- // Don't notify when there aren't changes.
+ // Don't notify when there aren't any changes.
EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0);
- store_->SetCurrentPolicy(policies, true);
+ store_->SetCurrentPolicy(policies);
loop_.RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer_);
}