Chromium Code Reviews| 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 class PairingRegistryTest : public testing::Test { | 16 class PairingRegistryTest : public testing::Test { |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 class MockDelegate : public PairingRegistry::Delegate { | 19 class MockDelegate : public PairingRegistry::Delegate { |
| 20 public: | 20 public: |
| 21 // MockDelegate saves to an explicit external PairedClients instance because | 21 // MockDelegate saves to an explicit external PairedClients instance because |
| 22 // PairingRegistry takes ownership of it and makes no guarantees about its | 22 // PairingRegistry takes ownership of it and makes no guarantees about its |
| 23 // lifetime, so this is a simple way of getting access to pairing results. | 23 // lifetime, so this is a simple way of getting access to pairing results. |
| 24 MockDelegate(PairingRegistry::PairedClients* paired_clients) | 24 explicit MockDelegate(PairingRegistry::PairedClients* paired_clients) |
| 25 : paired_clients_(paired_clients) { | 25 : paired_clients_(paired_clients) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual void Save( | 28 virtual void Save( |
| 29 const PairingRegistry::PairedClients& paired_clients) OVERRIDE { | 29 const PairingRegistry::PairedClients& paired_clients) OVERRIDE { |
| 30 *paired_clients_ = paired_clients; | 30 *paired_clients_ = paired_clients; |
| 31 } | 31 } |
| 32 virtual PairingRegistry::PairedClients LoadOnCurrentThread() OVERRIDE { | |
| 33 // This convenience method should not be called by the PairingRegistry and | |
| 34 // isn't called by the unit test either. | |
| 35 EXPECT_TRUE(false); | |
|
Lambros
2013/05/31 18:51:59
nit: ADD_FAILURE(); is cleaner.
Jamie
2013/06/19 17:56:44
This is gone in the current version.
| |
| 36 return PairingRegistry::PairedClients(); | |
| 37 } | |
| 32 | 38 |
| 33 protected: | 39 protected: |
| 34 PairingRegistry::PairedClients* paired_clients_; | 40 PairingRegistry::PairedClients* paired_clients_; |
| 35 }; | 41 }; |
| 36 | 42 |
| 37 TEST_F(PairingRegistryTest, LoadAndLookup) { | 43 TEST_F(PairingRegistryTest, LoadAndLookup) { |
| 38 PairingRegistry::Pairing client_info = { | 44 PairingRegistry::Pairing client_info = { |
| 45 base::Time(), | |
| 39 "client_id", | 46 "client_id", |
| 40 "client_name", | 47 "client_name", |
| 41 "shared_secret" | 48 "shared_secret" |
| 42 }; | 49 }; |
| 43 PairingRegistry::PairedClients clients; | 50 PairingRegistry::PairedClients clients; |
| 44 clients[client_info.client_id] = client_info; | 51 clients[client_info.client_id] = client_info; |
| 45 scoped_ptr<PairingRegistry::Delegate> delegate(new MockDelegate(&clients)); | 52 scoped_ptr<PairingRegistry::Delegate> delegate(new MockDelegate(&clients)); |
| 46 | 53 |
| 47 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass(), | 54 scoped_refptr<PairingRegistry> registry(new PairingRegistry(delegate.Pass(), |
| 48 clients)); | 55 clients)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 65 | 72 |
| 66 ASSERT_EQ(clients.size(), 2u); | 73 ASSERT_EQ(clients.size(), 2u); |
| 67 PairingRegistry::Pairing first = clients.begin()->second; | 74 PairingRegistry::Pairing first = clients.begin()->second; |
| 68 PairingRegistry::Pairing second = (++clients.begin())->second; | 75 PairingRegistry::Pairing second = (++clients.begin())->second; |
| 69 EXPECT_EQ(first.client_name, second.client_name); | 76 EXPECT_EQ(first.client_name, second.client_name); |
| 70 EXPECT_NE(first.client_id, second.client_id); | 77 EXPECT_NE(first.client_id, second.client_id); |
| 71 } | 78 } |
| 72 | 79 |
| 73 } // namespace protocol | 80 } // namespace protocol |
| 74 } // namespace remoting | 81 } // namespace remoting |
| OLD | NEW |