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

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: 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 "components/policy/core/common/fake_async_policy_loader.h"
10 #include "policy/policy_constants.h" 11 #include "policy/policy_constants.h"
11 #include "remoting/host/dns_blackhole_checker.h" 12 #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" 13 #include "remoting/host/policy_hack/mock_policy_callback.h"
14 #include "remoting/host/policy_hack/policy_service_watcher.h"
14 #include "remoting/host/policy_hack/policy_watcher.h" 15 #include "remoting/host/policy_hack/policy_watcher.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace remoting { 19 namespace remoting {
19 namespace policy_hack { 20 namespace policy_hack {
20 21
21 class PolicyWatcherTest : public testing::Test { 22 class PolicyWatcherTest : public testing::Test {
22 public: 23 public:
23 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {} 24 PolicyWatcherTest() : message_loop_(base::MessageLoop::TYPE_IO) {}
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
35 scoped_ptr<policy::FakeAsyncPolicyLoader> policy_loader(
36 new policy::FakeAsyncPolicyLoader(message_loop_proxy_));
37 // retaining a pointer to keep control over policy contents.
38 policy_loader_ = policy_loader.get();
39 policy_watcher_ = PolicyServiceWatcher::CreateFromPolicyLoader(
40 message_loop_proxy_, policy_loader.Pass());
Łukasz Anforowicz 2015/01/22 00:12:28 I am not happy with handing over a scoped_ptr<Fake
Mattias Nissler (ping if slow) 2015/01/22 16:05:08 I think what you have is fair. If you really feel
Łukasz Anforowicz 2015/01/22 18:28:06 Thanks. I'll leave it as-is. Moving the ownershi
41
34 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true); 42 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
35 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, 43 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal,
36 false); 44 false);
37 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1); 45 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1);
38 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain, 46 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
39 std::string()); 47 std::string());
40 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain); 48 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain);
41 SetDefaults(nat_true_others_default_); 49 SetDefaults(nat_true_others_default_);
42 nat_true_others_default_.SetBoolean( 50 nat_true_others_default_.SetBoolean(
43 policy::key::kRemoteAccessHostFirewallTraversal, true); 51 policy::key::kRemoteAccessHostFirewallTraversal, true);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 base::RunLoop().RunUntilIdle(); 124 base::RunLoop().RunUntilIdle();
117 } 125 }
118 126
119 void StopWatching() { 127 void StopWatching() {
120 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1); 128 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1);
121 policy_watcher_->StopWatching(base::Bind( 129 policy_watcher_->StopWatching(base::Bind(
122 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this))); 130 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this)));
123 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
124 } 132 }
125 133
134 void SetPolicies(const base::DictionaryValue& dict) {
135 policy_loader_->ClearPolicies();
136 policy_loader_->AddPolicies(
137 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()),
138 dict, policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_MACHINE);
139 policy_loader_->PostReloadOnBackgroundThread(true /* force reload asap */);
140 base::RunLoop().RunUntilIdle();
141 }
142
143 void SignalTransientErrorForTest() {
144 policy_watcher_->SignalTransientPolicyError();
145 }
146
126 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); 147 MOCK_METHOD0(PostPolicyWatcherShutdown, void());
127 148
128 static const char* kHostDomain; 149 static const char* kHostDomain;
129 static const char* kPortRange; 150 static const char* kPortRange;
130 base::MessageLoop message_loop_; 151 base::MessageLoop message_loop_;
131 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 152 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
132 MockPolicyCallback mock_policy_callback_; 153 MockPolicyCallback mock_policy_callback_;
133 PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_; 154 PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_;
134 PolicyWatcher::PolicyErrorCallback policy_error_callback_; 155 PolicyWatcher::PolicyErrorCallback policy_error_callback_;
135 scoped_ptr<FakePolicyWatcher> policy_watcher_; 156 policy::FakeAsyncPolicyLoader* policy_loader_;
157 scoped_ptr<PolicyWatcher> policy_watcher_;
136 base::DictionaryValue empty_; 158 base::DictionaryValue empty_;
137 base::DictionaryValue nat_true_; 159 base::DictionaryValue nat_true_;
138 base::DictionaryValue nat_false_; 160 base::DictionaryValue nat_false_;
139 base::DictionaryValue nat_one_; 161 base::DictionaryValue nat_one_;
140 base::DictionaryValue domain_empty_; 162 base::DictionaryValue domain_empty_;
141 base::DictionaryValue domain_full_; 163 base::DictionaryValue domain_full_;
142 base::DictionaryValue nat_true_others_default_; 164 base::DictionaryValue nat_true_others_default_;
143 base::DictionaryValue nat_false_others_default_; 165 base::DictionaryValue nat_false_others_default_;
144 base::DictionaryValue domain_empty_others_default_; 166 base::DictionaryValue domain_empty_others_default_;
145 base::DictionaryValue domain_full_others_default_; 167 base::DictionaryValue domain_full_others_default_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 dict.SetBoolean(policy::key::kRemoteAccessHostAllowGnubbyAuth, true); 203 dict.SetBoolean(policy::key::kRemoteAccessHostAllowGnubbyAuth, true);
182 #if !defined(NDEBUG) 204 #if !defined(NDEBUG)
183 dict.SetString(policy::key::kRemoteAccessHostDebugOverridePolicies, ""); 205 dict.SetString(policy::key::kRemoteAccessHostDebugOverridePolicies, "");
184 #endif 206 #endif
185 } 207 }
186 }; 208 };
187 209
188 const char* PolicyWatcherTest::kHostDomain = "google.com"; 210 const char* PolicyWatcherTest::kHostDomain = "google.com";
189 const char* PolicyWatcherTest::kPortRange = "12400-12409"; 211 const char* PolicyWatcherTest::kPortRange = "12400-12409";
190 212
191 MATCHER_P(IsPolicies, dict, "") { 213 using ::testing::Matcher;
192 return arg->Equals(dict); 214 using ::testing::MatcherInterface;
215 using ::testing::MatchResultListener;
216
217 class DictionaryValueEqMatcher
Łukasz Anforowicz 2015/01/22 00:12:28 I've added a quick-and-dirty DictionaryValueEqMatc
Mattias Nissler (ping if slow) 2015/01/22 16:05:08 I'm not sure there's justification enough to add a
Łukasz Anforowicz 2015/01/22 18:28:06 Doh... yes - this is much easier. Thanks.
218 : public MatcherInterface<const base::DictionaryValue*> {
219 public:
220 explicit DictionaryValueEqMatcher(const base::DictionaryValue& expected_dict)
221 : expected_dict_(expected_dict.DeepCopy()) {}
222
223 virtual bool MatchAndExplain(const base::DictionaryValue* actual_dict,
224 MatchResultListener* listener) const {
225 if (actual_dict == nullptr) {
226 *listener << "actual dictionary is null";
227 return false;
228 }
229
230 for (base::DictionaryValue::Iterator i(*actual_dict); !i.IsAtEnd();
231 i.Advance()) {
232 if (!MatchAndExplainPair(i, *expected_dict_, "actual", "expected",
233 listener)) {
234 return false;
235 }
236 }
237
238 for (base::DictionaryValue::Iterator i(*expected_dict_); !i.IsAtEnd();
239 i.Advance()) {
240 if (!MatchAndExplainPair(i, *actual_dict, "expected", "actual",
241 listener)) {
242 return false;
243 }
244 }
245
246 // Double-check the code above correctly calculates dictionary equality.
247 CHECK(actual_dict->Equals(expected_dict_.get()));
248
249 return true;
250 }
251
252 virtual void DescribeTo(::std::ostream* os) const {
253 *os << "dictionary equality check";
254 }
255
256 virtual void DescribeNegationTo(::std::ostream* os) const {
257 *os << "dictionary inequality check";
258 }
259
260 private:
261 virtual bool MatchAndExplainPair(const base::DictionaryValue::Iterator& iter,
262 const base::DictionaryValue& other_dict,
263 const std::string& iter_name,
264 const std::string& other_name,
265 MatchResultListener* listener) const {
266 const std::string& key = iter.key();
267 if (!other_dict.HasKey(key)) {
268 *listener << "key '" << key << "' is present in " << iter_name
269 << ", but not in " << other_name << " dictionary.";
270 return false;
271 }
272
273 const base::Value* other_value;
274 CHECK(other_dict.Get(key, &other_value));
275
276 if (other_value->GetType() != iter.value().GetType()) {
277 *listener << "value of '" << key << "' key "
278 << "is a " << other_value->GetType() << " in " << other_name
279 << " but is a " << iter.value().GetType() << " in " << iter_name
280 << " dictionary.";
281 return false;
282 }
283
284 if (!other_value->Equals(&iter.value())) {
285 switch (iter.value().GetType()) {
286 case base::Value::Type::TYPE_BOOLEAN: {
287 bool other_bool;
288 bool iter_bool;
289 CHECK(iter.value().GetAsBoolean(&iter_bool));
290 CHECK(other_value->GetAsBoolean(&other_bool));
291 *listener << "value of '" << key << "' key "
292 << "equals " << other_bool << " in " << other_name
293 << " but equals " << iter_bool << " in " << iter_name
294 << " dictionary";
295 break;
296 }
297 case base::Value::Type::TYPE_STRING: {
298 std::string other_string;
299 std::string iter_string;
300 CHECK(iter.value().GetAsString(&iter_string));
301 CHECK(other_value->GetAsString(&other_string));
302 *listener << "value of '" << key << "' key "
303 << "equals '" << other_string << "' in " << other_name
304 << " but equals '" << iter_string << "' in " << iter_name
305 << " dictionary";
306 break;
307 }
308 default: {
309 *listener << "value of '" << key << "' key "
310 << "is different in " << other_name << " and in "
311 << iter_name << " dictionary";
312 break;
313 }
314 }
315 return false;
316 }
317
318 return true;
319 }
320
321 scoped_ptr<base::DictionaryValue> expected_dict_;
322 };
323
324 inline Matcher<const base::DictionaryValue*> DictionaryValueEq(
325 const base::DictionaryValue& expected_dict) {
326 return MakeMatcher(new DictionaryValueEqMatcher(expected_dict));
193 } 327 }
194 328
195 TEST_F(PolicyWatcherTest, None) { 329 TEST_F(PolicyWatcherTest, None) {
196 EXPECT_CALL(mock_policy_callback_, 330 EXPECT_CALL(mock_policy_callback_,
197 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 331 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
198 332
199 StartWatching(); 333 SetPolicies(empty_);
200 policy_watcher_->SetPolicies(&empty_); 334 StartWatching();
201 StopWatching(); 335 StopWatching();
202 } 336 }
203 337
204 TEST_F(PolicyWatcherTest, NatTrue) { 338 TEST_F(PolicyWatcherTest, NatTrue) {
205 EXPECT_CALL(mock_policy_callback_, 339 EXPECT_CALL(mock_policy_callback_,
206 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 340 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
207 341
208 StartWatching(); 342 SetPolicies(nat_true_);
209 policy_watcher_->SetPolicies(&nat_true_); 343 StartWatching();
210 StopWatching(); 344 StopWatching();
211 } 345 }
212 346
213 TEST_F(PolicyWatcherTest, NatFalse) { 347 TEST_F(PolicyWatcherTest, NatFalse) {
214 EXPECT_CALL(mock_policy_callback_, 348 EXPECT_CALL(mock_policy_callback_,
215 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 349 OnPolicyUpdatePtr(DictionaryValueEq(nat_false_others_default_)));
216 350
217 StartWatching(); 351 SetPolicies(nat_false_);
218 policy_watcher_->SetPolicies(&nat_false_); 352 StartWatching();
219 StopWatching(); 353 StopWatching();
220 } 354 }
221 355
222 TEST_F(PolicyWatcherTest, NatOne) { 356 TEST_F(PolicyWatcherTest, NatOne) {
223 EXPECT_CALL(mock_policy_callback_, 357 EXPECT_CALL(mock_policy_callback_,
224 OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); 358 OnPolicyUpdatePtr(DictionaryValueEq(nat_false_others_default_)));
225 359
226 StartWatching(); 360 SetPolicies(nat_one_);
227 policy_watcher_->SetPolicies(&nat_one_); 361 StartWatching();
228 StopWatching(); 362 StopWatching();
229 } 363 }
230 364
231 TEST_F(PolicyWatcherTest, DomainEmpty) { 365 TEST_F(PolicyWatcherTest, DomainEmpty) {
232 EXPECT_CALL(mock_policy_callback_, 366 EXPECT_CALL(
233 OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_))); 367 mock_policy_callback_,
234 368 OnPolicyUpdatePtr(DictionaryValueEq(domain_empty_others_default_)));
235 StartWatching(); 369
236 policy_watcher_->SetPolicies(&domain_empty_); 370 SetPolicies(domain_empty_);
371 StartWatching();
237 StopWatching(); 372 StopWatching();
238 } 373 }
239 374
240 TEST_F(PolicyWatcherTest, DomainFull) { 375 TEST_F(PolicyWatcherTest, DomainFull) {
241 EXPECT_CALL(mock_policy_callback_, 376 EXPECT_CALL(
242 OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_))); 377 mock_policy_callback_,
243 378 OnPolicyUpdatePtr(DictionaryValueEq(domain_full_others_default_)));
244 StartWatching(); 379
245 policy_watcher_->SetPolicies(&domain_full_); 380 SetPolicies(domain_full_);
381 StartWatching();
246 StopWatching(); 382 StopWatching();
247 } 383 }
248 384
249 TEST_F(PolicyWatcherTest, NatNoneThenTrue) { 385 TEST_F(PolicyWatcherTest, NatNoneThenTrue) {
250 EXPECT_CALL(mock_policy_callback_, 386 EXPECT_CALL(mock_policy_callback_,
251 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 387 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
252 388
253 StartWatching(); 389 SetPolicies(empty_);
254 policy_watcher_->SetPolicies(&empty_); 390 StartWatching();
255 policy_watcher_->SetPolicies(&nat_true_); 391 SetPolicies(nat_true_);
256 StopWatching(); 392 StopWatching();
257 } 393 }
258 394
259 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) { 395 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) {
260 EXPECT_CALL(mock_policy_callback_, 396 EXPECT_CALL(mock_policy_callback_,
261 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 397 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
262 398
263 StartWatching(); 399 SetPolicies(empty_);
264 policy_watcher_->SetPolicies(&empty_); 400 StartWatching();
265 policy_watcher_->SetPolicies(&nat_true_); 401 SetPolicies(nat_true_);
266 policy_watcher_->SetPolicies(&nat_true_); 402 SetPolicies(nat_true_);
267 StopWatching(); 403 StopWatching();
268 } 404 }
269 405
270 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) { 406 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) {
271 testing::InSequence sequence; 407 testing::InSequence sequence;
272 EXPECT_CALL(mock_policy_callback_, 408 EXPECT_CALL(mock_policy_callback_,
273 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 409 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
274 EXPECT_CALL(mock_policy_callback_, 410 EXPECT_CALL(mock_policy_callback_,
275 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 411 OnPolicyUpdatePtr(DictionaryValueEq(nat_false_)));
276 412
277 StartWatching(); 413 SetPolicies(empty_);
278 policy_watcher_->SetPolicies(&empty_); 414 StartWatching();
279 policy_watcher_->SetPolicies(&nat_true_); 415 SetPolicies(nat_true_);
280 policy_watcher_->SetPolicies(&nat_true_); 416 SetPolicies(nat_true_);
281 policy_watcher_->SetPolicies(&nat_false_); 417 SetPolicies(nat_false_);
282 StopWatching(); 418 StopWatching();
283 } 419 }
284 420
285 TEST_F(PolicyWatcherTest, NatNoneThenFalse) { 421 TEST_F(PolicyWatcherTest, NatNoneThenFalse) {
286 testing::InSequence sequence; 422 testing::InSequence sequence;
287 EXPECT_CALL(mock_policy_callback_, 423 EXPECT_CALL(mock_policy_callback_,
288 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 424 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
289 EXPECT_CALL(mock_policy_callback_, 425 EXPECT_CALL(mock_policy_callback_,
290 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 426 OnPolicyUpdatePtr(DictionaryValueEq(nat_false_)));
291 427
292 StartWatching(); 428 SetPolicies(empty_);
293 policy_watcher_->SetPolicies(&empty_); 429 StartWatching();
294 policy_watcher_->SetPolicies(&nat_false_); 430 SetPolicies(nat_false_);
295 StopWatching(); 431 StopWatching();
296 } 432 }
297 433
298 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) { 434 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) {
299 testing::InSequence sequence; 435 testing::InSequence sequence;
300 EXPECT_CALL(mock_policy_callback_, 436 EXPECT_CALL(mock_policy_callback_,
301 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 437 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
302 EXPECT_CALL(mock_policy_callback_, 438 EXPECT_CALL(mock_policy_callback_,
303 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 439 OnPolicyUpdatePtr(DictionaryValueEq(nat_false_)));
304 EXPECT_CALL(mock_policy_callback_, 440 EXPECT_CALL(mock_policy_callback_,
305 OnPolicyUpdatePtr(IsPolicies(&nat_true_))); 441 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_)));
306 442
307 StartWatching(); 443 SetPolicies(empty_);
308 policy_watcher_->SetPolicies(&empty_); 444 StartWatching();
309 policy_watcher_->SetPolicies(&nat_false_); 445 SetPolicies(nat_false_);
310 policy_watcher_->SetPolicies(&nat_true_); 446 SetPolicies(nat_true_);
311 StopWatching(); 447 StopWatching();
312 } 448 }
313 449
314 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) { 450 TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) {
315 testing::InSequence sequence; 451 testing::InSequence sequence;
316 EXPECT_CALL(mock_policy_callback_, 452 EXPECT_CALL(mock_policy_callback_,
317 OnPolicyUpdatePtr(IsPolicies( 453 OnPolicyUpdatePtr(
318 &nat_true_domain_empty_others_default_))); 454 DictionaryValueEq(nat_true_domain_empty_others_default_)));
319 EXPECT_CALL(mock_policy_callback_, 455 EXPECT_CALL(mock_policy_callback_,
320 OnPolicyUpdatePtr(IsPolicies(&domain_full_))); 456 OnPolicyUpdatePtr(DictionaryValueEq(domain_full_)));
321 EXPECT_CALL(mock_policy_callback_, 457 EXPECT_CALL(mock_policy_callback_,
322 OnPolicyUpdatePtr(IsPolicies(&nat_false_))); 458 OnPolicyUpdatePtr(DictionaryValueEq(nat_false_)));
323 EXPECT_CALL(mock_policy_callback_, 459 EXPECT_CALL(mock_policy_callback_,
324 OnPolicyUpdatePtr(IsPolicies(&domain_empty_))); 460 OnPolicyUpdatePtr(DictionaryValueEq(domain_empty_)));
325 EXPECT_CALL(mock_policy_callback_, 461 EXPECT_CALL(mock_policy_callback_,
326 OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_))); 462 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_domain_full_)));
327 463
328 StartWatching(); 464 SetPolicies(nat_true_domain_empty_);
329 policy_watcher_->SetPolicies(&nat_true_domain_empty_); 465 StartWatching();
330 policy_watcher_->SetPolicies(&nat_true_domain_full_); 466 SetPolicies(nat_true_domain_full_);
331 policy_watcher_->SetPolicies(&nat_false_domain_full_); 467 SetPolicies(nat_false_domain_full_);
332 policy_watcher_->SetPolicies(&nat_false_domain_empty_); 468 SetPolicies(nat_false_domain_empty_);
333 policy_watcher_->SetPolicies(&nat_true_domain_full_); 469 SetPolicies(nat_true_domain_full_);
334 StopWatching(); 470 StopWatching();
335 } 471 }
336 472
337 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) { 473 TEST_F(PolicyWatcherTest, FilterUnknownPolicies) {
338 testing::InSequence sequence; 474 testing::InSequence sequence;
339 EXPECT_CALL(mock_policy_callback_, 475 EXPECT_CALL(mock_policy_callback_,
340 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 476 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
341 477
342 StartWatching(); 478 SetPolicies(empty_);
343 policy_watcher_->SetPolicies(&empty_); 479 StartWatching();
344 policy_watcher_->SetPolicies(&unknown_policies_); 480 SetPolicies(unknown_policies_);
345 policy_watcher_->SetPolicies(&empty_); 481 SetPolicies(empty_);
346 StopWatching(); 482 StopWatching();
347 } 483 }
348 484
349 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) { 485 TEST_F(PolicyWatcherTest, DebugOverrideNatPolicy) {
350 #if !defined(NDEBUG) 486 #if !defined(NDEBUG)
351 EXPECT_CALL(mock_policy_callback_, 487 EXPECT_CALL(mock_policy_callback_,
352 OnPolicyUpdatePtr(IsPolicies(&nat_false_overridden_others_default_))); 488 OnPolicyUpdatePtr(
489 DictionaryValueEq(nat_false_overridden_others_default_)));
353 #else 490 #else
354 EXPECT_CALL(mock_policy_callback_, 491 EXPECT_CALL(mock_policy_callback_,
355 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 492 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
356 #endif 493 #endif
357 494
358 StartWatching(); 495 SetPolicies(nat_true_and_overridden_);
359 policy_watcher_->SetPolicies(&nat_true_and_overridden_); 496 StartWatching();
360 StopWatching(); 497 StopWatching();
361 } 498 }
362 499
363 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) { 500 TEST_F(PolicyWatcherTest, PairingFalseThenTrue) {
364 testing::InSequence sequence; 501 testing::InSequence sequence;
365 EXPECT_CALL(mock_policy_callback_, 502 EXPECT_CALL(mock_policy_callback_,
366 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 503 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
367 EXPECT_CALL(mock_policy_callback_, 504 EXPECT_CALL(mock_policy_callback_,
368 OnPolicyUpdatePtr(IsPolicies(&pairing_false_))); 505 OnPolicyUpdatePtr(DictionaryValueEq(pairing_false_)));
369 EXPECT_CALL(mock_policy_callback_, 506 EXPECT_CALL(mock_policy_callback_,
370 OnPolicyUpdatePtr(IsPolicies(&pairing_true_))); 507 OnPolicyUpdatePtr(DictionaryValueEq(pairing_true_)));
371 508
372 StartWatching(); 509 SetPolicies(empty_);
373 policy_watcher_->SetPolicies(&empty_); 510 StartWatching();
374 policy_watcher_->SetPolicies(&pairing_false_); 511 SetPolicies(pairing_false_);
375 policy_watcher_->SetPolicies(&pairing_true_); 512 SetPolicies(pairing_true_);
376 StopWatching(); 513 StopWatching();
377 } 514 }
378 515
379 TEST_F(PolicyWatcherTest, GnubbyAuth) { 516 TEST_F(PolicyWatcherTest, GnubbyAuth) {
380 testing::InSequence sequence; 517 testing::InSequence sequence;
381 EXPECT_CALL(mock_policy_callback_, 518 EXPECT_CALL(mock_policy_callback_,
382 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 519 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
383 EXPECT_CALL(mock_policy_callback_, 520 EXPECT_CALL(mock_policy_callback_,
384 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_false_))); 521 OnPolicyUpdatePtr(DictionaryValueEq(gnubby_auth_false_)));
385 EXPECT_CALL(mock_policy_callback_, 522 EXPECT_CALL(mock_policy_callback_,
386 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); 523 OnPolicyUpdatePtr(DictionaryValueEq(gnubby_auth_true_)));
387 524
388 StartWatching(); 525 SetPolicies(empty_);
389 policy_watcher_->SetPolicies(&empty_); 526 StartWatching();
390 policy_watcher_->SetPolicies(&gnubby_auth_false_); 527 SetPolicies(gnubby_auth_false_);
391 policy_watcher_->SetPolicies(&gnubby_auth_true_); 528 SetPolicies(gnubby_auth_true_);
392 StopWatching(); 529 StopWatching();
393 } 530 }
394 531
395 TEST_F(PolicyWatcherTest, Relay) { 532 TEST_F(PolicyWatcherTest, Relay) {
396 testing::InSequence sequence; 533 testing::InSequence sequence;
397 EXPECT_CALL(mock_policy_callback_, 534 EXPECT_CALL(mock_policy_callback_,
398 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 535 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
399 EXPECT_CALL(mock_policy_callback_, 536 EXPECT_CALL(mock_policy_callback_,
400 OnPolicyUpdatePtr(IsPolicies(&relay_false_))); 537 OnPolicyUpdatePtr(DictionaryValueEq(relay_false_)));
401 EXPECT_CALL(mock_policy_callback_, 538 EXPECT_CALL(mock_policy_callback_,
402 OnPolicyUpdatePtr(IsPolicies(&relay_true_))); 539 OnPolicyUpdatePtr(DictionaryValueEq(relay_true_)));
403 540
404 StartWatching(); 541 SetPolicies(empty_);
405 policy_watcher_->SetPolicies(&empty_); 542 StartWatching();
406 policy_watcher_->SetPolicies(&relay_false_); 543 SetPolicies(relay_false_);
407 policy_watcher_->SetPolicies(&relay_true_); 544 SetPolicies(relay_true_);
408 StopWatching(); 545 StopWatching();
409 } 546 }
410 547
411 TEST_F(PolicyWatcherTest, UdpPortRange) { 548 TEST_F(PolicyWatcherTest, UdpPortRange) {
412 testing::InSequence sequence; 549 testing::InSequence sequence;
413 EXPECT_CALL(mock_policy_callback_, 550 EXPECT_CALL(mock_policy_callback_,
414 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 551 OnPolicyUpdatePtr(DictionaryValueEq(nat_true_others_default_)));
415 EXPECT_CALL(mock_policy_callback_, 552 EXPECT_CALL(mock_policy_callback_,
416 OnPolicyUpdatePtr(IsPolicies(&port_range_full_))); 553 OnPolicyUpdatePtr(DictionaryValueEq(port_range_full_)));
417 EXPECT_CALL(mock_policy_callback_, 554 EXPECT_CALL(mock_policy_callback_,
418 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); 555 OnPolicyUpdatePtr(DictionaryValueEq(port_range_empty_)));
419 556
420 StartWatching(); 557 SetPolicies(empty_);
421 policy_watcher_->SetPolicies(&empty_); 558 StartWatching();
422 policy_watcher_->SetPolicies(&port_range_full_); 559 SetPolicies(port_range_full_);
423 policy_watcher_->SetPolicies(&port_range_empty_); 560 SetPolicies(port_range_empty_);
424 StopWatching(); 561 StopWatching();
425 } 562 }
426 563
427 const int kMaxTransientErrorRetries = 5; 564 const int kMaxTransientErrorRetries = 5;
428 565
429 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) { 566 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) {
430 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); 567 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
431 568
432 StartWatching(); 569 StartWatching();
433 policy_watcher_->SignalTransientErrorForTest(); 570 SignalTransientErrorForTest();
434 StopWatching(); 571 StopWatching();
435 } 572 }
436 573
437 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) { 574 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) {
438 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()); 575 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr());
439 576
440 StartWatching(); 577 StartWatching();
441 for (int i = 0; i < kMaxTransientErrorRetries; i++) { 578 for (int i = 0; i < kMaxTransientErrorRetries; i++) {
442 policy_watcher_->SignalTransientErrorForTest(); 579 SignalTransientErrorForTest();
443 } 580 }
444 StopWatching(); 581 StopWatching();
445 } 582 }
446 583
447 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { 584 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) {
448 testing::InSequence s; 585 testing::InSequence s;
449 EXPECT_CALL(mock_policy_callback_, 586 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_));
450 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
451 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); 587 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
452 588
453 StartWatching(); 589 StartWatching();
454 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 590 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
455 policy_watcher_->SignalTransientErrorForTest(); 591 SignalTransientErrorForTest();
456 } 592 }
457 policy_watcher_->SetPolicies(&nat_true_); 593 SetPolicies(nat_true_);
458 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 594 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
459 policy_watcher_->SignalTransientErrorForTest(); 595 SignalTransientErrorForTest();
460 } 596 }
461 StopWatching(); 597 StopWatching();
462 } 598 }
463 599
464 // Unit tests cannot instantiate PolicyWatcher on ChromeOS 600 // Unit tests cannot instantiate PolicyWatcher on ChromeOS
465 // (as this requires running inside a browser process). 601 // (as this requires running inside a browser process).
466 #ifndef OS_CHROMEOS 602 #ifndef OS_CHROMEOS
467 603
468 namespace { 604 namespace {
469 605
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 run_loop.RunUntilIdle(); 659 run_loop.RunUntilIdle();
524 } 660 }
525 661
526 // Today, the only verification offered by this test is: 662 // Today, the only verification offered by this test is:
527 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy 663 // - Manual verification of policy values dumped by OnPolicyUpdatedDumpPolicy
528 // - Automated verification that nothing crashed 664 // - Automated verification that nothing crashed
529 } 665 }
530 666
531 #endif 667 #endif
532 668
533 // TODO(lukasza): We should consider adding a test against a
534 // MockConfigurationPolicyProvider.
535
536 } // namespace policy_hack 669 } // namespace policy_hack
537 } // namespace remoting 670 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698