Bug 1449737 [wpt PR 10223] - Revert "bluetooth: FakeBluetoothChooser impl.", a=testonly
authorFrançois Doray <fdoray@chromium.org>
Mon, 09 Apr 2018 18:26:03 +0000
changeset 467213 c5d8e8a1bde77ee37963d564ed1b880799a827ff
parent 467212 462919f2fedc343b3292252b9a817f0d1848a72d
child 467214 f33779c9c5725285f27d1a3c4ce565b4392b1768
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
bugs1449737, 10223, 826787, 719827, 719826, 824704, 962983, 546509, 984299, 546572
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 1449737 [wpt PR 10223] - Revert "bluetooth: FakeBluetoothChooser impl.", a=testonly Automatic update from web-platform-testsRevert "bluetooth: FakeBluetoothChooser impl." This reverts commit 188adfb51a7c4ca1ab0cbeaffdec4f7cd76857f7. Reason for revert: https://crbug.com/826787 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. > > BUG=719827,719826,824704 > > Change-Id: I56a04e6bdb2de38d9163d7bc350db578deeb9ba3 > Reviewed-on: https://chromium-review.googlesource.com/962983 > Reviewed-by: Daniel Cheng <dcheng@chromium.org> > Reviewed-by: Conley Owens <cco3@chromium.org> > Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org> > Commit-Queue: Ovidio Henriquez <odejesush@chromium.org> > Cr-Commit-Position: refs/heads/master@{#546509} TBR=dcheng@chromium.org,cco3@chromium.org,ortuno@chromium.org,odejesush@chromium.org Change-Id: I0597151ec5878d41ac631b72296203bc99b1f2c8 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: 719827, 719826, 824704, 826787 Reviewed-on: https://chromium-review.googlesource.com/984299 Commit-Queue: François Doray <fdoray@chromium.org> Reviewed-by: François Doray <fdoray@chromium.org> Cr-Commit-Position: refs/heads/master@{#546572} wpt-commits: d5fea759ccb42cb19ed8553b99e74165fbfa79bb wpt-pr: 10223 wpt-commits: d5fea759ccb42cb19ed8553b99e74165fbfa79bb wpt-pr: 10223
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
@@ -402619,17 +402619,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 = 1621859352;
-  var kFakeBluetoothChooser_SelectPeripheral_Name = 2020261727;
-  var kFakeBluetoothChooser_Cancel_Name = 1853602100;
-  var kFakeBluetoothChooser_Rescan_Name = 1622289967;
+  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 ' +