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

Side by Side 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: Addressed code review feedback from Sergey. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <iostream>
Sergey Ulanov 2015/01/13 22:30:01 Don't need this anymore
Łukasz Anforowicz 2015/01/13 23:21:24 Ooops. Done.
6
5 #include "base/basictypes.h" 7 #include "base/basictypes.h"
6 #include "base/bind.h" 8 #include "base/bind.h"
7 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 10 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
10 #include "remoting/host/dns_blackhole_checker.h" 12 #include "remoting/host/dns_blackhole_checker.h"
11 #include "remoting/host/policy_hack/fake_policy_watcher.h" 13 #include "remoting/host/policy_hack/fake_policy_watcher.h"
12 #include "remoting/host/policy_hack/mock_policy_callback.h" 14 #include "remoting/host/policy_hack/mock_policy_callback.h"
13 #include "remoting/host/policy_hack/policy_watcher.h" 15 #include "remoting/host/policy_hack/policy_watcher.h"
14 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace remoting { 19 namespace remoting {
18 namespace policy_hack { 20 namespace policy_hack {
19 21
20 class PolicyWatcherTest : public testing::Test { 22 class PolicyWatcherTest : public testing::Test {
21 public: 23 public:
22 PolicyWatcherTest() { 24 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {}
23 }
24 25
25 void SetUp() override { 26 void SetUp() override {
26 message_loop_proxy_ = base::MessageLoopProxy::current(); 27 message_loop_proxy_ = base::MessageLoopProxy::current();
27 policy_updated_callback_ = base::Bind( 28 policy_updated_callback_ = base::Bind(
28 &MockPolicyCallback::OnPolicyUpdate, 29 &MockPolicyCallback::OnPolicyUpdate,
29 base::Unretained(&mock_policy_callback_)); 30 base::Unretained(&mock_policy_callback_));
30 policy_error_callback_ = base::Bind( 31 policy_error_callback_ = base::Bind(
31 &MockPolicyCallback::OnPolicyError, 32 &MockPolicyCallback::OnPolicyError,
32 base::Unretained(&mock_policy_callback_)); 33 base::Unretained(&mock_policy_callback_));
33 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); 34 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_));
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 442 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
442 policy_watcher_->SignalTransientErrorForTest(); 443 policy_watcher_->SignalTransientErrorForTest();
443 } 444 }
444 policy_watcher_->SetPolicies(&nat_true_); 445 policy_watcher_->SetPolicies(&nat_true_);
445 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 446 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
446 policy_watcher_->SignalTransientErrorForTest(); 447 policy_watcher_->SignalTransientErrorForTest();
447 } 448 }
448 StopWatching(); 449 StopWatching();
449 } 450 }
450 451
452 // Unit tests cannot instantiate PolicyWatcher on ChromeOS
453 // (as this requires running inside a browser process).
454 #ifndef OS_CHROMEOS
455
456 namespace {
457
458 void OnPolicyUpdatedDumpPolicy(scoped_ptr<base::DictionaryValue> policies) {
459 VLOG(1) << "OnPolicyUpdated callback received the following policies:";
460
461 for (base::DictionaryValue::Iterator iter(*policies); !iter.IsAtEnd();
462 iter.Advance()) {
463 switch (iter.value().GetType()) {
464 case base::Value::Type::TYPE_STRING: {
465 std::string value;
466 CHECK(iter.value().GetAsString(&value));
467 VLOG(1) << iter.key() << " = "
468 << "string: " << '"' << value << '"';
469 break;
470 }
471 case base::Value::Type::TYPE_BOOLEAN: {
472 bool value;
473 CHECK(iter.value().GetAsBoolean(&value));
474 VLOG(1) << iter.key() << " = "
475 << "boolean: " << (value ? "True" : "False");
476 break;
477 }
478 default: {
479 VLOG(1) << iter.key() << " = "
480 << "unrecognized type";
481 break;
482 }
483 }
484 }
485 }
486
487 } // anonymous namespace
488
489 // To dump policy contents, run unit tests with the following flags:
490 // out/Debug/remoting_unittests --gtest_filter=*TestRealChromotingPolicy* -v=1
491 TEST_F(PolicyWatcherTest, TestRealChromotingPolicy) {
492 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
493 base::MessageLoop::current()->task_runner();
494 scoped_ptr<PolicyWatcher> policy_watcher(
495 PolicyWatcher::Create(nullptr, task_runner));
496
497 {
498 base::RunLoop run_loop;
499 policy_watcher->StartWatching(base::Bind(OnPolicyUpdatedDumpPolicy),
500 base::Bind(base::DoNothing));
501 run_loop.RunUntilIdle();
502 }
503
504 {
505 base::RunLoop run_loop;
506 PolicyWatcher* raw_policy_watcher = policy_watcher.release();
507 raw_policy_watcher->StopWatching(
508 base::Bind(base::IgnoreResult(
509 &base::SequencedTaskRunner::DeleteSoon<PolicyWatcher>),
510 task_runner, FROM_HERE, raw_policy_watcher));
511 run_loop.RunUntilIdle();
512 }
513
514 // Today, the only verification offered by this test is:
515 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy
516 // - Automated verification that nothing crashed
517 }
518
519 #endif
520
521 // TODO(lukasza): We should consider adding a test against a
522 // MockConfigurationPolicyProvider.
523
451 } // namespace policy_hack 524 } // namespace policy_hack
452 } // namespace remoting 525 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698