OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/prefs/pref_value_map.h" | 5 #include "base/prefs/pref_value_map.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "chrome/browser/search/contextual_search_policy_handler_android.h" | 7 #include "chrome/browser/search/contextual_search_policy_handler_android.h" |
8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
9 #include "components/policy/core/common/policy_map.h" | 9 #include "components/policy/core/common/policy_map.h" |
10 #include "policy/policy_constants.h" | 10 #include "policy/policy_constants.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace policy { | 13 namespace policy { |
14 | 14 |
15 TEST(ContextualSearchPolicyHandlerAndroidTest, Default) { | 15 TEST(ContextualSearchPolicyHandlerAndroidTest, Default) { |
16 PolicyMap policy; | 16 PolicyMap policy; |
17 PrefValueMap prefs; | 17 PrefValueMap prefs; |
18 ContextualSearchPolicyHandlerAndroid handler; | 18 ContextualSearchPolicyHandlerAndroid handler; |
19 handler.ApplyPolicySettings(policy, &prefs); | 19 handler.ApplyPolicySettings(policy, &prefs); |
20 std::string pref_value; | 20 std::string pref_value; |
21 EXPECT_FALSE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); | 21 EXPECT_FALSE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); |
22 EXPECT_EQ("", pref_value); | 22 EXPECT_EQ("", pref_value); |
23 } | 23 } |
24 | 24 |
25 TEST(ContextualSearchPolicyHandlerAndroidTest, Enabled) { | 25 TEST(ContextualSearchPolicyHandlerAndroidTest, Enabled) { |
26 PolicyMap policy; | 26 PolicyMap policy; |
27 policy.Set(key::kContextualSearchEnabled, | 27 policy.Set(key::kContextualSearchEnabled, |
28 POLICY_LEVEL_MANDATORY, | 28 POLICY_LEVEL_MANDATORY, |
29 POLICY_SCOPE_USER, | 29 POLICY_SCOPE_USER, |
| 30 POLICY_SOURCE_PLATFORM, |
30 new base::FundamentalValue(true), | 31 new base::FundamentalValue(true), |
31 NULL); | 32 NULL); |
32 PrefValueMap prefs; | 33 PrefValueMap prefs; |
33 ContextualSearchPolicyHandlerAndroid handler; | 34 ContextualSearchPolicyHandlerAndroid handler; |
34 handler.ApplyPolicySettings(policy, &prefs); | 35 handler.ApplyPolicySettings(policy, &prefs); |
35 | 36 |
36 // Enabling Contextual Search policy should not set the pref. | 37 // Enabling Contextual Search policy should not set the pref. |
37 std::string pref_value; | 38 std::string pref_value; |
38 EXPECT_FALSE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); | 39 EXPECT_FALSE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); |
39 EXPECT_EQ("", pref_value); | 40 EXPECT_EQ("", pref_value); |
40 } | 41 } |
41 | 42 |
42 TEST(ContextualSearchPolicyHandlerAndroidTest, Disabled) { | 43 TEST(ContextualSearchPolicyHandlerAndroidTest, Disabled) { |
43 PolicyMap policy; | 44 PolicyMap policy; |
44 policy.Set(key::kContextualSearchEnabled, | 45 policy.Set(key::kContextualSearchEnabled, |
45 POLICY_LEVEL_MANDATORY, | 46 POLICY_LEVEL_MANDATORY, |
46 POLICY_SCOPE_USER, | 47 POLICY_SCOPE_USER, |
| 48 POLICY_SOURCE_PLATFORM, |
47 new base::FundamentalValue(false), | 49 new base::FundamentalValue(false), |
48 NULL); | 50 NULL); |
49 PrefValueMap prefs; | 51 PrefValueMap prefs; |
50 ContextualSearchPolicyHandlerAndroid handler; | 52 ContextualSearchPolicyHandlerAndroid handler; |
51 handler.ApplyPolicySettings(policy, &prefs); | 53 handler.ApplyPolicySettings(policy, &prefs); |
52 | 54 |
53 // Disabling Contextual Search should switch the pref to managed. | 55 // Disabling Contextual Search should switch the pref to managed. |
54 std::string pref_value; | 56 std::string pref_value; |
55 EXPECT_TRUE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); | 57 EXPECT_TRUE(prefs.GetString(prefs::kContextualSearchEnabled, &pref_value)); |
56 EXPECT_EQ("false", pref_value); | 58 EXPECT_EQ("false", pref_value); |
57 } | 59 } |
58 | 60 |
59 } // namespace policy | 61 } // namespace policy |
OLD | NEW |