Bug 1331599 - script-generated patch to replace removeEventListener calls with the once option when possible, r=jaws.

This commit is contained in:
Florian Quèze 2017-01-25 07:01:52 +01:00
Родитель 390f0b4fef
Коммит 0e0865f4fc
491 изменённых файлов: 1353 добавлений и 2307 удалений

Просмотреть файл

@ -51,10 +51,9 @@ window.location = "data:application/vnd.mozilla.xul+xml;charset=utf-8,<window/>"
// Create a promise that is delivered once add-on window is interactive,
// used by add-on runner to defer add-on loading until window is ready.
var { promise, resolve } = defer();
eventTarget.addEventListener("DOMContentLoaded", function handler(event) {
eventTarget.removeEventListener("DOMContentLoaded", handler);
eventTarget.addEventListener("DOMContentLoaded", function(event) {
resolve();
});
}, {once: true});
exports.ready = promise;
exports.window = window;

Просмотреть файл

@ -317,10 +317,9 @@ TestRunner.prototype = {
resolve()
}
else {
win.addEventListener("DOMContentLoaded", function onLoad() {
win.removeEventListener("DOMContentLoaded", onLoad);
win.addEventListener("DOMContentLoaded", function() {
resolve();
});
}, {once: true});
}
});
});

Просмотреть файл

@ -19,8 +19,7 @@ const open = ({ id }) => new Promise((resolve, reject) => {
let browser = getBrowserForTab(tab);
// waiting for the about:addons page to load
browser.addEventListener("load", function onPageLoad() {
browser.removeEventListener("load", onPageLoad, true);
browser.addEventListener("load", function() {
let window = browser.contentWindow;
// wait for the add-on's "addon-options-displayed"
@ -37,6 +36,6 @@ const open = ({ id }) => new Promise((resolve, reject) => {
// display the add-on inline preferences page
window.gViewController.commands.cmd_showItemDetails.doCommand({ id: id }, true);
}, true);
}, {capture: true, once: true});
});
exports.open = open;

Просмотреть файл

@ -74,9 +74,7 @@ const registerFrame = ({id, url}) => {
outerFrame.setAttribute("scrolling", "no");
outerFrame.setAttribute("disablehistory", true);
outerFrame.setAttribute("seamless", "seamless");
outerFrame.addEventListener("load", function onload() {
outerFrame.removeEventListener("load", onload, true);
outerFrame.addEventListener("load", function() {
let doc = outerFrame.contentDocument;
let innerFrame = doc.createElementNS(HTML_NS, "iframe");
@ -91,7 +89,7 @@ const registerFrame = ({id, url}) => {
"left: 0", "overflow: hidden"].join(";"));
doc.body.appendChild(innerFrame);
}, true);
}, {capture: true, once: true});
view.appendChild(outerFrame);

Просмотреть файл

@ -213,10 +213,9 @@ function onFocus(window) {
resolve(window);
}
else {
window.addEventListener("focus", function focusListener() {
window.removeEventListener("focus", focusListener, true);
window.addEventListener("focus", function() {
resolve(window);
}, true);
}, {capture: true, once: true});
}
return promise;

Просмотреть файл

@ -21,10 +21,9 @@ exports.testCrossDomainIframe = function(assert, done) {
contentScript: "new " + function ContentScriptScope() {
self.on("message", function (url) {
let iframe = document.createElement("iframe");
iframe.addEventListener("load", function onload() {
iframe.removeEventListener("load", onload);
iframe.addEventListener("load", function() {
self.postMessage(iframe.contentWindow.document.body.innerHTML);
});
}, {once: true});
iframe.setAttribute("src", url);
document.documentElement.appendChild(iframe);
});

Просмотреть файл

@ -173,8 +173,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) {
let ifWindow = helper.xrayWindow.document.getElementById("iframe").contentWindow;
// Listen without proxies, to check that it will work in regular case
// simulate listening from a web document.
ifWindow.addEventListener("message", function listener(event) {
ifWindow.removeEventListener("message", listener);
ifWindow.addEventListener("message", function(event) {
// As we are in system principal, event is an XrayWrapper
// xrays use current compartments when calling postMessage method.
// Whereas js proxies was using postMessage method compartment,
@ -187,7 +186,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) {
"message data is correct");
helper.done();
});
}, {once: true});
helper.createWorker(
'new ' + function ContentScriptScope() {
@ -659,8 +658,6 @@ exports["test Listeners"] = createProxyTest(html, function (helper) {
let addEventListenerCalled = false;
let expandoCalled = false;
input.addEventListener("click", function onclick(event) {
input.removeEventListener("click", onclick, true);
assert(!addEventListenerCalled, "closure given to addEventListener is called once");
if (addEventListenerCalled)
return;
@ -689,7 +686,7 @@ exports["test Listeners"] = createProxyTest(html, function (helper) {
input.click();
}, 0);
}, true);
}, {capture: true, once: true});
input.click();
}
@ -747,21 +744,18 @@ exports["test Cross Domain Iframe"] = createProxyTest("", function (helper) {
self.on("message", function (url) {
// Creates an iframe with this page
let iframe = document.createElement("iframe");
iframe.addEventListener("load", function onload() {
iframe.removeEventListener("load", onload, true);
iframe.addEventListener("load", function() {
try {
// Try to communicate with iframe's content
window.addEventListener("message", function onmessage(event) {
window.removeEventListener("message", onmessage, true);
window.addEventListener("message", function(event) {
assert(event.data == "hello world", "COW works properly");
self.port.emit("end");
}, true);
}, {capture: true, once: true});
iframe.contentWindow.postMessage("hello", "*");
} catch(e) {
assert(false, "COW fails : "+e.message);
}
}, true);
}, {capture: true, once: true});
iframe.setAttribute("src", url);
document.body.appendChild(iframe);
});

Просмотреть файл

@ -75,8 +75,7 @@ function loadAndWait(browser, url, callback) {
function WorkerTest(url, callback) {
return function testFunction(assert, done) {
let chromeWindow = makeWindow();
chromeWindow.addEventListener("load", function onload() {
chromeWindow.removeEventListener("load", onload, true);
chromeWindow.addEventListener("load", function() {
let browser = chromeWindow.document.createElement("browser");
browser.setAttribute("type", "content");
chromeWindow.document.documentElement.appendChild(browser);
@ -90,7 +89,7 @@ function WorkerTest(url, callback) {
});
});
});
}, true);
}, {capture: true, once: true});
};
}
@ -767,8 +766,7 @@ exports["test:check worker API with page history"] = WorkerTest(
}, 0);
// Wait for the document to be hidden
browser.addEventListener("pagehide", function onpagehide() {
browser.removeEventListener("pagehide", onpagehide);
browser.addEventListener("pagehide", function() {
// Now any event sent to this worker should be cached
worker.postMessage("message");
@ -808,7 +806,7 @@ exports["test:check worker API with page history"] = WorkerTest(
browser.goForward();
}, 500);
});
}, {once: true});
});
}

Просмотреть файл

@ -13,14 +13,13 @@ exports["test sdk/event/dom does not leak when attached to closed window"] = fun
let loader = Loader(module);
let { open } = loader.require('sdk/event/dom');
let w = openWindow();
w.addEventListener("DOMWindowClose", function windowClosed(evt) {
w.removeEventListener("DOMWindowClose", windowClosed);
w.addEventListener("DOMWindowClose", function(evt) {
// The sdk/event/dom module tries to clean itself up when DOMWindowClose
// is fired. Verify that it doesn't leak if its attached to an
// already closed window either. (See bug 1268898.)
open(w.document, "TestEvent1");
resolve(loader);
});
}, {once: true});
w.close();
});
});

Просмотреть файл

