Chromium Code Reviews| Index: remoting/host/policy_hack/policy_watcher_unittest.cc |
| diff --git a/remoting/host/policy_hack/policy_watcher_unittest.cc b/remoting/host/policy_hack/policy_watcher_unittest.cc |
| index cb9415485e8bc961f1d9678cfa0f2d9cbaa65a09..6c7d385d95ae8228020541168260ca0af3dfa69f 100644 |
| --- a/remoting/host/policy_hack/policy_watcher_unittest.cc |
| +++ b/remoting/host/policy_hack/policy_watcher_unittest.cc |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <iostream> |
| + |
| #include "base/basictypes.h" |
| #include "base/bind.h" |
| #include "base/message_loop/message_loop.h" |
| @@ -19,8 +21,7 @@ namespace policy_hack { |
| class PolicyWatcherTest : public testing::Test { |
| public: |
| - PolicyWatcherTest() { |
| - } |
| + PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} |
| void SetUp() override { |
| message_loop_proxy_ = base::MessageLoopProxy::current(); |
| @@ -448,5 +449,78 @@ TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { |
| StopWatching(); |
| } |
| +// Unit tests cannot instantiate PolicyWatcher on ChromeOS |
| +// (as this requires running inside a browser process). |
|
Mattias Nissler (ping if slow)
2015/01/06 09:06:12
You could create a fake PolicyService and test aga
Łukasz Anforowicz
2015/01/07 17:54:15
If PolicyServiceWatcher is here for the long term,
Mattias Nissler (ping if slow)
2015/01/08 09:58:36
OK, fair enough.
|
| +#ifndef OS_CHROMEOS |
| + |
| +namespace { |
| + |
| +void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) { |
| + if (!VLOG_IS_ON(1)) { |
| + return; |
| + } |
| + |
| + std::cout << "OnPolicyUpdated callback received the following policies:" |
| + << std::endl; |
| + |
| + for (base::DictionaryValue::Iterator iter(*policies); !iter.IsAtEnd(); |
| + iter.Advance()) { |
| + std::cout << iter.key() << " = "; |
| + switch (iter.value().GetType()) { |
| + case base::Value::Type::TYPE_STRING: { |
| + std::string value; |
| + CHECK(iter.value().GetAsString(&value)); |
| + std::cout << "string: " << '"' << value << '"'; |
| + break; |
| + } |
| + case base::Value::Type::TYPE_BOOLEAN: { |
| + bool value; |
| + CHECK(iter.value().GetAsBoolean(&value)); |
| + std::cout << "boolean: " << (value ? "True" : "False"); |
| + break; |
| + } |
| + default: { |
| + std::cout << "unrecognized type"; |
| + break; |
| + } |
| + } |
| + std::cout << std::endl; |
| + } |
| +} |
| + |
| +} // anonymous namespace |
| + |
| +// To dump policy contents, run unit tests with the following flags: |
| +// --gtest_filter=*TestRealChromotingPolicy* -v=1 |
| +TEST_F(PolicyWatcherTest, TestRealChromotingPolicy) { |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| + base::MessageLoop::current()->task_runner(); |
| + scoped_ptr<PolicyWatcher> policy_watcher( |
| + PolicyWatcher::Create(nullptr, task_runner)); |
| + |
| + { |
| + base::RunLoop run_loop; |
| + policy_watcher->StartWatching(base::Bind(OnPolicyUpdatedDumpPolicy), |
| + base::Bind(base::DoNothing)); |
| + run_loop.RunUntilIdle(); |
| + } |
| + |
| + { |
| + base::RunLoop run_loop; |
| + PolicyWatcher* raw_policy_watcher = policy_watcher.release(); |
| + raw_policy_watcher->StopWatching( |
| + base::Bind(base::IgnoreResult( |
| + &base::SequencedTaskRunner::DeleteSoon<PolicyWatcher>), |
| + task_runner, FROM_HERE, raw_policy_watcher)); |
| + run_loop.RunUntilIdle(); |
| + } |
| + |
| + // Today, the only verification offered by this test is: |
| + // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy |
| + // - Automated verification that nothing crashed |
|
Mattias Nissler (ping if slow)
2015/01/06 09:06:12
It may make sense to add a test that tests PolicyS
Łukasz Anforowicz
2015/01/07 17:54:15
Yes, but see my other comment for explanation why
Mattias Nissler (ping if slow)
2015/01/08 09:58:36
OK, might still want to document proposed improvem
Łukasz Anforowicz
2015/01/08 23:09:26
I thought about it and the test against a MockConf
|
| +} |
| + |
| +#endif |
| + |
| } // namespace policy_hack |
| } // namespace remoting |