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

Side by Side Diff: chrome/browser/policy/profile_policy_connector_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 "chrome/browser/policy/profile_policy_connector.h" 5 #include "chrome/browser/policy/profile_policy_connector.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 #include "chrome/test/base/testing_browser_process.h" 11 #include "chrome/test/base/testing_browser_process.h"
11 #include "components/autofill/core/common/autofill_pref_names.h" 12 #include "components/autofill/core/common/autofill_pref_names.h"
12 #include "components/policy/core/browser/browser_policy_connector.h" 13 #include "components/policy/core/browser/browser_policy_connector.h"
13 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 14 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
14 #include "components/policy/core/common/cloud/cloud_policy_manager.h" 15 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
15 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 16 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
16 #include "components/policy/core/common/mock_configuration_policy_provider.h" 17 #include "components/policy/core/common/mock_configuration_policy_provider.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 &schema_registry_, cloud_policy_manager_.get()); 90 &schema_registry_, cloud_policy_manager_.get());
90 91
91 // No policy is set initially. 92 // No policy is set initially.
92 EXPECT_FALSE( 93 EXPECT_FALSE(
93 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled)); 94 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled));
94 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string()); 95 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string());
95 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue( 96 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue(
96 key::kAutoFillEnabled)); 97 key::kAutoFillEnabled));
97 98
98 // Set the policy at the cloud provider. 99 // Set the policy at the cloud provider.
99 cloud_policy_store_.policy_map_.Set(key::kAutoFillEnabled, 100 cloud_policy_store_.policy_map_.Set(
100 POLICY_LEVEL_MANDATORY, 101 key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
101 POLICY_SCOPE_USER, 102 POLICY_SOURCE_CLOUD, base::WrapUnique(new base::FundamentalValue(false)),
102 POLICY_SOURCE_CLOUD, 103 nullptr);
103 new base::FundamentalValue(false),
104 nullptr);
105 cloud_policy_store_.NotifyStoreLoaded(); 104 cloud_policy_store_.NotifyStoreLoaded();
106 base::RunLoop().RunUntilIdle(); 105 base::RunLoop().RunUntilIdle();
107 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); 106 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled));
108 const base::Value* value = 107 const base::Value* value =
109 connector.policy_service()->GetPolicies(chrome_ns).GetValue( 108 connector.policy_service()->GetPolicies(chrome_ns).GetValue(
110 key::kAutoFillEnabled); 109 key::kAutoFillEnabled);
111 ASSERT_TRUE(value); 110 ASSERT_TRUE(value);
112 EXPECT_TRUE(base::FundamentalValue(false).Equals(value)); 111 EXPECT_TRUE(base::FundamentalValue(false).Equals(value));
113 112
114 // Now test with a higher-priority provider also setting the policy. 113 // Now test with a higher-priority provider also setting the policy.
115 PolicyMap map; 114 PolicyMap map;
116 map.Set(key::kAutoFillEnabled, 115 map.Set(key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
117 POLICY_LEVEL_MANDATORY,
118 POLICY_SCOPE_USER,
119 POLICY_SOURCE_CLOUD, 116 POLICY_SOURCE_CLOUD,
120 new base::FundamentalValue(true), 117 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
121 nullptr);
122 mock_provider_.UpdateChromePolicy(map); 118 mock_provider_.UpdateChromePolicy(map);
123 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); 119 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled));
124 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue( 120 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue(
125 key::kAutoFillEnabled); 121 key::kAutoFillEnabled);
126 ASSERT_TRUE(value); 122 ASSERT_TRUE(value);
127 EXPECT_TRUE(base::FundamentalValue(true).Equals(value)); 123 EXPECT_TRUE(base::FundamentalValue(true).Equals(value));
128 124
129 // Cleanup. 125 // Cleanup.
130 connector.Shutdown(); 126 connector.Shutdown();
131 } 127 }
132 128
133 } // namespace policy 129 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_startup_browsertest.cc ('k') | chrome/browser/prefs/proxy_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698