Bug 1447518 [wpt PR 10118] - bluetooth: Add RemoveFakeDescriptor to BT test, a=testonly
authorOvidio Henriquez <odejesush@chromium.org>
Mon, 09 Apr 2018 18:07:51 +0000
changeset 467173 11950385d641864aa54dce17a36aff1f5ae3c30c
parent 467172 fdaca2ea8a6fa572d788176044e343f72edb09a9
child 467174 df17dcd3282ca150f3b996d13192ee6ae5ada745
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1447518, 10118, 569709, 972334, 545448
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 1447518 [wpt PR 10118] - bluetooth: Add RemoveFakeDescriptor to BT test, a=testonly Automatic update from web-platform-testsbluetooth: Add RemoveFakeDescriptor to BT test This change allows the removal of a descriptor to be simulated by the Bluetooth test interface. A generated test script was also converted to test the new interface. BUG=569709 Change-Id: Id4286a3e44cd04ee1b371938f1ef89f33458269c Reviewed-on: https://chromium-review.googlesource.com/972334 Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Conley Owens <cco3@chromium.org> Commit-Queue: Ovidio Henriquez <odejesush@chromium.org> Cr-Commit-Position: refs/heads/master@{#545448} wpt-commits: 273bb41376c98c36e743186b63ec3cffa58a5339 wpt-pr: 10118 wpt-commits: 273bb41376c98c36e743186b63ec3cffa58a5339 wpt-pr: 10118
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
@@ -2265,16 +2265,165 @@
   };
 
   FakeCentral_AddFakeDescriptor_ResponseParams.encode = function(encoder, val) {
     var packed;
     encoder.writeUint32(FakeCentral_AddFakeDescriptor_ResponseParams.encodedSize);
     encoder.writeUint32(0);
     encoder.encodeStruct(codec.NullableString, val.descriptorId);
   };
