Skip to content

Commit

Permalink
Modify ProximitySensor tests (#19214)
Browse files Browse the repository at this point in the history
* Modify ProximitySensor tests

- Support mock sensor
- Add verifyProSensorReading function
  • Loading branch information
xiuqijix authored and Raphael Kubo da Costa committed Sep 27, 2019
1 parent c3c56f5 commit ccd18e2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
9 changes: 8 additions & 1 deletion generic-sensor/resources/generic-sensor-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ function sensor_test(func, name, properties) {
}

function verifySensorReading(pattern, values, timestamp, isNull) {
// If |val| cannot be converted to a float, we return the original value.
// This can happen when a value in |pattern| is not a number.
function round(val) {
return Number.parseFloat(val).toPrecision(6);
const res = Number.parseFloat(val).toPrecision(6);
return res === "NaN" ? val : res;
}

if (isNull) {
Expand Down Expand Up @@ -92,6 +95,10 @@ function verifyGeoSensorReading(pattern, {latitude, longitude, altitude,
accuracy, altitudeAccuracy, heading, speed], timestamp, isNull);
}

function verifyProximitySensorReading(pattern, {distance, max, near, timestamp}, isNull) {
return verifySensorReading(pattern, [distance, max, near], timestamp, isNull);
}

// A "sliding window" that iterates over |data| and returns one item at a
// time, advancing and wrapping around as needed. |data| must be an array of
// arrays.
Expand Down
2 changes: 1 addition & 1 deletion proximity/ProximitySensor-iframe-access.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="help" href="https://w3c.github.io/proximity/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/generic-sensor/generic-sensor-tests.js"></script>
<script src="/generic-sensor/resources/generic-sensor-helpers.js"></script>
<script src="/generic-sensor/generic-sensor-iframe-tests.sub.js"></script>
<script src="/generic-sensor/generic-sensor-feature-policy-test.sub.js"></script>
<div id="log"></div>
Expand Down
22 changes: 20 additions & 2 deletions proximity/ProximitySensor.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@
<link rel="help" href="https://w3c.github.io/proximity/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/generic-sensor/resources/generic-sensor-helpers.js"></script>
<script src="/generic-sensor/generic-sensor-tests.js"></script>
<div id="log"></div>

<script>

runGenericSensorTests('ProximitySensor');
'use strict';

// near: 0 stands for false, 1 stands for true, which will be convert to boolean
// in mock sensor
const kReadings = {
readings: [
[1.12345, 2.12345, 1]
],
expectedReadings: [
[1.12345, 2.12345, true]
]
};

runGenericSensorTests(
'ProximitySensor',
kReadings,
verifyProximitySensorReading,
['proximity']);

</script>
20 changes: 0 additions & 20 deletions proximity/ProximitySensor_onerror-manual.https.html

This file was deleted.

3 changes: 2 additions & 1 deletion resources/chromium/generic_sensor_mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ var GenericSensorTest = (() => {
['RelativeOrientationSensor',
device.mojom.SensorType.RELATIVE_ORIENTATION_QUATERNION],
['RelativeOrientationEulerAngles',
device.mojom.SensorType.RELATIVE_ORIENTATION_EULER_ANGLES]
device.mojom.SensorType.RELATIVE_ORIENTATION_EULER_ANGLES],
['ProximitySensor', device.mojom.SensorType.PROXIMITY]
]);
this.binding_ = new mojo.Binding(device.mojom.SensorProvider, this);

Expand Down

0 comments on commit ccd18e2

Please sign in to comment.