Bug 1449999 [wpt PR 10242] - Revert "bluetooth: FakeBluetoothChooser impl.", a=testonly
authorFrançois Doray <fdoray@chromium.org>
Mon, 09 Apr 2018 18:34:11 +0000
changeset 467231 b9ec8ae030bea685aeca96d4a375dfdfdd2c1420
parent 467230 febe2a9b5189fcafcddd96ad10f865cea1b48859
child 467232 af731bdba5037619bd3d5ba61898652df1f1c49d
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
bugs1449999, 10242, 824704, 719827, 719826, 826787, 985195, 546729, 986592, 546851
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 1449999 [wpt PR 10242] - Revert "bluetooth: FakeBluetoothChooser impl.", a=testonly Automatic update from web-platform-testsRevert "bluetooth: FakeBluetoothChooser impl." This reverts commit 6a337f19713e049cd42969b0c909c59aff4146cd. Reason for revert: https://crbug.com/824704 These tests are failing: external/wpt/bluetooth/server/getPrimaryServices/blocklisted-services-with-uuid.https.html external/wpt/bluetooth/server/getPrimaryServices/blocklisted-services.https.html external/wpt/bluetooth/service/getCharacteristic/gen-blocklisted-characteristic.https.html external/wpt/bluetooth/service/getCharacteristics/blocklisted-characteristics.https.html external/wpt/bluetooth/service/getCharacteristics/gen-blocklisted-characteristic-with-uuid.https.html Original change's description: > bluetooth: FakeBluetoothChooser impl. > > Implements the interfaces that FakeBluetoothChooser overrides. The > mojom::FakeBluetoothChooser overrides are implemented by running > |event_handler_| with the appropriate arguments. The BluetoothChooser > overrides do nothing at the moment, since the base class is only meant > to update the chooser user interface. > > This change also begins to partially convert a Bluetooth chooser test to test > the interface and deletes the temporary tests that were created to test this > API. > > This change reverts commit 42624492cd5e80855f1dd3a5a8146b258def2c2a, which > reverted the original change. The original change caused the > new-scan-device-added.html test to fail because of a Mojo validation error > resulting from not updating the > third_party/.../external/wpt/resources/chromium/fake_bluetooth_chooser.mojom.js > file needed by the test. > > Bug: 719827, 719826, 824704, 826787 > Change-Id: I5e5cce7e809b4d71216c2d074a417ea822d5e527 > Reviewed-on: https://chromium-review.googlesource.com/985195 > Commit-Queue: Ovidio Henriquez <odejesush@chromium.org> > Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org> > Reviewed-by: Daniel Cheng <dcheng@chromium.org> > Cr-Commit-Position: refs/heads/master@{#546729} TBR=dcheng@chromium.org,cco3@chromium.org,ortuno@chromium.org,odejesush@chromium.org Change-Id: Ie2ef2af1ae74e8dd5ca01441027adaa59e6e0c0f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: 719827, 719826, 824704, 826787 Reviewed-on: https://chromium-review.googlesource.com/986592 Reviewed-by: François Doray <fdoray@chromium.org> Commit-Queue: François Doray <fdoray@chromium.org> Cr-Commit-Position: refs/heads/master@{#546851} wpt-commits: 709111adbc503d82692ae71f2397eda8bef635f2 wpt-pr: 10242 wpt-commits: 709111adbc503d82692ae71f2397eda8bef635f2 wpt-pr: 10242
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/bluetooth/resources/bluetooth-helpers.js
testing/web-platform/tests/resources/chromium/fake_bluetooth_chooser.mojom.js
testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -402652,17 +402652,17 @@
    "2bf20db77582e6df2674dd0a5cf444d630b3b999",
    "testharness"
   ],
   "bluetooth/requestDevice/single-filter-single-service.https.html": [
    "f147182b894cbb0f338111b146dfa16193610265",
    "testharness"
   ],
   "bluetooth/resources/bluetooth-helpers.js": [
-   "e4d7f8127e43e68b75e3103c6832c3c867a8bd9c",
+   "9d2b233c511627f6a4fe93bdaf16ba28c4a6ead9",
    "support"
   ],
   "bluetooth/resources/health-thermometer-iframe.html": [
    "f175a62907e65c03e326832449b0b8e3276387d8",
    "support"
   ],
   "bluetooth/script-tests/base_test_html.template": [
    "abe5c81d5d9be9b0c6069ba0a465ca3efc24b442",
--- a/testing/web-platform/tests/bluetooth/resources/bluetooth-helpers.js
+++ b/testing/web-platform/tests/bluetooth/resources/bluetooth-helpers.js
@@ -472,25 +472,16 @@ function setUpPreconnectedDevice({
   return navigator.bluetooth.test.simulateCentral({state: 'powered-on'})
     .then(fake_central => fake_central.simulatePreconnectedPeripheral({
       address: address,
       name: name,
       knownServiceUUIDs: knownServiceUUIDs,
     }));
 }
 
-const health_thermometer_ad_packet = {
-  deviceAddress: '09:09:09:09:09:09',
-  rssi: -10,
-  scanRecord: {
-    name: 'Health Thermometer',
-    uuids: [health_thermometer.uuid],
-  },
-};
-
 // Returns a FakePeripheral that corresponds to a simulated pre-connected device
 // called 'Health Thermometer'. The device has two known serviceUUIDs:
 // 'generic_access' and 'health_thermometer'.
 function setUpHealthThermometerDevice() {
   return setUpPreconnectedDevice({
     address: '09:09:09:09:09:09',
     name: 'Health Thermometer',
     knownServiceUUIDs: ['generic_access', 'health_thermometer'],
--- a/testing/web-platform/tests/resources/chromium/fake_bluetooth_chooser.mojom.js
+++ b/testing/web-platform/tests/resources/chromium/fake_bluetooth_chooser.mojom.js
@@ -300,16 +300,62 @@
   };
 
   FakeBluetoothChooser_SelectPeripheral_Params.encode = function(encoder, val) {
     var packed;
     encoder.writeUint32(FakeBluetoothChooser_SelectPeripheral_Params.encodedSize);
     encoder.writeUint32(0);
     encoder.encodeStruct(codec.String, val.peripheralAddress);
   };
+  function FakeBluetoothChooser_SelectPeripheral_ResponseParams(values) {
+    this.initDefaults_();
+    this.initFields_(values);
+  }
+
+
+  FakeBluetoothChooser_SelectPeripheral_ResponseParams.prototype.initDefaults_ = function() {
+  };
+  FakeBluetoothChooser_SelectPeripheral_ResponseParams.prototype.initFields_ = function(fields) {
+    for(var field in fields) {
+        if (this.hasOwnProperty(field))
+          this[field] = fields[field];
+    }
+  };
+
+  FakeBluetoothChooser_SelectPeripheral_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: 8}
+    ];
+    err = messageValidator.validateStructVersion(offset, kVersionSizes);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+    return validator.validationError.NONE;
+  };
+
+  FakeBluetoothChooser_SelectPeripheral_ResponseParams.encodedSize = codec.kStructHeaderSize + 0;
+
+  FakeBluetoothChooser_SelectPeripheral_ResponseParams.decode = function(decoder) {
+    var packed;
+    var val = new FakeBluetoothChooser_SelectPeripheral_ResponseParams();
+    var numberOfBytes = decoder.readUint32();
+    var version = decoder.readUint32();
+    return val;
+  };
+
+  FakeBluetoothChooser_SelectPeripheral_ResponseParams.encode = function(encoder, val) {
+    var packed;
+    encoder.writeUint32(FakeBluetoothChooser_SelectPeripheral_ResponseParams.encodedSize);
+    encoder.writeUint32(0);
+  };
   function FakeBluetoothChooser_Cancel_Params(values) {
     this.initDefaults_();
     this.initFields_(values);
   }
 
 
   FakeBluetoothChooser_Cancel_Params.prototype.initDefaults_ = function() {
   };
@@ -346,16 +392,62 @@
     return val;
   };
 
   FakeBluetoothChooser_Cancel_Params.encode = function(encoder, val) {
     var packed;
     encoder.writeUint32(FakeBluetoothChooser_Cancel_Params.encodedSize);
     encoder.writeUint32(0);
   };
