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

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

Issue 746723002: Revert of Reporting of policy errors via host-offline-reason: part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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_linux.cc ('k') | remoting/host/remoting_me2me_host.cc » ('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/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 void SetUp() override { 25 void SetUp() override {
26 message_loop_proxy_ = base::MessageLoopProxy::current(); 26 message_loop_proxy_ = base::MessageLoopProxy::current();
27 policy_updated_callback_ = base::Bind( 27 policy_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate,
28 &MockPolicyCallback::OnPolicyUpdate, 28 base::Unretained(&mock_policy_callback_));
29 base::Unretained(&mock_policy_callback_));
30 policy_error_callback_ = base::Bind(
31 &MockPolicyCallback::OnPolicyError,
32 base::Unretained(&mock_policy_callback_));
33 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); 29 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_));
34 nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 30 nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true);
35 nat_false_.SetBoolean(PolicyWatcher::kNatPolicyName, false); 31 nat_false_.SetBoolean(PolicyWatcher::kNatPolicyName, false);
36 nat_one_.SetInteger(PolicyWatcher::kNatPolicyName, 1); 32 nat_one_.SetInteger(PolicyWatcher::kNatPolicyName, 1);
37 domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, 33 domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName,
38 std::string()); 34 std::string());
39 domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, kHostDomain); 35 domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, kHostDomain);
40 SetDefaults(nat_true_others_default_); 36 SetDefaults(nat_true_others_default_);
41 nat_true_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 37 nat_true_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, true);
42 SetDefaults(nat_false_others_default_); 38 SetDefaults(nat_false_others_default_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 nat_false_overridden_others_default_.SetBoolean( 87 nat_false_overridden_others_default_.SetBoolean(
92 PolicyWatcher::kNatPolicyName, false); 88 PolicyWatcher::kNatPolicyName, false);
93 nat_false_overridden_others_default_.SetString( 89 nat_false_overridden_others_default_.SetString(
94 PolicyWatcher::kHostDebugOverridePoliciesName, 90 PolicyWatcher::kHostDebugOverridePoliciesName,
95 kOverrideNatTraversalToFalse); 91 kOverrideNatTraversalToFalse);
96 #endif 92 #endif
97 } 93 }
98 94
99 protected: 95 protected:
100 void StartWatching() { 96 void StartWatching() {
101 policy_watcher_->StartWatching( 97 policy_watcher_->StartWatching(policy_callback_);
102 policy_updated_callback_,
103 policy_error_callback_);
104 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
105 } 99 }
106 100
107 void StopWatching() { 101 void StopWatching() {
108 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1); 102 EXPECT_CALL(*this, PostPolicyWatcherShutdown()).Times(1);
109 policy_watcher_->StopWatching(base::Bind( 103 policy_watcher_->StopWatching(base::Bind(
110 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this))); 104 &PolicyWatcherTest::PostPolicyWatcherShutdown, base::Unretained(this)));
111 base::RunLoop().RunUntilIdle(); 105 base::RunLoop().RunUntilIdle();
112 } 106 }
113 107
114 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); 108 MOCK_METHOD0(PostPolicyWatcherShutdown, void());
115 109
116 static const char* kHostDomain; 110 static const char* kHostDomain;
117 static const char* kPortRange; 111 static const char* kPortRange;
118 base::MessageLoop message_loop_; 112 base::MessageLoop message_loop_;
119 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 113 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
120 MockPolicyCallback mock_policy_callback_; 114 MockPolicyCallback mock_policy_callback_;
121 PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_; 115 PolicyWatcher::PolicyCallback policy_callback_;
122 PolicyWatcher::PolicyErrorCallback policy_error_callback_;
123 scoped_ptr<FakePolicyWatcher> policy_watcher_; 116 scoped_ptr<FakePolicyWatcher> policy_watcher_;
124 base::DictionaryValue empty_; 117 base::DictionaryValue empty_;
125 base::DictionaryValue nat_true_; 118 base::DictionaryValue nat_true_;
126 base::DictionaryValue nat_false_; 119 base::DictionaryValue nat_false_;
127 base::DictionaryValue nat_one_; 120 base::DictionaryValue nat_one_;
128 base::DictionaryValue domain_empty_; 121 base::DictionaryValue domain_empty_;
129 base::DictionaryValue domain_full_; 122 base::DictionaryValue domain_full_;
130 base::DictionaryValue nat_true_others_default_; 123 base::DictionaryValue nat_true_others_default_;
131 base::DictionaryValue nat_false_others_default_; 124 base::DictionaryValue nat_false_others_default_;
132 base::DictionaryValue domain_empty_others_default_; 125 base::DictionaryValue domain_empty_others_default_;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 EXPECT_CALL(mock_policy_callback_, 397 EXPECT_CALL(mock_policy_callback_,
405 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_))); 398 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_)));
406 399
407 StartWatching(); 400 StartWatching();
408 policy_watcher_->SetPolicies(&empty_); 401 policy_watcher_->SetPolicies(&empty_);
409 policy_watcher_->SetPolicies(&port_range_full_); 402 policy_watcher_->SetPolicies(&port_range_full_);
410 policy_watcher_->SetPolicies(&port_range_empty_); 403 policy_watcher_->SetPolicies(&port_range_empty_);
411 StopWatching(); 404 StopWatching();
412 } 405 }
413 406
414 const int kMaxTransientErrorRetries = 5;
415
416 TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) {
417 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
418
419 StartWatching();
420 policy_watcher_->SignalTransientErrorForTest();
421 StopWatching();
422 }
423
424 TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) {
425 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr());
426
427 StartWatching();
428 for (int i = 0; i < kMaxTransientErrorRetries; i++) {
429 policy_watcher_->SignalTransientErrorForTest();
430 }
431 StopWatching();
432 }
433
434 TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) {
435 testing::InSequence s;
436 EXPECT_CALL(mock_policy_callback_,
437 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
438 EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0);
439
440 StartWatching();
441 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
442 policy_watcher_->SignalTransientErrorForTest();
443 }
444 policy_watcher_->SetPolicies(&nat_true_);
445 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
446 policy_watcher_->SignalTransientErrorForTest();
447 }
448 StopWatching();
449 }
450
451 } // namespace policy_hack 407 } // namespace policy_hack
452 } // namespace remoting 408 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/policy_watcher_linux.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698