Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: components/policy/core/browser/autofill_policy_handler_unittest.cc

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ptr_util.h"
5 #include "base/values.h" 6 #include "base/values.h"
6 #include "components/autofill/core/common/autofill_pref_names.h" 7 #include "components/autofill/core/common/autofill_pref_names.h"
7 #include "components/policy/core/browser/autofill_policy_handler.h" 8 #include "components/policy/core/browser/autofill_policy_handler.h"
8 #include "components/policy/core/common/policy_map.h" 9 #include "components/policy/core/common/policy_map.h"
9 #include "components/policy/core/common/policy_types.h" 10 #include "components/policy/core/common/policy_types.h"
10 #include "components/prefs/pref_value_map.h" 11 #include "components/prefs/pref_value_map.h"
11 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace policy { 15 namespace policy {
15 16
16 // Test cases for the Autofill policy setting. 17 // Test cases for the Autofill policy setting.
17 class AutofillPolicyHandlerTest : public testing::Test {}; 18 class AutofillPolicyHandlerTest : public testing::Test {};
18 19
19 TEST_F(AutofillPolicyHandlerTest, Default) { 20 TEST_F(AutofillPolicyHandlerTest, Default) {
20 PolicyMap policy; 21 PolicyMap policy;
21 PrefValueMap prefs; 22 PrefValueMap prefs;
22 AutofillPolicyHandler handler; 23 AutofillPolicyHandler handler;
23 handler.ApplyPolicySettings(policy, &prefs); 24 handler.ApplyPolicySettings(policy, &prefs);
24 EXPECT_FALSE(prefs.GetValue(autofill::prefs::kAutofillEnabled, NULL)); 25 EXPECT_FALSE(prefs.GetValue(autofill::prefs::kAutofillEnabled, NULL));
25 } 26 }
26 27
27 TEST_F(AutofillPolicyHandlerTest, Enabled) { 28 TEST_F(AutofillPolicyHandlerTest, Enabled) {
28 PolicyMap policy; 29 PolicyMap policy;
29 policy.Set(key::kAutoFillEnabled, 30 policy.Set(key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
30 POLICY_LEVEL_MANDATORY,
31 POLICY_SCOPE_USER,
32 POLICY_SOURCE_CLOUD, 31 POLICY_SOURCE_CLOUD,
33 new base::FundamentalValue(true), 32 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
34 NULL);
35 PrefValueMap prefs; 33 PrefValueMap prefs;
36 AutofillPolicyHandler handler; 34 AutofillPolicyHandler handler;
37 handler.ApplyPolicySettings(policy, &prefs); 35 handler.ApplyPolicySettings(policy, &prefs);
38 36
39 // Enabling Autofill should not set the pref. 37 // Enabling Autofill should not set the pref.
40 EXPECT_FALSE(prefs.GetValue(autofill::prefs::kAutofillEnabled, NULL)); 38 EXPECT_FALSE(prefs.GetValue(autofill::prefs::kAutofillEnabled, NULL));
41 } 39 }
42 40
43 TEST_F(AutofillPolicyHandlerTest, Disabled) { 41 TEST_F(AutofillPolicyHandlerTest, Disabled) {
44 PolicyMap policy; 42 PolicyMap policy;
45 policy.Set(key::kAutoFillEnabled, 43 policy.Set(key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
46 POLICY_LEVEL_MANDATORY,
47 POLICY_SCOPE_USER,
48 POLICY_SOURCE_CLOUD, 44 POLICY_SOURCE_CLOUD,
49 new base::FundamentalValue(false), 45 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
50 NULL);
51 PrefValueMap prefs; 46 PrefValueMap prefs;
52 AutofillPolicyHandler handler; 47 AutofillPolicyHandler handler;
53 handler.ApplyPolicySettings(policy, &prefs); 48 handler.ApplyPolicySettings(policy, &prefs);
54 49
55 // Disabling Autofill should switch the pref to managed. 50 // Disabling Autofill should switch the pref to managed.
56 const base::Value* value = NULL; 51 const base::Value* value = NULL;
57 EXPECT_TRUE(prefs.GetValue(autofill::prefs::kAutofillEnabled, &value)); 52 EXPECT_TRUE(prefs.GetValue(autofill::prefs::kAutofillEnabled, &value));
58 ASSERT_TRUE(value); 53 ASSERT_TRUE(value);
59 bool autofill_enabled = true; 54 bool autofill_enabled = true;
60 bool result = value->GetAsBoolean(&autofill_enabled); 55 bool result = value->GetAsBoolean(&autofill_enabled);
61 ASSERT_TRUE(result); 56 ASSERT_TRUE(result);
62 EXPECT_FALSE(autofill_enabled); 57 EXPECT_FALSE(autofill_enabled);
63 } 58 }
64 59
65 } // namespace policy 60 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698