https://github.com/web-platform-tests/wpt
Raw File
Tip revision: dd79be3ee575503e4e9595dfe8ce8141d8aedb72 authored by Hiroki Nakagawa on 22 March 2018, 05:53:36 UTC
Worker: Support ES Modules on DedicatedWorker behind the runtime flag
Tip revision: dd79be3
wakelock-onactivechange.https.html
<!DOCTYPE html>
<meta charset="utf-8">
<title>Wake Lock 'onactivechange' Test</title>
<link rel="help" href="https://w3c.github.io/wake-lock/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>

promise_test(async t => {
  const wakeLock = await navigator.getWakeLock("screen");
  const eventWatcher = new EventWatcher(t, wakeLock, "activechange");
  assert_false(wakeLock.active, "the active is false before wake lock is acquired");

  let request = wakeLock.createRequest();
  let evt1 = await eventWatcher.wait_for("activechange");
  assert_true(evt1.isTrusted && !evt1.bubbles && !evt1.cancelable && evt1 instanceof Event, "a simple event is fired");
  assert_equals(evt1.type, "activechange", "the event name is 'activechange'");
  assert_equals(evt1.target, wakeLock, "event.target is WakeLock.");
  assert_true(wakeLock.active, "the active is true when wake lock is acquired");

  request.cancel();
  let evt2 = await eventWatcher.wait_for("activechange");
  assert_true(evt2.isTrusted && !evt2.bubbles && !evt2.cancelable && evt2 instanceof Event, "a simple event is fired");
  assert_false(wakeLock.active, "the active is false when wake lock is released");
}, "Test that 'activechange' event is fire and wakeLock.active is valid");

</script>
back to top