summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/ambient-light
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/ambient-light')
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor.js5
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor_browsing_context.html31
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor_onchange-manual.html36
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor_onstatechange.html39
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor_start.html31
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor_stop.html30
-rw-r--r--testing/web-platform/tests/ambient-light/AmbientLightSensor_tests.html11
-rw-r--r--testing/web-platform/tests/ambient-light/OWNERS5
-rw-r--r--testing/web-platform/tests/ambient-light/idlharness.html107
-rw-r--r--testing/web-platform/tests/ambient-light/support-iframe.html11
10 files changed, 306 insertions, 0 deletions
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor.js b/testing/web-platform/tests/ambient-light/AmbientLightSensor.js
new file mode 100644
index 000000000..5a1f8ea2f
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor.js
@@ -0,0 +1,5 @@
+(function() {
+ test(function() {
+ assert_true(false);
+ }, 'Test suite not implemented yet.');
+})();
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor_browsing_context.html b/testing/web-platform/tests/ambient-light/AmbientLightSensor_browsing_context.html
new file mode 100644
index 000000000..e0ada32ba
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor_browsing_context.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>AmbientLightSensor Test: Sensor readings must only be available in the top-level browsing context</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="https://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<iframe src="support-iframe.html" id="frame" style="display:none">
+</iframe>
+<script>
+
+async_test(function (t) {
+ document.getElementById('frame').onload = t.step_func_done(function(event) {
+ var iframe = document.getElementById('frame').contentWindow;
+ let reading = iframe.document.getElementById('reading').value;
+ assert_equals(reading, "null");
+ });
+}, "sensor readings can not be fired within iframes");
+
+test(function() {
+ let sensor = new AmbientLightSensor();
+ sensor.start();
+ var win = window.open('', '_blank');
+ let reading = String(sensor.reading);
+ win.close();
+ sensor.stop();
+ assert_equals(reading, "null");
+}, "sensor readings can not be fired on the background tab");
+
+</script>
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor_onchange-manual.html b/testing/web-platform/tests/ambient-light/AmbientLightSensor_onchange-manual.html
new file mode 100644
index 000000000..01950f739
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor_onchange-manual.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>AmbientLightSensor Test: onchange</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="https://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<h2>Description</h2>
+<p>
+ This test validates that the "onchange" event can be invoked when changing the ambient light illuminance of the device.
+</p>
+
+<h2>Precondition</h2>
+<ol>
+ <li>
+ Change the ambient light illuminance of the device.
+ </li>
+</ol>
+
+<script>
+
+async_test(function(t) {
+ let sensor = new AmbientLightSensor();
+ sensor.start();
+
+ sensor.onchange = t.step_func_done(function(event) {
+ sensor.stop();
+ });
+
+ sensor.onerror = t.step_func_done(function(event) {
+ assert_unreached(event.error.name + ":" + event.error.message);
+ });
+}, "event change fired");
+
+</script>
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor_onstatechange.html b/testing/web-platform/tests/ambient-light/AmbientLightSensor_onstatechange.html
new file mode 100644
index 000000000..99a706f20
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor_onstatechange.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>AmbientLightSensor Test: onstatechange</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="https://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+var sensor;
+setup(function() {
+ sensor = new AmbientLightSensor();
+});
+
+test(function() {
+ assert_equals(sensor.state, "idle");
+}, "The default sensor.state is 'idle'.");
+
+async_test(function(t) {
+ sensor.onstatechange = t.step_func_done(function(event) {
+ assert_equals(sensor.state, "activating");
+ });
+ sensor.onerror = t.step_func_done(function(event) {
+ assert_unreached(event.error.name + ":" + event.error.message);
+ });
+ sensor.start();
+}, "The sensor.state changes to 'activating' after sensor.start().");
+
+async_test(function(t) {
+ sensor.onstatechange = t.step_func_done(function(event) {
+ assert_equals(sensor.state, "idle");
+ });
+ sensor.onerror = t.step_func_done(function(event) {
+ assert_unreached(event.error.name + ":" + event.error.message);
+ });
+ sensor.stop();
+}, "The sensor.state changes to 'idle' after sensor.stop().");
+
+</script>
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor_start.html b/testing/web-platform/tests/ambient-light/AmbientLightSensor_start.html
new file mode 100644
index 000000000..2ac29be21
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor_start.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>AmbientLightSensor Test: start()</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="https://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+var sensor, start_return;
+
+setup(function() {
+ sensor = new AmbientLightSensor();
+ start_return = sensor.start();
+});
+
+test(function() {
+ assert_equals(String(sensor.reading), "[object AmbientLightSensorReading]");
+}, "the sensor.reading is AmbientLightSensorReading after executing start() method");
+
+test(function() {
+ assert_throws("InvalidStateError", function() { sensor.start(); }, "start() twice");
+}, "throw an InvalidStateError exception when state is neither idle nor errored");
+
+//TODO: The permission is not ready.
+
+test(function() {
+ assert_equals(start_return, undefined);
+}, "the sensor.start() return undefined");
+
+</script>
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor_stop.html b/testing/web-platform/tests/ambient-light/AmbientLightSensor_stop.html
new file mode 100644
index 000000000..34cd3600b
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor_stop.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>AmbientLightSensor Test: stop()</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="https://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+
+var sensor, stop_return;
+setup(function() {
+ sensor = new AmbientLightSensor();
+ sensor.start();
+ stop_return = sensor.stop();
+});
+
+test(function() {
+ assert_equals(String(sensor.reading), "null");
+}, "the sensor.reading is null after executing stop() method");
+
+test(function() {
+ assert_throws("InvalidStateError", function() { sensor.stop(); }, "stop() twice");
+}, "throw an InvalidStateError exception when state is either idle or errored");
+
+test(function() {
+ assert_equals(stop_return, undefined);
+}, "the sensor.stop() returns undefined");
+
+</script>
diff --git a/testing/web-platform/tests/ambient-light/AmbientLightSensor_tests.html b/testing/web-platform/tests/ambient-light/AmbientLightSensor_tests.html
new file mode 100644
index 000000000..200859715
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/AmbientLightSensor_tests.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<meta charset=utf8>
+<meta content=long name=timeout>
+<meta content="width=device-width, initial-scale=1" name=viewport>
+<title>Ambient Light Sensor Test Suite</title>
+<link rel="help" href="http://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="AmbientLightSensor.js"></script>
+<div id="log"></div>
+
diff --git a/testing/web-platform/tests/ambient-light/OWNERS b/testing/web-platform/tests/ambient-light/OWNERS
new file mode 100644
index 000000000..d0b7f095c
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/OWNERS
@@ -0,0 +1,5 @@
+@zqzhang
+@Volker-E
+@dontcallmedom
+@tobie
+@riju
diff --git a/testing/web-platform/tests/ambient-light/idlharness.html b/testing/web-platform/tests/ambient-light/idlharness.html
new file mode 100644
index 000000000..f88a602a6
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/idlharness.html
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Ambient Light Sensor IDL tests</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<link rel="help" href="http://www.w3.org/TR/ambient-light/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/WebIDLParser.js"></script>
+<script src="/resources/idlharness.js"></script>
+<style>
+ pre {
+ display: none;
+ }
+</style>
+<div id="log"></div>
+
+<pre id="idl">
+interface Event {
+};
+
+interface Error {
+};
+
+dictionary EventInit {
+};
+</pre>
+
+<pre id="generic-idl">
+interface Sensor : EventTarget {
+ readonly attribute SensorState state;
+ readonly attribute SensorReading? reading;
+ void start();
+ void stop();
+ attribute EventHandler onchange;
+ attribute EventHandler onstatechange;
+ attribute EventHandler onerror;
+};
+
+dictionary SensorOptions {
+ double? frequency;
+};
+
+enum SensorState {
+ "idle",
+ "activating",
+ "active",
+ "errored"
+};
+
+interface SensorReading {
+ readonly attribute DOMHighResTimeStamp timeStamp;
+};
+
+[Constructor(DOMString type, SensorReadingEventInit eventInitDict)]
+interface SensorReadingEvent : Event {
+ readonly attribute SensorReading reading;
+};
+
+dictionary SensorReadingEventInit : EventInit {
+ SensorReading reading;
+};
+
+[Constructor(DOMString type, SensorErrorEventInit errorEventInitDict)]
+interface SensorErrorEvent : Event {
+ readonly attribute Error error;
+};
+
+dictionary SensorErrorEventInit : EventInit {
+ Error error;
+};
+</pre>
+
+<pre id="ambient-light-idl">
+[Constructor(optional SensorOptions sensorOptions)]
+interface AmbientLightSensor : Sensor {
+ readonly attribute AmbientLightSensorReading? reading;
+};
+
+[Constructor(AmbientLightSensorReadingInit ambientLightSensorReadingInit)]
+interface AmbientLightSensorReading : SensorReading {
+ readonly attribute unrestricted double illuminance;
+};
+
+dictionary AmbientLightSensorReadingInit {
+ unrestricted double illuminance;
+};
+
+</pre>
+
+<script>
+(function() {
+ "use strict";
+ var idl_array = new IdlArray();
+ idl_array.add_untested_idls(document.getElementById('idl').textContent);
+ idl_array.add_untested_idls(document.getElementById('generic-idl').textContent);
+ idl_array.add_idls(document.getElementById('ambient-light-idl').textContent);
+
+ idl_array.add_objects({
+ AmbientLightSensor: ['new AmbientLightSensor();'],
+ AmbientLightSensorReading: ['new AmbientLightSensorReading({ illuminance: 750 });'],
+ SensorReadingEvent: ['new SensorReadingEvent("reading", { reading: new AmbientLightSensorReading({ illuminance: 750 }) });']
+ });
+
+ idl_array.test();
+})();
+</script>
+
diff --git a/testing/web-platform/tests/ambient-light/support-iframe.html b/testing/web-platform/tests/ambient-light/support-iframe.html
new file mode 100644
index 000000000..994642d51
--- /dev/null
+++ b/testing/web-platform/tests/ambient-light/support-iframe.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<meta charset="utf-8">
+<input type="text" id="reading" />
+<script>
+
+let sensor = new AmbientLightSensor();
+sensor.start();
+document.getElementById("reading").value = String(sensor.reading);
+sensor.stop();
+
+</script>