Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 11 #include "chrome/browser/policy/configuration_policy_reader.h" | 11 #include "chrome/browser/policy/configuration_policy_reader.h" |
| 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 13 #include "chrome/browser/policy/mock_configuration_policy_reader.h" | 13 #include "chrome/browser/policy/mock_configuration_policy_reader.h" |
| 14 #include "policy/policy_constants.h" | 14 #include "policy/policy_constants.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using ::testing::Return; | 17 using ::testing::Return; |
| 18 using ::testing::ReturnNull; | 18 using ::testing::ReturnNull; |
| 19 using ::testing::_; | 19 using ::testing::_; |
| 20 | 20 |
| 21 namespace policy { | 21 namespace policy { |
| 22 | 22 |
| 23 class ConfigurationPolicyReaderTest : public testing::Test { | 23 class ConfigurationPolicyReaderTest : public testing::Test { |
| 24 protected: | 24 protected: |
| 25 ConfigurationPolicyReaderTest() : provider_() { | 25 ConfigurationPolicyReaderTest() : provider_() { |
| 26 managed_reader_.reset( | 26 reader_.reset(new ConfigurationPolicyReader(&provider_)); |
| 27 new ConfigurationPolicyReader(&provider_, PolicyStatusInfo::MANDATORY)); | |
| 28 recommended_reader_.reset(new ConfigurationPolicyReader(&provider_, | |
| 29 PolicyStatusInfo::RECOMMENDED)); | |
| 30 status_ok_ = ASCIIToUTF16("OK"); | 27 status_ok_ = ASCIIToUTF16("OK"); |
| 31 } | 28 } |
| 32 | 29 |
| 33 DictionaryValue* CreateDictionary(const char* policy_name, | 30 DictionaryValue* CreateDictionary(const char* policy_name, |
| 34 Value* policy_value) { | 31 Value* policy_value) { |
| 35 DictionaryValue* dict = new DictionaryValue(); | 32 DictionaryValue* dict = new DictionaryValue(); |
| 36 dict->SetString(std::string(PolicyStatusInfo::kNameDictPath), | 33 dict->SetString(PolicyStatusInfo::kNameDictPath, ASCIIToUTF16(policy_name)); |
| 37 ASCIIToUTF16(policy_name)); | 34 dict->SetString(PolicyStatusInfo::kLevelDictPath, |
| 38 dict->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | 35 PolicyStatusInfo::GetPolicyLevelString( |
| 39 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::MANDATORY)); | 36 POLICY_LEVEL_MANDATORY)); |
| 40 dict->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 37 dict->SetString(PolicyStatusInfo::kScopeDictPath, |
| 41 PolicyStatusInfo::GetSourceTypeString(PolicyStatusInfo::USER)); | 38 PolicyStatusInfo::GetPolicyScopeString( |
| 42 dict->Set(std::string(PolicyStatusInfo::kValueDictPath), policy_value); | 39 POLICY_SCOPE_USER)); |
| 43 dict->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), true); | 40 dict->Set(PolicyStatusInfo::kValueDictPath, policy_value); |
| 44 dict->SetString(std::string(PolicyStatusInfo::kStatusDictPath), status_ok_); | 41 dict->SetBoolean(PolicyStatusInfo::kSetDictPath, true); |
| 42 dict->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_); | |
| 45 | 43 |
| 46 return dict; | 44 return dict; |
| 47 } | 45 } |
| 48 | 46 |
| 49 MockConfigurationPolicyProvider provider_; | 47 MockConfigurationPolicyProvider provider_; |
| 50 scoped_ptr<ConfigurationPolicyReader> managed_reader_; | 48 scoped_ptr<ConfigurationPolicyReader> reader_; |
| 51 scoped_ptr<ConfigurationPolicyReader> recommended_reader_; | |
| 52 string16 status_ok_; | 49 string16 status_ok_; |
| 53 }; | 50 }; |
| 54 | 51 |
| 55 TEST_F(ConfigurationPolicyReaderTest, GetDefault) { | 52 TEST_F(ConfigurationPolicyReaderTest, GetDefault) { |
| 56 EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(kPolicyHomepageLocation)); | 53 EXPECT_EQ(NULL, reader_->GetPolicyStatus(key::kHomepageLocation)); |
| 57 } | 54 } |
| 58 | 55 |
| 59 // Test for list-valued policy settings. | 56 // Test for list-valued policy settings. |
| 60 TEST_F(ConfigurationPolicyReaderTest, SetListValue) { | 57 TEST_F(ConfigurationPolicyReaderTest, SetListValue) { |
| 61 ListValue* in_value = new ListValue(); | 58 ListValue in_value; |
| 62 in_value->Append(Value::CreateStringValue("test1")); | 59 in_value.Append(Value::CreateStringValue("test1")); |
| 63 in_value->Append(Value::CreateStringValue("test2")); | 60 in_value.Append(Value::CreateStringValue("test2")); |
| 64 provider_.AddPolicy(kPolicyRestoreOnStartupURLs, in_value); | 61 ListValue recommended_value; |
|
Mattias Nissler (ping if slow)
2012/01/18 15:07:07
if this is called recommend_value, then we should
Joao da Silva
2012/01/18 16:49:29
Done.
| |
| 65 managed_reader_->OnUpdatePolicy(&provider_); | 62 recommended_value.Append(Value::CreateStringValue("test3")); |
| 63 recommended_value.Append(Value::CreateStringValue("test4")); | |
| 64 provider_.AddMandatoryPolicy(key::kRestoreOnStartupURLs, in_value.DeepCopy()); | |
| 65 provider_.AddRecommendedPolicy(key::kDisabledSchemes, | |
| 66 recommended_value.DeepCopy()); | |
| 67 reader_->OnUpdatePolicy(&provider_); | |
| 66 | 68 |
| 67 scoped_ptr<DictionaryValue> | 69 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kRestoreOnStartupURLs, |
| 68 dict(CreateDictionary(key::kRestoreOnStartupURLs, in_value->DeepCopy())); | 70 in_value.DeepCopy())); |
| 69 scoped_ptr<DictionaryValue> result( | 71 scoped_ptr<DictionaryValue> result( |
| 70 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs)); | 72 reader_->GetPolicyStatus(key::kRestoreOnStartupURLs)); |
| 71 EXPECT_TRUE(dict->Equals(result.get())); | 73 EXPECT_TRUE(dict->Equals(result.get())); |
| 72 | 74 |
| 73 recommended_reader_->OnUpdatePolicy(&provider_); | 75 dict.reset(CreateDictionary(key::kDisabledSchemes, |
| 74 dict->SetString("level", | 76 recommended_value.DeepCopy())); |
| 75 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 77 dict->SetString( |
| 76 result.reset( | 78 "level", |
| 77 recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs)); | 79 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 80 result.reset(reader_->GetPolicyStatus(key::kDisabledSchemes)); | |
| 78 EXPECT_TRUE(dict->Equals(result.get())); | 81 EXPECT_TRUE(dict->Equals(result.get())); |
| 79 } | 82 } |
| 80 | 83 |
| 81 // Test for string-valued policy settings. | 84 // Test for string-valued policy settings. |
| 82 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) { | 85 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) { |
| 83 provider_.AddPolicy(kPolicyHomepageLocation, | 86 StringValue string1("http://chromium.org"); |
|
Mattias Nissler (ping if slow)
2012/01/18 15:07:07
maybe call these mandatory_value and recommended_v
Joao da Silva
2012/01/18 16:49:29
Done.
| |
| 84 Value::CreateStringValue("http://chromium.org")); | 87 StringValue string2("http://www.google.com/q={searchTerms}"); |
| 85 managed_reader_->OnUpdatePolicy(&provider_); | 88 provider_.AddMandatoryPolicy(key::kHomepageLocation, string1.DeepCopy()); |
| 89 provider_.AddRecommendedPolicy(key::kDefaultSearchProviderSearchURL, | |
| 90 string2.DeepCopy()); | |
| 91 reader_->OnUpdatePolicy(&provider_); | |
| 86 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kHomepageLocation, | 92 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kHomepageLocation, |
| 87 Value::CreateStringValue("http://chromium.org"))); | 93 string1.DeepCopy())); |
| 88 scoped_ptr<DictionaryValue> result( | 94 scoped_ptr<DictionaryValue> result( |
| 89 managed_reader_->GetPolicyStatus(kPolicyHomepageLocation)); | 95 reader_->GetPolicyStatus(key::kHomepageLocation)); |
| 90 EXPECT_TRUE(dict->Equals(result.get())); | 96 EXPECT_TRUE(dict->Equals(result.get())); |
| 91 | 97 |
| 92 recommended_reader_->OnUpdatePolicy(&provider_); | 98 dict.reset(CreateDictionary(key::kDefaultSearchProviderSearchURL, |
| 93 dict->SetString("level", | 99 string2.DeepCopy())); |
| 94 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 100 dict->SetString( |
| 95 result.reset( | 101 "level", |
| 96 recommended_reader_->GetPolicyStatus(kPolicyHomepageLocation)); | 102 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 103 result.reset(reader_->GetPolicyStatus(key::kDefaultSearchProviderSearchURL)); | |
| 97 EXPECT_TRUE(dict->Equals(result.get())); | 104 EXPECT_TRUE(dict->Equals(result.get())); |
| 98 } | 105 } |
| 99 | 106 |
| 100 // Test for boolean-valued policy settings. | 107 // Test for boolean-valued policy settings. |
| 101 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) { | 108 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) { |
| 102 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(true)); | 109 provider_.AddMandatoryPolicy(key::kShowHomeButton, |
| 103 managed_reader_->OnUpdatePolicy(&provider_); | 110 Value::CreateBooleanValue(true)); |
| 104 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kShowHomeButton, | 111 provider_.AddRecommendedPolicy(key::kHomepageIsNewTabPage, |
| 105 Value::CreateBooleanValue(true))); | 112 Value::CreateBooleanValue(false)); |
| 113 reader_->OnUpdatePolicy(&provider_); | |
| 114 scoped_ptr<DictionaryValue> dict( | |
| 115 CreateDictionary(key::kShowHomeButton, Value::CreateBooleanValue(true))); | |
| 106 scoped_ptr<DictionaryValue> result( | 116 scoped_ptr<DictionaryValue> result( |
| 107 managed_reader_->GetPolicyStatus(kPolicyShowHomeButton)); | 117 reader_->GetPolicyStatus(key::kShowHomeButton)); |
| 108 EXPECT_TRUE(dict->Equals(result.get())); | 118 EXPECT_TRUE(dict->Equals(result.get())); |
| 109 | 119 |
| 110 recommended_reader_->OnUpdatePolicy(&provider_); | 120 dict.reset(CreateDictionary(key::kHomepageIsNewTabPage, |
| 111 dict->SetString("level", | 121 Value::CreateBooleanValue(false))); |
| 112 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 122 dict->SetString( |
| 113 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton)); | 123 "level", |
| 114 EXPECT_TRUE(dict->Equals(result.get())); | 124 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 115 | 125 result.reset(reader_->GetPolicyStatus(key::kHomepageIsNewTabPage)); |
| 116 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(false)); | |
| 117 managed_reader_->OnUpdatePolicy(&provider_); | |
| 118 dict->Set( | |
| 119 PolicyStatusInfo::kValueDictPath, Value::CreateBooleanValue(false)); | |
| 120 dict->SetString("level", | |
| 121 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::MANDATORY)); | |
| 122 result.reset(managed_reader_->GetPolicyStatus(kPolicyShowHomeButton)); | |
| 123 EXPECT_TRUE(dict->Equals(result.get())); | |
| 124 | |
| 125 recommended_reader_->OnUpdatePolicy(&provider_); | |
| 126 dict->SetString("level", | |
| 127 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | |
| 128 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton)); | |
| 129 EXPECT_TRUE(dict->Equals(result.get())); | 126 EXPECT_TRUE(dict->Equals(result.get())); |
| 130 } | 127 } |
| 131 | 128 |
| 132 // Test for integer-valued policy settings. | 129 // Test for integer-valued policy settings. |
| 133 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { | 130 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { |
| 134 provider_.AddPolicy(kPolicyRestoreOnStartup, Value::CreateIntegerValue(3)); | 131 provider_.AddMandatoryPolicy(key::kRestoreOnStartup, |
| 135 managed_reader_->OnUpdatePolicy(&provider_); | 132 Value::CreateIntegerValue(3)); |
| 136 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kRestoreOnStartup, | 133 provider_.AddRecommendedPolicy(key::kIncognitoModeAvailability, |
| 137 Value::CreateIntegerValue(3))); | 134 Value::CreateIntegerValue(2)); |
| 135 reader_->OnUpdatePolicy(&provider_); | |
| 136 scoped_ptr<DictionaryValue> dict( | |
| 137 CreateDictionary(key::kRestoreOnStartup, Value::CreateIntegerValue(3))); | |
| 138 scoped_ptr<DictionaryValue> result( | 138 scoped_ptr<DictionaryValue> result( |
| 139 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartup)); | 139 reader_->GetPolicyStatus(key::kRestoreOnStartup)); |
| 140 EXPECT_TRUE(dict->Equals(result.get())); | 140 EXPECT_TRUE(dict->Equals(result.get())); |
| 141 | 141 |
| 142 recommended_reader_->OnUpdatePolicy(&provider_); | 142 dict.reset(CreateDictionary(key::kIncognitoModeAvailability, |
| 143 dict->SetString("level", | 143 Value::CreateIntegerValue(2))); |
| 144 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 144 dict->SetString( |
| 145 result.reset(recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartup)); | 145 "level", |
| 146 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); | |
| 147 result.reset(reader_->GetPolicyStatus(key::kIncognitoModeAvailability)); | |
| 146 EXPECT_TRUE(dict->Equals(result.get())); | 148 EXPECT_TRUE(dict->Equals(result.get())); |
| 147 } | 149 } |
| 148 | 150 |
| 149 class PolicyStatusTest : public testing::Test { | 151 class PolicyStatusTest : public testing::Test { |
| 150 protected: | 152 protected: |
| 151 PolicyStatusTest() { | 153 PolicyStatusTest() { |
| 152 managed_platform_ = new MockConfigurationPolicyReader(); | 154 managed_platform_ = new MockConfigurationPolicyReader(); |
| 153 managed_cloud_ = new MockConfigurationPolicyReader(); | 155 managed_cloud_ = new MockConfigurationPolicyReader(); |
| 154 recommended_platform_ = new MockConfigurationPolicyReader(); | 156 recommended_platform_ = new MockConfigurationPolicyReader(); |
| 155 recommended_cloud_ = new MockConfigurationPolicyReader(); | 157 recommended_cloud_ = new MockConfigurationPolicyReader(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 179 void SendPolicies() { | 181 void SendPolicies() { |
| 180 EXPECT_CALL(*managed_platform_, GetPolicyStatus(_)) | 182 EXPECT_CALL(*managed_platform_, GetPolicyStatus(_)) |
| 181 .WillRepeatedly(ReturnNull()); | 183 .WillRepeatedly(ReturnNull()); |
| 182 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(_)) | 184 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(_)) |
| 183 .WillRepeatedly(ReturnNull()); | 185 .WillRepeatedly(ReturnNull()); |
| 184 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(_)) | 186 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(_)) |
| 185 .WillRepeatedly(ReturnNull()); | 187 .WillRepeatedly(ReturnNull()); |
| 186 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(_)) | 188 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(_)) |
| 187 .WillRepeatedly(ReturnNull()); | 189 .WillRepeatedly(ReturnNull()); |
| 188 | 190 |
| 189 EXPECT_CALL(*managed_platform_, GetPolicyStatus(kPolicyInstantEnabled)) | 191 EXPECT_CALL(*managed_platform_, GetPolicyStatus(key::kInstantEnabled)) |
| 190 .WillRepeatedly(Return(CreateDictionary(key::kInstantEnabled, | 192 .WillRepeatedly(Return(CreateDictionary(key::kInstantEnabled, |
| 191 PolicyStatusInfo::MANDATORY))); | 193 POLICY_LEVEL_MANDATORY))); |
| 192 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(kPolicyDisablePluginFinder)) | 194 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(key::kDisablePluginFinder)) |
| 193 .WillRepeatedly(Return(CreateDictionary(key::kDisablePluginFinder, | 195 .WillRepeatedly(Return(CreateDictionary(key::kDisablePluginFinder, |
| 194 PolicyStatusInfo::MANDATORY))); | 196 POLICY_LEVEL_MANDATORY))); |
| 195 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(kPolicySyncDisabled)) | 197 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(key::kSyncDisabled)) |
| 196 .WillRepeatedly( | 198 .WillRepeatedly(Return(CreateDictionary(key::kSyncDisabled, |
| 197 Return(CreateDictionary(key::kSyncDisabled, | 199 POLICY_LEVEL_RECOMMENDED))); |
| 198 PolicyStatusInfo::RECOMMENDED))); | 200 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(key::kTranslateEnabled)) |
| 199 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(kPolicyTranslateEnabled)) | 201 .WillRepeatedly(Return(CreateDictionary(key::kTranslateEnabled, |
| 200 .WillRepeatedly( | 202 POLICY_LEVEL_RECOMMENDED))); |
| 201 Return(CreateDictionary(key::kTranslateEnabled, | |
| 202 PolicyStatusInfo::RECOMMENDED))); | |
| 203 } | 203 } |
| 204 | 204 |
| 205 DictionaryValue* CreateDictionary(const char* name, | 205 DictionaryValue* CreateDictionary(const char* name, PolicyLevel level) { |
| 206 PolicyStatusInfo::PolicyLevel level) { | |
| 207 DictionaryValue* value = new DictionaryValue(); | 206 DictionaryValue* value = new DictionaryValue(); |
| 208 value->SetString(std::string(PolicyStatusInfo::kNameDictPath), | 207 value->SetString(PolicyStatusInfo::kNameDictPath, ASCIIToUTF16(name)); |
| 209 ASCIIToUTF16(name)); | 208 value->SetString(PolicyStatusInfo::kLevelDictPath, |
| 210 value->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | |
| 211 PolicyStatusInfo::GetPolicyLevelString(level)); | 209 PolicyStatusInfo::GetPolicyLevelString(level)); |
| 212 value->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 210 value->SetString(PolicyStatusInfo::kScopeDictPath, |
| 213 PolicyStatusInfo::GetSourceTypeString(PolicyStatusInfo::USER)); | 211 PolicyStatusInfo::GetPolicyScopeString(POLICY_SCOPE_USER)); |
| 214 value->SetBoolean(std::string(PolicyStatusInfo::kValueDictPath), true); | 212 value->SetBoolean(PolicyStatusInfo::kValueDictPath, true); |
| 215 value->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), true); | 213 value->SetBoolean(PolicyStatusInfo::kSetDictPath, true); |
| 216 value->SetString(std::string(PolicyStatusInfo::kStatusDictPath), | 214 value->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_); |
| 217 status_ok_); | |
| 218 | 215 |
| 219 return value; | 216 return value; |
| 220 } | 217 } |
| 221 | 218 |
| 222 void SetDictionaryPaths(DictionaryValue* dict, | 219 void SetDictionaryPaths(DictionaryValue* dict, |
| 223 const char* policy_name, | 220 const char* policy_name, |
| 224 bool defined, | 221 bool defined, |
| 225 PolicyStatusInfo::PolicyLevel level) { | 222 PolicyLevel level) { |
| 226 dict->SetString(PolicyStatusInfo::kNameDictPath, | 223 dict->SetString(PolicyStatusInfo::kNameDictPath, |
| 227 ASCIIToUTF16(policy_name)); | 224 ASCIIToUTF16(policy_name)); |
| 228 if (defined) { | 225 if (defined) { |
| 229 dict->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | 226 dict->SetString(PolicyStatusInfo::kLevelDictPath, |
| 230 PolicyStatusInfo::GetPolicyLevelString(level)); | 227 PolicyStatusInfo::GetPolicyLevelString(level)); |
| 231 } | 228 } |
| 232 } | 229 } |
| 233 | 230 |
| 234 MockConfigurationPolicyReader* managed_platform_; | 231 MockConfigurationPolicyReader* managed_platform_; |
| 235 MockConfigurationPolicyReader* managed_cloud_; | 232 MockConfigurationPolicyReader* managed_cloud_; |
| 236 MockConfigurationPolicyReader* recommended_platform_; | 233 MockConfigurationPolicyReader* recommended_platform_; |
| 237 MockConfigurationPolicyReader* recommended_cloud_; | 234 MockConfigurationPolicyReader* recommended_cloud_; |
| 238 scoped_ptr<PolicyStatus> policy_status_; | 235 scoped_ptr<PolicyStatus> policy_status_; |
| 239 const PolicyDefinitionList* policy_list_; | 236 const PolicyDefinitionList* policy_list_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 252 | 249 |
| 253 TEST_F(PolicyStatusTest, GetPolicyStatusListSetPolicies) { | 250 TEST_F(PolicyStatusTest, GetPolicyStatusListSetPolicies) { |
| 254 SendPolicies(); | 251 SendPolicies(); |
| 255 bool any_policies_sent; | 252 bool any_policies_sent; |
| 256 scoped_ptr<ListValue> status_list( | 253 scoped_ptr<ListValue> status_list( |
| 257 policy_status_->GetPolicyStatusList(&any_policies_sent)); | 254 policy_status_->GetPolicyStatusList(&any_policies_sent)); |
| 258 EXPECT_TRUE(any_policies_sent); | 255 EXPECT_TRUE(any_policies_sent); |
| 259 EXPECT_EQ(policy_list_size_, status_list->GetSize()); | 256 EXPECT_EQ(policy_list_size_, status_list->GetSize()); |
| 260 | 257 |
| 261 scoped_ptr<DictionaryValue> undefined_dict(new DictionaryValue()); | 258 scoped_ptr<DictionaryValue> undefined_dict(new DictionaryValue()); |
| 262 undefined_dict->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | 259 undefined_dict->SetString(PolicyStatusInfo::kLevelDictPath, |
| 263 PolicyStatusInfo::GetPolicyLevelString( | 260 PolicyStatusInfo::GetPolicyLevelString( |
| 264 PolicyStatusInfo::LEVEL_UNDEFINED)); | 261 POLICY_LEVEL_MANDATORY)); |
| 265 undefined_dict->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 262 undefined_dict->SetString(PolicyStatusInfo::kScopeDictPath, |
| 266 PolicyStatusInfo::GetSourceTypeString( | 263 PolicyStatusInfo::GetPolicyScopeString( |
| 267 PolicyStatusInfo::SOURCE_TYPE_UNDEFINED)); | 264 POLICY_SCOPE_USER)); |
| 268 undefined_dict->Set(std::string(PolicyStatusInfo::kValueDictPath), | 265 undefined_dict->Set(PolicyStatusInfo::kValueDictPath, |
| 269 Value::CreateNullValue()); | 266 Value::CreateNullValue()); |
| 270 undefined_dict->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), | 267 undefined_dict->SetBoolean(PolicyStatusInfo::kSetDictPath, false); |
| 271 false); | 268 undefined_dict->SetString(PolicyStatusInfo::kStatusDictPath, string16()); |
| 272 undefined_dict->SetString(std::string(PolicyStatusInfo::kStatusDictPath), | |
| 273 string16()); | |
| 274 | 269 |
| 275 scoped_ptr<DictionaryValue> defined_dict(new DictionaryValue()); | 270 scoped_ptr<DictionaryValue> defined_dict(new DictionaryValue()); |
| 276 defined_dict->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 271 defined_dict->SetString(PolicyStatusInfo::kScopeDictPath, |
| 277 PolicyStatusInfo::GetSourceTypeString(PolicyStatusInfo::USER)); | 272 PolicyStatusInfo::GetPolicyScopeString( |
| 278 defined_dict->Set(std::string(PolicyStatusInfo::kValueDictPath), | 273 POLICY_SCOPE_USER)); |
| 274 defined_dict->Set(PolicyStatusInfo::kValueDictPath, | |
| 279 Value::CreateBooleanValue(true)); | 275 Value::CreateBooleanValue(true)); |
| 280 defined_dict->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), true); | 276 defined_dict->SetBoolean(PolicyStatusInfo::kSetDictPath, true); |
| 281 defined_dict->SetString(std::string(PolicyStatusInfo::kStatusDictPath), | 277 defined_dict->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_); |
| 282 status_ok_); | 278 |
| 279 struct { | |
| 280 const char *name; | |
| 281 PolicyLevel level; | |
| 282 } cases[] = { | |
| 283 { key::kInstantEnabled, POLICY_LEVEL_MANDATORY }, | |
| 284 { key::kDisablePluginFinder, POLICY_LEVEL_MANDATORY }, | |
| 285 { key::kSyncDisabled, POLICY_LEVEL_RECOMMENDED }, | |
| 286 { key::kTranslateEnabled, POLICY_LEVEL_RECOMMENDED }, | |
| 287 { NULL, POLICY_LEVEL_MANDATORY }, | |
| 288 }; | |
| 283 | 289 |
| 284 for (const PolicyDefinitionList::Entry* entry = policy_list_->begin; | 290 for (const PolicyDefinitionList::Entry* entry = policy_list_->begin; |
| 285 entry != policy_list_->end; ++entry) { | 291 entry != policy_list_->end; ++entry) { |
| 286 Value* status_dict = NULL; | 292 Value* status_dict = NULL; |
| 287 | 293 |
| 288 // Every policy in |policy_list_| has to appear in the returned ListValue. | 294 // Every policy in |policy_list_| has to appear in the returned ListValue. |
| 289 string16 name = ASCIIToUTF16(entry->name); | 295 string16 name = ASCIIToUTF16(entry->name); |
| 290 for (ListValue::const_iterator status_entry = status_list->begin(); | 296 for (ListValue::const_iterator status_entry = status_list->begin(); |
| 291 status_entry != status_list->end(); | 297 status_entry != status_list->end(); |
| 292 ++status_entry) { | 298 ++status_entry) { |
| 293 string16 value; | 299 string16 value; |
| 294 ASSERT_TRUE((*status_entry)->IsType(Value::TYPE_DICTIONARY)); | 300 ASSERT_TRUE((*status_entry)->IsType(Value::TYPE_DICTIONARY)); |
| 295 DictionaryValue* dict = static_cast<DictionaryValue*>(*status_entry); | 301 DictionaryValue* dict = static_cast<DictionaryValue*>(*status_entry); |
| 296 ASSERT_TRUE(dict->GetString(std::string(PolicyStatusInfo::kNameDictPath), | 302 ASSERT_TRUE(dict->GetString(PolicyStatusInfo::kNameDictPath, |
| 297 &value)); | 303 &value)); |
| 298 | 304 if (value == name) |
| 299 if (value == name) { | |
| 300 status_dict = *status_entry; | 305 status_dict = *status_entry; |
| 301 } | |
| 302 } | 306 } |
| 303 | 307 |
| 304 ASSERT_FALSE(status_dict == NULL); | 308 ASSERT_FALSE(status_dict == NULL); |
| 305 | 309 |
| 306 switch (entry->policy_type) { | 310 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 307 case kPolicyInstantEnabled: | 311 if (entry->name == cases[i].name || cases[i].name == NULL) { |
| 308 SetDictionaryPaths(defined_dict.get(), | 312 DictionaryValue* dict = |
| 313 cases[i].name ? defined_dict.get() : undefined_dict.get(); | |
| 314 SetDictionaryPaths(dict, | |
| 309 entry->name, | 315 entry->name, |
| 310 true, | 316 cases[i].name != NULL, |
| 311 PolicyStatusInfo::MANDATORY); | 317 cases[i].level); |
| 312 EXPECT_TRUE(defined_dict->Equals(status_dict)); | 318 EXPECT_TRUE(dict->Equals(status_dict)); |
| 313 break; | 319 break; |
| 314 case kPolicyDisablePluginFinder: | 320 } |
| 315 SetDictionaryPaths(defined_dict.get(), | |
| 316 entry->name, | |
| 317 true, | |
| 318 PolicyStatusInfo::MANDATORY); | |
| 319 EXPECT_TRUE(defined_dict->Equals(status_dict)); | |
| 320 break; | |
| 321 case kPolicySyncDisabled: | |
| 322 SetDictionaryPaths(defined_dict.get(), | |
| 323 entry->name, | |
| 324 true, | |
| 325 PolicyStatusInfo::RECOMMENDED); | |
| 326 EXPECT_TRUE(defined_dict->Equals(status_dict)); | |
| 327 break; | |
| 328 case kPolicyTranslateEnabled: | |
| 329 SetDictionaryPaths(defined_dict.get(), | |
| 330 entry->name, | |
| 331 true, | |
| 332 PolicyStatusInfo::RECOMMENDED); | |
| 333 EXPECT_TRUE(defined_dict->Equals(status_dict)); | |
| 334 break; | |
| 335 default: | |
| 336 SetDictionaryPaths(undefined_dict.get(), | |
| 337 entry->name, | |
| 338 false, | |
| 339 PolicyStatusInfo::LEVEL_UNDEFINED); | |
| 340 EXPECT_TRUE(undefined_dict->Equals(status_dict)); | |
| 341 break; | |
| 342 } | 321 } |
| 343 } | 322 } |
| 344 } | 323 } |
| 345 | 324 |
| 346 } // namespace policy | 325 } // namespace policy |
| OLD | NEW |