OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/proximity_auth/bluetooth_connection_finder.h" | 5 #include "components/proximity_auth/bluetooth_connection_finder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 const char kDeviceName[] = "Device name"; | 29 const char kDeviceName[] = "Device name"; |
30 const char kBluetoothAddress[] = "11:22:33:44:55:66"; | 30 const char kBluetoothAddress[] = "11:22:33:44:55:66"; |
31 const RemoteDevice kRemoteDevice = {kDeviceName, kBluetoothAddress}; | 31 const RemoteDevice kRemoteDevice = {kDeviceName, kBluetoothAddress}; |
32 | 32 |
33 const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF"; | 33 const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF"; |
34 | 34 |
35 class MockConnection : public Connection { | 35 class MockConnection : public Connection { |
36 public: | 36 public: |
37 MockConnection() : Connection(kRemoteDevice) {} | 37 MockConnection() : Connection(kRemoteDevice) {} |
38 virtual ~MockConnection() {} | 38 ~MockConnection() override {} |
39 | 39 |
40 MOCK_METHOD0(Connect, void()); | 40 MOCK_METHOD0(Connect, void()); |
41 | 41 |
42 using Connection::SetStatus; | 42 using Connection::SetStatus; |
43 | 43 |
44 private: | 44 private: |
45 void Disconnect() {} | 45 void Disconnect() override {} |
46 void SendMessageImpl(scoped_ptr<WireMessage> message) {} | 46 void SendMessageImpl(scoped_ptr<WireMessage> message) override {} |
47 | 47 |
48 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 48 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
49 }; | 49 }; |
50 | 50 |
51 class MockBluetoothConnectionFinder : public BluetoothConnectionFinder { | 51 class MockBluetoothConnectionFinder : public BluetoothConnectionFinder { |
52 public: | 52 public: |
53 MockBluetoothConnectionFinder() | 53 MockBluetoothConnectionFinder() |
54 : BluetoothConnectionFinder(kRemoteDevice, | 54 : BluetoothConnectionFinder(kRemoteDevice, |
55 device::BluetoothUUID(kUuid), | 55 device::BluetoothUUID(kUuid), |
56 base::TimeDelta()) {} | 56 base::TimeDelta()) {} |
57 virtual ~MockBluetoothConnectionFinder() {} | 57 ~MockBluetoothConnectionFinder() override {} |
58 | 58 |
59 MOCK_METHOD0(CreateConnectionProxy, Connection*()); | 59 MOCK_METHOD0(CreateConnectionProxy, Connection*()); |
60 | 60 |
61 // Creates a mock connection and sets an expectation that the mock connection | 61 // Creates a mock connection and sets an expectation that the mock connection |
62 // finder's CreateConnection() method will be called and will return the | 62 // finder's CreateConnection() method will be called and will return the |
63 // created connection. Returns a reference to the created connection. | 63 // created connection. Returns a reference to the created connection. |
64 // NOTE: The returned connection's lifetime is managed by the connection | 64 // NOTE: The returned connection's lifetime is managed by the connection |
65 // finder. | 65 // finder. |
66 MockConnection* ExpectCreateConnection() { | 66 MockConnection* ExpectCreateConnection() { |
67 scoped_ptr<MockConnection> connection(new NiceMock<MockConnection>()); | 67 scoped_ptr<MockConnection> connection(new NiceMock<MockConnection>()); |
68 MockConnection* connection_alias = connection.get(); | 68 MockConnection* connection_alias = connection.get(); |
69 EXPECT_CALL(*this, CreateConnectionProxy()) | 69 EXPECT_CALL(*this, CreateConnectionProxy()) |
70 .WillOnce(Return(connection.release())); | 70 .WillOnce(Return(connection.release())); |
71 return connection_alias; | 71 return connection_alias; |
72 } | 72 } |
73 | 73 |
74 using BluetoothConnectionFinder::AdapterPresentChanged; | 74 using BluetoothConnectionFinder::AdapterPresentChanged; |
75 using BluetoothConnectionFinder::AdapterPoweredChanged; | 75 using BluetoothConnectionFinder::AdapterPoweredChanged; |
76 | 76 |
77 protected: | 77 protected: |
78 virtual scoped_ptr<Connection> CreateConnection() override { | 78 scoped_ptr<Connection> CreateConnection() override { |
79 return make_scoped_ptr(CreateConnectionProxy()); | 79 return make_scoped_ptr(CreateConnectionProxy()); |
80 } | 80 } |
81 | 81 |
82 private: | 82 private: |
83 DISALLOW_COPY_AND_ASSIGN(MockBluetoothConnectionFinder); | 83 DISALLOW_COPY_AND_ASSIGN(MockBluetoothConnectionFinder); |
84 }; | 84 }; |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 class ProximityAuthBluetoothConnectionFinderTest : public testing::Test { | 88 class ProximityAuthBluetoothConnectionFinderTest : public testing::Test { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 run_loop.RunUntilIdle(); | 268 run_loop.RunUntilIdle(); |
269 ON_CALL(*adapter_, IsPresent()).WillByDefault(Return(true)); | 269 ON_CALL(*adapter_, IsPresent()).WillByDefault(Return(true)); |
270 | 270 |
271 // Now that there is no pending task, events should once again trigger new | 271 // Now that there is no pending task, events should once again trigger new |
272 // polling iterations. | 272 // polling iterations. |
273 connection_finder.ExpectCreateConnection(); | 273 connection_finder.ExpectCreateConnection(); |
274 connection_finder.AdapterPresentChanged(adapter_.get(), true); | 274 connection_finder.AdapterPresentChanged(adapter_.get(), true); |
275 } | 275 } |
276 | 276 |
277 } // namespace proximity_auth | 277 } // namespace proximity_auth |
OLD | NEW |