summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser/browser_wakelock.js
blob: 5cef231d07600dc5de3b5296e68425a133d0ed1d (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

"use strict";

add_task(async () => {
  info("creating test window");
  let win = await BrowserTestUtils.openNewBrowserWindow();

  const pm = Cc["@mozilla.org/power/powermanagerservice;1"].getService(
    Ci.nsIPowerManagerService
  );

  is(
    pm.getWakeLockState("screen"),
    "unlocked",
    "Wakelock should be unlocked state"
  );

  info("aquiring wakelock");
  const wakelock = pm.newWakeLock("screen", win);
  isnot(
    pm.getWakeLockState("screen"),
    "unlocked",
    "Wakelock shouldn't be unlocked state"
  );

  info("releasing wakelock");
  wakelock.unlock();
  is(
    pm.getWakeLockState("screen"),
    "unlocked",
    "Wakelock should be unlocked state"
  );

  info("closing test window");
  await BrowserTestUtils.closeWindow(win);
});