+  function FakeBluetoothChooser_Cancel_ResponseParams(values) {
+    this.initDefaults_();
+    this.initFields_(values);
+  }
+
+
+  FakeBluetoothChooser_Cancel_ResponseParams.prototype.initDefaults_ = function() {
+  };
+  FakeBluetoothChooser_Cancel_ResponseParams.prototype.initFields_ = function(fields) {
+    for(var field in fields) {
+        if (this.hasOwnProperty(field))
+          this[field] = fields[field];
+    }
+  };
+
+  FakeBluetoothChooser_Cancel_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: 8}
+    ];
+    err = messageValidator.validateStructVersion(offset, kVersionSizes);
+    if (err !== validator.validationError.NONE)
+        return err;
+
+    return validator.validationError.NONE;
+  };
+
+  FakeBluetoothChooser_Cancel_ResponseParams.encodedSize = codec.kStructHeaderSize + 0;
+
+  FakeBluetoothChooser_Cancel_ResponseParams.decode = function(decoder) {
+    var packed;
+    var val = new FakeBluetoothChooser_Cancel_ResponseParams();
+    var numberOfBytes = decoder.readUint32();
+    var version = decoder.readUint32();
+    return val;
+  };
+
+  FakeBluetoothChooser_Cancel_ResponseParams.encode = function(encoder, val) {
+    var packed;
+    encoder.writeUint32(FakeBluetoothChooser_Cancel_ResponseParams.encodedSize);
+    encoder.writeUint32(0);
+  };
   function FakeBluetoothChooser_Rescan_Params(values) {
     this.initDefaults_();
     this.initFields_(values);
   }
 
 
   FakeBluetoothChooser_Rescan_Params.prototype.initDefaults_ = function() {
   };
