Bug 1442083 [wpt PR 9723] - bluetooth: Handle UUIDs in service data, a=testonly
authorOvidio Henriquez <odejesush@chromium.org>
Mon, 09 Apr 2018 14:34:46 +0000
changeset 413456 5771401ddf284de9b628d3bbc3a99f33b21a1fd4
parent 413455 1ba389b58ab983ade0a33922b1c7be1cd15ba226
child 413457 f724a325a3519511d87f6dbea9a9a2bacb47b0e9
push id33850
push userapavel@mozilla.com
push dateMon, 16 Apr 2018 09:53:48 +0000
treeherdermozilla-central@6276ec7ebbf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1442083, 817603, 942307, 542344
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1442083 [wpt PR 9723] - bluetooth: Handle UUIDs in service data, a=testonly Automatic update from web-platform-testsbluetooth: Handle UUIDs in service data Adds a Mojo typemap to properly handle the UUID strings in the service_data field of ScanRecord. The typemap allows the service_data field to map to a device::BluetoothDevice::ServiceDataMap object in C++. BUG=817603 Change-Id: Ie4d5785e8b04098fda76ca8bc99c58141c9b5b82 Reviewed-on: https://chromium-review.googlesource.com/942307 Commit-Queue: Ovidio Henriquez <odejesush@chromium.org> Reviewed-by: Ken Rockot <rockot@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org> Cr-Commit-Position: refs/heads/master@{#542344} wpt-commits: 2f6cfc454994046a779b984bc02f129f4ac67ab0 wpt-pr: 9723 wpt-commits: 2f6cfc454994046a779b984bc02f129f4ac67ab0 wpt-pr: 9723
testing/web-platform/tests/resources/chromium/fake_bluetooth.mojom.js
testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
--- a/testing/web-platform/tests/resources/chromium/fake_bluetooth.mojom.js
+++ b/testing/web-platform/tests/resources/chromium/fake_bluetooth.mojom.js
@@ -185,44 +185,100 @@
     encoder.encodeStruct(codec.Int8, val.value);
     encoder.skip(1);
     encoder.skip(1);
     encoder.skip(1);
     encoder.skip(1);
     encoder.skip(1);
     encoder.skip(1);
   };
+  function ServiceDataMap(values) {
+    this.initDefaults_();
+    this.initFields_(values);
+  }
+
+
+  ServiceDataMap.prototype.initDefaults_ = function() {
+    this.serviceData = null;
+  };
+  ServiceDataMap.prototype.initFields_ = function(fields) {
+    for(var field in fields) {
+        if (this.hasOwnProperty(field))
+          this[field] = fields[field];
+    }
+  };
+
+  ServiceDataMap.validate = function(messageValidator, offset) {
+    var err;
+    err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+    var kVersionSizes = [
+      {version: 0, numBytes: 16}
+    ];
+    err = messageValidator.validateStructVersion(offset, kVersionSizes);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+
+    // validate ServiceDataMap.serviceData
+    err = messageValidator.validateMapPointer(offset + codec.kStructHeaderSize + 0, false, codec.String, new codec.ArrayOf(codec.Uint8), false);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+    return validator.validationError.NONE;
+  };
+
+  ServiceDataMap.encodedSize = codec.kStructHeaderSize + 8;
+
+  ServiceDataMap.decode = function(decoder) {
+    var packed;
+    var val = new ServiceDataMap();
+    var numberOfBytes = decoder.readUint32();
+    var version = decoder.readUint32();
+    val.serviceData = decoder.decodeMapPointer(codec.String, new codec.ArrayOf(codec.Uint8));
+    return val;
+  };
+
+  ServiceDataMap.encode = function(encoder, val) {
+    var packed;
+    encoder.writeUint32(ServiceDataMap.encodedSize);
+    encoder.writeUint32(0);
+    encoder.encodeMapPointer(codec.String, new codec.ArrayOf(codec.Uint8), val.serviceData);
+  };
   function ScanRecord(values) {
     this.initDefaults_();
     this.initFields_(values);
   }
 
 
   ScanRecord.prototype.initDefaults_ = function() {
     this.name = null;
     this.uuids = null;
     this.appearance = null;
     this.txPower = null;
     this.manufacturerData = null;
+    this.serviceData = null;
   };
   ScanRecord.prototype.initFields_ = function(fields) {
     for(var field in fields) {
         if (this.hasOwnProperty(field))
           this[field] = fields[field];
     }
   };
 
   ScanRecord.validate = function(messageValidator, offset) {
     var err;
     err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize);
     if (err !== validator.validationError.NONE)
         return err;
 
     var kVersionSizes = [
-      {version: 0, numBytes: 48}
+      {version: 0, numBytes: 56}
     ];
     err = messageValidator.validateStructVersion(offset, kVersionSizes);
     if (err !== validator.validationError.NONE)
         return err;
 
 
     // validate ScanRecord.name
     err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, true)
