2010-09-10 02:15:44 +04:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var gActiveListeners = {};
|
2010-09-10 02:15:44 +04:00
|
|
|
|
2017-07-05 05:20:55 +03:00
|
|
|
// These event (un)registration handlers only work for one window, DONOT use
|
|
|
|
// them with multiple windows.
|
|
|
|
function registerPopupEventHandler(eventName, callback, win) {
|
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
2017-05-10 19:19:34 +03:00
|
|
|
gActiveListeners[eventName] = function(event) {
|
2017-07-05 05:20:55 +03:00
|
|
|
if (event.target != win.PopupNotifications.panel)
|
2010-09-10 02:15:44 +04:00
|
|
|
return;
|
2017-07-05 05:20:55 +03:00
|
|
|
win.PopupNotifications.panel.removeEventListener(
|
|
|
|
eventName,
|
|
|
|
gActiveListeners[eventName]);
|
2010-09-10 02:15:44 +04:00
|
|
|
delete gActiveListeners[eventName];
|
|
|
|
|
2017-07-05 05:20:55 +03:00
|
|
|
callback.call(win.PopupNotifications.panel);
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2017-07-05 05:20:55 +03:00
|
|
|
win.PopupNotifications.panel.addEventListener(eventName,
|
|
|
|
gActiveListeners[eventName]);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
2017-07-05 05:20:55 +03:00
|
|
|
function unregisterPopupEventHandler(eventName, win)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
2017-07-05 05:20:55 +03:00
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
|
|
|
win.PopupNotifications.panel.removeEventListener(eventName,
|
|
|
|
gActiveListeners[eventName]);
|
2010-09-10 02:15:44 +04:00
|
|
|
delete gActiveListeners[eventName];
|
|
|
|
}
|
|
|
|
|
2017-07-05 05:20:55 +03:00
|
|
|
function unregisterAllPopupEventHandlers(win)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
2017-07-05 05:20:55 +03:00
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
2010-09-10 02:15:44 +04:00
|
|
|
for (let eventName in gActiveListeners) {
|
2017-07-05 05:20:55 +03:00
|
|
|
win.PopupNotifications.panel.removeEventListener(
|
|
|
|
eventName,
|
|
|
|
gActiveListeners[eventName]);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
gActiveListeners = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerMainCommand(popup)
|
|
|
|
{
|
|
|
|
info("triggering main command");
|
|
|
|
let notifications = popup.childNodes;
|
|
|
|
ok(notifications.length > 0, "at least one notification displayed");
|
|
|
|
let notification = notifications[0];
|
|
|
|
info("triggering command: " + notification.getAttribute("buttonlabel"));
|
|
|
|
|
2016-11-20 20:40:08 +03:00
|
|
|
EventUtils.synthesizeMouseAtCenter(notification.button, {});
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
2016-11-20 20:40:22 +03:00
|
|
|
function triggerSecondaryCommand(popup)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
2016-11-20 20:40:22 +03:00
|
|
|
info("triggering secondary command");
|
2010-09-10 02:15:44 +04:00
|
|
|
let notifications = popup.childNodes;
|
|
|
|
ok(notifications.length > 0, "at least one notification displayed");
|
|
|
|
let notification = notifications[0];
|
2016-11-20 20:40:22 +03:00
|
|
|
EventUtils.synthesizeMouseAtCenter(notification.secondaryButton, {});
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function dismissNotification(popup)
|
|
|
|
{
|
|
|
|
info("dismissing notification");
|
2017-05-10 19:19:34 +03:00
|
|
|
executeSoon(function() {
|
2018-02-14 22:15:39 +03:00
|
|
|
EventUtils.synthesizeKey("KEY_Escape");
|
2010-09-10 02:15:44 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-20 10:10:24 +03:00
|
|
|
function waitForMessage(aMessage, browser)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
2017-07-20 10:10:24 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
/* eslint-disable no-undef */
|
2017-07-04 19:03:18 +03:00
|
|
|
// When contentScript runs, "this" is a ContentFrameMessageManager (so that's where
|
|
|
|
// addEventListener will add the listener), but the non-bubbling "message" event is
|
|
|
|
// sent to the Window involved, so we need a capturing listener.
|
2017-07-20 10:10:24 +03:00
|
|
|
function contentScript() {
|
|
|
|
addEventListener("message", function(event) {
|
|
|
|
sendAsyncMessage("testLocal:message",
|
|
|
|
{message: event.data});
|
2017-07-04 19:03:18 +03:00
|
|
|
}, {once: true, capture: true}, true);
|
2017-07-20 10:10:24 +03:00
|
|
|
}
|
|
|
|
/* eslint-enable no-undef */
|
|
|
|
|
|
|
|
let script = "data:,(" + contentScript.toString() + ")();";
|
|
|
|
|
|
|
|
let mm = browser.selectedBrowser.messageManager;
|
|
|
|
|
|
|
|
mm.addMessageListener("testLocal:message", function listener(msg) {
|
|
|
|
mm.removeMessageListener("testLocal:message", listener);
|
|
|
|
mm.removeDelayedFrameScript(script);
|
|
|
|
is(msg.data.message, aMessage, "received " + aMessage);
|
|
|
|
if (msg.data.message == aMessage) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
2016-10-19 05:55:12 +03:00
|
|
|
});
|
2017-07-20 10:10:24 +03:00
|
|
|
|
|
|
|
mm.loadFrameScript(script, true);
|
2016-10-19 05:55:12 +03:00
|
|
|
});
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchEvent(eventName)
|
|
|
|
{
|
|
|
|
info("dispatching event: " + eventName);
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent(eventName, false, false);
|
|
|
|
gBrowser.selectedBrowser.contentWindow.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-11-28 11:44:12 +03:00
|
|
|
function setPermission(url, permission)
|
2010-09-10 02:15:44 +04:00
|
|
|
{
|
2018-01-10 20:25:52 +03:00
|
|
|
let uri = Services.io.newURI(url);
|
|
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
|
|
|
|
|
|
|
|
Services.perms.addFromPrincipal(principal, permission,
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function removePermission(url, permission)
|
|
|
|
{
|
2018-01-10 20:25:52 +03:00
|
|
|
let uri = Services.io.newURI(url);
|
|
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
|
|
|
|
|
|
|
|
Services.perms.removeFromPrincipal(principal, permission);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPermission(url, permission)
|
|
|
|
{
|
2018-01-10 20:25:52 +03:00
|
|
|
let uri = Services.io.newURI(url);
|
|
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
|
|
|
|
|
|
|
|
return Services.perms.testPermissionFromPrincipal(principal, permission);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|