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 "remoting/protocol/pairing_registry.h" | 5 #include "remoting/protocol/pairing_registry.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 EXPECT_EQ(expected.client_id(), value); | 31 EXPECT_EQ(expected.client_id(), value); |
32 | 32 |
33 EXPECT_FALSE(actual.HasKey(PairingRegistry::kSharedSecretKey)); | 33 EXPECT_FALSE(actual.HasKey(PairingRegistry::kSharedSecretKey)); |
34 } | 34 } |
35 | 35 |
36 // SaveCallback that expects to be called with success = true. | 36 // SaveCallback that expects to be called with success = true. |
37 void ExpectSaveSuccess(bool success) { | 37 void ExpectSaveSuccess(bool success) { |
38 EXPECT_TRUE(success); | 38 EXPECT_TRUE(success); |
39 } | 39 } |
40 | 40 |
41 void ExpectClientName(const std::string& expected, | |
42 PairingRegistry::Pairing actual) { | |
43 EXPECT_EQ(expected, actual.client_name()); | |
44 } | |
45 | |
46 void ExpectNoPairings(scoped_ptr<base::ListValue> pairings) { | |
47 EXPECT_TRUE(pairings->empty()); | |
48 } | |
49 | |
41 } // namespace | 50 } // namespace |
42 | 51 |
43 namespace remoting { | 52 namespace remoting { |
44 namespace protocol { | 53 namespace protocol { |
45 | 54 |
46 class PairingRegistryTest : public testing::Test { | 55 class PairingRegistryTest : public testing::Test { |
47 public: | 56 public: |
48 void CompareSecret(const std::string& expected, | 57 void CompareSecret(const std::string& expected, |
49 PairingRegistry::Pairing actual) { | 58 PairingRegistry::Pairing actual) { |
50 EXPECT_EQ(expected, actual.shared_secret()); | 59 EXPECT_EQ(expected, actual.shared_secret()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 180 |
172 // Re-read the list, and verify it is empty. | 181 // Re-read the list, and verify it is empty. |
173 registry->GetAllPairings( | 182 registry->GetAllPairings( |
174 base::Bind(&PairingRegistryTest::set_pairings, | 183 base::Bind(&PairingRegistryTest::set_pairings, |
175 base::Unretained(this))); | 184 base::Unretained(this))); |
176 mock_delegate->RunCallback(); | 185 mock_delegate->RunCallback(); |
177 | 186 |
178 EXPECT_TRUE(pairings_->empty()); | 187 EXPECT_TRUE(pairings_->empty()); |
179 } | 188 } |
180 | 189 |
190 TEST_F(PairingRegistryTest, SerializedRequests) { | |
191 MockPairingRegistryDelegate* mock_delegate = | |
192 new MockPairingRegistryDelegate(); | |
193 scoped_ptr<PairingRegistry::Delegate> delegate(mock_delegate); | |
194 mock_delegate->set_run_save_callback_automatically(false); | |
195 | |
196 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass())); | |
197 PairingRegistry::Pairing pairing_1 = registry->CreatePairing("client1"); | |
198 PairingRegistry::Pairing pairing_2 = registry->CreatePairing("client2"); | |
199 registry->GetPairing(pairing_1.client_id(), | |
200 base::Bind(ExpectClientName, "client1")); | |
201 registry->GetPairing(pairing_2.client_id(), | |
202 base::Bind(ExpectClientName, "client2")); | |
203 registry->DeletePairing(pairing_2.client_id(), base::Bind(ExpectSaveSuccess)); | |
204 registry->GetPairing(pairing_1.client_id(), | |
205 base::Bind(ExpectClientName, "client1")); | |
206 registry->GetPairing(pairing_2.client_id(), | |
207 base::Bind(ExpectClientName, "")); | |
208 registry->ClearAllPairings(base::Bind(ExpectSaveSuccess)); | |
Lambros
2013/07/18 20:34:51
optional: I know I originally wrote this myself in
Jamie
2013/07/18 22:44:56
Bind is needed to wrap a bare function. See callba
| |
209 registry->GetAllPairings(base::Bind(ExpectNoPairings)); | |
210 PairingRegistry::Pairing pairing_3 = registry->CreatePairing("client3"); | |
211 registry->GetPairing(pairing_3.client_id(), | |
212 base::Bind(ExpectClientName, "client3")); | |
213 | |
214 while (mock_delegate->HasCallback()) { | |
215 mock_delegate->RunCallback(); | |
Lambros
2013/07/18 20:34:51
I think we should verify the number of times this
Jamie
2013/07/18 22:44:56
This test shouldn't care how many *delegate* callb
| |
216 } | |
217 } | |
218 | |
181 } // namespace protocol | 219 } // namespace protocol |
182 } // namespace remoting | 220 } // namespace remoting |
OLD | NEW |