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

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

Powered by Google App Engine
This is Rietveld 408576698