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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "remoting/protocol/protocol_mock_objects.h" | 11 #include "remoting/protocol/protocol_mock_objects.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 namespace protocol { | 16 namespace protocol { |
17 | 17 |
18 class PairingRegistryTest : public testing::Test { | 18 class PairingRegistryTest : public testing::Test { |
19 public: | 19 public: |
20 virtual void SetUp() OVERRIDE { | 20 virtual void SetUp() OVERRIDE { |
21 got_secret_ = false; | 21 got_secret_ = false; |
22 } | 22 } |
23 | 23 |
24 void CompareSecret(const std::string& expected, | 24 void CompareSecret(const std::string& expected, |
25 PairingRegistry::Pairing actual) { | 25 PairingRegistry::Pairing actual) { |
26 EXPECT_EQ(actual.shared_secret, expected); | 26 EXPECT_EQ(actual.shared_secret(), expected); |
27 got_secret_ = true; | 27 got_secret_ = true; |
28 } | 28 } |
29 | 29 |
30 protected: | 30 protected: |
31 bool got_secret_; | 31 bool got_secret_; |
32 }; | 32 }; |
33 | 33 |
34 TEST_F(PairingRegistryTest, GetPairing) { | 34 TEST_F(PairingRegistryTest, GetPairing) { |
35 PairingRegistry::Pairing client_info = { | 35 PairingRegistry::Pairing client_info = |
36 "client_id", | 36 PairingRegistry::Pairing::Create("client_name"); |
37 "client_name", | |
38 "shared_secret" | |
39 }; | |
40 MockPairingRegistryDelegate* mock_delegate = | 37 MockPairingRegistryDelegate* mock_delegate = |
41 new MockPairingRegistryDelegate(); | 38 new MockPairingRegistryDelegate(); |
42 mock_delegate->AddPairing(client_info); | 39 mock_delegate->AddPairing(client_info, PairingRegistry::AddPairingCallback()); |
43 scoped_ptr<PairingRegistry::Delegate> delegate(mock_delegate); | 40 scoped_ptr<PairingRegistry::Delegate> delegate(mock_delegate); |
44 | 41 |
45 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass())); | 42 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass())); |
46 | 43 |
47 registry->GetPairing(client_info.client_id, | 44 registry->GetPairing(client_info.client_id(), |
48 base::Bind(&PairingRegistryTest::CompareSecret, | 45 base::Bind(&PairingRegistryTest::CompareSecret, |
49 base::Unretained(this), | 46 base::Unretained(this), |
50 client_info.shared_secret)); | 47 client_info.shared_secret())); |
51 mock_delegate->RunCallback(); | 48 mock_delegate->RunCallback(); |
52 EXPECT_TRUE(got_secret_); | 49 EXPECT_TRUE(got_secret_); |
53 } | 50 } |
54 | 51 |
55 TEST_F(PairingRegistryTest, AddPairing) { | 52 TEST_F(PairingRegistryTest, AddPairing) { |
56 MockPairingRegistryDelegate* mock_delegate = | 53 MockPairingRegistryDelegate* mock_delegate = |
57 new MockPairingRegistryDelegate(); | 54 new MockPairingRegistryDelegate(); |
58 scoped_ptr<PairingRegistry::Delegate> delegate(mock_delegate); | 55 scoped_ptr<PairingRegistry::Delegate> delegate(mock_delegate); |
59 | 56 |
60 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass())); | 57 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass())); |
61 | 58 |
62 // Verify that we can create pairings from two clients with the same name, but | 59 // Verify that we can create pairings from two clients with the same name, but |
63 // that they aren't allocated the same client id. | 60 // that they aren't allocated the same client id. |
64 PairingRegistry::Pairing pairing_1 = registry->CreatePairing("client_name"); | 61 PairingRegistry::Pairing pairing_1 = registry->CreatePairing("client_name"); |
65 PairingRegistry::Pairing pairing_2 = registry->CreatePairing("client_name"); | 62 PairingRegistry::Pairing pairing_2 = registry->CreatePairing("client_name"); |
66 | 63 |
67 const PairingRegistry::PairedClients& clients = | 64 const PairingRegistry::PairedClients& clients = |
68 mock_delegate->paired_clients(); | 65 mock_delegate->paired_clients(); |
69 ASSERT_EQ(clients.size(), 2u); | 66 ASSERT_EQ(clients.size(), 2u); |
70 PairingRegistry::Pairing first = clients.begin()->second; | 67 PairingRegistry::Pairing first = clients.begin()->second; |
71 PairingRegistry::Pairing second = (++clients.begin())->second; | 68 PairingRegistry::Pairing second = (++clients.begin())->second; |
72 EXPECT_EQ(first.client_name, second.client_name); | 69 EXPECT_EQ(first.client_name(), second.client_name()); |
73 EXPECT_NE(first.client_id, second.client_id); | 70 EXPECT_NE(first.client_id(), second.client_id()); |
74 } | 71 } |
75 | 72 |
76 } // namespace protocol | 73 } // namespace protocol |
77 } // namespace remoting | 74 } // namespace remoting |
OLD | NEW |