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() {
|
2010-09-10 02:15:44 +04:00
|
|
|
EventUtils.synthesizeKey("VK_ESCAPE", {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
function contentScript() {
|
|
|
|
addEventListener("message", function(event) {
|
|
|
|
sendAsyncMessage("testLocal:message",
|
|
|
|
{message: event.data});
|
|
|
|
}, {once: true}, true);
|
|
|
|
}
|
|
|
|
/* 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
|
|
|
{
|
2012-07-06 01:11:48 +04:00
|
|
|
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
|
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
let uri = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)
|
2017-01-09 22:27:26 +03:00
|
|
|
.newURI(url);
|
2015-08-18 10:01:42 +03:00
|
|
|
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
|
|
|
let principal = ssm.createCodebasePrincipal(uri, {});
|
2012-07-23 22:08:07 +04:00
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
Components.classes["@mozilla.org/permissionmanager;1"]
|
2014-11-28 11:44:12 +03:00
|
|
|
.getService(nsIPermissionManager)
|
|
|
|
.addFromPrincipal(principal, permission,
|
|
|
|
nsIPermissionManager.ALLOW_ACTION);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function removePermission(url, permission)
|
|
|
|
{
|
|
|
|
let uri = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)
|
2017-01-09 22:27:26 +03:00
|
|
|
.newURI(url);
|
2015-08-18 10:01:42 +03:00
|
|
|
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
|
|
|
let principal = ssm.createCodebasePrincipal(uri, {});
|
2012-07-23 22:08:07 +04:00
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIPermissionManager)
|
2012-07-23 22:08:07 +04:00
|
|
|
.removeFromPrincipal(principal, permission);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPermission(url, permission)
|
|
|
|
{
|
|
|
|
let uri = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)
|
2017-01-09 22:27:26 +03:00
|
|
|
.newURI(url);
|
2015-08-18 10:01:42 +03:00
|
|
|
let ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
|
|
|
let principal = ssm.createCodebasePrincipal(uri, {});
|
2012-07-23 22:08:07 +04:00
|
|
|
|
2010-09-10 02:15:44 +04:00
|
|
|
return Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIPermissionManager)
|
2012-07-23 22:08:07 +04:00
|
|
|
.testPermissionFromPrincipal(principal, permission);
|
2010-09-10 02:15:44 +04:00
|
|
|
}
|