@@ -438,20 +530,20 @@
     return val;
   };
 
   FakeBluetoothChooser_Rescan_ResponseParams.encode = function(encoder, val) {
     var packed;
     encoder.writeUint32(FakeBluetoothChooser_Rescan_ResponseParams.encodedSize);
     encoder.writeUint32(0);
   };
-  var kFakeBluetoothChooser_WaitForEvents_Name = 1899695487;
-  var kFakeBluetoothChooser_SelectPeripheral_Name = 728735403;
-  var kFakeBluetoothChooser_Cancel_Name = 246208861;
-  var kFakeBluetoothChooser_Rescan_Name = 1031326211;
+  var kFakeBluetoothChooser_WaitForEvents_Name = 457051710;
+  var kFakeBluetoothChooser_SelectPeripheral_Name = 1924310743;
+  var kFakeBluetoothChooser_Cancel_Name = 1388880682;
+  var kFakeBluetoothChooser_Rescan_Name = 2112671529;
 
   function FakeBluetoothChooserPtr(handleOrPtrInfo) {
     this.ptr = new bindings.InterfacePtrController(FakeBluetoothChooser,
                                                    handleOrPtrInfo);
   }
 
   function FakeBluetoothChooserAssociatedPtr(associatedInterfacePtrInfo) {
     this.ptr = new associatedBindings.AssociatedInterfacePtrController(
@@ -494,36 +586,56 @@
   FakeBluetoothChooserPtr.prototype.selectPeripheral = function() {
     return FakeBluetoothChooserProxy.prototype.selectPeripheral
         .apply(this.ptr.getProxy(), arguments);
   };
 
   FakeBluetoothChooserProxy.prototype.selectPeripheral = function(peripheralAddress) {
     var params = new FakeBluetoothChooser_SelectPeripheral_Params();
     params.peripheralAddress = peripheralAddress;
-    var builder = new codec.MessageV0Builder(
-        kFakeBluetoothChooser_SelectPeripheral_Name,
-        codec.align(FakeBluetoothChooser_SelectPeripheral_Params.encodedSize));
-    builder.encodeStruct(FakeBluetoothChooser_SelectPeripheral_Params, params);
-    var message = builder.finish();
-    this.receiver_.accept(message);
+    return new Promise(function(resolve, reject) {
+      var builder = new codec.MessageV1Builder(
+          kFakeBluetoothChooser_SelectPeripheral_Name,
+          codec.align(FakeBluetoothChooser_SelectPeripheral_Params.encodedSize),
+          codec.kMessageExpectsResponse, 0);
+      builder.encodeStruct(FakeBluetoothChooser_SelectPeripheral_Params, params);
+      var message = builder.finish();
+      this.receiver_.acceptAndExpectResponse(message).then(function(message) {
+        var reader = new codec.MessageReader(message);
+        var responseParams =
+            reader.decodeStruct(FakeBluetoothChooser_SelectPeripheral_ResponseParams);
+        resolve(responseParams);
+      }).catch(function(result) {
+        reject(Error("Connection error: " + result));
+      });
+    }.bind(this));
   };
   FakeBluetoothChooserPtr.prototype.cancel = function() {
     return FakeBluetoothChooserProxy.prototype.cancel
         .apply(this.ptr.getProxy(), arguments);
   };
 
   FakeBluetoothChooserProxy.prototype.cancel = function() {
     var params = new FakeBluetoothChooser_Cancel_Params();
-    var builder = new codec.MessageV0Builder(
-        kFakeBluetoothChooser_Cancel_Name,
-        codec.align(FakeBluetoothChooser_Cancel_Params.encodedSize));
-    builder.encodeStruct(FakeBluetoothChooser_Cancel_Params, params);
-    var message = builder.finish();
-    this.receiver_.accept(message);
+    return new Promise(function(resolve, reject) {
+      var builder = new codec.MessageV1Builder(
+          kFakeBluetoothChooser_Cancel_Name,
+          codec.align(FakeBluetoothChooser_Cancel_Params.encodedSize),
+          codec.kMessageExpectsResponse, 0);
+      builder.encodeStruct(FakeBluetoothChooser_Cancel_Params, params);
+      var message = builder.finish();
+      this.receiver_.acceptAndExpectResponse(message).then(function(message) {
+        var reader = new codec.MessageReader(message);
+        var responseParams =
+            reader.decodeStruct(FakeBluetoothChooser_Cancel_ResponseParams);
+        resolve(responseParams);
+      }).catch(function(result) {
+        reject(Error("Connection error: " + result));
+      });
+    }.bind(this));
   };
   FakeBluetoothChooserPtr.prototype.rescan = function() {
     return FakeBluetoothChooserProxy.prototype.rescan
         .apply(this.ptr.getProxy(), arguments);
   };
 
   FakeBluetoothChooserProxy.prototype.rescan = function() {
     var params = new FakeBluetoothChooser_Rescan_Params();
@@ -559,24 +671,16 @@
   }
   FakeBluetoothChooserStub.prototype.rescan = function() {
     return this.delegate_ && this.delegate_.rescan && this.delegate_.rescan();
   }
 
   FakeBluetoothChooserStub.prototype.accept = function(message) {
     var reader = new codec.MessageReader(message);
     switch (reader.messageName) {
-    case kFakeBluetoothChooser_SelectPeripheral_Name:
-      var params = reader.decodeStruct(FakeBluetoothChooser_SelectPeripheral_Params);
-      this.selectPeripheral(params.peripheralAddress);
-      return true;
-    case kFakeBluetoothChooser_Cancel_Name:
-      var params = reader.decodeStruct(FakeBluetoothChooser_Cancel_Params);
-      this.cancel();
-      return true;
     default:
       return false;
     }
   };
 
   FakeBluetoothChooserStub.prototype.acceptWithResponder =
       function(message, responder) {
     var reader = new codec.MessageReader(message);
@@ -592,16 +696,46 @@
             codec.align(FakeBluetoothChooser_WaitForEvents_ResponseParams.encodedSize),
             codec.kMessageIsResponse, reader.requestID);
         builder.encodeStruct(FakeBluetoothChooser_WaitForEvents_ResponseParams,
                              responseParams);
         var message = builder.finish();
         responder.accept(message);
       });
       return true;
