Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 std::vector<ReceivedMessage>{{test_devices_[0], "response2"}}); | 678 std::vector<ReceivedMessage>{{test_devices_[0], "response2"}}); |
| 679 | 679 |
| 680 manager_->UnregisterRemoteDevice(test_devices_[0], | 680 manager_->UnregisterRemoteDevice(test_devices_[0], |
| 681 MessageType::TETHER_AVAILABILITY_REQUEST); | 681 MessageType::TETHER_AVAILABILITY_REQUEST); |
| 682 VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ | 682 VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ |
| 683 {test_devices_[0], cryptauth::SecureChannel::Status::AUTHENTICATED, | 683 {test_devices_[0], cryptauth::SecureChannel::Status::AUTHENTICATED, |
| 684 cryptauth::SecureChannel::Status::DISCONNECTED}}); | 684 cryptauth::SecureChannel::Status::DISCONNECTED}}); |
| 685 VerifyDeviceNotRegistered(test_devices_[0]); | 685 VerifyDeviceNotRegistered(test_devices_[0]); |
| 686 } | 686 } |
| 687 | 687 |
| 688 // Test for fix to crbug.com/706640. This test will crash without the fix. | |
|
Kyle Horimoto
2017/04/06 21:17:30
In addition to just testing that it doesn't crash,
Ryan Hansberry
2017/04/06 22:14:59
Good call, done.
| |
| 689 TEST_F(BleConnectionManagerTest, | |
| 690 TestSuccessfulConnection_SendAndReceive_MultipleAdvertisementsReceived) { | |
| 691 EXPECT_CALL(*mock_ble_scanner_, | |
| 692 RegisterScanFilterForDevice(test_devices_[0])); | |
| 693 EXPECT_CALL(*mock_ble_advertiser_, | |
| 694 StartAdvertisingToDevice(test_devices_[0])); | |
| 695 EXPECT_CALL(*mock_ble_scanner_, | |
| 696 UnregisterScanFilterForDevice(test_devices_[0])); | |
| 697 EXPECT_CALL(*mock_ble_advertiser_, StopAdvertisingToDevice(test_devices_[0])); | |
| 698 | |
| 699 manager_->RegisterRemoteDevice(test_devices_[0], | |
| 700 MessageType::TETHER_AVAILABILITY_REQUEST); | |
| 701 VerifyAdvertisingTimeoutSet(test_devices_[0]); | |
| 702 VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ | |
| 703 {test_devices_[0], cryptauth::SecureChannel::Status::DISCONNECTED, | |
| 704 cryptauth::SecureChannel::Status::CONNECTING}}); | |
| 705 | |
| 706 fake_secure_channel_factory_->SetExpectedDeviceAddress( | |
| 707 std::string(kBluetoothAddress1)); | |
| 708 | |
| 709 // Simulate multiple advertisements being received: | |
| 710 mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1), | |
| 711 test_devices_[0]); | |
| 712 mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1), | |
| 713 test_devices_[0]); | |
| 714 mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1), | |
| 715 test_devices_[0]); | |
| 716 | |
| 717 FakeSecureChannel* channel = GetChannelForDevice(test_devices_[0]); | |
| 718 AuthenticateChannel(test_devices_[0]); | |
| 719 | |
| 720 manager_->SendMessage(test_devices_[0], "request1"); | |
|
Kyle Horimoto
2017/04/06 21:17:30
Do we need the stuff from here onwards? Seems unre
Ryan Hansberry
2017/04/06 22:14:59
Nope, no need for it. Removed.
| |
| 721 VerifyLastMessageSent(channel, "request1", 1); | |
| 722 | |
| 723 channel->ReceiveMessage(std::string(kTetherFeature), "response1"); | |
| 724 VerifyReceivedMessages( | |
| 725 std::vector<ReceivedMessage>{{test_devices_[0], "response1"}}); | |
| 726 | |
| 727 manager_->SendMessage(test_devices_[0], "request2"); | |
| 728 VerifyLastMessageSent(channel, "request2", 2); | |
| 729 | |
| 730 channel->ReceiveMessage(std::string(kTetherFeature), "response2"); | |
| 731 VerifyReceivedMessages( | |
| 732 std::vector<ReceivedMessage>{{test_devices_[0], "response2"}}); | |
| 733 | |
| 734 manager_->UnregisterRemoteDevice(test_devices_[0], | |
| 735 MessageType::TETHER_AVAILABILITY_REQUEST); | |
| 736 VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{ | |
| 737 {test_devices_[0], cryptauth::SecureChannel::Status::AUTHENTICATED, | |
| 738 cryptauth::SecureChannel::Status::DISCONNECTED}}); | |
| 739 VerifyDeviceNotRegistered(test_devices_[0]); | |
| 740 } | |
| 741 | |
| 688 TEST_F(BleConnectionManagerTest, | 742 TEST_F(BleConnectionManagerTest, |
| 689 TestSuccessfulConnection_MultipleConnectionReasons) { | 743 TestSuccessfulConnection_MultipleConnectionReasons) { |
| 690 EXPECT_CALL(*mock_ble_scanner_, | 744 EXPECT_CALL(*mock_ble_scanner_, |
| 691 RegisterScanFilterForDevice(test_devices_[0])); | 745 RegisterScanFilterForDevice(test_devices_[0])); |
| 692 EXPECT_CALL(*mock_ble_advertiser_, | 746 EXPECT_CALL(*mock_ble_advertiser_, |
| 693 StartAdvertisingToDevice(test_devices_[0])); | 747 StartAdvertisingToDevice(test_devices_[0])); |
| 694 EXPECT_CALL(*mock_ble_scanner_, | 748 EXPECT_CALL(*mock_ble_scanner_, |
| 695 UnregisterScanFilterForDevice(test_devices_[0])); | 749 UnregisterScanFilterForDevice(test_devices_[0])); |
| 696 EXPECT_CALL(*mock_ble_advertiser_, StopAdvertisingToDevice(test_devices_[0])); | 750 EXPECT_CALL(*mock_ble_advertiser_, StopAdvertisingToDevice(test_devices_[0])); |
| 697 | 751 |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 cryptauth::SecureChannel::Status::DISCONNECTED}, | 1248 cryptauth::SecureChannel::Status::DISCONNECTED}, |
| 1195 {test_devices_[1], cryptauth::SecureChannel::Status::CONNECTING, | 1249 {test_devices_[1], cryptauth::SecureChannel::Status::CONNECTING, |
| 1196 cryptauth::SecureChannel::Status::DISCONNECTED}, | 1250 cryptauth::SecureChannel::Status::DISCONNECTED}, |
| 1197 {test_devices_[2], cryptauth::SecureChannel::Status::CONNECTING, | 1251 {test_devices_[2], cryptauth::SecureChannel::Status::CONNECTING, |
| 1198 cryptauth::SecureChannel::Status::DISCONNECTED}}); | 1252 cryptauth::SecureChannel::Status::DISCONNECTED}}); |
| 1199 } | 1253 } |
| 1200 | 1254 |
| 1201 } // namespace tether | 1255 } // namespace tether |
| 1202 | 1256 |
| 1203 } // namespace cryptauth | 1257 } // namespace cryptauth |
| OLD | NEW |