OLD | NEW |
---|---|
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() { |
23 } | 23 } |
24 | 24 |
25 virtual void SetUp() override { | 25 virtual void SetUp() override { |
26 message_loop_proxy_ = base::MessageLoopProxy::current(); | 26 message_loop_proxy_ = base::MessageLoopProxy::current(); |
27 policy_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate, | 27 policy_updated_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate, |
28 base::Unretained(&mock_policy_callback_)); | |
Lambros
2014/11/14 01:42:47
nit: Wrong indentation. Should line up with first
Łukasz Anforowicz
2014/11/14 03:17:18
Ah, right. I was doing a search & replace of poli
| |
29 policy_error_callback_ = base::Bind(&MockPolicyCallback::OnPolicyError, | |
28 base::Unretained(&mock_policy_callback_)); | 30 base::Unretained(&mock_policy_callback_)); |
29 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); | 31 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); |
30 nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true); | 32 nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true); |
31 nat_false_.SetBoolean(PolicyWatcher::kNatPolicyName, false); | 33 nat_false_.SetBoolean(PolicyWatcher::kNatPolicyName, false); |
32 nat_one_.SetInteger(PolicyWatcher::kNatPolicyName, 1); | 34 nat_one_.SetInteger(PolicyWatcher::kNatPolicyName, 1); |
33 domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, | 35 domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, |
34 std::string()); | 36 std::string()); |
35 domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, kHostDomain); | 37 domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, kHostDomain); |
36 SetDefaults(nat_true_others_default_); | 38 SetDefaults(nat_true_others_default_); |
37 nat_true_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, true); | 39 nat_true_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, true); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 nat_false_overridden_others_default_.SetBoolean( | 89 nat_false_overridden_others_default_.SetBoolean( |
88 PolicyWatcher::kNatPolicyName, false); | 90 PolicyWatcher::kNatPolicyName, false); |
89 nat_false_overridden_others_default_.SetString( | 91 nat_false_overridden_others_default_.SetString( |
90 PolicyWatcher::kHostDebugOverridePoliciesName, | 92 PolicyWatcher::kHostDebugOverridePoliciesName, |
91 kOverrideNatTraversalToFalse); | 93 kOverrideNatTraversalToFalse); |
92 #endif | 94 #endif |
93 } | 95 } |
94 | 96 |
95 protected: | 97 protected: |
96 void StartWatching() { | 98 void StartWatching() { |
97 policy_watcher_->StartWatching(policy_callback_); | 99 policy_watcher_->StartWatching( |
100 policy_updated_callback_, | |
101 policy_error_callback_); | |
98 base::RunLoop().RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
99 } | 103 } |
100 | 104 |
101 void StopWatching() { | 105 void StopWatching() { |
102 base::WaitableEvent stop_event(false, false); | 106 base::WaitableEvent stop_event(false, false); |
103 policy_watcher_->StopWatching(&stop_event); | 107 policy_watcher_->StopWatching(&stop_event); |
104 base::RunLoop().RunUntilIdle(); | 108 base::RunLoop().RunUntilIdle(); |
105 EXPECT_EQ(true, stop_event.IsSignaled()); | 109 EXPECT_EQ(true, stop_event.IsSignaled()); |
106 } | 110 } |
107 | 111 |
108 static const char* kHostDomain; | 112 static const char* kHostDomain; |
109 static const char* kPortRange; | 113 static const char* kPortRange; |
110 base::MessageLoop message_loop_; | 114 base::MessageLoop message_loop_; |
111 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 115 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
112 MockPolicyCallback mock_policy_callback_; | 116 MockPolicyCallback mock_policy_callback_; |
113 PolicyWatcher::PolicyCallback policy_callback_; | 117 PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_; |
118 PolicyWatcher::PolicyErrorCallback policy_error_callback_; | |
114 scoped_ptr<FakePolicyWatcher> policy_watcher_; | 119 scoped_ptr<FakePolicyWatcher> policy_watcher_; |
115 base::DictionaryValue empty_; | 120 base::DictionaryValue empty_; |
116 base::DictionaryValue nat_true_; | 121 base::DictionaryValue nat_true_; |
117 base::DictionaryValue nat_false_; | 122 base::DictionaryValue nat_false_; |
118 base::DictionaryValue nat_one_; | 123 base::DictionaryValue nat_one_; |
119 base::DictionaryValue domain_empty_; | 124 base::DictionaryValue domain_empty_; |
120 base::DictionaryValue domain_full_; | 125 base::DictionaryValue domain_full_; |
121 base::DictionaryValue nat_true_others_default_; | 126 base::DictionaryValue nat_true_others_default_; |
122 base::DictionaryValue nat_false_others_default_; | 127 base::DictionaryValue nat_false_others_default_; |
123 base::DictionaryValue domain_empty_others_default_; | 128 base::DictionaryValue domain_empty_others_default_; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 EXPECT_CALL(mock_policy_callback_, | 400 EXPECT_CALL(mock_policy_callback_, |
396 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); | 401 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); |
397 | 402 |
398 StartWatching(); | 403 StartWatching(); |
399 policy_watcher_->SetPolicies(&empty_); | 404 policy_watcher_->SetPolicies(&empty_); |
400 policy_watcher_->SetPolicies(&port_range_full_); | 405 policy_watcher_->SetPolicies(&port_range_full_); |
401 policy_watcher_->SetPolicies(&port_range_empty_); | 406 policy_watcher_->SetPolicies(&port_range_empty_); |
402 StopWatching(); | 407 StopWatching(); |
403 } | 408 } |
404 | 409 |
410 const int kMaxTransientErrorRetries = 5; | |
411 | |
412 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) { | |
413 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); | |
414 | |
415 StartWatching(); | |
416 policy_watcher_->SignalTransientErrorForTest(); | |
417 StopWatching(); | |
418 } | |
419 | |
420 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) { | |
421 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()); | |
422 | |
423 StartWatching(); | |
424 for (int i = 0; i < kMaxTransientErrorRetries; i++) { | |
425 policy_watcher_->SignalTransientErrorForTest(); | |
426 } | |
427 StopWatching(); | |
428 } | |
429 | |
430 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { | |
431 testing::InSequence s; | |
432 EXPECT_CALL(mock_policy_callback_, | |
433 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); | |
434 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); | |
435 | |
436 StartWatching(); | |
437 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { | |
438 policy_watcher_->SignalTransientErrorForTest(); | |
439 } | |
440 policy_watcher_->SetPolicies(&nat_true_); | |
441 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { | |
442 policy_watcher_->SignalTransientErrorForTest(); | |
443 } | |
444 StopWatching(); | |
445 } | |
446 | |
405 } // namespace policy_hack | 447 } // namespace policy_hack |
406 } // namespace remoting | 448 } // namespace remoting |
OLD | NEW |