| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" |
| 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "remoting/host/policy_hack/fake_nat_policy.h" |
| 10 #include "remoting/host/policy_hack/mock_policy_callback.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace remoting { |
| 15 namespace policy_hack { |
| 16 |
| 17 class PolicyWatcherTest : public testing::Test { |
| 18 public: |
| 19 PolicyWatcherTest() { |
| 20 } |
| 21 |
| 22 virtual void SetUp() OVERRIDE { |
| 23 message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 24 policy_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate, |
| 25 base::Unretained(&mock_policy_callback_)); |
| 26 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); |
| 27 nat_true.SetBoolean(PolicyWatcher::kNatPolicyName, true); |
| 28 nat_false.SetBoolean(PolicyWatcher::kNatPolicyName, false); |
| 29 nat_one.SetInteger(PolicyWatcher::kNatPolicyName, 1); |
| 30 } |
| 31 |
| 32 protected: |
| 33 void StartWatching() { |
| 34 policy_watcher_->StartWatching(policy_callback_); |
| 35 message_loop_.RunUntilIdle(); |
| 36 } |
| 37 |
| 38 void StopWatching() { |
| 39 base::WaitableEvent stop_event(false, false); |
| 40 policy_watcher_->StopWatching(&stop_event); |
| 41 message_loop_.RunUntilIdle(); |
| 42 EXPECT_EQ(true, stop_event.IsSignaled()); |
| 43 } |
| 44 |
| 45 MessageLoop message_loop_; |
| 46 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 47 MockPolicyCallback mock_policy_callback_; |
| 48 PolicyWatcher::PolicyCallback policy_callback_; |
| 49 scoped_ptr<FakePolicyWatcher> policy_watcher_; |
| 50 base::DictionaryValue empty; |
| 51 base::DictionaryValue nat_true; |
| 52 base::DictionaryValue nat_false; |
| 53 base::DictionaryValue nat_one; |
| 54 }; |
| 55 |
| 56 MATCHER_P(IsPolicies, dict, "") { |
| 57 return arg->Equals(dict); |
| 58 } |
| 59 |
| 60 TEST_F(PolicyWatcherTest, None) { |
| 61 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 62 |
| 63 StartWatching(); |
| 64 policy_watcher_->SetPolicies(&empty); |
| 65 StopWatching(); |
| 66 } |
| 67 |
| 68 TEST_F(PolicyWatcherTest, NatTrue) { |
| 69 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 70 |
| 71 StartWatching(); |
| 72 policy_watcher_->SetPolicies(&nat_true); |
| 73 StopWatching(); |
| 74 } |
| 75 |
| 76 TEST_F(PolicyWatcherTest, NatFalse) { |
| 77 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); |
| 78 |
| 79 StartWatching(); |
| 80 policy_watcher_->SetPolicies(&nat_false); |
| 81 StopWatching(); |
| 82 } |
| 83 |
| 84 TEST_F(PolicyWatcherTest, NatOne) { |
| 85 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); |
| 86 |
| 87 StartWatching(); |
| 88 policy_watcher_->SetPolicies(&nat_one); |
| 89 StopWatching(); |
| 90 } |
| 91 |
| 92 TEST_F(PolicyWatcherTest, NatNoneThenTrue) { |
| 93 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 94 |
| 95 StartWatching(); |
| 96 policy_watcher_->SetPolicies(&empty); |
| 97 policy_watcher_->SetPolicies(&nat_true); |
| 98 StopWatching(); |
| 99 } |
| 100 |
| 101 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) { |
| 102 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 103 |
| 104 StartWatching(); |
| 105 policy_watcher_->SetPolicies(&empty); |
| 106 policy_watcher_->SetPolicies(&nat_true); |
| 107 policy_watcher_->SetPolicies(&nat_true); |
| 108 StopWatching(); |
| 109 } |
| 110 |
| 111 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) { |
| 112 testing::InSequence sequence; |
| 113 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 114 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); |
| 115 |
| 116 StartWatching(); |
| 117 policy_watcher_->SetPolicies(&empty); |
| 118 policy_watcher_->SetPolicies(&nat_true); |
| 119 policy_watcher_->SetPolicies(&nat_true); |
| 120 policy_watcher_->SetPolicies(&nat_false); |
| 121 StopWatching(); |
| 122 } |
| 123 |
| 124 TEST_F(PolicyWatcherTest, NatNoneThenFalse) { |
| 125 testing::InSequence sequence; |
| 126 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 127 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); |
| 128 |
| 129 StartWatching(); |
| 130 policy_watcher_->SetPolicies(&empty); |
| 131 policy_watcher_->SetPolicies(&nat_false); |
| 132 StopWatching(); |
| 133 } |
| 134 |
| 135 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) { |
| 136 testing::InSequence sequence; |
| 137 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 138 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); |
| 139 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); |
| 140 |
| 141 StartWatching(); |
| 142 policy_watcher_->SetPolicies(&empty); |
| 143 policy_watcher_->SetPolicies(&nat_false); |
| 144 policy_watcher_->SetPolicies(&nat_true); |
| 145 StopWatching(); |
| 146 } |
| 147 |
| 148 } // namespace policy_hack |
| 149 } // namespace remoting |
| OLD | NEW |