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/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.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 "chrome/browser/policy/proto/old_generic_format.pb.h" |
| 19 #include "chrome/test/testing_browser_process_test.h" |
19 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using testing::_; | 24 using testing::_; |
24 | 25 |
25 namespace policy { | 26 namespace policy { |
26 | 27 |
27 // Decodes a CloudPolicySettings object into two maps with mandatory and | 28 // Decodes a CloudPolicySettings object into two maps with mandatory and |
28 // recommended settings, respectively. The implementation is generated code | 29 // recommended settings, respectively. The implementation is generated code |
29 // in policy/cloud_policy_generated.cc. | 30 // in policy/cloud_policy_generated.cc. |
30 void DecodePolicy(const em::CloudPolicySettings& policy, | 31 void DecodePolicy(const em::CloudPolicySettings& policy, |
31 PolicyMap* mandatory, PolicyMap* recommended); | 32 PolicyMap* mandatory, PolicyMap* recommended); |
32 | 33 |
33 // The implementations of these methods are in cloud_policy_generated.cc. | 34 // The implementations of these methods are in cloud_policy_generated.cc. |
34 Value* DecodeIntegerValue(google::protobuf::int64 value); | 35 Value* DecodeIntegerValue(google::protobuf::int64 value); |
35 ListValue* DecodeStringList(const em::StringList& string_list); | 36 ListValue* DecodeStringList(const em::StringList& string_list); |
36 | 37 |
37 class MockCloudPolicyCacheBaseObserver | 38 class MockCloudPolicyCacheBaseObserver |
38 : public CloudPolicyCacheBase::Observer { | 39 : public CloudPolicyCacheBase::Observer { |
39 public: | 40 public: |
40 MockCloudPolicyCacheBaseObserver() {} | 41 MockCloudPolicyCacheBaseObserver() {} |
41 virtual ~MockCloudPolicyCacheBaseObserver() {} | 42 virtual ~MockCloudPolicyCacheBaseObserver() {} |
42 MOCK_METHOD1(OnCacheUpdate, void(CloudPolicyCacheBase*)); | 43 MOCK_METHOD1(OnCacheUpdate, void(CloudPolicyCacheBase*)); |
43 void OnCacheGoingAway(CloudPolicyCacheBase*) {} | 44 void OnCacheGoingAway(CloudPolicyCacheBase*) {} |
44 }; | 45 }; |
45 | 46 |
46 // Tests the device management policy cache. | 47 // Tests the device management policy cache. |
47 class UserPolicyCacheTest : public testing::Test { | 48 class UserPolicyCacheTest : public TestingBrowserProcessTest { |
48 protected: | 49 protected: |
49 UserPolicyCacheTest() | 50 UserPolicyCacheTest() |
50 : loop_(MessageLoop::TYPE_UI), | 51 : loop_(MessageLoop::TYPE_UI), |
51 ui_thread_(BrowserThread::UI, &loop_), | 52 ui_thread_(BrowserThread::UI, &loop_), |
52 file_thread_(BrowserThread::FILE, &loop_) {} | 53 file_thread_(BrowserThread::FILE, &loop_) {} |
53 | 54 |
54 void SetUp() { | 55 void SetUp() { |
55 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 56 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
56 } | 57 } |
57 | 58 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // If new-style policy comes in, it should override old-style policy. | 378 // If new-style policy comes in, it should override old-style policy. |
378 policy = CreateHomepagePolicy("http://www.example.com", | 379 policy = CreateHomepagePolicy("http://www.example.com", |
379 base::Time::NowFromSystemTime(), | 380 base::Time::NowFromSystemTime(), |
380 em::PolicyOptions::RECOMMENDED); | 381 em::PolicyOptions::RECOMMENDED); |
381 SetPolicy(&cache, policy, true); | 382 SetPolicy(&cache, policy, true); |
382 EXPECT_TRUE(expected.Equals(recommended_policy(cache))); | 383 EXPECT_TRUE(expected.Equals(recommended_policy(cache))); |
383 EXPECT_TRUE(empty.Equals(mandatory_policy(cache))); | 384 EXPECT_TRUE(empty.Equals(mandatory_policy(cache))); |
384 } | 385 } |
385 | 386 |
386 } // namespace policy | 387 } // namespace policy |
OLD | NEW |