@ -13,14 +13,12 @@ exports["test sdk/tab/events does not leak new window"] = function*(assert) {
let loader = Loader(module);
let { events } = loader.require('sdk/tab/events');
let w = openWindow();
w.addEventListener("load", function windowLoaded(evt) {
w.removeEventListener("load", windowLoaded);
w.addEventListener("DOMWindowClose", function windowClosed(evt) {
w.removeEventListener("DOMWindowClose", windowClosed);
w.addEventListener("load", function(evt) {
w.addEventListener("DOMWindowClose", function(evt) {
resolve(loader);
});
}, {once: true});
w.close();
});
}, {once: true});
});
});
}
@ -30,15 +28,13 @@ exports["test sdk/tab/events does not leak when attached to existing window"] =
return new Promise(resolve => {
let loader = Loader(module);
let w = openWindow();
w.addEventListener("load", function windowLoaded(evt) {
w.removeEventListener("load", windowLoaded);
w.addEventListener("load", function(evt) {
let { events } = loader.require('sdk/tab/events');
w.addEventListener("DOMWindowClose", function windowClosed(evt) {
w.removeEventListener("DOMWindowClose", windowClosed);
w.addEventListener("DOMWindowClose", function(evt) {
resolve(loader);
});
}, {once: true});
w.close();
});
}, {once: true});
});
});
}

Просмотреть файл

@ -49,15 +49,13 @@ exports["test window/events for leaks with existing window"] = function*(assert)
return new Promise((resolve, reject) => {
let loader = Loader(module);
let w = open();
w.addEventListener("load", function windowLoaded(evt) {
w.removeEventListener("load", windowLoaded);
w.addEventListener("load", function(evt) {
let { events } = loader.require("sdk/window/events");
w.addEventListener("DOMWindowClose", function windowClosed(evt) {
w.removeEventListener("DOMWindowClose", windowClosed);
w.addEventListener("DOMWindowClose", function(evt) {
resolve(loader);
});
}, {once: true});
w.close();
});
}, {once: true});
});
});
};

Просмотреть файл

@ -13,10 +13,9 @@ function openTab(rawWindow, url) {
return resolve();
}
window.addEventListener("load", function onLoad() {
window.removeEventListener("load", onLoad, true);
window.addEventListener("load", function() {
resolve();
}, true);
}, {capture: true, once: true});
return null;
})

Просмотреть файл

@ -173,8 +173,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) {
let ifWindow = helper.xrayWindow.document.getElementById("iframe").contentWindow;
// Listen without proxies, to check that it will work in regular case
// simulate listening from a web document.
ifWindow.addEventListener("message", function listener(event) {
ifWindow.removeEventListener("message", listener);
ifWindow.addEventListener("message", function(event) {
// As we are in system principal, event is an XrayWrapper
// xrays use current compartments when calling postMessage method.
// Whereas js proxies was using postMessage method compartment,
@ -187,7 +186,7 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) {
"message data is correct");
helper.done();
});
}, {once: true});
helper.createWorker(
'new ' + function ContentScriptScope() {
@ -659,8 +658,6 @@ exports["test Listeners"] = createProxyTest(html, function (helper) {
let addEventListenerCalled = false;
let expandoCalled = false;
input.addEventListener("click", function onclick(event) {
input.removeEventListener("click", onclick, true);
assert(!addEventListenerCalled, "closure given to addEventListener is called once");
if (addEventListenerCalled)
return;
@ -689,7 +686,7 @@ exports["test Listeners"] = createProxyTest(html, function (helper) {
input.click();
}, 0);
}, true);
}, {capture: true, once: true});
input.click();
}
@ -747,21 +744,18 @@ exports["test Cross Domain Iframe"] = createProxyTest("", function (helper) {
self.on("message", function (url) {
// Creates an iframe with this page
let iframe = document.createElement("iframe");
iframe.addEventListener("load", function onload() {
iframe.removeEventListener("load", onload, true);
iframe.addEventListener("load", function() {
try {
// Try to communicate with iframe's content
window.addEventListener("message", function onmessage(event) {
window.removeEventListener("message", onmessage, true);
window.addEventListener("message", function(event) {
assert(event.data == "hello world", "COW works properly");
self.port.emit("end");
}, true);
}, {capture: true, once: true});
iframe.contentWindow.postMessage("hello", "*");
} catch(e) {
assert(false, "COW fails : "+e.message);
}
}, true);
}, {capture: true, once: true});
iframe.setAttribute("src", url);
document.body.appendChild(iframe);
});

Просмотреть файл

@ -74,8 +74,7 @@ function loadAndWait(browser, url, callback) {
function WorkerTest(url, callback) {
return function testFunction(assert, done) {
let chromeWindow = makeWindow();
chromeWindow.addEventListener("load", function onload() {
chromeWindow.removeEventListener("load", onload, true);
chromeWindow.addEventListener("load", function() {
let browser = chromeWindow.document.createElement("browser");
browser.setAttribute("type", "content");
chromeWindow.document.documentElement.appendChild(browser);
@ -89,7 +88,7 @@ function WorkerTest(url, callback) {
});
});
});
}, true);
}, {capture: true, once: true});
};
}
@ -751,8 +750,7 @@ exports["test:check worker API with page history"] = WorkerTest(
}, 0);
// Wait for the document to be hidden
browser.addEventListener("pagehide", function onpagehide() {
browser.removeEventListener("pagehide", onpagehide);
browser.addEventListener("pagehide", function() {
// Now any event sent to this worker should throw
assert.throws(
@ -781,7 +779,7 @@ exports["test:check worker API with page history"] = WorkerTest(
browser.goForward();
}, 500);
});
}, {once: true});
});
}

Просмотреть файл

@ -75,8 +75,7 @@ function loadAndWait(browser, url, callback) {
function WorkerTest(url, callback) {
return function testFunction(assert, done) {
let chromeWindow = makeWindow();
chromeWindow.addEventListener("load", function onload() {
chromeWindow.removeEventListener("load", onload, true);
chromeWindow.addEventListener("load", function() {
let browser = chromeWindow.document.createElement("browser");
browser.setAttribute("type", "content");
chromeWindow.document.documentElement.appendChild(browser);
@ -90,7 +89,7 @@ function WorkerTest(url, callback) {
});
});
});
}, true);
}, {capture: true, once: true});
};
}
@ -768,8 +767,7 @@ exports["test:check worker API with page history"] = WorkerTest(
}, 0);
// Wait for the document to be hidden
browser.addEventListener("pagehide", function onpagehide() {
browser.removeEventListener("pagehide", onpagehide);
browser.addEventListener("pagehide", function() {
// Now any event sent to this worker should be cached
worker.postMessage("message");
@ -809,7 +807,7 @@ exports["test:check worker API with page history"] = WorkerTest(
browser.goForward();
}, 500);
});
}, {once: true});
});
}

Просмотреть файл

@ -29,13 +29,12 @@ exports['test fram has js disabled by default'] = function(assert, done) {
uri: 'data:text/html;charset=utf-8,<script>document.documentElement.innerHTML' +
'= "J" + "S"</script>',
});
frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
frame.contentWindow.removeEventListener('DOMContentLoaded', ready);
frame.contentWindow.addEventListener('DOMContentLoaded', function() {
assert.ok(!~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
'JS was executed');
close(window).then(done);
});
}, {once: true});
});
};
@ -46,13 +45,12 @@ exports['test frame with js enabled'] = function(assert, done) {
'= "J" + "S"</script>',
allowJavascript: true
});
frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
frame.contentWindow.removeEventListener('DOMContentLoaded', ready);
frame.contentWindow.addEventListener('DOMContentLoaded', function() {
assert.ok(~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
'JS was executed');
close(window).then(done);
});
}, {once: true});
});
};

Просмотреть файл