+  function FakeCentral_RemoveFakeDescriptor_Params(values) {
+    this.initDefaults_();
+    this.initFields_(values);
+  }
+
+
+  FakeCentral_RemoveFakeDescriptor_Params.prototype.initDefaults_ = function() {
+    this.identifier = null;
+    this.characteristicId = null;
+    this.serviceId = null;
+    this.peripheralAddress = null;
+  };
+  FakeCentral_RemoveFakeDescriptor_Params.prototype.initFields_ = function(fields) {
+    for(var field in fields) {
+        if (this.hasOwnProperty(field))
+          this[field] = fields[field];
+    }
+  };
+
+  FakeCentral_RemoveFakeDescriptor_Params.validate = function(messageValidator, offset) {
+    var err;
+    err = messageValidator.validateStructHeader(offset, codec.kStructHeaderSize);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+    var kVersionSizes = [
+      {version: 0, numBytes: 40}
+    ];
+    err = messageValidator.validateStructVersion(offset, kVersionSizes);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+
+    // validate FakeCentral_RemoveFakeDescriptor_Params.identifier
+    err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 0, false)
+    if (err !== validator.validationError.NONE)
+        return err;
+
+
+    // validate FakeCentral_RemoveFakeDescriptor_Params.characteristicId
+    err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 8, false)
+    if (err !== validator.validationError.NONE)
+        return err;
+
+
+    // validate FakeCentral_RemoveFakeDescriptor_Params.serviceId
+    err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 16, false)
+    if (err !== validator.validationError.NONE)
+        return err;
+
+
+    // validate FakeCentral_RemoveFakeDescriptor_Params.peripheralAddress
+    err = messageValidator.validateStringPointer(offset + codec.kStructHeaderSize + 24, false)
+    if (err !== validator.validationError.NONE)
+        return err;
+
+    return validator.validationError.NONE;
+  };
+
+  FakeCentral_RemoveFakeDescriptor_Params.encodedSize = codec.kStructHeaderSize + 32;
+
+  FakeCentral_RemoveFakeDescriptor_Params.decode = function(decoder) {
+    var packed;
+    var val = new FakeCentral_RemoveFakeDescriptor_Params();
+    var numberOfBytes = decoder.readUint32();
+    var version = decoder.readUint32();
+    val.identifier = decoder.decodeStruct(codec.String);
+    val.characteristicId = decoder.decodeStruct(codec.String);
+    val.serviceId = decoder.decodeStruct(codec.String);
+    val.peripheralAddress = decoder.decodeStruct(codec.String);
+    return val;
+  };
+
+  FakeCentral_RemoveFakeDescriptor_Params.encode = function(encoder, val) {
+    var packed;
+    encoder.writeUint32(FakeCentral_RemoveFakeDescriptor_Params.encodedSize);
+    encoder.writeUint32(0);
+    encoder.encodeStruct(codec.String, val.identifier);
+    encoder.encodeStruct(codec.String, val.characteristicId);
+    encoder.encodeStruct(codec.String, val.serviceId);
+    encoder.encodeStruct(codec.String, val.peripheralAddress);
+  };
+  function FakeCentral_RemoveFakeDescriptor_ResponseParams(values) {
+    this.initDefaults_();
+    this.initFields_(values);
+  }
+
+
+  FakeCentral_RemoveFakeDescriptor_ResponseParams.prototype.initDefaults_ = function() {
+    this.success = false;
+  };
+  FakeCentral_RemoveFakeDescriptor_ResponseParams.prototype.initFields_ = function(fields) {
+    for(var field in fields) {
+        if (this.hasOwnProperty(field))
+          this[field] = fields[field];
+    }
+  };
+
+  FakeCentral_RemoveFakeDescriptor_ResponseParams.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;
+
+
+    return validator.validationError.NONE;
+  };
+
+  FakeCentral_RemoveFakeDescriptor_ResponseParams.encodedSize = codec.kStructHeaderSize + 8;
+
+  FakeCentral_RemoveFakeDescriptor_ResponseParams.decode = function(decoder) {
+    var packed;
+    var val = new FakeCentral_RemoveFakeDescriptor_ResponseParams();
+    var numberOfBytes = decoder.readUint32();
+    var version = decoder.readUint32();
+    packed = decoder.readUint8();
+    val.success = (packed >> 0) & 1 ? true : false;
+    decoder.skip(1);
+    decoder.skip(1);
+    decoder.skip(1);
+    decoder.skip(1);
+    decoder.skip(1);
+    decoder.skip(1);
+    decoder.skip(1);
+    return val;
+  };
+
+  FakeCentral_RemoveFakeDescriptor_ResponseParams.encode = function(encoder, val) {
+    var packed;
+    encoder.writeUint32(FakeCentral_RemoveFakeDescriptor_ResponseParams.encodedSize);
+    encoder.writeUint32(0);
+    packed = 0;
+    packed |= (val.success & 1) << 0
+    encoder.writeUint8(packed);
+    encoder.skip(1);
+    encoder.skip(1);
+    encoder.skip(1);
+    encoder.skip(1);
+    encoder.skip(1);
+    encoder.skip(1);
+    encoder.skip(1);
+  };
   function FakeCentral_SetNextReadCharacteristicResponse_Params(values) {
     this.initDefaults_();
     this.initFields_(values);
   }
 
 
   FakeCentral_SetNextReadCharacteristicResponse_Params.prototype.initDefaults_ = function() {
     this.gattCode = 0;
@@ -3305,21 +3454,22 @@
   var kFakeCentral_SetNextGATTDiscoveryResponse_Name = 3;
   var kFakeCentral_SimulateGATTDisconnection_Name = 4;
   var kFakeCentral_SimulateGATTServicesChanged_Name = 5;
   var kFakeCentral_AddFakeService_Name = 6;
   var kFakeCentral_RemoveFakeService_Name = 7;
   var kFakeCentral_AddFakeCharacteristic_Name = 8;
   var kFakeCentral_RemoveFakeCharacteristic_Name = 9;
   var kFakeCentral_AddFakeDescriptor_Name = 10;
-  var kFakeCentral_SetNextReadCharacteristicResponse_Name = 11;
-  var kFakeCentral_SetNextWriteCharacteristicResponse_Name = 12;
-  var kFakeCentral_SetNextSubscribeToNotificationsResponse_Name = 13;
-  var kFakeCentral_GetLastWrittenValue_Name = 14;
-  var kFakeCentral_SetNextReadDescriptorResponse_Name = 15;
+  var kFakeCentral_RemoveFakeDescriptor_Name = 11;
+  var kFakeCentral_SetNextReadCharacteristicResponse_Name = 12;
+  var kFakeCentral_SetNextWriteCharacteristicResponse_Name = 13;
+  var kFakeCentral_SetNextSubscribeToNotificationsResponse_Name = 14;
+  var kFakeCentral_GetLastWrittenValue_Name = 15;
+  var kFakeCentral_SetNextReadDescriptorResponse_Name = 16;
 
   function FakeCentralPtr(handleOrPtrInfo) {
     this.ptr = new bindings.InterfacePtrController(FakeCentral,
                                                    handleOrPtrInfo);
   }
 
   function FakeCentralAssociatedPtr(associatedInterfacePtrInfo) {
     this.ptr = new associatedBindings.AssociatedInterfacePtrController(
@@ -3618,16 +3768,44 @@
         var responseParams =
             reader.decodeStruct(FakeCentral_AddFakeDescriptor_ResponseParams);
         resolve(responseParams);
       }).catch(function(result) {
         reject(Error("Connection error: " + result));
       });
     }.bind(this));
   };
