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

Unified Diff: chromeos/components/tether/ble_connection_manager_unittest.cc

Issue 2804123002: BleConnectionManager: Check when receiving BLE advertisements if a SecureChannel already exists. No… (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/components/tether/ble_connection_manager_unittest.cc
diff --git a/chromeos/components/tether/ble_connection_manager_unittest.cc b/chromeos/components/tether/ble_connection_manager_unittest.cc
index 6ce9b41a3ec45201bbea31425c6c59c92372823b..4b5b7dd08c7bd2af197486e5123e36336aa98fed 100644
--- a/chromeos/components/tether/ble_connection_manager_unittest.cc
+++ b/chromeos/components/tether/ble_connection_manager_unittest.cc
@@ -685,6 +685,60 @@ TEST_F(BleConnectionManagerTest, TestSuccessfulConnection_SendAndReceive) {
VerifyDeviceNotRegistered(test_devices_[0]);
}
+// 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.
+TEST_F(BleConnectionManagerTest,
+ TestSuccessfulConnection_SendAndReceive_MultipleAdvertisementsReceived) {
+ EXPECT_CALL(*mock_ble_scanner_,
+ RegisterScanFilterForDevice(test_devices_[0]));
+ EXPECT_CALL(*mock_ble_advertiser_,
+ StartAdvertisingToDevice(test_devices_[0]));
+ EXPECT_CALL(*mock_ble_scanner_,
+ UnregisterScanFilterForDevice(test_devices_[0]));
+ EXPECT_CALL(*mock_ble_advertiser_, StopAdvertisingToDevice(test_devices_[0]));
+
+ manager_->RegisterRemoteDevice(test_devices_[0],
+ MessageType::TETHER_AVAILABILITY_REQUEST);
+ VerifyAdvertisingTimeoutSet(test_devices_[0]);
+ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
+ {test_devices_[0], cryptauth::SecureChannel::Status::DISCONNECTED,
+ cryptauth::SecureChannel::Status::CONNECTING}});
+
+ fake_secure_channel_factory_->SetExpectedDeviceAddress(
+ std::string(kBluetoothAddress1));
+
+ // Simulate multiple advertisements being received:
+ mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1),
+ test_devices_[0]);
+ mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1),
+ test_devices_[0]);
+ mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1),
+ test_devices_[0]);
+
+ FakeSecureChannel* channel = GetChannelForDevice(test_devices_[0]);
+ AuthenticateChannel(test_devices_[0]);
+
+ 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.
+ VerifyLastMessageSent(channel, "request1", 1);
+
+ channel->ReceiveMessage(std::string(kTetherFeature), "response1");
+ VerifyReceivedMessages(
+ std::vector<ReceivedMessage>{{test_devices_[0], "response1"}});
+
+ manager_->SendMessage(test_devices_[0], "request2");
+ VerifyLastMessageSent(channel, "request2", 2);
+
+ channel->ReceiveMessage(std::string(kTetherFeature), "response2");
+ VerifyReceivedMessages(
+ std::vector<ReceivedMessage>{{test_devices_[0], "response2"}});
+
+ manager_->UnregisterRemoteDevice(test_devices_[0],
+ MessageType::TETHER_AVAILABILITY_REQUEST);
+ VerifyConnectionStateChanges(std::vector<SecureChannelStatusChange>{
+ {test_devices_[0], cryptauth::SecureChannel::Status::AUTHENTICATED,
+ cryptauth::SecureChannel::Status::DISCONNECTED}});
+ VerifyDeviceNotRegistered(test_devices_[0]);
+}
+
TEST_F(BleConnectionManagerTest,
TestSuccessfulConnection_MultipleConnectionReasons) {
EXPECT_CALL(*mock_ble_scanner_,

Powered by Google App Engine
This is Rietveld 408576698