tor-browser

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

browser_bug1020245_openPreferences_to_paneContent.js (5434B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test opening to the differerent panes and subcategories in Preferences
      5 add_task(async function () {
      6  let prefs = await openPreferencesViaOpenPreferencesAPI("panePrivacy");
      7  is(prefs.selectedPane, "panePrivacy", "Privacy pane was selected");
      8  prefs = await openPreferencesViaHash("privacy");
      9  is(
     10    prefs.selectedPane,
     11    "panePrivacy",
     12    "Privacy pane is selected when hash is 'privacy'"
     13  );
     14  prefs = await openPreferencesViaOpenPreferencesAPI("nonexistant-category");
     15  is(
     16    prefs.selectedPane,
     17    "paneGeneral",
     18    "General pane is selected by default when a nonexistant-category is requested"
     19  );
     20  prefs = await openPreferencesViaHash("nonexistant-category");
     21  is(
     22    prefs.selectedPane,
     23    "paneGeneral",
     24    "General pane is selected when hash is a nonexistant-category"
     25  );
     26  prefs = await openPreferencesViaHash();
     27  is(prefs.selectedPane, "paneGeneral", "General pane is selected by default");
     28  prefs = await openPreferencesViaOpenPreferencesAPI("privacy-reports", {
     29    leaveOpen: true,
     30  });
     31  is(prefs.selectedPane, "panePrivacy", "Privacy pane is selected by default");
     32  let doc = gBrowser.contentDocument;
     33  is(
     34    doc.location.hash,
     35    "#privacy",
     36    "The subcategory should be removed from the URI"
     37  );
     38  await TestUtils.waitForCondition(
     39    () => doc.querySelector(".spotlight"),
     40    "Wait for the reports section is spotlighted."
     41  );
     42  is(
     43    doc.querySelector(".spotlight").getAttribute("data-subcategory"),
     44    "reports",
     45    "The reports section is spotlighted."
     46  );
     47  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     48 });
     49 
     50 // Test opening Preferences with subcategory on an existing Preferences tab. See bug 1358475.
     51 add_task(async function () {
     52  let prefs = await openPreferencesViaOpenPreferencesAPI("general", {
     53    leaveOpen: true,
     54  });
     55  is(prefs.selectedPane, "paneGeneral", "General pane is selected by default");
     56  let doc = gBrowser.contentDocument;
     57  is(
     58    doc.location.hash,
     59    "#general",
     60    "The subcategory should be removed from the URI"
     61  );
     62  // The reasons that here just call the `openPreferences` API without the helping function are
     63  //   - already opened one about:preferences tab up there and
     64  //   - the goal is to test on the existing tab and
     65  //   - using `openPreferencesViaOpenPreferencesAPI` would introduce more handling of additional about:blank and unneccessary event
     66  await openPreferences("privacy-reports");
     67  let selectedPane = gBrowser.contentWindow.history.state;
     68  is(selectedPane, "panePrivacy", "Privacy pane should be selected");
     69  is(
     70    doc.location.hash,
     71    "#privacy",
     72    "The subcategory should be removed from the URI"
     73  );
     74  await TestUtils.waitForCondition(
     75    () => doc.querySelector(".spotlight"),
     76    "Wait for the reports section is spotlighted."
     77  );
     78  is(
     79    doc.querySelector(".spotlight").getAttribute("data-subcategory"),
     80    "reports",
     81    "The reports section is spotlighted."
     82  );
     83  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     84 });
     85 
     86 // Test opening to a subcategory displays the correct values for preferences
     87 add_task(async function () {
     88  // Skip if crash reporting isn't enabled since the checkbox will be missing.
     89  if (!AppConstants.MOZ_CRASHREPORTER) {
     90    return;
     91  }
     92 
     93  await SpecialPowers.pushPrefEnv({
     94    set: [["browser.crashReports.unsubmittedCheck.autoSubmit2", true]],
     95  });
     96  await openPreferencesViaOpenPreferencesAPI("privacy-reports", {
     97    leaveOpen: true,
     98  });
     99 
    100  let doc = gBrowser.contentDocument;
    101  ok(
    102    doc.querySelector("#automaticallySubmitCrashesBox").checked,
    103    "Checkbox for automatically submitting crashes should be checked when the pref is true and only Reports are requested"
    104  );
    105 
    106  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    107  await SpecialPowers.popPrefEnv();
    108 });
    109 
    110 add_task(async function () {
    111  // Skip if crash reporting isn't enabled since the checkbox will be missing.
    112  if (!AppConstants.MOZ_CRASHREPORTER) {
    113    return;
    114  }
    115 
    116  await SpecialPowers.pushPrefEnv({
    117    set: [["browser.crashReports.unsubmittedCheck.autoSubmit2", false]],
    118  });
    119  await openPreferencesViaOpenPreferencesAPI("privacy-reports", {
    120    leaveOpen: true,
    121  });
    122 
    123  let doc = gBrowser.contentDocument;
    124  ok(
    125    !doc.querySelector("#automaticallySubmitCrashesBox").checked,
    126    "Checkbox for automatically submitting crashes should not be checked when the pref is false only Reports are requested"
    127  );
    128 
    129  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    130  await SpecialPowers.popPrefEnv();
    131 });
    132 
    133 function openPreferencesViaHash(aPane) {
    134  return new Promise(resolve => {
    135    let finalPrefPaneLoaded = TestUtils.topicObserved(
    136      "sync-pane-loaded",
    137      () => true
    138    );
    139    gBrowser.selectedTab = BrowserTestUtils.addTab(
    140      gBrowser,
    141      "about:preferences" + (aPane ? "#" + aPane : "")
    142    );
    143    let newTabBrowser = gBrowser.selectedBrowser;
    144 
    145    newTabBrowser.addEventListener(
    146      "Initialized",
    147      function () {
    148        newTabBrowser.contentWindow.addEventListener(
    149          "load",
    150          async function () {
    151            let win = gBrowser.contentWindow;
    152            let selectedPane = win.history.state;
    153            await finalPrefPaneLoaded;
    154            gBrowser.removeCurrentTab();
    155            resolve({ selectedPane });
    156          },
    157          { once: true }
    158        );
    159      },
    160      { capture: true, once: true }
    161    );
    162  });
    163 }