page-visibility.https.html (2193B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://github.com/samuelgoto/idle-detection"> 3 <title>Tests the Idle Detection API</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/test-only-api.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script src="/page-visibility/resources/window_state_context.js"></script> 10 <script src="resources/idle-detection-helper.js"></script> 11 <script> 12 'use strict'; 13 14 promise_setup(async t => { 15 await test_driver.set_permission({ name: 'idle-detection' }, 'granted'); 16 if (isChromiumBased) { 17 await loadChromiumResources(); 18 } 19 }) 20 21 promise_test(async t => { 22 let monitor; 23 24 expect(addMonitor).andReturn(async (monitorPtr) => { 25 monitor = monitorPtr; 26 return { 27 error: IdleDetectorError.SUCCESS, 28 state: { 29 idleTime: null, 30 screenLocked: false 31 } 32 }; 33 }); 34 35 const controller = new AbortController(); 36 t.add_cleanup(() => { 37 controller.abort(); 38 }); 39 const detector = new IdleDetector(); 40 const watcher = new EventWatcher(t, detector, ["change"]); 41 const initial_state = watcher.wait_for("change"); 42 43 await detector.start({threshold: 60000, signal: controller.signal}); 44 await initial_state; 45 46 assert_equals(detector.userState, "active"); 47 assert_false(document.hidden); 48 49 const {minimize, restore} = window_state_context(t); 50 51 await minimize(); 52 monitor.update( 53 { 54 idleTime: { milliseconds: 0 }, 55 screenLocked: false 56 }, 57 /*is_overridden_by_devtools=*/true 58 ); 59 60 // Assert that the detector works while the page is not visible. 61 await watcher.wait_for("change"); 62 assert_equals(detector.userState, "idle"); 63 assert_true(document.hidden); 64 65 await restore(); 66 monitor.update( 67 { 68 idleTime: null, 69 screenLocked: false 70 }, 71 /*is_overridden_by_devtools=*/true 72 ); 73 74 await watcher.wait_for("change"); 75 assert_equals(detector.userState, "active"); 76 assert_false(document.hidden); 77 }, 'Page visibility.'); 78 79 </script>