| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 8 #include "device/bluetooth/test/mock_bluetooth_device.h" | 8 #include "device/bluetooth/test/mock_bluetooth_device.h" |
| 9 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" | 9 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" |
| 10 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 10 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const char kTestServiceId0[] = "service_id0"; | 54 const char kTestServiceId0[] = "service_id0"; |
| 55 const char kTestServiceUuid0[] = "1234"; | 55 const char kTestServiceUuid0[] = "1234"; |
| 56 | 56 |
| 57 const char kTestServiceId1[] = "service_id1"; | 57 const char kTestServiceId1[] = "service_id1"; |
| 58 const char kTestServiceUuid1[] = "5678"; | 58 const char kTestServiceUuid1[] = "5678"; |
| 59 | 59 |
| 60 // Test characteristic constants. | 60 // Test characteristic constants. |
| 61 const char kTestCharacteristicId0[] = "char_id0"; | 61 const char kTestCharacteristicId0[] = "char_id0"; |
| 62 const char kTestCharacteristicUuid0[] = "1211"; | 62 const char kTestCharacteristicUuid0[] = "1211"; |
| 63 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties0 = | 63 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties0 = |
| 64 BluetoothGattCharacteristic::kPropertyBroadcast | | 64 BluetoothGattCharacteristic::PROPERTY_BROADCAST | |
| 65 BluetoothGattCharacteristic::kPropertyRead | | 65 BluetoothGattCharacteristic::PROPERTY_READ | |
| 66 BluetoothGattCharacteristic::kPropertyWriteWithoutResponse | | 66 BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE | |
| 67 BluetoothGattCharacteristic::kPropertyIndicate; | 67 BluetoothGattCharacteristic::PROPERTY_INDICATE; |
| 68 const uint8 kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04, 0x05}; | 68 const uint8 kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04, 0x05}; |
| 69 | 69 |
| 70 const char kTestCharacteristicId1[] = "char_id1"; | 70 const char kTestCharacteristicId1[] = "char_id1"; |
| 71 const char kTestCharacteristicUuid1[] = "1212"; | 71 const char kTestCharacteristicUuid1[] = "1212"; |
| 72 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties1 = | 72 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties1 = |
| 73 BluetoothGattCharacteristic::kPropertyRead | | 73 BluetoothGattCharacteristic::PROPERTY_READ | |
| 74 BluetoothGattCharacteristic::kPropertyWrite | | 74 BluetoothGattCharacteristic::PROPERTY_WRITE | |
| 75 BluetoothGattCharacteristic::kPropertyNotify; | 75 BluetoothGattCharacteristic::PROPERTY_NOTIFY; |
| 76 const uint8 kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08}; | 76 const uint8 kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08}; |
| 77 | 77 |
| 78 const char kTestCharacteristicId2[] = "char_id2"; | 78 const char kTestCharacteristicId2[] = "char_id2"; |
| 79 const char kTestCharacteristicUuid2[] = "1213"; | 79 const char kTestCharacteristicUuid2[] = "1213"; |
| 80 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties2 = | 80 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties2 = |
| 81 BluetoothGattCharacteristic::kPropertyNone; | 81 BluetoothGattCharacteristic::PROPERTY_NONE; |
| 82 | 82 |
| 83 // Test descriptor constants. | 83 // Test descriptor constants. |
| 84 const char kTestDescriptorId0[] = "desc_id0"; | 84 const char kTestDescriptorId0[] = "desc_id0"; |
| 85 const char kTestDescriptorUuid0[] = "1221"; | 85 const char kTestDescriptorUuid0[] = "1221"; |
| 86 const uint8 kTestDescriptorDefaultValue0[] = {0x01, 0x02, 0x03}; | 86 const uint8 kTestDescriptorDefaultValue0[] = {0x01, 0x02, 0x03}; |
| 87 | 87 |
| 88 const char kTestDescriptorId1[] = "desc_id1"; | 88 const char kTestDescriptorId1[] = "desc_id1"; |
| 89 const char kTestDescriptorUuid1[] = "1222"; | 89 const char kTestDescriptorUuid1[] = "1222"; |
| 90 const uint8 kTestDescriptorDefaultValue1[] = {0x04, 0x05}; | 90 const uint8 kTestDescriptorDefaultValue1[] = {0x04, 0x05}; |
| 91 | 91 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // need to reflect what the characteristic is actually capable of, since | 146 // need to reflect what the characteristic is actually capable of, since |
| 147 // the JS API just passes values through from | 147 // the JS API just passes values through from |
| 148 // device::BluetoothGattCharacteristic. | 148 // device::BluetoothGattCharacteristic. |
| 149 std::vector<uint8> default_value; | 149 std::vector<uint8> default_value; |
| 150 chrc0_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( | 150 chrc0_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( |
| 151 service0_.get(), | 151 service0_.get(), |
| 152 kTestCharacteristicId0, | 152 kTestCharacteristicId0, |
| 153 BluetoothUUID(kTestCharacteristicUuid0), | 153 BluetoothUUID(kTestCharacteristicUuid0), |
| 154 false /* is_local */, | 154 false /* is_local */, |
| 155 kTestCharacteristicProperties0, | 155 kTestCharacteristicProperties0, |
| 156 BluetoothGattCharacteristic::kPermissionNone)); | 156 BluetoothGattCharacteristic::PERMISSION_NONE)); |
| 157 default_value.assign(kTestCharacteristicDefaultValue0, | 157 default_value.assign(kTestCharacteristicDefaultValue0, |
| 158 (kTestCharacteristicDefaultValue0 + | 158 (kTestCharacteristicDefaultValue0 + |
| 159 sizeof(kTestCharacteristicDefaultValue0))); | 159 sizeof(kTestCharacteristicDefaultValue0))); |
| 160 ON_CALL(*chrc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); | 160 ON_CALL(*chrc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); |
| 161 | 161 |
| 162 chrc1_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( | 162 chrc1_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( |
| 163 service0_.get(), | 163 service0_.get(), |
| 164 kTestCharacteristicId1, | 164 kTestCharacteristicId1, |
| 165 BluetoothUUID(kTestCharacteristicUuid1), | 165 BluetoothUUID(kTestCharacteristicUuid1), |
| 166 false /* is_local */, | 166 false /* is_local */, |
| 167 kTestCharacteristicProperties1, | 167 kTestCharacteristicProperties1, |
| 168 BluetoothGattCharacteristic::kPermissionNone)); | 168 BluetoothGattCharacteristic::PERMISSION_NONE)); |
| 169 default_value.assign(kTestCharacteristicDefaultValue1, | 169 default_value.assign(kTestCharacteristicDefaultValue1, |
| 170 (kTestCharacteristicDefaultValue1 + | 170 (kTestCharacteristicDefaultValue1 + |
| 171 sizeof(kTestCharacteristicDefaultValue1))); | 171 sizeof(kTestCharacteristicDefaultValue1))); |
| 172 ON_CALL(*chrc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); | 172 ON_CALL(*chrc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); |
| 173 | 173 |
| 174 chrc2_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( | 174 chrc2_.reset(new testing::NiceMock<MockBluetoothGattCharacteristic>( |
| 175 service1_.get(), | 175 service1_.get(), |
| 176 kTestCharacteristicId2, | 176 kTestCharacteristicId2, |
| 177 BluetoothUUID(kTestCharacteristicUuid2), | 177 BluetoothUUID(kTestCharacteristicUuid2), |
| 178 false /* is_local */, | 178 false /* is_local */, |
| 179 kTestCharacteristicProperties2, | 179 kTestCharacteristicProperties2, |
| 180 BluetoothGattCharacteristic::kPermissionNone)); | 180 BluetoothGattCharacteristic::PERMISSION_NONE)); |
| 181 | 181 |
| 182 desc0_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>( | 182 desc0_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>( |
| 183 chrc0_.get(), | 183 chrc0_.get(), |
| 184 kTestDescriptorId0, | 184 kTestDescriptorId0, |
| 185 BluetoothUUID(kTestDescriptorUuid0), | 185 BluetoothUUID(kTestDescriptorUuid0), |
| 186 false /* is_local */, | 186 false /* is_local */, |
| 187 BluetoothGattCharacteristic::kPermissionNone)); | 187 BluetoothGattCharacteristic::PERMISSION_NONE)); |
| 188 default_value.assign( | 188 default_value.assign( |
| 189 kTestDescriptorDefaultValue0, | 189 kTestDescriptorDefaultValue0, |
| 190 (kTestDescriptorDefaultValue0 + sizeof(kTestDescriptorDefaultValue0))); | 190 (kTestDescriptorDefaultValue0 + sizeof(kTestDescriptorDefaultValue0))); |
| 191 ON_CALL(*desc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); | 191 ON_CALL(*desc0_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); |
| 192 | 192 |
| 193 desc1_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>( | 193 desc1_.reset(new testing::NiceMock<MockBluetoothGattDescriptor>( |
| 194 chrc0_.get(), | 194 chrc0_.get(), |
| 195 kTestDescriptorId1, | 195 kTestDescriptorId1, |
| 196 BluetoothUUID(kTestDescriptorUuid1), | 196 BluetoothUUID(kTestDescriptorUuid1), |
| 197 false /* is_local */, | 197 false /* is_local */, |
| 198 BluetoothGattCharacteristic::kPermissionNone)); | 198 BluetoothGattCharacteristic::PERMISSION_NONE)); |
| 199 default_value.assign( | 199 default_value.assign( |
| 200 kTestDescriptorDefaultValue1, | 200 kTestDescriptorDefaultValue1, |
| 201 (kTestDescriptorDefaultValue1 + sizeof(kTestDescriptorDefaultValue1))); | 201 (kTestDescriptorDefaultValue1 + sizeof(kTestDescriptorDefaultValue1))); |
| 202 ON_CALL(*desc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); | 202 ON_CALL(*desc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 protected: | 205 protected: |
| 206 BluetoothLowEnergyEventRouter* event_router() { | 206 BluetoothLowEnergyEventRouter* event_router() { |
| 207 return extensions::BluetoothLowEnergyAPI::Get(browser()->profile()) | 207 return extensions::BluetoothLowEnergyAPI::Get(browser()->profile()) |
| 208 ->event_router(); | 208 ->event_router(); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 .Times(12) | 532 .Times(12) |
| 533 .WillRepeatedly(Return(device0_.get())); | 533 .WillRepeatedly(Return(device0_.get())); |
| 534 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) | 534 EXPECT_CALL(*device0_, GetGattService(kTestServiceId0)) |
| 535 .Times(12) | 535 .Times(12) |
| 536 .WillRepeatedly(Return(service0_.get())); | 536 .WillRepeatedly(Return(service0_.get())); |
| 537 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) | 537 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0)) |
| 538 .Times(12) | 538 .Times(12) |
| 539 .WillRepeatedly(Return(chrc0_.get())); | 539 .WillRepeatedly(Return(chrc0_.get())); |
| 540 EXPECT_CALL(*chrc0_, GetProperties()) | 540 EXPECT_CALL(*chrc0_, GetProperties()) |
| 541 .Times(12) | 541 .Times(12) |
| 542 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyNone)) | 542 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_NONE)) |
| 543 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyBroadcast)) | 543 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_BROADCAST)) |
| 544 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyRead)) | 544 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_READ)) |
| 545 .WillOnce( | 545 .WillOnce( |
| 546 Return(BluetoothGattCharacteristic::kPropertyWriteWithoutResponse)) | 546 Return(BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)) |
| 547 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyWrite)) | 547 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_WRITE)) |
| 548 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyNotify)) | 548 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_NOTIFY)) |
| 549 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyIndicate)) | 549 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_INDICATE)) |
| 550 .WillOnce(Return( | 550 .WillOnce(Return( |
| 551 BluetoothGattCharacteristic::kPropertyAuthenticatedSignedWrites)) | 551 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES)) |
| 552 .WillOnce( | 552 .WillOnce( |
| 553 Return(BluetoothGattCharacteristic::kPropertyExtendedProperties)) | 553 Return(BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES)) |
| 554 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyReliableWrite)) | 554 .WillOnce(Return(BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE)) |
| 555 .WillOnce( | 555 .WillOnce( |
| 556 Return(BluetoothGattCharacteristic::kPropertyWritableAuxiliaries)) | 556 Return(BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES)) |
| 557 .WillOnce(Return( | 557 .WillOnce(Return( |
| 558 BluetoothGattCharacteristic::kPropertyBroadcast | | 558 BluetoothGattCharacteristic::PROPERTY_BROADCAST | |
| 559 BluetoothGattCharacteristic::kPropertyRead | | 559 BluetoothGattCharacteristic::PROPERTY_READ | |
| 560 BluetoothGattCharacteristic::kPropertyWriteWithoutResponse | | 560 BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE | |
| 561 BluetoothGattCharacteristic::kPropertyWrite | | 561 BluetoothGattCharacteristic::PROPERTY_WRITE | |
| 562 BluetoothGattCharacteristic::kPropertyNotify | | 562 BluetoothGattCharacteristic::PROPERTY_NOTIFY | |
| 563 BluetoothGattCharacteristic::kPropertyIndicate | | 563 BluetoothGattCharacteristic::PROPERTY_INDICATE | |
| 564 BluetoothGattCharacteristic::kPropertyAuthenticatedSignedWrites | | 564 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES | |
| 565 BluetoothGattCharacteristic::kPropertyExtendedProperties | | 565 BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES | |
| 566 BluetoothGattCharacteristic::kPropertyReliableWrite | | 566 BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE | |
| 567 BluetoothGattCharacteristic::kPropertyWritableAuxiliaries)); | 567 BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES)); |
| 568 | 568 |
| 569 ExtensionTestMessageListener listener("ready", true); | 569 ExtensionTestMessageListener listener("ready", true); |
| 570 listener.set_failure_message("fail"); | 570 listener.set_failure_message("fail"); |
| 571 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 571 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 572 "bluetooth_low_energy/characteristic_properties"))); | 572 "bluetooth_low_energy/characteristic_properties"))); |
| 573 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 573 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 574 | 574 |
| 575 listener.Reply("go"); | 575 listener.Reply("go"); |
| 576 | 576 |
| 577 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 577 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); | 1295 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); |
| 1296 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); | 1296 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); |
| 1297 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); | 1297 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); |
| 1298 event_router()->GattServiceRemoved( | 1298 event_router()->GattServiceRemoved( |
| 1299 mock_adapter_, device0_.get(), service1_.get()); | 1299 mock_adapter_, device0_.get(), service1_.get()); |
| 1300 event_router()->GattServiceRemoved( | 1300 event_router()->GattServiceRemoved( |
| 1301 mock_adapter_, device0_.get(), service0_.get()); | 1301 mock_adapter_, device0_.get(), service0_.get()); |
| 1302 } | 1302 } |
| 1303 | 1303 |
| 1304 } // namespace | 1304 } // namespace |
| OLD | NEW |