summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/screen-wake-lock/wakelock-onrelease.https.html
blob: 896748411be22c8937421361b7dac95a36448f7a (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
<!DOCTYPE html>
<link rel="help" href="https://w3c.github.io/screen-wake-lock/#the-onrelease-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
promise_test(async t => {
  await test_driver.set_permission({name: 'screen-wake-lock'}, 'granted');

  const lock = await navigator.wakeLock.request("screen");
  return new Promise(resolve => {
    lock.onrelease = resolve;
    lock.release();
  }).then(ev => {
    assert_class_string(ev, "Event", "release() must fire an Event object");
    assert_equals(ev.target, lock, "The event's target must be the lock that was acquired");
    assert_true(ev.isTrusted);
    assert_false(ev.bubbles);
    assert_false(ev.cancelable);
  });
}, "Test onreleased event's basic properties");

promise_test(async t => {
  await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');

  const lock = await navigator.wakeLock.request("screen");

  let releaseFired = false;
  lock.onrelease = t.step_func(() => {
    releaseFired = true;
  });

  const releasePromise = lock.release();
  assert_true(releaseFired, "The 'release' event fires immediately after release() is called");

  return releasePromise;
}, "Ensure onrelease is called before WakeLockSentinel.release() resolves");

promise_test(async t => {
  await test_driver.set_permission({ name: 'screen-wake-lock' }, 'granted');

  const lock = await navigator.wakeLock.request("screen");

  let eventCount = 0;
  lock.onrelease = t.step_func(() => {
    eventCount++;
  });

  await lock.release();
  await lock.release();
  assert_equals(eventCount, 1, "The 'release' event was fired once");
}, "Ensure onrelease is fired exactly once");
</script>