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

Side by Side Diff: components/proximity_auth/throttled_bluetooth_connection_finder_unittest.cc

Issue 1351473003: Refactor fake Connection subclasses in proximity_auth/ tests to a single file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client_rename
Patch Set: rebase Created 5 years, 2 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
« no previous file with comments | « components/proximity_auth/remote_device_life_cycle_impl_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/throttled_bluetooth_connection_finder.h" 5 #include "components/proximity_auth/throttled_bluetooth_connection_finder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "components/proximity_auth/bluetooth_connection_finder.h" 10 #include "components/proximity_auth/bluetooth_connection_finder.h"
11 #include "components/proximity_auth/bluetooth_throttler.h" 11 #include "components/proximity_auth/bluetooth_throttler.h"
12 #include "components/proximity_auth/connection.h" 12 #include "components/proximity_auth/fake_connection.h"
13 #include "components/proximity_auth/remote_device.h" 13 #include "components/proximity_auth/remote_device.h"
14 #include "components/proximity_auth/wire_message.h" 14 #include "components/proximity_auth/wire_message.h"
15 #include "device/bluetooth/bluetooth_uuid.h" 15 #include "device/bluetooth/bluetooth_uuid.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using testing::NiceMock; 19 using testing::NiceMock;
20 using testing::Return; 20 using testing::Return;
21 using testing::_; 21 using testing::_;
22 22
23 namespace proximity_auth { 23 namespace proximity_auth {
24 namespace { 24 namespace {
25 25
26 const int kPollingIntervalSeconds = 7; 26 const int kPollingIntervalSeconds = 7;
27 const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF"; 27 const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF";
28 28
29 // A callback that stores a found |connection| into |out|. 29 // A callback that stores a found |connection| into |out|.
30 void SaveConnection(scoped_ptr<Connection>* out, 30 void SaveConnection(scoped_ptr<Connection>* out,
31 scoped_ptr<Connection> connection) { 31 scoped_ptr<Connection> connection) {
32 *out = connection.Pass(); 32 *out = connection.Pass();
33 } 33 }
34 34
35 class StubConnection : public Connection {
36 public:
37 StubConnection() : Connection(RemoteDevice()) {}
38 ~StubConnection() override {}
39
40 void Connect() override {}
41 void Disconnect() override {}
42 void SendMessageImpl(scoped_ptr<WireMessage> message) override {}
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(StubConnection);
46 };
47
48 class MockBluetoothThrottler : public BluetoothThrottler { 35 class MockBluetoothThrottler : public BluetoothThrottler {
49 public: 36 public:
50 MockBluetoothThrottler() {} 37 MockBluetoothThrottler() {}
51 ~MockBluetoothThrottler() override {} 38 ~MockBluetoothThrottler() override {}
52 39
53 MOCK_CONST_METHOD0(GetDelay, base::TimeDelta()); 40 MOCK_CONST_METHOD0(GetDelay, base::TimeDelta());
54 MOCK_METHOD1(OnConnection, void(Connection* connection)); 41 MOCK_METHOD1(OnConnection, void(Connection* connection));
55 42
56 private: 43 private:
57 DISALLOW_COPY_AND_ASSIGN(MockBluetoothThrottler); 44 DISALLOW_COPY_AND_ASSIGN(MockBluetoothThrottler);
58 }; 45 };
59 46
60 class FakeBluetoothConnectionFinder : public BluetoothConnectionFinder { 47 class FakeBluetoothConnectionFinder : public BluetoothConnectionFinder {
61 public: 48 public:
62 FakeBluetoothConnectionFinder() 49 FakeBluetoothConnectionFinder()
63 : BluetoothConnectionFinder( 50 : BluetoothConnectionFinder(
64 RemoteDevice(), 51 RemoteDevice(),
65 device::BluetoothUUID(kUuid), 52 device::BluetoothUUID(kUuid),
66 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)) {} 53 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)) {}
67 ~FakeBluetoothConnectionFinder() override {} 54 ~FakeBluetoothConnectionFinder() override {}
68 55
69 void Find(const ConnectionCallback& connection_callback) override { 56 void Find(const ConnectionCallback& connection_callback) override {
70 connection_callback.Run(make_scoped_ptr(new StubConnection)); 57 connection_callback.Run(
58 make_scoped_ptr(new FakeConnection(RemoteDevice())));
71 } 59 }
72 60
73 private: 61 private:
74 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothConnectionFinder); 62 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothConnectionFinder);
75 }; 63 };
76 64
77 } // namespace 65 } // namespace
78 66
79 class ProximityAuthThrottledBluetoothConnectionFinderTest 67 class ProximityAuthThrottledBluetoothConnectionFinderTest
80 : public testing::Test { 68 : public testing::Test {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 ThrottledBluetoothConnectionFinder connection_finder( 112 ThrottledBluetoothConnectionFinder connection_finder(
125 make_scoped_ptr(new FakeBluetoothConnectionFinder), task_runner_, 113 make_scoped_ptr(new FakeBluetoothConnectionFinder), task_runner_,
126 &throttler_); 114 &throttler_);
127 scoped_ptr<Connection> connection; 115 scoped_ptr<Connection> connection;
128 EXPECT_CALL(throttler_, OnConnection(_)); 116 EXPECT_CALL(throttler_, OnConnection(_));
129 connection_finder.Find(base::Bind(&SaveConnection, &connection)); 117 connection_finder.Find(base::Bind(&SaveConnection, &connection));
130 EXPECT_TRUE(connection); 118 EXPECT_TRUE(connection);
131 } 119 }
132 120
133 } // namespace proximity_auth 121 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/remote_device_life_cycle_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698