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

Side by Side Diff: remoting/host/policy_watcher_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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
« no previous file with comments | « remoting/host/policy_watcher.cc ('k') | remoting/host/register_support_host_request.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "remoting/host/policy_watcher.h"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
7 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 12 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
11 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
12 #include "base/test/mock_log.h" 15 #include "base/test/mock_log.h"
13 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
14 #include "build/build_config.h" 17 #include "build/build_config.h"
15 #include "components/policy/core/common/fake_async_policy_loader.h" 18 #include "components/policy/core/common/fake_async_policy_loader.h"
16 #include "policy/policy_constants.h" 19 #include "policy/policy_constants.h"
17 #include "remoting/host/dns_blackhole_checker.h" 20 #include "remoting/host/dns_blackhole_checker.h"
18 #include "remoting/host/policy_watcher.h"
19 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 namespace remoting { 24 namespace remoting {
23 25
24 namespace key = ::policy::key; 26 namespace key = ::policy::key;
25 27
26 MATCHER_P(IsPolicies, dict, "") { 28 MATCHER_P(IsPolicies, dict, "") {
27 bool equal = arg->Equals(dict); 29 bool equal = arg->Equals(dict);
28 if (!equal) { 30 if (!equal) {
29 std::string actual_value; 31 std::string actual_value;
30 base::JSONWriter::WriteWithOptions( 32 base::JSONWriter::WriteWithOptions(
31 *arg, base::JSONWriter::OPTIONS_PRETTY_PRINT, &actual_value); 33 *arg, base::JSONWriter::OPTIONS_PRETTY_PRINT, &actual_value);
32 34
33 std::string expected_value; 35 std::string expected_value;
34 base::JSONWriter::WriteWithOptions( 36 base::JSONWriter::WriteWithOptions(
35 *dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &expected_value); 37 *dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &expected_value);
36 38
37 *result_listener << "Policies are not equal. "; 39 *result_listener << "Policies are not equal. ";
38 *result_listener << "Expected policy: " << expected_value << ". "; 40 *result_listener << "Expected policy: " << expected_value << ". ";
39 *result_listener << "Actual policy: " << actual_value << "."; 41 *result_listener << "Actual policy: " << actual_value << ".";
40 } 42 }
41 return equal; 43 return equal;
42 } 44 }
43 45
44 class MockPolicyCallback { 46 class MockPolicyCallback {
45 public: 47 public:
46 MockPolicyCallback(){}; 48 MockPolicyCallback(){};
47 49
48 // TODO(lukasza): gmock cannot mock a method taking scoped_ptr<T>... 50 // TODO(lukasza): gmock cannot mock a method taking std::unique_ptr<T>...
49 MOCK_METHOD1(OnPolicyUpdatePtr, void(const base::DictionaryValue* policies)); 51 MOCK_METHOD1(OnPolicyUpdatePtr, void(const base::DictionaryValue* policies));
50 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { 52 void OnPolicyUpdate(std::unique_ptr<base::DictionaryValue> policies) {
51 OnPolicyUpdatePtr(policies.get()); 53 OnPolicyUpdatePtr(policies.get());
52 } 54 }
53 55
54 MOCK_METHOD0(OnPolicyError, void()); 56 MOCK_METHOD0(OnPolicyError, void());
55 57
56 private: 58 private:
57 DISALLOW_COPY_AND_ASSIGN(MockPolicyCallback); 59 DISALLOW_COPY_AND_ASSIGN(MockPolicyCallback);
58 }; 60 };
59 61
60 class PolicyWatcherTest : public testing::Test { 62 class PolicyWatcherTest : public testing::Test {
61 public: 63 public:
62 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} 64 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {}
63 65
64 void SetUp() override { 66 void SetUp() override {
65 // We expect no callbacks unless explicitly specified by individual tests. 67 // We expect no callbacks unless explicitly specified by individual tests.
66 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)).Times(0); 68 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)).Times(0);
67 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); 69 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0);
68 70
69 // Retaining a raw pointer to keep control over policy contents. 71 // Retaining a raw pointer to keep control over policy contents.
70 policy_loader_ = 72 policy_loader_ =
71 new policy::FakeAsyncPolicyLoader(base::ThreadTaskRunnerHandle::Get()); 73 new policy::FakeAsyncPolicyLoader(base::ThreadTaskRunnerHandle::Get());
72 policy_watcher_ = 74 policy_watcher_ =
73 PolicyWatcher::CreateFromPolicyLoader(make_scoped_ptr(policy_loader_)); 75 PolicyWatcher::CreateFromPolicyLoader(base::WrapUnique(policy_loader_));
74 76
75 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); 77 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true);
76 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); 78 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false);
77 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); 79 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1);
78 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); 80 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1);
79 nat_one_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); 81 nat_one_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain);
80 domain_empty_.SetString(key::kRemoteAccessHostDomain, std::string()); 82 domain_empty_.SetString(key::kRemoteAccessHostDomain, std::string());
81 domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); 83 domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain);
82 SetDefaults(nat_true_others_default_); 84 SetDefaults(nat_true_others_default_);
83 nat_true_others_default_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, 85 nat_true_others_default_.SetBoolean(key::kRemoteAccessHostFirewallTraversal,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 194
193 static const char* kHostDomain; 195 static const char* kHostDomain;
194 static const char* kPortRange; 196 static const char* kPortRange;
195 base::MessageLoop message_loop_; 197 base::MessageLoop message_loop_;
196 MockPolicyCallback mock_policy_callback_; 198 MockPolicyCallback mock_policy_callback_;
197 199
198 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains 200 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains
199 // a raw pointer to |policy_loader_| in order to control the simulated / faked 201 // a raw pointer to |policy_loader_| in order to control the simulated / faked
200 // policy contents. 202 // policy contents.
201 policy::FakeAsyncPolicyLoader* policy_loader_; 203 policy::FakeAsyncPolicyLoader* policy_loader_;
202 scoped_ptr<PolicyWatcher> policy_watcher_; 204 std::unique_ptr<PolicyWatcher> policy_watcher_;
203 205
204 base::DictionaryValue empty_; 206 base::DictionaryValue empty_;
205 base::DictionaryValue nat_true_; 207 base::DictionaryValue nat_true_;
206 base::DictionaryValue nat_false_; 208 base::DictionaryValue nat_false_;
207 base::DictionaryValue nat_one_; 209 base::DictionaryValue nat_one_;
208 base::DictionaryValue nat_one_domain_full_; 210 base::DictionaryValue nat_one_domain_full_;
209 base::DictionaryValue domain_empty_; 211 base::DictionaryValue domain_empty_;
210 base::DictionaryValue domain_full_; 212 base::DictionaryValue domain_full_;
211 base::DictionaryValue nat_true_others_default_; 213 base::DictionaryValue nat_true_others_default_;
212 base::DictionaryValue nat_false_others_default_; 214 base::DictionaryValue nat_false_others_default_;
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 647
646 // And check one, random "boolean" policy to see if the type propagated 648 // And check one, random "boolean" policy to see if the type propagated
647 // correctly from policy_templates.json file. 649 // correctly from policy_templates.json file.
648 const policy::Schema boolean_schema = 650 const policy::Schema boolean_schema =
649 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); 651 schema->GetKnownProperty("RemoteAccessHostRequireCurtain");
650 EXPECT_TRUE(boolean_schema.valid()); 652 EXPECT_TRUE(boolean_schema.valid());
651 EXPECT_EQ(boolean_schema.type(), base::Value::Type::TYPE_BOOLEAN); 653 EXPECT_EQ(boolean_schema.type(), base::Value::Type::TYPE_BOOLEAN);
652 } 654 }
653 655
654 } // namespace remoting 656 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_watcher.cc ('k') | remoting/host/register_support_host_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698