2017-04-17 10:06:39 +03:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
2018-08-20 15:33:10 +03:00
|
|
|
const NS_ERROR_STORAGE_BUSY = Cr.NS_ERROR_STORAGE_BUSY;
|
|
|
|
|
2017-04-17 10:06:39 +03:00
|
|
|
var gActiveListeners = {};
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
gActiveListeners[eventName] = function (event) {
|
|
|
|
if (event.target != win.PopupNotifications.panel)
|
|
|
|
return;
|
|
|
|
win.PopupNotifications.panel.removeEventListener(
|
|
|
|
eventName,
|
|
|
|
gActiveListeners[eventName]);
|
|
|
|
delete gActiveListeners[eventName];
|
|
|
|
|
|
|
|
callback.call(win.PopupNotifications.panel);
|
|
|
|
}
|
|
|
|
win.PopupNotifications.panel.addEventListener(eventName,
|
|
|
|
gActiveListeners[eventName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function unregisterAllPopupEventHandlers(win)
|
|
|
|
{
|
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
|
|
|
for (let eventName in gActiveListeners) {
|
|
|
|
win.PopupNotifications.panel.removeEventListener(
|
|
|
|
eventName,
|
|
|
|
gActiveListeners[eventName]);
|
|
|
|
}
|
|
|
|
gActiveListeners = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
function triggerMainCommand(popup, win)
|
|
|
|
{
|
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
|
|
|
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"));
|
|
|
|
|
|
|
|
EventUtils.synthesizeMouseAtCenter(notification.button, {}, win);
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:15:05 +03:00
|
|
|
async function triggerSecondaryCommand(popup, actionIndex, win)
|
2017-04-17 10:06:39 +03:00
|
|
|
{
|
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
2018-11-02 11:15:05 +03:00
|
|
|
|
2017-04-17 10:06:39 +03:00
|
|
|
info("triggering secondary command");
|
|
|
|
let notifications = popup.childNodes;
|
|
|
|
ok(notifications.length > 0, "at least one notification displayed");
|
|
|
|
let notification = notifications[0];
|
2018-11-02 11:15:05 +03:00
|
|
|
|
|
|
|
if (!actionIndex) {
|
|
|
|
await EventUtils.synthesizeMouseAtCenter(notification.secondaryButton, {}, win);
|
|
|
|
} else {
|
|
|
|
// Click the dropmarker arrow and wait for the menu to show up.
|
|
|
|
let dropdownPromise =
|
|
|
|
BrowserTestUtils.waitForEvent(notification.menupopup, "popupshown");
|
|
|
|
await EventUtils.synthesizeMouseAtCenter(notification.menubutton, {});
|
|
|
|
await dropdownPromise;
|
|
|
|
|
|
|
|
let actionMenuItem = notification.querySelectorAll("menuitem")[actionIndex - 1];
|
|
|
|
await EventUtils.synthesizeMouseAtCenter(actionMenuItem, {});
|
|
|
|
}
|
2017-04-17 10:06:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function dismissNotification(popup, win)
|
|
|
|
{
|
|
|
|
if (!win) {
|
|
|
|
win = window;
|
|
|
|
}
|
|
|
|
info("dismissing notification");
|
|
|
|
executeSoon(function () {
|
|
|
|
EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-30 19:40:19 +03:00
|
|
|
function waitForMessage(aMessage, browser)
|
2017-04-17 10:06:39 +03:00
|
|
|
{
|
2017-06-30 19:40:19 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
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-06-30 19:40:19 +03:00
|
|
|
function contentScript() {
|
|
|
|
addEventListener("message", function(event) {
|
|
|
|
sendAsyncMessage("testLocal:persisted",
|
|
|
|
{persisted: event.data});
|
2017-07-04 19:03:18 +03:00
|
|
|
}, {once: true, capture: true}, true);
|
2017-06-30 19:40:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let script = "data:,(" + contentScript.toString() + ")();";
|
|
|
|
|
|
|
|
let mm = browser.selectedBrowser.messageManager;
|
|
|
|
|
|
|
|
mm.addMessageListener("testLocal:persisted", function listener(msg) {
|
|
|
|
mm.removeMessageListener("testLocal:persisted", listener);
|
|
|
|
mm.removeDelayedFrameScript(script);
|
|
|
|
is(msg.data.persisted, aMessage, "received " + aMessage);
|
|
|
|
if (msg.data.persisted == aMessage) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject();
|
|
|
|
}
|
2017-04-17 10:06:39 +03:00
|
|
|
});
|
2017-06-30 19:40:19 +03:00
|
|
|
|
|
|
|
mm.loadFrameScript(script, true);
|
2017-04-17 10:06:39 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePermission(url, permission)
|
|
|
|
{
|
2018-02-28 20:51:33 +03:00
|
|
|
let uri = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService)
|
|
|
|
.newURI(url);
|
|
|
|
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
2017-04-17 10:06:39 +03:00
|
|
|
let principal = ssm.createCodebasePrincipal(uri, {});
|
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
Cc["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Ci.nsIPermissionManager)
|
|
|
|
.removeFromPrincipal(principal, permission);
|
2017-04-17 10:06:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPermission(url, permission)
|
|
|
|
{
|
2018-02-28 20:51:33 +03:00
|
|
|
let uri = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService)
|
|
|
|
.newURI(url);
|
|
|
|
let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
2017-04-17 10:06:39 +03:00
|
|
|
let principal = ssm.createCodebasePrincipal(uri, {});
|
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
return Cc["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Ci.nsIPermissionManager)
|
|
|
|
.testPermissionFromPrincipal(principal, permission);
|
2017-04-17 10:06:39 +03:00
|
|
|
}
|
2018-08-20 15:33:10 +03:00
|
|
|
|
|
|
|
function getCurrentPrincipal()
|
|
|
|
{
|
|
|
|
return Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSimpleDatabase(principal)
|
|
|
|
{
|
|
|
|
let connection = Cc["@mozilla.org/dom/sdb-connection;1"]
|
|
|
|
.createInstance(Ci.nsISDBConnection);
|
|
|
|
|
|
|
|
if (!principal) {
|
|
|
|
principal = getCurrentPrincipal();
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.init(principal);
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestFinished(request) {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
request.callback = function(request) {
|
|
|
|
if (request.resultCode == Cr.NS_OK) {
|
|
|
|
resolve(request.result);
|
|
|
|
} else {
|
|
|
|
reject(request.resultCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.scriptloader.loadSubScript(
|
|
|
|
"chrome://mochitests/content/browser/dom/quota/test/head-shared.js", this);
|