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

Unified Diff: remoting/host/policy_hack/policy_watcher_unittest.cc

Issue 830193002: Using PolicyServiceWatcher instead of PolicyWatcherLinux/Win/Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reuploading with lower "similarity". Created 5 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 side-by-side diff with in-line comments
Download patch
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..797b01d58df3a57c90b9490aba1ad1005d18768e 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,81 @@ 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) {
+ if (!VLOG_IS_ON(1)) {
Sergey Ulanov 2015/01/13 01:17:04 You won't need this if you use VLOG() instead of s
Łukasz Anforowicz 2015/01/13 18:28:29 Advantage of using VLOG_IS_ON + std::cout: - Outpu
+ return;
+ }
+
+ std::cout << "OnPolicyUpdated callback received the following policies:"
Sergey Ulanov 2015/01/13 01:17:04 please use LOG() or VLOG() for logging, instead of
Łukasz Anforowicz 2015/01/13 18:28:29 Done.
+ << 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:
+// 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

Powered by Google App Engine
This is Rietveld 408576698