| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/user_policy_cache.h" | 5 #include "chrome/browser/policy/user_policy_cache.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/memory/scoped_temp_dir.h" | 11 #include "base/memory/scoped_temp_dir.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/policy/configuration_policy_provider.h" | 14 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 15 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 16 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 16 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 17 #include "chrome/browser/policy/proto/device_management_local.pb.h" | 17 #include "chrome/browser/policy/proto/device_management_local.pb.h" |
| 18 #include "chrome/browser/policy/proto/old_generic_format.pb.h" |
| 18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace policy { | 23 namespace policy { |
| 23 | 24 |
| 24 // Decodes a CloudPolicySettings object into two maps with mandatory and | 25 // Decodes a CloudPolicySettings object into two maps with mandatory and |
| 25 // recommended settings, respectively. The implementation is generated code | 26 // recommended settings, respectively. The implementation is generated code |
| 26 // in policy/cloud_policy_generated.cc. | 27 // in policy/cloud_policy_generated.cc. |
| 27 void DecodePolicy(const em::CloudPolicySettings& policy, | 28 void DecodePolicy(const em::CloudPolicySettings& policy, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 em::PolicyOptions::MANDATORY); | 329 em::PolicyOptions::MANDATORY); |
| 329 SetPolicy(&cache, updated_policy, true); | 330 SetPolicy(&cache, updated_policy, true); |
| 330 | 331 |
| 331 cache.Load(); | 332 cache.Load(); |
| 332 PolicyMap expected; | 333 PolicyMap expected; |
| 333 expected.Set(kPolicyHomepageLocation, | 334 expected.Set(kPolicyHomepageLocation, |
| 334 Value::CreateStringValue("http://www.chromium.org")); | 335 Value::CreateStringValue("http://www.chromium.org")); |
| 335 EXPECT_TRUE(expected.Equals(mandatory_policy(cache))); | 336 EXPECT_TRUE(expected.Equals(mandatory_policy(cache))); |
| 336 } | 337 } |
| 337 | 338 |
| 339 // Test case for the temporary support for GenericNamedValues in the |
| 340 // CloudPolicySettings protobuf. Can be removed when this support is no longer |
| 341 // required. |
| 342 TEST_F(UserPolicyCacheTest, OldStylePolicy) { |
| 343 UserPolicyCache cache(test_file()); |
| 344 em::PolicyFetchResponse* policy = new em::PolicyFetchResponse(); |
| 345 em::PolicyData signed_response; |
| 346 em::LegacyChromeSettingsProto settings; |
| 347 em::GenericNamedValue* named_value = settings.add_named_value(); |
| 348 named_value->set_name("HomepageLocation"); |
| 349 em::GenericValue* value_container = named_value->mutable_value(); |
| 350 value_container->set_value_type(em::GenericValue::VALUE_TYPE_STRING); |
| 351 value_container->set_string_value("http://www.example.com"); |
| 352 EXPECT_TRUE( |
| 353 settings.SerializeToString(signed_response.mutable_policy_value())); |
| 354 base::TimeDelta timestamp = |
| 355 base::Time::NowFromSystemTime() - base::Time::UnixEpoch(); |
| 356 signed_response.set_timestamp(timestamp.InMilliseconds()); |
| 357 EXPECT_TRUE( |
| 358 signed_response.SerializeToString(policy->mutable_policy_data())); |
| 359 |
| 360 SetPolicy(&cache, policy, true); |
| 361 PolicyMap expected; |
| 362 expected.Set(kPolicyHomepageLocation, |
| 363 Value::CreateStringValue("http://www.example.com")); |
| 364 PolicyMap empty; |
| 365 EXPECT_TRUE(expected.Equals(mandatory_policy(cache))); |
| 366 EXPECT_TRUE(empty.Equals(recommended_policy(cache))); |
| 367 // If new-style policy comes in, it should override old-style policy. |
| 368 policy = CreateHomepagePolicy("http://www.example.com", |
| 369 base::Time::NowFromSystemTime(), |
| 370 em::PolicyOptions::RECOMMENDED); |
| 371 SetPolicy(&cache, policy, true); |
| 372 EXPECT_TRUE(expected.Equals(recommended_policy(cache))); |
| 373 EXPECT_TRUE(empty.Equals(mandatory_policy(cache))); |
| 374 } |
| 375 |
| 338 } // namespace policy | 376 } // namespace policy |
| OLD | NEW |