From ccd18e2437e2d2c1434bd0e9f4aca07796e01427 Mon Sep 17 00:00:00 2001 From: kaixinjxq Date: Sat, 28 Sep 2019 02:27:56 +0800 Subject: [PATCH] Modify ProximitySensor tests (#19214) * Modify ProximitySensor tests - Support mock sensor - Add verifyProSensorReading function --- .../resources/generic-sensor-helpers.js | 9 +++++++- .../ProximitySensor-iframe-access.https.html | 2 +- proximity/ProximitySensor.https.html | 22 +++++++++++++++++-- .../ProximitySensor_onerror-manual.https.html | 20 ----------------- resources/chromium/generic_sensor_mocks.js | 3 ++- 5 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 proximity/ProximitySensor_onerror-manual.https.html diff --git a/generic-sensor/resources/generic-sensor-helpers.js b/generic-sensor/resources/generic-sensor-helpers.js index 8302f6f6cfbc77..afc2fadec9d8da 100644 --- a/generic-sensor/resources/generic-sensor-helpers.js +++ b/generic-sensor/resources/generic-sensor-helpers.js @@ -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) { @@ -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. diff --git a/proximity/ProximitySensor-iframe-access.https.html b/proximity/ProximitySensor-iframe-access.https.html index 016ae48eb9824f..0ceba805be3ae0 100644 --- a/proximity/ProximitySensor-iframe-access.https.html +++ b/proximity/ProximitySensor-iframe-access.https.html @@ -5,7 +5,7 @@ - +
diff --git a/proximity/ProximitySensor.https.html b/proximity/ProximitySensor.https.html index 03db98e7d0dc18..648071382552fd 100644 --- a/proximity/ProximitySensor.https.html +++ b/proximity/ProximitySensor.https.html @@ -5,10 +5,28 @@ + -
+ diff --git a/proximity/ProximitySensor_onerror-manual.https.html b/proximity/ProximitySensor_onerror-manual.https.html deleted file mode 100644 index 7e506f0482e144..00000000000000 --- a/proximity/ProximitySensor_onerror-manual.https.html +++ /dev/null @@ -1,20 +0,0 @@ - - -ProximitySensor Test: onerror - - - - - -
-

Precondition

-
    -
  1. - Disable the Proximity Sensor or run test on a device without Proximity Sensor. -
  2. -
- diff --git a/resources/chromium/generic_sensor_mocks.js b/resources/chromium/generic_sensor_mocks.js index 4f1370236876f4..a7272a65fa3e7f 100644 --- a/resources/chromium/generic_sensor_mocks.js +++ b/resources/chromium/generic_sensor_mocks.js @@ -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);