Commit 0ed72da7 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa Committed by Commit Bot

sensor-helpers.js: Clean-up some of the Promise usage.

Convert some functions that explicitly returned resolved promises into async
ones, and drop |reject| from promise functions that only use |resolve|.

Bug: 987639
Change-Id: I77193e6f19f724848707e8b7e9f012eedda7c267
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1718374
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681344}
parent 5d573aa2
...@@ -18,11 +18,6 @@ class CallbackWrapper { ...@@ -18,11 +18,6 @@ class CallbackWrapper {
} }
function sensorMocks() { function sensorMocks() {
// Helper function that returns resolved promise with result.
function sensorResponse(success) {
return Promise.resolve({success});
}
// Class that mocks Sensor interface defined in sensor.mojom // Class that mocks Sensor interface defined in sensor.mojom
class MockSensor { class MockSensor {
constructor(sensorRequest, handle, offset, size, reportingMode) { constructor(sensorRequest, handle, offset, size, reportingMode) {
...@@ -50,13 +45,13 @@ function sensorMocks() { ...@@ -50,13 +45,13 @@ function sensorMocks() {
} }
// Returns default configuration. // Returns default configuration.
getDefaultConfiguration() { async getDefaultConfiguration() {
return Promise.resolve({frequency: 5}); return { frequency: 5 };
} }
// Adds configuration for the sensor and starts reporting fake data // Adds configuration for the sensor and starts reporting fake data
// through setSensorReading function. // through setSensorReading function.
addConfiguration(configuration) { async addConfiguration(configuration) {
assert_not_equals(configuration, null, "Invalid sensor configuration."); assert_not_equals(configuration, null, "Invalid sensor configuration.");
this.requestedFrequencies_.push(configuration.frequency); this.requestedFrequencies_.push(configuration.frequency);
...@@ -70,7 +65,7 @@ function sensorMocks() { ...@@ -70,7 +65,7 @@ function sensorMocks() {
if (this.addConfigurationCalled_ != null) if (this.addConfigurationCalled_ != null)
this.addConfigurationCalled_(this); this.addConfigurationCalled_(this);
return sensorResponse(!this.startShouldFail_); return { success: !this.startShouldFail_ };
} }
// Removes sensor configuration from the list of active configurations and // Removes sensor configuration from the list of active configurations and
...@@ -134,9 +129,9 @@ function sensorMocks() { ...@@ -134,9 +129,9 @@ function sensorMocks() {
} }
// Sets fake data that is used to deliver sensor reading updates. // Sets fake data that is used to deliver sensor reading updates.
setSensorReading(readingData) { async setSensorReading(readingData) {
this.readingData_ = readingData; this.readingData_ = readingData;
return Promise.resolve(this); return this;
} }
// Sets flag that forces sensor to fail when addConfiguration is invoked. // Sets flag that forces sensor to fail when addConfiguration is invoked.
...@@ -152,28 +147,28 @@ function sensorMocks() { ...@@ -152,28 +147,28 @@ function sensorMocks() {
// Returns resolved promise if suspend() was called, rejected otherwise. // Returns resolved promise if suspend() was called, rejected otherwise.
suspendCalled() { suspendCalled() {
return new Promise((resolve, reject) => { return new Promise(resolve => {
this.suspendCalled_ = resolve; this.suspendCalled_ = resolve;
}); });
} }
// Returns resolved promise if resume() was called, rejected otherwise. // Returns resolved promise if resume() was called, rejected otherwise.
resumeCalled() { resumeCalled() {
return new Promise((resolve, reject) => { return new Promise(resolve => {
this.resumeCalled_ = resolve; this.resumeCalled_ = resolve;
}); });
} }
// Resolves promise when addConfiguration() is called. // Resolves promise when addConfiguration() is called.
addConfigurationCalled() { addConfigurationCalled() {
return new Promise((resolve, reject) => { return new Promise(resolve => {
this.addConfigurationCalled_ = resolve; this.addConfigurationCalled_ = resolve;
}); });
} }
// Resolves promise when removeConfiguration() is called. // Resolves promise when removeConfiguration() is called.
removeConfigurationCalled() { removeConfigurationCalled() {
return new Promise((resolve, reject) => { return new Promise(resolve => {
this.removeConfigurationCalled_ = resolve; this.removeConfigurationCalled_ = resolve;
}); });
} }
...@@ -209,7 +204,6 @@ function sensorMocks() { ...@@ -209,7 +204,6 @@ function sensorMocks() {
assert_true(this.requestedFrequencies_.length > 0); assert_true(this.requestedFrequencies_.length > 0);
return this.requestedFrequencies_[0]; return this.requestedFrequencies_[0];
} }
} }
// Class that mocks SensorProvider interface defined in // Class that mocks SensorProvider interface defined in
...@@ -357,7 +351,7 @@ function sensorMocks() { ...@@ -357,7 +351,7 @@ function sensorMocks() {
return Promise.resolve(this.activeSensors_.get(type)); return Promise.resolve(this.activeSensors_.get(type));
} }
return new Promise((resolve, reject) => { return new Promise(resolve => {
if (!this.resolveFuncs_.has(type)) { if (!this.resolveFuncs_.has(type)) {
this.resolveFuncs_.set(type, []); this.resolveFuncs_.set(type, []);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment