summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/bluetooth/characteristic/getDescriptors/gen-descriptor-get-same-object.https.window.js
blob: 7f1001f3eee795307dfac2899f4dac78e2f2de23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=/common/gc.js
// META: script=/bluetooth/resources/bluetooth-test.js
// META: script=/bluetooth/resources/bluetooth-fake-devices.js
// Generated by //third_party/WebKit/LayoutTests/bluetooth/generate.py
'use strict';
const test_desc = 'Calls to getDescriptors should return the same object.';
let characteristic;

bluetooth_test(() => getMeasurementIntervalCharacteristic()
    .then(_ => ({characteristic} = _))
    .then(() => Promise.all([
      characteristic.getDescriptors(user_description.alias),
      characteristic.getDescriptors(user_description.name),
      characteristic.getDescriptors(user_description.uuid)
    ]))
    .then(descriptors_arrays => {
      assert_true(descriptors_arrays.length > 0)

      // Convert to arrays if necessary.
      for (let i = 0; i < descriptors_arrays.length; i++) {
        descriptors_arrays[i] = [].concat(descriptors_arrays[i]);
      }

      for (let i = 1; i < descriptors_arrays.length; i++) {
        assert_equals(descriptors_arrays[0].length,
            descriptors_arrays[i].length);
      }

      let base_set = new Set(descriptors_arrays[0]);
      for (let descriptors of descriptors_arrays) {
        descriptors.forEach(descriptor => assert_true(base_set.has(descriptor)));
      }
    }), test_desc);