basics.tentative.https.window.js (2949B)
1 // META: script=/resources/testdriver.js 2 // META: script=/resources/testdriver-vendor.js 3 // META: title=Idle Detection API: Basics 4 5 'use strict'; 6 7 promise_setup(async t => { 8 await test_driver.set_permission({name: 'idle-detection'}, 'granted'); 9 }) 10 11 promise_test(async t => { 12 let detector = new IdleDetector(); 13 let watcher = new EventWatcher(t, detector, ["change"]); 14 let initial_state = watcher.wait_for("change"); 15 16 await detector.start(); 17 await initial_state; 18 19 assert_true(['active', 'idle'].includes(detector.userState), 20 'has a valid user state'); 21 assert_true(['locked', 'unlocked'].includes(detector.screenState), 22 'has a valid screen state'); 23 }, 'start() basics'); 24 25 promise_test(async t => { 26 let used = false; 27 28 const detector = new IdleDetector(); 29 detector.start({ 30 get threshold() { 31 used = true; 32 return 60000; 33 } 34 }); 35 36 assert_true(used, 'start() options "threshold" member was used'); 37 }, 'start() uses threshold property'); 38 39 promise_test(async t => { 40 let used = false; 41 42 const controller = new AbortController(); 43 const detector = new IdleDetector(); 44 detector.start({ 45 get signal() { 46 used = true; 47 return controller.signal; 48 } 49 }); 50 51 assert_true(used, 'start() options "signal" member was used'); 52 }, 'start() uses signal property'); 53 54 55 promise_test(async t => { 56 const detector = new IdleDetector(); 57 await promise_rejects_js(t, TypeError, detector.start({threshold: 0})); 58 }, 'start() rejects with invalid threshold (0)'); 59 60 promise_test(async t => { 61 const detector = new IdleDetector(); 62 await promise_rejects_js(t, TypeError, detector.start({threshold: 59000})); 63 }, 'start() rejects with threshold below minimum (59000)'); 64 65 promise_test(async t => { 66 const detector = new IdleDetector(); 67 await detector.start({threshold: 60000}); 68 }, 'start() rejects threshold (60000)'); 69 70 promise_test(async t => { 71 const detector = new IdleDetector(); 72 await detector.start({threshold: 61000}); 73 }, 'start() allows threshold (61000)'); 74 75 promise_test(async t => { 76 const detector = new IdleDetector(); 77 await promise_rejects_js(t, TypeError, detector.start({threshold: null})); 78 }, 'start() rejects with invalid threshold (null)'); 79 80 promise_test(async t => { 81 const detector = new IdleDetector(); 82 await promise_rejects_js(t, TypeError, detector.start({threshold: -1})); 83 }, 'start() rejects with invalid threshold (-1)'); 84 85 promise_test(async t => { 86 const detector = new IdleDetector(); 87 await promise_rejects_js(t, TypeError, detector.start({threshold: NaN})); 88 }, 'start() rejects with invalid threshold (NaN)'); 89 90 promise_test(async t => { 91 const detector = new IdleDetector(); 92 await detector.start(); 93 }, 'start() uses a default value for the threshold when none is passed'); 94 95 promise_test(async t => { 96 const detector = new IdleDetector(); 97 await detector.start({threshold: undefined}); 98 }, 'start() uses a default value for the threshold');