tor-browser

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

browser_site_login_exceptions_policy.js (3940B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
      7  "resource://testing-common/EnterprisePolicyTesting.sys.mjs"
      8 );
      9 
     10 const PERMISSIONS_URL =
     11  "chrome://browser/content/preferences/dialogs/permissions.xhtml";
     12 
     13 var exceptionsDialog;
     14 
     15 add_task(async function openLoginExceptionsSubDialog() {
     16  await SpecialPowers.pushPrefEnv({
     17    set: [["browser.settings-redesign.enabled", false]],
     18  });
     19  // ensure rememberSignons is off for this test;
     20  ok(
     21    !Services.prefs.getBoolPref("signon.rememberSignons"),
     22    "Check initial value of signon.rememberSignons pref"
     23  );
     24 
     25  await EnterprisePolicyTesting.setupPolicyEngineWithJson({
     26    policies: {
     27      PasswordManagerExceptions: ["https://pwexception.example.com"],
     28    },
     29  });
     30 
     31  await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
     32 
     33  let dialogOpened = promiseLoadSubDialog(PERMISSIONS_URL);
     34 
     35  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     36    let doc = content.document;
     37    let savePasswordCheckBox = doc.getElementById("savePasswords");
     38    savePasswordCheckBox.click();
     39 
     40    let loginExceptionsButton = doc.getElementById("passwordExceptions");
     41    loginExceptionsButton.click();
     42  });
     43 
     44  exceptionsDialog = await dialogOpened;
     45 
     46  let doc = exceptionsDialog.document;
     47 
     48  let richlistbox = doc.getElementById("permissionsBox");
     49  Assert.equal(richlistbox.itemCount, 1, `Row count should initially be 1`);
     50 
     51  richlistbox.focus();
     52  richlistbox.selectedIndex = 0;
     53  Assert.ok(doc.getElementById("removePermission").disabled);
     54 
     55  // Undo the save password change.
     56  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     57    let savePasswordCheckBox = content.document.getElementById("savePasswords");
     58    if (savePasswordCheckBox.checked) {
     59      savePasswordCheckBox.click();
     60    }
     61  });
     62 
     63  gBrowser.removeCurrentTab();
     64  await EnterprisePolicyTesting.setupPolicyEngineWithJson("");
     65 });
     66 
     67 add_task(async function openLoginExceptionsSubDialogNew() {
     68  await SpecialPowers.pushPrefEnv({
     69    set: [["browser.settings-redesign.enabled", true]],
     70  });
     71  // ensure rememberSignons is off for this test;
     72  ok(
     73    !Services.prefs.getBoolPref("signon.rememberSignons"),
     74    "Check initial value of signon.rememberSignons pref"
     75  );
     76 
     77  await EnterprisePolicyTesting.setupPolicyEngineWithJson({
     78    policies: {
     79      PasswordManagerExceptions: ["https://pwexception.example.com"],
     80    },
     81  });
     82 
     83  info("Opening privacy panel");
     84  await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
     85 
     86  let dialogOpened = promiseLoadSubDialog(PERMISSIONS_URL);
     87 
     88  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
     89    let doc = content.document;
     90    let savePasswordCheckBox = doc.getElementById("savePasswords");
     91    savePasswordCheckBox.click();
     92 
     93    let loginExceptionsButton = doc.getElementById("managePasswordExceptions");
     94    await ContentTaskUtils.waitForCondition(
     95      () => !loginExceptionsButton.disabled
     96    );
     97    loginExceptionsButton.click();
     98  });
     99 
    100  info("Waiting for dialog to open");
    101  exceptionsDialog = await dialogOpened;
    102 
    103  info("Assert remove permission is disabled");
    104  let doc = exceptionsDialog.document;
    105 
    106  let richlistbox = doc.getElementById("permissionsBox");
    107  Assert.equal(richlistbox.itemCount, 1, `Row count should initially be 1`);
    108 
    109  richlistbox.focus();
    110  richlistbox.selectedIndex = 0;
    111  Assert.ok(doc.getElementById("removePermission").disabled);
    112 
    113  // Undo the save password change.
    114  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    115    let savePasswordCheckBox = content.document.getElementById("savePasswords");
    116    if (savePasswordCheckBox.checked) {
    117      savePasswordCheckBox.click();
    118    }
    119  });
    120 
    121  gBrowser.removeCurrentTab();
    122  await EnterprisePolicyTesting.setupPolicyEngineWithJson("");
    123 });