diff --git a/testing/web-platform/tests/generic-sensor/generic-sensor-tests.js b/testing/web-platform/tests/generic-sensor/generic-sensor-tests.js index 1779fd6bb5923..f0d37fb9f24b6 100644 --- a/testing/web-platform/tests/generic-sensor/generic-sensor-tests.js +++ b/testing/web-platform/tests/generic-sensor/generic-sensor-tests.js @@ -246,12 +246,15 @@ function runGenericSensorTests(sensorName, assert_true(verificationFunction(expected, sensor2, /*isNull=*/true)); }, `${sensorName}: sensor reading is correct.`); - sensor_test(async t => { + sensor_test(async (t, sensorProvider) => { assert_true(sensorName in self); const sensor = new sensorType(); const sensorWatcher = new EventWatcher(t, sensor, ["reading", "error"]); sensor.start(); + const mockSensor = await sensorProvider.getCreatedSensor(sensorName); + await mockSensor.setSensorReading(readings); + await sensorWatcher.wait_for("reading"); const cachedTimeStamp1 = sensor.timestamp; @@ -392,6 +395,7 @@ function runGenericSensorTests(sensorName, fastSensor.start(); const mockSensor = await sensorProvider.getCreatedSensor(sensorName); + await mockSensor.setSensorReading(readings); const fastCounter = await new Promise((resolve, reject) => { let fastSensorNotifiedCounter = 0; diff --git a/testing/web-platform/tests/resources/chromium/generic_sensor_mocks.js b/testing/web-platform/tests/resources/chromium/generic_sensor_mocks.js index eb28c48d3a719..5e902f2523dd6 100644 --- a/testing/web-platform/tests/resources/chromium/generic_sensor_mocks.js +++ b/testing/web-platform/tests/resources/chromium/generic_sensor_mocks.js @@ -199,6 +199,19 @@ var GenericSensorTest = (() => { this.maxFrequency_ = Math.min(10, this.maxFrequency_); } + // Chromium applies some rounding and other privacy-related measures that + // can cause ALS not to report a reading when it has not changed beyond a + // certain threshold compared to the previous illuminance value. Make + // each reading return a different value that is significantly different + // from the previous one when setSensorReading() is not called by client + // code (e.g. run_generic_sensor_iframe_tests()). + if (type == device.mojom.SensorType.AMBIENT_LIGHT) { + this.activeSensors_.get(type).setSensorReading([ + [window.performance.now() * 100], + [(window.performance.now() + 50) * 100] + ]); + } + const initParams = new device.mojom.SensorInitParams({ sensor: sensorPtr, clientReceiver: mojo.makeRequest(this.activeSensors_.get(type).client_),