| 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 mandatory_value; |
| 62 in_value->Append(Value::CreateStringValue("test1")); | 59 mandatory_value.Append(Value::CreateStringValue("test1")); |
| 63 in_value->Append(Value::CreateStringValue("test2")); | 60 mandatory_value.Append(Value::CreateStringValue("test2")); |
| 64 provider_.AddPolicy(kPolicyRestoreOnStartupURLs, in_value); | 61 ListValue recommended_value; |
| 65 managed_reader_->OnUpdatePolicy(&provider_); | 62 recommended_value.Append(Value::CreateStringValue("test3")); |
| 63 recommended_value.Append(Value::CreateStringValue("test4")); |
| 64 provider_.AddMandatoryPolicy(key::kRestoreOnStartupURLs, |
| 65 mandatory_value.DeepCopy()); |
| 66 provider_.AddRecommendedPolicy(key::kDisabledSchemes, |
| 67 recommended_value.DeepCopy()); |
| 68 reader_->OnUpdatePolicy(&provider_); |
| 66 | 69 |
| 67 scoped_ptr<DictionaryValue> | 70 scoped_ptr<DictionaryValue> dict( |
| 68 dict(CreateDictionary(key::kRestoreOnStartupURLs, in_value->DeepCopy())); | 71 CreateDictionary(key::kRestoreOnStartupURLs, |
| 72 mandatory_value.DeepCopy())); |
| 69 scoped_ptr<DictionaryValue> result( | 73 scoped_ptr<DictionaryValue> result( |
| 70 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs)); | 74 reader_->GetPolicyStatus(key::kRestoreOnStartupURLs)); |
| 71 EXPECT_TRUE(dict->Equals(result.get())); | 75 EXPECT_TRUE(dict->Equals(result.get())); |
| 72 | 76 |
| 73 recommended_reader_->OnUpdatePolicy(&provider_); | 77 dict.reset(CreateDictionary(key::kDisabledSchemes, |
| 74 dict->SetString("level", | 78 recommended_value.DeepCopy())); |
| 75 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 79 dict->SetString( |
| 76 result.reset( | 80 "level", |
| 77 recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs)); | 81 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 82 result.reset(reader_->GetPolicyStatus(key::kDisabledSchemes)); |
| 78 EXPECT_TRUE(dict->Equals(result.get())); | 83 EXPECT_TRUE(dict->Equals(result.get())); |
| 79 } | 84 } |
| 80 | 85 |
| 81 // Test for string-valued policy settings. | 86 // Test for string-valued policy settings. |
| 82 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) { | 87 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) { |
| 83 provider_.AddPolicy(kPolicyHomepageLocation, | 88 StringValue mandatory_value("http://chromium.org"); |
| 84 Value::CreateStringValue("http://chromium.org")); | 89 StringValue recommended_value("http://www.google.com/q={searchTerms}"); |
| 85 managed_reader_->OnUpdatePolicy(&provider_); | 90 provider_.AddMandatoryPolicy(key::kHomepageLocation, |
| 86 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kHomepageLocation, | 91 mandatory_value.DeepCopy()); |
| 87 Value::CreateStringValue("http://chromium.org"))); | 92 provider_.AddRecommendedPolicy(key::kDefaultSearchProviderSearchURL, |
| 93 recommended_value.DeepCopy()); |
| 94 reader_->OnUpdatePolicy(&provider_); |
| 95 scoped_ptr<DictionaryValue> dict( |
| 96 CreateDictionary(key::kHomepageLocation, |
| 97 mandatory_value.DeepCopy())); |
| 88 scoped_ptr<DictionaryValue> result( | 98 scoped_ptr<DictionaryValue> result( |
| 89 managed_reader_->GetPolicyStatus(kPolicyHomepageLocation)); | 99 reader_->GetPolicyStatus(key::kHomepageLocation)); |
| 90 EXPECT_TRUE(dict->Equals(result.get())); | 100 EXPECT_TRUE(dict->Equals(result.get())); |
| 91 | 101 |
| 92 recommended_reader_->OnUpdatePolicy(&provider_); | 102 dict.reset(CreateDictionary(key::kDefaultSearchProviderSearchURL, |
| 93 dict->SetString("level", | 103 recommended_value.DeepCopy())); |
| 94 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 104 dict->SetString( |
| 95 result.reset( | 105 "level", |
| 96 recommended_reader_->GetPolicyStatus(kPolicyHomepageLocation)); | 106 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 107 result.reset(reader_->GetPolicyStatus(key::kDefaultSearchProviderSearchURL)); |
| 97 EXPECT_TRUE(dict->Equals(result.get())); | 108 EXPECT_TRUE(dict->Equals(result.get())); |
| 98 } | 109 } |
| 99 | 110 |
| 100 // Test for boolean-valued policy settings. | 111 // Test for boolean-valued policy settings. |
| 101 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) { | 112 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) { |
| 102 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(true)); | 113 provider_.AddMandatoryPolicy(key::kShowHomeButton, |
| 103 managed_reader_->OnUpdatePolicy(&provider_); | 114 Value::CreateBooleanValue(true)); |
| 104 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kShowHomeButton, | 115 provider_.AddRecommendedPolicy(key::kHomepageIsNewTabPage, |
| 105 Value::CreateBooleanValue(true))); | 116 Value::CreateBooleanValue(false)); |
| 117 reader_->OnUpdatePolicy(&provider_); |
| 118 scoped_ptr<DictionaryValue> dict( |
| 119 CreateDictionary(key::kShowHomeButton, Value::CreateBooleanValue(true))); |
| 106 scoped_ptr<DictionaryValue> result( | 120 scoped_ptr<DictionaryValue> result( |
| 107 managed_reader_->GetPolicyStatus(kPolicyShowHomeButton)); | 121 reader_->GetPolicyStatus(key::kShowHomeButton)); |
| 108 EXPECT_TRUE(dict->Equals(result.get())); | 122 EXPECT_TRUE(dict->Equals(result.get())); |
| 109 | 123 |
| 110 recommended_reader_->OnUpdatePolicy(&provider_); | 124 dict.reset(CreateDictionary(key::kHomepageIsNewTabPage, |
| 111 dict->SetString("level", | 125 Value::CreateBooleanValue(false))); |
| 112 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 126 dict->SetString( |
| 113 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton)); | 127 "level", |
| 114 EXPECT_TRUE(dict->Equals(result.get())); | 128 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 115 | 129 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())); | 130 EXPECT_TRUE(dict->Equals(result.get())); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // Test for integer-valued policy settings. | 133 // Test for integer-valued policy settings. |
| 133 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { | 134 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { |
| 134 provider_.AddPolicy(kPolicyRestoreOnStartup, Value::CreateIntegerValue(3)); | 135 provider_.AddMandatoryPolicy(key::kRestoreOnStartup, |
| 135 managed_reader_->OnUpdatePolicy(&provider_); | 136 Value::CreateIntegerValue(3)); |
| 136 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kRestoreOnStartup, | 137 provider_.AddRecommendedPolicy(key::kIncognitoModeAvailability, |
| 137 Value::CreateIntegerValue(3))); | 138 Value::CreateIntegerValue(2)); |
| 139 reader_->OnUpdatePolicy(&provider_); |
| 140 scoped_ptr<DictionaryValue> dict( |
| 141 CreateDictionary(key::kRestoreOnStartup, Value::CreateIntegerValue(3))); |
| 138 scoped_ptr<DictionaryValue> result( | 142 scoped_ptr<DictionaryValue> result( |
| 139 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartup)); | 143 reader_->GetPolicyStatus(key::kRestoreOnStartup)); |
| 140 EXPECT_TRUE(dict->Equals(result.get())); | 144 EXPECT_TRUE(dict->Equals(result.get())); |
| 141 | 145 |
| 142 recommended_reader_->OnUpdatePolicy(&provider_); | 146 dict.reset(CreateDictionary(key::kIncognitoModeAvailability, |
| 143 dict->SetString("level", | 147 Value::CreateIntegerValue(2))); |
| 144 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); | 148 dict->SetString( |
| 145 result.reset(recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartup)); | 149 "level", |
| 150 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); |
| 151 result.reset(reader_->GetPolicyStatus(key::kIncognitoModeAvailability)); |
| 146 EXPECT_TRUE(dict->Equals(result.get())); | 152 EXPECT_TRUE(dict->Equals(result.get())); |
| 147 } | 153 } |
| 148 | 154 |
| 149 class PolicyStatusTest : public testing::Test { | 155 class PolicyStatusTest : public testing::Test { |
| 150 protected: | 156 protected: |
| 151 PolicyStatusTest() { | 157 PolicyStatusTest() { |
| 152 managed_platform_ = new MockConfigurationPolicyReader(); | 158 managed_platform_ = new MockConfigurationPolicyReader(); |
| 153 managed_cloud_ = new MockConfigurationPolicyReader(); | 159 managed_cloud_ = new MockConfigurationPolicyReader(); |
| 154 recommended_platform_ = new MockConfigurationPolicyReader(); | 160 recommended_platform_ = new MockConfigurationPolicyReader(); |
| 155 recommended_cloud_ = new MockConfigurationPolicyReader(); | 161 recommended_cloud_ = new MockConfigurationPolicyReader(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 179 void SendPolicies() { | 185 void SendPolicies() { |
| 180 EXPECT_CALL(*managed_platform_, GetPolicyStatus(_)) | 186 EXPECT_CALL(*managed_platform_, GetPolicyStatus(_)) |
| 181 .WillRepeatedly(ReturnNull()); | 187 .WillRepeatedly(ReturnNull()); |
| 182 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(_)) | 188 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(_)) |
| 183 .WillRepeatedly(ReturnNull()); | 189 .WillRepeatedly(ReturnNull()); |
| 184 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(_)) | 190 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(_)) |
| 185 .WillRepeatedly(ReturnNull()); | 191 .WillRepeatedly(ReturnNull()); |
| 186 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(_)) | 192 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(_)) |
| 187 .WillRepeatedly(ReturnNull()); | 193 .WillRepeatedly(ReturnNull()); |
| 188 | 194 |
| 189 EXPECT_CALL(*managed_platform_, GetPolicyStatus(kPolicyInstantEnabled)) | 195 EXPECT_CALL(*managed_platform_, GetPolicyStatus(key::kInstantEnabled)) |
| 190 .WillRepeatedly(Return(CreateDictionary(key::kInstantEnabled, | 196 .WillRepeatedly(Return(CreateDictionary(key::kInstantEnabled, |
| 191 PolicyStatusInfo::MANDATORY))); | 197 POLICY_LEVEL_MANDATORY))); |
| 192 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(kPolicyDisablePluginFinder)) | 198 EXPECT_CALL(*managed_cloud_, GetPolicyStatus(key::kDisablePluginFinder)) |
| 193 .WillRepeatedly(Return(CreateDictionary(key::kDisablePluginFinder, | 199 .WillRepeatedly(Return(CreateDictionary(key::kDisablePluginFinder, |
| 194 PolicyStatusInfo::MANDATORY))); | 200 POLICY_LEVEL_MANDATORY))); |
| 195 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(kPolicySyncDisabled)) | 201 EXPECT_CALL(*recommended_platform_, GetPolicyStatus(key::kSyncDisabled)) |
| 196 .WillRepeatedly( | 202 .WillRepeatedly(Return(CreateDictionary(key::kSyncDisabled, |
| 197 Return(CreateDictionary(key::kSyncDisabled, | 203 POLICY_LEVEL_RECOMMENDED))); |
| 198 PolicyStatusInfo::RECOMMENDED))); | 204 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(key::kTranslateEnabled)) |
| 199 EXPECT_CALL(*recommended_cloud_, GetPolicyStatus(kPolicyTranslateEnabled)) | 205 .WillRepeatedly(Return(CreateDictionary(key::kTranslateEnabled, |
| 200 .WillRepeatedly( | 206 POLICY_LEVEL_RECOMMENDED))); |
| 201 Return(CreateDictionary(key::kTranslateEnabled, | |
| 202 PolicyStatusInfo::RECOMMENDED))); | |
| 203 } | 207 } |
| 204 | 208 |
| 205 DictionaryValue* CreateDictionary(const char* name, | 209 DictionaryValue* CreateDictionary(const char* name, PolicyLevel level) { |
| 206 PolicyStatusInfo::PolicyLevel level) { | |
| 207 DictionaryValue* value = new DictionaryValue(); | 210 DictionaryValue* value = new DictionaryValue(); |
| 208 value->SetString(std::string(PolicyStatusInfo::kNameDictPath), | 211 value->SetString(PolicyStatusInfo::kNameDictPath, ASCIIToUTF16(name)); |
| 209 ASCIIToUTF16(name)); | 212 value->SetString(PolicyStatusInfo::kLevelDictPath, |
| 210 value->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | |
| 211 PolicyStatusInfo::GetPolicyLevelString(level)); | 213 PolicyStatusInfo::GetPolicyLevelString(level)); |
| 212 value->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 214 value->SetString(PolicyStatusInfo::kScopeDictPath, |
| 213 PolicyStatusInfo::GetSourceTypeString(PolicyStatusInfo::USER)); | 215 PolicyStatusInfo::GetPolicyScopeString(POLICY_SCOPE_USER)); |
| 214 value->SetBoolean(std::string(PolicyStatusInfo::kValueDictPath), true); | 216 value->SetBoolean(PolicyStatusInfo::kValueDictPath, true); |
| 215 value->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), true); | 217 value->SetBoolean(PolicyStatusInfo::kSetDictPath, true); |
| 216 value->SetString(std::string(PolicyStatusInfo::kStatusDictPath), | 218 value->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_); |
| 217 status_ok_); | |
| 218 | 219 |
| 219 return value; | 220 return value; |
| 220 } | 221 } |
| 221 | 222 |
| 222 void SetDictionaryPaths(DictionaryValue* dict, | 223 void SetDictionaryPaths(DictionaryValue* dict, |
| 223 const char* policy_name, | 224 const char* policy_name, |
| 224 bool defined, | 225 bool defined, |
| 225 PolicyStatusInfo::PolicyLevel level) { | 226 PolicyLevel level) { |
| 226 dict->SetString(PolicyStatusInfo::kNameDictPath, | 227 dict->SetString(PolicyStatusInfo::kNameDictPath, |
| 227 ASCIIToUTF16(policy_name)); | 228 ASCIIToUTF16(policy_name)); |
| 228 if (defined) { | 229 if (defined) { |
| 229 dict->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | 230 dict->SetString(PolicyStatusInfo::kLevelDictPath, |
| 230 PolicyStatusInfo::GetPolicyLevelString(level)); | 231 PolicyStatusInfo::GetPolicyLevelString(level)); |
| 231 } | 232 } |
| 232 } | 233 } |
| 233 | 234 |
| 234 MockConfigurationPolicyReader* managed_platform_; | 235 MockConfigurationPolicyReader* managed_platform_; |
| 235 MockConfigurationPolicyReader* managed_cloud_; | 236 MockConfigurationPolicyReader* managed_cloud_; |
| 236 MockConfigurationPolicyReader* recommended_platform_; | 237 MockConfigurationPolicyReader* recommended_platform_; |
| 237 MockConfigurationPolicyReader* recommended_cloud_; | 238 MockConfigurationPolicyReader* recommended_cloud_; |
| 238 scoped_ptr<PolicyStatus> policy_status_; | 239 scoped_ptr<PolicyStatus> policy_status_; |
| 239 const PolicyDefinitionList* policy_list_; | 240 const PolicyDefinitionList* policy_list_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 252 | 253 |
| 253 TEST_F(PolicyStatusTest, GetPolicyStatusListSetPolicies) { | 254 TEST_F(PolicyStatusTest, GetPolicyStatusListSetPolicies) { |
| 254 SendPolicies(); | 255 SendPolicies(); |
| 255 bool any_policies_sent; | 256 bool any_policies_sent; |
| 256 scoped_ptr<ListValue> status_list( | 257 scoped_ptr<ListValue> status_list( |
| 257 policy_status_->GetPolicyStatusList(&any_policies_sent)); | 258 policy_status_->GetPolicyStatusList(&any_policies_sent)); |
| 258 EXPECT_TRUE(any_policies_sent); | 259 EXPECT_TRUE(any_policies_sent); |
| 259 EXPECT_EQ(policy_list_size_, status_list->GetSize()); | 260 EXPECT_EQ(policy_list_size_, status_list->GetSize()); |
| 260 | 261 |
| 261 scoped_ptr<DictionaryValue> undefined_dict(new DictionaryValue()); | 262 scoped_ptr<DictionaryValue> undefined_dict(new DictionaryValue()); |
| 262 undefined_dict->SetString(std::string(PolicyStatusInfo::kLevelDictPath), | 263 undefined_dict->SetString(PolicyStatusInfo::kLevelDictPath, |
| 263 PolicyStatusInfo::GetPolicyLevelString( | 264 PolicyStatusInfo::GetPolicyLevelString( |
| 264 PolicyStatusInfo::LEVEL_UNDEFINED)); | 265 POLICY_LEVEL_MANDATORY)); |
| 265 undefined_dict->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 266 undefined_dict->SetString(PolicyStatusInfo::kScopeDictPath, |
| 266 PolicyStatusInfo::GetSourceTypeString( | 267 PolicyStatusInfo::GetPolicyScopeString( |
| 267 PolicyStatusInfo::SOURCE_TYPE_UNDEFINED)); | 268 POLICY_SCOPE_USER)); |
| 268 undefined_dict->Set(std::string(PolicyStatusInfo::kValueDictPath), | 269 undefined_dict->Set(PolicyStatusInfo::kValueDictPath, |
| 269 Value::CreateNullValue()); | 270 Value::CreateNullValue()); |
| 270 undefined_dict->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), | 271 undefined_dict->SetBoolean(PolicyStatusInfo::kSetDictPath, false); |
| 271 false); | 272 undefined_dict->SetString(PolicyStatusInfo::kStatusDictPath, string16()); |
| 272 undefined_dict->SetString(std::string(PolicyStatusInfo::kStatusDictPath), | |
| 273 string16()); | |
| 274 | 273 |
| 275 scoped_ptr<DictionaryValue> defined_dict(new DictionaryValue()); | 274 scoped_ptr<DictionaryValue> defined_dict(new DictionaryValue()); |
| 276 defined_dict->SetString(std::string(PolicyStatusInfo::kSourceTypeDictPath), | 275 defined_dict->SetString(PolicyStatusInfo::kScopeDictPath, |
| 277 PolicyStatusInfo::GetSourceTypeString(PolicyStatusInfo::USER)); | 276 PolicyStatusInfo::GetPolicyScopeString( |
| 278 defined_dict->Set(std::string(PolicyStatusInfo::kValueDictPath), | 277 POLICY_SCOPE_USER)); |
| 278 defined_dict->Set(PolicyStatusInfo::kValueDictPath, |
| 279 Value::CreateBooleanValue(true)); | 279 Value::CreateBooleanValue(true)); |
| 280 defined_dict->SetBoolean(std::string(PolicyStatusInfo::kSetDictPath), true); | 280 defined_dict->SetBoolean(PolicyStatusInfo::kSetDictPath, true); |
| 281 defined_dict->SetString(std::string(PolicyStatusInfo::kStatusDictPath), | 281 defined_dict->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_); |
| 282 status_ok_); | 282 |
| 283 struct { |
| 284 const char *name; |
| 285 PolicyLevel level; |
| 286 } cases[] = { |
| 287 { key::kInstantEnabled, POLICY_LEVEL_MANDATORY }, |
| 288 { key::kDisablePluginFinder, POLICY_LEVEL_MANDATORY }, |
| 289 { key::kSyncDisabled, POLICY_LEVEL_RECOMMENDED }, |
| 290 { key::kTranslateEnabled, POLICY_LEVEL_RECOMMENDED }, |
| 291 { NULL, POLICY_LEVEL_MANDATORY }, |
| 292 }; |
| 283 | 293 |
| 284 for (const PolicyDefinitionList::Entry* entry = policy_list_->begin; | 294 for (const PolicyDefinitionList::Entry* entry = policy_list_->begin; |
| 285 entry != policy_list_->end; ++entry) { | 295 entry != policy_list_->end; ++entry) { |
| 286 Value* status_dict = NULL; | 296 Value* status_dict = NULL; |
| 287 | 297 |
| 288 // Every policy in |policy_list_| has to appear in the returned ListValue. | 298 // Every policy in |policy_list_| has to appear in the returned ListValue. |
| 289 string16 name = ASCIIToUTF16(entry->name); | 299 string16 name = ASCIIToUTF16(entry->name); |
| 290 for (ListValue::const_iterator status_entry = status_list->begin(); | 300 for (ListValue::const_iterator status_entry = status_list->begin(); |
| 291 status_entry != status_list->end(); | 301 status_entry != status_list->end(); |
| 292 ++status_entry) { | 302 ++status_entry) { |
| 293 string16 value; | 303 string16 value; |
| 294 ASSERT_TRUE((*status_entry)->IsType(Value::TYPE_DICTIONARY)); | 304 ASSERT_TRUE((*status_entry)->IsType(Value::TYPE_DICTIONARY)); |
| 295 DictionaryValue* dict = static_cast<DictionaryValue*>(*status_entry); | 305 DictionaryValue* dict = static_cast<DictionaryValue*>(*status_entry); |
| 296 ASSERT_TRUE(dict->GetString(std::string(PolicyStatusInfo::kNameDictPath), | 306 ASSERT_TRUE(dict->GetString(PolicyStatusInfo::kNameDictPath, |
| 297 &value)); | 307 &value)); |
| 298 | 308 if (value == name) |
| 299 if (value == name) { | |
| 300 status_dict = *status_entry; | 309 status_dict = *status_entry; |
| 301 } | |
| 302 } | 310 } |
| 303 | 311 |
| 304 ASSERT_FALSE(status_dict == NULL); | 312 ASSERT_FALSE(status_dict == NULL); |
| 305 | 313 |
| 306 switch (entry->policy_type) { | 314 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 307 case kPolicyInstantEnabled: | 315 if (entry->name == cases[i].name || cases[i].name == NULL) { |
| 308 SetDictionaryPaths(defined_dict.get(), | 316 DictionaryValue* dict = |
| 317 cases[i].name ? defined_dict.get() : undefined_dict.get(); |
| 318 SetDictionaryPaths(dict, |
| 309 entry->name, | 319 entry->name, |
| 310 true, | 320 cases[i].name != NULL, |
| 311 PolicyStatusInfo::MANDATORY); | 321 cases[i].level); |
| 312 EXPECT_TRUE(defined_dict->Equals(status_dict)); | 322 EXPECT_TRUE(dict->Equals(status_dict)); |
| 313 break; | 323 break; |
| 314 case kPolicyDisablePluginFinder: | 324 } |
| 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 } | 325 } |
| 343 } | 326 } |
| 344 } | 327 } |
| 345 | 328 |
| 346 } // namespace policy | 329 } // namespace policy |
| OLD | NEW |