const char kTestCharacteristicId0[] = "char_id0";
const char kTestCharacteristicUuid0[] = "1211";
const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties0 =
- BluetoothGattCharacteristic::kPropertyBroadcast |
- BluetoothGattCharacteristic::kPropertyRead |
- BluetoothGattCharacteristic::kPropertyWriteWithoutResponse |
- BluetoothGattCharacteristic::kPropertyIndicate;
+ BluetoothGattCharacteristic::PROPERTY_BROADCAST |
+ BluetoothGattCharacteristic::PROPERTY_READ |
+ BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE |
+ BluetoothGattCharacteristic::PROPERTY_INDICATE;
const uint8 kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04, 0x05};
const char kTestCharacteristicId1[] = "char_id1";
const char kTestCharacteristicUuid1[] = "1212";
const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties1 =
- BluetoothGattCharacteristic::kPropertyRead |
- BluetoothGattCharacteristic::kPropertyWrite |
- BluetoothGattCharacteristic::kPropertyNotify;
+ BluetoothGattCharacteristic::PROPERTY_READ |
+ BluetoothGattCharacteristic::PROPERTY_WRITE |
+ BluetoothGattCharacteristic::PROPERTY_NOTIFY;
const uint8 kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08};
const char kTestCharacteristicId2[] = "char_id2";
const char kTestCharacteristicUuid2[] = "1213";
const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties2 =
- BluetoothGattCharacteristic::kPropertyNone;
+ BluetoothGattCharacteristic::PROPERTY_NONE;
// Test descriptor constants.
const char kTestDescriptorId0[] = "desc_id0";
public:
BluetoothLowEnergyApiTest() {}
- virtual ~BluetoothLowEnergyApiTest() {}
+ ~BluetoothLowEnergyApiTest() override {}
- virtual void SetUpOnMainThread() OVERRIDE {
+ void SetUpOnMainThread() override {
ExtensionApiTest::SetUpOnMainThread();
empty_extension_ = extensions::test_util::CreateEmptyExtension();
SetUpMocks();
}
- virtual void TearDownOnMainThread() OVERRIDE {
+ void TearDownOnMainThread() override {
EXPECT_CALL(*mock_adapter_, RemoveObserver(_));
}
BluetoothUUID(kTestCharacteristicUuid0),
false /* is_local */,
kTestCharacteristicProperties0,
- BluetoothGattCharacteristic::kPermissionNone));
+ BluetoothGattCharacteristic::PERMISSION_NONE));
default_value.assign(kTestCharacteristicDefaultValue0,
(kTestCharacteristicDefaultValue0 +
sizeof(kTestCharacteristicDefaultValue0)));
BluetoothUUID(kTestCharacteristicUuid1),
false /* is_local */,
kTestCharacteristicProperties1,
- BluetoothGattCharacteristic::kPermissionNone));
+ BluetoothGattCharacteristic::PERMISSION_NONE));
default_value.assign(kTestCharacteristicDefaultValue1,
(kTestCharacteristicDefaultValue1 +
sizeof(kTestCharacteristicDefaultValue1)));
BluetoothUUID(kTestCharacteristicUuid2),
false /* is_local */,
kTestCharacteristicProperties2,
- BluetoothGattCharacteristic::kPermissionNone));
+ BluetoothGattCharacteristic::PERMISSION_NONE));
desc0_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>(
chrc0_.get(),
kTestDescriptorId0,
BluetoothUUID(kTestDescriptorUuid0),
false /* is_local */,
- BluetoothGattCharacteristic::kPermissionNone));
+ BluetoothGattCharacteristic::PERMISSION_NONE));
default_value.assign(
kTestDescriptorDefaultValue0,
(kTestDescriptorDefaultValue0 + sizeof(kTestDescriptorDefaultValue0)));
kTestDescriptorId1,
BluetoothUUID(kTestDescriptorUuid1),
false /* is_local */,
- BluetoothGattCharacteristic::kPermissionNone));
+ BluetoothGattCharacteristic::PERMISSION_NONE));
default_value.assign(
kTestDescriptorDefaultValue1,
(kTestDescriptorDefaultValue1 + sizeof(kTestDescriptorDefaultValue1)));
// Load and wait for setup.
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_services")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
// Load and wait for setup.
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_service")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
catcher.RestrictToBrowserContext(browser()->profile());
// Load the extension and let it set up.
- ExtensionTestMessageListener listener("ready", true);
+ ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/service_events")));
mock_adapter_, device0_.get(), service0_.get());
EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
event_router()->GattDiscoveryCompleteForService(mock_adapter_,
service0_.get());
- ExtensionTestMessageListener get_service_success_listener("getServiceSuccess",
- true);
+ ExtensionTestMessageListener get_service_success_listener(true);
EXPECT_TRUE(get_service_success_listener.WaitUntilSatisfied());
+ ASSERT_EQ("getServiceSuccess", get_service_success_listener.message())
+ << get_service_success_listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
event_router()->GattServiceRemoved(
mock_adapter_, device0_.get(), service0_.get());
- ExtensionTestMessageListener get_service_fail_listener("getServiceFail",
- true);
+ ExtensionTestMessageListener get_service_fail_listener(true);
EXPECT_TRUE(get_service_fail_listener.WaitUntilSatisfied());
+ ASSERT_EQ("getServiceFail", get_service_fail_listener.message())
+ << get_service_fail_listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
// Wait for initial call to end with failure as there is no mapping.
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
EXPECT_TRUE(listener.WaitUntilSatisfied());
// Set up for the rest of the calls before replying. Included services can be
// Load the extension and wait for first test.
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
.WillRepeatedly(Return(chrc0_.get()));
EXPECT_CALL(*chrc0_, GetProperties())
.Times(12)
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyNone))
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyBroadcast))
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyRead))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_NONE))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_BROADCAST))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_READ))
.WillOnce(
- Return(BluetoothGattCharacteristic::kPropertyWriteWithoutResponse))
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyWrite))
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyNotify))
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyIndicate))
+ Return(BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_WRITE))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_NOTIFY))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_INDICATE))
.WillOnce(Return(
- BluetoothGattCharacteristic::kPropertyAuthenticatedSignedWrites))
+ BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES))
.WillOnce(
- Return(BluetoothGattCharacteristic::kPropertyExtendedProperties))
- .WillOnce(Return(BluetoothGattCharacteristic::kPropertyReliableWrite))
+ Return(BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES))
+ .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE))
.WillOnce(
- Return(BluetoothGattCharacteristic::kPropertyWritableAuxiliaries))
+ Return(BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES))
.WillOnce(Return(
- BluetoothGattCharacteristic::kPropertyBroadcast |
- BluetoothGattCharacteristic::kPropertyRead |
- BluetoothGattCharacteristic::kPropertyWriteWithoutResponse |
- BluetoothGattCharacteristic::kPropertyWrite |
- BluetoothGattCharacteristic::kPropertyNotify |
- BluetoothGattCharacteristic::kPropertyIndicate |
- BluetoothGattCharacteristic::kPropertyAuthenticatedSignedWrites |
- BluetoothGattCharacteristic::kPropertyExtendedProperties |
- BluetoothGattCharacteristic::kPropertyReliableWrite |
- BluetoothGattCharacteristic::kPropertyWritableAuxiliaries));
+ BluetoothGattCharacteristic::PROPERTY_BROADCAST |
+ BluetoothGattCharacteristic::PROPERTY_READ |
+ BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE |
+ BluetoothGattCharacteristic::PROPERTY_WRITE |
+ BluetoothGattCharacteristic::PROPERTY_NOTIFY |
+ BluetoothGattCharacteristic::PROPERTY_INDICATE |
+ BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES |
+ BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES |
+ BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE |
+ BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/characteristic_properties")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/get_removed_characteristic")));
- ExtensionTestMessageListener listener("ready", true);
+ ExtensionTestMessageListener listener(true);
EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
testing::Mock::VerifyAndClearExpectations(service0_.get());
listener.Reply("go");
listener.Reset();
EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go");
std::vector<uint8> value;
EXPECT_CALL(*chrc0_, ReadRemoteCharacteristic(_, _))
.Times(2)
- .WillOnce(InvokeCallbackArgument<1>())
+ .WillOnce(
+ InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED))
.WillOnce(InvokeCallbackArgument<0>(value));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/read_characteristic_value")));
- EXPECT_TRUE(listener.WaitUntilSatisfied());
+ listener.WaitUntilSatisfied();
listener.Reply("go");
std::vector<uint8> write_value;
EXPECT_CALL(*chrc0_, WriteRemoteCharacteristic(_, _, _))
.Times(2)
- .WillOnce(InvokeCallbackArgument<2>())
+ .WillOnce(
+ InvokeCallbackArgument<2>(BluetoothGattService::GATT_ERROR_FAILED))
.WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>()));
EXPECT_CALL(*chrc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/write_characteristic_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
.WillOnce(Return(descriptors));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptors")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
// Load the extension and wait for first test.
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth_low_energy/get_descriptor")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/get_removed_descriptor")));
- ExtensionTestMessageListener listener("ready", true);
+ ExtensionTestMessageListener listener(true);
EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
testing::Mock::VerifyAndClearExpectations(device0_.get());
testing::Mock::VerifyAndClearExpectations(service0_.get());
listener.Reply("go");
listener.Reset();
EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
listener.Reply("go");
event_router()->GattDescriptorAdded(mock_adapter_, desc0_.get());
EXPECT_CALL(*mock_adapter_, GetDevice(_))
- .Times(3)
+ .Times(9)
.WillRepeatedly(Return(device0_.get()));
EXPECT_CALL(*device0_, GetGattService(kTestServiceId0))
- .Times(3)
+ .Times(9)
.WillRepeatedly(Return(service0_.get()));
EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
- .Times(3)
+ .Times(9)
.WillRepeatedly(Return(chrc0_.get()));
EXPECT_CALL(*chrc0_, GetDescriptor(kTestDescriptorId0))
- .Times(3)
+ .Times(9)
.WillRepeatedly(Return(desc0_.get()));
std::vector<uint8> value;
EXPECT_CALL(*desc0_, ReadRemoteDescriptor(_, _))
- .Times(2)
- .WillOnce(InvokeCallbackArgument<1>())
+ .Times(8)
+ .WillOnce(
+ InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED))
+ .WillOnce(InvokeCallbackArgument<1>(
+ BluetoothGattService::GATT_ERROR_INVALID_LENGTH))
+ .WillOnce(InvokeCallbackArgument<1>(
+ BluetoothGattService::GATT_ERROR_NOT_PERMITTED))
+ .WillOnce(InvokeCallbackArgument<1>(
+ BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED))
+ .WillOnce(InvokeCallbackArgument<1>(
+ BluetoothGattService::GATT_ERROR_NOT_PAIRED))
+ .WillOnce(InvokeCallbackArgument<1>(
+ BluetoothGattService::GATT_ERROR_NOT_SUPPORTED))
+ .WillOnce(InvokeCallbackArgument<1>(
+ BluetoothGattService::GATT_ERROR_IN_PROGRESS))
.WillOnce(InvokeCallbackArgument<0>(value));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/read_descriptor_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
std::vector<uint8> write_value;
EXPECT_CALL(*desc0_, WriteRemoteDescriptor(_, _, _))
.Times(2)
- .WillOnce(InvokeCallbackArgument<2>())
+ .WillOnce(
+ InvokeCallbackArgument<2>(BluetoothGattService::GATT_ERROR_FAILED))
.WillOnce(DoAll(SaveArg<0>(&write_value), InvokeCallbackArgument<1>()));
EXPECT_CALL(*desc0_, GetValue()).Times(1).WillOnce(ReturnRef(write_value));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/write_descriptor_value")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
ResultCatcher catcher;
catcher.RestrictToBrowserContext(browser()->profile());
- ExtensionTestMessageListener listener("ready", true);
+ ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/uuid_permission_events")));
EXPECT_TRUE(listener.WaitUntilSatisfied());
listener.Reply("go");
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+ ASSERT_EQ("ready", listener.message()) << listener.message();
event_router()->GattDescriptorRemoved(mock_adapter_, desc0_.get());
event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get());
EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress1))
.WillRepeatedly(Return(device1_.get()));
EXPECT_CALL(*device0_, CreateGattConnection(_, _))
- .Times(3)
+ .Times(9)
.WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED))
+ .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_INPROGRESS))
+ .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_FAILED))
+ .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_REJECTED))
+ .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_CANCELED))
+ .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_TIMEOUT))
+ .WillOnce(
+ InvokeCallbackArgument<1>(BluetoothDevice::ERROR_UNSUPPORTED_DEVICE))
.WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>(
CreateGattConnection(kTestLeDeviceAddress0,
true /* expect_disconnect */)))
.Times(1)
.WillOnce(SaveArg<0>(&connect_callback));
- ExtensionTestMessageListener listener("ready", true);
+ ExtensionTestMessageListener listener(true);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/connect_in_progress")));
- listener.WaitUntilSatisfied();
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
connect_callback.Run(conn_ptr.Pass());
listener.Reset();
- listener.WaitUntilSatisfied();
+ EXPECT_TRUE(listener.WaitUntilSatisfied());
+ ASSERT_EQ("ready", listener.message()) << listener.message();
disconnect_callback.Run();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
EXPECT_CALL(*chrc0_, StartNotifySession(_, _))
.Times(2)
- .WillOnce(InvokeCallbackArgument<1>())
.WillOnce(
- InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>(
- session0));
+ InvokeCallbackArgument<1>(BluetoothGattService::GATT_ERROR_FAILED))
+ .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattNotifySession>(
+ session0));
EXPECT_CALL(*chrc1_, StartNotifySession(_, _))
.Times(1)
.WillOnce(
session1));
ExtensionTestMessageListener listener("ready", true);
+ listener.set_failure_message("fail");
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
"bluetooth_low_energy/start_stop_notifications")));