aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/idle-detection/basics.tentative.https.any.js
blob: c31faff8fcbdbd58b4aad6ea562d4d8671b738cc (plain) (blame)
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
// META: title=Idle Detection API: Basics

'use strict';

promise_test(async t => {
  let status = new IdleDetector();

  let watcher = new EventWatcher(t, status, ["change"]);

  await status.start();

  await watcher.wait_for("change");

  assert_true(['active', 'idle'].includes(status.state.user),
                'status has a valid user state');
  assert_true(['locked', 'unlocked'].includes(status.state.screen),
                'status has a valid screen state');

}, 'start() basics');

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

  new IdleDetector({
    get threshold() {
      used = true;
      return 60;
    }
  });

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

promise_test(async t => {
  try {
    new IdleDetector({threshold: 0});
    assert_unreached('Threshold under 60 should reject');
  } catch (error) {
    assert_equals(error.name, 'TypeError');
  }
}, 'constructor throws with invalid threshold (0)');

promise_test(async t => {
  try {
    new IdleDetector({threshold: 59});
    assert_unreached('Threshold under 60 should reject');
  } catch (error) {
    assert_equals(error.name, 'TypeError');
  }
}, 'constructor throws with threshold below minimum (59)');

promise_test(async t => {
  new IdleDetector({threshold: 60});
}, 'constructor allows threshold (60)');

promise_test(async t => {
  new IdleDetector({threshold: 61});
}, 'constructor allows threshold (61)');

promise_test(async t => {
  try {
    new IdleDetector({threshold: null});
    assert_unreached('Threshold of null should reject');
  } catch (error) {
    assert_equals(error.name, 'TypeError');
  }
}, 'constructor throws with invalid threshold (null)');

promise_test(async t => {
  try {
    new IdleDetector({threshold: -1});
    assert_unreached('Threshold of negative numbers should reject');
  } catch (error) {
    assert_equals(error.name, 'TypeError');
  }
}, 'constructor throws with invalid threshold (-1)');

promise_test(async t => {
  try {
    new IdleDetector({threshold: NaN});
    assert_unreached('Threshold of NaN should reject');
  } catch (error) {
    assert_equals(error.name, 'TypeError');
  }
}, 'constructor throws with invalid threshold (NaN)');

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

promise_test(async t => {
  new IdleDetector({threshold: undefined});
}, 'constructor uses a default value for the threshold');