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

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

Issue 858303003: Removing FakePolicyWatcher and introducing FakeAsyncPolicyLoader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... 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
« no previous file with comments | « remoting/host/policy_hack/policy_watcher.h ('k') | remoting/remoting_host_srcs.gypi » ('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 (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/json/json_writer.h"
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "components/policy/core/common/fake_async_policy_loader.h"
10 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
11 #include "remoting/host/dns_blackhole_checker.h" 13 #include "remoting/host/dns_blackhole_checker.h"
12 #include "remoting/host/policy_hack/fake_policy_watcher.h"
13 #include "remoting/host/policy_hack/mock_policy_callback.h" 14 #include "remoting/host/policy_hack/mock_policy_callback.h"
15 #include "remoting/host/policy_hack/policy_service_watcher.h"
14 #include "remoting/host/policy_hack/policy_watcher.h" 16 #include "remoting/host/policy_hack/policy_watcher.h"
15 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 namespace remoting { 20 namespace remoting {
19 namespace policy_hack { 21 namespace policy_hack {
20 22
21 class PolicyWatcherTest : public testing::Test { 23 class PolicyWatcherTest : public testing::Test {
22 public: 24 public:
23 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} 25 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {}
24 26
25 void SetUp() override { 27 void SetUp() override {
26 message_loop_proxy_ = base::MessageLoopProxy::current(); 28 message_loop_proxy_ = base::MessageLoopProxy::current();
27 policy_updated_callback_ = base::Bind( 29 policy_updated_callback_ = base::Bind(
28 &MockPolicyCallback::OnPolicyUpdate, 30 &MockPolicyCallback::OnPolicyUpdate,
29 base::Unretained(&mock_policy_callback_)); 31 base::Unretained(&mock_policy_callback_));
30 policy_error_callback_ = base::Bind( 32 policy_error_callback_ = base::Bind(
31 &MockPolicyCallback::OnPolicyError, 33 &MockPolicyCallback::OnPolicyError,
32 base::Unretained(&mock_policy_callback_)); 34 base::Unretained(&mock_policy_callback_));
33 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); 35
36 // Retaining a raw pointer to keep control over policy contents.
37 policy_loader_ = new policy::FakeAsyncPolicyLoader(message_loop_proxy_);
38 policy_watcher_ = PolicyServiceWatcher::CreateFromPolicyLoader(
39 message_loop_proxy_, make_scoped_ptr(policy_loader_));
40
34 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true); 41 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
35 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, 42 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal,
36 false); 43 false);
37 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1); 44 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1);
38 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain, 45 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
39 std::string()); 46 std::string());
40 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain); 47 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain);
41 SetDefaults(nat_true_others_default_); 48 SetDefaults(nat_true_others_default_);
42 nat_true_others_default_.SetBoolean( 49 nat_true_others_default_.SetBoolean(
43 policy::key::kRemoteAccessHostFirewallTraversal, true); 50 policy::key::kRemoteAccessHostFirewallTraversal, true);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #if !defined(NDEBUG) 108 #if !defined(NDEBUG)
102 SetDefaults(nat_false_overridden_others_default_); 109 SetDefaults(nat_false_overridden_others_default_);
103 nat_false_overridden_others_default_.SetBoolean( 110 nat_false_overridden_others_default_.SetBoolean(
104 policy::key::kRemoteAccessHostFirewallTraversal, false); 111 policy::key::kRemoteAccessHostFirewallTraversal, false);
105 nat_false_overridden_others_default_.SetString( 112 nat_false_overridden_others_default_.SetString(
106 policy::key::kRemoteAccessHostDebugOverridePolicies, 113 policy::key::kRemoteAccessHostDebugOverridePolicies,
107 kOverrideNatTraversalToFalse); 114 kOverrideNatTraversalToFalse);
108 #endif 115 #endif
109 } 116 }
110 117
118 void TearDown() override {
119 policy_watcher_.reset();
120 policy_loader_ = nullptr;
121 base::RunLoop().RunUntilIdle();
122 }
123
111 protected: 124 protected:
112 void StartWatching() { 125 void StartWatching() {
113 policy_watcher_->StartWatching( 126 policy_watcher_->StartWatching(
114 policy_updated_callback_, 127 policy_updated_callback_,
115 policy_error_callback_); 128 policy_error_callback_);
116 base::RunLoop().RunUntilIdle(); 129 base::RunLoop().RunUntilIdle();
117 } 130 }
118 131
119 void StopWatching() { 132 void StopWatching() {
120 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1); 133 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1);
121 policy_watcher_->StopWatching(base::Bind( 134 policy_watcher_->StopWatching(base::Bind(
122 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this))); 135 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this)));
123 base::RunLoop().RunUntilIdle(); 136 base::RunLoop().RunUntilIdle();
124 } 137 }
125 138
139 void SetPolicies(const base::DictionaryValue& dict) {
140 // Copy |dict| into |policy_bundle|.
141 policy::PolicyNamespace policy_namespace =
142 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string());
143 policy::PolicyBundle policy_bundle;
144 policy::PolicyMap& policy_map = policy_bundle.Get(policy_namespace);
145 policy_map.LoadFrom(&dict, policy::POLICY_LEVEL_MANDATORY,
146 policy::POLICY_SCOPE_MACHINE);
147
148 // Simulate a policy file/registry/preference update.
149 policy_loader_->SetPolicies(policy_bundle);
150 policy_loader_->PostReloadOnBackgroundThread(true /* force reload asap */);
151 base::RunLoop().RunUntilIdle();
152 }
153
154 void SignalTransientErrorForTest() {
155 policy_watcher_->SignalTransientPolicyError();
156 }
157
126 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); 158 MOCK_METHOD0(PostPolicyWatcherShutdown, void());
127 159
128 static const char* kHostDomain; 160 static const char* kHostDomain;
129 static const char* kPortRange; 161 static const char* kPortRange;
130 base::MessageLoop message_loop_; 162 base::MessageLoop message_loop_;
131 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 163 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
132 MockPolicyCallback mock_policy_callback_; 164 MockPolicyCallback mock_policy_callback_;
133 PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_; 165 PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_;
134 PolicyWatcher::PolicyErrorCallback policy_error_callback_; 166 PolicyWatcher::PolicyErrorCallback policy_error_callback_;
135 scoped_ptr<FakePolicyWatcher> policy_watcher_; 167
168 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains
169 // a raw pointer to |policy_loader_| in order to control the simulated / faked
170 // policy contents.
171 policy::FakeAsyncPolicyLoader* policy_loader_;
172 scoped_ptr<PolicyWatcher> policy_watcher_;
173
136 base::DictionaryValue empty_; 174 base::DictionaryValue empty_;
137 base::DictionaryValue nat_true_; 175 base::DictionaryValue nat_true_;
138 base::DictionaryValue nat_false_; 176 base::DictionaryValue nat_false_;
139 base::DictionaryValue nat_one_; 177 base::DictionaryValue nat_one_;
140 base::DictionaryValue domain_empty_; 178 base::DictionaryValue domain_empty_;
141 base::DictionaryValue domain_full_; 179 base::DictionaryValue domain_full_;
142 base::DictionaryValue nat_true_others_default_; 180 base::DictionaryValue nat_true_others_default_;
143 base::DictionaryValue nat_false_others_default_; 181 base::DictionaryValue nat_false_others_default_;
144 base::DictionaryValue domain_empty_others_default_; 182 base::DictionaryValue domain_empty_others_default_;
145 base::DictionaryValue domain_full_others_default_; 183 base::DictionaryValue domain_full_others_default_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 #if !defined(NDEBUG) 220 #if !defined(NDEBUG)
183 dict.SetString(policy::key::kRemoteAccessHostDebugOverridePolicies, ""); 221 dict.SetString(policy::key::kRemoteAccessHostDebugOverridePolicies, "");
184 #endif 222 #endif
185 } 223 }
186 }; 224 };
187 225
188 const char* PolicyWatcherTest::kHostDomain = "google.com"; 226 const char* PolicyWatcherTest::kHostDomain = "google.com";
189 const char* PolicyWatcherTest::kPortRange = "12400-12409"; 227 const char* PolicyWatcherTest::kPortRange = "12400-12409";
190 228
191 MATCHER_P(IsPolicies, dict, "") { 229 MATCHER_P(IsPolicies, dict, "") {
192 return arg->Equals(dict); 230 bool equal = arg->Equals(dict);
231 if (!equal) {
232 std::string actual_value;
233 base::JSONWriter::WriteWithOptions(
234 arg, base::JSONWriter::OPTIONS_PRETTY_PRINT, &actual_value);
235
236 std::string expected_value;
237 base::JSONWriter::WriteWithOptions(
238 dict, base::JSONWriter::OPTIONS_PRETTY_PRINT, &expected_value);
239
240 *result_listener << "Policies are not equal. ";
241 *result_listener << "Expected policy: " << expected_value << ". ";
242 *result_listener << "Actual policy: " << actual_value << ".";
243 }
244 return equal;
193 } 245 }
194 246
195 TEST_F(PolicyWatcherTest, None) { 247 TEST_F(PolicyWatcherTest, None) {
196 EXPECT_CALL(mock_policy_callback_, 248 EXPECT_CALL(mock_policy_callback_,
197 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 249 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
198 250
251 SetPolicies(empty_);
199 StartWatching(); 252 StartWatching();
200 policy_watcher_->SetPolicies(&empty_);
201 StopWatching(); 253 StopWatching();
202 } 254 }
203 255
204 TEST_F(PolicyWatcherTest, NatTrue) { 256 TEST_F(PolicyWatcherTest, NatTrue) {
205 EXPECT_CALL(mock_policy_callback_, 257 EXPECT_CALL(mock_policy_callback_,
206 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 258 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
207 259
260 SetPolicies(nat_true_);
208 StartWatching(); 261 StartWatching();
209 policy_watcher_->SetPolicies(&nat_true_);
210 StopWatching(); 262 StopWatching();
211 } 263 }
212 264
213 TEST_F(PolicyWatcherTest, NatFalse) { 265 TEST_F(PolicyWatcherTest, NatFalse) {
214 EXPECT_CALL(mock_policy_callback_, 266 EXPECT_CALL(mock_policy_callback_,
215 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 267 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
216 268
269 SetPolicies(nat_false_);
217 StartWatching(); 270 StartWatching();
218 policy_watcher_->SetPolicies(&nat_false_);
219 StopWatching(); 271 StopWatching();
220 } 272 }
221 273
222 TEST_F(PolicyWatcherTest, NatOne) { 274 TEST_F(PolicyWatcherTest, NatOne) {
223 EXPECT_CALL(mock_policy_callback_, 275 EXPECT_CALL(mock_policy_callback_,
224 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 276 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
225 277
278 SetPolicies(nat_one_);
226 StartWatching(); 279 StartWatching();
227 policy_watcher_->SetPolicies(&nat_one_);
228 StopWatching(); 280 StopWatching();
229 } 281 }
230 282
231 TEST_F(PolicyWatcherTest, DomainEmpty) { 283 TEST_F(PolicyWatcherTest, DomainEmpty) {
232 EXPECT_CALL(mock_policy_callback_, 284 EXPECT_CALL(mock_policy_callback_,
233 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_))); 285 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_)));
234 286
287 SetPolicies(domain_empty_);
235 StartWatching(); 288 StartWatching();
236 policy_watcher_->SetPolicies(&domain_empty_);
237 StopWatching(); 289 StopWatching();
238 } 290 }
239 291
240 TEST_F(PolicyWatcherTest, DomainFull) { 292 TEST_F(PolicyWatcherTest, DomainFull) {
241 EXPECT_CALL(mock_policy_callback_, 293 EXPECT_CALL(mock_policy_callback_,
242 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_))); 294 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_)));
243 295
296 SetPolicies(domain_full_);
244 StartWatching(); 297 StartWatching();
245 policy_watcher_->SetPolicies(&domain_full_);
246 StopWatching(); 298 StopWatching();
247 } 299 }
248 300
249 TEST_F(PolicyWatcherTest, NatNoneThenTrue) { 301 TEST_F(PolicyWatcherTest, NatNoneThenTrue) {
250 EXPECT_CALL(mock_policy_callback_, 302 EXPECT_CALL(mock_policy_callback_,
251 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 303 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
252 304
305 SetPolicies(empty_);
253 StartWatching(); 306 StartWatching();
254 policy_watcher_->SetPolicies(&empty_); 307 SetPolicies(nat_true_);
255 policy_watcher_->SetPolicies(&nat_true_);
256 StopWatching(); 308 StopWatching();
257 } 309 }
258 310
259 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) { 311 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) {
260 EXPECT_CALL(mock_policy_callback_, 312 EXPECT_CALL(mock_policy_callback_,
261 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 313 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
262 314
315 SetPolicies(empty_);
263 StartWatching(); 316 StartWatching();
264 policy_watcher_->SetPolicies(&empty_); 317 SetPolicies(nat_true_);
265 policy_watcher_->SetPolicies(&nat_true_); 318 SetPolicies(nat_true_);
266 policy_watcher_->SetPolicies(&nat_true_);
267 StopWatching(); 319 StopWatching();
268 } 320 }
269 321
270 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) { 322 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) {
271 testing::InSequence sequence; 323 testing::InSequence sequence;
272 EXPECT_CALL(mock_policy_callback_, 324 EXPECT_CALL(mock_policy_callback_,
273 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 325 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
274 EXPECT_CALL(mock_policy_callback_, 326 EXPECT_CALL(mock_policy_callback_,
275 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 327 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
276 328
329 SetPolicies(empty_);
277 StartWatching(); 330 StartWatching();
278 policy_watcher_->SetPolicies(&empty_); 331 SetPolicies(nat_true_);
279 policy_watcher_->SetPolicies(&nat_true_); 332 SetPolicies(nat_true_);
280 policy_watcher_->SetPolicies(&nat_true_); 333 SetPolicies(nat_false_);
281 policy_watcher_->SetPolicies(&nat_false_);
282 StopWatching(); 334 StopWatching();
283 } 335 }
284 336
285 TEST_F(PolicyWatcherTest, NatNoneThenFalse) { 337 TEST_F(PolicyWatcherTest, NatNoneThenFalse) {
286 testing::InSequence sequence; 338 testing::InSequence sequence;
287 EXPECT_CALL(mock_policy_callback_, 339 EXPECT_CALL(mock_policy_callback_,
288 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 340 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
289 EXPECT_CALL(mock_policy_callback_, 341 EXPECT_CALL(mock_policy_callback_,
290 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 342 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
291 343
344 SetPolicies(empty_);
292 StartWatching(); 345 StartWatching();
293 policy_watcher_->SetPolicies(&empty_); 346 SetPolicies(nat_false_);
294 policy_watcher_->SetPolicies(&nat_false_);
295 StopWatching(); 347 StopWatching();
296 } 348 }
297 349
298 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) { 350 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) {
299 testing::InSequence sequence; 351 testing::InSequence sequence;
300 EXPECT_CALL(mock_policy_callback_, 352 EXPECT_CALL(mock_policy_callback_,
301 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 353 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
302 EXPECT_CALL(mock_policy_callback_, 354 EXPECT_CALL(mock_policy_callback_,
303 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 355 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
304 EXPECT_CALL(mock_policy_callback_, 356 EXPECT_CALL(mock_policy_callback_,
305 OnPolicyUpdatePtr(IsPolicies(&nat_true_))); 357 OnPolicyUpdatePtr(IsPolicies(&nat_true_)));
306 358
359 SetPolicies(empty_);
307 StartWatching(); 360 StartWatching();
308 policy_watcher_->SetPolicies(&empty_); 361 SetPolicies(nat_false_);
309 policy_watcher_->SetPolicies(&nat_false_); 362 SetPolicies(nat_true_);
310 policy_watcher_->SetPolicies(&nat_true_);
311 StopWatching(); 363 StopWatching();
312 } 364 }
313 365
314 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) { 366 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) {
315 testing::InSequence sequence; 367 testing::InSequence sequence;
316 EXPECT_CALL(mock_policy_callback_, 368 EXPECT_CALL(mock_policy_callback_,
317 OnPolicyUpdatePtr(IsPolicies( 369 OnPolicyUpdatePtr(IsPolicies(
318 &nat_true_domain_empty_others_default_))); 370 &nat_true_domain_empty_others_default_)));
319 EXPECT_CALL(mock_policy_callback_, 371 EXPECT_CALL(mock_policy_callback_,
320 OnPolicyUpdatePtr(IsPolicies(&domain_full_))); 372 OnPolicyUpdatePtr(IsPolicies(&domain_full_)));
321 EXPECT_CALL(mock_policy_callback_, 373 EXPECT_CALL(mock_policy_callback_,
322 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 374 OnPolicyUpdatePtr(IsPolicies(&nat_false_)));
323 EXPECT_CALL(mock_policy_callback_, 375 EXPECT_CALL(mock_policy_callback_,
324 OnPolicyUpdatePtr(IsPolicies(&domain_empty_))); 376 OnPolicyUpdatePtr(IsPolicies(&domain_empty_)));
325 EXPECT_CALL(mock_policy_callback_, 377 EXPECT_CALL(mock_policy_callback_,
326 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_))); 378 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_)));
327 379
380 SetPolicies(nat_true_domain_empty_);
328 StartWatching(); 381 StartWatching();
329 policy_watcher_->SetPolicies(&nat_true_domain_empty_); 382 SetPolicies(nat_true_domain_full_);
330 policy_watcher_->SetPolicies(&nat_true_domain_full_); 383 SetPolicies(nat_false_domain_full_);
331 policy_watcher_->SetPolicies(&nat_false_domain_full_); 384 SetPolicies(nat_false_domain_empty_);
332 policy_watcher_->SetPolicies(&nat_false_domain_empty_); 385 SetPolicies(nat_true_domain_full_);
333 policy_watcher_->SetPolicies(&nat_true_domain_full_);
334 StopWatching(); 386 StopWatching();
335 } 387 }
336 388
337 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) { 389 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) {
338 testing::InSequence sequence; 390 testing::InSequence sequence;
339 EXPECT_CALL(mock_policy_callback_, 391 EXPECT_CALL(mock_policy_callback_,
340 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 392 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
341 393
394 SetPolicies(empty_);
342 StartWatching(); 395 StartWatching();
343 policy_watcher_->SetPolicies(&empty_); 396 SetPolicies(unknown_policies_);
344 policy_watcher_->SetPolicies(&unknown_policies_); 397 SetPolicies(empty_);
345 policy_watcher_->SetPolicies(&empty_);
346 StopWatching(); 398 StopWatching();
347 } 399 }
348 400
349 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) { 401 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) {
350 #if !defined(NDEBUG) 402 #if !defined(NDEBUG)
351 EXPECT_CALL(mock_policy_callback_, 403 EXPECT_CALL(
404 mock_policy_callback_,
352 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_))); 405 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_)));
353 #else 406 #else
354 EXPECT_CALL(mock_policy_callback_, 407 EXPECT_CALL(mock_policy_callback_,
355 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 408 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
356 #endif 409 #endif
357 410
411 SetPolicies(nat_true_and_overridden_);
358 StartWatching(); 412 StartWatching();
359 policy_watcher_->SetPolicies(&nat_true_and_overridden_);
360 StopWatching(); 413 StopWatching();
361 } 414 }
362 415
363 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) { 416 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) {
364 testing::InSequence sequence; 417 testing::InSequence sequence;
365 EXPECT_CALL(mock_policy_callback_, 418 EXPECT_CALL(mock_policy_callback_,
366 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 419 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
367 EXPECT_CALL(mock_policy_callback_, 420 EXPECT_CALL(mock_policy_callback_,
368 OnPolicyUpdatePtr(IsPolicies(&pairing_false_))); 421 OnPolicyUpdatePtr(IsPolicies(&pairing_false_)));
369 EXPECT_CALL(mock_policy_callback_, 422 EXPECT_CALL(mock_policy_callback_,
370 OnPolicyUpdatePtr(IsPolicies(&pairing_true_))); 423 OnPolicyUpdatePtr(IsPolicies(&pairing_true_)));
371 424
425 SetPolicies(empty_);
372 StartWatching(); 426 StartWatching();
373 policy_watcher_->SetPolicies(&empty_); 427 SetPolicies(pairing_false_);
374 policy_watcher_->SetPolicies(&pairing_false_); 428 SetPolicies(pairing_true_);
375 policy_watcher_->SetPolicies(&pairing_true_);
376 StopWatching(); 429 StopWatching();
377 } 430 }
378 431
379 TEST_F(PolicyWatcherTest, GnubbyAuth) { 432 TEST_F(PolicyWatcherTest, GnubbyAuth) {
380 testing::InSequence sequence; 433 testing::InSequence sequence;
381 EXPECT_CALL(mock_policy_callback_, 434 EXPECT_CALL(mock_policy_callback_,
382 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 435 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
383 EXPECT_CALL(mock_policy_callback_, 436 EXPECT_CALL(mock_policy_callback_,
384 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_))); 437 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_)));
385 EXPECT_CALL(mock_policy_callback_, 438 EXPECT_CALL(mock_policy_callback_,
386 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); 439 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_)));
387 440
441 SetPolicies(empty_);
388 StartWatching(); 442 StartWatching();
389 policy_watcher_->SetPolicies(&empty_); 443 SetPolicies(gnubby_auth_false_);
390 policy_watcher_->SetPolicies(&gnubby_auth_false_); 444 SetPolicies(gnubby_auth_true_);
391 policy_watcher_->SetPolicies(&gnubby_auth_true_);
392 StopWatching(); 445 StopWatching();
393 } 446 }
394 447
395 TEST_F(PolicyWatcherTest, Relay) { 448 TEST_F(PolicyWatcherTest, Relay) {
396 testing::InSequence sequence; 449 testing::InSequence sequence;
397 EXPECT_CALL(mock_policy_callback_, 450 EXPECT_CALL(mock_policy_callback_,
398 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 451 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
399 EXPECT_CALL(mock_policy_callback_, 452 EXPECT_CALL(mock_policy_callback_,
400 OnPolicyUpdatePtr(IsPolicies(&relay_false_))); 453 OnPolicyUpdatePtr(IsPolicies(&relay_false_)));
401 EXPECT_CALL(mock_policy_callback_, 454 EXPECT_CALL(mock_policy_callback_,
402 OnPolicyUpdatePtr(IsPolicies(&relay_true_))); 455 OnPolicyUpdatePtr(IsPolicies(&relay_true_)));
403 456
457 SetPolicies(empty_);
404 StartWatching(); 458 StartWatching();
405 policy_watcher_->SetPolicies(&empty_); 459 SetPolicies(relay_false_);
406 policy_watcher_->SetPolicies(&relay_false_); 460 SetPolicies(relay_true_);
407 policy_watcher_->SetPolicies(&relay_true_);
408 StopWatching(); 461 StopWatching();
409 } 462 }
410 463
411 TEST_F(PolicyWatcherTest, UdpPortRange) { 464 TEST_F(PolicyWatcherTest, UdpPortRange) {
412 testing::InSequence sequence; 465 testing::InSequence sequence;
413 EXPECT_CALL(mock_policy_callback_, 466 EXPECT_CALL(mock_policy_callback_,
414 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 467 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
415 EXPECT_CALL(mock_policy_callback_, 468 EXPECT_CALL(mock_policy_callback_,
416 OnPolicyUpdatePtr(IsPolicies(&port_range_full_))); 469 OnPolicyUpdatePtr(IsPolicies(&port_range_full_)));
417 EXPECT_CALL(mock_policy_callback_, 470 EXPECT_CALL(mock_policy_callback_,
418 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); 471 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_)));
419 472
473 SetPolicies(empty_);
420 StartWatching(); 474 StartWatching();
421 policy_watcher_->SetPolicies(&empty_); 475 SetPolicies(port_range_full_);
422 policy_watcher_->SetPolicies(&port_range_full_); 476 SetPolicies(port_range_empty_);
423 policy_watcher_->SetPolicies(&port_range_empty_);
424 StopWatching(); 477 StopWatching();
425 } 478 }
426 479
427 const int kMaxTransientErrorRetries = 5; 480 const int kMaxTransientErrorRetries = 5;
428 481
429 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) { 482 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) {
430 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); 483 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
431 484
432 StartWatching(); 485 StartWatching();
433 policy_watcher_->SignalTransientErrorForTest(); 486 SignalTransientErrorForTest();
434 StopWatching(); 487 StopWatching();
435 } 488 }
436 489
437 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) { 490 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) {
438 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()); 491 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr());
439 492
440 StartWatching(); 493 StartWatching();
441 for (int i = 0; i < kMaxTransientErrorRetries; i++) { 494 for (int i = 0; i < kMaxTransientErrorRetries; i++) {
442 policy_watcher_->SignalTransientErrorForTest(); 495 SignalTransientErrorForTest();
443 } 496 }
444 StopWatching(); 497 StopWatching();
445 } 498 }
446 499
447 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { 500 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) {
448 testing::InSequence s; 501 testing::InSequence s;
449 EXPECT_CALL(mock_policy_callback_, 502 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_));
450 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
451 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); 503 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
452 504
453 StartWatching(); 505 StartWatching();
454 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 506 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
455 policy_watcher_->SignalTransientErrorForTest(); 507 SignalTransientErrorForTest();
456 } 508 }
457 policy_watcher_->SetPolicies(&nat_true_); 509 SetPolicies(nat_true_);
458 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 510 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
459 policy_watcher_->SignalTransientErrorForTest(); 511 SignalTransientErrorForTest();
460 } 512 }
461 StopWatching(); 513 StopWatching();
462 } 514 }
463 515
464 // Unit tests cannot instantiate PolicyWatcher on ChromeOS 516 // Unit tests cannot instantiate PolicyWatcher on ChromeOS
465 // (as this requires running inside a browser process). 517 // (as this requires running inside a browser process).
466 #ifndef OS_CHROMEOS 518 #ifndef OS_CHROMEOS
467 519
468 namespace { 520 namespace {
469 521
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 run_loop.RunUntilIdle(); 575 run_loop.RunUntilIdle();
524 } 576 }
525 577
526 // Today, the only verification offered by this test is: 578 // Today, the only verification offered by this test is:
527 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy 579 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy
528 // - Automated verification that nothing crashed 580 // - Automated verification that nothing crashed
529 } 581 }
530 582
531 #endif 583 #endif
532 584
533 // TODO(lukasza): We should consider adding a test against a
534 // MockConfigurationPolicyProvider.
535
536 } // namespace policy_hack 585 } // namespace policy_hack
537 } // namespace remoting 586 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/policy_watcher.h ('k') | remoting/remoting_host_srcs.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698