@ -1027,8 +1027,7 @@ exports.testAttachToTabsOnly = function(assert, done) {
let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
onReady: function () {
let element = this.element;
element.addEventListener('DOMContentLoaded', function onload() {
element.removeEventListener('DOMContentLoaded', onload);
element.addEventListener('DOMContentLoaded', function() {
hiddenFrames.remove(hiddenFrame);
if (!xulApp.is("Fennec")) {
@ -1037,7 +1036,7 @@ exports.testAttachToTabsOnly = function(assert, done) {
else {
openBrowserIframe();
}
});
}, {once: true});
element.setAttribute('src', 'data:text/html;charset=utf-8,foo');
}
}));
@ -1046,11 +1045,10 @@ exports.testAttachToTabsOnly = function(assert, done) {
function openToplevelWindow() {
assert.pass('Open toplevel window');
let win = open('data:text/html;charset=utf-8,bar');
win.addEventListener('DOMContentLoaded', function onload() {
win.removeEventListener('DOMContentLoaded', onload);
win.addEventListener('DOMContentLoaded', function() {
win.close();
openBrowserIframe();
});
}, {once: true});
}
function openBrowserIframe() {
@ -1060,11 +1058,10 @@ exports.testAttachToTabsOnly = function(assert, done) {
let iframe = document.createElement('iframe');
iframe.setAttribute('type', 'content');
iframe.setAttribute('src', 'data:text/html;charset=utf-8,foobar');
iframe.addEventListener('DOMContentLoaded', function onload() {
iframe.removeEventListener('DOMContentLoaded', onload);
iframe.addEventListener('DOMContentLoaded', function() {
iframe.parentNode.removeChild(iframe);
openTabWithIframes();
});
}, {once: true});
document.documentElement.appendChild(iframe);
}

Просмотреть файл

@ -1095,10 +1095,9 @@ exports.testSidebarLeakCheckDestroyAfterAttach = function*(assert) {
yield new Promise(resolve => {
let panelBrowser = window.document.getElementById('sidebar').contentDocument.getElementById('web-panels-browser');
panelBrowser.contentWindow.addEventListener('unload', function onUnload() {
panelBrowser.contentWindow.removeEventListener('unload', onUnload);
panelBrowser.contentWindow.addEventListener('unload', function() {
resolve();
});
}, {once: true});
sidebar.destroy();
});
@ -1137,10 +1136,9 @@ exports.testSidebarLeakCheckUnloadAfterAttach = function*(assert) {
let panelBrowser = window.document.getElementById('sidebar').contentDocument.getElementById('web-panels-browser');
yield new Promise(resolve => {
panelBrowser.contentWindow.addEventListener('unload', function onUnload() {
panelBrowser.contentWindow.removeEventListener('unload', onUnload);
panelBrowser.contentWindow.addEventListener('unload', function() {
resolve();
});
}, {once: true});
loader.unload();
});

Просмотреть файл

@ -41,8 +41,7 @@ exports.testWindowTracker = function(assert, done) {
var myWindow = makeEmptyWindow();
assert.pass('window was created');
myWindow.addEventListener("load", function onload() {
myWindow.removeEventListener("load", onload);
myWindow.addEventListener("load", function() {
assert.pass("test window has opened");
// test bug 638007 (new is optional), using new
@ -61,7 +60,7 @@ exports.testWindowTracker = function(assert, done) {
}
}
});
});
}, {once: true});
};
exports['test window watcher untracker'] = function(assert, done) {

Просмотреть файл

@ -51,12 +51,11 @@ exports.testLocalXhr = function(assert, done) {
assert.equal(req.responseText, '{}\n', 'XMLHttpRequest should get local files');
}
};
req.addEventListener('load', function onload() {
req.removeEventListener('load', onload);
req.addEventListener('load', function() {
assert.pass('addEventListener for load event worked');
assert.ok(ready, 'onreadystatechange listener worked');
done();
});
}, {once: true});
req.send(null);
};

Просмотреть файл

@ -60,10 +60,9 @@ var OrientationChangeHandler = {
return;
}
window.addEventListener("resize", function waitForResize(e) {
window.removeEventListener("resize", waitForResize);
window.addEventListener("resize", function(e) {
trigger();
});
}, {once: true});
}
};

Просмотреть файл

