2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 // The path to the top level directory.
7 const depth
= "../../../../";
9 var gActiveListeners
= {};
11 loadScript("dom/quota/test/common/browser.js");
13 function loadScript(path
) {
14 const url
= new URL(depth
+ path
, gTestPath
);
15 Services
.scriptloader
.loadSubScript(url
.href
, this);
18 // These event (un)registration handlers only work for one window, DONOT use
19 // them with multiple windows.
21 function registerPopupEventHandler(eventName
, callback
, win
) {
25 gActiveListeners
[eventName
] = function (event
) {
26 if (event
.target
!= win
.PopupNotifications
.panel
) {
29 win
.PopupNotifications
.panel
.removeEventListener(
31 gActiveListeners
[eventName
]
33 delete gActiveListeners
[eventName
];
35 callback
.call(win
.PopupNotifications
.panel
);
37 win
.PopupNotifications
.panel
.addEventListener(
39 gActiveListeners
[eventName
]
43 function unregisterAllPopupEventHandlers(win
) {
47 for (let eventName
in gActiveListeners
) {
48 win
.PopupNotifications
.panel
.removeEventListener(
50 gActiveListeners
[eventName
]
53 gActiveListeners
= {};
56 function triggerMainCommand(popup
, win
) {
60 info("triggering main command");
61 let notifications
= popup
.childNodes
;
62 ok(notifications
.length
, "at least one notification displayed");
63 let notification
= notifications
[0];
64 info("triggering command: " + notification
.getAttribute("buttonlabel"));
66 EventUtils
.synthesizeMouseAtCenter(notification
.button
, {}, win
);
69 async
function triggerSecondaryCommand(popup
, remember
= false, win
= window
) {
70 info("triggering secondary command");
71 let notifications
= popup
.childNodes
;
72 ok(notifications
.length
, "at least one notification displayed");
73 let notification
= notifications
[0];
76 notification
.checkbox
.checked
= true;
79 await EventUtils
.synthesizeMouseAtCenter(
80 notification
.secondaryButton
,
86 function dismissNotification(popup
, win
= window
) {
87 info("dismissing notification");
88 executeSoon(function () {
89 EventUtils
.synthesizeKey("VK_ESCAPE", {}, win
);
93 function waitForMessage(aMessage
, browser
) {
94 // We cannot capture aMessage inside the checkFn, so we override the
95 // checkFn.toSource to tunnel aMessage instead.
96 let checkFn = function () {};
97 checkFn
.toSource = function () {
98 return `function checkFn(event) {
99 let message = ${aMessage.toSource()};
100 if (event.data == message) {
104 \`Unexpected result
: \$\{event
.data
\}, expected
\$\{message
\}\`
109 return BrowserTestUtils
.waitForContentEvent(
110 browser
.selectedBrowser
,
114 /* wantsUntrusted */ true
116 // An assertion in checkFn wouldn't be recorded as part of the test, so we
117 // use this assertion to confirm that we've successfully received the
118 // message (we'll only reach this point if that's the case).
119 ok(true, "Received message: " + aMessage
);
123 function removePermission(url
, permission
) {
124 let uri
= Cc
["@mozilla.org/network/io-service;1"]
125 .getService(Ci
.nsIIOService
)
127 let ssm
= Cc
["@mozilla.org/scriptsecuritymanager;1"].getService(
128 Ci
.nsIScriptSecurityManager
130 let principal
= ssm
.createContentPrincipal(uri
, {});
132 Cc
["@mozilla.org/permissionmanager;1"]
133 .getService(Ci
.nsIPermissionManager
)
134 .removeFromPrincipal(principal
, permission
);
137 function getPermission(url
, permission
) {
138 let uri
= Cc
["@mozilla.org/network/io-service;1"]
139 .getService(Ci
.nsIIOService
)
141 let ssm
= Cc
["@mozilla.org/scriptsecuritymanager;1"].getService(
142 Ci
.nsIScriptSecurityManager
144 let principal
= ssm
.createContentPrincipal(uri
, {});
146 return Cc
["@mozilla.org/permissionmanager;1"]
147 .getService(Ci
.nsIPermissionManager
)
148 .testPermissionFromPrincipal(principal
, permission
);