summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/idle-detection/basics.tentative.https.window.js
blob: 32cb6204b99012abd26ba78d838929c8183a7c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: title=Idle Detection API: Basics

'use strict';

promise_setup(async t => {
  await test_driver.set_permission({name: 'idle-detection'}, 'granted');
})

promise_test(async t => {
  let detector = new IdleDetector();
  let watcher = new EventWatcher(t, detector, ["change"]);
  let initial_state = watcher.wait_for("change");

  await detector.start();
  await initial_state;

  assert_true(['active', 'idle'].includes(detector.userState),
                'has a valid user state');
  assert_true(['locked', 'unlocked'].includes(detector.screenState),
                'has a valid screen state');
}, 'start() basics');

promise_test(async t => {
  let used = false;

  const detector = new IdleDetector();
  detector.start({
    get threshold() {
      used = true;
      return 60000;
    }
  });

  assert_true(used, 'start() options "threshold" member was used');
}, 'start() uses threshold property');

promise_test(async t => {
  let used = false;

  const controller = new AbortController();
  const detector = new IdleDetector();
  detector.start({
    get signal() {
      used = true;
      return controller.signal;
    }
  });

  assert_true(used, 'start() options "signal" member was used');
}, 'start() uses signal property');


promise_test(async t => {
  const detector = new IdleDetector();
  await promise_rejects_js(t, TypeError, detector.start({threshold: 0}));
}, 'start() rejects with invalid threshold (0)');

promise_test(async t => {
  const detector = new IdleDetector();
  await promise_rejects_js(t, TypeError, detector.start({threshold: 59000}));
}, 'start() rejects with threshold below minimum (59000)');

promise_test(async t => {
  const detector = new IdleDetector();
  await detector.start({threshold: 60000});
}, 'start() rejects threshold (60000)');

promise_test(async t => {
  const detector = new IdleDetector();
  await detector.start({threshold: 61000});
}, 'start() allows threshold (61000)');

promise_test(async t => {
  const detector = new IdleDetector();
  await promise_rejects_js(t, TypeError, detector.start({threshold: null}));
}, 'start() rejects with invalid threshold (null)');

promise_test(async t => {
  const detector = new IdleDetector();
  await promise_rejects_js(t, TypeError, detector.start({threshold: -1}));
}, 'start() rejects with invalid threshold (-1)');

promise_test(async t => {
  const detector = new IdleDetector();
  await promise_rejects_js(t, TypeError, detector.start({threshold: NaN}));
}, 'start() rejects with invalid threshold (NaN)');

promise_test(async t => {
  const detector = new IdleDetector();
  await detector.start();
}, 'start() uses a default value for the threshold when none is passed');

promise_test(async t => {
  const detector = new IdleDetector();
  await detector.start({threshold: undefined});
}, 'start() uses a default value for the threshold');