OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/host/policy_watcher.h" | 5 #include "remoting/host/policy_watcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Simulate a policy file/registry/preference update. | 183 // Simulate a policy file/registry/preference update. |
184 policy_loader_->SetPolicies(policy_bundle); | 184 policy_loader_->SetPolicies(policy_bundle); |
185 policy_loader_->PostReloadOnBackgroundThread(true /* force reload asap */); | 185 policy_loader_->PostReloadOnBackgroundThread(true /* force reload asap */); |
186 base::RunLoop().RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
187 } | 187 } |
188 | 188 |
189 const policy::Schema* GetPolicySchema() { | 189 const policy::Schema* GetPolicySchema() { |
190 return policy_watcher_->GetPolicySchema(); | 190 return policy_watcher_->GetPolicySchema(); |
191 } | 191 } |
192 | 192 |
193 const base::DictionaryValue& GetDefaultValues() { | 193 const base::DictionaryValue* GetDefaultValues() { |
194 return *(policy_watcher_->default_values_); | 194 return policy_watcher_->GetDefaultValues(); |
195 } | 195 } |
196 | 196 |
197 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); | 197 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); |
198 | 198 |
199 static const char* kHostDomain; | 199 static const char* kHostDomain; |
200 static const char* kPortRange; | 200 static const char* kPortRange; |
201 base::MessageLoop message_loop_; | 201 base::MessageLoop message_loop_; |
202 MockPolicyCallback mock_policy_callback_; | 202 MockPolicyCallback mock_policy_callback_; |
203 | 203 |
204 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains | 204 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 kDefaultHostTalkGadgetPrefix); | 257 kDefaultHostTalkGadgetPrefix); |
258 dict.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); | 258 dict.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); |
259 dict.SetString(key::kRemoteAccessHostTokenUrl, ""); | 259 dict.SetString(key::kRemoteAccessHostTokenUrl, ""); |
260 dict.SetString(key::kRemoteAccessHostTokenValidationUrl, ""); | 260 dict.SetString(key::kRemoteAccessHostTokenValidationUrl, ""); |
261 dict.SetString(key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); | 261 dict.SetString(key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); |
262 dict.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); | 262 dict.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); |
263 dict.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); | 263 dict.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); |
264 dict.SetBoolean(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, | 264 dict.SetBoolean(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, |
265 false); | 265 false); |
266 | 266 |
267 ASSERT_THAT(&dict, IsPolicies(&GetDefaultValues())) | 267 ASSERT_THAT(&dict, IsPolicies(GetDefaultValues())) |
268 << "Sanity check that defaults expected by the test code " | 268 << "Sanity check that defaults expected by the test code " |
269 << "match what is stored in PolicyWatcher::default_values_"; | 269 << "match what is stored in PolicyWatcher::default_values_"; |
270 } | 270 } |
271 }; | 271 }; |
272 | 272 |
273 const char* PolicyWatcherTest::kHostDomain = "google.com"; | 273 const char* PolicyWatcherTest::kHostDomain = "google.com"; |
274 const char* PolicyWatcherTest::kPortRange = "12400-12409"; | 274 const char* PolicyWatcherTest::kPortRange = "12400-12409"; |
275 | 275 |
276 TEST_F(PolicyWatcherTest, None) { | 276 TEST_F(PolicyWatcherTest, None) { |
277 EXPECT_CALL(mock_policy_callback_, | 277 EXPECT_CALL(mock_policy_callback_, |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 629 } |
630 | 630 |
631 TEST_F(PolicyWatcherTest, PolicySchemaAndPolicyWatcherShouldBeInSync) { | 631 TEST_F(PolicyWatcherTest, PolicySchemaAndPolicyWatcherShouldBeInSync) { |
632 // This test verifies that | 632 // This test verifies that |
633 // 1) policy schema (generated out of policy_templates.json) | 633 // 1) policy schema (generated out of policy_templates.json) |
634 // and | 634 // and |
635 // 2) PolicyWatcher's code (i.e. contents of the |default_values_| field) | 635 // 2) PolicyWatcher's code (i.e. contents of the |default_values_| field) |
636 // are kept in-sync. | 636 // are kept in-sync. |
637 | 637 |
638 std::map<std::string, base::Value::Type> expected_schema; | 638 std::map<std::string, base::Value::Type> expected_schema; |
639 for (base::DictionaryValue::Iterator i(GetDefaultValues()); !i.IsAtEnd(); | 639 for (base::DictionaryValue::Iterator i(*GetDefaultValues()); !i.IsAtEnd(); |
640 i.Advance()) { | 640 i.Advance()) { |
641 expected_schema[i.key()] = i.value().GetType(); | 641 expected_schema[i.key()] = i.value().GetType(); |
642 } | 642 } |
643 #if defined(OS_WIN) | 643 #if defined(OS_WIN) |
644 // RemoteAccessHostMatchUsername is marked in policy_templates.json as not | 644 // RemoteAccessHostMatchUsername is marked in policy_templates.json as not |
645 // supported on Windows and therefore is (by design) excluded from the schema. | 645 // supported on Windows and therefore is (by design) excluded from the schema. |
646 expected_schema.erase(key::kRemoteAccessHostMatchUsername); | 646 expected_schema.erase(key::kRemoteAccessHostMatchUsername); |
647 #else // !defined(OS_WIN) | 647 #else // !defined(OS_WIN) |
648 // RemoteAssistanceHostAllowUiAccess does not exist on non-Windows platforms. | 648 // RemoteAssistanceHostAllowUiAccess does not exist on non-Windows platforms. |
649 expected_schema.erase(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance); | 649 expected_schema.erase(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance); |
(...skipping 28 matching lines...) Expand all Loading... |
678 | 678 |
679 // And check one, random "boolean" policy to see if the type propagated | 679 // And check one, random "boolean" policy to see if the type propagated |
680 // correctly from policy_templates.json file. | 680 // correctly from policy_templates.json file. |
681 const policy::Schema boolean_schema = | 681 const policy::Schema boolean_schema = |
682 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); | 682 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); |
683 EXPECT_TRUE(boolean_schema.valid()); | 683 EXPECT_TRUE(boolean_schema.valid()); |
684 EXPECT_EQ(boolean_schema.type(), base::Value::Type::BOOLEAN); | 684 EXPECT_EQ(boolean_schema.type(), base::Value::Type::BOOLEAN); |
685 } | 685 } |
686 | 686 |
687 } // namespace remoting | 687 } // namespace remoting |
OLD | NEW |