page-visibility.https.html (1587B)
1 <!DOCTYPE html> 2 <html> 3 <body> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script src="/page-visibility/resources/window_state_context.js"></script> 9 <script src="../resources/orientation-event-helpers.js"></script> 10 <script> 11 'use strict'; 12 13 promise_test(async (t) => { 14 const helper = new SensorTestHelper(t, 'deviceorientation'); 15 await helper.grantSensorsPermissions(); 16 await helper.initializeSensors(); 17 18 const orientationData = generateOrientationData(1, 2, 3, false); 19 20 await helper.setData(orientationData); 21 const event = getExpectedOrientationEvent(orientationData); 22 await waitForEvent(event); 23 24 const {minimize, restore} = window_state_context(t); 25 await minimize(); 26 assert_true(document.hidden); 27 28 let hiddenEventPromise = new Promise((resolve, reject) => { 29 window.addEventListener( 30 'deviceorientation', 31 event => { 32 if (document.hidden) { 33 reject(); 34 } else { 35 resolve(); 36 } 37 }, 38 { once: true }); 39 }); 40 41 // Sleep for a while to make sure no deviceorientation events are fired 42 // while the page is hidden. 43 await new Promise(resolve => { t.step_timeout(resolve, 100); }); 44 await restore(); 45 assert_false(document.hidden); 46 return Promise.all([hiddenEventPromise, waitForEvent(event)]); 47 }, 'Tests to check that deviceorientation events are not fired when the page is not visible.'); 48 </script> 49 </body> 50 </html>