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/chromeos/settings/device_settings_cache.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_cache.h" |
6 | 6 |
7 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 7 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
8 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 8 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/test/base/testing_pref_service.h" | 10 #include "chrome/test/base/testing_pref_service.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace em = enterprise_management; | 13 namespace em = enterprise_management; |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 class DeviceSettingsCacheTest : public testing::Test { | 17 class DeviceSettingsCacheTest : public testing::Test { |
18 protected: | 18 protected: |
19 virtual void SetUp() { | 19 virtual void SetUp() { |
20 // prepare some data. | 20 // prepare some data. |
21 policy_.set_policy_type("google/chromeos/device"); | 21 policy_.set_policy_type("google/chromeos/device"); |
22 em::ChromeDeviceSettingsProto pol; | 22 em::ChromeDeviceSettingsProto pol; |
23 pol.mutable_allow_new_users()->set_allow_new_users(false); | 23 pol.mutable_allow_new_users()->set_allow_new_users(false); |
24 policy_.set_policy_value(pol.SerializeAsString()); | 24 policy_.set_policy_value(pol.SerializeAsString()); |
25 | 25 |
26 device_settings_cache::RegisterPrefs(&local_state_); | 26 device_settings_cache::RegisterPrefs(&local_state_); |
27 } | 27 } |
28 | 28 |
29 TestingPrefService local_state_; | 29 TestingPrefServiceSimple local_state_; |
30 em::PolicyData policy_; | 30 em::PolicyData policy_; |
31 }; | 31 }; |
32 | 32 |
33 TEST_F(DeviceSettingsCacheTest, Basic) { | 33 TEST_F(DeviceSettingsCacheTest, Basic) { |
34 EXPECT_TRUE(device_settings_cache::Store(policy_, &local_state_)); | 34 EXPECT_TRUE(device_settings_cache::Store(policy_, &local_state_)); |
35 | 35 |
36 em::PolicyData policy_out; | 36 em::PolicyData policy_out; |
37 EXPECT_TRUE(device_settings_cache::Retrieve(&policy_out, &local_state_)); | 37 EXPECT_TRUE(device_settings_cache::Retrieve(&policy_out, &local_state_)); |
38 | 38 |
39 EXPECT_TRUE(policy_out.has_policy_type()); | 39 EXPECT_TRUE(policy_out.has_policy_type()); |
40 EXPECT_TRUE(policy_out.has_policy_value()); | 40 EXPECT_TRUE(policy_out.has_policy_value()); |
41 | 41 |
42 em::ChromeDeviceSettingsProto pol; | 42 em::ChromeDeviceSettingsProto pol; |
43 pol.ParseFromString(policy_out.policy_value()); | 43 pol.ParseFromString(policy_out.policy_value()); |
44 EXPECT_TRUE(pol.has_allow_new_users()); | 44 EXPECT_TRUE(pol.has_allow_new_users()); |
45 EXPECT_FALSE(pol.allow_new_users().allow_new_users()); | 45 EXPECT_FALSE(pol.allow_new_users().allow_new_users()); |
46 } | 46 } |
47 | 47 |
48 TEST_F(DeviceSettingsCacheTest, CorruptData) { | 48 TEST_F(DeviceSettingsCacheTest, CorruptData) { |
49 EXPECT_TRUE(device_settings_cache::Store(policy_, &local_state_)); | 49 EXPECT_TRUE(device_settings_cache::Store(policy_, &local_state_)); |
50 | 50 |
51 local_state_.SetString(prefs::kDeviceSettingsCache, "blaaa"); | 51 local_state_.SetString(prefs::kDeviceSettingsCache, "blaaa"); |
52 | 52 |
53 em::PolicyData policy_out; | 53 em::PolicyData policy_out; |
54 EXPECT_FALSE(device_settings_cache::Retrieve(&policy_out, &local_state_)); | 54 EXPECT_FALSE(device_settings_cache::Retrieve(&policy_out, &local_state_)); |
55 } | 55 } |
56 | 56 |
57 } // namespace chromeos | 57 } // namespace chromeos |
OLD | NEW |