+  FakeCentralPtr.prototype.removeFakeDescriptor = function() {
+    return FakeCentralProxy.prototype.removeFakeDescriptor
+        .apply(this.ptr.getProxy(), arguments);
+  };
+
+  FakeCentralProxy.prototype.removeFakeDescriptor = function(identifier, characteristicId, serviceId, peripheralAddress) {
+    var params = new FakeCentral_RemoveFakeDescriptor_Params();
+    params.identifier = identifier;
+    params.characteristicId = characteristicId;
+    params.serviceId = serviceId;
+    params.peripheralAddress = peripheralAddress;
+    return new Promise(function(resolve, reject) {
+      var builder = new codec.MessageV1Builder(
+          kFakeCentral_RemoveFakeDescriptor_Name,
+          codec.align(FakeCentral_RemoveFakeDescriptor_Params.encodedSize),
+          codec.kMessageExpectsResponse, 0);
+      builder.encodeStruct(FakeCentral_RemoveFakeDescriptor_Params, params);
+      var message = builder.finish();
+      this.receiver_.acceptAndExpectResponse(message).then(function(message) {
+        var reader = new codec.MessageReader(message);
+        var responseParams =
+            reader.decodeStruct(FakeCentral_RemoveFakeDescriptor_ResponseParams);
+        resolve(responseParams);
+      }).catch(function(result) {
+        reject(Error("Connection error: " + result));
+      });
+    }.bind(this));
+  };
   FakeCentralPtr.prototype.setNextReadCharacteristicResponse = function() {
     return FakeCentralProxy.prototype.setNextReadCharacteristicResponse
         .apply(this.ptr.getProxy(), arguments);
   };
 
   FakeCentralProxy.prototype.setNextReadCharacteristicResponse = function(gattCode, value, characteristicId, serviceId, peripheralAddress) {
     var params = new FakeCentral_SetNextReadCharacteristicResponse_Params();
     params.gattCode = gattCode;
@@ -3797,16 +3975,19 @@
     return this.delegate_ && this.delegate_.addFakeCharacteristic && this.delegate_.addFakeCharacteristic(characteristicUuid, properties, serviceId, peripheralAddress);
   }
   FakeCentralStub.prototype.removeFakeCharacteristic = function(identifier, serviceId, peripheralAddress) {
     return this.delegate_ && this.delegate_.removeFakeCharacteristic && this.delegate_.removeFakeCharacteristic(identifier, serviceId, peripheralAddress);
   }
   FakeCentralStub.prototype.addFakeDescriptor = function(descriptorUuid, characteristicId, serviceId, peripheralAddress) {
     return this.delegate_ && this.delegate_.addFakeDescriptor && this.delegate_.addFakeDescriptor(descriptorUuid, characteristicId, serviceId, peripheralAddress);
   }
+  FakeCentralStub.prototype.removeFakeDescriptor = function(identifier, characteristicId, serviceId, peripheralAddress) {
+    return this.delegate_ && this.delegate_.removeFakeDescriptor && this.delegate_.removeFakeDescriptor(identifier, characteristicId, serviceId, peripheralAddress);
+  }
   FakeCentralStub.prototype.setNextReadCharacteristicResponse = function(gattCode, value, characteristicId, serviceId, peripheralAddress) {
     return this.delegate_ && this.delegate_.setNextReadCharacteristicResponse && this.delegate_.setNextReadCharacteristicResponse(gattCode, value, characteristicId, serviceId, peripheralAddress);
   }
   FakeCentralStub.prototype.setNextWriteCharacteristicResponse = function(gattCode, characteristicId, serviceId, peripheralAddress) {
     return this.delegate_ && this.delegate_.setNextWriteCharacteristicResponse && this.delegate_.setNextWriteCharacteristicResponse(gattCode, characteristicId, serviceId, peripheralAddress);
   }
   FakeCentralStub.prototype.setNextSubscribeToNotificationsResponse = function(gattCode, characteristicId, serviceId, peripheralAddress) {
     return this.delegate_ && this.delegate_.setNextSubscribeToNotificationsResponse && this.delegate_.setNextSubscribeToNotificationsResponse(gattCode, characteristicId, serviceId, peripheralAddress);
@@ -3999,16 +4180,32 @@
             codec.align(FakeCentral_AddFakeDescriptor_ResponseParams.encodedSize),
             codec.kMessageIsResponse, reader.requestID);
         builder.encodeStruct(FakeCentral_AddFakeDescriptor_ResponseParams,
                              responseParams);
         var message = builder.finish();
         responder.accept(message);
       });
       return true;
