Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 4 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /orientation-event/device-orientation-events-unavailable-on-insecure-origins.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>Device Sensor Events not exposed to insecure origins</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/orientation-event-helpers.js"></script>
<script>
if (window.location.origin != get_host_info().HTTP_ORIGIN) {
window.location = get_host_info().HTTP_ORIGIN + window.location.pathname;
promise_test(_ => new Promise(_ => {}), "Stall tests on the wrong host.");
} else {
test(() => {
assert_false('DeviceMotionEvent' in window);
assert_false('DeviceOrientationEvent' in window);
assert_false('DeviceOrientationAbsoluteEvent' in window);
assert_false('DeviceMotionEventAcceleration' in window);
assert_false('DeviceMotionEventRotationRate' in window);
assert_false('ondevicemotion' in window);
assert_false('ondeviceorientation' in window);
assert_false('ondeviceorientationabsolute' in window);
}, 'Event interfaces and event handlers are not exposed on `window`.');
promise_test(async (t) => {
const helper = new SensorTestHelper(t, 'devicemotion');
await helper.initializeSensors();
const motionData = generateMotionData(1, 2, 3,
4, 5, 6,
7, 8, 9);
await helper.setData(motionData);
window.ondevicemotion = t.unreached_func("devicemotion event should not be fired.");
await new Promise(r => t.step_timeout(r, 1000));
}, 'addEventListener() for `devicemotion` does not crash but the handler never fires.');
promise_test(async (t) => {
const helper = new SensorTestHelper(t, 'deviceorientation');
await helper.initializeSensors();
const orientationData = generateOrientationData(1.1, 2.2, 3.3, false);
await helper.setData(orientationData);
window.ondeviceorientation = t.unreached_func("deviceorientation event should not be fired.");
await new Promise(r => t.step_timeout(r, 1000));
}, 'addEventListener() for `deviceorientation` does not crash but the handler never fires.');
promise_test(async (t) => {
const helper = new SensorTestHelper(t, 'deviceorientationabsolute');
await helper.initializeSensors();
const orientationData = generateOrientationData(1.1, 2.2, 3.3, true);
await helper.setData(orientationData);
window.ondeviceorientationabsolute = t.unreached_func("deviceorientationabsolute event should not be fired.");
await new Promise(r => t.step_timeout(r, 1000));
}, 'addEventListener() for `deviceorientationabsolute` does not crash but the handler never fires.');
}
</script>