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

Side by Side 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: khorimoto@ comments. 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 unified diff | Download patch
« no previous file with comments | « chromeos/components/tether/ble_connection_manager.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 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
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.
689 TEST_F(BleConnectionManagerTest,
690 TestSuccessfulConnection_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 FakeSecureChannel* channel = GetChannelForDevice(test_devices_[0]);
713
714 mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1),
715 test_devices_[0]);
716 // Verify that a new channel has not been created:
717 EXPECT_EQ(channel, GetChannelForDevice(test_devices_[0]));
718
719 mock_ble_scanner_->SimulateScanResults(std::string(kBluetoothAddress1),
720 test_devices_[0]);
721 // Verify that a new channel has not been created:
722 EXPECT_EQ(channel, GetChannelForDevice(test_devices_[0]));
723 }
724
688 TEST_F(BleConnectionManagerTest, 725 TEST_F(BleConnectionManagerTest,
689 TestSuccessfulConnection_MultipleConnectionReasons) { 726 TestSuccessfulConnection_MultipleConnectionReasons) {
690 EXPECT_CALL(*mock_ble_scanner_, 727 EXPECT_CALL(*mock_ble_scanner_,
691 RegisterScanFilterForDevice(test_devices_[0])); 728 RegisterScanFilterForDevice(test_devices_[0]));
692 EXPECT_CALL(*mock_ble_advertiser_, 729 EXPECT_CALL(*mock_ble_advertiser_,
693 StartAdvertisingToDevice(test_devices_[0])); 730 StartAdvertisingToDevice(test_devices_[0]));
694 EXPECT_CALL(*mock_ble_scanner_, 731 EXPECT_CALL(*mock_ble_scanner_,
695 UnregisterScanFilterForDevice(test_devices_[0])); 732 UnregisterScanFilterForDevice(test_devices_[0]));
696 EXPECT_CALL(*mock_ble_advertiser_, StopAdvertisingToDevice(test_devices_[0])); 733 EXPECT_CALL(*mock_ble_advertiser_, StopAdvertisingToDevice(test_devices_[0]));
697 734
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 cryptauth::SecureChannel::Status::DISCONNECTED}, 1231 cryptauth::SecureChannel::Status::DISCONNECTED},
1195 {test_devices_[1], cryptauth::SecureChannel::Status::CONNECTING, 1232 {test_devices_[1], cryptauth::SecureChannel::Status::CONNECTING,
1196 cryptauth::SecureChannel::Status::DISCONNECTED}, 1233 cryptauth::SecureChannel::Status::DISCONNECTED},
1197 {test_devices_[2], cryptauth::SecureChannel::Status::CONNECTING, 1234 {test_devices_[2], cryptauth::SecureChannel::Status::CONNECTING,
1198 cryptauth::SecureChannel::Status::DISCONNECTED}}); 1235 cryptauth::SecureChannel::Status::DISCONNECTED}});
1199 } 1236 }
1200 1237
1201 } // namespace tether 1238 } // namespace tether
1202 1239
1203 } // namespace cryptauth 1240 } // namespace cryptauth
OLDNEW
« no previous file with comments | « chromeos/components/tether/ble_connection_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698