1 async function dohExceptionsSubdialogOpened(dialogOverlay) {
2 const promiseSubDialogLoaded = promiseLoadSubDialog(
3 "chrome://browser/content/preferences/dialogs/dohExceptions.xhtml"
5 const contentDocument = gBrowser.contentDocument;
6 contentDocument.getElementById("dohExceptionsButton").click();
7 const win = await promiseSubDialogLoaded;
8 dialogOverlay = content.gSubDialog._topDialog._overlay;
9 ok(!BrowserTestUtils.isHidden(dialogOverlay), "The dialog is visible.");
13 function acceptDoHExceptionsSubdialog(win) {
14 const button = win.document.querySelector("dialog").getButton("accept");
18 function cancelDoHExceptionsSubdialog(win) {
19 const button = win.document.querySelector("dialog").getButton("cancel");
23 function addNewException(domain, dialog) {
24 let url = dialog.document.getElementById("url");
25 let addButton = dialog.document.getElementById("btnAddException");
29 "The Add button is disabled when domain's input box is empty"
33 EventUtils.sendString(domain);
37 "The Add button is enabled when some text is on domain's input box"
45 "Domain input box is empty after adding a new domain to the list"
49 "The Add button is disabled after exception has been added to the list"
53 add_task(async function () {
54 Services.prefs.lockPref("network.trr.excluded-domains");
56 await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
59 let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
60 let win = await dohExceptionsSubdialogOpened(dialogOverlay);
63 win.document.getElementById("btnAddException").disabled,
64 "The Add button is disabled when preference is locked"
67 win.document.getElementById("url").disabled,
68 "The url input box is disabled when preference is locked"
71 cancelDoHExceptionsSubdialog(win);
72 Services.prefs.unlockPref("network.trr.excluded-domains");
73 win = await dohExceptionsSubdialogOpened(dialogOverlay);
76 win.document.getElementById("btnAddException").disabled,
77 "The Add button is disabled when preference is not locked"
80 !win.document.getElementById("url").disabled,
81 "The url input box is enabled when preference is not locked"
84 cancelDoHExceptionsSubdialog(win);
85 gBrowser.removeCurrentTab();
88 add_task(async function () {
89 await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
92 let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
94 ok(BrowserTestUtils.isHidden(dialogOverlay), "The dialog is invisible.");
95 let win = await dohExceptionsSubdialogOpened(dialogOverlay);
96 acceptDoHExceptionsSubdialog(win);
97 ok(BrowserTestUtils.isHidden(dialogOverlay), "The dialog is invisible.");
99 win = await dohExceptionsSubdialogOpened(dialogOverlay);
101 win.document.getElementById("permissionsBox").itemCount,
103 "There are no exceptions set."
106 win.document.getElementById("removeException").disabled,
107 "The Remove button is disabled when there are no exceptions on the list"
110 win.document.getElementById("removeAllExceptions").disabled,
111 "The Remove All button is disabled when there are no exceptions on the list"
114 win.document.getElementById("btnAddException").disabled,
115 "The Add button is disabled when dialog box has just been opened"
118 addNewException("test1.com", win);
120 win.document.getElementById("permissionsBox").itemCount,
122 "List shows 1 new item"
124 let activeExceptions = win.document.getElementById("permissionsBox").children;
126 activeExceptions[0].getAttribute("domain"),
128 "test1.com added to the list"
131 !win.document.getElementById("removeAllExceptions").disabled,
132 "The Remove All button is enabled when there is one exception on the list"
134 addNewException("test2.com", win);
135 addNewException("test3.com", win);
137 win.document.getElementById("permissionsBox").itemCount,
139 "List shows 3 domain items"
142 win.document.getElementById("removeException").disabled,
143 "The Remove button is disabled when no exception has been selected"
145 win.document.getElementById("permissionsBox").selectedIndex = 1;
147 !win.document.getElementById("removeException").disabled,
148 "The Remove button is enabled when an exception has been selected"
150 win.document.getElementById("removeException").doCommand();
152 win.document.getElementById("permissionsBox").itemCount,
154 "List shows 2 domain items after removing one of the three"
156 activeExceptions = win.document.getElementById("permissionsBox").children;
158 win.document.getElementById("permissionsBox").itemCount == 2 &&
159 activeExceptions[0].getAttribute("domain") == "test1.com" &&
160 activeExceptions[1].getAttribute("domain") == "test3.com",
161 "test1.com and test3.com are the only items left on the list"
164 win.document.getElementById("permissionsBox").selectedIndex,
166 "There is no selected item after removal"
168 addNewException("test2.com", win);
169 activeExceptions = win.document.getElementById("permissionsBox").children;
171 win.document.getElementById("permissionsBox").itemCount == 3 &&
172 activeExceptions[1].getAttribute("domain") == "test2.com",
173 "test2.com has been added as the second item"
175 win.document.getElementById("removeAllExceptions").doCommand();
177 win.document.getElementById("permissionsBox").itemCount,
179 "There are no elements on the list after clicking Remove All"
182 acceptDoHExceptionsSubdialog(win);
184 gBrowser.removeCurrentTab();