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

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

Issue 10804040: [Chromoting] Refactor the host policy watcher so that policies can easily be added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for Windows. Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
(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_policy_watcher.h"
10 #include "remoting/host/policy_hack/mock_policy_callback.h"
11 #include "remoting/host/policy_hack/policy_watcher.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace remoting {
16 namespace policy_hack {
17
18 class PolicyWatcherTest : public testing::Test {
19 public:
20 PolicyWatcherTest() {
21 }
22
23 virtual void SetUp() OVERRIDE {
24 message_loop_proxy_ = base::MessageLoopProxy::current();
25 policy_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate,
26 base::Unretained(&mock_policy_callback_));
27 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_));
28 nat_true.SetBoolean(PolicyWatcher::kNatPolicyName, true);
29 nat_false.SetBoolean(PolicyWatcher::kNatPolicyName, false);
30 nat_one.SetInteger(PolicyWatcher::kNatPolicyName, 1);
31 }
32
33 protected:
34 void StartWatching() {
35 policy_watcher_->StartWatching(policy_callback_);
36 message_loop_.RunUntilIdle();
37 }
38
39 void StopWatching() {
40 base::WaitableEvent stop_event(false, false);
41 policy_watcher_->StopWatching(&stop_event);
42 message_loop_.RunUntilIdle();
43 EXPECT_EQ(true, stop_event.IsSignaled());
44 }
45
46 MessageLoop message_loop_;
47 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
48 MockPolicyCallback mock_policy_callback_;
49 PolicyWatcher::PolicyCallback policy_callback_;
50 scoped_ptr<FakePolicyWatcher> policy_watcher_;
51 base::DictionaryValue empty;
52 base::DictionaryValue nat_true;
53 base::DictionaryValue nat_false;
54 base::DictionaryValue nat_one;
55 };
56
57 MATCHER_P(IsPolicies, dict, "") {
58 return arg->Equals(dict);
59 }
60
61 TEST_F(PolicyWatcherTest, None) {
62 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
63
64 StartWatching();
65 policy_watcher_->SetPolicies(&empty);
66 StopWatching();
67 }
68
69 TEST_F(PolicyWatcherTest, NatTrue) {
70 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
71
72 StartWatching();
73 policy_watcher_->SetPolicies(&nat_true);
74 StopWatching();
75 }
76
77 TEST_F(PolicyWatcherTest, NatFalse) {
78 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false)));
79
80 StartWatching();
81 policy_watcher_->SetPolicies(&nat_false);
82 StopWatching();
83 }
84
85 TEST_F(PolicyWatcherTest, NatOne) {
86 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false)));
87
88 StartWatching();
89 policy_watcher_->SetPolicies(&nat_one);
90 StopWatching();
91 }
92
93 TEST_F(PolicyWatcherTest, NatNoneThenTrue) {
94 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
95
96 StartWatching();
97 policy_watcher_->SetPolicies(&empty);
98 policy_watcher_->SetPolicies(&nat_true);
99 StopWatching();
100 }
101
102 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) {
103 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
104
105 StartWatching();
106 policy_watcher_->SetPolicies(&empty);
107 policy_watcher_->SetPolicies(&nat_true);
108 policy_watcher_->SetPolicies(&nat_true);
109 StopWatching();
110 }
111
112 TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) {
113 testing::InSequence sequence;
114 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
115 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false)));
116
117 StartWatching();
118 policy_watcher_->SetPolicies(&empty);
119 policy_watcher_->SetPolicies(&nat_true);
120 policy_watcher_->SetPolicies(&nat_true);
121 policy_watcher_->SetPolicies(&nat_false);
122 StopWatching();
123 }
124
125 TEST_F(PolicyWatcherTest, NatNoneThenFalse) {
126 testing::InSequence sequence;
127 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
128 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false)));
129
130 StartWatching();
131 policy_watcher_->SetPolicies(&empty);
132 policy_watcher_->SetPolicies(&nat_false);
133 StopWatching();
134 }
135
136 TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) {
137 testing::InSequence sequence;
138 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
139 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false)));
140 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true)));
141
142 StartWatching();
143 policy_watcher_->SetPolicies(&empty);
144 policy_watcher_->SetPolicies(&nat_false);
145 policy_watcher_->SetPolicies(&nat_true);
146 StopWatching();
147 }
148
149 } // namespace policy_hack
150 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/policy_watcher_mac.mm ('k') | remoting/host/policy_hack/policy_watcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698