summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/screen-wake-lock/wakelock-onrelease.https.html
blob: fb071b3763d6e1060e7b616da5102c3d463de163 (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
<!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 onreleased is called before WakeLockSentinel.release() resolves");
</script>