@ -113,8 +113,7 @@ var steps = [
SystemAppProxy.registerFrame(frame);
assert.ok(true, "Frame created and registered");
frame.contentWindow.addEventListener("load", function onload() {
frame.contentWindow.removeEventListener("load", onload);
frame.contentWindow.addEventListener("load", function() {
assert.ok(true, "Frame document loaded");
// Declare that the iframe is now loaded.
@ -128,7 +127,7 @@ var steps = [
// Once pending events are received,
// we will run checkEventDispatching from `listener` function
});
}, {once: true});
frame.setAttribute("src", "data:text/html,system app");
},

Просмотреть файл

@ -50,10 +50,9 @@ function loadBrowser() {
iframe.src = 'about:blank';
document.body.appendChild(iframe);
iframe.addEventListener("load", function onLoad() {
iframe.removeEventListener("load", onLoad);
iframe.addEventListener("load", function() {
runNext();
});
}, {once: true});
}
gScript.addMessageListener("permission-request", function (detail) {

Просмотреть файл

@ -497,8 +497,7 @@ function getDefaultProfilePath() {
return defaultProfile.rootDir.path;
}
document.addEventListener("DOMContentLoaded", function onload() {
document.removeEventListener("DOMContentLoaded", onload, true);
document.addEventListener("DOMContentLoaded", function() {
init();
var buttonGetStarted = document.getElementById("buttonGetStarted");
buttonGetStarted.addEventListener("click", getStarted);
@ -511,7 +510,7 @@ document.addEventListener("DOMContentLoaded", function onload() {
var buttonOpenPrefs = document.getElementById("buttonOpenPrefs")
buttonOpenPrefs.addEventListener("click", openPrefs);
}, true);
}, {capture: true, once: true});
function initObservers() {
function observe(subject, topic, data) {

Просмотреть файл

@ -226,10 +226,9 @@ function setupSearch() {
// immediately when the element is first drawn, so the
// attribute is also used for styling when the page first loads.
searchText = document.getElementById("searchText");
searchText.addEventListener("blur", function searchText_onBlur() {
searchText.removeEventListener("blur", searchText_onBlur);
searchText.addEventListener("blur", function() {
searchText.removeAttribute("autofocus");
});
}, {once: true});
if (!gContentSearchController) {
gContentSearchController =

Просмотреть файл

@ -1943,10 +1943,9 @@ function focusAndSelectUrlBar() {
// We can't focus it when it's disabled, so we need to re-run ourselves when
// we've finished leaving customize mode.
if (CustomizationHandler.isExitingCustomizeMode) {
gNavToolbox.addEventListener("aftercustomization", function afterCustomize() {
gNavToolbox.removeEventListener("aftercustomization", afterCustomize);
gNavToolbox.addEventListener("aftercustomization", function() {
focusAndSelectUrlBar();
});
}, {once: true});
return true;
}

Просмотреть файл

@ -853,10 +853,9 @@ ContentSearchUIController.prototype = {
"chrome://browser/skin/search-engine-placeholder.png");
}
img.setAttribute("src", uri);
img.addEventListener("load", function imgLoad() {
img.removeEventListener("load", imgLoad);
img.addEventListener("load", function() {
URL.revokeObjectURL(uri);
});
}, {once: true});
button.appendChild(img);
button.style.width = buttonWidth + "px";
button.setAttribute("title", engine.name);

Просмотреть файл

@ -32,10 +32,9 @@ var gCustomize = {
},
hidePanel: function() {
this._nodes.overlay.addEventListener("transitionend", function onTransitionEnd() {
gCustomize._nodes.overlay.removeEventListener("transitionend", onTransitionEnd);
this._nodes.overlay.addEventListener("transitionend", function() {
gCustomize._nodes.overlay.style.display = "none";
});
}, {once: true});
this._nodes.overlay.style.opacity = 0;
this._nodes.button.removeAttribute("active");
this._nodes.panel.removeAttribute("open");

Просмотреть файл

@ -111,8 +111,6 @@ var gSyncUtils = {
iframe.collapsed = true;
document.documentElement.appendChild(iframe);
iframe.contentWindow.addEventListener("load", function() {
iframe.contentWindow.removeEventListener("load", arguments.callee);
// Insert the Sync Key into the page.
let el = iframe.contentDocument.getElementById("synckey");
el.firstChild.nodeValue = pp;
@ -129,7 +127,7 @@ var gSyncUtils = {
el.firstChild.nodeValue = privacyURL;
callback(iframe);
});
}, {once: true});
},
/**

Просмотреть файл

@ -1114,10 +1114,9 @@
var forwardButtonContainer = document.getElementById("urlbar-wrapper");
if (forwardButtonContainer) {
forwardButtonContainer.setAttribute("switchingtabs", "true");
window.addEventListener("MozAfterPaint", function removeSwitchingtabsAttr() {
window.removeEventListener("MozAfterPaint", removeSwitchingtabsAttr);
window.addEventListener("MozAfterPaint", function() {
forwardButtonContainer.removeAttribute("switchingtabs");
});
}, {once: true});
}
this._appendStatusPanel();

Просмотреть файл

@ -3,15 +3,14 @@ function promiseAlertWindow() {
let listener = {
onOpenWindow(window) {
let alertWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
alertWindow.addEventListener("load", function onLoad() {
alertWindow.removeEventListener("load", onLoad);
alertWindow.addEventListener("load", function() {
let windowType = alertWindow.document.documentElement.getAttribute("windowtype");
if (windowType != "alert:alert") {
return;
}
Services.wm.removeListener(listener);
resolve(alertWindow);
});
}, {once: true});
},
};
Services.wm.addListener(listener);

Просмотреть файл

@ -565,9 +565,7 @@ function* withSnippetsMap(setupFn, testFn, testArgs = null, parentFn = null) {
let document = content.document;
// We're not using Promise-based listeners, because they resolve asynchronously.
// The snippets test setup code relies on synchronous behaviour here.
document.addEventListener("AboutHomeLoadSnippets", function loadSnippets() {
document.removeEventListener("AboutHomeLoadSnippets", loadSnippets);
document.addEventListener("AboutHomeLoadSnippets", function() {
let updateSnippets;
if (args.setupFnSource) {
updateSnippets = eval(`(() => (${args.setupFnSource}))()`);
@ -594,7 +592,7 @@ function* withSnippetsMap(setupFn, testFn, testArgs = null, parentFn = null) {
resolve();
});
});
}, {once: true});
});
});
};

Просмотреть файл

@ -12,10 +12,9 @@ add_task(function* () {
// While in the child process, add a listener for the popstate event here. This
// event will fire when the mouse click happens.
content.addEventListener("popstate", function onPopState() {
content.removeEventListener("popstate", onPopState);
content.addEventListener("popstate", function() {
sendAsyncMessage("Test:PopStateOccurred", { location: content.document.location.href });
});
}, {once: true});
});
window.maximize();

Просмотреть файл

@ -68,13 +68,12 @@ function test_paste(aCurrentTest) {
// Focus the element and wait for focus event.
info("About to focus " + element.id);
element.addEventListener("focus", function() {
element.removeEventListener("focus", arguments.callee);
executeSoon(function() {
// Pasting is async because the Accel+V codepath ends up going through
// nsDocumentViewer::FireClipboardEvent.
info("Pasting into " + element.id);
EventUtils.synthesizeKey("v", { accelKey: true });
});
});
}, {once: true});
element.focus();
}

Просмотреть файл

@ -25,10 +25,9 @@ function addTab(aURI, aIndex) {
gBrowser.removeTab(gBrowser.tabs[0], {skipPermitUnload: true});
tab.linkedBrowser.addEventListener("load", function(event) {
event.currentTarget.removeEventListener("load", arguments.callee, true);
if (++count == URIS.length)
executeSoon(doTabsTest);
}, true);
}, {capture: true, once: true});
}
function doTabsTest() {
@ -36,14 +35,13 @@ function doTabsTest() {
// sample of "close related tabs" feature
gBrowser.tabContainer.addEventListener("TabClose", function(event) {
event.currentTarget.removeEventListener("TabClose", arguments.callee, true);
var closedTab = event.originalTarget;
var scheme = closedTab.linkedBrowser.currentURI.scheme;
Array.slice(gBrowser.tabs).forEach(function(aTab) {
if (aTab != closedTab && aTab.linkedBrowser.currentURI.scheme == scheme)
gBrowser.removeTab(aTab, {skipPermitUnload: true});
});
}, true);
}, {capture: true, once: true});
gBrowser.removeTab(gBrowser.tabs[0], {skipPermitUnload: true});
is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly");

Просмотреть файл

@ -44,10 +44,9 @@ function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
gBrowser.selectedBrowser.addEventListener("load", function() {
waitForStarChange(false, initTest);
}, true);
}, {capture: true, once: true});
content.location = testURL;
}

Просмотреть файл

@ -6,13 +6,10 @@ function test() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec,
"mediaTab");
pageInfo.addEventListener("load", function() {
pageInfo.removeEventListener("load", arguments.callee, true);
pageInfo.onFinished.push(function() {
executeSoon(function() {
var imageTree = pageInfo.document.getElementById("imagetree");
@ -28,8 +25,8 @@ function test() {
finish();
});
});
}, true);
}, true);
}, {capture: true, once: true});
}, {capture: true, once: true});
content.location =
"data:text/html," +

Просмотреть файл

@ -4,8 +4,6 @@ function test() {
"http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug479408_sample.html");
gBrowser.addEventListener("DOMLinkAdded", function(aEvent) {
gBrowser.removeEventListener("DOMLinkAdded", arguments.callee, true);
executeSoon(function() {
ok(!tab.linkedBrowser.engines,
"the subframe's search engine wasn't detected");
@ -13,5 +11,5 @@ function test() {
gBrowser.removeTab(tab);
finish();
});
}, true);
}, {capture: true, once: true});
}

Просмотреть файл

@ -12,13 +12,11 @@ function test() {
// test normal close
tabA = gBrowser.addTab(testPage);
gBrowser.tabContainer.addEventListener("TabClose", function(firstTabCloseEvent) {
gBrowser.tabContainer.removeEventListener("TabClose", arguments.callee, true);
ok(!firstTabCloseEvent.detail.adoptedBy, "This was a normal tab close");
// test tab close by moving
tabB = gBrowser.addTab(testPage);
gBrowser.tabContainer.addEventListener("TabClose", function(secondTabCloseEvent) {
gBrowser.tabContainer.removeEventListener("TabClose", arguments.callee, true);
executeSoon(function() {
ok(secondTabCloseEvent.detail.adoptedBy, "This was a tab closed by moving");
@ -26,9 +24,9 @@ function test() {
newWin.close();
executeSoon(finish);
});
}, true);
}, {capture: true, once: true});
newWin = gBrowser.replaceTabWithWindow(tabB);
}, true);
}, {capture: true, once: true});
gBrowser.removeTab(tabA);
}

Просмотреть файл

@ -6,15 +6,12 @@ function test() {
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
var doc = gBrowser.contentDocument;
var testImg = doc.getElementById("test-image");
var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec,
"mediaTab", testImg);
pageInfo.addEventListener("load", function() {
pageInfo.removeEventListener("load", arguments.callee, true);
pageInfo.onFinished.push(function() {
executeSoon(function() {
var pageInfoImg = pageInfo.document.getElementById("thepreviewimage");
@ -28,8 +25,8 @@ function test() {
finish();
});
});
}, true);
}, true);
}, {capture: true, once: true});
}, {capture: true, once: true});
content.location =
"data:text/html," +

Просмотреть файл

@ -61,10 +61,9 @@ function waitForProgressNotification(aPanelOpen = false, aExpectedCount = 1) {
panelEventPromise = Promise.resolve();
} else {
panelEventPromise = new Promise(resolve => {
PopupNotifications.panel.addEventListener("popupshowing", function eventListener() {
PopupNotifications.panel.removeEventListener("popupshowing", eventListener);
PopupNotifications.panel.addEventListener("popupshowing", function() {
resolve();
});
}, {once: true});
});
}
@ -134,10 +133,9 @@ function waitForNotification(aId, aExpectedCount = 1) {
function waitForNotificationClose() {
return new Promise(resolve => {
info("Waiting for notification to close");
PopupNotifications.panel.addEventListener("popuphidden", function listener() {
PopupNotifications.panel.removeEventListener("popuphidden", listener);
PopupNotifications.panel.addEventListener("popuphidden", function() {
resolve();
});
}, {once: true});
});
}

Просмотреть файл

@ -12,10 +12,9 @@ function test() {
// Verify that about:addons loads
waitForExplicitFinish();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
let browser = blanktab.linkedBrowser;
is(browser.currentURI.spec, "about:addons", "about:addons should load into blank tab.");
gBrowser.removeTab(blanktab);
finish();
}, true);
}, {capture: true, once: true});
}

Просмотреть файл

@ -17,8 +17,6 @@ function test() {
let tab = gBrowser.selectedTab = gBrowser.addTab();
tab.linkedBrowser.addEventListener("load", (function(event) {
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let uri = makeURI(testURL);
let bmTxn =
new PlacesCreateBookmarkTransaction(uri,
@ -28,7 +26,7 @@ function test() {
ok(PlacesUtils.bookmarks.isBookmarked(uri), "the test url is bookmarked");
waitForStarChange(true, onStarred);
}), true);
}), {capture: true, once: true});
content.location = testURL;
}

Просмотреть файл

@ -10,9 +10,8 @@ var LightweightThemeManager = tempScope.LightweightThemeManager;
function wait_for_notification(aCallback) {
PopupNotifications.panel.addEventListener("popupshown", function() {
PopupNotifications.panel.removeEventListener("popupshown", arguments.callee);
aCallback(PopupNotifications.panel);
});
}, {once: true});
}
var TESTS = [

Просмотреть файл

@ -30,18 +30,16 @@ function duplicate(delta, msg, cb) {
duplicateTabIn(gBrowser.selectedTab, "tab", delta);
let tab = gBrowser.selectedTab;
tab.addEventListener("SSTabRestored", function tabRestoredListener() {
tab.removeEventListener("SSTabRestored", tabRestoredListener);
tab.addEventListener("SSTabRestored", function() {
is(gBrowser.sessionHistory.index, start + delta, msg);
executeSoon(cb);
});
}, {once: true});
}
function loadAndWait(url, cb) {
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
executeSoon(cb);
}, true);
}, {capture: true, once: true});
gBrowser.loadURI(url);
}

Просмотреть файл

@ -4,8 +4,6 @@ function test() {
var tab = gBrowser.addTab();
tab.addEventListener("TabClose", function() {
tab.removeEventListener("TabClose", arguments.callee);
ok(tab.linkedBrowser, "linkedBrowser should still exist during the TabClose event");
executeSoon(function() {
@ -13,7 +11,7 @@ function test() {
finish();
});
});
}, {once: true});
gBrowser.removeTab(tab);
}

Просмотреть файл

@ -35,10 +35,9 @@ function test() {
}
function load(aTab, aUrl, aCallback) {
aTab.linkedBrowser.addEventListener("load", function onload(aEvent) {
aEvent.currentTarget.removeEventListener("load", onload, true);
aTab.linkedBrowser.addEventListener("load", function(aEvent) {
waitForFocus(aCallback, content);
}, true);
}, {capture: true, once: true});
aTab.linkedBrowser.loadURI(aUrl);
}

Просмотреть файл

@ -65,10 +65,9 @@ add_task(function* () {
// Wait for the iframe to load.
return new Promise(resolve => {
iframe.addEventListener("load", function onload() {
iframe.removeEventListener("load", onload, true);
iframe.addEventListener("load", function() {
resolve("context-showonlythisframe");
}, true);
}, {capture: true, once: true});
});
});
},

Просмотреть файл

@ -28,9 +28,8 @@ function test() {
}
function load(aTab, aUrl, aCallback) {
aTab.linkedBrowser.addEventListener("load", function onload(aEvent) {
aEvent.currentTarget.removeEventListener("load", onload, true);
aTab.linkedBrowser.addEventListener("load", function(aEvent) {
waitForFocus(aCallback, content);
}, true);
}, {capture: true, once: true});
aTab.linkedBrowser.loadURI(aUrl);
}

Просмотреть файл

@ -83,8 +83,7 @@ function openNewTab(aWindow, aCallback) {
return;
}
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
browser.addEventListener("load", function() {
executeSoon(aCallback);
}, true);
}, {capture: true, once: true});
}

Просмотреть файл

@ -48,8 +48,7 @@ function preparePendingTab(aCallback) {
}
function whenLoaded(aElement, aCallback) {
aElement.addEventListener("load", function onLoad() {
aElement.removeEventListener("load", onLoad, true);
aElement.addEventListener("load", function() {
executeSoon(aCallback);
}, true);
}, {capture: true, once: true});
}

Просмотреть файл

@ -7,8 +7,7 @@ function test() {
ok(true, "Starting up");
gBrowser.selectedBrowser.focus();
gURLBar.addEventListener("focus", function onFocus() {
gURLBar.removeEventListener("focus", onFocus);
gURLBar.addEventListener("focus", function() {
ok(true, "Invoked onfocus handler");
EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true });
@ -17,7 +16,7 @@ function test() {
ok(true, "Evaluated without crashing");
finish();
});
});
}, {once: true});
gURLBar.inputField.value = "javascript: var foo = '11111111'; ";
gURLBar.focus();
}

Просмотреть файл

@ -10,14 +10,13 @@ add_task(function*() {
textbox.select();
yield new Promise((resolve, reject) => {
textbox.addEventListener("copy", function copyEvent(event) {
textbox.removeEventListener("copy", copyEvent, true);
textbox.addEventListener("copy", function(event) {
event.clipboardData.setData("text/plain", "Alternate");
// For this test, it doesn't matter that the file isn't actually a file.
event.clipboardData.setData("application/x-moz-file", "Sample");
event.preventDefault();
resolve();
}, true)
}, {capture: true, once: true})
EventUtils.synthesizeKey("c", { accelKey: true });
});
@ -40,9 +39,7 @@ add_task(function*() {
textbox.focus();
yield new Promise((resolve, reject) => {
textbox.addEventListener("paste", function copyEvent(event) {
textbox.removeEventListener("paste", copyEvent, true);
textbox.addEventListener("paste", function(event) {
let dt = event.clipboardData;
is(dt.types.length, 3, "number of types");
ok(dt.types.includes("text/plain"), "text/plain exists in types");
@ -51,7 +48,7 @@ add_task(function*() {
is(dt.mozGetDataAt("text/plain", 0), "Alternate", "text/plain returned in mozGetDataAt");
resolve();
}, true);
}, {capture: true, once: true});
EventUtils.synthesizeKey("v", { accelKey: true });
});

Просмотреть файл

@ -7,11 +7,10 @@ add_task(function* () {
// Wait for a process change and then fulfil the promise.
function awaitProcessChange(browser) {
return new Promise(resolve => {
browser.addEventListener("BrowserChangedProcess", function bcp(e) {
browser.removeEventListener("BrowserChangedProcess", bcp);
browser.addEventListener("BrowserChangedProcess", function(e) {
ok(true, "The browser changed process!");
resolve();
});
}, {once: true});
});
}

Просмотреть файл

@ -45,10 +45,9 @@ function promiseNextTick() {
*/
function promiseWaitForAlertActive(aNotificationBox) {
let deferred = PromiseUtils.defer();
aNotificationBox.addEventListener("AlertActive", function onActive() {
aNotificationBox.removeEventListener("AlertActive", onActive, true);
aNotificationBox.addEventListener("AlertActive", function() {
deferred.resolve();
});
}, {once: true});
return deferred.promise;
}

Просмотреть файл

@ -6,9 +6,8 @@ function doc() {
function setHandlerFunc(aResultFunc) {
gBrowser.addEventListener("DOMLinkAdded", function(event) {
gBrowser.removeEventListener("DOMLinkAdded", arguments.callee);
executeSoon(aResultFunc);
});
}, {once: true});
}
function test() {
@ -17,9 +16,8 @@ function test() {
gBrowser.selectedTab = gBrowser.addTab();
browser = gBrowser.selectedBrowser;
browser.addEventListener("load", function(event) {
event.currentTarget.removeEventListener("load", arguments.callee, true);
iconDiscovery();
}, true);
}, {capture: true, once: true});
var rootDir = getRootDirectory(gTestPath);
content.location = rootDir + "discovery.html";
}

Просмотреть файл

@ -48,9 +48,7 @@ function* expectFocusOnF6(backward, expectedDocument, expectedElement, onContent
return;
}
contentExpectedElement.addEventListener("focus", function focusReceived() {
contentExpectedElement.removeEventListener("focus", focusReceived, true);
contentExpectedElement.addEventListener("focus", function() {
const contentFM = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager);
let details = contentFM.focusedWindow.document.documentElement.id;
@ -59,7 +57,7 @@ function* expectFocusOnF6(backward, expectedDocument, expectedElement, onContent
}
sendSyncMessage("BrowserTest:FocusChanged", { details });
}, true);
}, {capture: true, once: true});
});
}

Просмотреть файл

@ -5,17 +5,15 @@ add_task(function *() {
gURLBar.focus();
window.addEventListener("keyup", function countKeyUps(event) {
window.removeEventListener("keyup", countKeyUps, true);
window.addEventListener("keyup", function(event) {
if (event.originalTarget == gURLBar.inputField) {
keyUps++;
}
}, true);
}, {capture: true, once: true});
gURLBar.addEventListener("keydown", function redirectFocus(event) {
gURLBar.removeEventListener("keydown", redirectFocus, true);
gURLBar.addEventListener("keydown", function(event) {
gBrowser.selectedBrowser.focus();
}, true);
}, {capture: true, once: true});
EventUtils.synthesizeKey("v", { });

Просмотреть файл

@ -14,13 +14,11 @@ function test() {
let numVisBeforeHide, numVisAfterHide;
gBrowser.tabContainer.addEventListener("TabSelect", function() {
gBrowser.tabContainer.removeEventListener("TabSelect", arguments.callee);
// While the next tab is being selected, hide the removing tab
numVisBeforeHide = gBrowser.visibleTabs.length;
gBrowser.hideTab(testTab);
numVisAfterHide = gBrowser.visibleTabs.length;
});
}, {once: true});
gBrowser.removeTab(testTab, {animate: true});
// Make sure the tab gets removed at the end of the animation by polling

Просмотреть файл

@ -46,9 +46,8 @@ add_task(function* test_keyword_bookmarklet() {
function* promisePageShow() {
return new Promise(resolve => {
gBrowser.selectedBrowser.addEventListener("pageshow", function listen() {
gBrowser.selectedBrowser.removeEventListener("pageshow", listen);
gBrowser.selectedBrowser.addEventListener("pageshow", function() {
resolve();
});
}, {once: true});
});
}

Просмотреть файл

@ -25,9 +25,8 @@ function test() {
ok(false, "Alert window opened");
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
win.addEventListener("load", function() {
win.removeEventListener("load", arguments.callee);
win.close();
});
}, {once: true});
executeSoon(finish);
}
}

Просмотреть файл

@ -23,10 +23,9 @@ function promiseNewWindow() {
if (topic == "domwindowopened") {
Services.ww.unregisterNotification(observer);
let win = subject.QueryInterface(Ci.nsIDOMWindow);
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad);
win.addEventListener("load", function() {
resolve(win);
});
}, {once: true});
}
};

