tor-browser

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

browser_shutdown_pref.js (2403B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const PREF_ACCESSIBILITY_FORCE_DISABLED = "accessibility.force_disabled";
      8 
      9 add_task(async function testForceDisable() {
     10  ok(
     11    !Services.appinfo.accessibilityEnabled,
     12    "Accessibility is disabled by default"
     13  );
     14 
     15  info("Reset force disabled preference");
     16  Services.prefs.clearUserPref(PREF_ACCESSIBILITY_FORCE_DISABLED);
     17 
     18  info("Enable accessibility service via XPCOM");
     19  let [a11yInitObserver, a11yInit] = initAccService();
     20  await a11yInitObserver;
     21 
     22  let accService = Cc["@mozilla.org/accessibilityService;1"].getService(
     23    Ci.nsIAccessibilityService
     24  );
     25  await a11yInit;
     26  ok(Services.appinfo.accessibilityEnabled, "Accessibility is enabled");
     27 
     28  info("Force disable a11y service via preference");
     29  let [a11yShutdownObserver, a11yShutdown] = shutdownAccService();
     30  await a11yShutdownObserver;
     31 
     32  Services.prefs.setIntPref(PREF_ACCESSIBILITY_FORCE_DISABLED, 1);
     33  await a11yShutdown;
     34  ok(!Services.appinfo.accessibilityEnabled, "Accessibility is disabled");
     35 
     36  info("Attempt to get an instance of a11y service and call its method.");
     37  accService = Cc["@mozilla.org/accessibilityService;1"].getService(
     38    Ci.nsIAccessibilityService
     39  );
     40  try {
     41    accService.getAccesssibleFor(document);
     42    ok(false, "getAccesssibleFor should've triggered an exception.");
     43  } catch (e) {
     44    ok(
     45      true,
     46      "getAccesssibleFor triggers an exception as a11y service is shutdown."
     47    );
     48  }
     49  ok(!Services.appinfo.accessibilityEnabled, "Accessibility is disabled");
     50 
     51  info("Reset force disabled preference");
     52  Services.prefs.clearUserPref(PREF_ACCESSIBILITY_FORCE_DISABLED);
     53 
     54  info("Create a11y service again");
     55  [a11yInitObserver, a11yInit] = initAccService();
     56  await a11yInitObserver;
     57 
     58  accService = Cc["@mozilla.org/accessibilityService;1"].getService(
     59    Ci.nsIAccessibilityService
     60  );
     61  await a11yInit;
     62  ok(Services.appinfo.accessibilityEnabled, "Accessibility is enabled");
     63 
     64  info("Remove all references to a11y service");
     65  [a11yShutdownObserver, a11yShutdown] = shutdownAccService();
     66  await a11yShutdownObserver;
     67 
     68  accService = null;
     69  forceGC();
     70  await a11yShutdown;
     71  ok(!Services.appinfo.accessibilityEnabled, "Accessibility is disabled");
     72 });