| <!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" sandbox="allow-scripts"> |
| </iframe> |
| <script> |
| |
| async_test(t => { |
| window.onmessage = t.step_func(e => { |
| assert_equals(e.data, "SecurityError"); |
| t.done(); |
| }); |
| }, "throw a 'SecurityError' when firing sensor readings within iframes"); |
| |
| async_test(t => { |
| let sensor = new AmbientLightSensor(); |
| sensor.start(); |
| sensor.onactivate = t.step_func_done(() => { |
| assert_not_equals(sensor.reading, null); |
| let cachedReading = sensor.reading; |
| let win = window.open('', '_blank'); |
| assert_equals(sensor.reading, cachedReading); |
| win.close(); |
| sensor.stop(); |
| }); |
| }, "sensor readings can not be fired on the background tab"); |
| |
| </script> |