+    case kFakeCentral_RemoveFakeDescriptor_Name:
+      var params = reader.decodeStruct(FakeCentral_RemoveFakeDescriptor_Params);
+      this.removeFakeDescriptor(params.identifier, params.characteristicId, params.serviceId, params.peripheralAddress).then(function(response) {
+        var responseParams =
+            new FakeCentral_RemoveFakeDescriptor_ResponseParams();
+        responseParams.success = response.success;
+        var builder = new codec.MessageV1Builder(
+            kFakeCentral_RemoveFakeDescriptor_Name,
+            codec.align(FakeCentral_RemoveFakeDescriptor_ResponseParams.encodedSize),
+            codec.kMessageIsResponse, reader.requestID);
+        builder.encodeStruct(FakeCentral_RemoveFakeDescriptor_ResponseParams,
+                             responseParams);
+        var message = builder.finish();
+        responder.accept(message);
+      });
+      return true;
     case kFakeCentral_SetNextReadCharacteristicResponse_Name:
       var params = reader.decodeStruct(FakeCentral_SetNextReadCharacteristicResponse_Params);
       this.setNextReadCharacteristicResponse(params.gattCode, params.value, params.characteristicId, params.serviceId, params.peripheralAddress).then(function(response) {
         var responseParams =
             new FakeCentral_SetNextReadCharacteristicResponse_ResponseParams();
         responseParams.success = response.success;
         var builder = new codec.MessageV1Builder(
             kFakeCentral_SetNextReadCharacteristicResponse_Name,
@@ -4133,16 +4330,20 @@
       case kFakeCentral_RemoveFakeCharacteristic_Name:
         if (message.expectsResponse())
           paramsClass = FakeCentral_RemoveFakeCharacteristic_Params;
       break;
       case kFakeCentral_AddFakeDescriptor_Name:
         if (message.expectsResponse())
           paramsClass = FakeCentral_AddFakeDescriptor_Params;
       break;
+      case kFakeCentral_RemoveFakeDescriptor_Name:
+        if (message.expectsResponse())
+          paramsClass = FakeCentral_RemoveFakeDescriptor_Params;
+      break;
       case kFakeCentral_SetNextReadCharacteristicResponse_Name:
         if (message.expectsResponse())
           paramsClass = FakeCentral_SetNextReadCharacteristicResponse_Params;
       break;
       case kFakeCentral_SetNextWriteCharacteristicResponse_Name:
         if (message.expectsResponse())
           paramsClass = FakeCentral_SetNextWriteCharacteristicResponse_Params;
       break;
@@ -4207,16 +4408,20 @@
       case kFakeCentral_RemoveFakeCharacteristic_Name:
         if (message.isResponse())
           paramsClass = FakeCentral_RemoveFakeCharacteristic_ResponseParams;
         break;
       case kFakeCentral_AddFakeDescriptor_Name:
         if (message.isResponse())
           paramsClass = FakeCentral_AddFakeDescriptor_ResponseParams;
         break;
+      case kFakeCentral_RemoveFakeDescriptor_Name:
+        if (message.isResponse())
+          paramsClass = FakeCentral_RemoveFakeDescriptor_ResponseParams;
+        break;
       case kFakeCentral_SetNextReadCharacteristicResponse_Name:
         if (message.isResponse())
           paramsClass = FakeCentral_SetNextReadCharacteristicResponse_ResponseParams;
         break;
       case kFakeCentral_SetNextWriteCharacteristicResponse_Name:
         if (message.isResponse())
           paramsClass = FakeCentral_SetNextWriteCharacteristicResponse_ResponseParams;
         break;
--- a/testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
+++ b/testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
@@ -439,16 +439,24 @@ class FakeRemoteGATTDescriptor {
     }
 
     let {success} =
       await this.fake_central_ptr_.setNextReadDescriptorResponse(
         gatt_code, value, ...this.ids_);
 
     if (!success) throw 'setNextReadDescriptorResponse failed';
   }
+
+  // Removes the fake GATT Descriptor from its fake characteristic.
+  async remove() {
+    let {success} =
+        await this.fake_central_ptr_.removeFakeDescriptor(...this.ids_);
+
+    if (!success) throw 'remove failed';
+  }
 }
 
 // FakeChooser allows clients to simulate events that a user would trigger when
 // using the Bluetooth chooser, and monitor the events that are produced.
 class FakeChooser {
   constructor() {
     this.fake_bluetooth_chooser_ptr_ =
         new content.mojom.FakeBluetoothChooserPtr();