diff --git a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc index 0c7bc7e1ff072..ae4d877b4f7eb 100644 --- a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc +++ b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc @@ -217,41 +217,19 @@ void FastPairGattServiceClientImpl::NotifyWriteAccountKeyError( std::move(write_account_key_callback_).Run(error); } -void FastPairGattServiceClientImpl::GattServicesDiscovered( +void FastPairGattServiceClientImpl::GattDiscoveryCompleteForService( device::BluetoothAdapter* adapter, - device::BluetoothDevice* device) { - // The Bluetooth adapter |this| observes notifies its observers to call this - // function for all devices known to the adapter once all GATT services of - // each device are ready. One FastPairGattServiceClientImpl is created per - // device handshake, so each is associated with a device. Before considering - // |device|'s discovered services, this client must ensure that it is the same - // as the associated device. - if (device_address_ != device->GetAddress()) - return; - + device::BluetoothRemoteGattService* service) { gatt_service_discovery_timer_.Stop(); - gatt_service_ = device->GetGattService(kFastPairBluetoothUuid.value()); - if (!gatt_service_) { - QP_LOG(WARNING) << __func__ - << ": Fast Pair GATT service expected but unavailable; " - << "GATT connection will be abandoned."; - - // TODO(b/257099968): Emit a metric "expected GATT service *not* found". - - // Since the Fast Pair GATT service is not found, this connection - // is fatal; |this| will be destroyed. - // The FastPairHandshake that owns |this| and the FastPairPairer that owns - // the FastPairHandshake will be notified of the failed connection. - NotifyInitializedError(PairFailure::kGattServiceDiscovery); - return; + // Verify that the discovered service and device are the ones we care about. + if (service->GetUUID() == kFastPairBluetoothUuid && + service->GetDevice()->GetAddress() == device_address_) { + QP_LOG(INFO) << __func__ + << ": Completed discovery for Fast Pair GATT service"; + gatt_service_ = service; + FindGattCharacteristicsAndStartNotifySessions(); } - - // TODO(b/257099968): Emit a metric "expected GATT service found". - - QP_LOG(INFO) << __func__ - << ": Completed discovery for Fast Pair GATT service"; - FindGattCharacteristicsAndStartNotifySessions(); } std::vector diff --git a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.h b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.h index 500732108cdbb..5efa7ab899a0b 100644 --- a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.h +++ b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.h @@ -131,12 +131,13 @@ class FastPairGattServiceClientImpl : public FastPairGattServiceClient { void ClearCurrentState(); // BluetoothAdapter::Observer + void GattDiscoveryCompleteForService( + device::BluetoothAdapter* adapter, + device::BluetoothRemoteGattService* service) override; void GattCharacteristicValueChanged( device::BluetoothAdapter* adapter, device::BluetoothRemoteGattCharacteristic* characteristic, const std::vector& value) override; - void GattServicesDiscovered(device::BluetoothAdapter* adapter, - device::BluetoothDevice* device) override; void FindGattCharacteristicsAndStartNotifySessions(); diff --git a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_unittest.cc b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_unittest.cc index 7e21faa4473f5..3127dda08fecd 100644 --- a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_unittest.cc +++ b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_unittest.cc @@ -61,6 +61,7 @@ constexpr base::TimeDelta kConnectingTestTimeout = base::Seconds(15); // Below constants are used to construct MockBluetoothDevice for testing. constexpr char kTestBleDeviceAddress[] = "11:12:13:14:15:16"; +const char kTestServiceId[] = "service_id1"; const std::string kUUIDString1 = "keybased"; const std::string kUUIDString2 = "passkey"; const std::string kUUIDString3 = "accountkey"; @@ -109,8 +110,6 @@ class FakeBluetoothAdapter public: FakeBluetoothAdapter() = default; - using device::BluetoothAdapter::NotifyGattServicesDiscovered; - // Move-only class FakeBluetoothAdapter(const FakeBluetoothAdapter&) = delete; FakeBluetoothAdapter& operator=(const FakeBluetoothAdapter&) = delete; @@ -123,13 +122,9 @@ class FakeBluetoothAdapter return nullptr; } - device::MockBluetoothDevice* GetMockDevice(const std::string& address) { - for (const auto& it : mock_devices_) { - if (it->GetAddress() == address) { - return it.get(); - } - } - return nullptr; + void NotifyGattDiscoveryCompleteForService( + device::BluetoothRemoteGattService* service) { + device::BluetoothAdapter::NotifyGattDiscoveryComplete(service); } void NotifyGattCharacteristicValueChanged( @@ -173,15 +168,10 @@ class FakeBluetoothDevice } } - void SetHasGattConnectionError(bool has_gatt_connection_error) { + void SetError(bool has_gatt_connection_error) { has_gatt_connection_error_ = has_gatt_connection_error; } - device::BluetoothRemoteGattService* GetGattService( - const std::string& identifier) const override { - return GetMockService(identifier); - } - // Move-only class FakeBluetoothDevice(const FakeBluetoothDevice&) = delete; FakeBluetoothDevice& operator=(const FakeBluetoothDevice&) = delete; @@ -296,72 +286,58 @@ class FastPairGattServiceClientTest : public testing::Test { void SetUp() override { fast_pair_data_encryptor_->public_key(kPublicKey); } void SuccessfulGattConnectionSetUp() { - FastPairServiceSetup(/*has_gatt_connection_error=*/false); + adapter_ = base::MakeRefCounted(); + device_ = CreateTestBluetoothDevice( + adapter_.get(), ash::quick_pair::kFastPairBluetoothUuid); + adapter_->AddMockDevice(std::move(device_)); + gatt_service_client_ = FastPairGattServiceClientImpl::Factory::Create( + adapter_->GetDevice(kTestBleDeviceAddress), adapter_.get(), + base::BindRepeating(&::ash::quick_pair::FastPairGattServiceClientTest:: + InitializedTestCallback, + weak_ptr_factory_.GetWeakPtr())); } void FailedGattConnectionSetUp() { - FastPairServiceSetup(/*has_gatt_connection_error=*/true); + adapter_ = base::MakeRefCounted(); + device_ = CreateTestBluetoothDevice( + adapter_.get(), ash::quick_pair::kFastPairBluetoothUuid); + device_->SetError(true); + adapter_->AddMockDevice(std::move(device_)); + gatt_service_client_ = FastPairGattServiceClientImpl::Factory::Create( + adapter_->GetDevice(kTestBleDeviceAddress), adapter_.get(), + base::BindRepeating(&::ash::quick_pair::FastPairGattServiceClientTest:: + InitializedTestCallback, + weak_ptr_factory_.GetWeakPtr())); } void NonFastPairServiceDataSetUp() { adapter_ = base::MakeRefCounted(); - adapter_->AddMockDevice( - CreateTestBluetoothDevice(adapter_.get(), kNonFastPairUuid)); - device_ = static_cast( - adapter_->GetMockDevice(kTestBleDeviceAddress)); - fast_pair_gatt_service_client_ = - FastPairGattServiceClientImpl::Factory::Create( - device_, adapter_.get(), - base::BindRepeating( - &::ash::quick_pair::FastPairGattServiceClientTest:: - InitializedTestCallback, - weak_ptr_factory_.GetWeakPtr())); - } - - // |fast_pair_gatt_service_client_| is initialized such that it is observing - // |adapter_| for changes concerning |device_|. |adapter_|, |device_|, and - // |fast_pair_gatt_service_| are initialized assuming that - // |fast_pair_gatt_service_| is a Fast Pair service. |adapter_| and |device_| - // require unique pointers to |device_| and |fast_pair_gatt_service_|, - // respectively, so |device_| and |fast_pair_gatt_service_| are raw pointers - // to these objects. - void FastPairServiceSetup(bool has_gatt_connection_error) { - adapter_ = base::MakeRefCounted(); - adapter_->AddMockDevice(CreateTestBluetoothDevice( - adapter_.get(), ash::quick_pair::kFastPairBluetoothUuid)); - device_ = static_cast( - adapter_->GetMockDevice(kTestBleDeviceAddress)); - device_->SetHasGattConnectionError(has_gatt_connection_error); - device_->AddMockService( + device_ = CreateTestBluetoothDevice(adapter_.get(), kNonFastPairUuid); + adapter_->AddMockDevice(std::move(device_)); + gatt_service_client_ = FastPairGattServiceClientImpl::Factory::Create( + adapter_->GetDevice(kTestBleDeviceAddress), adapter_.get(), + base::BindRepeating(&::ash::quick_pair::FastPairGattServiceClientTest:: + InitializedTestCallback, + weak_ptr_factory_.GetWeakPtr())); + } + + void NotifyGattDiscoveryCompleteForService() { + auto gatt_service = std::make_unique>( - device_, ash::quick_pair::kFastPairBluetoothUuid.value(), - ash::quick_pair::kFastPairBluetoothUuid, - /*is_primary=*/true)); - fast_pair_gatt_service_ = - static_cast*>( - device_->GetMockService( - ash::quick_pair::kFastPairBluetoothUuid.value())); - ON_CALL(*(fast_pair_gatt_service_), GetDevice) + CreateTestBluetoothDevice(adapter_.get(), + ash::quick_pair::kFastPairBluetoothUuid) + .get(), + kTestServiceId, ash::quick_pair::kFastPairBluetoothUuid, + /*is_primary=*/true); + gatt_service_ = std::move(gatt_service); + ON_CALL(*(gatt_service_.get()), GetDevice) .WillByDefault( testing::Return(adapter_->GetDevice(kTestBleDeviceAddress))); - fast_pair_gatt_service_client_ = - FastPairGattServiceClientImpl::Factory::Create( - device_, adapter_.get(), - base::BindRepeating( - &::ash::quick_pair::FastPairGattServiceClientTest:: - InitializedTestCallback, - weak_ptr_factory_.GetWeakPtr())); - } - - // Creates FakeBluetoothGattCharacteristic unique pointers to pass to - // |fast_pair_gatt_service_| based on the characteristic-related booleans set - // in each unit test. - void CharacteristicSetup() { if (!keybased_char_error_) { fake_key_based_characteristic_ = std::make_unique( - fast_pair_gatt_service_, kUUIDString1, - kKeyBasedCharacteristicUuid1, kProperties, kPermissions); + gatt_service_.get(), kUUIDString1, kKeyBasedCharacteristicUuid1, + kProperties, kPermissions); if (keybased_notify_session_error_) fake_key_based_characteristic_->SetNotifySessionError(true); @@ -382,15 +358,15 @@ class FastPairGattServiceClientTest : public testing::Test { temp_fake_key_based_characteristic_ = fake_key_based_characteristic_.get(); - fast_pair_gatt_service_->AddMockCharacteristic( + gatt_service_->AddMockCharacteristic( std::move(fake_key_based_characteristic_)); } if (!passkey_char_error_) { fake_passkey_characteristic_ = std::make_unique( - fast_pair_gatt_service_, kUUIDString2, - kPasskeyCharacteristicUuid1, kProperties, kPermissions); + gatt_service_.get(), kUUIDString2, kPasskeyCharacteristicUuid1, + kProperties, kPermissions); if (passkey_notify_session_error_) fake_passkey_characteristic_->SetNotifySessionError(true); @@ -410,33 +386,27 @@ class FastPairGattServiceClientTest : public testing::Test { temp_passkey_based_characteristic_ = fake_passkey_characteristic_.get(); - fast_pair_gatt_service_->AddMockCharacteristic( + gatt_service_->AddMockCharacteristic( std::move(fake_passkey_characteristic_)); } auto fake_account_key_characteristic = std::make_unique( - fast_pair_gatt_service_, kUUIDString3, - kAccountKeyCharacteristicUuid1, kProperties, kPermissions); + gatt_service_.get(), kUUIDString3, kAccountKeyCharacteristicUuid1, + kProperties, kPermissions); if (account_key_write_error_) { fake_account_key_characteristic->SetWriteError(true); } - fast_pair_gatt_service_->AddMockCharacteristic( + gatt_service_->AddMockCharacteristic( std::move(fake_account_key_characteristic)); - } - - // Wrapper to call FakeBluetoothAdapter::GattServicesDiscovered(). - void DiscoverGattServices() { - adapter_->NotifyGattServicesDiscovered(device_); + adapter_->NotifyGattDiscoveryCompleteForService(gatt_service_.get()); } bool ServiceIsSet() { - if (!fast_pair_gatt_service_client_->gatt_service()) + if (!gatt_service_client_->gatt_service()) return false; - - return fast_pair_gatt_service_client_->gatt_service() == - fast_pair_gatt_service_; + return gatt_service_client_->gatt_service() == gatt_service_.get(); } void SetPasskeyCharacteristicError(bool passkey_char_error) { @@ -499,7 +469,7 @@ class FastPairGattServiceClientTest : public testing::Test { } void WriteRequestToKeyBased() { - fast_pair_gatt_service_client_->WriteRequestAsync( + gatt_service_client_->WriteRequestAsync( kMessageType, kFlags, kProviderAddress, kSeekersAddress, fast_pair_data_encryptor_.get(), base::BindRepeating(&::ash::quick_pair::FastPairGattServiceClientTest:: @@ -508,7 +478,7 @@ class FastPairGattServiceClientTest : public testing::Test { } void WriteRequestToPasskey() { - fast_pair_gatt_service_client_->WritePasskeyAsync( + gatt_service_client_->WritePasskeyAsync( kSeekerPasskey, kPasskey, fast_pair_data_encryptor_.get(), base::BindRepeating(&::ash::quick_pair::FastPairGattServiceClientTest:: WriteTestCallback, @@ -516,7 +486,7 @@ class FastPairGattServiceClientTest : public testing::Test { } void WriteAccountKey() { - fast_pair_gatt_service_client_->WriteAccountKey( + gatt_service_client_->WriteAccountKey( kAccountKey, fast_pair_data_encryptor_.get(), base::BindRepeating(&::ash::quick_pair::FastPairGattServiceClientTest:: AccountKeyCallback, @@ -547,7 +517,7 @@ class FastPairGattServiceClientTest : public testing::Test { base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment::TimeSource::MOCK_TIME}; base::HistogramTester histogram_tester_; - std::unique_ptr fast_pair_gatt_service_client_; + std::unique_ptr gatt_service_client_; private: // We need temporary pointers to use for write/ready requests because we @@ -571,18 +541,14 @@ class FastPairGattServiceClientTest : public testing::Test { absl::optional initalized_failure_; absl::optional write_failure_; scoped_refptr adapter_; - - // A raw ptr that |adapter_| has a unique ptr to. - FakeBluetoothDevice* device_ = nullptr; + std::unique_ptr device_; std::unique_ptr fake_key_based_characteristic_; std::unique_ptr fast_pair_data_encryptor_ = std::make_unique(); std::unique_ptr fake_passkey_characteristic_; - - // A raw ptr that |device_| has a unique ptr to. - testing::NiceMock* fast_pair_gatt_service_ = - nullptr; + std::unique_ptr> + gatt_service_; base::WeakPtrFactory weak_ptr_factory_{this}; }; @@ -595,8 +561,7 @@ TEST_F(FastPairGattServiceClientTest, GattServiceDiscoveryTimeout) { histogram_tester().ExpectTotalCount(kNotifyPasskeyCharacteristicTime, 0); SuccessfulGattConnectionSetUp(); FastForwardTimeByConnetingTimeout(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kGattServiceDiscoveryTimeout); EXPECT_FALSE(ServiceIsSet()); @@ -638,9 +603,8 @@ TEST_F(FastPairGattServiceClientTest, GattConnectionSuccess) { histogram_tester().ExpectTotalCount(kWritePasskeyCharacteristicGattError, 0); histogram_tester().ExpectTotalCount(kNotifyPasskeyCharacteristicTime, 0); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); - EXPECT_TRUE(fast_pair_gatt_service_client_->IsConnected()); + NotifyGattDiscoveryCompleteForService(); + EXPECT_TRUE(gatt_service_client_->IsConnected()); histogram_tester().ExpectTotalCount(kTotalGattConnectionTime, 1); histogram_tester().ExpectTotalCount(kGattConnectionResult, 1); histogram_tester().ExpectTotalCount(kGattConnectionErrorMetric, 0); @@ -660,8 +624,7 @@ TEST_F(FastPairGattServiceClientTest, FailedKeyBasedCharacteristics) { histogram_tester().ExpectTotalCount(kNotifyKeyBasedCharacteristicTime, 0); SetKeybasedCharacteristicError(true); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kKeyBasedPairingCharacteristicDiscovery); EXPECT_FALSE(ServiceIsSet()); @@ -671,8 +634,7 @@ TEST_F(FastPairGattServiceClientTest, FailedKeyBasedCharacteristics) { TEST_F(FastPairGattServiceClientTest, FailedPasskeyCharacteristics) { SetPasskeyCharacteristicError(true); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kPasskeyCharacteristicDiscovery); EXPECT_FALSE(ServiceIsSet()); @@ -683,8 +645,7 @@ TEST_F(FastPairGattServiceClientTest, SuccessfulCharacteristicsStartNotify) { SetKeybasedCharacteristicError(false); SetPasskeyCharacteristicError(false); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); histogram_tester().ExpectTotalCount(kNotifyKeyBasedCharacteristicTime, 0); @@ -694,8 +655,7 @@ TEST_F(FastPairGattServiceClientTest, StartNotifyPasskeyFailure) { histogram_tester().ExpectTotalCount(kNotifyPasskeyCharacteristicTime, 0); SuccessfulGattConnectionSetUp(); SetPasskeyNotifySessionError(true); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kPasskeyCharacteristicNotifySession); EXPECT_FALSE(ServiceIsSet()); @@ -706,8 +666,7 @@ TEST_F(FastPairGattServiceClientTest, StartNotifyKeybasedFailure) { histogram_tester().ExpectTotalCount(kNotifyKeyBasedCharacteristicTime, 0); SuccessfulGattConnectionSetUp(); SetKeybasedNotifySessionError(true); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kKeyBasedPairingCharacteristicNotifySession); EXPECT_FALSE(ServiceIsSet()); @@ -718,8 +677,7 @@ TEST_F(FastPairGattServiceClientTest, PasskeyStartNotifyTimeout) { histogram_tester().ExpectTotalCount(kNotifyPasskeyCharacteristicTime, 0); SetPasskeyNotifySessionTimeout(true); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kPasskeyCharacteristicNotifySessionTimeout); EXPECT_FALSE(ServiceIsSet()); @@ -730,8 +688,7 @@ TEST_F(FastPairGattServiceClientTest, KeyBasedStartNotifyTimeout) { histogram_tester().ExpectTotalCount(kNotifyKeyBasedCharacteristicTime, 0); SetKeybasedNotifySessionTimeout(true); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kKeyBasedPairingCharacteristicNotifySessionTimeout); EXPECT_FALSE(ServiceIsSet()); @@ -743,8 +700,7 @@ TEST_F(FastPairGattServiceClientTest, MultipleNotifyTimeout) { SetKeybasedNotifySessionTimeout(true); SetPasskeyNotifySessionTimeout(true); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kKeyBasedPairingCharacteristicNotifySessionTimeout); EXPECT_FALSE(ServiceIsSet()); @@ -755,8 +711,7 @@ TEST_F(FastPairGattServiceClientTest, WriteKeyBasedRequest) { histogram_tester().ExpectTotalCount(kWriteKeyBasedCharacteristicGattError, 0); histogram_tester().ExpectTotalCount(kNotifyKeyBasedCharacteristicTime, 0); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToKeyBased(); @@ -770,8 +725,7 @@ TEST_F(FastPairGattServiceClientTest, WriteKeyBasedRequestError) { histogram_tester().ExpectTotalCount(kWriteKeyBasedCharacteristicGattError, 0); SetKeyBasedWriteError(); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToKeyBased(); @@ -784,8 +738,7 @@ TEST_F(FastPairGattServiceClientTest, WriteKeyBasedRequestError) { TEST_F(FastPairGattServiceClientTest, WriteKeyBasedRequestTimeout) { SetWriteRequestTimeout(); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToKeyBased(); @@ -798,8 +751,7 @@ TEST_F(FastPairGattServiceClientTest, WritePasskeyRequest) { histogram_tester().ExpectTotalCount(kWritePasskeyCharacteristicGattError, 0); histogram_tester().ExpectTotalCount(kNotifyPasskeyCharacteristicTime, 0); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToPasskey(); @@ -813,8 +765,7 @@ TEST_F(FastPairGattServiceClientTest, WritePasskeyRequestError) { histogram_tester().ExpectTotalCount(kWritePasskeyCharacteristicGattError, 0); SetPasskeyWriteError(); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToPasskey(); @@ -828,8 +779,7 @@ TEST_F(FastPairGattServiceClientTest, WritePasskeyRequestTimeout) { histogram_tester().ExpectTotalCount(kWritePasskeyCharacteristicGattError, 0); SetWritePasskeyTimeout(); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToPasskey(); @@ -843,8 +793,7 @@ TEST_F(FastPairGattServiceClientTest, WriteAccountKey) { 0); histogram_tester().ExpectTotalCount(kWriteAccountKeyTimeMetric, 0); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToKeyBased(); @@ -863,8 +812,7 @@ TEST_F(FastPairGattServiceClientTest, WriteAccountKeyFailure) { histogram_tester().ExpectTotalCount(kWriteAccountKeyTimeMetric, 0); SetAccountKeyCharacteristicWriteError(true); SuccessfulGattConnectionSetUp(); - CharacteristicSetup(); - DiscoverGattServices(); + NotifyGattDiscoveryCompleteForService(); EXPECT_EQ(GetInitializedCallbackResult(), absl::nullopt); EXPECT_TRUE(ServiceIsSet()); WriteRequestToKeyBased(); @@ -877,15 +825,5 @@ TEST_F(FastPairGattServiceClientTest, WriteAccountKeyFailure) { histogram_tester().ExpectTotalCount(kWriteAccountKeyTimeMetric, 0); } -TEST_F(FastPairGattServiceClientTest, FastPairGattServiceDiscoveryFailure) { - // The service associated with |device_| is not the Fast Pair service; - // The FastPairGattServiceClient will not be able to find it and will fail - // with the PairFailure::kGattServiceDiscovery error. - NonFastPairServiceDataSetUp(); - DiscoverGattServices(); - EXPECT_EQ(GetInitializedCallbackResult(), PairFailure::kGattServiceDiscovery); - EXPECT_FALSE(ServiceIsSet()); -} - } // namespace quick_pair } // namespace ash