@@ -248,43 +304,51 @@
         return err;
 
 
     // validate ScanRecord.manufacturerData
     err = messageValidator.validateMapPointer(offset + codec.kStructHeaderSize + 32, true, codec.Uint8, new codec.ArrayOf(codec.Uint8), false);
     if (err !== validator.validationError.NONE)
         return err;
 
+
+    // validate ScanRecord.serviceData
+    err = messageValidator.validateStructPointer(offset + codec.kStructHeaderSize + 40, ServiceDataMap, true);
+    if (err !== validator.validationError.NONE)
+        return err;
+
     return validator.validationError.NONE;
   };
 
-  ScanRecord.encodedSize = codec.kStructHeaderSize + 40;
+  ScanRecord.encodedSize = codec.kStructHeaderSize + 48;
 
   ScanRecord.decode = function(decoder) {
     var packed;
     var val = new ScanRecord();
     var numberOfBytes = decoder.readUint32();
     var version = decoder.readUint32();
     val.name = decoder.decodeStruct(codec.NullableString);
     val.uuids = decoder.decodeArrayPointer(new codec.PointerTo(uuid$.UUID));
     val.appearance = decoder.decodeStructPointer(Appearance);
     val.txPower = decoder.decodeStructPointer(Power);
     val.manufacturerData = decoder.decodeMapPointer(codec.Uint8, new codec.ArrayOf(codec.Uint8));
+    val.serviceData = decoder.decodeStructPointer(ServiceDataMap);
     return val;
   };
 
   ScanRecord.encode = function(encoder, val) {
     var packed;
     encoder.writeUint32(ScanRecord.encodedSize);
     encoder.writeUint32(0);
     encoder.encodeStruct(codec.NullableString, val.name);
     encoder.encodeArrayPointer(new codec.PointerTo(uuid$.UUID), val.uuids);
     encoder.encodeStructPointer(Appearance, val.appearance);
     encoder.encodeStructPointer(Power, val.txPower);
     encoder.encodeMapPointer(codec.Uint8, new codec.ArrayOf(codec.Uint8), val.manufacturerData);
+    encoder.encodeStructPointer(ServiceDataMap, val.serviceData);
   };
   function ScanResult(values) {
     this.initDefaults_();
     this.initFields_(values);
   }
 
 
   ScanResult.prototype.initDefaults_ = function() {
@@ -4187,16 +4251,17 @@
   FakeCentralProxy.prototype.validator = validateFakeCentralResponse;
   exports.kHCISuccess = kHCISuccess;
   exports.kHCIConnectionTimeout = kHCIConnectionTimeout;
   exports.kGATTSuccess = kGATTSuccess;
   exports.kGATTInvalidHandle = kGATTInvalidHandle;
   exports.CentralState = CentralState;
   exports.Appearance = Appearance;
   exports.Power = Power;
+  exports.ServiceDataMap = ServiceDataMap;
   exports.ScanRecord = ScanRecord;
   exports.ScanResult = ScanResult;
   exports.CharacteristicProperties = CharacteristicProperties;
   exports.FakeBluetooth = FakeBluetooth;
   exports.FakeBluetoothPtr = FakeBluetoothPtr;
   exports.FakeBluetoothAssociatedPtr = FakeBluetoothAssociatedPtr;
   exports.FakeCentral = FakeCentral;
   exports.FakeCentralPtr = FakeCentralPtr;
--- a/testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
+++ b/testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
@@ -159,18 +159,22 @@ class FakeCentral {
 
     // Convert manufacturerData from a record<DOMString, BufferSource> into a
     // map<uint8, array<uint8>> for Mojo.
     if ('manufacturerData' in scanResult.scanRecord) {
       scanResult.scanRecord.manufacturerData = convertToMojoMap(
           scanResult.scanRecord.manufacturerData, Number);
     }
 
-    // TODO(https://crbug.com/817603): Add a conversion process for serviceData
-    // when the field is added in Mojo.
+    // Convert serviceData from a record<DOMString, BufferSource> into a
+    // map<string, array<uint8>> for Mojo.
+    if ('serviceData' in scanResult.scanRecord) {
+      scanResult.scanRecord.serviceData.serviceData = convertToMojoMap(
+          scanResult.scanRecord.serviceData, BluetoothUUID.getService);
+    }
 
     await this.fake_central_ptr_.simulateAdvertisementReceived(
         new bluetooth.mojom.ScanResult(scanResult));
 
     return this.fetchOrCreatePeripheral_(scanResult.deviceAddress);
   }
 
   // Create a fake_peripheral object from the given address.