+    case kFakeBluetoothChooser_SelectPeripheral_Name:
+      var params = reader.decodeStruct(FakeBluetoothChooser_SelectPeripheral_Params);
+      this.selectPeripheral(params.peripheralAddress).then(function(response) {
+        var responseParams =
+            new FakeBluetoothChooser_SelectPeripheral_ResponseParams();
+        var builder = new codec.MessageV1Builder(
+            kFakeBluetoothChooser_SelectPeripheral_Name,
+            codec.align(FakeBluetoothChooser_SelectPeripheral_ResponseParams.encodedSize),
+            codec.kMessageIsResponse, reader.requestID);
+        builder.encodeStruct(FakeBluetoothChooser_SelectPeripheral_ResponseParams,
+                             responseParams);
+        var message = builder.finish();
+        responder.accept(message);
+      });
+      return true;
+    case kFakeBluetoothChooser_Cancel_Name:
+      var params = reader.decodeStruct(FakeBluetoothChooser_Cancel_Params);
+      this.cancel().then(function(response) {
+        var responseParams =
+            new FakeBluetoothChooser_Cancel_ResponseParams();
+        var builder = new codec.MessageV1Builder(
+            kFakeBluetoothChooser_Cancel_Name,
+            codec.align(FakeBluetoothChooser_Cancel_ResponseParams.encodedSize),
+            codec.kMessageIsResponse, reader.requestID);
+        builder.encodeStruct(FakeBluetoothChooser_Cancel_ResponseParams,
+                             responseParams);
+        var message = builder.finish();
+        responder.accept(message);
+      });
+      return true;
     case kFakeBluetoothChooser_Rescan_Name:
       var params = reader.decodeStruct(FakeBluetoothChooser_Rescan_Params);
       this.rescan().then(function(response) {
         var responseParams =
             new FakeBluetoothChooser_Rescan_ResponseParams();
         var builder = new codec.MessageV1Builder(
             kFakeBluetoothChooser_Rescan_Name,
             codec.align(FakeBluetoothChooser_Rescan_ResponseParams.encodedSize),
@@ -621,21 +755,21 @@
     var message = messageValidator.message;
     var paramsClass = null;
     switch (message.getName()) {
       case kFakeBluetoothChooser_WaitForEvents_Name:
         if (message.expectsResponse())
           paramsClass = FakeBluetoothChooser_WaitForEvents_Params;
       break;
       case kFakeBluetoothChooser_SelectPeripheral_Name:
-        if (!message.expectsResponse() && !message.isResponse())
+        if (message.expectsResponse())
           paramsClass = FakeBluetoothChooser_SelectPeripheral_Params;
       break;
       case kFakeBluetoothChooser_Cancel_Name:
-        if (!message.expectsResponse() && !message.isResponse())
+        if (message.expectsResponse())
           paramsClass = FakeBluetoothChooser_Cancel_Params;
       break;
       case kFakeBluetoothChooser_Rescan_Name:
         if (message.expectsResponse())
           paramsClass = FakeBluetoothChooser_Rescan_Params;
       break;
     }
     if (paramsClass === null)
@@ -646,16 +780,24 @@
   function validateFakeBluetoothChooserResponse(messageValidator) {
    var message = messageValidator.message;
    var paramsClass = null;
    switch (message.getName()) {
       case kFakeBluetoothChooser_WaitForEvents_Name:
         if (message.isResponse())
           paramsClass = FakeBluetoothChooser_WaitForEvents_ResponseParams;
         break;
+      case kFakeBluetoothChooser_SelectPeripheral_Name:
+        if (message.isResponse())
+          paramsClass = FakeBluetoothChooser_SelectPeripheral_ResponseParams;
+        break;
+      case kFakeBluetoothChooser_Cancel_Name:
+        if (message.isResponse())
+          paramsClass = FakeBluetoothChooser_Cancel_ResponseParams;
+        break;
       case kFakeBluetoothChooser_Rescan_Name:
         if (message.isResponse())
           paramsClass = FakeBluetoothChooser_Rescan_ResponseParams;
         break;
     }
     if (paramsClass === null)
       return validator.validationError.NONE;
     return paramsClass.validate(messageValidator, messageValidator.message.getHeaderNumBytes());
--- a/testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
+++ b/testing/web-platform/tests/resources/chromium/web-bluetooth-test.js
@@ -484,31 +484,16 @@ class FakeRemoteGATTDescriptor {
 // using the Bluetooth chooser, and monitor the events that are produced.
 class FakeChooser {
   constructor() {
     this.fake_bluetooth_chooser_ptr_ =
         new content.mojom.FakeBluetoothChooserPtr();
     Mojo.bindInterface(content.mojom.FakeBluetoothChooser.name,
         mojo.makeRequest(this.fake_bluetooth_chooser_ptr_).handle, 'process');
   }
-
-  async selectPeripheral(peripheral) {
-    if (!(peripheral instanceof FakePeripheral)) {
-      throw '|peripheral| must be an instance of FakePeripheral';
-    }
-    await this.fake_bluetooth_chooser_ptr_.selectPeripheral(peripheral.address);
-  }
-
-  async cancel() {
-    await this.fake_bluetooth_chooser_ptr_.cancel();
-  }
-
-  async rescan() {
-    await this.fake_bluetooth_chooser_ptr_.rescan();
-  }
 }
 
 // If this line fails, it means that current environment does not support the
 // Web Bluetooth Test API.
 try {
   navigator.bluetooth.test = new FakeBluetooth();
 } catch {
     throw 'Web Bluetooth Test API is not implemented on this ' +