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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc

Issue 262053003: chrome.bluetoothLowEnergy: Implement getCharacteristic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h"
7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h" 7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_event_router.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const uint8 kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04, 0x05}; 50 const uint8 kTestCharacteristicDefaultValue0[] = {0x01, 0x02, 0x03, 0x04, 0x05};
51 51
52 const char kTestCharacteristicId1[] = "char_id1"; 52 const char kTestCharacteristicId1[] = "char_id1";
53 const char kTestCharacteristicUuid1[] = "1212"; 53 const char kTestCharacteristicUuid1[] = "1212";
54 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties1 = 54 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties1 =
55 BluetoothGattCharacteristic::kPropertyRead | 55 BluetoothGattCharacteristic::kPropertyRead |
56 BluetoothGattCharacteristic::kPropertyWrite | 56 BluetoothGattCharacteristic::kPropertyWrite |
57 BluetoothGattCharacteristic::kPropertyNotify; 57 BluetoothGattCharacteristic::kPropertyNotify;
58 const uint8 kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08}; 58 const uint8 kTestCharacteristicDefaultValue1[] = {0x06, 0x07, 0x08};
59 59
60 const char kTestCharacteristicId2[] = "char_id1"; 60 const char kTestCharacteristicId2[] = "char_id2";
61 const char kTestCharacteristicUuid2[] = "1213"; 61 const char kTestCharacteristicUuid2[] = "1213";
62 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties2 = 62 const BluetoothGattCharacteristic::Properties kTestCharacteristicProperties2 =
63 BluetoothGattCharacteristic::kPropertyNone; 63 BluetoothGattCharacteristic::kPropertyNone;
64 64
65 class BluetoothLowEnergyApiTest : public ExtensionApiTest { 65 class BluetoothLowEnergyApiTest : public ExtensionApiTest {
66 public: 66 public:
67 BluetoothLowEnergyApiTest() {} 67 BluetoothLowEnergyApiTest() {}
68 68
69 virtual ~BluetoothLowEnergyApiTest() {} 69 virtual ~BluetoothLowEnergyApiTest() {}
70 70
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics"))); 360 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristics")));
361 EXPECT_TRUE(listener.WaitUntilSatisfied()); 361 EXPECT_TRUE(listener.WaitUntilSatisfied());
362 362
363 listener.Reply("go"); 363 listener.Reply("go");
364 364
365 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 365 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
366 event_router()->GattServiceRemoved(device_.get(), service0_.get()); 366 event_router()->GattServiceRemoved(device_.get(), service0_.get());
367 event_router()->DeviceRemoved(mock_adapter_, device_.get()); 367 event_router()->DeviceRemoved(mock_adapter_, device_.get());
368 } 368 }
369 369
370 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetCharacteristic) {
371 ResultCatcher catcher;
372 catcher.RestrictToProfile(browser()->profile());
373
374 event_router()->DeviceAdded(mock_adapter_, device_.get());
375 event_router()->GattServiceAdded(device_.get(), service0_.get());
376 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get());
377
378 EXPECT_CALL(*mock_adapter_, GetDevice(_))
379 .Times(4)
380 .WillOnce(Return(static_cast<BluetoothDevice*>(NULL)))
381 .WillRepeatedly(Return(device_.get()));
382
383 EXPECT_CALL(*device_, GetGattService(kTestServiceId0))
384 .Times(3)
385 .WillOnce(Return(static_cast<BluetoothGattService*>(NULL)))
386 .WillRepeatedly(Return(service0_.get()));
387
388 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
389 .Times(2)
390 .WillOnce(Return(static_cast<BluetoothGattCharacteristic*>(NULL)))
391 .WillOnce(Return(chrc0_.get()));
392
393 // Load the extension and wait for first test.
394 ExtensionTestMessageListener listener("ready", true);
395 ASSERT_TRUE(LoadExtension(
396 test_data_dir_.AppendASCII("bluetooth_low_energy/get_characteristic")));
397 EXPECT_TRUE(listener.WaitUntilSatisfied());
398
399 listener.Reply("go");
400
401 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
402
403 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get());
404 event_router()->GattServiceRemoved(device_.get(), service0_.get());
405 event_router()->DeviceRemoved(mock_adapter_, device_.get());
406 }
407
408 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, CharacteristicProperties) {
409 ResultCatcher catcher;
410 catcher.RestrictToProfile(browser()->profile());
411
412 event_router()->DeviceAdded(mock_adapter_, device_.get());
413 event_router()->GattServiceAdded(device_.get(), service0_.get());
414 event_router()->GattCharacteristicAdded(service0_.get(), chrc0_.get());
415
416 EXPECT_CALL(*mock_adapter_, GetDevice(_))
417 .Times(12)
418 .WillRepeatedly(Return(device_.get()));
419 EXPECT_CALL(*device_, GetGattService(kTestServiceId0))
420 .Times(12)
421 .WillRepeatedly(Return(service0_.get()));
422 EXPECT_CALL(*service0_, GetCharacteristic(kTestCharacteristicId0))
423 .Times(12)
424 .WillRepeatedly(Return(chrc0_.get()));
425 EXPECT_CALL(*chrc0_, GetProperties())
426 .Times(12)
427 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyNone))
428 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyBroadcast))
429 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyRead))
430 .WillOnce(
431 Return(BluetoothGattCharacteristic::kPropertyWriteWithoutResponse))
432 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyWrite))
433 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyNotify))
434 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyIndicate))
435 .WillOnce(Return(
436 BluetoothGattCharacteristic::kPropertyAuthenticatedSignedWrites))
437 .WillOnce(
438 Return(BluetoothGattCharacteristic::kPropertyExtendedProperties))
439 .WillOnce(Return(BluetoothGattCharacteristic::kPropertyReliableWrite))
440 .WillOnce(
441 Return(BluetoothGattCharacteristic::kPropertyWriteableAuxiliaries))
442 .WillOnce(Return(
443 BluetoothGattCharacteristic::kPropertyBroadcast |
444 BluetoothGattCharacteristic::kPropertyRead |
445 BluetoothGattCharacteristic::kPropertyWriteWithoutResponse |
446 BluetoothGattCharacteristic::kPropertyWrite |
447 BluetoothGattCharacteristic::kPropertyNotify |
448 BluetoothGattCharacteristic::kPropertyIndicate |
449 BluetoothGattCharacteristic::kPropertyAuthenticatedSignedWrites |
450 BluetoothGattCharacteristic::kPropertyExtendedProperties |
451 BluetoothGattCharacteristic::kPropertyReliableWrite |
452 BluetoothGattCharacteristic::kPropertyWriteableAuxiliaries));
453
454 ExtensionTestMessageListener listener("ready", true);
455 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
456 "bluetooth_low_energy/characteristic_properties")));
457 EXPECT_TRUE(listener.WaitUntilSatisfied());
458
459 listener.Reply("go");
460
461 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
462
463 event_router()->GattCharacteristicRemoved(service0_.get(), chrc0_.get());
464 event_router()->GattServiceRemoved(device_.get(), service0_.get());
465 event_router()->DeviceRemoved(mock_adapter_, device_.get());
466 }
467
370 } // namespace 468 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698