Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html

Issue 2472403002: [Sensors] Align sensor reading attribute implementation with the specification (Closed)
Patch Set: Comments from Tim Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html
diff --git a/third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html b/third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html
index c5a0829d700e3c6dbbc6df053ba4ccb50b6f3667..94458f1d6a492ed8eb516af27c04e47e6fa60e77 100644
--- a/third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html
+++ b/third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html
@@ -185,8 +185,8 @@ sensor_test(sensor => {
}
};
- ambientLightSensor.onchange = e => {
- assert_equals(e.reading.illuminance, kDefaultReadingValue);
+ ambientLightSensor.onchange = () => {
+ assert_equals(ambientLightSensor.reading.illuminance, kDefaultReadingValue);
ambientLightSensor.stop();
};
@@ -214,8 +214,8 @@ sensor_test(sensor => {
}
}
- ambientLightSensor.onchange = e => {
- assert_equals(e.reading.illuminance, kDefaultReadingValue);
+ ambientLightSensor.onchange = () => {
+ assert_equals(ambientLightSensor.reading.illuminance, kDefaultReadingValue);
ambientLightSensor.stop();
}
ambientLightSensor.onerror = reject;
@@ -235,8 +235,8 @@ sensor_test(sensor => {
})
.then((mockSensor) => {
return new Promise((resolve, reject) => {
- ambientLightSensor.onchange = e => {
- if (e.reading.illuminance == kDefaultReadingValue) {
+ ambientLightSensor.onchange = () => {
+ if (ambientLightSensor.reading.illuminance == kDefaultReadingValue) {
resolve(mockSensor);
}
}
@@ -268,4 +268,53 @@ sensor_test(sensor => {
}, 'Test that sensor receives suspend / resume notifications when page'
+' visibility changes.');
+
+sensor_test(sensor => {
+ let sensor1 = new AmbientLightSensor({frequency: 60});
+ sensor1.start();
+
+ let sensor2 = new AmbientLightSensor({frequency: 20});
+ sensor2.start();
+ let testPromise = sensor.mockSensorProvider.getCreatedSensor()
+ .then(mockSensor => {
+ return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
+ })
+ .then((mockSensor) => {
+ return new Promise((resolve, reject) => {
+ sensor1.onstatechange = event => {
+ if (sensor1.state === 'idle') {
+ resolve(mockSensor);
+ }
+ };
+
+ sensor1.onchange = () => {
+ // Reading value is correct.
+ assert_equals(sensor1.reading.illuminance, kDefaultReadingValue);
+
+ // Both sensors share the same reading instance.
+ let reading = sensor1.reading;
+ assert_equals(reading, sensor2.reading);
+
+ // After first sensor stops its reading is null, reading for second
+ // sensor sensor remains.
+ sensor1.stop();
+ assert_equals(sensor1.reading, null);
+ assert_equals(sensor2.reading.illuminance, kDefaultReadingValue);
+
+ sensor2.stop();
+ assert_equals(sensor2.reading, null);
+
+ // Cached reading remains.
+ assert_equals(reading.illuminance, kDefaultReadingValue);
+ };
+
+ sensor1.onerror = reject;
+ sensor2.onerror = reject;
+ });
+ })
+ .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
+
+ return testPromise;
+}, 'Test that sensor reading is correct.');
+
</script>

Powered by Google App Engine
This is Rietveld 408576698