browser_site_login_exceptions.js (4550B)
1 "use strict"; 2 const PERMISSIONS_URL = 3 "chrome://browser/content/preferences/dialogs/permissions.xhtml"; 4 5 var exceptionsDialog; 6 7 add_task(async function openLoginExceptionsSubDialog() { 8 await SpecialPowers.pushPrefEnv({ 9 set: [["browser.settings-redesign.enabled", false]], 10 }); 11 // ensure rememberSignons is off for this test; 12 ok( 13 !Services.prefs.getBoolPref("signon.rememberSignons"), 14 "Check initial value of signon.rememberSignons pref" 15 ); 16 17 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 18 19 let dialogOpened = promiseLoadSubDialog(PERMISSIONS_URL); 20 21 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 22 let doc = content.document; 23 let savePasswordCheckBox = doc.getElementById("savePasswords"); 24 Assert.ok( 25 !savePasswordCheckBox.checked, 26 "Save Password CheckBox should be unchecked by default" 27 ); 28 savePasswordCheckBox.click(); 29 30 let loginExceptionsButton = doc.getElementById("passwordExceptions"); 31 loginExceptionsButton.click(); 32 }); 33 34 exceptionsDialog = await dialogOpened; 35 36 await addALoginException(); 37 await deleteALoginException(); 38 39 exceptionsDialog.close(); 40 41 // Undo the save password change. 42 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 43 let doc = content.document; 44 let savePasswordCheckBox = doc.getElementById("savePasswords"); 45 if (savePasswordCheckBox.checked) { 46 savePasswordCheckBox.click(); 47 } 48 }); 49 50 gBrowser.removeCurrentTab(); 51 }); 52 53 add_task(async function openLoginExceptionsSubDialogNew() { 54 await SpecialPowers.pushPrefEnv({ 55 set: [["browser.settings-redesign.enabled", true]], 56 }); 57 // ensure rememberSignons is off for this test; 58 ok( 59 !Services.prefs.getBoolPref("signon.rememberSignons"), 60 "Check initial value of signon.rememberSignons pref" 61 ); 62 63 await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); 64 65 let dialogOpened = promiseLoadSubDialog(PERMISSIONS_URL); 66 67 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 68 let doc = content.document; 69 let savePasswordCheckBox = doc.getElementById("savePasswords"); 70 Assert.ok( 71 !savePasswordCheckBox.checked, 72 "Save Password CheckBox should be unchecked by default" 73 ); 74 savePasswordCheckBox.click(); 75 76 let loginExceptionsButton = doc.getElementById("managePasswordExceptions"); 77 await ContentTaskUtils.waitForCondition( 78 () => !loginExceptionsButton.disabled 79 ); 80 loginExceptionsButton.click(); 81 }); 82 83 exceptionsDialog = await dialogOpened; 84 85 await addALoginException(); 86 await deleteALoginException(); 87 88 exceptionsDialog.close(); 89 90 // Undo the save password change. 91 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 92 let doc = content.document; 93 let savePasswordCheckBox = doc.getElementById("savePasswords"); 94 if (savePasswordCheckBox.checked) { 95 savePasswordCheckBox.click(); 96 } 97 }); 98 99 gBrowser.removeCurrentTab(); 100 }); 101 102 async function addALoginException() { 103 let doc = exceptionsDialog.document; 104 105 let richlistbox = doc.getElementById("permissionsBox"); 106 Assert.equal(richlistbox.itemCount, 0, "Row count should initially be 0"); 107 108 let inputBox = doc.getElementById("url"); 109 inputBox.focus(); 110 111 EventUtils.sendString("www.example.com", exceptionsDialog); 112 113 let btnBlock = doc.getElementById("btnBlock"); 114 btnBlock.click(); 115 116 await TestUtils.waitForCondition(() => richlistbox.itemCount == 2); 117 118 let expectedResult = ["http://www.example.com", "https://www.example.com"]; 119 for (let website of expectedResult) { 120 let elements = richlistbox.getElementsByAttribute("origin", website); 121 is(elements.length, 1, "It should find only one coincidence"); 122 } 123 } 124 125 async function deleteALoginException() { 126 let doc = exceptionsDialog.document; 127 128 let richlistbox = doc.getElementById("permissionsBox"); 129 let currentItems = 2; 130 Assert.equal( 131 richlistbox.itemCount, 132 currentItems, 133 `Row count should initially be ${currentItems}` 134 ); 135 richlistbox.focus(); 136 137 while (richlistbox.itemCount) { 138 richlistbox.selectedIndex = 0; 139 140 if (AppConstants.platform == "macosx") { 141 EventUtils.synthesizeKey("KEY_Backspace"); 142 } else { 143 EventUtils.synthesizeKey("KEY_Delete"); 144 } 145 146 currentItems -= 1; 147 148 await TestUtils.waitForCondition( 149 () => richlistbox.itemCount == currentItems 150 ); 151 is_element_visible( 152 content.gSubDialog._dialogs[0]._box, 153 "Subdialog is visible after deleting an element" 154 ); 155 } 156 }