| 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>
|
|
|