Bug 1899500 - Implement explicit resource management in Baseline compiler. r=arai
[gecko.git] / browser / components / preferences / tests / browser_dns_over_https_exceptions_subdialog.js
blobc24c13e9e87f1d970a5a6172968451d9ff9e5d7d
1 async function dohExceptionsSubdialogOpened(dialogOverlay) {
2   const promiseSubDialogLoaded = promiseLoadSubDialog(
3     "chrome://browser/content/preferences/dialogs/dohExceptions.xhtml"
4   );
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.");
10   return win;
13 function acceptDoHExceptionsSubdialog(win) {
14   const button = win.document.querySelector("dialog").getButton("accept");
15   button.doCommand();
18 function cancelDoHExceptionsSubdialog(win) {
19   const button = win.document.querySelector("dialog").getButton("cancel");
20   button.doCommand();
23 function addNewException(domain, dialog) {
24   let url = dialog.document.getElementById("url");
25   let addButton = dialog.document.getElementById("btnAddException");
27   ok(
28     addButton.disabled,
29     "The Add button is disabled when domain's input box is empty"
30   );
32   url.focus();
33   EventUtils.sendString(domain);
35   ok(
36     !addButton.disabled,
37     "The Add button is enabled when some text is on domain's input box"
38   );
40   addButton.click();
42   is(
43     url.value,
44     "",
45     "Domain input box is empty after adding a new domain to the list"
46   );
47   ok(
48     addButton.disabled,
49     "The Add button is disabled after exception has been added to the list"
50   );
53 add_task(async function () {
54   Services.prefs.lockPref("network.trr.excluded-domains");
56   await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
57     leaveOpen: true,
58   });
59   let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
60   let win = await dohExceptionsSubdialogOpened(dialogOverlay);
62   ok(
63     win.document.getElementById("btnAddException").disabled,
64     "The Add button is disabled when preference is locked"
65   );
66   ok(
67     win.document.getElementById("url").disabled,
68     "The url input box is disabled when preference is locked"
69   );
71   cancelDoHExceptionsSubdialog(win);
72   Services.prefs.unlockPref("network.trr.excluded-domains");
73   win = await dohExceptionsSubdialogOpened(dialogOverlay);
75   ok(
76     win.document.getElementById("btnAddException").disabled,
77     "The Add button is disabled when preference is not locked"
78   );
79   ok(
80     !win.document.getElementById("url").disabled,
81     "The url input box is enabled when preference is not locked"
82   );
84   cancelDoHExceptionsSubdialog(win);
85   gBrowser.removeCurrentTab();
86 });
88 add_task(async function () {
89   await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
90     leaveOpen: true,
91   });
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);
100   Assert.equal(
101     win.document.getElementById("permissionsBox").itemCount,
102     0,
103     "There are no exceptions set."
104   );
105   ok(
106     win.document.getElementById("removeException").disabled,
107     "The Remove button is disabled when there are no exceptions on the list"
108   );
109   ok(
110     win.document.getElementById("removeAllExceptions").disabled,
111     "The Remove All button is disabled when there are no exceptions on the list"
112   );
113   ok(
114     win.document.getElementById("btnAddException").disabled,
115     "The Add button is disabled when dialog box has just been opened"
116   );
118   addNewException("test1.com", win);
119   Assert.equal(
120     win.document.getElementById("permissionsBox").itemCount,
121     1,
122     "List shows 1 new item"
123   );
124   let activeExceptions = win.document.getElementById("permissionsBox").children;
125   is(
126     activeExceptions[0].getAttribute("domain"),
127     "test1.com",
128     "test1.com added to the list"
129   );
130   ok(
131     !win.document.getElementById("removeAllExceptions").disabled,
132     "The Remove All button is enabled when there is one exception on the list"
133   );
134   addNewException("test2.com", win);
135   addNewException("test3.com", win);
136   Assert.equal(
137     win.document.getElementById("permissionsBox").itemCount,
138     3,
139     "List shows 3 domain items"
140   );
141   ok(
142     win.document.getElementById("removeException").disabled,
143     "The Remove button is disabled when no exception has been selected"
144   );
145   win.document.getElementById("permissionsBox").selectedIndex = 1;
146   ok(
147     !win.document.getElementById("removeException").disabled,
148     "The Remove button is enabled when an exception has been selected"
149   );
150   win.document.getElementById("removeException").doCommand();
151   Assert.equal(
152     win.document.getElementById("permissionsBox").itemCount,
153     2,
154     "List shows 2 domain items after removing one of the three"
155   );
156   activeExceptions = win.document.getElementById("permissionsBox").children;
157   ok(
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"
162   );
163   is(
164     win.document.getElementById("permissionsBox").selectedIndex,
165     -1,
166     "There is no selected item after removal"
167   );
168   addNewException("test2.com", win);
169   activeExceptions = win.document.getElementById("permissionsBox").children;
170   ok(
171     win.document.getElementById("permissionsBox").itemCount == 3 &&
172       activeExceptions[1].getAttribute("domain") == "test2.com",
173     "test2.com has been added as the second item"
174   );
175   win.document.getElementById("removeAllExceptions").doCommand();
176   is(
177     win.document.getElementById("permissionsBox").itemCount,
178     0,
179     "There are no elements on the list after clicking Remove All"
180   );
182   acceptDoHExceptionsSubdialog(win);
184   gBrowser.removeCurrentTab();