Skip to content

Commit

Permalink
Revert "bluetooth: FakeBluetoothChooser impl."
Browse files Browse the repository at this point in the history
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 <[email protected]>
> Reviewed-by: Conley Owens <[email protected]>
> Reviewed-by: Giovanni Ortuño Urquidi <[email protected]>
> Commit-Queue: Ovidio Henriquez <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#546509}

[email protected],[email protected],[email protected],[email protected]

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 <[email protected]>
Reviewed-by: François Doray <[email protected]>
Cr-Commit-Position: refs/heads/master@{#546572}
  • Loading branch information
fdoray authored and foolip committed Mar 28, 2018
1 parent c2cd757 commit d5fea75
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 50 deletions.
9 changes: 0 additions & 9 deletions bluetooth/resources/bluetooth-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,6 @@ function setUpPreconnectedDevice({
}));
}

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'.
Expand Down
194 changes: 168 additions & 26 deletions resources/chromium/fake_bluetooth_chooser.mojom.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,52 @@
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);
Expand Down Expand Up @@ -351,6 +397,52 @@
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);
Expand Down Expand Up @@ -443,10 +535,10 @@
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,
Expand Down Expand Up @@ -499,12 +591,22 @@
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
Expand All @@ -513,12 +615,22 @@

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
Expand Down Expand Up @@ -564,14 +676,6 @@
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;
}
Expand All @@ -597,6 +701,36 @@
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) {
Expand Down Expand Up @@ -626,11 +760,11 @@
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:
Expand All @@ -651,6 +785,14 @@
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;
Expand Down
15 changes: 0 additions & 15 deletions resources/chromium/web-bluetooth-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,21 +489,6 @@ class FakeChooser {
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
Expand Down

0 comments on commit d5fea75

Please sign in to comment.