Просмотреть файл

@ -68,12 +68,11 @@ function test() {
// tab to open - which we track via an "Initialized" event.
PopupNotifications.panel.firstElementChild.button.click();
let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
newTabBrowser.addEventListener("Initialized", function PrefInit() {
newTabBrowser.removeEventListener("Initialized", PrefInit, true);
newTabBrowser.addEventListener("Initialized", function() {
executeSoon(function() {
checkInContentPreferences(newTabBrowser.contentWindow);
})
}, true);
}, {capture: true, once: true});
});
onCachedAttached.then(function() {
Services.prefs.setIntPref("offline-apps.quota.warn", 1);
@ -87,9 +86,8 @@ function test() {
function promiseNotification() {
return new Promise(resolve => {
PopupNotifications.panel.addEventListener("popupshown", function onShown() {
PopupNotifications.panel.removeEventListener("popupshown", onShown);
PopupNotifications.panel.addEventListener("popupshown", function() {
resolve();
});
}, {once: true});
});
}

Просмотреть файл

@ -4,12 +4,10 @@ function test() {
var pageInfo;
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function loadListener() {
gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
gBrowser.selectedBrowser.addEventListener("load", function() {
Services.obs.addObserver(observer, "page-info-dialog-loaded", false);
pageInfo = BrowserPageInfo();
}, true);
}, {capture: true, once: true});
content.location =
"https://example.com/browser/browser/base/content/test/general/feed_tab.html";

Просмотреть файл

@ -786,15 +786,13 @@ WindowHelper.prototype = {
let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
win.addEventListener("load", function onload(event) {
win.removeEventListener("load", onload);
if (win.name !== "SanitizeDialog")
return;
wh.win = win;
loaded = true;
executeSoon(() => wh.onload());
});
}, {once: true});
win.addEventListener("unload", function onunload(event) {
if (win.name !== "SanitizeDialog") {

Просмотреть файл

@ -104,9 +104,7 @@ var windowObserver = {
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
win.addEventListener("load", function onLoad(event) {
win.removeEventListener("load", onLoad);
win.addEventListener("load", function(event) {
if (win.location == UCT_URI) {
SimpleTest.executeSoon(function() {
if (windowObserver._callback) {
@ -117,7 +115,7 @@ var windowObserver = {
}
});
}
});
}, {once: true});
}
};

Просмотреть файл

@ -329,10 +329,9 @@ add_task(function*() {
elem = content.document.getElementById(contentStep[0]);
}
changedWin.addEventListener("MozAfterPaint", function onPaint() {
changedWin.removeEventListener("MozAfterPaint", onPaint);
changedWin.addEventListener("MozAfterPaint", function() {
resolve();
});
}, {once: true});
elem.style = contentStep[1];
elem.getBoundingClientRect();
@ -675,11 +674,10 @@ add_task(function* test_mousemove_correcttarget() {
yield popupShownPromise;
yield new Promise(resolve => {
window.addEventListener("mousemove", function checkForMouseMove(event) {
window.removeEventListener("mousemove", checkForMouseMove, true);
window.addEventListener("mousemove", function(event) {
is(event.target.localName.indexOf("menu"), 0, "mouse over menu");
resolve();
}, true);
}, {capture: true, once: true});
EventUtils.synthesizeMouseAtCenter(selectPopup.firstChild, { type: "mousemove" });
});

Просмотреть файл

@ -8,13 +8,11 @@ function test() {
let tab = gBrowser.addTab(testPath + "file_bug970276_popup1.html");
tab.linkedBrowser.addEventListener("load", function() {
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
let expectedIcon = testPath + "file_bug970276_favicon1.ico";
is(gBrowser.getIcon(tab), expectedIcon, "Correct icon.");
gBrowser.removeTab(tab);
finish();
}, true);
}, {capture: true, once: true});
}

Просмотреть файл

@ -224,10 +224,9 @@ add_task(function*() {
let switchWaiter;
if (gMultiProcessBrowser) {
switchWaiter = new Promise((resolve, reject) => {
gBrowser.addEventListener("TabSwitchDone", function listener() {
gBrowser.removeEventListener("TabSwitchDone", listener);
gBrowser.addEventListener("TabSwitchDone", function() {
executeSoon(resolve);
});
}, {once: true});
});
}
@ -326,10 +325,9 @@ add_task(function*() {
gURLBar.focus();
yield new Promise((resolve, reject) => {
window.addEventListener("pageshow", function navigationOccured(event) {
window.removeEventListener("pageshow", navigationOccured, true);
window.addEventListener("pageshow", function(event) {
resolve();
}, true);
}, {capture: true, once: true});
document.getElementById("Browser:Back").doCommand();
});

Просмотреть файл

@ -7,10 +7,9 @@ const kTestPage = "http://example.org/browser/browser/base/content/test/general/
function promiseNewTabSwitched() {
return new Promise(resolve => {
gBrowser.addEventListener("TabSwitchDone", function onSwitch() {
gBrowser.removeEventListener("TabSwitchDone", onSwitch);
gBrowser.addEventListener("TabSwitchDone", function() {
executeSoon(resolve);
});
}, {once: true});
});
}

Просмотреть файл

@ -19,7 +19,6 @@ function test() {
is(gBrowser.visibleTabs.length, 3, "3 tabs should be open");
// Wait for tab load, the code checks for currentURI.
testTab2.linkedBrowser.addEventListener("load", function() {
testTab2.linkedBrowser.removeEventListener("load", arguments.callee, true);
is(Disabled(), false, "Bookmark All Tabs should be enabled since there are two tabs with different addresses");
// Hide the original tab
@ -52,7 +51,7 @@ function test() {
is(gBrowser.selectedTab, origTab, "got the orig tab");
is(origTab.hidden, false, "and it's not hidden -- visible!");
finish();
}, true);
}, {capture: true, once: true});
}
function Disabled() {

Просмотреть файл

@ -94,10 +94,9 @@ var messageHandlers = {
type: "mousemove",
clickcount: 0,
}
row.addEventListener("mousemove", function handler() {
row.removeEventListener("mousemove", handler);
row.addEventListener("mousemove", function() {
ack("mousemove");
});
}, {once: true});
content.synthesizeMouseAtCenter(row, event);
},

Просмотреть файл

@ -5,11 +5,9 @@
</head>
<body>
<script>
window.addEventListener("load", function onLoad() {
window.removeEventListener("load", onLoad, true);
window.addEventListener("load", function() {
document.getElementById("test").addEventListener("click", onClick, true);
}, true);
}, {capture: true, once: true});
function onClick(aEvent) {
aEvent.preventDefault();

Просмотреть файл

@ -86,19 +86,17 @@ function openToolbarCustomizationUI(aCallback, aBrowserWin) {
aBrowserWin.gCustomizeMode.enter();
aBrowserWin.gNavToolbox.addEventListener("customizationready", function UI_loaded() {
aBrowserWin.gNavToolbox.removeEventListener("customizationready", UI_loaded);
aBrowserWin.gNavToolbox.addEventListener("customizationready", function() {
executeSoon(function() {
aCallback(aBrowserWin)
});
});
}, {once: true});
}
function closeToolbarCustomizationUI(aCallback, aBrowserWin) {
aBrowserWin.gNavToolbox.addEventListener("aftercustomization", function unloaded() {
aBrowserWin.gNavToolbox.removeEventListener("aftercustomization", unloaded);
aBrowserWin.gNavToolbox.addEventListener("aftercustomization", function() {
executeSoon(aCallback);
});
}, {once: true});
aBrowserWin.gCustomizeMode.exit();
}
@ -235,10 +233,9 @@ function resetBlocklist() {
function whenNewWindowLoaded(aOptions, aCallback) {
let win = OpenBrowserWindow(aOptions);
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad);
win.addEventListener("load", function() {
aCallback(win);
});
}, {once: true});
}
function promiseWindowWillBeClosed(win) {
@ -271,10 +268,9 @@ function promiseOpenAndLoadWindow(aOptions, aWaitForDelayedStartup = false) {
}, "browser-delayed-startup-finished", false);
} else {
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad);
win.addEventListener("load", function() {
deferred.resolve(win);
});
}, {once: true});
}
return deferred.promise;
}
@ -574,12 +570,11 @@ var FullZoomHelper = {
let didPs = false;
let didZoom = false;
gBrowser.addEventListener("pageshow", function listener(event) {
gBrowser.removeEventListener("pageshow", listener, true);
gBrowser.addEventListener("pageshow", function(event) {
didPs = true;
if (didZoom)
resolve();
}, true);
}, {capture: true, once: true});
if (direction == this.BACK)
gBrowser.goBack();

Просмотреть файл

@ -428,10 +428,9 @@ function* simulateExternalDrop(aDestIndex) {
resolve();
}
iframe.addEventListener("load", function onLoad() {
iframe.removeEventListener("load", onLoad);
iframe.addEventListener("load", function() {
content.setTimeout(iframeLoaded, 0);
});
}, {once: true});
iframe.setAttribute("src", url);
iframe.style.width = "50px";

Просмотреть файл

@ -363,10 +363,9 @@ function waitForNotificationShown(notification, callback) {
executeSoon(callback);
return;
}
PopupNotifications.panel.addEventListener("popupshown", function onShown(e) {
PopupNotifications.panel.removeEventListener("popupshown", onShown);
PopupNotifications.panel.addEventListener("popupshown", function(e) {
callback();
});
}, {once: true});
notification.reshow();
}

Просмотреть файл

@ -286,8 +286,7 @@ function triggerSecondaryCommand(popup, index) {
// Extra secondary actions appear in a menu.
notification.secondaryButton.nextSibling.nextSibling.focus();
popup.addEventListener("popupshown", function handle() {
popup.removeEventListener("popupshown", handle);
popup.addEventListener("popupshown", function() {
info("Command popup open for notification " + notification.id);
// Press down until the desired command is selected. Decrease index by one
// since the secondary action was handled above.
@ -296,7 +295,7 @@ function triggerSecondaryCommand(popup, index) {
}
// Activate
EventUtils.synthesizeKey("VK_RETURN", {});
});
}, {once: true});
// One down event to open the popup
info("Open the popup to trigger secondary command for notification " + notification.id);

Просмотреть файл

@ -25,9 +25,7 @@ function startNewTabTestCase(aTestNumber) {
let menu = gTestWindow.document.getElementById("context-openlinkinusercontext-menu");
let menupopup = menu.menupopup;
menu.addEventListener("popupshown", function onPopupShown() {
menu.removeEventListener("popupshown", onPopupShown);
menu.addEventListener("popupshown", function() {
is(menupopup.nodeType, Node.ELEMENT_NODE, "We have a menupopup.");
ok(menupopup.firstChild, "We have a first container entry.");
@ -35,13 +33,12 @@ function startNewTabTestCase(aTestNumber) {
is(firstContext.nodeType, Node.ELEMENT_NODE, "We have a first container entry.");
ok(firstContext.hasAttribute("data-usercontextid"), "We have a usercontextid value.");
aContextMenu.addEventListener("popuphidden", function onPopupHidden() {
aContextMenu.removeEventListener("popuphidden", onPopupHidden);
aContextMenu.addEventListener("popuphidden", function() {
firstContext.doCommand();
});
}, {once: true});
aContextMenu.hidePopup();
});
}, {once: true});
menupopup.showPopup();
});

Просмотреть файл

@ -28,9 +28,7 @@ function startNewTabTestCase(aTestNumber) {
let menu = gTestWindow.document.getElementById("context-openlinkinusercontext-menu");
let menupopup = menu.menupopup;
menu.addEventListener("popupshown", function onPopupShown() {
menu.removeEventListener("popupshown", onPopupShown);
menu.addEventListener("popupshown", function() {
is(menupopup.nodeType, Node.ELEMENT_NODE, "We have a menupopup.");
ok(menupopup.firstChild, "We have a first container entry.");
@ -39,13 +37,12 @@ function startNewTabTestCase(aTestNumber) {
ok(firstContext.hasAttribute("data-usercontextid"), "We have a usercontextid value.");
is("0", firstContext.getAttribute("data-usercontextid"), "We have the right usercontextid value.");
aContextMenu.addEventListener("popuphidden", function onPopupHidden() {
aContextMenu.removeEventListener("popuphidden", onPopupHidden);
aContextMenu.addEventListener("popuphidden", function() {
firstContext.doCommand();
});
}, {once: true});
aContextMenu.hidePopup();
});
}, {once: true});
menupopup.showPopup();
});

Просмотреть файл

@ -157,15 +157,12 @@ var tests = {
let domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
domwindow.addEventListener("load", function _load() {
domwindow.removeEventListener("load", _load);
domwindow.addEventListener("unload", function _unload() {
domwindow.removeEventListener("unload", _unload);
domwindow.addEventListener("load", function() {
domwindow.addEventListener("unload", function() {
info("blocklist window was closed");
Services.wm.removeListener(listener);
next();
});
}, {once: true});
is(domwindow.document.location.href, URI_EXTENSION_BLOCKLIST_DIALOG, "dialog opened and focused");
// wait until after load to cancel so the dialog has initalized. we
@ -175,7 +172,7 @@ var tests = {
info("***** hit the cancel button\n");
cancelButton.doCommand();
});
});
}, {once: true});
},
onCloseWindow(aXULWindow) { },
onWindowTitleChange(aXULWindow, aNewTitle) { }

Просмотреть файл

@ -370,15 +370,14 @@ var tests = {
EventUtils.sendKey("i");
EventUtils.sendKey("l");
SocialShare.panel.addEventListener("popuphidden", function hidden(evt) {
SocialShare.panel.removeEventListener("popuphidden", hidden);
SocialShare.panel.addEventListener("popuphidden", function(evt) {
let topwin = Services.wm.getMostRecentWindow(null);
is(topwin, window, "no dialog is open");
BrowserTestUtils.removeTab(testTab).then(() => {
SocialService.disableProvider(manifest.origin, next);
});
});
}, {once: true});
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
});

Просмотреть файл

@ -242,8 +242,7 @@ var tests = {
let addonsTab = gBrowser.addTab();
gBrowser.selectedTab = addonsTab;
BrowserOpenAddonsMgr("addons://list/service");
gBrowser.selectedBrowser.addEventListener("load", function tabLoad() {
gBrowser.selectedBrowser.removeEventListener("load", tabLoad, true);
gBrowser.selectedBrowser.addEventListener("load", function() {
is(addonsTab.linkedBrowser.currentURI.spec, "about:addons", "about:addons should load into blank tab.");
activateOneProvider(gProviders[0], true, function() {
@ -277,6 +276,6 @@ var tests = {
});
});
});
}, true);
}, {capture: true, once: true});
}
}

