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

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: Fixed building for Chrome OS. Created 5 years, 12 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..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

Powered by Google App Engine
This is Rietveld 408576698