Bug 1899500 - Implement explicit resource management in Baseline compiler. r=arai
[gecko.git] / browser / components / preferences / tests / browser_site_login_exceptions.js
blob508232b2340a4cd910af9cfe6133bba60cff6445
1 "use strict";
2 const PERMISSIONS_URL =
3   "chrome://browser/content/preferences/dialogs/permissions.xhtml";
5 var exceptionsDialog;
7 add_task(async function openLoginExceptionsSubDialog() {
8   // ensure rememberSignons is off for this test;
9   ok(
10     !Services.prefs.getBoolPref("signon.rememberSignons"),
11     "Check initial value of signon.rememberSignons pref"
12   );
14   // Undo the save password change.
15   registerCleanupFunction(async function () {
16     await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
17       let doc = content.document;
18       let savePasswordCheckBox = doc.getElementById("savePasswords");
19       if (savePasswordCheckBox.checked) {
20         savePasswordCheckBox.click();
21       }
22     });
24     gBrowser.removeCurrentTab();
25   });
27   await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
29   let dialogOpened = promiseLoadSubDialog(PERMISSIONS_URL);
31   await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
32     let doc = content.document;
33     let savePasswordCheckBox = doc.getElementById("savePasswords");
34     Assert.ok(
35       !savePasswordCheckBox.checked,
36       "Save Password CheckBox should be unchecked by default"
37     );
38     savePasswordCheckBox.click();
40     let loginExceptionsButton = doc.getElementById("passwordExceptions");
41     loginExceptionsButton.click();
42   });
44   exceptionsDialog = await dialogOpened;
45 });
47 add_task(async function addALoginException() {
48   let doc = exceptionsDialog.document;
50   let richlistbox = doc.getElementById("permissionsBox");
51   Assert.equal(richlistbox.itemCount, 0, "Row count should initially be 0");
53   let inputBox = doc.getElementById("url");
54   inputBox.focus();
56   EventUtils.sendString("www.example.com", exceptionsDialog);
58   let btnBlock = doc.getElementById("btnBlock");
59   btnBlock.click();
61   await TestUtils.waitForCondition(() => richlistbox.itemCount == 2);
63   let expectedResult = ["http://www.example.com", "https://www.example.com"];
64   for (let website of expectedResult) {
65     let elements = richlistbox.getElementsByAttribute("origin", website);
66     is(elements.length, 1, "It should find only one coincidence");
67   }
68 });
70 add_task(async function deleteALoginException() {
71   let doc = exceptionsDialog.document;
73   let richlistbox = doc.getElementById("permissionsBox");
74   let currentItems = 2;
75   Assert.equal(
76     richlistbox.itemCount,
77     currentItems,
78     `Row count should initially be ${currentItems}`
79   );
80   richlistbox.focus();
82   while (richlistbox.itemCount) {
83     richlistbox.selectedIndex = 0;
85     if (AppConstants.platform == "macosx") {
86       EventUtils.synthesizeKey("KEY_Backspace");
87     } else {
88       EventUtils.synthesizeKey("KEY_Delete");
89     }
91     currentItems -= 1;
93     await TestUtils.waitForCondition(
94       () => richlistbox.itemCount == currentItems
95     );
96     is_element_visible(
97       content.gSubDialog._dialogs[0]._box,
98       "Subdialog is visible after deleting an element"
99     );
100   }