tor-browser

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

browser_ensure_prefs_bindings_initted.js (1431B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /*
      7 * Check that panes that aren't the default have their bindings initialized
      8 * and 'preference' attributes are processed correctly.
      9 */
     10 add_task(async function test_prefs_bindings_initted() {
     11  await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
     12  let doc = gBrowser.selectedBrowser.contentDocument;
     13  let prefReader = doc.ownerGlobal.Preferences;
     14  let prefBasedCheckboxes = Array.from(
     15    doc.querySelectorAll("checkbox[preference]")
     16  );
     17 
     18  // Then check all the preferences:
     19  for (let checkbox of prefBasedCheckboxes) {
     20    let pref = checkbox.getAttribute("preference");
     21    if (Services.prefs.getPrefType(pref) == Services.prefs.PREF_BOOL) {
     22      info(`Waiting for checkbox to match pref ${pref}`);
     23      // Ensure the task setting up prefs has run.
     24      await BrowserTestUtils.waitForMutationCondition(
     25        checkbox,
     26        { attributeFilter: ["checked"] },
     27        () => checkbox.checked == prefReader.get(pref).value
     28      );
     29      is(
     30        checkbox.checked,
     31        prefReader.get(pref).value,
     32        `Checkbox value should match preference (${pref}).`
     33      );
     34      // Ignore all other types. The mapping is normally non-trivial and done
     35      // using syncfrompreference handlers in JS.
     36    }
     37  }
     38 
     39  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     40 });