OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ptr_util.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "chrome/browser/net/disk_cache_dir_policy_handler.h" | 9 #include "chrome/browser/net/disk_cache_dir_policy_handler.h" |
9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
10 #include "components/policy/core/common/policy_map.h" | 11 #include "components/policy/core/common/policy_map.h" |
11 #include "components/policy/core/common/policy_types.h" | 12 #include "components/policy/core/common/policy_types.h" |
12 #include "components/prefs/pref_value_map.h" | 13 #include "components/prefs/pref_value_map.h" |
13 #include "policy/policy_constants.h" | 14 #include "policy/policy_constants.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace policy { | 17 namespace policy { |
17 | 18 |
18 class DiskCacheDirPolicyTest : public testing::Test { | 19 class DiskCacheDirPolicyTest : public testing::Test { |
19 protected: | 20 protected: |
20 PolicyMap policy_; | 21 PolicyMap policy_; |
21 DiskCacheDirPolicyHandler handler_; | 22 DiskCacheDirPolicyHandler handler_; |
22 PrefValueMap prefs_; | 23 PrefValueMap prefs_; |
23 }; | 24 }; |
24 | 25 |
25 TEST_F(DiskCacheDirPolicyTest, Default) { | 26 TEST_F(DiskCacheDirPolicyTest, Default) { |
26 handler_.ApplyPolicySettings(policy_, &prefs_); | 27 handler_.ApplyPolicySettings(policy_, &prefs_); |
27 EXPECT_FALSE(prefs_.GetValue(prefs::kDiskCacheDir, NULL)); | 28 EXPECT_FALSE(prefs_.GetValue(prefs::kDiskCacheDir, NULL)); |
28 } | 29 } |
29 | 30 |
30 TEST_F(DiskCacheDirPolicyTest, SetPolicyInvalid) { | 31 TEST_F(DiskCacheDirPolicyTest, SetPolicyInvalid) { |
31 // DiskCacheDir policy expects a string; give it a boolean. | 32 // DiskCacheDir policy expects a string; give it a boolean. |
32 policy_.Set(key::kDiskCacheDir, | 33 policy_.Set(key::kDiskCacheDir, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
33 POLICY_LEVEL_MANDATORY, | |
34 POLICY_SCOPE_USER, | |
35 POLICY_SOURCE_CLOUD, | 34 POLICY_SOURCE_CLOUD, |
36 new base::FundamentalValue(false), | 35 base::WrapUnique(new base::FundamentalValue(false)), nullptr); |
37 NULL); | |
38 handler_.ApplyPolicySettings(policy_, &prefs_); | 36 handler_.ApplyPolicySettings(policy_, &prefs_); |
39 EXPECT_FALSE(prefs_.GetValue(prefs::kDiskCacheDir, NULL)); | 37 EXPECT_FALSE(prefs_.GetValue(prefs::kDiskCacheDir, NULL)); |
40 } | 38 } |
41 | 39 |
42 TEST_F(DiskCacheDirPolicyTest, SetPolicyValid) { | 40 TEST_F(DiskCacheDirPolicyTest, SetPolicyValid) { |
43 // Use a variable in the value. It should be expanded by the handler. | 41 // Use a variable in the value. It should be expanded by the handler. |
44 const std::string in = "${user_name}/foo"; | 42 const std::string in = "${user_name}/foo"; |
45 policy_.Set(key::kDiskCacheDir, | 43 policy_.Set(key::kDiskCacheDir, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
46 POLICY_LEVEL_MANDATORY, | 44 POLICY_SOURCE_CLOUD, base::WrapUnique(new base::StringValue(in)), |
47 POLICY_SCOPE_USER, | 45 nullptr); |
48 POLICY_SOURCE_CLOUD, | |
49 new base::StringValue(in), | |
50 NULL); | |
51 handler_.ApplyPolicySettings(policy_, &prefs_); | 46 handler_.ApplyPolicySettings(policy_, &prefs_); |
52 | 47 |
53 const base::Value* value; | 48 const base::Value* value; |
54 ASSERT_TRUE(prefs_.GetValue(prefs::kDiskCacheDir, &value)); | 49 ASSERT_TRUE(prefs_.GetValue(prefs::kDiskCacheDir, &value)); |
55 std::string out; | 50 std::string out; |
56 ASSERT_TRUE(value->GetAsString(&out)); | 51 ASSERT_TRUE(value->GetAsString(&out)); |
57 EXPECT_NE(std::string::npos, out.find("foo")); | 52 EXPECT_NE(std::string::npos, out.find("foo")); |
58 EXPECT_EQ(std::string::npos, out.find("${user_name}")); | 53 EXPECT_EQ(std::string::npos, out.find("${user_name}")); |
59 } | 54 } |
60 | 55 |
61 } // namespace policy | 56 } // namespace policy |
OLD | NEW |