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

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

Issue 762863002: Removed policy::PolicyNamespaceKey. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pass values in ctors Created 6 years 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/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.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 "chrome/test/base/testing_browser_process.h" 10 #include "chrome/test/base/testing_browser_process.h"
(...skipping 23 matching lines...) Expand all
34 34
35 void SetUp() override { 35 void SetUp() override {
36 // This must be set up before the TestingBrowserProcess is created. 36 // This must be set up before the TestingBrowserProcess is created.
37 BrowserPolicyConnector::SetPolicyProviderForTesting(&mock_provider_); 37 BrowserPolicyConnector::SetPolicyProviderForTesting(&mock_provider_);
38 38
39 EXPECT_CALL(mock_provider_, IsInitializationComplete(_)) 39 EXPECT_CALL(mock_provider_, IsInitializationComplete(_))
40 .WillRepeatedly(Return(true)); 40 .WillRepeatedly(Return(true));
41 41
42 cloud_policy_store_.NotifyStoreLoaded(); 42 cloud_policy_store_.NotifyStoreLoaded();
43 cloud_policy_manager_.reset( 43 cloud_policy_manager_.reset(
44 new CloudPolicyManager(PolicyNamespaceKey("", ""), 44 new CloudPolicyManager(std::string(),
45 std::string(),
45 &cloud_policy_store_, 46 &cloud_policy_store_,
46 loop_.message_loop_proxy(), 47 loop_.message_loop_proxy(),
47 loop_.message_loop_proxy(), 48 loop_.message_loop_proxy(),
48 loop_.message_loop_proxy())); 49 loop_.message_loop_proxy()));
49 } 50 }
50 51
51 void TearDown() override { 52 void TearDown() override {
52 TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(NULL); 53 TestingBrowserProcess::GetGlobal()->SetBrowserPolicyConnector(nullptr);
53 cloud_policy_manager_->Shutdown(); 54 cloud_policy_manager_->Shutdown();
54 } 55 }
55 56
56 base::MessageLoop loop_; 57 base::MessageLoop loop_;
57 SchemaRegistry schema_registry_; 58 SchemaRegistry schema_registry_;
58 MockConfigurationPolicyProvider mock_provider_; 59 MockConfigurationPolicyProvider mock_provider_;
59 MockCloudPolicyStore cloud_policy_store_; 60 MockCloudPolicyStore cloud_policy_store_;
60 scoped_ptr<CloudPolicyManager> cloud_policy_manager_; 61 scoped_ptr<CloudPolicyManager> cloud_policy_manager_;
61 }; 62 };
62 63
63 TEST_F(ProfilePolicyConnectorTest, IsPolicyFromCloudPolicy) { 64 TEST_F(ProfilePolicyConnectorTest, IsPolicyFromCloudPolicy) {
64 ProfilePolicyConnector connector; 65 ProfilePolicyConnector connector;
65 connector.Init(false, 66 connector.Init(false,
66 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
67 NULL, 68 nullptr,
68 #endif 69 #endif
69 &schema_registry_, 70 &schema_registry_,
70 cloud_policy_manager_.get()); 71 cloud_policy_manager_.get());
71 72
72 // No policy is set initially. 73 // No policy is set initially.
73 EXPECT_FALSE( 74 EXPECT_FALSE(
74 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled)); 75 connector.IsPolicyFromCloudPolicy(autofill::prefs::kAutofillEnabled));
75 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); 76 PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string());
76 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue( 77 EXPECT_FALSE(connector.policy_service()->GetPolicies(chrome_ns).GetValue(
77 key::kAutoFillEnabled)); 78 key::kAutoFillEnabled));
78 79
79 // Set the policy at the cloud provider. 80 // Set the policy at the cloud provider.
80 cloud_policy_store_.policy_map_.Set(key::kAutoFillEnabled, 81 cloud_policy_store_.policy_map_.Set(key::kAutoFillEnabled,
81 POLICY_LEVEL_MANDATORY, 82 POLICY_LEVEL_MANDATORY,
82 POLICY_SCOPE_USER, 83 POLICY_SCOPE_USER,
83 new base::FundamentalValue(false), 84 new base::FundamentalValue(false),
84 NULL); 85 nullptr);
85 cloud_policy_store_.NotifyStoreLoaded(); 86 cloud_policy_store_.NotifyStoreLoaded();
86 base::RunLoop().RunUntilIdle(); 87 base::RunLoop().RunUntilIdle();
87 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); 88 EXPECT_TRUE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled));
88 const base::Value* value = 89 const base::Value* value =
89 connector.policy_service()->GetPolicies(chrome_ns).GetValue( 90 connector.policy_service()->GetPolicies(chrome_ns).GetValue(
90 key::kAutoFillEnabled); 91 key::kAutoFillEnabled);
91 ASSERT_TRUE(value); 92 ASSERT_TRUE(value);
92 EXPECT_TRUE(base::FundamentalValue(false).Equals(value)); 93 EXPECT_TRUE(base::FundamentalValue(false).Equals(value));
93 94
94 // Now test with a higher-priority provider also setting the policy. 95 // Now test with a higher-priority provider also setting the policy.
95 PolicyMap map; 96 PolicyMap map;
96 map.Set(key::kAutoFillEnabled, 97 map.Set(key::kAutoFillEnabled,
97 POLICY_LEVEL_MANDATORY, 98 POLICY_LEVEL_MANDATORY,
98 POLICY_SCOPE_USER, 99 POLICY_SCOPE_USER,
99 new base::FundamentalValue(true), 100 new base::FundamentalValue(true),
100 NULL); 101 nullptr);
101 mock_provider_.UpdateChromePolicy(map); 102 mock_provider_.UpdateChromePolicy(map);
102 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled)); 103 EXPECT_FALSE(connector.IsPolicyFromCloudPolicy(key::kAutoFillEnabled));
103 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue( 104 value = connector.policy_service()->GetPolicies(chrome_ns).GetValue(
104 key::kAutoFillEnabled); 105 key::kAutoFillEnabled);
105 ASSERT_TRUE(value); 106 ASSERT_TRUE(value);
106 EXPECT_TRUE(base::FundamentalValue(true).Equals(value)); 107 EXPECT_TRUE(base::FundamentalValue(true).Equals(value));
107 108
108 // Cleanup. 109 // Cleanup.
109 connector.Shutdown(); 110 connector.Shutdown();
110 } 111 }
111 112
112 } // namespace policy 113 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698