tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_notifications_do_not_disturb.js (1685B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 registerCleanupFunction(function () {
      5  while (gBrowser.tabs[1]) {
      6    gBrowser.removeTab(gBrowser.tabs[1]);
      7  }
      8 });
      9 
     10 add_task(async function () {
     11  let prefs = await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
     12    leaveOpen: true,
     13  });
     14  is(prefs.selectedPane, "panePrivacy", "Privacy pane was selected");
     15 
     16  let doc = gBrowser.contentDocument;
     17  let notificationsDoNotDisturbBox = doc.getElementById(
     18    "notificationsDoNotDisturb"
     19  ).control;
     20  if (notificationsDoNotDisturbBox.hidden) {
     21    todo(false, "Do not disturb is not available on this platform");
     22    return;
     23  }
     24 
     25  let alertService;
     26  try {
     27    alertService = Cc["@mozilla.org/alerts-service;1"]
     28      .getService(Ci.nsIAlertsService)
     29      .QueryInterface(Ci.nsIAlertsDoNotDisturb);
     30  } catch (ex) {
     31    ok(true, "Do not disturb is not available on this platform: " + ex.message);
     32    return;
     33  }
     34 
     35  let checkbox = doc.getElementById("notificationsDoNotDisturb").control
     36    .controlEl;
     37  ok(!checkbox.checked, "Checkbox should not be checked by default");
     38  ok(
     39    !alertService.manualDoNotDisturb,
     40    "Do not disturb should be off by default"
     41  );
     42 
     43  let checkboxChanged = BrowserTestUtils.waitForEvent(checkbox, "change");
     44  checkbox.click();
     45  await checkboxChanged;
     46  ok(
     47    alertService.manualDoNotDisturb,
     48    "Do not disturb should be enabled when checked"
     49  );
     50 
     51  checkboxChanged = BrowserTestUtils.waitForEvent(checkbox, "change");
     52  checkbox.click();
     53  await checkboxChanged;
     54  ok(
     55    !alertService.manualDoNotDisturb,
     56    "Do not disturb should be disabled when unchecked"
     57  );
     58 });