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

Side by Side Diff: chromeos/components/tether/ble_connection_manager_unittest.cc

Issue 2915833003: Tether: Break helper TimerFactory out of BleConnectionManager and HostScanCache. (Closed)
Patch Set: khorimoto@ comments. Created 3 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chromeos/components/tether/ble_connection_manager.h" 5 #include "chromeos/components/tether/ble_connection_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/timer/mock_timer.h" 8 #include "base/timer/mock_timer.h"
9 #include "chromeos/components/tether/ble_constants.h" 9 #include "chromeos/components/tether/ble_constants.h"
10 #include "chromeos/components/tether/proto/tether.pb.h" 10 #include "chromeos/components/tether/proto/tether.pb.h"
11 #include "chromeos/components/tether/timer_factory.h"
11 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection. h" 12 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection. h"
12 #include "components/cryptauth/bluetooth_throttler.h" 13 #include "components/cryptauth/bluetooth_throttler.h"
13 #include "components/cryptauth/connection.h" 14 #include "components/cryptauth/connection.h"
14 #include "components/cryptauth/fake_connection.h" 15 #include "components/cryptauth/fake_connection.h"
15 #include "components/cryptauth/fake_cryptauth_service.h" 16 #include "components/cryptauth/fake_cryptauth_service.h"
16 #include "components/cryptauth/fake_secure_channel.h" 17 #include "components/cryptauth/fake_secure_channel.h"
17 #include "components/cryptauth/fake_secure_message_delegate.h" 18 #include "components/cryptauth/fake_secure_message_delegate.h"
18 #include "components/cryptauth/remote_device_test_util.h" 19 #include "components/cryptauth/remote_device_test_util.h"
19 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 20 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 54
54 struct ReceivedMessage { 55 struct ReceivedMessage {
55 ReceivedMessage(const cryptauth::RemoteDevice& remote_device, 56 ReceivedMessage(const cryptauth::RemoteDevice& remote_device,
56 const std::string& payload) 57 const std::string& payload)
57 : remote_device(remote_device), payload(payload) {} 58 : remote_device(remote_device), payload(payload) {}
58 59
59 cryptauth::RemoteDevice remote_device; 60 cryptauth::RemoteDevice remote_device;
60 std::string payload; 61 std::string payload;
61 }; 62 };
62 63
64 class MockTimerFactory : public TimerFactory {
65 public:
66 std::unique_ptr<base::Timer> CreateOneShotTimer() override {
67 return base::MakeUnique<base::MockTimer>(false /* retains_user_task */,
68 false /* is_repeating */);
69 }
70 };
71
63 class TestObserver : public BleConnectionManager::Observer { 72 class TestObserver : public BleConnectionManager::Observer {
64 public: 73 public:
65 TestObserver() {} 74 TestObserver() {}
66 75
67 // BleConnectionManager::Observer: 76 // BleConnectionManager::Observer:
68 void OnSecureChannelStatusChanged( 77 void OnSecureChannelStatusChanged(
69 const cryptauth::RemoteDevice& remote_device, 78 const cryptauth::RemoteDevice& remote_device,
70 const cryptauth::SecureChannel::Status& old_status, 79 const cryptauth::SecureChannel::Status& old_status,
71 const cryptauth::SecureChannel::Status& new_status) override { 80 const cryptauth::SecureChannel::Status& new_status) override {
72 connection_status_changes_.push_back( 81 connection_status_changes_.push_back(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 static_cast<FakeConnectionWithAddress*>(connection.get()); 231 static_cast<FakeConnectionWithAddress*>(connection.get());
223 EXPECT_EQ(expected_device_address_, fake_connection->GetDeviceAddress()); 232 EXPECT_EQ(expected_device_address_, fake_connection->GetDeviceAddress());
224 return base::WrapUnique( 233 return base::WrapUnique(
225 new FakeSecureChannel(std::move(connection), cryptauth_service)); 234 new FakeSecureChannel(std::move(connection), cryptauth_service));
226 } 235 }
227 236
228 private: 237 private:
229 std::string expected_device_address_; 238 std::string expected_device_address_;
230 }; 239 };
231 240
232 class MockTimerFactory : public BleConnectionManager::TimerFactory {
233 public:
234 std::unique_ptr<base::Timer> CreateTimer() override {
235 return base::MakeUnique<base::MockTimer>(false /* retains_user_task */,
236 false /* is_repeating */);
237 }
238 };
239
240 BleConnectionManagerTest() : test_devices_(CreateTestDevices(4)) { 241 BleConnectionManagerTest() : test_devices_(CreateTestDevices(4)) {
241 // These tests assume a maximum of two concurrent advertisers. Some of the 242 // These tests assume a maximum of two concurrent advertisers. Some of the
242 // multi-device tests would need to be re-written if this constant changes. 243 // multi-device tests would need to be re-written if this constant changes.
243 EXPECT_EQ(2, kMaxConcurrentAdvertisements); 244 EXPECT_EQ(2, kMaxConcurrentAdvertisements);
244 } 245 }
245 246
246 void SetUp() override { 247 void SetUp() override {
247 verified_status_changes_.clear(); 248 verified_status_changes_.clear();
248 verified_received_messages_.clear(); 249 verified_received_messages_.clear();
249 250
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 cryptauth::SecureChannel::Status::DISCONNECTED}, 1212 cryptauth::SecureChannel::Status::DISCONNECTED},
1212 {test_devices_[1], cryptauth::SecureChannel::Status::CONNECTING, 1213 {test_devices_[1], cryptauth::SecureChannel::Status::CONNECTING,
1213 cryptauth::SecureChannel::Status::DISCONNECTED}, 1214 cryptauth::SecureChannel::Status::DISCONNECTED},
1214 {test_devices_[2], cryptauth::SecureChannel::Status::CONNECTING, 1215 {test_devices_[2], cryptauth::SecureChannel::Status::CONNECTING,
1215 cryptauth::SecureChannel::Status::DISCONNECTED}}); 1216 cryptauth::SecureChannel::Status::DISCONNECTED}});
1216 } 1217 }
1217 1218
1218 } // namespace tether 1219 } // namespace tether
1219 1220
1220 } // namespace cryptauth 1221 } // namespace cryptauth
OLDNEW
« no previous file with comments | « chromeos/components/tether/ble_connection_manager.cc ('k') | chromeos/components/tether/fake_ble_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698