Просмотреть файл

@ -81,19 +81,17 @@ function openToolbarCustomizationUI(aCallback, aBrowserWin) {
aBrowserWin.gCustomizeMode.enter();
aBrowserWin.gNavToolbox.addEventListener("customizationready", function UI_loaded() {
aBrowserWin.gNavToolbox.removeEventListener("customizationready", UI_loaded);
aBrowserWin.gNavToolbox.addEventListener("customizationready", function() {
executeSoon(function() {
aCallback(aBrowserWin)
});
});
}, {once: true});
}
function closeToolbarCustomizationUI(aCallback, aBrowserWin) {
aBrowserWin.gNavToolbox.addEventListener("aftercustomization", function unloaded() {
aBrowserWin.gNavToolbox.removeEventListener("aftercustomization", unloaded);
aBrowserWin.gNavToolbox.addEventListener("aftercustomization", function() {
executeSoon(aCallback);
});
}, {once: true});
aBrowserWin.gCustomizeMode.exit();
}

Просмотреть файл

@ -16,11 +16,10 @@ add_task(function* test_switchtab_decodeuri() {
info("switch-to-tab");
yield new Promise((resolve, reject) => {
// In case of success it should switch tab.
gBrowser.tabContainer.addEventListener("TabSelect", function select() {
gBrowser.tabContainer.removeEventListener("TabSelect", select);
gBrowser.tabContainer.addEventListener("TabSelect", function() {
is(gBrowser.selectedTab, tab, "Should have switched to the right tab");
resolve();
});
}, {once: true});
EventUtils.synthesizeKey("VK_RETURN", { });
});

Просмотреть файл

@ -45,9 +45,8 @@ add_task(function* () {
return new Promise((resolve, reject) => {
gBrowser.selectedBrowser.focus();
gURLBar.addEventListener("input", function() {
gURLBar.removeEventListener("input", arguments.callee);
resolve();
});
}, {once: true});
gURLBar.focus();
EventUtils.synthesizeKey("VK_BACK_SPACE", {});
});

Просмотреть файл

@ -196,10 +196,9 @@ function* promiseOpenNewTab(url = "about:blank") {
function promiseNewTabSwitched() {
return new Promise(resolve => {
gBrowser.addEventListener("TabSwitchDone", function onSwitch() {
gBrowser.removeEventListener("TabSwitchDone", onSwitch);
gBrowser.addEventListener("TabSwitchDone", function() {
executeSoon(resolve);
});
}, {once: true});
});
}

Просмотреть файл

@ -22,10 +22,9 @@ function urlClick(url) {
function promiseNewTabSwitched() {
return new Promise(resolve => {
gBrowser.addEventListener("TabSwitchDone", function onSwitch() {
gBrowser.removeEventListener("TabSwitchDone", onSwitch);
gBrowser.addEventListener("TabSwitchDone", function() {
executeSoon(resolve);
});
}, {once: true});
});
}

Просмотреть файл

@ -11,10 +11,9 @@ add_task(function* clearURLBarAfterParentProcessURL() {
let tab = yield new Promise(resolve => {
gBrowser.selectedTab = gBrowser.addTab("about:preferences");
let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
newTabBrowser.addEventListener("Initialized", function onInit() {
newTabBrowser.removeEventListener("Initialized", onInit, true);
newTabBrowser.addEventListener("Initialized", function() {
resolve(gBrowser.selectedTab);
}, true);
}, {capture: true, once: true});
});
document.getElementById("home-button").click();
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
@ -31,10 +30,9 @@ add_task(function* clearURLBarAfterParentProcessURLInExistingTab() {
let tab = yield new Promise(resolve => {
gBrowser.selectedTab = gBrowser.addTab();
let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
newTabBrowser.addEventListener("Initialized", function onInit() {
newTabBrowser.removeEventListener("Initialized", onInit, true);
newTabBrowser.addEventListener("Initialized", function() {
resolve(gBrowser.selectedTab);
}, true);
}, {capture: true, once: true});
newTabBrowser.loadURI("about:preferences");
});
document.getElementById("home-button").click();

Просмотреть файл

@ -244,11 +244,10 @@ function assertVisible(visible, win = window) {
function promiseTransition(win = window) {
return new Promise(resolve => {
win.gURLBar.popup.addEventListener("transitionend", function onEnd() {
win.gURLBar.popup.removeEventListener("transitionend", onEnd, true);
win.gURLBar.popup.addEventListener("transitionend", function() {
// The urlbar needs to handle the transitionend first, but that happens
// naturally since promises are resolved at the end of the current tick.
resolve();
}, true);
}, {capture: true, once: true});
});
}

Просмотреть файл

@ -588,9 +588,7 @@ function test() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
@ -611,7 +609,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -85,9 +85,7 @@ function test() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
@ -103,7 +101,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -225,9 +225,7 @@ function test() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
@ -246,7 +244,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -586,9 +586,7 @@ function test() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
@ -609,7 +607,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -78,9 +78,7 @@ function runTest() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
@ -101,7 +99,7 @@ function runTest() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -260,9 +260,7 @@ function test() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
@ -283,7 +281,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -219,9 +219,7 @@ function test() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
@ -240,7 +238,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -71,9 +71,7 @@ function runTest() {
browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
@ -94,7 +92,7 @@ function runTest() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content/",
"https://example.com/");

Просмотреть файл

@ -333,9 +333,7 @@ function test() {
gBrowser.selectedTab = tab;
let browser = tab.linkedBrowser;
browser.addEventListener("load", function onload() {
browser.removeEventListener("load", onload, true);
browser.addEventListener("load", function() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
@ -356,7 +354,7 @@ function test() {
ok(false, "Unexpected Exception: " + ex);
finish();
});
}, true);
}, {capture: true, once: true});
let rootDir = getRootDirectory(gTestPath);
rootDir = rootDir.replace("chrome://mochitests/content", ORIGIN);
content.location = rootDir + "get_user_media.html";

Просмотреть файл

@ -49,9 +49,7 @@ function promiseWindow(url) {
return new Promise(resolve => {
Services.obs.addObserver(function obs(win) {
win.QueryInterface(Ci.nsIDOMWindow);
win.addEventListener("load", function loadHandler() {
win.removeEventListener("load", loadHandler);
win.addEventListener("load", function() {
if (win.location.href !== url) {
info("ignoring a window with this url: " + win.location.href);
return;
@ -59,7 +57,7 @@ function promiseWindow(url) {
Services.obs.removeObserver(obs, "domwindowopened");
resolve(win);
});
}, {once: true});
}, "domwindowopened", false);
});
}
@ -275,15 +273,13 @@ function promiseMessage(aMessage, aAction) {
function promisePopupNotificationShown(aName, aAction) {
let deferred = Promise.defer();
PopupNotifications.panel.addEventListener("popupshown", function popupNotifShown() {
PopupNotifications.panel.removeEventListener("popupshown", popupNotifShown);
PopupNotifications.panel.addEventListener("popupshown", function() {
ok(!!PopupNotifications.getNotification(aName), aName + " notification shown");
ok(PopupNotifications.isPanelOpen, "notification panel open");
ok(!!PopupNotifications.panel.firstChild, "notification panel populated");
deferred.resolve();
});
}, {once: true});
if (aAction)
aAction();

Просмотреть файл

@ -26,10 +26,9 @@ add_task(function* () {
info("Synthesize a mouse click and wait for a new tab...");
let newTab = yield new Promise((resolve, reject) => {
gBrowser.tabContainer.addEventListener("TabOpen", function onTabOpen(openEvent) {
gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen);
gBrowser.tabContainer.addEventListener("TabOpen", function(openEvent) {
resolve(openEvent.target);
})
}, {once: true})
BrowserTestUtils.synthesizeMouseAtCenter("#clickMe", { button: 1 }, browser);
});

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше