Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 <script src="bluetooth-helpers.js"></script> | |
| 5 <script> | |
| 6 test(function(t) { assert_exists(window, "testRunner"); t.done(); }, | |
| 7 "window.testRunner is required for the following tests."); | |
| 8 | |
| 9 var service1 = "00001800-0000-1000-8000-00805f9b34fb"; | |
|
Jeffrey Yasskin
2015/06/03 00:24:04
Comment what these services and characteristics ar
ortuno
2015/06/03 21:57:03
Done.
| |
| 10 var characteristic1 = "00002a00-0000-1000-8000-00805f9b34fb"; | |
| 11 var characteristic2 = "00002a01-0000-1000-8000-00805f9b34fb"; | |
| 12 | |
| 13 sequential_promise_test(function() { | |
| 14 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | |
| 15 return navigator.bluetooth.requestDevice().then(function(device) { | |
| 16 return device.connectGATT().then(function(gattServer) { | |
|
Jeffrey Yasskin
2015/06/03 00:24:04
I think this could be:
sequential_promise_test(fu
ortuno
2015/06/03 21:57:04
Done.
| |
| 17 return gattServer.getPrimaryService(service1).then(function(service) { | |
| 18 testRunner.setBluetoothMockDataSet('EmptyAdapter'); | |
| 19 return service.getCharacteristic(characteristic1).then(function() { | |
| 20 assert_unreached("Device went out of range, should fail."); | |
| 21 }, function(e) { | |
| 22 assert_equals(e.name, "NetworkError"); | |
| 23 }); | |
| 24 }); | |
| 25 }); | |
| 26 }); | |
| 27 }, 'Device goes out of range. Reject with NetworkError.'); | |
| 28 | |
| 29 sequential_promise_test(function() { | |
| 30 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | |
| 31 return navigator.bluetooth.requestDevice().then(function(device) { | |
| 32 return device.connectGATT(); | |
| 33 }).then(function(gattServer) { | |
| 34 return gattServer.getPrimaryService(service1); | |
| 35 }).then(function(service) { | |
| 36 return service.getCharacteristic(characteristic2); | |
|
Jeffrey Yasskin
2015/06/03 00:24:04
It'd be better to query for a characteristic that
ortuno
2015/06/03 21:57:04
Done.
| |
| 37 }).then(function(characteristic) { | |
| 38 assert_equals(characteristic, null, | |
| 39 "Non existent characteristic should return null."); | |
| 40 }); | |
| 41 }, 'Request for wrong characteristic. Should return null.'); | |
| 42 | |
| 43 sequential_promise_test(function() { | |
| 44 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | |
| 45 return navigator.bluetooth.requestDevice().then(function(device) { | |
| 46 return device.connectGATT(); | |
| 47 }).then(function(gattServer) { | |
| 48 return gattServer.getPrimaryService(service1); | |
| 49 }).then(function(service) { | |
| 50 return service.getCharacteristic(characteristic1); | |
| 51 }).then(function(characteristic) { | |
| 52 assert_equals(characteristic.uuid, characteristic1, | |
| 53 "Characteristic UUID should be the same as requested UUID."); | |
| 54 }); | |
| 55 }, 'Request for characteristic. Should return right characteristic'); | |
| 56 | |
| 57 sequential_promise_test(function() { | |
| 58 testRunner.setBluetoothMockDataSet('ConnectableDeviceAdapter'); | |
| 59 return navigator.bluetooth.requestDevice().then(function(device) { | |
| 60 return device.connectGATT(); | |
| 61 }).then(function(gattServer) { | |
| 62 return gattServer.getPrimaryService(service1); | |
| 63 }).then(function(services) { | |
| 64 return Promise.all([services.getCharacteristic(characteristic1), | |
| 65 services.getCharacteristic(characteristic1)]); | |
| 66 }).then(function(characteristics) { | |
| 67 // TODO(ortuno): getCharacteristic should return the same object | |
| 68 // if it was created earlier. | |
| 69 // https://crbug.com/495270 | |
| 70 assert_not_equals(characteristics[0], characteristics[1], | |
| 71 "Should return the same service as the first call."); | |
| 72 }); | |
| 73 }, 'Calls to get the same characteristic should return the same object.'); | |
| 74 | |
| 75 </script> | |
| OLD | NEW |