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

Side by Side Diff: chrome/browser/policy/profile_policy_connector_unittest.cc

Issue 2606773002: Setup Chromad user policy plumbing (Closed)
Patch Set: Rebase Created 3 years, 11 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/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 base::MessageLoop loop_; 57 base::MessageLoop loop_;
58 SchemaRegistry schema_registry_; 58 SchemaRegistry schema_registry_;
59 MockConfigurationPolicyProvider mock_provider_; 59 MockConfigurationPolicyProvider mock_provider_;
60 MockCloudPolicyStore cloud_policy_store_; 60 MockCloudPolicyStore cloud_policy_store_;
61 std::unique_ptr<CloudPolicyManager> cloud_policy_manager_; 61 std::unique_ptr<CloudPolicyManager> cloud_policy_manager_;
62 }; 62 };
63 63
64 TEST_F(ProfilePolicyConnectorTest, IsManagedForManagedUsers) { 64 TEST_F(ProfilePolicyConnectorTest, IsManagedForManagedUsers) {
65 ProfilePolicyConnector connector; 65 ProfilePolicyConnector connector;
66 connector.Init( 66 connector.Init(nullptr /* user */, &schema_registry_,
67 #if defined(OS_CHROMEOS) 67 cloud_policy_manager_.get(), &cloud_policy_store_);
68 nullptr,
69 #endif
70 &schema_registry_, cloud_policy_manager_.get());
71 EXPECT_FALSE(connector.IsManaged()); 68 EXPECT_FALSE(connector.IsManaged());
72 EXPECT_EQ(connector.GetManagementDomain(), ""); 69 EXPECT_EQ(connector.GetManagementDomain(), "");
73 70
74 cloud_policy_store_.policy_.reset(new enterprise_management::PolicyData()); 71 cloud_policy_store_.policy_.reset(new enterprise_management::PolicyData());
75 cloud_policy_store_.policy_->set_username("test@testdomain.com"); 72 cloud_policy_store_.policy_->set_username("test@testdomain.com");
76 cloud_policy_store_.policy_->set_state( 73 cloud_policy_store_.policy_->set_state(
77 enterprise_management::PolicyData::ACTIVE); 74 enterprise_management::PolicyData::ACTIVE);
78 EXPECT_TRUE(connector.IsManaged()); 75 EXPECT_TRUE(connector.IsManaged());
79 EXPECT_EQ(connector.GetManagementDomain(), "testdomain.com"); 76 EXPECT_EQ(connector.GetManagementDomain(), "testdomain.com");
80 77
81 // Cleanup. 78 // Cleanup.
82 connector.Shutdown(); 79 connector.Shutdown();
83 } 80 }
84 81
85 TEST_F(ProfilePolicyConnectorTest, IsPolicyFromCloudPolicy) { 82 TEST_F(ProfilePolicyConnectorTest, IsProfilePolicy) {
86 ProfilePolicyConnector connector; 83 ProfilePolicyConnector connector;
87 connector.Init( 84 connector.Init(nullptr /* user */, &schema_registry_,
88 #if defined(OS_CHROMEOS) 85 cloud_policy_manager_.get(), &cloud_policy_store_);
89 nullptr,
90 #endif
91 &schema_registry_, cloud_policy_manager_.get());
92 86
93 // No policy is set initially. 87 // No policy is set initially.
94 EXPECT_FALSE( 88 EXPECT_FALSE(connector.IsProfilePolicy(autofill::prefs::kAutofillEnabled));
95 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled));
96 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string()); 89 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string());
97 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue( 90 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue(
98 key::kAutoFillEnabled)); 91 key::kAutoFillEnabled));
99 92
100 // Set the policy at the cloud provider. 93 // Set the policy at the cloud provider.
101 cloud_policy_store_.policy_map_.Set( 94 cloud_policy_store_.policy_map_.Set(
102 key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 95 key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
103 POLICY_SOURCE_CLOUD, base::MakeUnique<base::FundamentalValue>(false), 96 POLICY_SOURCE_CLOUD, base::MakeUnique<base::FundamentalValue>(false),
104 nullptr); 97 nullptr);
105 cloud_policy_store_.NotifyStoreLoaded(); 98 cloud_policy_store_.NotifyStoreLoaded();
106 base::RunLoop().RunUntilIdle(); 99 base::RunLoop().RunUntilIdle();
107 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); 100 EXPECT_TRUE(connector.IsProfilePolicy(key::kAutoFillEnabled));
108 const base::Value* value = 101 const base::Value* value =
109 connector.policy_service()->GetPolicies(chrome_ns).GetValue( 102 connector.policy_service()->GetPolicies(chrome_ns).GetValue(
110 key::kAutoFillEnabled); 103 key::kAutoFillEnabled);
111 ASSERT_TRUE(value); 104 ASSERT_TRUE(value);
112 EXPECT_TRUE(base::FundamentalValue(false).Equals(value)); 105 EXPECT_TRUE(base::FundamentalValue(false).Equals(value));
113 106
114 // Now test with a higher-priority provider also setting the policy. 107 // Now test with a higher-priority provider also setting the policy.
115 PolicyMap map; 108 PolicyMap map;
116 map.Set(key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 109 map.Set(key::kAutoFillEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
117 POLICY_SOURCE_CLOUD, base::MakeUnique<base::FundamentalValue>(true), 110 POLICY_SOURCE_CLOUD, base::MakeUnique<base::FundamentalValue>(true),
118 nullptr); 111 nullptr);
119 mock_provider_.UpdateChromePolicy(map); 112 mock_provider_.UpdateChromePolicy(map);
120 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); 113 EXPECT_FALSE(connector.IsProfilePolicy(key::kAutoFillEnabled));
121 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue( 114 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue(
122 key::kAutoFillEnabled); 115 key::kAutoFillEnabled);
123 ASSERT_TRUE(value); 116 ASSERT_TRUE(value);
124 EXPECT_TRUE(base::FundamentalValue(true).Equals(value)); 117 EXPECT_TRUE(base::FundamentalValue(true).Equals(value));
125 118
126 // Cleanup. 119 // Cleanup.
127 connector.Shutdown(); 120 connector.Shutdown();
128 } 121 }
129 122
130 } // namespace policy 123 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698