| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/mock_log.h" | 12 #include "base/test/mock_log.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 12 #include "components/policy/core/common/fake_async_policy_loader.h" | 14 #include "components/policy/core/common/fake_async_policy_loader.h" |
| 13 #include "policy/policy_constants.h" | 15 #include "policy/policy_constants.h" |
| 14 #include "remoting/host/dns_blackhole_checker.h" | 16 #include "remoting/host/dns_blackhole_checker.h" |
| 15 #include "remoting/host/policy_watcher.h" | 17 #include "remoting/host/policy_watcher.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 namespace remoting { | 21 namespace remoting { |
| 20 | 22 |
| 21 namespace key = ::policy::key; | 23 namespace key = ::policy::key; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 58 |
| 57 class PolicyWatcherTest : public testing::Test { | 59 class PolicyWatcherTest : public testing::Test { |
| 58 public: | 60 public: |
| 59 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} | 61 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} |
| 60 | 62 |
| 61 void SetUp() override { | 63 void SetUp() override { |
| 62 // We expect no callbacks unless explicitly specified by individual tests. | 64 // We expect no callbacks unless explicitly specified by individual tests. |
| 63 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)).Times(0); | 65 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)).Times(0); |
| 64 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); | 66 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); |
| 65 | 67 |
| 66 message_loop_proxy_ = base::MessageLoopProxy::current(); | |
| 67 | |
| 68 // Retaining a raw pointer to keep control over policy contents. | 68 // Retaining a raw pointer to keep control over policy contents. |
| 69 policy_loader_ = new policy::FakeAsyncPolicyLoader(message_loop_proxy_); | 69 policy_loader_ = |
| 70 new policy::FakeAsyncPolicyLoader(base::ThreadTaskRunnerHandle::Get()); |
| 70 policy_watcher_ = | 71 policy_watcher_ = |
| 71 PolicyWatcher::CreateFromPolicyLoader(make_scoped_ptr(policy_loader_)); | 72 PolicyWatcher::CreateFromPolicyLoader(make_scoped_ptr(policy_loader_)); |
| 72 | 73 |
| 73 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); | 74 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); |
| 74 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); | 75 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); |
| 75 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); | 76 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); |
| 76 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); | 77 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); |
| 77 nat_one_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 78 nat_one_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); |
| 78 domain_empty_.SetString(key::kRemoteAccessHostDomain, std::string()); | 79 domain_empty_.SetString(key::kRemoteAccessHostDomain, std::string()); |
| 79 domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 80 domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 200 |
| 200 const base::DictionaryValue& GetDefaultValues() { | 201 const base::DictionaryValue& GetDefaultValues() { |
| 201 return *(policy_watcher_->default_values_); | 202 return *(policy_watcher_->default_values_); |
| 202 } | 203 } |
| 203 | 204 |
| 204 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); | 205 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); |
| 205 | 206 |
| 206 static const char* kHostDomain; | 207 static const char* kHostDomain; |
| 207 static const char* kPortRange; | 208 static const char* kPortRange; |
| 208 base::MessageLoop message_loop_; | 209 base::MessageLoop message_loop_; |
| 209 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 210 MockPolicyCallback mock_policy_callback_; | 210 MockPolicyCallback mock_policy_callback_; |
| 211 | 211 |
| 212 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains | 212 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains |
| 213 // a raw pointer to |policy_loader_| in order to control the simulated / faked | 213 // a raw pointer to |policy_loader_| in order to control the simulated / faked |
| 214 // policy contents. | 214 // policy contents. |
| 215 policy::FakeAsyncPolicyLoader* policy_loader_; | 215 policy::FakeAsyncPolicyLoader* policy_loader_; |
| 216 scoped_ptr<PolicyWatcher> policy_watcher_; | 216 scoped_ptr<PolicyWatcher> policy_watcher_; |
| 217 | 217 |
| 218 base::DictionaryValue empty_; | 218 base::DictionaryValue empty_; |
| 219 base::DictionaryValue nat_true_; | 219 base::DictionaryValue nat_true_; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 } | 743 } |
| 744 | 744 |
| 745 // Today, the only verification offered by this test is: | 745 // Today, the only verification offered by this test is: |
| 746 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy | 746 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy |
| 747 // - Automated verification that nothing crashed | 747 // - Automated verification that nothing crashed |
| 748 } | 748 } |
| 749 | 749 |
| 750 #endif | 750 #endif |
| 751 | 751 |
| 752 } // namespace remoting | 752 } // namespace remoting |
| OLD | NEW |