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

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

Issue 2332323002: [sensors] Ambient light sensor bindings implementation (Closed)
Patch Set: Fixes for comments from Haraken Created 4 years, 3 months 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
new file mode 100644
index 0000000000000000000000000000000000000000..d06a3989d4f531ad7803afae2b3d82daa7a0f899
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="../resources/mojo-helpers.js"></script>
+<script src="resources/sensor-helpers.js"></script>
+<script>
+
+'use strict';
+
+if (!window.testRunner)
+ debug('This test cannot be run without the TestRunner');
+
+function update_sensor_reading(buffer) {
+ buffer[0] = window.performance.now();
+ buffer[1] = 3.1415;
+}
+
+sensor_test(sensor => {
+ sensor.mockSensorProvider.setGetSensorShouldFail(true);
+ let ambientLightSensor = new AmbientLightSensor();
+ ambientLightSensor.start();
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onstatechange = event => {
+ assert_equals(ambientLightSensor.state, 'errored');
+ resolve();
+ };
+ });
+}, 'Test that sensor state changes to "errored" when sensor is not supported.');
+
+sensor_test(sensor => {
+ let mockSensorCreated = sensor.mockSensorProvider.getCreatedSensor();
+ let ambientLightSensor = new AmbientLightSensor({frequency: 1});
+ ambientLightSensor.start();
+ ambientLightSensor.stop();
+ return mockSensorCreated;
+}, 'Test that sensor can be successfully created if sensor is supported.');
+
+sensor_test(sensor => {
+ let ambientLightSensor = new AmbientLightSensor({frequency: 1});
+ let mockSensorCreated = sensor.mockSensorProvider.getCreatedSensor()
+ .then(mockSensor => {
+ mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onchange = e => {
+ if (e.reading.illuminance == 3.1415) {
+ resolve();
+ }
+ }
+ ambientLightSensor.onerror = reject;
+ ambientLightSensor.start();
+ });
+ });
+ return mockSensorCreated;
+}, 'Test that onChange is called and sensor reading is valid.');
+
+sensor_test(sensor => {
+ let ambientLightSensor = new AmbientLightSensor();
+ let mockSensorCreated = sensor.mockSensorProvider.getCreatedSensor()
+ .then(mockSensor => {
+ mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onstatechange = () => {
+ if (ambientLightSensor.state === 'active') {
+ resolve();
+ }
+ }
+ ambientLightSensor.start();
+ });
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onchange = e => {
+ if (e.reading.illuminance == 3.1415) {
+ resolve();
+ }
+ }
+ ambientLightSensor.onerror = reject;
+ });
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onstatechange = () => {
+ if (ambientLightSensor.state === 'idle') {
+ assert_equals(ambientLightSensor.reading, null);
+ resolve();
+ }
+ }
+
+ ambientLightSensor.onerror = reject;
+ ambientLightSensor.stop();
+ });
+ });
+
+ return mockSensorCreated;
+}, 'Test that sensor reading is not updated when sensor is stopped.');
+
+sensor_test(sensor => {
+ let ambientLightSensor = new AmbientLightSensor();
+ let mockSensorCreated = sensor.mockSensorProvider.getCreatedSensor()
+ .then(mockSensor => {
+ mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onchange = e => {
+ if (e.reading.illuminance == 3.1415) {
+ resolve();
+ }
+ }
+ ambientLightSensor.onerror = reject;
+ ambientLightSensor.start();
+ });
+ });
+ return mockSensorCreated;
+}, 'Test that sensor can be constructed with default configuration.');
+
+sensor_test(sensor => {
+ let ambientLightSensor = new AmbientLightSensor();
+ let mockSensorCreated = sensor.mockSensorProvider.getCreatedSensor()
+ .then(mockSensor => {
+ mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ ambientLightSensor.onchange = e => {
+ if (e.reading.illuminance == 3.1415) {
+ resolve();
+ }
+ }
+ ambientLightSensor.onerror = reject;
+ ambientLightSensor.start();
+ });
+ })
+ .then(() => {
+ testRunner.setPageVisibility("hidden");
+ return mockSensor.isSuspendCalled();
+ })
+ .then(() => {
+ testRunner.setPageVisibility("visible");
+ return mockSensor.isResumeCalled();
+ });
+ return mockSensorCreated;
+}, 'Test that sensor receives suspend / resume notifications when page'
+ +' visibility changes.');
+
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698