device-orientation-events-unavailable-on-insecure-origins.html (2779B)
1 <!DOCTYPE html> 2 <title>Device Sensor Events not exposed to insecure origins</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/get-host-info.sub.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script src="resources/orientation-event-helpers.js"></script> 9 <script> 10 11 if (window.location.origin != get_host_info().HTTP_ORIGIN) { 12 window.location = get_host_info().HTTP_ORIGIN + window.location.pathname; 13 promise_test(_ => new Promise(_ => {}), "Stall tests on the wrong host."); 14 } else { 15 test(() => { 16 assert_false('DeviceMotionEvent' in window); 17 assert_false('DeviceOrientationEvent' in window); 18 assert_false('DeviceOrientationAbsoluteEvent' in window); 19 assert_false('DeviceMotionEventAcceleration' in window); 20 assert_false('DeviceMotionEventRotationRate' in window); 21 assert_false('ondevicemotion' in window); 22 assert_false('ondeviceorientation' in window); 23 assert_false('ondeviceorientationabsolute' in window); 24 }, 'Event interfaces and event handlers are not exposed on `window`.'); 25 26 promise_test(async (t) => { 27 const helper = new SensorTestHelper(t, 'devicemotion'); 28 await helper.initializeSensors(); 29 const motionData = generateMotionData(1, 2, 3, 30 4, 5, 6, 31 7, 8, 9); 32 await helper.setData(motionData); 33 34 window.ondevicemotion = t.unreached_func("devicemotion event should not be fired."); 35 36 await new Promise(r => t.step_timeout(r, 1000)); 37 }, 'addEventListener() for `devicemotion` does not crash but the handler never fires.'); 38 39 promise_test(async (t) => { 40 const helper = new SensorTestHelper(t, 'deviceorientation'); 41 await helper.initializeSensors(); 42 const orientationData = generateOrientationData(1.1, 2.2, 3.3, false); 43 await helper.setData(orientationData); 44 45 window.ondeviceorientation = t.unreached_func("deviceorientation event should not be fired."); 46 47 await new Promise(r => t.step_timeout(r, 1000)); 48 }, 'addEventListener() for `deviceorientation` does not crash but the handler never fires.'); 49 50 promise_test(async (t) => { 51 const helper = new SensorTestHelper(t, 'deviceorientationabsolute'); 52 await helper.initializeSensors(); 53 const orientationData = generateOrientationData(1.1, 2.2, 3.3, true); 54 await helper.setData(orientationData); 55 56 window.ondeviceorientationabsolute = t.unreached_func("deviceorientationabsolute event should not be fired."); 57 58 await new Promise(r => t.step_timeout(r, 1000)); 59 }, 'addEventListener() for `deviceorientationabsolute` does not crash but the handler never fires.'); 60 } 61 </script>