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..73544c5c3f9930298a015a868172d758de5d0ebc 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> |
Sergey Ulanov
2015/01/13 22:30:01
Don't need this anymore
Łukasz Anforowicz
2015/01/13 23:21:24
Ooops. Done.
|
+ |
#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,77 @@ TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { |
StopWatching(); |
} |
+// Unit tests cannot instantiate PolicyWatcher on ChromeOS |
+// (as this requires running inside a browser process). |
+#ifndef OS_CHROMEOS |
+ |
+namespace { |
+ |
+void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) { |
+ VLOG(1) << "OnPolicyUpdated callback received the following policies:"; |
+ |
+ for (base::DictionaryValue::Iterator iter(*policies); !iter.IsAtEnd(); |
+ iter.Advance()) { |
+ switch (iter.value().GetType()) { |
+ case base::Value::Type::TYPE_STRING: { |
+ std::string value; |
+ CHECK(iter.value().GetAsString(&value)); |
+ VLOG(1) << iter.key() << " = " |
+ << "string: " << '"' << value << '"'; |
+ break; |
+ } |
+ case base::Value::Type::TYPE_BOOLEAN: { |
+ bool value; |
+ CHECK(iter.value().GetAsBoolean(&value)); |
+ VLOG(1) << iter.key() << " = " |
+ << "boolean: " << (value ? "True" : "False"); |
+ break; |
+ } |
+ default: { |
+ VLOG(1) << iter.key() << " = " |
+ << "unrecognized type"; |
+ break; |
+ } |
+ } |
+ } |
+} |
+ |
+} // anonymous namespace |
+ |
+// To dump policy contents, run unit tests with the following flags: |
+// out/Debug/remoting_unittests --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 |
+} |
+ |
+#endif |
+ |
+// TODO(lukasza): We should consider adding a test against a |
+// MockConfigurationPolicyProvider. |
+ |
} // namespace policy_hack |
} // namespace remoting |