| 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/policy/configuration_policy_provider_test.h" | 5 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/policy/asynchronous_policy_loader.h" | 10 #include "chrome/browser/policy/asynchronous_policy_loader.h" |
| 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" | 11 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 12 #include "chrome/browser/policy/configuration_policy_provider.h" | 12 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 14 #include "chrome/browser/policy/policy_bundle.h" | 14 #include "chrome/browser/policy/policy_bundle.h" |
| 15 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 | 18 |
| 19 using content::BrowserThread; |
| 19 using ::testing::Mock; | 20 using ::testing::Mock; |
| 20 using ::testing::_; | 21 using ::testing::_; |
| 21 | 22 |
| 22 namespace policy { | 23 namespace policy { |
| 23 | 24 |
| 24 namespace test_policy_definitions { | 25 namespace test_policy_definitions { |
| 25 | 26 |
| 26 const char kKeyString[] = "StringPolicy"; | 27 const char kKeyString[] = "StringPolicy"; |
| 27 const char kKeyBoolean[] = "BooleanPolicy"; | 28 const char kKeyBoolean[] = "BooleanPolicy"; |
| 28 const char kKeyInteger[] = "IntegerPolicy"; | 29 const char kKeyInteger[] = "IntegerPolicy"; |
| 29 const char kKeyStringList[] = "StringListPolicy"; | 30 const char kKeyStringList[] = "StringListPolicy"; |
| 30 const char kKeyDictionary[] = "DictionaryPolicy"; | 31 const char kKeyDictionary[] = "DictionaryPolicy"; |
| 31 | 32 |
| 32 static const PolicyDefinitionList::Entry kEntries[] = { | 33 static const PolicyDefinitionList::Entry kEntries[] = { |
| 33 { kKeyString, base::Value::TYPE_STRING }, | 34 { kKeyString, base::Value::TYPE_STRING }, |
| 34 { kKeyBoolean, base::Value::TYPE_BOOLEAN }, | 35 { kKeyBoolean, base::Value::TYPE_BOOLEAN }, |
| 35 { kKeyInteger, base::Value::TYPE_INTEGER }, | 36 { kKeyInteger, base::Value::TYPE_INTEGER }, |
| 36 { kKeyStringList, base::Value::TYPE_LIST }, | 37 { kKeyStringList, base::Value::TYPE_LIST }, |
| 37 { kKeyDictionary, base::Value::TYPE_DICTIONARY }, | 38 { kKeyDictionary, base::Value::TYPE_DICTIONARY }, |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 const PolicyDefinitionList kList = { | 41 const PolicyDefinitionList kList = { |
| 41 kEntries, kEntries + arraysize(kEntries) | 42 kEntries, kEntries + arraysize(kEntries) |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 } // namespace test_policy_definitions | 45 } // namespace test_policy_definitions |
| 45 | 46 |
| 47 PolicyTestBase::PolicyTestBase() |
| 48 : ui_thread_(BrowserThread::UI, &loop_), |
| 49 file_thread_(BrowserThread::FILE, &loop_) {} |
| 50 |
| 51 PolicyTestBase::~PolicyTestBase() {} |
| 52 |
| 53 void PolicyTestBase::TearDown() { |
| 54 loop_.RunAllPending(); |
| 55 } |
| 56 |
| 46 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, | 57 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, |
| 47 PolicyScope scope) | 58 PolicyScope scope) |
| 48 : level_(level), scope_(scope) {} | 59 : level_(level), scope_(scope) {} |
| 49 | 60 |
| 50 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} | 61 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} |
| 51 | 62 |
| 52 PolicyLevel PolicyProviderTestHarness::policy_level() const { | 63 PolicyLevel PolicyProviderTestHarness::policy_level() const { |
| 53 return level_; | 64 return level_; |
| 54 } | 65 } |
| 55 | 66 |
| 56 PolicyScope PolicyProviderTestHarness::policy_scope() const { | 67 PolicyScope PolicyProviderTestHarness::policy_scope() const { |
| 57 return scope_; | 68 return scope_; |
| 58 } | 69 } |
| 59 | 70 |
| 60 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} | 71 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} |
| 61 | 72 |
| 62 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} | 73 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} |
| 63 | 74 |
| 64 void ConfigurationPolicyProviderTest::SetUp() { | 75 void ConfigurationPolicyProviderTest::SetUp() { |
| 65 AsynchronousPolicyTestBase::SetUp(); | 76 PolicyTestBase::SetUp(); |
| 66 | 77 |
| 67 test_harness_.reset((*GetParam())()); | 78 test_harness_.reset((*GetParam())()); |
| 68 test_harness_->SetUp(); | 79 test_harness_->SetUp(); |
| 69 | 80 |
| 70 provider_.reset( | 81 provider_.reset( |
| 71 test_harness_->CreateProvider(&test_policy_definitions::kList)); | 82 test_harness_->CreateProvider(&test_policy_definitions::kList)); |
| 72 // Some providers do a reload on init. Make sure any notifications generated | 83 // Some providers do a reload on init. Make sure any notifications generated |
| 73 // are fired now. | 84 // are fired now. |
| 74 loop_.RunAllPending(); | 85 loop_.RunAllPending(); |
| 75 | 86 |
| 76 const PolicyBundle kEmptyBundle; | 87 const PolicyBundle kEmptyBundle; |
| 77 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 88 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
| 78 } | 89 } |
| 79 | 90 |
| 80 void ConfigurationPolicyProviderTest::TearDown() { | 91 void ConfigurationPolicyProviderTest::TearDown() { |
| 81 // Give providers the chance to clean up after themselves on the file thread. | 92 // Give providers the chance to clean up after themselves on the file thread. |
| 82 provider_.reset(); | 93 provider_.reset(); |
| 83 | 94 |
| 84 AsynchronousPolicyTestBase::TearDown(); | 95 PolicyTestBase::TearDown(); |
| 85 } | 96 } |
| 86 | 97 |
| 87 void ConfigurationPolicyProviderTest::CheckValue( | 98 void ConfigurationPolicyProviderTest::CheckValue( |
| 88 const char* policy_name, | 99 const char* policy_name, |
| 89 const base::Value& expected_value, | 100 const base::Value& expected_value, |
| 90 base::Closure install_value) { | 101 base::Closure install_value) { |
| 91 // Install the value, reload policy and check the provider for the value. | 102 // Install the value, reload policy and check the provider for the value. |
| 92 install_value.Run(); | 103 install_value.Run(); |
| 93 provider_->RefreshPolicies(); | 104 provider_->RefreshPolicies(); |
| 94 loop_.RunAllPending(); | 105 loop_.RunAllPending(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 PolicyBundle expected_bundle; | 252 PolicyBundle expected_bundle; |
| 242 base::DictionaryValue* expected_value = new base::DictionaryValue(); | 253 base::DictionaryValue* expected_value = new base::DictionaryValue(); |
| 243 expected_value->SetInteger(key::kProxyServerMode, 3); | 254 expected_value->SetInteger(key::kProxyServerMode, 3); |
| 244 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") | 255 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") |
| 245 .Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 256 .Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 246 expected_value); | 257 expected_value); |
| 247 EXPECT_TRUE(provider.policies().Equals(expected_bundle)); | 258 EXPECT_TRUE(provider.policies().Equals(expected_bundle)); |
| 248 } | 259 } |
| 249 | 260 |
| 250 } // namespace policy | 261 } // namespace policy |
| OLD | NEW |