| 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_advertiser.h" | 5 #include "chromeos/components/tether/ble_advertiser.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chromeos/components/tether/ble_constants.h" | 8 #include "chromeos/components/tether/ble_constants.h" |
| 9 #include "chromeos/components/tether/mock_local_device_data_provider.h" | |
| 10 #include "components/cryptauth/mock_foreground_eid_generator.h" | 9 #include "components/cryptauth/mock_foreground_eid_generator.h" |
| 10 #include "components/cryptauth/mock_local_device_data_provider.h" |
| 11 #include "components/cryptauth/mock_remote_beacon_seed_fetcher.h" | 11 #include "components/cryptauth/mock_remote_beacon_seed_fetcher.h" |
| 12 #include "components/cryptauth/proto/cryptauth_api.pb.h" | 12 #include "components/cryptauth/proto/cryptauth_api.pb.h" |
| 13 #include "components/cryptauth/remote_device_test_util.h" | 13 #include "components/cryptauth/remote_device_test_util.h" |
| 14 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 14 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 15 #include "device/bluetooth/test/mock_bluetooth_advertisement.h" | 15 #include "device/bluetooth/test/mock_bluetooth_advertisement.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using testing::Invoke; | 18 using testing::Invoke; |
| 19 using testing::Return; | 19 using testing::Return; |
| 20 using testing::StrictMock; | 20 using testing::StrictMock; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 CreateFakeBeaconSeedsForDevice(fake_devices_[1]); | 141 CreateFakeBeaconSeedsForDevice(fake_devices_[1]); |
| 142 std::vector<cryptauth::BeaconSeed> device_2_beacon_seeds = | 142 std::vector<cryptauth::BeaconSeed> device_2_beacon_seeds = |
| 143 CreateFakeBeaconSeedsForDevice(fake_devices_[2]); | 143 CreateFakeBeaconSeedsForDevice(fake_devices_[2]); |
| 144 mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[0], | 144 mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[0], |
| 145 &device_0_beacon_seeds); | 145 &device_0_beacon_seeds); |
| 146 mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[1], | 146 mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[1], |
| 147 &device_1_beacon_seeds); | 147 &device_1_beacon_seeds); |
| 148 mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[2], | 148 mock_seed_fetcher_->SetSeedsForDevice(fake_devices_[2], |
| 149 &device_2_beacon_seeds); | 149 &device_2_beacon_seeds); |
| 150 | 150 |
| 151 mock_local_data_provider_ = base::MakeUnique<MockLocalDeviceDataProvider>(); | 151 mock_local_data_provider_ = |
| 152 base::MakeUnique<cryptauth::MockLocalDeviceDataProvider>(); |
| 152 mock_local_data_provider_->SetPublicKey( | 153 mock_local_data_provider_->SetPublicKey( |
| 153 base::MakeUnique<std::string>(kFakePublicKey)); | 154 base::MakeUnique<std::string>(kFakePublicKey)); |
| 154 | 155 |
| 155 ble_advertiser_ = base::WrapUnique(new BleAdvertiser( | 156 ble_advertiser_ = base::WrapUnique(new BleAdvertiser( |
| 156 mock_adapter_, std::move(eid_generator), mock_seed_fetcher_.get(), | 157 mock_adapter_, std::move(eid_generator), mock_seed_fetcher_.get(), |
| 157 mock_local_data_provider_.get())); | 158 mock_local_data_provider_.get())); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void TearDown() override { | 161 void TearDown() override { |
| 161 // Delete the advertiser to ensure that cleanup happens properly. | 162 // Delete the advertiser to ensure that cleanup happens properly. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 individual_advertisement->AdvertisementReleased( | 227 individual_advertisement->AdvertisementReleased( |
| 227 individual_advertisement->advertisement_.get()); | 228 individual_advertisement->advertisement_.get()); |
| 228 } | 229 } |
| 229 | 230 |
| 230 std::unique_ptr<BleAdvertiser> ble_advertiser_; | 231 std::unique_ptr<BleAdvertiser> ble_advertiser_; |
| 231 | 232 |
| 232 scoped_refptr<StrictMock<MockBluetoothAdapterWithAdvertisements>> | 233 scoped_refptr<StrictMock<MockBluetoothAdapterWithAdvertisements>> |
| 233 mock_adapter_; | 234 mock_adapter_; |
| 234 cryptauth::MockForegroundEidGenerator* mock_eid_generator_; | 235 cryptauth::MockForegroundEidGenerator* mock_eid_generator_; |
| 235 std::unique_ptr<cryptauth::MockRemoteBeaconSeedFetcher> mock_seed_fetcher_; | 236 std::unique_ptr<cryptauth::MockRemoteBeaconSeedFetcher> mock_seed_fetcher_; |
| 236 std::unique_ptr<MockLocalDeviceDataProvider> mock_local_data_provider_; | 237 std::unique_ptr<cryptauth::MockLocalDeviceDataProvider> |
| 238 mock_local_data_provider_; |
| 237 | 239 |
| 238 std::vector<scoped_refptr<RegisterAdvertisementArgs>> | 240 std::vector<scoped_refptr<RegisterAdvertisementArgs>> |
| 239 register_advertisement_args_; | 241 register_advertisement_args_; |
| 240 std::vector<BleAdvertiser::IndividualAdvertisement*> | 242 std::vector<BleAdvertiser::IndividualAdvertisement*> |
| 241 individual_advertisements_; | 243 individual_advertisements_; |
| 242 | 244 |
| 243 const std::vector<cryptauth::RemoteDevice> fake_devices_; | 245 const std::vector<cryptauth::RemoteDevice> fake_devices_; |
| 244 const std::vector<cryptauth::DataWithTimestamp> fake_advertisements_; | 246 const std::vector<cryptauth::DataWithTimestamp> fake_advertisements_; |
| 245 | 247 |
| 246 private: | 248 private: |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 VerifyAdvertisementHasStarted(individual_advertisements_[0]); | 468 VerifyAdvertisementHasStarted(individual_advertisements_[0]); |
| 467 | 469 |
| 468 // Now, unregister. | 470 // Now, unregister. |
| 469 EXPECT_TRUE(ble_advertiser_->StopAdvertisingToDevice(fake_devices_[0])); | 471 EXPECT_TRUE(ble_advertiser_->StopAdvertisingToDevice(fake_devices_[0])); |
| 470 EXPECT_FALSE(individual_advertisements_.size()); | 472 EXPECT_FALSE(individual_advertisements_.size()); |
| 471 } | 473 } |
| 472 | 474 |
| 473 } // namespace tether | 475 } // namespace tether |
| 474 | 476 |
| 475 } // namespace chromeos | 477 } // namespace chromeos |
| OLD | NEW |