mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1362882 - script-generated patch to switch from Promise.defer() to new Promise() where it's straightforward, rs=Mossop.
This commit is contained in:
parent
67e56b7404
commit
97f401c644
@ -66,26 +66,26 @@ var gTests = [
|
||||
HTTPS_BASE + "healthreport_testRemoteCommands.html");
|
||||
},
|
||||
run(iframe) {
|
||||
let deferred = Promise.defer();
|
||||
let results = 0;
|
||||
try {
|
||||
iframe.contentWindow.addEventListener("FirefoxHealthReportTestResponse", function evtHandler(event) {
|
||||
let data = event.detail.data;
|
||||
if (data.type == "testResult") {
|
||||
ok(data.pass, data.info);
|
||||
results++;
|
||||
} else if (data.type == "testsComplete") {
|
||||
is(results, data.count, "Checking number of results received matches the number of tests that should have run");
|
||||
iframe.contentWindow.removeEventListener("FirefoxHealthReportTestResponse", evtHandler, true);
|
||||
deferred.resolve();
|
||||
}
|
||||
}, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
let results = 0;
|
||||
try {
|
||||
iframe.contentWindow.addEventListener("FirefoxHealthReportTestResponse", function evtHandler(event) {
|
||||
let data = event.detail.data;
|
||||
if (data.type == "testResult") {
|
||||
ok(data.pass, data.info);
|
||||
results++;
|
||||
} else if (data.type == "testsComplete") {
|
||||
is(results, data.count, "Checking number of results received matches the number of tests that should have run");
|
||||
iframe.contentWindow.removeEventListener("FirefoxHealthReportTestResponse", evtHandler, true);
|
||||
resolve();
|
||||
}
|
||||
}, true);
|
||||
|
||||
} catch (e) {
|
||||
ok(false, "Failed to get all commands");
|
||||
deferred.reject();
|
||||
}
|
||||
return deferred.promise;
|
||||
} catch (e) {
|
||||
ok(false, "Failed to get all commands");
|
||||
reject();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@ -114,18 +114,18 @@ function test() {
|
||||
}
|
||||
|
||||
function promiseNewTabLoadEvent(aUrl, aEventType = "load") {
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
tab.linkedBrowser.addEventListener(aEventType, function(event) {
|
||||
let iframe = tab.linkedBrowser.contentDocument.getElementById("remote-report");
|
||||
iframe.addEventListener("load", function frameLoad(e) {
|
||||
if (iframe.contentWindow.location.href == "about:blank" ||
|
||||
e.target != iframe) {
|
||||
return;
|
||||
}
|
||||
iframe.removeEventListener("load", frameLoad);
|
||||
deferred.resolve(iframe);
|
||||
});
|
||||
}, {capture: true, once: true});
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
tab.linkedBrowser.addEventListener(aEventType, function(event) {
|
||||
let iframe = tab.linkedBrowser.contentDocument.getElementById("remote-report");
|
||||
iframe.addEventListener("load", function frameLoad(e) {
|
||||
if (iframe.contentWindow.location.href == "about:blank" ||
|
||||
e.target != iframe) {
|
||||
return;
|
||||
}
|
||||
iframe.removeEventListener("load", frameLoad);
|
||||
resolve(iframe);
|
||||
});
|
||||
}, {capture: true, once: true});
|
||||
});
|
||||
}
|
||||
|
@ -28,19 +28,19 @@ function test() {
|
||||
var zoomLevel = ZoomManager.zoom;
|
||||
|
||||
// Start the sub-document load.
|
||||
let deferred = Promise.defer();
|
||||
executeSoon(function() {
|
||||
BrowserTestUtils.browserLoaded(testBrowser, true).then(url => {
|
||||
is(url, TEST_IFRAME_URL, "got the load event for the iframe");
|
||||
is(ZoomManager.zoom, zoomLevel, "zoom is retained after sub-document load");
|
||||
await new Promise(resolve => {
|
||||
executeSoon(function() {
|
||||
BrowserTestUtils.browserLoaded(testBrowser, true).then(url => {
|
||||
is(url, TEST_IFRAME_URL, "got the load event for the iframe");
|
||||
is(ZoomManager.zoom, zoomLevel, "zoom is retained after sub-document load");
|
||||
|
||||
FullZoomHelper.removeTabAndWaitForLocationChange().
|
||||
then(() => deferred.resolve());
|
||||
});
|
||||
ContentTask.spawn(testBrowser, TEST_IFRAME_URL, url => {
|
||||
content.document.querySelector("iframe").src = url;
|
||||
FullZoomHelper.removeTabAndWaitForLocationChange().
|
||||
then(() => resolve());
|
||||
});
|
||||
ContentTask.spawn(testBrowser, TEST_IFRAME_URL, url => {
|
||||
content.document.querySelector("iframe").src = url;
|
||||
});
|
||||
});
|
||||
});
|
||||
await deferred.promise;
|
||||
})().then(finish, FullZoomHelper.failAndContinue(finish));
|
||||
}
|
||||
|
@ -74,9 +74,9 @@ function testNavigation() {
|
||||
}
|
||||
|
||||
function waitForNextTurn() {
|
||||
let deferred = Promise.defer();
|
||||
setTimeout(() => deferred.resolve(), 0);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
var finishTestStarted = false;
|
||||
|
@ -386,16 +386,16 @@ add_task(async function cycleEngines() {
|
||||
await msg("key", { key: "VK_DOWN", waitForSuggestions: true });
|
||||
|
||||
let promiseEngineChange = function(newEngineName) {
|
||||
let deferred = Promise.defer();
|
||||
Services.obs.addObserver(function resolver(subj, topic, data) {
|
||||
if (data != "engine-current") {
|
||||
return;
|
||||
}
|
||||
SimpleTest.is(subj.name, newEngineName, "Engine cycled correctly");
|
||||
Services.obs.removeObserver(resolver, "browser-search-engine-modified");
|
||||
deferred.resolve();
|
||||
}, "browser-search-engine-modified");
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
Services.obs.addObserver(function resolver(subj, topic, data) {
|
||||
if (data != "engine-current") {
|
||||
return;
|
||||
}
|
||||
SimpleTest.is(subj.name, newEngineName, "Engine cycled correctly");
|
||||
Services.obs.removeObserver(resolver, "browser-search-engine-modified");
|
||||
resolve();
|
||||
}, "browser-search-engine-modified");
|
||||
});
|
||||
}
|
||||
|
||||
let p = promiseEngineChange(TEST_ENGINE_PREFIX + " " + TEST_ENGINE_2_BASENAME);
|
||||
@ -665,15 +665,15 @@ function msg(type, data = null) {
|
||||
type,
|
||||
data,
|
||||
});
|
||||
let deferred = Promise.defer();
|
||||
gMsgMan.addMessageListener(TEST_MSG, function onMsg(msgObj) {
|
||||
if (msgObj.data.type != type) {
|
||||
return;
|
||||
}
|
||||
gMsgMan.removeMessageListener(TEST_MSG, onMsg);
|
||||
deferred.resolve(msgObj.data.data);
|
||||
return new Promise(resolve => {
|
||||
gMsgMan.addMessageListener(TEST_MSG, function onMsg(msgObj) {
|
||||
if (msgObj.data.type != type) {
|
||||
return;
|
||||
}
|
||||
gMsgMan.removeMessageListener(TEST_MSG, onMsg);
|
||||
resolve(msgObj.data.data);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function checkState(actualState, expectedInputVal, expectedSuggestions,
|
||||
@ -737,16 +737,16 @@ async function promiseTab() {
|
||||
}
|
||||
|
||||
function promiseMsg(name, type, msgMan) {
|
||||
let deferred = Promise.defer();
|
||||
info("Waiting for " + name + " message " + type + "...");
|
||||
msgMan.addMessageListener(name, function onMsg(msgObj) {
|
||||
info("Received " + name + " message " + msgObj.data.type + "\n");
|
||||
if (msgObj.data.type == type) {
|
||||
msgMan.removeMessageListener(name, onMsg);
|
||||
deferred.resolve(msgObj);
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
info("Waiting for " + name + " message " + type + "...");
|
||||
msgMan.addMessageListener(name, function onMsg(msgObj) {
|
||||
info("Received " + name + " message " + msgObj.data.type + "\n");
|
||||
if (msgObj.data.type == type) {
|
||||
msgMan.removeMessageListener(name, onMsg);
|
||||
resolve(msgObj);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function setUpEngines() {
|
||||
|
@ -20,31 +20,31 @@ add_task(async function test_remoteWebNavigation_postdata() {
|
||||
let server = new obj.HttpServer();
|
||||
server.start(-1);
|
||||
|
||||
let loadDeferred = Promise.defer();
|
||||
await new Promise(resolve => {
|
||||
|
||||
server.registerPathHandler("/test", (request, response) => {
|
||||
let body = obj.CommonUtils.readBytesFromInputStream(request.bodyInputStream);
|
||||
is(body, "success", "request body is correct");
|
||||
is(request.method, "POST", "request was a post");
|
||||
response.write("Received from POST: " + body);
|
||||
resolve();
|
||||
});
|
||||
|
||||
let i = server.identity;
|
||||
let path = i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/test";
|
||||
|
||||
let postdata =
|
||||
"Content-Length: 7\r\n" +
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
||||
"\r\n" +
|
||||
"success";
|
||||
|
||||
openUILinkIn(path, "tab", null, makeInputStream(postdata));
|
||||
|
||||
server.registerPathHandler("/test", (request, response) => {
|
||||
let body = obj.CommonUtils.readBytesFromInputStream(request.bodyInputStream);
|
||||
is(body, "success", "request body is correct");
|
||||
is(request.method, "POST", "request was a post");
|
||||
response.write("Received from POST: " + body);
|
||||
loadDeferred.resolve();
|
||||
});
|
||||
|
||||
let i = server.identity;
|
||||
let path = i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/test";
|
||||
|
||||
let postdata =
|
||||
"Content-Length: 7\r\n" +
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
||||
"\r\n" +
|
||||
"success";
|
||||
|
||||
openUILinkIn(path, "tab", null, makeInputStream(postdata));
|
||||
|
||||
await loadDeferred.promise;
|
||||
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
|
||||
let serverStoppedDeferred = Promise.defer();
|
||||
server.stop(function() { serverStoppedDeferred.resolve(); });
|
||||
await serverStoppedDeferred.promise;
|
||||
await new Promise(resolve => {
|
||||
server.stop(function() { resolve(); });
|
||||
});
|
||||
});
|
||||
|
@ -19,27 +19,27 @@ var FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.j
|
||||
var Downloads = (Components.utils.import("resource://gre/modules/Downloads.jsm", {})).Downloads;
|
||||
|
||||
function promiseFormHistoryRemoved() {
|
||||
let deferred = Promise.defer();
|
||||
Services.obs.addObserver(function onfh() {
|
||||
Services.obs.removeObserver(onfh, "satchel-storage-changed");
|
||||
deferred.resolve();
|
||||
}, "satchel-storage-changed");
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
Services.obs.addObserver(function onfh() {
|
||||
Services.obs.removeObserver(onfh, "satchel-storage-changed");
|
||||
resolve();
|
||||
}, "satchel-storage-changed");
|
||||
});
|
||||
}
|
||||
|
||||
function promiseDownloadRemoved(list) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let view = {
|
||||
onDownloadRemoved(download) {
|
||||
list.removeView(view);
|
||||
deferred.resolve();
|
||||
}
|
||||
};
|
||||
let view = {
|
||||
onDownloadRemoved(download) {
|
||||
list.removeView(view);
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
list.addView(view);
|
||||
list.addView(view);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test() {
|
||||
@ -50,27 +50,27 @@ add_task(async function test() {
|
||||
});
|
||||
|
||||
function countEntries(name, message, check) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
var obj = {};
|
||||
if (name !== null)
|
||||
obj.fieldname = name;
|
||||
var obj = {};
|
||||
if (name !== null)
|
||||
obj.fieldname = name;
|
||||
|
||||
let count;
|
||||
FormHistory.count(obj, { handleResult: result => count = result,
|
||||
handleError(error) {
|
||||
deferred.reject(error)
|
||||
throw new Error("Error occurred searching form history: " + error);
|
||||
},
|
||||
handleCompletion(reason) {
|
||||
if (!reason) {
|
||||
check(count, message);
|
||||
deferred.resolve();
|
||||
}
|
||||
},
|
||||
});
|
||||
let count;
|
||||
FormHistory.count(obj, { handleResult: result => count = result,
|
||||
handleError(error) {
|
||||
reject(error)
|
||||
throw new Error("Error occurred searching form history: " + error);
|
||||
},
|
||||
handleCompletion(reason) {
|
||||
if (!reason) {
|
||||
check(count, message);
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
async function onHistoryReady() {
|
||||
@ -445,72 +445,72 @@ async function onHistoryReady() {
|
||||
}
|
||||
|
||||
function setupHistory() {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let places = [];
|
||||
let places = [];
|
||||
|
||||
function addPlace(aURI, aTitle, aVisitDate) {
|
||||
places.push({
|
||||
uri: aURI,
|
||||
title: aTitle,
|
||||
visits: [{
|
||||
visitDate: aVisitDate,
|
||||
transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
|
||||
}]
|
||||
function addPlace(aURI, aTitle, aVisitDate) {
|
||||
places.push({
|
||||
uri: aURI,
|
||||
title: aTitle,
|
||||
visits: [{
|
||||
visitDate: aVisitDate,
|
||||
transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
addPlace(makeURI("http://10minutes.com/"), "10 minutes ago", now_uSec - 10 * kUsecPerMin);
|
||||
addPlace(makeURI("http://1hour.com/"), "Less than 1 hour ago", now_uSec - 45 * kUsecPerMin);
|
||||
addPlace(makeURI("http://1hour10minutes.com/"), "1 hour 10 minutes ago", now_uSec - 70 * kUsecPerMin);
|
||||
addPlace(makeURI("http://2hour.com/"), "Less than 2 hours ago", now_uSec - 90 * kUsecPerMin);
|
||||
addPlace(makeURI("http://2hour10minutes.com/"), "2 hours 10 minutes ago", now_uSec - 130 * kUsecPerMin);
|
||||
addPlace(makeURI("http://4hour.com/"), "Less than 4 hours ago", now_uSec - 180 * kUsecPerMin);
|
||||
addPlace(makeURI("http://4hour10minutes.com/"), "4 hours 10 minutesago", now_uSec - 250 * kUsecPerMin);
|
||||
|
||||
let today = new Date();
|
||||
today.setHours(0);
|
||||
today.setMinutes(0);
|
||||
today.setSeconds(1);
|
||||
addPlace(makeURI("http://today.com/"), "Today", today.getTime() * 1000);
|
||||
|
||||
let lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
addPlace(makeURI("http://before-today.com/"), "Before Today", lastYear.getTime() * 1000);
|
||||
PlacesUtils.asyncHistory.updatePlaces(places, {
|
||||
handleError: () => ok(false, "Unexpected error in adding visit."),
|
||||
handleResult: () => { },
|
||||
handleCompletion: () => resolve()
|
||||
});
|
||||
}
|
||||
|
||||
addPlace(makeURI("http://10minutes.com/"), "10 minutes ago", now_uSec - 10 * kUsecPerMin);
|
||||
addPlace(makeURI("http://1hour.com/"), "Less than 1 hour ago", now_uSec - 45 * kUsecPerMin);
|
||||
addPlace(makeURI("http://1hour10minutes.com/"), "1 hour 10 minutes ago", now_uSec - 70 * kUsecPerMin);
|
||||
addPlace(makeURI("http://2hour.com/"), "Less than 2 hours ago", now_uSec - 90 * kUsecPerMin);
|
||||
addPlace(makeURI("http://2hour10minutes.com/"), "2 hours 10 minutes ago", now_uSec - 130 * kUsecPerMin);
|
||||
addPlace(makeURI("http://4hour.com/"), "Less than 4 hours ago", now_uSec - 180 * kUsecPerMin);
|
||||
addPlace(makeURI("http://4hour10minutes.com/"), "4 hours 10 minutesago", now_uSec - 250 * kUsecPerMin);
|
||||
|
||||
let today = new Date();
|
||||
today.setHours(0);
|
||||
today.setMinutes(0);
|
||||
today.setSeconds(1);
|
||||
addPlace(makeURI("http://today.com/"), "Today", today.getTime() * 1000);
|
||||
|
||||
let lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
addPlace(makeURI("http://before-today.com/"), "Before Today", lastYear.getTime() * 1000);
|
||||
PlacesUtils.asyncHistory.updatePlaces(places, {
|
||||
handleError: () => ok(false, "Unexpected error in adding visit."),
|
||||
handleResult: () => { },
|
||||
handleCompletion: () => deferred.resolve()
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
async function setupFormHistory() {
|
||||
|
||||
function searchEntries(terms, params) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let results = [];
|
||||
FormHistory.search(terms, params, { handleResult: result => results.push(result),
|
||||
handleError(error) {
|
||||
deferred.reject(error);
|
||||
throw new Error("Error occurred searching form history: " + error);
|
||||
},
|
||||
handleCompletion(reason) { deferred.resolve(results); }
|
||||
});
|
||||
return deferred.promise;
|
||||
let results = [];
|
||||
FormHistory.search(terms, params, { handleResult: result => results.push(result),
|
||||
handleError(error) {
|
||||
reject(error);
|
||||
throw new Error("Error occurred searching form history: " + error);
|
||||
},
|
||||
handleCompletion(reason) { resolve(results); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function update(changes) {
|
||||
let deferred = Promise.defer();
|
||||
FormHistory.update(changes, { handleError(error) {
|
||||
deferred.reject(error);
|
||||
throw new Error("Error occurred searching form history: " + error);
|
||||
},
|
||||
handleCompletion(reason) { deferred.resolve(); }
|
||||
});
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
FormHistory.update(changes, { handleError(error) {
|
||||
reject(error);
|
||||
throw new Error("Error occurred searching form history: " + error);
|
||||
},
|
||||
handleCompletion(reason) { resolve(); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Make sure we've got a clean DB to start with, then add the entries we'll be testing.
|
||||
|
@ -37,19 +37,19 @@ add_task(async function test_star_redirect() {
|
||||
* Waits for the star to reflect the expected state.
|
||||
*/
|
||||
function promiseStarState(aValue) {
|
||||
let deferred = Promise.defer();
|
||||
let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED
|
||||
: BookmarkingUI.STATUS_UNSTARRED;
|
||||
(function checkState() {
|
||||
if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING ||
|
||||
BookmarkingUI.status != expectedStatus) {
|
||||
info("Waiting for star button change.");
|
||||
setTimeout(checkState, 1000);
|
||||
} else {
|
||||
deferred.resolve();
|
||||
}
|
||||
})();
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let expectedStatus = aValue ? BookmarkingUI.STATUS_STARRED
|
||||
: BookmarkingUI.STATUS_UNSTARRED;
|
||||
(function checkState() {
|
||||
if (BookmarkingUI.status == BookmarkingUI.STATUS_UPDATING ||
|
||||
BookmarkingUI.status != expectedStatus) {
|
||||
info("Waiting for star button change.");
|
||||
setTimeout(checkState, 1000);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,19 +66,19 @@ function promiseStarState(aValue) {
|
||||
function promiseTabLoadEvent(aTab, aURL, aFinalURL) {
|
||||
if (!aFinalURL)
|
||||
aFinalURL = aURL;
|
||||
let deferred = Promise.defer();
|
||||
info("Wait for load tab event");
|
||||
aTab.linkedBrowser.addEventListener("load", function load(event) {
|
||||
if (event.originalTarget != aTab.linkedBrowser.contentDocument ||
|
||||
event.target.location.href == "about:blank" ||
|
||||
event.target.location.href != aFinalURL) {
|
||||
info("skipping spurious load event");
|
||||
return;
|
||||
}
|
||||
aTab.linkedBrowser.removeEventListener("load", load, true);
|
||||
info("Tab load event received");
|
||||
deferred.resolve();
|
||||
}, true, true);
|
||||
aTab.linkedBrowser.loadURI(aURL);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
info("Wait for load tab event");
|
||||
aTab.linkedBrowser.addEventListener("load", function load(event) {
|
||||
if (event.originalTarget != aTab.linkedBrowser.contentDocument ||
|
||||
event.target.location.href == "about:blank" ||
|
||||
event.target.location.href != aFinalURL) {
|
||||
info("skipping spurious load event");
|
||||
return;
|
||||
}
|
||||
aTab.linkedBrowser.removeEventListener("load", load, true);
|
||||
info("Tab load event received");
|
||||
resolve();
|
||||
}, true, true);
|
||||
aTab.linkedBrowser.loadURI(aURL);
|
||||
});
|
||||
}
|
||||
|
@ -59,19 +59,19 @@ add_task(async function() {
|
||||
|
||||
// resolves promise when directory links are downloaded and written to disk
|
||||
function watchLinksChangeOnce() {
|
||||
let deferred = Promise.defer();
|
||||
let observer = {
|
||||
onManyLinksChanged: () => {
|
||||
DirectoryLinksProvider.removeObserver(observer);
|
||||
NewTabUtils.links.populateCache(() => {
|
||||
NewTabUtils.allPages.update();
|
||||
deferred.resolve();
|
||||
}, true);
|
||||
}
|
||||
};
|
||||
observer.onDownloadFail = observer.onManyLinksChanged;
|
||||
DirectoryLinksProvider.addObserver(observer);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let observer = {
|
||||
onManyLinksChanged: () => {
|
||||
DirectoryLinksProvider.removeObserver(observer);
|
||||
NewTabUtils.links.populateCache(() => {
|
||||
NewTabUtils.allPages.update();
|
||||
resolve();
|
||||
}, true);
|
||||
}
|
||||
};
|
||||
observer.onDownloadFail = observer.onManyLinksChanged;
|
||||
DirectoryLinksProvider.addObserver(observer);
|
||||
});
|
||||
}
|
||||
|
||||
let gOrigDirectorySource = Services.prefs.getCharPref(PREF_NEWTAB_DIRECTORYSOURCE);
|
||||
|
@ -37,17 +37,17 @@ function closeAllNotifications() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
for (let notification of notificationBox.allNotifications) {
|
||||
waitForNotificationClose(notification, function() {
|
||||
if (notificationBox.allNotifications.length === 0) {
|
||||
deferred.resolve();
|
||||
}
|
||||
});
|
||||
notification.close();
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
for (let notification of notificationBox.allNotifications) {
|
||||
waitForNotificationClose(notification, function() {
|
||||
if (notificationBox.allNotifications.length === 0) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
notification.close();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function whenDelayedStartupFinished(aWindow, aCallback) {
|
||||
@ -123,9 +123,9 @@ function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
|
||||
}
|
||||
|
||||
function promiseWaitForCondition(aConditionFn) {
|
||||
let deferred = Promise.defer();
|
||||
waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass.");
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
waitForCondition(aConditionFn, resolve, "Condition didn't pass.");
|
||||
});
|
||||
}
|
||||
|
||||
function promiseWaitForEvent(object, eventName, capturing = false, chrome = false) {
|
||||
@ -185,9 +185,9 @@ function setTestPluginEnabledState(newEnabledState, pluginName) {
|
||||
}
|
||||
|
||||
function pushPrefs(...aPrefs) {
|
||||
let deferred = Promise.defer();
|
||||
SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
SpecialPowers.pushPrefEnv({"set": aPrefs}, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function updateBlocklist(aCallback) {
|
||||
@ -238,23 +238,23 @@ function promiseWindowClosed(win) {
|
||||
}
|
||||
|
||||
function promiseOpenAndLoadWindow(aOptions, aWaitForDelayedStartup = false) {
|
||||
let deferred = Promise.defer();
|
||||
let win = OpenBrowserWindow(aOptions);
|
||||
if (aWaitForDelayedStartup) {
|
||||
Services.obs.addObserver(function onDS(aSubject, aTopic, aData) {
|
||||
if (aSubject != win) {
|
||||
return;
|
||||
}
|
||||
Services.obs.removeObserver(onDS, "browser-delayed-startup-finished");
|
||||
deferred.resolve(win);
|
||||
}, "browser-delayed-startup-finished");
|
||||
return new Promise(resolve => {
|
||||
let win = OpenBrowserWindow(aOptions);
|
||||
if (aWaitForDelayedStartup) {
|
||||
Services.obs.addObserver(function onDS(aSubject, aTopic, aData) {
|
||||
if (aSubject != win) {
|
||||
return;
|
||||
}
|
||||
Services.obs.removeObserver(onDS, "browser-delayed-startup-finished");
|
||||
resolve(win);
|
||||
}, "browser-delayed-startup-finished");
|
||||
|
||||
} else {
|
||||
win.addEventListener("load", function() {
|
||||
deferred.resolve(win);
|
||||
}, {once: true});
|
||||
}
|
||||
return deferred.promise;
|
||||
} else {
|
||||
win.addEventListener("load", function() {
|
||||
resolve(win);
|
||||
}, {once: true});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,12 +304,12 @@ function waitForAsyncUpdates(aCallback, aScope, aArguments) {
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseIsURIVisited(aURI, aExpectedValue) {
|
||||
let deferred = Promise.defer();
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
deferred.resolve(aIsVisited);
|
||||
});
|
||||
return new Promise(resolve => {
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
resolve(aIsVisited);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function whenNewTabLoaded(aWindow, aCallback) {
|
||||
@ -329,9 +329,9 @@ function whenTabLoaded(aTab, aCallback) {
|
||||
}
|
||||
|
||||
function promiseTabLoaded(aTab) {
|
||||
let deferred = Promise.defer();
|
||||
whenTabLoaded(aTab, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
whenTabLoaded(aTab, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,22 +343,22 @@ function promiseTabLoaded(aTab) {
|
||||
* True if each visit to the URI should be cleared, false otherwise
|
||||
*/
|
||||
function promiseHistoryClearedState(aURIs, aShouldBeCleared) {
|
||||
let deferred = Promise.defer();
|
||||
let callbackCount = 0;
|
||||
let niceStr = aShouldBeCleared ? "no longer" : "still";
|
||||
function callbackDone() {
|
||||
if (++callbackCount == aURIs.length)
|
||||
deferred.resolve();
|
||||
}
|
||||
aURIs.forEach(function(aURI) {
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(uri, isVisited) {
|
||||
is(isVisited, !aShouldBeCleared,
|
||||
"history visit " + uri.spec + " should " + niceStr + " exist");
|
||||
callbackDone();
|
||||
return new Promise(resolve => {
|
||||
let callbackCount = 0;
|
||||
let niceStr = aShouldBeCleared ? "no longer" : "still";
|
||||
function callbackDone() {
|
||||
if (++callbackCount == aURIs.length)
|
||||
resolve();
|
||||
}
|
||||
aURIs.forEach(function(aURI) {
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(uri, isVisited) {
|
||||
is(isVisited, !aShouldBeCleared,
|
||||
"history visit " + uri.spec + " should " + niceStr + " exist");
|
||||
callbackDone();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -676,12 +676,12 @@ function promisePopupEvent(popup, eventSuffix) {
|
||||
return Promise.resolve();
|
||||
|
||||
let eventType = "popup" + eventSuffix;
|
||||
let deferred = Promise.defer();
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
deferred.resolve();
|
||||
}, {once: true});
|
||||
return new Promise(resolve => {
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
|
@ -16,13 +16,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
||||
* @rejects Never.
|
||||
*/
|
||||
function promiseTopicObserved(topic) {
|
||||
let deferred = Promise.defer();
|
||||
info("Waiting for observer topic " + topic);
|
||||
Services.obs.addObserver(function PTO_observe(obsSubject, obsTopic, obsData) {
|
||||
Services.obs.removeObserver(PTO_observe, obsTopic);
|
||||
deferred.resolve([obsSubject, obsData]);
|
||||
}, topic);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
info("Waiting for observer topic " + topic);
|
||||
Services.obs.addObserver(function PTO_observe(obsSubject, obsTopic, obsData) {
|
||||
Services.obs.removeObserver(PTO_observe, obsTopic);
|
||||
resolve([obsSubject, obsData]);
|
||||
}, topic);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -409,12 +409,12 @@ function test() {
|
||||
|
||||
function promiseOneMessage(tab, messageName) {
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
let deferred = Promise.defer();
|
||||
mm.addMessageListener(messageName, function onmessage(message) {
|
||||
mm.removeMessageListener(messageName, onmessage);
|
||||
deferred.resolve(message);
|
||||
return new Promise(resolve => {
|
||||
mm.addMessageListener(messageName, function onmessage(message) {
|
||||
mm.removeMessageListener(messageName, onmessage);
|
||||
resolve(message);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseNewTabLoadEvent(aUrl) {
|
||||
@ -432,34 +432,34 @@ function promiseNewTabLoadEvent(aUrl) {
|
||||
// Returns a promise which is resolved with the iframe's URL after a new
|
||||
// tab is created and the iframe in that tab loads.
|
||||
function promiseNewTabWithIframeLoadEvent(aUrl) {
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
let browser = tab.linkedBrowser;
|
||||
let mm = browser.messageManager;
|
||||
return new Promise(resolve => {
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl);
|
||||
let browser = tab.linkedBrowser;
|
||||
let mm = browser.messageManager;
|
||||
|
||||
// give it an e10s-friendly content script to help with our tests,
|
||||
// and wait for it to tell us about the iframe load.
|
||||
mm.addMessageListener("test:iframe:load", function onFrameLoad(message) {
|
||||
mm.removeMessageListener("test:iframe:load", onFrameLoad);
|
||||
deferred.resolve([tab, message.data.url]);
|
||||
// give it an e10s-friendly content script to help with our tests,
|
||||
// and wait for it to tell us about the iframe load.
|
||||
mm.addMessageListener("test:iframe:load", function onFrameLoad(message) {
|
||||
mm.removeMessageListener("test:iframe:load", onFrameLoad);
|
||||
resolve([tab, message.data.url]);
|
||||
});
|
||||
mm.loadFrameScript(CHROME_BASE + "content_aboutAccounts.js", true);
|
||||
});
|
||||
mm.loadFrameScript(CHROME_BASE + "content_aboutAccounts.js", true);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function checkVisibilities(tab, data) {
|
||||
let ids = Object.keys(data);
|
||||
let mm = tab.linkedBrowser.messageManager;
|
||||
let deferred = Promise.defer();
|
||||
mm.addMessageListener("test:check-visibilities-response", function onResponse(message) {
|
||||
mm.removeMessageListener("test:check-visibilities-response", onResponse);
|
||||
for (let id of ids) {
|
||||
is(message.data[id], data[id], "Element '" + id + "' has correct visibility");
|
||||
}
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
mm.addMessageListener("test:check-visibilities-response", function onResponse(message) {
|
||||
mm.removeMessageListener("test:check-visibilities-response", onResponse);
|
||||
for (let id of ids) {
|
||||
is(message.data[id], data[id], "Element '" + id + "' has correct visibility");
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
mm.sendAsyncMessage("test:check-visibilities", {ids});
|
||||
});
|
||||
mm.sendAsyncMessage("test:check-visibilities", {ids});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// watch out - these will fire observers which if you aren't careful, may
|
||||
|
@ -9,31 +9,31 @@ registerCleanupFunction(function() {
|
||||
});
|
||||
|
||||
function promiseNotification(aBrowser, value, expected, input) {
|
||||
let deferred = Promise.defer();
|
||||
let notificationBox = aBrowser.getNotificationBox(aBrowser.selectedBrowser);
|
||||
if (expected) {
|
||||
info("Waiting for " + value + " notification");
|
||||
let checkForNotification = function() {
|
||||
if (notificationBox.getNotificationWithValue(value)) {
|
||||
info("Saw the notification");
|
||||
notificationObserver.disconnect();
|
||||
notificationObserver = null;
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
let notificationBox = aBrowser.getNotificationBox(aBrowser.selectedBrowser);
|
||||
if (expected) {
|
||||
info("Waiting for " + value + " notification");
|
||||
let checkForNotification = function() {
|
||||
if (notificationBox.getNotificationWithValue(value)) {
|
||||
info("Saw the notification");
|
||||
notificationObserver.disconnect();
|
||||
notificationObserver = null;
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
if (notificationObserver) {
|
||||
notificationObserver.disconnect();
|
||||
}
|
||||
notificationObserver = new MutationObserver(checkForNotification);
|
||||
notificationObserver.observe(notificationBox, {childList: true});
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
is(notificationBox.getNotificationWithValue(value), null,
|
||||
`We are expecting to not get a notification for ${input}`);
|
||||
resolve();
|
||||
}, 1000);
|
||||
}
|
||||
if (notificationObserver) {
|
||||
notificationObserver.disconnect();
|
||||
}
|
||||
notificationObserver = new MutationObserver(checkForNotification);
|
||||
notificationObserver.observe(notificationBox, {childList: true});
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
is(notificationBox.getNotificationWithValue(value), null,
|
||||
`We are expecting to not get a notification for ${input}`);
|
||||
deferred.resolve();
|
||||
}, 1000);
|
||||
}
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
async function runURLBarSearchTest({valueToOpen, expectSearch, expectNotification, aWindow = window}) {
|
||||
@ -131,9 +131,9 @@ function get_test_function_for_localhost_with_hostname(hostName, isPrivate) {
|
||||
let promiseWin = BrowserTestUtils.waitForNewWindow();
|
||||
win = OpenBrowserWindow({private: true});
|
||||
await promiseWin;
|
||||
let deferredOpenFocus = Promise.defer();
|
||||
waitForFocus(deferredOpenFocus.resolve, win);
|
||||
await deferredOpenFocus.promise;
|
||||
await new Promise(resolve => {
|
||||
waitForFocus(resolve, win);
|
||||
});
|
||||
} else {
|
||||
win = window;
|
||||
}
|
||||
@ -174,10 +174,10 @@ function get_test_function_for_localhost_with_hostname(hostName, isPrivate) {
|
||||
if (isPrivate) {
|
||||
info("Waiting for private window to close");
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
let deferredFocus = Promise.defer();
|
||||
info("Waiting for focus");
|
||||
waitForFocus(deferredFocus.resolve, window);
|
||||
await deferredFocus.promise;
|
||||
await new Promise(resolve => {
|
||||
info("Waiting for focus");
|
||||
waitForFocus(resolve, window);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,12 +138,12 @@ function promisePopupEvent(popup, eventSuffix) {
|
||||
return Promise.resolve();
|
||||
|
||||
let eventType = "popup" + eventSuffix;
|
||||
let deferred = Promise.defer();
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
deferred.resolve();
|
||||
}, {once: true});
|
||||
return new Promise(resolve => {
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
|
@ -31,9 +31,9 @@ function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
|
||||
}
|
||||
|
||||
function promiseWaitForCondition(aConditionFn, retryTimes) {
|
||||
let deferred = Promise.defer();
|
||||
waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass.", retryTimes);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
waitForCondition(aConditionFn, resolve, "Condition didn't pass.", retryTimes);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,15 +137,15 @@ async function assertWebRTCIndicatorStatus(expected) {
|
||||
|
||||
if (document.readyState != "complete") {
|
||||
info("Waiting for the sharing indicator's document to load");
|
||||
let deferred = Promise.defer();
|
||||
document.addEventListener("readystatechange",
|
||||
function onReadyStateChange() {
|
||||
if (document.readyState != "complete")
|
||||
return;
|
||||
document.removeEventListener("readystatechange", onReadyStateChange);
|
||||
deferred.resolve();
|
||||
await new Promise(resolve => {
|
||||
document.addEventListener("readystatechange",
|
||||
function onReadyStateChange() {
|
||||
if (document.readyState != "complete")
|
||||
return;
|
||||
document.removeEventListener("readystatechange", onReadyStateChange);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await deferred.promise;
|
||||
}
|
||||
|
||||
for (let item of ["video", "audio", "screen"]) {
|
||||
@ -166,12 +166,12 @@ function promisePopupEvent(popup, eventSuffix) {
|
||||
return Promise.resolve();
|
||||
|
||||
let eventType = "popup" + eventSuffix;
|
||||
let deferred = Promise.defer();
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
deferred.resolve();
|
||||
}, {once: true});
|
||||
return new Promise(resolve => {
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function promiseNotificationShown(notification) {
|
||||
@ -274,47 +274,47 @@ function promiseMessage(aMessage, aAction) {
|
||||
}
|
||||
|
||||
function promisePopupNotificationShown(aName, aAction) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
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");
|
||||
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});
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
if (aAction)
|
||||
aAction();
|
||||
if (aAction)
|
||||
aAction();
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function promisePopupNotification(aName) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
waitForCondition(() => PopupNotifications.getNotification(aName),
|
||||
() => {
|
||||
ok(!!PopupNotifications.getNotification(aName),
|
||||
aName + " notification appeared");
|
||||
waitForCondition(() => PopupNotifications.getNotification(aName),
|
||||
() => {
|
||||
ok(!!PopupNotifications.getNotification(aName),
|
||||
aName + " notification appeared");
|
||||
|
||||
deferred.resolve();
|
||||
}, "timeout waiting for popup notification " + aName);
|
||||
resolve();
|
||||
}, "timeout waiting for popup notification " + aName);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function promiseNoPopupNotification(aName) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
waitForCondition(() => !PopupNotifications.getNotification(aName),
|
||||
() => {
|
||||
ok(!PopupNotifications.getNotification(aName),
|
||||
aName + " notification removed");
|
||||
deferred.resolve();
|
||||
}, "timeout waiting for popup notification " + aName + " to disappear");
|
||||
waitForCondition(() => !PopupNotifications.getNotification(aName),
|
||||
() => {
|
||||
ok(!PopupNotifications.getNotification(aName),
|
||||
aName + " notification removed");
|
||||
resolve();
|
||||
}, "timeout waiting for popup notification " + aName + " to disappear");
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
const kActionAlways = 1;
|
||||
|
@ -28,20 +28,20 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
function promiseFullscreenChange() {
|
||||
let deferred = Promise.defer();
|
||||
info("Wait for fullscreen change");
|
||||
return new Promise((resolve, reject) => {
|
||||
info("Wait for fullscreen change");
|
||||
|
||||
let timeoutId = setTimeout(() => {
|
||||
window.removeEventListener("fullscreen", onFullscreenChange, true);
|
||||
deferred.reject("Fullscreen change did not happen within " + 20000 + "ms");
|
||||
}, 20000);
|
||||
let timeoutId = setTimeout(() => {
|
||||
window.removeEventListener("fullscreen", onFullscreenChange, true);
|
||||
reject("Fullscreen change did not happen within " + 20000 + "ms");
|
||||
}, 20000);
|
||||
|
||||
function onFullscreenChange(event) {
|
||||
clearTimeout(timeoutId);
|
||||
window.removeEventListener("fullscreen", onFullscreenChange, true);
|
||||
info("Fullscreen event received");
|
||||
deferred.resolve();
|
||||
}
|
||||
window.addEventListener("fullscreen", onFullscreenChange, true);
|
||||
return deferred.promise;
|
||||
function onFullscreenChange(event) {
|
||||
clearTimeout(timeoutId);
|
||||
window.removeEventListener("fullscreen", onFullscreenChange, true);
|
||||
info("Fullscreen event received");
|
||||
resolve();
|
||||
}
|
||||
window.addEventListener("fullscreen", onFullscreenChange, true);
|
||||
});
|
||||
}
|
||||
|
@ -33,19 +33,19 @@ add_task(function asyncCleanup() {
|
||||
});
|
||||
|
||||
function waitForPageLoad(aTab) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let timeoutId = setTimeout(() => {
|
||||
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
|
||||
deferred.reject("Page didn't load within " + 20000 + "ms");
|
||||
}, 20000);
|
||||
let timeoutId = setTimeout(() => {
|
||||
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
|
||||
reject("Page didn't load within " + 20000 + "ms");
|
||||
}, 20000);
|
||||
|
||||
function onTabLoad(event) {
|
||||
clearTimeout(timeoutId);
|
||||
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
|
||||
info("Tab event received: load");
|
||||
deferred.resolve();
|
||||
}
|
||||
aTab.linkedBrowser.addEventListener("load", onTabLoad, true, true);
|
||||
return deferred.promise;
|
||||
function onTabLoad(event) {
|
||||
clearTimeout(timeoutId);
|
||||
aTab.linkedBrowser.removeEventListener("load", onTabLoad, true);
|
||||
info("Tab event received: load");
|
||||
resolve();
|
||||
}
|
||||
aTab.linkedBrowser.addEventListener("load", onTabLoad, true, true);
|
||||
});
|
||||
}
|
||||
|
@ -59,32 +59,32 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
function promiseObserverNotification(aObserver) {
|
||||
let deferred = Promise.defer();
|
||||
function notificationCallback(e) {
|
||||
Services.obs.removeObserver(notificationCallback, aObserver);
|
||||
clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
}
|
||||
let timeoutId = setTimeout(() => {
|
||||
Services.obs.removeObserver(notificationCallback, aObserver);
|
||||
deferred.reject("Notification '" + aObserver + "' did not happen within 20 seconds.");
|
||||
}, kTimeoutInMS);
|
||||
Services.obs.addObserver(notificationCallback, aObserver);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
function notificationCallback(e) {
|
||||
Services.obs.removeObserver(notificationCallback, aObserver);
|
||||
clearTimeout(timeoutId);
|
||||
resolve();
|
||||
}
|
||||
let timeoutId = setTimeout(() => {
|
||||
Services.obs.removeObserver(notificationCallback, aObserver);
|
||||
reject("Notification '" + aObserver + "' did not happen within 20 seconds.");
|
||||
}, kTimeoutInMS);
|
||||
Services.obs.addObserver(notificationCallback, aObserver);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseTabSelect() {
|
||||
let deferred = Promise.defer();
|
||||
let container = window.gBrowser.tabContainer;
|
||||
let timeoutId = setTimeout(() => {
|
||||
container.removeEventListener("TabSelect", callback);
|
||||
deferred.reject("TabSelect did not happen within 20 seconds");
|
||||
}, kTimeoutInMS);
|
||||
function callback(e) {
|
||||
container.removeEventListener("TabSelect", callback);
|
||||
clearTimeout(timeoutId);
|
||||
executeSoon(deferred.resolve);
|
||||
}
|
||||
container.addEventListener("TabSelect", callback);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let container = window.gBrowser.tabContainer;
|
||||
let timeoutId = setTimeout(() => {
|
||||
container.removeEventListener("TabSelect", callback);
|
||||
reject("TabSelect did not happen within 20 seconds");
|
||||
}, kTimeoutInMS);
|
||||
function callback(e) {
|
||||
container.removeEventListener("TabSelect", callback);
|
||||
clearTimeout(timeoutId);
|
||||
executeSoon(resolve);
|
||||
}
|
||||
container.addEventListener("TabSelect", callback);
|
||||
});
|
||||
}
|
||||
|
@ -17,16 +17,16 @@ const kSmallWidth = 400;
|
||||
* resolves as soon as the menu is ready for interaction.
|
||||
*/
|
||||
function bookmarksMenuPanelShown() {
|
||||
let deferred = Promise.defer();
|
||||
let bookmarksMenuPopup = document.getElementById("BMB_bookmarksPopup");
|
||||
let onTransitionEnd = (e) => {
|
||||
if (e.target == bookmarksMenuPopup) {
|
||||
bookmarksMenuPopup.removeEventListener("transitionend", onTransitionEnd);
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
let bookmarksMenuPopup = document.getElementById("BMB_bookmarksPopup");
|
||||
let onTransitionEnd = (e) => {
|
||||
if (e.target == bookmarksMenuPopup) {
|
||||
bookmarksMenuPopup.removeEventListener("transitionend", onTransitionEnd);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
bookmarksMenuPopup.addEventListener("transitionend", onTransitionEnd);
|
||||
return deferred.promise;
|
||||
bookmarksMenuPopup.addEventListener("transitionend", onTransitionEnd);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,28 +97,28 @@ add_task(async function() {
|
||||
// reusing it prevents a potential race between unload handlers where the
|
||||
// one from promiseWindowClosed could fire before the onWindowClosed
|
||||
// (and therefore onAreaNodeRegistered) one, causing the test to fail.
|
||||
let windowCloseDeferred = Promise.defer();
|
||||
listener = {
|
||||
onAreaNodeUnregistered(aArea, aNode, aReason) {
|
||||
if (aArea == TOOLBARID) {
|
||||
is(aNode, otherTB, "Should be informed about other toolbar");
|
||||
is(aReason, CustomizableUI.REASON_WINDOW_CLOSED, "Reason should be correct.");
|
||||
wasInformedCorrectlyOfAreaDisappearing = (aReason === CustomizableUI.REASON_WINDOW_CLOSED);
|
||||
}
|
||||
},
|
||||
onWindowClosed(aWindow) {
|
||||
if (aWindow == otherWin) {
|
||||
windowCloseDeferred.resolve(aWindow);
|
||||
} else {
|
||||
info("Other window was closed!");
|
||||
info("Other window title: " + (aWindow.document && aWindow.document.title));
|
||||
info("Our window title: " + (otherWin.document && otherWin.document.title));
|
||||
}
|
||||
},
|
||||
};
|
||||
CustomizableUI.addListener(listener);
|
||||
otherWin.close();
|
||||
let windowClosed = await windowCloseDeferred.promise;
|
||||
let windowClosed = await new Promise(resolve => {
|
||||
listener = {
|
||||
onAreaNodeUnregistered(aArea, aNode, aReason) {
|
||||
if (aArea == TOOLBARID) {
|
||||
is(aNode, otherTB, "Should be informed about other toolbar");
|
||||
is(aReason, CustomizableUI.REASON_WINDOW_CLOSED, "Reason should be correct.");
|
||||
wasInformedCorrectlyOfAreaDisappearing = (aReason === CustomizableUI.REASON_WINDOW_CLOSED);
|
||||
}
|
||||
},
|
||||
onWindowClosed(aWindow) {
|
||||
if (aWindow == otherWin) {
|
||||
resolve(aWindow);
|
||||
} else {
|
||||
info("Other window was closed!");
|
||||
info("Other window title: " + (aWindow.document && aWindow.document.title));
|
||||
info("Our window title: " + (otherWin.document && otherWin.document.title));
|
||||
}
|
||||
},
|
||||
};
|
||||
CustomizableUI.addListener(listener);
|
||||
otherWin.close();
|
||||
});
|
||||
|
||||
is(windowClosed, otherWin, "Window should have sent onWindowClosed notification.");
|
||||
ok(wasInformedCorrectlyOfAreaDisappearing, "Should be told about window closing.");
|
||||
|
@ -88,19 +88,19 @@ async function openPrefsFromMenuPanel(expectedPanelId, entryPoint) {
|
||||
let setupButton = subpanel.querySelector(".PanelUI-remotetabs-prefs-button");
|
||||
setupButton.click();
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let handler = (e) => {
|
||||
if (e.originalTarget != gBrowser.selectedBrowser.contentDocument ||
|
||||
e.target.location.href == "about:blank") {
|
||||
info("Skipping spurious 'load' event for " + e.target.location.href);
|
||||
return;
|
||||
await new Promise(resolve => {
|
||||
let handler = (e) => {
|
||||
if (e.originalTarget != gBrowser.selectedBrowser.contentDocument ||
|
||||
e.target.location.href == "about:blank") {
|
||||
info("Skipping spurious 'load' event for " + e.target.location.href);
|
||||
return;
|
||||
}
|
||||
gBrowser.selectedBrowser.removeEventListener("load", handler, true);
|
||||
resolve();
|
||||
}
|
||||
gBrowser.selectedBrowser.removeEventListener("load", handler, true);
|
||||
deferred.resolve();
|
||||
}
|
||||
gBrowser.selectedBrowser.addEventListener("load", handler, true);
|
||||
gBrowser.selectedBrowser.addEventListener("load", handler, true);
|
||||
|
||||
await deferred.promise;
|
||||
});
|
||||
newTab = gBrowser.selectedTab;
|
||||
|
||||
is(gBrowser.currentURI.spec, "about:preferences?entrypoint=" + entryPoint + "#sync",
|
||||
|
@ -203,16 +203,16 @@ function endCustomizing(aWindow = window) {
|
||||
return true;
|
||||
}
|
||||
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", true);
|
||||
let deferredEndCustomizing = Promise.defer();
|
||||
function onCustomizationEnds() {
|
||||
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", false);
|
||||
aWindow.gNavToolbox.removeEventListener("aftercustomization", onCustomizationEnds);
|
||||
deferredEndCustomizing.resolve();
|
||||
}
|
||||
aWindow.gNavToolbox.addEventListener("aftercustomization", onCustomizationEnds);
|
||||
aWindow.gCustomizeMode.exit();
|
||||
return new Promise(resolve => {
|
||||
function onCustomizationEnds() {
|
||||
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", false);
|
||||
aWindow.gNavToolbox.removeEventListener("aftercustomization", onCustomizationEnds);
|
||||
resolve();
|
||||
}
|
||||
aWindow.gNavToolbox.addEventListener("aftercustomization", onCustomizationEnds);
|
||||
aWindow.gCustomizeMode.exit();
|
||||
|
||||
return deferredEndCustomizing.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function startCustomizing(aWindow = window) {
|
||||
@ -220,53 +220,53 @@ function startCustomizing(aWindow = window) {
|
||||
return null;
|
||||
}
|
||||
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", true);
|
||||
let deferred = Promise.defer();
|
||||
function onCustomizing() {
|
||||
aWindow.gNavToolbox.removeEventListener("customizationready", onCustomizing);
|
||||
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", false);
|
||||
deferred.resolve();
|
||||
}
|
||||
aWindow.gNavToolbox.addEventListener("customizationready", onCustomizing);
|
||||
aWindow.gCustomizeMode.enter();
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
function onCustomizing() {
|
||||
aWindow.gNavToolbox.removeEventListener("customizationready", onCustomizing);
|
||||
Services.prefs.setBoolPref("browser.uiCustomization.disableAnimation", false);
|
||||
resolve();
|
||||
}
|
||||
aWindow.gNavToolbox.addEventListener("customizationready", onCustomizing);
|
||||
aWindow.gCustomizeMode.enter();
|
||||
});
|
||||
}
|
||||
|
||||
function promiseObserverNotified(aTopic) {
|
||||
let deferred = Promise.defer();
|
||||
Services.obs.addObserver(function onNotification(subject, topic, data) {
|
||||
Services.obs.removeObserver(onNotification, topic);
|
||||
deferred.resolve({subject, data});
|
||||
}, aTopic);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
Services.obs.addObserver(function onNotification(subject, topic, data) {
|
||||
Services.obs.removeObserver(onNotification, topic);
|
||||
resolve({subject, data});
|
||||
}, aTopic);
|
||||
});
|
||||
}
|
||||
|
||||
function openAndLoadWindow(aOptions, aWaitForDelayedStartup = false) {
|
||||
let deferred = Promise.defer();
|
||||
let win = OpenBrowserWindow(aOptions);
|
||||
if (aWaitForDelayedStartup) {
|
||||
Services.obs.addObserver(function onDS(aSubject, aTopic, aData) {
|
||||
if (aSubject != win) {
|
||||
return;
|
||||
}
|
||||
Services.obs.removeObserver(onDS, "browser-delayed-startup-finished");
|
||||
deferred.resolve(win);
|
||||
}, "browser-delayed-startup-finished");
|
||||
return new Promise(resolve => {
|
||||
let win = OpenBrowserWindow(aOptions);
|
||||
if (aWaitForDelayedStartup) {
|
||||
Services.obs.addObserver(function onDS(aSubject, aTopic, aData) {
|
||||
if (aSubject != win) {
|
||||
return;
|
||||
}
|
||||
Services.obs.removeObserver(onDS, "browser-delayed-startup-finished");
|
||||
resolve(win);
|
||||
}, "browser-delayed-startup-finished");
|
||||
|
||||
} else {
|
||||
win.addEventListener("load", function() {
|
||||
deferred.resolve(win);
|
||||
}, {once: true});
|
||||
}
|
||||
return deferred.promise;
|
||||
} else {
|
||||
win.addEventListener("load", function() {
|
||||
resolve(win);
|
||||
}, {once: true});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function promiseWindowClosed(win) {
|
||||
let deferred = Promise.defer();
|
||||
win.addEventListener("unload", function() {
|
||||
deferred.resolve();
|
||||
}, {once: true});
|
||||
win.close();
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
win.addEventListener("unload", function() {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
win.close();
|
||||
});
|
||||
}
|
||||
|
||||
function promisePanelShown(win) {
|
||||
@ -280,17 +280,17 @@ function promiseOverflowShown(win) {
|
||||
}
|
||||
|
||||
function promisePanelElementShown(win, aPanel) {
|
||||
let deferred = Promise.defer();
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
deferred.reject("Panel did not show within 20 seconds.");
|
||||
}, 20000);
|
||||
function onPanelOpen(e) {
|
||||
aPanel.removeEventListener("popupshown", onPanelOpen);
|
||||
win.clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
}
|
||||
aPanel.addEventListener("popupshown", onPanelOpen);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
reject("Panel did not show within 20 seconds.");
|
||||
}, 20000);
|
||||
function onPanelOpen(e) {
|
||||
aPanel.removeEventListener("popupshown", onPanelOpen);
|
||||
win.clearTimeout(timeoutId);
|
||||
resolve();
|
||||
}
|
||||
aPanel.addEventListener("popupshown", onPanelOpen);
|
||||
});
|
||||
}
|
||||
|
||||
function promisePanelHidden(win) {
|
||||
@ -304,17 +304,17 @@ function promiseOverflowHidden(win) {
|
||||
}
|
||||
|
||||
function promisePanelElementHidden(win, aPanel) {
|
||||
let deferred = Promise.defer();
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
deferred.reject("Panel did not hide within 20 seconds.");
|
||||
}, 20000);
|
||||
function onPanelClose(e) {
|
||||
aPanel.removeEventListener("popuphidden", onPanelClose);
|
||||
win.clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
}
|
||||
aPanel.addEventListener("popuphidden", onPanelClose);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
reject("Panel did not hide within 20 seconds.");
|
||||
}, 20000);
|
||||
function onPanelClose(e) {
|
||||
aPanel.removeEventListener("popuphidden", onPanelClose);
|
||||
win.clearTimeout(timeoutId);
|
||||
resolve();
|
||||
}
|
||||
aPanel.addEventListener("popuphidden", onPanelClose);
|
||||
});
|
||||
}
|
||||
|
||||
function isPanelUIOpen() {
|
||||
@ -322,33 +322,33 @@ function isPanelUIOpen() {
|
||||
}
|
||||
|
||||
function subviewShown(aSubview) {
|
||||
let deferred = Promise.defer();
|
||||
let win = aSubview.ownerGlobal;
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
deferred.reject("Subview (" + aSubview.id + ") did not show within 20 seconds.");
|
||||
}, 20000);
|
||||
function onViewShowing(e) {
|
||||
aSubview.removeEventListener("ViewShowing", onViewShowing);
|
||||
win.clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
}
|
||||
aSubview.addEventListener("ViewShowing", onViewShowing);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let win = aSubview.ownerGlobal;
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
reject("Subview (" + aSubview.id + ") did not show within 20 seconds.");
|
||||
}, 20000);
|
||||
function onViewShowing(e) {
|
||||
aSubview.removeEventListener("ViewShowing", onViewShowing);
|
||||
win.clearTimeout(timeoutId);
|
||||
resolve();
|
||||
}
|
||||
aSubview.addEventListener("ViewShowing", onViewShowing);
|
||||
});
|
||||
}
|
||||
|
||||
function subviewHidden(aSubview) {
|
||||
let deferred = Promise.defer();
|
||||
let win = aSubview.ownerGlobal;
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
deferred.reject("Subview (" + aSubview.id + ") did not hide within 20 seconds.");
|
||||
}, 20000);
|
||||
function onViewHiding(e) {
|
||||
aSubview.removeEventListener("ViewHiding", onViewHiding);
|
||||
win.clearTimeout(timeoutId);
|
||||
deferred.resolve();
|
||||
}
|
||||
aSubview.addEventListener("ViewHiding", onViewHiding);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let win = aSubview.ownerGlobal;
|
||||
let timeoutId = win.setTimeout(() => {
|
||||
reject("Subview (" + aSubview.id + ") did not hide within 20 seconds.");
|
||||
}, 20000);
|
||||
function onViewHiding(e) {
|
||||
aSubview.removeEventListener("ViewHiding", onViewHiding);
|
||||
win.clearTimeout(timeoutId);
|
||||
resolve();
|
||||
}
|
||||
aSubview.addEventListener("ViewHiding", onViewHiding);
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCondition(aConditionFn, aMaxTries = 50, aCheckInterval = 100) {
|
||||
@ -372,9 +372,9 @@ function waitForCondition(aConditionFn, aMaxTries = 50, aCheckInterval = 100) {
|
||||
}
|
||||
|
||||
function waitFor(aTimeout = 100) {
|
||||
let deferred = Promise.defer();
|
||||
setTimeout(() => deferred.resolve(), aTimeout);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(), aTimeout);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -401,29 +401,29 @@ function promiseTabLoadEvent(aTab, aURL) {
|
||||
* @return {Promise} resolved when navigation has finished.
|
||||
*/
|
||||
function promiseTabHistoryNavigation(aDirection = -1, aConditionFn) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let timeoutId = setTimeout(() => {
|
||||
gBrowser.removeEventListener("pageshow", listener, true);
|
||||
deferred.reject("Pageshow did not happen within " + kTabEventFailureTimeoutInMs + "ms");
|
||||
}, kTabEventFailureTimeoutInMs);
|
||||
let timeoutId = setTimeout(() => {
|
||||
gBrowser.removeEventListener("pageshow", listener, true);
|
||||
reject("Pageshow did not happen within " + kTabEventFailureTimeoutInMs + "ms");
|
||||
}, kTabEventFailureTimeoutInMs);
|
||||
|
||||
function listener(event) {
|
||||
gBrowser.removeEventListener("pageshow", listener, true);
|
||||
clearTimeout(timeoutId);
|
||||
function listener(event) {
|
||||
gBrowser.removeEventListener("pageshow", listener, true);
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (aConditionFn) {
|
||||
waitForCondition(aConditionFn).then(() => deferred.resolve(),
|
||||
aReason => deferred.reject(aReason));
|
||||
} else {
|
||||
deferred.resolve();
|
||||
if (aConditionFn) {
|
||||
waitForCondition(aConditionFn).then(() => resolve(),
|
||||
aReason => reject(aReason));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
gBrowser.addEventListener("pageshow", listener, true);
|
||||
gBrowser.addEventListener("pageshow", listener, true);
|
||||
|
||||
content.history.go(aDirection);
|
||||
content.history.go(aDirection);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -479,16 +479,16 @@ function popupHidden(aPopup) {
|
||||
* yield popupHiddenPromise;
|
||||
*/
|
||||
function promisePopupEvent(aPopup, aEventSuffix) {
|
||||
let deferred = Promise.defer();
|
||||
let eventType = "popup" + aEventSuffix;
|
||||
return new Promise(resolve => {
|
||||
let eventType = "popup" + aEventSuffix;
|
||||
|
||||
function onPopupEvent(e) {
|
||||
aPopup.removeEventListener(eventType, onPopupEvent);
|
||||
deferred.resolve();
|
||||
}
|
||||
function onPopupEvent(e) {
|
||||
aPopup.removeEventListener(eventType, onPopupEvent);
|
||||
resolve();
|
||||
}
|
||||
|
||||
aPopup.addEventListener(eventType, onPopupEvent);
|
||||
return deferred.promise;
|
||||
aPopup.addEventListener(eventType, onPopupEvent);
|
||||
});
|
||||
}
|
||||
|
||||
// This is a simpler version of the context menu check that
|
||||
|
@ -98,18 +98,18 @@ function unlockWidth(aItemIDs) {
|
||||
* @param aIsOverflowed if we're waiting for the item to be overflowed.
|
||||
*/
|
||||
function waitForOverflowed(aItem, aIsOverflowed) {
|
||||
let deferOverflow = Promise.defer();
|
||||
if (aItem.overflowed == aIsOverflowed) {
|
||||
return deferOverflow.resolve();
|
||||
}
|
||||
|
||||
let observer = new MutationObserver(function(aMutations) {
|
||||
return new Promise(resolve => {
|
||||
if (aItem.overflowed == aIsOverflowed) {
|
||||
observer.disconnect();
|
||||
deferOverflow.resolve();
|
||||
return resolve();
|
||||
}
|
||||
});
|
||||
observer.observe(aItem.node, {attributes: true});
|
||||
|
||||
return deferOverflow.promise;
|
||||
let observer = new MutationObserver(function(aMutations) {
|
||||
if (aItem.overflowed == aIsOverflowed) {
|
||||
observer.disconnect();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
observer.observe(aItem.node, {attributes: true});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -64,32 +64,32 @@ function promiseOpenAndLoadWindow(aOptions) {
|
||||
* @rejects if a valid load event is not received within a meaningful interval
|
||||
*/
|
||||
function promiseTabLoadEvent(tab, url, eventType = "load") {
|
||||
let deferred = Promise.defer();
|
||||
info("Wait tab event: " + eventType);
|
||||
return new Promise(resolve => {
|
||||
info("Wait tab event: " + eventType);
|
||||
|
||||
function handle(event) {
|
||||
if (event.originalTarget != tab.linkedBrowser.contentDocument ||
|
||||
event.target.location.href == "about:blank" ||
|
||||
(url && event.target.location.href != url)) {
|
||||
info("Skipping spurious '" + eventType + "'' event" +
|
||||
" for " + event.target.location.href);
|
||||
return;
|
||||
function handle(event) {
|
||||
if (event.originalTarget != tab.linkedBrowser.contentDocument ||
|
||||
event.target.location.href == "about:blank" ||
|
||||
(url && event.target.location.href != url)) {
|
||||
info("Skipping spurious '" + eventType + "'' event" +
|
||||
" for " + event.target.location.href);
|
||||
return;
|
||||
}
|
||||
// Remove reference to tab from the cleanup function:
|
||||
realCleanup = () => {};
|
||||
tab.linkedBrowser.removeEventListener(eventType, handle, true);
|
||||
info("Tab event received: " + eventType);
|
||||
resolve(event);
|
||||
}
|
||||
// Remove reference to tab from the cleanup function:
|
||||
realCleanup = () => {};
|
||||
tab.linkedBrowser.removeEventListener(eventType, handle, true);
|
||||
info("Tab event received: " + eventType);
|
||||
deferred.resolve(event);
|
||||
}
|
||||
|
||||
// Juggle a bit to avoid leaks:
|
||||
let realCleanup = () => tab.linkedBrowser.removeEventListener(eventType, handle, true);
|
||||
registerCleanupFunction(() => realCleanup());
|
||||
// Juggle a bit to avoid leaks:
|
||||
let realCleanup = () => tab.linkedBrowser.removeEventListener(eventType, handle, true);
|
||||
registerCleanupFunction(() => realCleanup());
|
||||
|
||||
tab.linkedBrowser.addEventListener(eventType, handle, true, true);
|
||||
if (url)
|
||||
tab.linkedBrowser.loadURI(url);
|
||||
return deferred.promise;
|
||||
tab.linkedBrowser.addEventListener(eventType, handle, true, true);
|
||||
if (url)
|
||||
tab.linkedBrowser.loadURI(url);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseWindowClosed(win) {
|
||||
@ -107,30 +107,30 @@ function promiseWindowClosed(win) {
|
||||
|
||||
|
||||
function promiseFocus() {
|
||||
let deferred = Promise.defer();
|
||||
waitForFocus(deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
waitForFocus(resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function promisePanelOpened() {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
if (DownloadsPanel.panel && DownloadsPanel.panel.state == "open") {
|
||||
return deferred.resolve();
|
||||
}
|
||||
if (DownloadsPanel.panel && DownloadsPanel.panel.state == "open") {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
// Hook to wait until the panel is shown.
|
||||
let originalOnPopupShown = DownloadsPanel.onPopupShown;
|
||||
DownloadsPanel.onPopupShown = function() {
|
||||
DownloadsPanel.onPopupShown = originalOnPopupShown;
|
||||
originalOnPopupShown.apply(this, arguments);
|
||||
// Hook to wait until the panel is shown.
|
||||
let originalOnPopupShown = DownloadsPanel.onPopupShown;
|
||||
DownloadsPanel.onPopupShown = function() {
|
||||
DownloadsPanel.onPopupShown = originalOnPopupShown;
|
||||
originalOnPopupShown.apply(this, arguments);
|
||||
|
||||
// Defer to the next tick of the event loop so that we don't continue
|
||||
// processing during the DOM event handler itself.
|
||||
setTimeout(deferred.resolve, 0);
|
||||
};
|
||||
// Defer to the next tick of the event loop so that we don't continue
|
||||
// processing during the DOM event handler itself.
|
||||
setTimeout(resolve, 0);
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
async function task_resetState() {
|
||||
|
@ -151,13 +151,13 @@ function synthesizeClickOnSelectedTreeCell(aTree, aOptions) {
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseIsURIVisited(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
resolve(aIsVisited);
|
||||
});
|
||||
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
deferred.resolve(aIsVisited);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseBookmarksNotification(notification, conditionFn) {
|
||||
|
@ -24,18 +24,18 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
function openPreferencesViaHash(aPane) {
|
||||
let deferred = Promise.defer();
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:preferences" + (aPane ? "#" + aPane : ""));
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
return new Promise(resolve => {
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:preferences" + (aPane ? "#" + aPane : ""));
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
gBrowser.removeCurrentTab();
|
||||
deferred.resolve({selectedPane});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
gBrowser.removeCurrentTab();
|
||||
resolve({selectedPane});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
@ -129,24 +129,24 @@ function waitForEvent(aSubject, aEventName, aTimeoutMs, aTarget) {
|
||||
}
|
||||
|
||||
function openPreferencesViaOpenPreferencesAPI(aPane, aAdvancedTab, aOptions) {
|
||||
let deferred = Promise.defer();
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||
openPreferences(aPane, aAdvancedTab ? {advancedTab: aAdvancedTab} : undefined);
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
return new Promise(resolve => {
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||
openPreferences(aPane, aAdvancedTab ? {advancedTab: aAdvancedTab} : undefined);
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
let doc = win.document;
|
||||
let selectedAdvancedTab = aAdvancedTab && doc.getElementById("advancedPrefs").selectedTab.id;
|
||||
if (!aOptions || !aOptions.leaveOpen)
|
||||
gBrowser.removeCurrentTab();
|
||||
deferred.resolve({selectedPane, selectedAdvancedTab});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
let doc = win.document;
|
||||
let selectedAdvancedTab = aAdvancedTab && doc.getElementById("advancedPrefs").selectedTab.id;
|
||||
if (!aOptions || !aOptions.leaveOpen)
|
||||
gBrowser.removeCurrentTab();
|
||||
resolve({selectedPane, selectedAdvancedTab});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCondition(aConditionFn, aMaxTries = 50, aCheckInterval = 100) {
|
||||
|
@ -60,18 +60,18 @@ add_task(async function() {
|
||||
|
||||
|
||||
function openPreferencesViaHash(aPane) {
|
||||
let deferred = Promise.defer();
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:preferences" + (aPane ? "#" + aPane : ""));
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
return new Promise(resolve => {
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:preferences" + (aPane ? "#" + aPane : ""));
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
gBrowser.removeCurrentTab();
|
||||
deferred.resolve({selectedPane});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
gBrowser.removeCurrentTab();
|
||||
resolve({selectedPane});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
@ -120,22 +120,22 @@ function waitForEvent(aSubject, aEventName, aTimeoutMs, aTarget) {
|
||||
}
|
||||
|
||||
function openPreferencesViaOpenPreferencesAPI(aPane, aOptions) {
|
||||
let deferred = Promise.defer();
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||
openPreferences(aPane);
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
return new Promise(resolve => {
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||
openPreferences(aPane);
|
||||
let newTabBrowser = gBrowser.selectedBrowser;
|
||||
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
if (!aOptions || !aOptions.leaveOpen)
|
||||
gBrowser.removeCurrentTab();
|
||||
deferred.resolve({selectedPane});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
newTabBrowser.addEventListener("Initialized", function() {
|
||||
newTabBrowser.contentWindow.addEventListener("load", function() {
|
||||
let win = gBrowser.contentWindow;
|
||||
let selectedPane = win.history.state;
|
||||
if (!aOptions || !aOptions.leaveOpen)
|
||||
gBrowser.removeCurrentTab();
|
||||
resolve({selectedPane});
|
||||
}, {once: true});
|
||||
}, {capture: true, once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCondition(aConditionFn, aMaxTries = 50, aCheckInterval = 100) {
|
||||
|
@ -16,11 +16,11 @@ function checkUrlbarFocus(win) {
|
||||
}
|
||||
|
||||
function openNewPrivateWindow() {
|
||||
let deferred = Promise.defer();
|
||||
whenNewWindowLoaded({private: true}, win => {
|
||||
executeSoon(() => deferred.resolve(win));
|
||||
return new Promise(resolve => {
|
||||
whenNewWindowLoaded({private: true}, win => {
|
||||
executeSoon(() => resolve(win));
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
|
@ -110,9 +110,9 @@ add_task(async function flush_on_tabclose_racy() {
|
||||
});
|
||||
|
||||
function promiseNewWindow() {
|
||||
let deferred = Promise.defer();
|
||||
whenNewWindowLoaded({private: false}, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
whenNewWindowLoaded({private: false}, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
async function createTabWithStorageData(urls, win = window) {
|
||||
|
@ -148,23 +148,23 @@ add_task(async function() {
|
||||
|
||||
// helper functions
|
||||
function waitForLoadsInBrowser(aBrowser, aLoadCount) {
|
||||
let deferred = Promise.defer();
|
||||
let loadCount = 0;
|
||||
aBrowser.addEventListener("load", function(aEvent) {
|
||||
if (++loadCount < aLoadCount) {
|
||||
info("Got " + loadCount + " loads, waiting until we have " + aLoadCount);
|
||||
return;
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
let loadCount = 0;
|
||||
aBrowser.addEventListener("load", function(aEvent) {
|
||||
if (++loadCount < aLoadCount) {
|
||||
info("Got " + loadCount + " loads, waiting until we have " + aLoadCount);
|
||||
return;
|
||||
}
|
||||
|
||||
aBrowser.removeEventListener("load", arguments.callee, true);
|
||||
deferred.resolve();
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
aBrowser.removeEventListener("load", arguments.callee, true);
|
||||
resolve();
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
function timeout(delay, task) {
|
||||
let deferred = Promise.defer();
|
||||
setTimeout(() => deferred.resolve(true), delay);
|
||||
task.then(() => deferred.resolve(false), deferred.reject);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => resolve(true), delay);
|
||||
task.then(() => resolve(false), reject);
|
||||
});
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
function promiseDelayedStartupFinished(win) {
|
||||
let deferred = Promise.defer();
|
||||
whenDelayedStartupFinished(win, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
whenDelayedStartupFinished(win, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseBrowserHasURL(browser, url) {
|
||||
|
@ -318,25 +318,25 @@ BingRequest.prototype = {
|
||||
"</TranslateArrayRequest>";
|
||||
|
||||
// Set up request options.
|
||||
let deferred = Promise.defer();
|
||||
let options = {
|
||||
onLoad: (responseText, xhr) => {
|
||||
deferred.resolve(this);
|
||||
},
|
||||
onError(e, responseText, xhr) {
|
||||
deferred.reject(xhr);
|
||||
},
|
||||
postData: requestString,
|
||||
headers
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
let options = {
|
||||
onLoad: (responseText, xhr) => {
|
||||
resolve(this);
|
||||
},
|
||||
onError(e, responseText, xhr) {
|
||||
reject(xhr);
|
||||
},
|
||||
postData: requestString,
|
||||
headers
|
||||
};
|
||||
|
||||
// Fire the request.
|
||||
let request = httpRequest(url, options);
|
||||
// Fire the request.
|
||||
let request = httpRequest(url, options);
|
||||
|
||||
// Override the response MIME type.
|
||||
request.overrideMimeType("text/xml");
|
||||
this.networkRequest = request;
|
||||
return deferred.promise;
|
||||
// Override the response MIME type.
|
||||
request.overrideMimeType("text/xml");
|
||||
this.networkRequest = request;
|
||||
});
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
@ -311,21 +311,21 @@ YandexRequest.prototype = {
|
||||
}
|
||||
|
||||
// Set up request options.
|
||||
let deferred = Promise.defer();
|
||||
let options = {
|
||||
onLoad: (responseText, xhr) => {
|
||||
deferred.resolve(this);
|
||||
},
|
||||
onError(e, responseText, xhr) {
|
||||
deferred.reject(xhr);
|
||||
},
|
||||
postData: params
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
let options = {
|
||||
onLoad: (responseText, xhr) => {
|
||||
resolve(this);
|
||||
},
|
||||
onError(e, responseText, xhr) {
|
||||
reject(xhr);
|
||||
},
|
||||
postData: params
|
||||
};
|
||||
|
||||
// Fire the request.
|
||||
this.networkRequest = httpRequest(url, options);
|
||||
// Fire the request.
|
||||
this.networkRequest = httpRequest(url, options);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
@ -119,15 +119,15 @@ function constructFixtureURL(filename) {
|
||||
* @param String url A URL to be loaded in the new tab.
|
||||
*/
|
||||
function promiseTestPageLoad(url) {
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(url);
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
browser.addEventListener("load", function listener() {
|
||||
if (browser.currentURI.spec == "about:blank")
|
||||
return;
|
||||
info("Page loaded: " + browser.currentURI.spec);
|
||||
browser.removeEventListener("load", listener, true);
|
||||
deferred.resolve(tab);
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(url);
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
browser.addEventListener("load", function listener() {
|
||||
if (browser.currentURI.spec == "about:blank")
|
||||
return;
|
||||
info("Page loaded: " + browser.currentURI.spec);
|
||||
browser.removeEventListener("load", listener, true);
|
||||
resolve(tab);
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
@ -57,44 +57,44 @@ function getDomainExceptions() {
|
||||
}
|
||||
|
||||
function getInfoBar() {
|
||||
let deferred = Promise.defer();
|
||||
let infobar =
|
||||
gBrowser.getNotificationBox().getNotificationWithValue("translation");
|
||||
return new Promise(resolve => {
|
||||
let infobar =
|
||||
gBrowser.getNotificationBox().getNotificationWithValue("translation");
|
||||
|
||||
if (!infobar) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
// Wait for all animations to finish
|
||||
Promise.all(infobar.getAnimations().map(animation => animation.finished))
|
||||
.then(() => deferred.resolve(infobar));
|
||||
}
|
||||
if (!infobar) {
|
||||
resolve();
|
||||
} else {
|
||||
// Wait for all animations to finish
|
||||
Promise.all(infobar.getAnimations().map(animation => animation.finished))
|
||||
.then(() => resolve(infobar));
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function openPopup(aPopup) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
aPopup.addEventListener("popupshown", function() {
|
||||
deferred.resolve();
|
||||
}, {once: true});
|
||||
aPopup.addEventListener("popupshown", function() {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
aPopup.focus();
|
||||
// One down event to open the popup.
|
||||
EventUtils.synthesizeKey("VK_DOWN",
|
||||
{ altKey: !navigator.platform.includes("Mac") });
|
||||
aPopup.focus();
|
||||
// One down event to open the popup.
|
||||
EventUtils.synthesizeKey("VK_DOWN",
|
||||
{ altKey: !navigator.platform.includes("Mac") });
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function waitForWindowLoad(aWin) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
aWin.addEventListener("load", function() {
|
||||
deferred.resolve();
|
||||
}, {capture: true, once: true});
|
||||
aWin.addEventListener("load", function() {
|
||||
resolve();
|
||||
}, {capture: true, once: true});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,17 +107,17 @@ function constructFixtureURL(filename) {
|
||||
* @param String url A URL to be loaded in the new tab.
|
||||
*/
|
||||
function promiseTestPageLoad(url) {
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(url);
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
browser.addEventListener("load", function listener() {
|
||||
if (browser.currentURI.spec == "about:blank")
|
||||
return;
|
||||
info("Page loaded: " + browser.currentURI.spec);
|
||||
browser.removeEventListener("load", listener, true);
|
||||
deferred.resolve(tab);
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(url);
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
browser.addEventListener("load", function listener() {
|
||||
if (browser.currentURI.spec == "about:blank")
|
||||
return;
|
||||
info("Page loaded: " + browser.currentURI.spec);
|
||||
browser.removeEventListener("load", listener, true);
|
||||
resolve(tab);
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
function showTranslationUI(tab, aDetectedLanguage) {
|
||||
|
@ -60,43 +60,43 @@ add_task(async function test_windowless_UITour() {
|
||||
Services.perms.add(pageURI, "uitour", Services.perms.ALLOW_ACTION);
|
||||
|
||||
// UITour's ping will resolve this promise.
|
||||
let deferredPing = Promise.defer();
|
||||
await new Promise(resolve => {
|
||||
|
||||
// Create a windowless browser and test that UITour works in it.
|
||||
let browserPromise = createHiddenBrowser(pageURL);
|
||||
browserPromise.then(frameInfo => {
|
||||
isnot(frameInfo.browser, null, "The browser must exist and not be null.");
|
||||
// Create a windowless browser and test that UITour works in it.
|
||||
let browserPromise = createHiddenBrowser(pageURL);
|
||||
browserPromise.then(frameInfo => {
|
||||
isnot(frameInfo.browser, null, "The browser must exist and not be null.");
|
||||
|
||||
// Load UITour frame script.
|
||||
frameInfo.browser.messageManager.loadFrameScript(
|
||||
"chrome://browser/content/content-UITour.js", false);
|
||||
// Load UITour frame script.
|
||||
frameInfo.browser.messageManager.loadFrameScript(
|
||||
"chrome://browser/content/content-UITour.js", false);
|
||||
|
||||
// When the page loads, try to use UITour API.
|
||||
frameInfo.browser.addEventListener("load", function loadListener() {
|
||||
info("The test page was correctly loaded.");
|
||||
// When the page loads, try to use UITour API.
|
||||
frameInfo.browser.addEventListener("load", function loadListener() {
|
||||
info("The test page was correctly loaded.");
|
||||
|
||||
frameInfo.browser.removeEventListener("load", loadListener, true);
|
||||
frameInfo.browser.removeEventListener("load", loadListener, true);
|
||||
|
||||
// Get a reference to the UITour API.
|
||||
info("Testing access to the UITour API.");
|
||||
let contentWindow = Cu.waiveXrays(frameInfo.browser.contentDocument.defaultView);
|
||||
isnot(contentWindow, null, "The content window must exist and not be null.");
|
||||
// Get a reference to the UITour API.
|
||||
info("Testing access to the UITour API.");
|
||||
let contentWindow = Cu.waiveXrays(frameInfo.browser.contentDocument.defaultView);
|
||||
isnot(contentWindow, null, "The content window must exist and not be null.");
|
||||
|
||||
let uitourAPI = contentWindow.Mozilla.UITour;
|
||||
let uitourAPI = contentWindow.Mozilla.UITour;
|
||||
|
||||
// Test the UITour API with a ping.
|
||||
uitourAPI.ping(function() {
|
||||
info("Ping response received from the UITour API.");
|
||||
// Test the UITour API with a ping.
|
||||
uitourAPI.ping(function() {
|
||||
info("Ping response received from the UITour API.");
|
||||
|
||||
// Make sure to clean up.
|
||||
destroyHiddenBrowser(frameInfo.frame, frameInfo.browser);
|
||||
// Make sure to clean up.
|
||||
destroyHiddenBrowser(frameInfo.frame, frameInfo.browser);
|
||||
|
||||
// Resolve our promise.
|
||||
deferredPing.resolve();
|
||||
});
|
||||
}, true);
|
||||
// Resolve our promise.
|
||||
resolve();
|
||||
});
|
||||
}, true);
|
||||
});
|
||||
|
||||
// Wait for the UITour ping to complete.
|
||||
});
|
||||
|
||||
// Wait for the UITour ping to complete.
|
||||
await deferredPing.promise;
|
||||
});
|
||||
|
@ -12,27 +12,27 @@ const SINGLE_TRY_TIMEOUT = 100;
|
||||
const NUMBER_OF_TRIES = 30;
|
||||
|
||||
function waitForConditionPromise(condition, timeoutMsg, tryCount = NUMBER_OF_TRIES) {
|
||||
let defer = Promise.defer();
|
||||
let tries = 0;
|
||||
function checkCondition() {
|
||||
if (tries >= tryCount) {
|
||||
defer.reject(timeoutMsg);
|
||||
return new Promise((resolve, reject) => {
|
||||
let tries = 0;
|
||||
function checkCondition() {
|
||||
if (tries >= tryCount) {
|
||||
reject(timeoutMsg);
|
||||
}
|
||||
var conditionPassed;
|
||||
try {
|
||||
conditionPassed = condition();
|
||||
} catch (e) {
|
||||
return reject(e);
|
||||
}
|
||||
if (conditionPassed) {
|
||||
return resolve();
|
||||
}
|
||||
tries++;
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return undefined;
|
||||
}
|
||||
var conditionPassed;
|
||||
try {
|
||||
conditionPassed = condition();
|
||||
} catch (e) {
|
||||
return defer.reject(e);
|
||||
}
|
||||
if (conditionPassed) {
|
||||
return defer.resolve();
|
||||
}
|
||||
tries++;
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return undefined;
|
||||
}
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return defer.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCondition(condition, nextTestFn, errorMsg) {
|
||||
|
@ -174,32 +174,32 @@ function installedExperimentAddons() {
|
||||
// addons are uninstalled.
|
||||
function uninstallAddons(addons) {
|
||||
let ids = new Set(addons.map(addon => addon.id));
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let listener = {};
|
||||
listener.onUninstalled = addon => {
|
||||
if (!ids.has(addon.id)) {
|
||||
return;
|
||||
let listener = {};
|
||||
listener.onUninstalled = addon => {
|
||||
if (!ids.has(addon.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ids.delete(addon.id);
|
||||
if (ids.size == 0) {
|
||||
AddonManager.removeAddonListener(listener);
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
AddonManager.addAddonListener(listener);
|
||||
|
||||
for (let addon of addons) {
|
||||
// Disabling the add-on before uninstalling is necessary to cause tests to
|
||||
// pass. This might be indicative of a bug in XPIProvider.
|
||||
// TODO follow up in bug 992396.
|
||||
addon.userDisabled = true;
|
||||
addon.uninstall();
|
||||
}
|
||||
|
||||
ids.delete(addon.id);
|
||||
if (ids.size == 0) {
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
AddonManager.addAddonListener(listener);
|
||||
|
||||
for (let addon of addons) {
|
||||
// Disabling the add-on before uninstalling is necessary to cause tests to
|
||||
// pass. This might be indicative of a bug in XPIProvider.
|
||||
// TODO follow up in bug 992396.
|
||||
addon.userDisabled = true;
|
||||
addon.uninstall();
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -934,44 +934,44 @@ Experiments.Experiments.prototype = {
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
|
||||
this._networkRequest = xhr;
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let log = this._log;
|
||||
let errorhandler = (evt) => {
|
||||
log.error("httpGetRequest::onError() - Error making request to " + url + ": " + evt.type);
|
||||
deferred.reject(new Error("Experiments - XHR error for " + url + " - " + evt.type));
|
||||
this._networkRequest = null;
|
||||
};
|
||||
xhr.onerror = errorhandler;
|
||||
xhr.ontimeout = errorhandler;
|
||||
xhr.onabort = errorhandler;
|
||||
|
||||
xhr.onload = (event) => {
|
||||
if (xhr.status !== 200 && xhr.state !== 0) {
|
||||
log.error("httpGetRequest::onLoad() - Request to " + url + " returned status " + xhr.status);
|
||||
deferred.reject(new Error("Experiments - XHR status for " + url + " is " + xhr.status));
|
||||
let log = this._log;
|
||||
let errorhandler = (evt) => {
|
||||
log.error("httpGetRequest::onError() - Error making request to " + url + ": " + evt.type);
|
||||
reject(new Error("Experiments - XHR error for " + url + " - " + evt.type));
|
||||
this._networkRequest = null;
|
||||
return;
|
||||
};
|
||||
xhr.onerror = errorhandler;
|
||||
xhr.ontimeout = errorhandler;
|
||||
xhr.onabort = errorhandler;
|
||||
|
||||
xhr.onload = (event) => {
|
||||
if (xhr.status !== 200 && xhr.state !== 0) {
|
||||
log.error("httpGetRequest::onLoad() - Request to " + url + " returned status " + xhr.status);
|
||||
reject(new Error("Experiments - XHR status for " + url + " is " + xhr.status));
|
||||
this._networkRequest = null;
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(xhr.responseText);
|
||||
this._networkRequest = null;
|
||||
};
|
||||
|
||||
try {
|
||||
xhr.open("GET", url);
|
||||
|
||||
if (xhr.channel instanceof Ci.nsISupportsPriority) {
|
||||
xhr.channel.priority = Ci.nsISupportsPriority.PRIORITY_LOWEST;
|
||||
}
|
||||
|
||||
xhr.timeout = MANIFEST_FETCH_TIMEOUT_MSEC;
|
||||
xhr.send(null);
|
||||
} catch (e) {
|
||||
this._log.error("httpGetRequest() - Error opening request to " + url + ": " + e);
|
||||
return Promise.reject(new Error("Experiments - Error opening XHR for " + url));
|
||||
}
|
||||
|
||||
deferred.resolve(xhr.responseText);
|
||||
this._networkRequest = null;
|
||||
};
|
||||
|
||||
try {
|
||||
xhr.open("GET", url);
|
||||
|
||||
if (xhr.channel instanceof Ci.nsISupportsPriority) {
|
||||
xhr.channel.priority = Ci.nsISupportsPriority.PRIORITY_LOWEST;
|
||||
}
|
||||
|
||||
xhr.timeout = MANIFEST_FETCH_TIMEOUT_MSEC;
|
||||
xhr.send(null);
|
||||
} catch (e) {
|
||||
this._log.error("httpGetRequest() - Error opening request to " + url + ": " + e);
|
||||
return Promise.reject(new Error("Experiments - Error opening XHR for " + url));
|
||||
}
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
@ -1968,35 +1968,35 @@ Experiments.ExperimentEntry.prototype = {
|
||||
throw new Error("Experiment addon requires a restart: " + addon.id);
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
await new Promise((resolve, reject) => {
|
||||
|
||||
// Else we need to enable it.
|
||||
let listener = {
|
||||
onEnabled: enabledAddon => {
|
||||
if (enabledAddon.id != addon.id) {
|
||||
return;
|
||||
}
|
||||
// Else we need to enable it.
|
||||
let listener = {
|
||||
onEnabled: enabledAddon => {
|
||||
if (enabledAddon.id != addon.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve();
|
||||
},
|
||||
};
|
||||
|
||||
for (let handler of ["onDisabled", "onOperationCancelled", "onUninstalled"]) {
|
||||
listener[handler] = (evtAddon) => {
|
||||
if (evtAddon.id != addon.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.reject("Failed to enable addon " + addon.id + " due to: " + handler);
|
||||
AddonManager.removeAddonListener(listener);
|
||||
resolve();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
this._log.info("reconcileAddonState() - Activating add-on: " + addon.id);
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.userDisabled = false;
|
||||
await deferred.promise;
|
||||
for (let handler of ["onDisabled", "onOperationCancelled", "onUninstalled"]) {
|
||||
listener[handler] = (evtAddon) => {
|
||||
if (evtAddon.id != addon.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
reject("Failed to enable addon " + addon.id + " due to: " + handler);
|
||||
};
|
||||
}
|
||||
|
||||
this._log.info("reconcileAddonState() - Activating add-on: " + addon.id);
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.userDisabled = false;
|
||||
});
|
||||
changes |= this.ADDON_CHANGE_ENABLE;
|
||||
|
||||
this._log.info("reconcileAddonState() - Add-on has been enabled: " + addon.id);
|
||||
@ -2049,13 +2049,13 @@ Experiments.ExperimentEntry.prototype = {
|
||||
throw new Error("shouldStop must not be called on disabled experiments.");
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
this.isApplicable().then(
|
||||
() => deferred.resolve({shouldStop: false}),
|
||||
reason => deferred.resolve({shouldStop: true, reason})
|
||||
);
|
||||
return new Promise(resolve => {
|
||||
this.isApplicable().then(
|
||||
() => resolve({shouldStop: false}),
|
||||
reason => resolve({shouldStop: true, reason})
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -159,17 +159,17 @@ function startAddonManagerOnly() {
|
||||
}
|
||||
|
||||
function getExperimentAddons(previous = false) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
||||
if (previous) {
|
||||
resolve(addons);
|
||||
} else {
|
||||
resolve(addons.filter(a => !a.appDisabled));
|
||||
}
|
||||
});
|
||||
|
||||
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
||||
if (previous) {
|
||||
deferred.resolve(addons);
|
||||
} else {
|
||||
deferred.resolve(addons.filter(a => !a.appDisabled));
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function createAppInfo(ID = "xpcshell@tests.mozilla.org", name = "XPCShell",
|
||||
|
@ -49,13 +49,13 @@ add_task(async function test_setup() {
|
||||
});
|
||||
|
||||
function isApplicable(experiment) {
|
||||
let deferred = Promise.defer();
|
||||
experiment.isApplicable().then(
|
||||
result => deferred.resolve({ applicable: true, reason: null }),
|
||||
reason => deferred.resolve({ applicable: false, reason })
|
||||
);
|
||||
return new Promise(resolve => {
|
||||
experiment.isApplicable().then(
|
||||
result => resolve({ applicable: true, reason: null }),
|
||||
reason => resolve({ applicable: false, reason })
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_startStop() {
|
||||
|
@ -518,24 +518,24 @@ this.ContentSearch = {
|
||||
if (!uri) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let deferred = Promise.defer();
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("GET", uri, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onload = () => {
|
||||
deferred.resolve(xhr.response);
|
||||
};
|
||||
xhr.onerror = xhr.onabort = xhr.ontimeout = () => {
|
||||
deferred.resolve(null);
|
||||
};
|
||||
try {
|
||||
// This throws if the URI is erroneously encoded.
|
||||
xhr.send();
|
||||
} catch (err) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("GET", uri, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onload = () => {
|
||||
resolve(xhr.response);
|
||||
};
|
||||
xhr.onerror = xhr.onabort = xhr.ontimeout = () => {
|
||||
resolve(null);
|
||||
};
|
||||
try {
|
||||
// This throws if the URI is erroneously encoded.
|
||||
xhr.send();
|
||||
} catch (err) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_ensureDataHasProperties(data, requiredProperties) {
|
||||
|
@ -153,33 +153,33 @@ var DirectoryLinksProvider = {
|
||||
* @return promise resolved to json string, "{}" returned if status != 200
|
||||
*/
|
||||
_downloadJsonData: function DirectoryLinksProvider__downloadJsonData(uri) {
|
||||
let deferred = Promise.defer();
|
||||
let xmlHttp = this._newXHR();
|
||||
return new Promise((resolve, reject) => {
|
||||
let xmlHttp = this._newXHR();
|
||||
|
||||
xmlHttp.onload = function(aResponse) {
|
||||
let json = this.responseText;
|
||||
if (this.status && this.status != 200) {
|
||||
json = "{}";
|
||||
xmlHttp.onload = function(aResponse) {
|
||||
let json = this.responseText;
|
||||
if (this.status && this.status != 200) {
|
||||
json = "{}";
|
||||
}
|
||||
resolve(json);
|
||||
};
|
||||
|
||||
xmlHttp.onerror = function(e) {
|
||||
reject("Fetching " + uri + " results in error code: " + e.target.status);
|
||||
};
|
||||
|
||||
try {
|
||||
xmlHttp.open("GET", uri);
|
||||
// Override the type so XHR doesn't complain about not well-formed XML
|
||||
xmlHttp.overrideMimeType(DIRECTORY_LINKS_TYPE);
|
||||
// Set the appropriate request type for servers that require correct types
|
||||
xmlHttp.setRequestHeader("Content-Type", DIRECTORY_LINKS_TYPE);
|
||||
xmlHttp.send();
|
||||
} catch (e) {
|
||||
reject("Error fetching " + uri);
|
||||
Cu.reportError(e);
|
||||
}
|
||||
deferred.resolve(json);
|
||||
};
|
||||
|
||||
xmlHttp.onerror = function(e) {
|
||||
deferred.reject("Fetching " + uri + " results in error code: " + e.target.status);
|
||||
};
|
||||
|
||||
try {
|
||||
xmlHttp.open("GET", uri);
|
||||
// Override the type so XHR doesn't complain about not well-formed XML
|
||||
xmlHttp.overrideMimeType(DIRECTORY_LINKS_TYPE);
|
||||
// Set the appropriate request type for servers that require correct types
|
||||
xmlHttp.setRequestHeader("Content-Type", DIRECTORY_LINKS_TYPE);
|
||||
xmlHttp.send();
|
||||
} catch (e) {
|
||||
deferred.reject("Error fetching " + uri);
|
||||
Cu.reportError(e);
|
||||
}
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -300,16 +300,16 @@ function checkMsg(actualMsg, expectedMsgData) {
|
||||
}
|
||||
|
||||
function waitForMsg(name, type) {
|
||||
let deferred = Promise.defer();
|
||||
info("Waiting for " + name + " message " + type + "...");
|
||||
gMsgMan.addMessageListener(name, function onMsg(msg) {
|
||||
info("Received " + name + " message " + msg.data.type + "\n");
|
||||
if (msg.data.type == type) {
|
||||
gMsgMan.removeMessageListener(name, onMsg);
|
||||
deferred.resolve(msg);
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
info("Waiting for " + name + " message " + type + "...");
|
||||
gMsgMan.addMessageListener(name, function onMsg(msg) {
|
||||
info("Received " + name + " message " + msg.data.type + "\n");
|
||||
if (msg.data.type == type) {
|
||||
gMsgMan.removeMessageListener(name, onMsg);
|
||||
resolve(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitForTestMsg(type) {
|
||||
@ -346,23 +346,23 @@ function waitForNewEngine(basename, numImages) {
|
||||
}
|
||||
|
||||
function addTab() {
|
||||
let deferred = Promise.defer();
|
||||
let tab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", function() {
|
||||
let url = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
|
||||
gMsgMan = tab.linkedBrowser.messageManager;
|
||||
gMsgMan.sendAsyncMessage(CONTENT_SEARCH_MSG, {
|
||||
type: "AddToWhitelist",
|
||||
data: ["about:blank"],
|
||||
});
|
||||
waitForMsg(CONTENT_SEARCH_MSG, "AddToWhitelistAck").then(() => {
|
||||
gMsgMan.loadFrameScript(url, false);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {capture: true, once: true});
|
||||
registerCleanupFunction(() => gBrowser.removeTab(tab));
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let tab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", function() {
|
||||
let url = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
|
||||
gMsgMan = tab.linkedBrowser.messageManager;
|
||||
gMsgMan.sendAsyncMessage(CONTENT_SEARCH_MSG, {
|
||||
type: "AddToWhitelist",
|
||||
data: ["about:blank"],
|
||||
});
|
||||
waitForMsg(CONTENT_SEARCH_MSG, "AddToWhitelistAck").then(() => {
|
||||
gMsgMan.loadFrameScript(url, false);
|
||||
resolve();
|
||||
});
|
||||
}, {capture: true, once: true});
|
||||
registerCleanupFunction(() => gBrowser.removeTab(tab));
|
||||
});
|
||||
}
|
||||
|
||||
var currentStateObj = async function() {
|
||||
@ -396,21 +396,21 @@ function arrayBufferFromDataURI(uri) {
|
||||
if (!uri) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
let deferred = Promise.defer();
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("GET", uri, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onerror = () => {
|
||||
deferred.resolve(null);
|
||||
};
|
||||
xhr.onload = () => {
|
||||
deferred.resolve(xhr.response);
|
||||
};
|
||||
try {
|
||||
xhr.send();
|
||||
} catch (err) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
xhr.open("GET", uri, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onerror = () => {
|
||||
resolve(null);
|
||||
};
|
||||
xhr.onload = () => {
|
||||
resolve(xhr.response);
|
||||
};
|
||||
try {
|
||||
xhr.send();
|
||||
} catch (err) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -7,27 +7,27 @@ const SINGLE_TRY_TIMEOUT = 100;
|
||||
const NUMBER_OF_TRIES = 30;
|
||||
|
||||
function waitForConditionPromise(condition, timeoutMsg, tryCount = NUMBER_OF_TRIES) {
|
||||
let defer = Promise.defer();
|
||||
let tries = 0;
|
||||
function checkCondition() {
|
||||
if (tries >= tryCount) {
|
||||
defer.reject(timeoutMsg);
|
||||
return new Promise((resolve, reject) => {
|
||||
let tries = 0;
|
||||
function checkCondition() {
|
||||
if (tries >= tryCount) {
|
||||
reject(timeoutMsg);
|
||||
}
|
||||
var conditionPassed;
|
||||
try {
|
||||
conditionPassed = condition();
|
||||
} catch (e) {
|
||||
return reject(e);
|
||||
}
|
||||
if (conditionPassed) {
|
||||
return resolve();
|
||||
}
|
||||
tries++;
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return undefined;
|
||||
}
|
||||
var conditionPassed;
|
||||
try {
|
||||
conditionPassed = condition();
|
||||
} catch (e) {
|
||||
return defer.reject(e);
|
||||
}
|
||||
if (conditionPassed) {
|
||||
return defer.resolve();
|
||||
}
|
||||
tries++;
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return undefined;
|
||||
}
|
||||
setTimeout(checkCondition, SINGLE_TRY_TIMEOUT);
|
||||
return defer.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function waitForCondition(condition, nextTest, errorMsg) {
|
||||
|
@ -90,12 +90,12 @@ function isIdentical(actual, expected) {
|
||||
}
|
||||
|
||||
function fetchData() {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
DirectoryLinksProvider.getLinks(linkData => {
|
||||
deferred.resolve(linkData);
|
||||
DirectoryLinksProvider.getLinks(linkData => {
|
||||
resolve(linkData);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function readJsonFile(jsonFile = DIRECTORY_LINKS_FILE) {
|
||||
|
@ -142,13 +142,13 @@ function longRunningAsyncTask(resolution = undefined, outResult = {}) {
|
||||
if (!("countFinished" in outResult)) {
|
||||
outResult.countFinished = 0;
|
||||
}
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(100, function() {
|
||||
++outResult.countFinished;
|
||||
outResult.isFinished = true;
|
||||
deferred.resolve(resolution);
|
||||
return new Promise(resolve => {
|
||||
do_timeout(100, function() {
|
||||
++outResult.countFinished;
|
||||
outResult.isFinished = true;
|
||||
resolve(resolution);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function get_exn(f) {
|
||||
|
@ -20,26 +20,26 @@ add_task(async function test_userContextId() {
|
||||
});
|
||||
|
||||
function doSearch(aString, aUserContextId) {
|
||||
let deferred = Promise.defer();
|
||||
let search = new AutoCompleteSearch("test");
|
||||
return new Promise(resolve => {
|
||||
let search = new AutoCompleteSearch("test");
|
||||
|
||||
search.startSearch = function(aSearchString,
|
||||
aSearchParam,
|
||||
aPreviousResult,
|
||||
aListener) {
|
||||
unregisterAutoCompleteSearch(search);
|
||||
deferred.resolve(aSearchParam);
|
||||
};
|
||||
search.startSearch = function(aSearchString,
|
||||
aSearchParam,
|
||||
aPreviousResult,
|
||||
aListener) {
|
||||
unregisterAutoCompleteSearch(search);
|
||||
resolve(aSearchParam);
|
||||
};
|
||||
|
||||
registerAutoCompleteSearch(search);
|
||||
registerAutoCompleteSearch(search);
|
||||
|
||||
let controller = Cc["@mozilla.org/autocomplete/controller;1"].
|
||||
getService(Ci.nsIAutoCompleteController);
|
||||
let controller = Cc["@mozilla.org/autocomplete/controller;1"].
|
||||
getService(Ci.nsIAutoCompleteController);
|
||||
|
||||
let input = new AutoCompleteInput([ search.name ], aUserContextId);
|
||||
controller.input = input;
|
||||
controller.startSearch(aString);
|
||||
let input = new AutoCompleteInput([ search.name ], aUserContextId);
|
||||
controller.input = input;
|
||||
controller.startSearch(aString);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,13 @@ this.configureLogging = function() {
|
||||
};
|
||||
|
||||
this.sleep = function(wait) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
setTimeout(() => {
|
||||
deferred.resolve();
|
||||
}, wait);
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, wait);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
};
|
||||
|
||||
this.TestingCrashManager = function(options) {
|
||||
|
@ -164,54 +164,54 @@ function processUpdateRequest() {
|
||||
|
||||
// Set up the local whitelist.
|
||||
function waitForUpdates() {
|
||||
let deferred = Promise.defer();
|
||||
gHttpServer.registerPathHandler("/downloads", function(request, response) {
|
||||
let blob = processUpdateRequest();
|
||||
response.setHeader("Content-Type",
|
||||
"application/vnd.google.safebrowsing-update", false);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(blob, blob.length);
|
||||
return new Promise((resolve, reject) => {
|
||||
gHttpServer.registerPathHandler("/downloads", function(request, response) {
|
||||
let blob = processUpdateRequest();
|
||||
response.setHeader("Content-Type",
|
||||
"application/vnd.google.safebrowsing-update", false);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(blob, blob.length);
|
||||
});
|
||||
|
||||
let streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
|
||||
.getService(Ci.nsIUrlClassifierStreamUpdater);
|
||||
|
||||
// Load up some update chunks for the safebrowsing server to serve. This
|
||||
// particular chunk contains the hash of whitelisted.com/ and
|
||||
// sb-ssl.google.com/safebrowsing/csd/certificate/.
|
||||
registerTableUpdate("goog-downloadwhite-digest256", "data/digest.chunk");
|
||||
|
||||
// Resolve the promise once processing the updates is complete.
|
||||
function updateSuccess(aEvent) {
|
||||
// Timeout of n:1000 is constructed in processUpdateRequest above and
|
||||
// passed back in the callback in nsIUrlClassifierStreamUpdater on success.
|
||||
do_check_eq("1000", aEvent);
|
||||
do_print("All data processed");
|
||||
resolve(true);
|
||||
}
|
||||
// Just throw if we ever get an update or download error.
|
||||
function handleError(aEvent) {
|
||||
do_throw("We didn't download or update correctly: " + aEvent);
|
||||
reject();
|
||||
}
|
||||
streamUpdater.downloadUpdates(
|
||||
"goog-downloadwhite-digest256",
|
||||
"goog-downloadwhite-digest256;\n",
|
||||
true,
|
||||
"http://localhost:4444/downloads",
|
||||
updateSuccess, handleError, handleError);
|
||||
});
|
||||
|
||||
let streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
|
||||
.getService(Ci.nsIUrlClassifierStreamUpdater);
|
||||
|
||||
// Load up some update chunks for the safebrowsing server to serve. This
|
||||
// particular chunk contains the hash of whitelisted.com/ and
|
||||
// sb-ssl.google.com/safebrowsing/csd/certificate/.
|
||||
registerTableUpdate("goog-downloadwhite-digest256", "data/digest.chunk");
|
||||
|
||||
// Resolve the promise once processing the updates is complete.
|
||||
function updateSuccess(aEvent) {
|
||||
// Timeout of n:1000 is constructed in processUpdateRequest above and
|
||||
// passed back in the callback in nsIUrlClassifierStreamUpdater on success.
|
||||
do_check_eq("1000", aEvent);
|
||||
do_print("All data processed");
|
||||
deferred.resolve(true);
|
||||
}
|
||||
// Just throw if we ever get an update or download error.
|
||||
function handleError(aEvent) {
|
||||
do_throw("We didn't download or update correctly: " + aEvent);
|
||||
deferred.reject();
|
||||
}
|
||||
streamUpdater.downloadUpdates(
|
||||
"goog-downloadwhite-digest256",
|
||||
"goog-downloadwhite-digest256;\n",
|
||||
true,
|
||||
"http://localhost:4444/downloads",
|
||||
updateSuccess, handleError, handleError);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseQueryReputation(query, expectedShouldBlock) {
|
||||
let deferred = Promise.defer();
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
do_check_eq(Cr.NS_OK, aStatus);
|
||||
do_check_eq(aShouldBlock, expectedShouldBlock);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
gAppRep.queryReputation(query, onComplete);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
do_check_eq(Cr.NS_OK, aStatus);
|
||||
do_check_eq(aShouldBlock, expectedShouldBlock);
|
||||
resolve(true);
|
||||
}
|
||||
gAppRep.queryReputation(query, onComplete);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
@ -263,16 +263,16 @@ add_task(async function test_disabled() {
|
||||
let query = {sourceURI: createURI("http://example.com"),
|
||||
suggestedFileName: "noop.bat",
|
||||
fileSize: 12};
|
||||
let deferred = Promise.defer();
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
resolve(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_disabled_through_lists() {
|
||||
@ -284,16 +284,16 @@ add_task(async function test_disabled_through_lists() {
|
||||
let query = {sourceURI: createURI("http://example.com"),
|
||||
suggestedFileName: "noop.bat",
|
||||
fileSize: 12};
|
||||
let deferred = Promise.defer();
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
resolve(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
add_task(async function test_teardown() {
|
||||
gStillRunning = false;
|
||||
|
@ -75,22 +75,22 @@ function readFileToString(aFilename) {
|
||||
* @rejects With an exception, if onSaveComplete is called with a failure code.
|
||||
*/
|
||||
function promiseSaverComplete(aSaver, aOnTargetChangeFn) {
|
||||
let deferred = Promise.defer();
|
||||
aSaver.observer = {
|
||||
onTargetChange: function BFSO_onSaveComplete(unused, aTarget) {
|
||||
if (aOnTargetChangeFn) {
|
||||
aOnTargetChangeFn(aTarget);
|
||||
}
|
||||
},
|
||||
onSaveComplete: function BFSO_onSaveComplete(unused, aStatus) {
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception("Saver failed.", aStatus));
|
||||
}
|
||||
},
|
||||
};
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
aSaver.observer = {
|
||||
onTargetChange: function BFSO_onSaveComplete(unused, aTarget) {
|
||||
if (aOnTargetChangeFn) {
|
||||
aOnTargetChangeFn(aTarget);
|
||||
}
|
||||
},
|
||||
onSaveComplete: function BFSO_onSaveComplete(unused, aStatus) {
|
||||
if (Components.isSuccessCode(aStatus)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception("Saver failed.", aStatus));
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,23 +108,23 @@ function promiseSaverComplete(aSaver, aOnTargetChangeFn) {
|
||||
* @rejects With an exception, if the copy fails.
|
||||
*/
|
||||
function promiseCopyToSaver(aSourceString, aSaverOutputStream, aCloseWhenDone) {
|
||||
let deferred = Promise.defer();
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let copier = Cc["@mozilla.org/network/async-stream-copier;1"]
|
||||
.createInstance(Ci.nsIAsyncStreamCopier);
|
||||
copier.init(inputStream, aSaverOutputStream, null, false, true, 0x8000, true,
|
||||
aCloseWhenDone);
|
||||
copier.asyncCopy({
|
||||
onStartRequest() { },
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
deferred.resolve();
|
||||
} else {
|
||||
deferred.reject(new Components.Exception(aStatusCode));
|
||||
}
|
||||
},
|
||||
}, null);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let inputStream = new StringInputStream(aSourceString, aSourceString.length);
|
||||
let copier = Cc["@mozilla.org/network/async-stream-copier;1"]
|
||||
.createInstance(Ci.nsIAsyncStreamCopier);
|
||||
copier.init(inputStream, aSaverOutputStream, null, false, true, 0x8000, true,
|
||||
aCloseWhenDone);
|
||||
copier.asyncCopy({
|
||||
onStartRequest() { },
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
if (Components.isSuccessCode(aStatusCode)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Components.Exception(aStatusCode));
|
||||
}
|
||||
},
|
||||
}, null);
|
||||
});
|
||||
}
|
||||
|
||||
// Registers a table for which to serve update chunks.
|
||||
@ -261,54 +261,54 @@ function processUpdateRequest() {
|
||||
|
||||
// Set up the local whitelist.
|
||||
function waitForUpdates() {
|
||||
let deferred = Promise.defer();
|
||||
gHttpServer.registerPathHandler("/downloads", function(request, response) {
|
||||
let blob = processUpdateRequest();
|
||||
response.setHeader("Content-Type",
|
||||
"application/vnd.google.safebrowsing-update", false);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(blob, blob.length);
|
||||
return new Promise((resolve, reject) => {
|
||||
gHttpServer.registerPathHandler("/downloads", function(request, response) {
|
||||
let blob = processUpdateRequest();
|
||||
response.setHeader("Content-Type",
|
||||
"application/vnd.google.safebrowsing-update", false);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(blob, blob.length);
|
||||
});
|
||||
|
||||
let streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
|
||||
.getService(Ci.nsIUrlClassifierStreamUpdater);
|
||||
|
||||
// Load up some update chunks for the safebrowsing server to serve. This
|
||||
// particular chunk contains the hash of whitelisted.com/ and
|
||||
// sb-ssl.google.com/safebrowsing/csd/certificate/.
|
||||
registerTableUpdate("goog-downloadwhite-digest256", "data/digest.chunk");
|
||||
|
||||
// Resolve the promise once processing the updates is complete.
|
||||
function updateSuccess(aEvent) {
|
||||
// Timeout of n:1000 is constructed in processUpdateRequest above and
|
||||
// passed back in the callback in nsIUrlClassifierStreamUpdater on success.
|
||||
do_check_eq("1000", aEvent);
|
||||
do_print("All data processed");
|
||||
resolve(true);
|
||||
}
|
||||
// Just throw if we ever get an update or download error.
|
||||
function handleError(aEvent) {
|
||||
do_throw("We didn't download or update correctly: " + aEvent);
|
||||
reject();
|
||||
}
|
||||
streamUpdater.downloadUpdates(
|
||||
"goog-downloadwhite-digest256",
|
||||
"goog-downloadwhite-digest256;\n",
|
||||
true,
|
||||
"http://localhost:4444/downloads",
|
||||
updateSuccess, handleError, handleError);
|
||||
});
|
||||
|
||||
let streamUpdater = Cc["@mozilla.org/url-classifier/streamupdater;1"]
|
||||
.getService(Ci.nsIUrlClassifierStreamUpdater);
|
||||
|
||||
// Load up some update chunks for the safebrowsing server to serve. This
|
||||
// particular chunk contains the hash of whitelisted.com/ and
|
||||
// sb-ssl.google.com/safebrowsing/csd/certificate/.
|
||||
registerTableUpdate("goog-downloadwhite-digest256", "data/digest.chunk");
|
||||
|
||||
// Resolve the promise once processing the updates is complete.
|
||||
function updateSuccess(aEvent) {
|
||||
// Timeout of n:1000 is constructed in processUpdateRequest above and
|
||||
// passed back in the callback in nsIUrlClassifierStreamUpdater on success.
|
||||
do_check_eq("1000", aEvent);
|
||||
do_print("All data processed");
|
||||
deferred.resolve(true);
|
||||
}
|
||||
// Just throw if we ever get an update or download error.
|
||||
function handleError(aEvent) {
|
||||
do_throw("We didn't download or update correctly: " + aEvent);
|
||||
deferred.reject();
|
||||
}
|
||||
streamUpdater.downloadUpdates(
|
||||
"goog-downloadwhite-digest256",
|
||||
"goog-downloadwhite-digest256;\n",
|
||||
true,
|
||||
"http://localhost:4444/downloads",
|
||||
updateSuccess, handleError, handleError);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseQueryReputation(query, expectedShouldBlock) {
|
||||
let deferred = Promise.defer();
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
do_check_eq(Cr.NS_OK, aStatus);
|
||||
do_check_eq(aShouldBlock, expectedShouldBlock);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
gAppRep.queryReputation(query, onComplete);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
do_check_eq(Cr.NS_OK, aStatus);
|
||||
do_check_eq(aShouldBlock, expectedShouldBlock);
|
||||
resolve(true);
|
||||
}
|
||||
gAppRep.queryReputation(query, onComplete);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
@ -390,16 +390,16 @@ add_task(async function test_disabled() {
|
||||
let query = {sourceURI: createURI("http://example.com"),
|
||||
suggestedFileName: "noop.bat",
|
||||
fileSize: 12};
|
||||
let deferred = Promise.defer();
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
resolve(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_disabled_through_lists() {
|
||||
@ -411,16 +411,16 @@ add_task(async function test_disabled_through_lists() {
|
||||
let query = {sourceURI: createURI("http://example.com"),
|
||||
suggestedFileName: "noop.bat",
|
||||
fileSize: 12};
|
||||
let deferred = Promise.defer();
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
gAppRep.queryReputation(query,
|
||||
function onComplete(aShouldBlock, aStatus) {
|
||||
// We should be getting NS_ERROR_NOT_AVAILABLE if the service is disabled
|
||||
do_check_eq(Cr.NS_ERROR_NOT_AVAILABLE, aStatus);
|
||||
do_check_false(aShouldBlock);
|
||||
resolve(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
add_task(async function test_teardown() {
|
||||
gStillRunning = false;
|
||||
|
@ -21,12 +21,12 @@ add_task(async function test_watching_non_existing() {
|
||||
|
||||
// Instantiate the native watcher.
|
||||
let watcher = makeWatcher();
|
||||
let deferred = Promise.defer();
|
||||
let error = await new Promise((resolve, reject) => {
|
||||
|
||||
// Try watch a path which doesn't exist.
|
||||
watcher.addPath(notExistingDir, deferred.reject, deferred.resolve);
|
||||
// Try watch a path which doesn't exist.
|
||||
watcher.addPath(notExistingDir, reject, resolve);
|
||||
|
||||
// Wait until the watcher informs us that there was an error.
|
||||
let error = await deferred.promise;
|
||||
// Wait until the watcher informs us that there was an error.
|
||||
});
|
||||
do_check_eq(error, Components.results.NS_ERROR_FILE_NOT_FOUND);
|
||||
});
|
||||
|
@ -492,26 +492,26 @@ this.DownloadIntegration = {
|
||||
verdict: "",
|
||||
});
|
||||
}
|
||||
let deferred = Promise.defer();
|
||||
let aReferrer = null;
|
||||
if (aDownload.source.referrer) {
|
||||
aReferrer = NetUtil.newURI(aDownload.source.referrer);
|
||||
}
|
||||
gApplicationReputationService.queryReputation({
|
||||
sourceURI: NetUtil.newURI(aDownload.source.url),
|
||||
referrerURI: aReferrer,
|
||||
fileSize: aDownload.currentBytes,
|
||||
sha256Hash: hash,
|
||||
suggestedFileName: OS.Path.basename(aDownload.target.path),
|
||||
signatureInfo: sigInfo,
|
||||
redirects: channelRedirects },
|
||||
function onComplete(aShouldBlock, aRv, aVerdict) {
|
||||
deferred.resolve({
|
||||
shouldBlock: aShouldBlock,
|
||||
verdict: (aShouldBlock && kVerdictMap[aVerdict]) || "",
|
||||
return new Promise(resolve => {
|
||||
let aReferrer = null;
|
||||
if (aDownload.source.referrer) {
|
||||
aReferrer = NetUtil.newURI(aDownload.source.referrer);
|
||||
}
|
||||
gApplicationReputationService.queryReputation({
|
||||
sourceURI: NetUtil.newURI(aDownload.source.url),
|
||||
referrerURI: aReferrer,
|
||||
fileSize: aDownload.currentBytes,
|
||||
sha256Hash: hash,
|
||||
suggestedFileName: OS.Path.basename(aDownload.target.path),
|
||||
signatureInfo: sigInfo,
|
||||
redirects: channelRedirects },
|
||||
function onComplete(aShouldBlock, aRv, aVerdict) {
|
||||
resolve({
|
||||
shouldBlock: aShouldBlock,
|
||||
verdict: (aShouldBlock && kVerdictMap[aVerdict]) || "",
|
||||
});
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
@ -1635,20 +1635,20 @@ add_task(async function test_cancel_midway_restart_with_content_encoding() {
|
||||
let download = await promiseStartDownload(httpUrl("interruptible_gzip.txt"));
|
||||
|
||||
// The first time, cancel the download midway.
|
||||
let deferCancel = Promise.defer();
|
||||
let onchange = function() {
|
||||
if (!download.stopped && !download.canceled &&
|
||||
download.currentBytes == TEST_DATA_SHORT_GZIP_ENCODED_FIRST.length) {
|
||||
deferCancel.resolve(download.cancel());
|
||||
}
|
||||
};
|
||||
await new Promise(resolve => {
|
||||
let onchange = function() {
|
||||
if (!download.stopped && !download.canceled &&
|
||||
download.currentBytes == TEST_DATA_SHORT_GZIP_ENCODED_FIRST.length) {
|
||||
resolve(download.cancel());
|
||||
}
|
||||
};
|
||||
|
||||
// Register for the notification, but also call the function directly in
|
||||
// case the download already reached the expected progress.
|
||||
download.onchange = onchange;
|
||||
onchange();
|
||||
// Register for the notification, but also call the function directly in
|
||||
// case the download already reached the expected progress.
|
||||
download.onchange = onchange;
|
||||
onchange();
|
||||
|
||||
await deferCancel.promise;
|
||||
});
|
||||
|
||||
do_check_true(download.stopped);
|
||||
|
||||
|
@ -161,9 +161,9 @@ function getTempFile(aLeafName) {
|
||||
* @rejects Never.
|
||||
*/
|
||||
function promiseExecuteSoon() {
|
||||
let deferred = Promise.defer();
|
||||
do_execute_soon(deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
do_execute_soon(resolve);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,9 +174,9 @@ function promiseExecuteSoon() {
|
||||
* @rejects Never.
|
||||
*/
|
||||
function promiseTimeout(aTime) {
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(aTime, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
do_timeout(aTime, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,29 +190,29 @@ function promiseTimeout(aTime) {
|
||||
* @rejects Never.
|
||||
*/
|
||||
function promiseWaitForVisit(aUrl) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let uri = NetUtil.newURI(aUrl);
|
||||
let uri = NetUtil.newURI(aUrl);
|
||||
|
||||
PlacesUtils.history.addObserver({
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]),
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisit(aURI, aVisitID, aTime, aSessionID, aReferringID,
|
||||
aTransitionType, aGUID, aHidden) {
|
||||
if (aURI.equals(uri)) {
|
||||
PlacesUtils.history.removeObserver(this);
|
||||
resolve([aTime, aTransitionType]);
|
||||
}
|
||||
},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI() {},
|
||||
onClearHistory() {},
|
||||
onPageChanged() {},
|
||||
onDeleteVisits() {},
|
||||
});
|
||||
|
||||
PlacesUtils.history.addObserver({
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]),
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisit(aURI, aVisitID, aTime, aSessionID, aReferringID,
|
||||
aTransitionType, aGUID, aHidden) {
|
||||
if (aURI.equals(uri)) {
|
||||
PlacesUtils.history.removeObserver(this);
|
||||
deferred.resolve([aTime, aTransitionType]);
|
||||
}
|
||||
},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI() {},
|
||||
onClearHistory() {},
|
||||
onPageChanged() {},
|
||||
onDeleteVisits() {},
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,14 +226,14 @@ function promiseWaitForVisit(aUrl) {
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseIsURIVisited(aUrl) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
PlacesUtils.asyncHistory.isURIVisited(NetUtil.newURI(aUrl),
|
||||
function(aURI, aIsVisited) {
|
||||
deferred.resolve(aIsVisited);
|
||||
});
|
||||
PlacesUtils.asyncHistory.isURIVisited(NetUtil.newURI(aUrl),
|
||||
function(aURI, aIsVisited) {
|
||||
resolve(aIsVisited);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,39 +329,39 @@ function promiseStartLegacyDownload(aSourceUrl, aOptions) {
|
||||
|
||||
let transfer = Cc["@mozilla.org/transfer;1"].createInstance(Ci.nsITransfer);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
Downloads.getList(Downloads.ALL).then(function(aList) {
|
||||
// Temporarily register a view that will get notified when the download we
|
||||
// are controlling becomes visible in the list of downloads.
|
||||
aList.addView({
|
||||
onDownloadAdded(aDownload) {
|
||||
aList.removeView(this).then(null, do_report_unexpected_exception);
|
||||
Downloads.getList(Downloads.ALL).then(function(aList) {
|
||||
// Temporarily register a view that will get notified when the download we
|
||||
// are controlling becomes visible in the list of downloads.
|
||||
aList.addView({
|
||||
onDownloadAdded(aDownload) {
|
||||
aList.removeView(this).then(null, do_report_unexpected_exception);
|
||||
|
||||
// Remove the download to keep the list empty for the next test. This
|
||||
// also allows the caller to register the "onchange" event directly.
|
||||
let promise = aList.remove(aDownload);
|
||||
// Remove the download to keep the list empty for the next test. This
|
||||
// also allows the caller to register the "onchange" event directly.
|
||||
let promise = aList.remove(aDownload);
|
||||
|
||||
// When the download object is ready, make it available to the caller.
|
||||
promise.then(() => deferred.resolve(aDownload),
|
||||
do_report_unexpected_exception);
|
||||
},
|
||||
// When the download object is ready, make it available to the caller.
|
||||
promise.then(() => resolve(aDownload),
|
||||
do_report_unexpected_exception);
|
||||
},
|
||||
}).then(null, do_report_unexpected_exception);
|
||||
|
||||
let isPrivate = aOptions && aOptions.isPrivate;
|
||||
|
||||
// Initialize the components so they reference each other. This will cause
|
||||
// the Download object to be created and added to the public downloads.
|
||||
transfer.init(sourceURI, NetUtil.newURI(targetFile), null, mimeInfo, null,
|
||||
null, persist, isPrivate);
|
||||
persist.progressListener = transfer;
|
||||
|
||||
// Start the actual download process.
|
||||
persist.savePrivacyAwareURI(sourceURI, null, null, 0, null, null, targetFile,
|
||||
isPrivate);
|
||||
}).then(null, do_report_unexpected_exception);
|
||||
|
||||
let isPrivate = aOptions && aOptions.isPrivate;
|
||||
|
||||
// Initialize the components so they reference each other. This will cause
|
||||
// the Download object to be created and added to the public downloads.
|
||||
transfer.init(sourceURI, NetUtil.newURI(targetFile), null, mimeInfo, null,
|
||||
null, persist, isPrivate);
|
||||
persist.progressListener = transfer;
|
||||
|
||||
// Start the actual download process.
|
||||
persist.savePrivacyAwareURI(sourceURI, null, null, 0, null, null, targetFile,
|
||||
isPrivate);
|
||||
}).then(null, do_report_unexpected_exception);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -382,54 +382,54 @@ function promiseStartExternalHelperAppServiceDownload(aSourceUrl) {
|
||||
let sourceURI = NetUtil.newURI(aSourceUrl ||
|
||||
httpUrl("interruptible_resumable.txt"));
|
||||
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
Downloads.getList(Downloads.PUBLIC).then(function(aList) {
|
||||
// Temporarily register a view that will get notified when the download we
|
||||
// are controlling becomes visible in the list of downloads.
|
||||
aList.addView({
|
||||
onDownloadAdded(aDownload) {
|
||||
aList.removeView(this).then(null, do_report_unexpected_exception);
|
||||
Downloads.getList(Downloads.PUBLIC).then(function(aList) {
|
||||
// Temporarily register a view that will get notified when the download we
|
||||
// are controlling becomes visible in the list of downloads.
|
||||
aList.addView({
|
||||
onDownloadAdded(aDownload) {
|
||||
aList.removeView(this).then(null, do_report_unexpected_exception);
|
||||
|
||||
// Remove the download to keep the list empty for the next test. This
|
||||
// also allows the caller to register the "onchange" event directly.
|
||||
let promise = aList.remove(aDownload);
|
||||
// Remove the download to keep the list empty for the next test. This
|
||||
// also allows the caller to register the "onchange" event directly.
|
||||
let promise = aList.remove(aDownload);
|
||||
|
||||
// When the download object is ready, make it available to the caller.
|
||||
promise.then(() => deferred.resolve(aDownload),
|
||||
do_report_unexpected_exception);
|
||||
},
|
||||
// When the download object is ready, make it available to the caller.
|
||||
promise.then(() => resolve(aDownload),
|
||||
do_report_unexpected_exception);
|
||||
},
|
||||
}).then(null, do_report_unexpected_exception);
|
||||
|
||||
let channel = NetUtil.newChannel({
|
||||
uri: sourceURI,
|
||||
loadUsingSystemPrincipal: true
|
||||
});
|
||||
|
||||
// Start the actual download process.
|
||||
channel.asyncOpen2({
|
||||
contentListener: null,
|
||||
|
||||
onStartRequest(aRequest, aContext) {
|
||||
let requestChannel = aRequest.QueryInterface(Ci.nsIChannel);
|
||||
this.contentListener = gExternalHelperAppService.doContent(
|
||||
requestChannel.contentType, aRequest, null, true);
|
||||
this.contentListener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
this.contentListener.onStopRequest(aRequest, aContext, aStatusCode);
|
||||
},
|
||||
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset,
|
||||
aCount) {
|
||||
this.contentListener.onDataAvailable(aRequest, aContext, aInputStream,
|
||||
aOffset, aCount);
|
||||
},
|
||||
});
|
||||
}).then(null, do_report_unexpected_exception);
|
||||
|
||||
let channel = NetUtil.newChannel({
|
||||
uri: sourceURI,
|
||||
loadUsingSystemPrincipal: true
|
||||
});
|
||||
|
||||
// Start the actual download process.
|
||||
channel.asyncOpen2({
|
||||
contentListener: null,
|
||||
|
||||
onStartRequest(aRequest, aContext) {
|
||||
let requestChannel = aRequest.QueryInterface(Ci.nsIChannel);
|
||||
this.contentListener = gExternalHelperAppService.doContent(
|
||||
requestChannel.contentType, aRequest, null, true);
|
||||
this.contentListener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
this.contentListener.onStopRequest(aRequest, aContext, aStatusCode);
|
||||
},
|
||||
|
||||
onDataAvailable(aRequest, aContext, aInputStream, aOffset,
|
||||
aCount) {
|
||||
this.contentListener.onDataAvailable(aRequest, aContext, aInputStream,
|
||||
aOffset, aCount);
|
||||
},
|
||||
});
|
||||
}).then(null, do_report_unexpected_exception);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,22 +444,22 @@ function promiseStartExternalHelperAppServiceDownload(aSourceUrl) {
|
||||
* @rejects Never.
|
||||
*/
|
||||
function promiseDownloadMidway(aDownload) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
// Wait for the download to reach half of its progress.
|
||||
let onchange = function() {
|
||||
if (!aDownload.stopped && !aDownload.canceled && aDownload.progress == 50) {
|
||||
aDownload.onchange = null;
|
||||
deferred.resolve();
|
||||
}
|
||||
};
|
||||
// Wait for the download to reach half of its progress.
|
||||
let onchange = function() {
|
||||
if (!aDownload.stopped && !aDownload.canceled && aDownload.progress == 50) {
|
||||
aDownload.onchange = null;
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
// Register for the notification, but also call the function directly in
|
||||
// case the download already reached the expected progress.
|
||||
aDownload.onchange = onchange;
|
||||
onchange();
|
||||
// Register for the notification, but also call the function directly in
|
||||
// case the download already reached the expected progress.
|
||||
aDownload.onchange = onchange;
|
||||
onchange();
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -532,26 +532,26 @@ function promiseVerifyContents(aPath, aExpectedContents) {
|
||||
do_throw("File is empty: " + aPath);
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
NetUtil.asyncFetch(
|
||||
{ uri: NetUtil.newURI(file), loadUsingSystemPrincipal: true },
|
||||
function(aInputStream, aStatus) {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
let contents = NetUtil.readInputStreamToString(aInputStream,
|
||||
aInputStream.available());
|
||||
if (contents.length > TEST_DATA_SHORT.length * 2 ||
|
||||
/[^\x20-\x7E]/.test(contents)) {
|
||||
// Do not print the entire content string to the test log.
|
||||
do_check_eq(contents.length, aExpectedContents.length);
|
||||
do_check_true(contents == aExpectedContents);
|
||||
} else {
|
||||
// Print the string if it is short and made of printable characters.
|
||||
do_check_eq(contents, aExpectedContents);
|
||||
}
|
||||
deferred.resolve();
|
||||
});
|
||||
await new Promise(resolve => {
|
||||
NetUtil.asyncFetch(
|
||||
{ uri: NetUtil.newURI(file), loadUsingSystemPrincipal: true },
|
||||
function(aInputStream, aStatus) {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
let contents = NetUtil.readInputStreamToString(aInputStream,
|
||||
aInputStream.available());
|
||||
if (contents.length > TEST_DATA_SHORT.length * 2 ||
|
||||
/[^\x20-\x7E]/.test(contents)) {
|
||||
// Do not print the entire content string to the test log.
|
||||
do_check_eq(contents.length, aExpectedContents.length);
|
||||
do_check_true(contents == aExpectedContents);
|
||||
} else {
|
||||
// Print the string if it is short and made of printable characters.
|
||||
do_check_eq(contents, aExpectedContents);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
|
||||
await deferred.promise;
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
|
@ -161,33 +161,33 @@ function promiseTableCount(aConnection) {
|
||||
* @rejects When there's a problem accessing the URL.
|
||||
*/
|
||||
function promiseEntityID(aUrl) {
|
||||
let deferred = Promise.defer();
|
||||
let entityID = "";
|
||||
let channel = NetUtil.newChannel({
|
||||
uri: NetUtil.newURI(aUrl),
|
||||
loadUsingSystemPrincipal: true
|
||||
return new Promise((resolve, reject) => {
|
||||
let entityID = "";
|
||||
let channel = NetUtil.newChannel({
|
||||
uri: NetUtil.newURI(aUrl),
|
||||
loadUsingSystemPrincipal: true
|
||||
});
|
||||
|
||||
channel.asyncOpen2({
|
||||
onStartRequest(aRequest) {
|
||||
if (aRequest instanceof Ci.nsIResumableChannel) {
|
||||
entityID = aRequest.entityID;
|
||||
}
|
||||
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
},
|
||||
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
if (aStatusCode == Cr.NS_BINDING_ABORTED) {
|
||||
resolve(entityID);
|
||||
} else {
|
||||
reject("Unexpected status code received");
|
||||
}
|
||||
},
|
||||
|
||||
onDataAvailable() {}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
channel.asyncOpen2({
|
||||
onStartRequest(aRequest) {
|
||||
if (aRequest instanceof Ci.nsIResumableChannel) {
|
||||
entityID = aRequest.entityID;
|
||||
}
|
||||
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
},
|
||||
|
||||
onStopRequest(aRequest, aContext, aStatusCode) {
|
||||
if (aStatusCode == Cr.NS_BINDING_ABORTED) {
|
||||
deferred.resolve(entityID);
|
||||
} else {
|
||||
deferred.reject("Unexpected status code received");
|
||||
}
|
||||
},
|
||||
|
||||
onDataAvailable() {}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,27 +39,27 @@ function getExpirablePRTime() {
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseExpirableDownloadVisit(aSourceUrl) {
|
||||
let deferred = Promise.defer();
|
||||
PlacesUtils.asyncHistory.updatePlaces(
|
||||
{
|
||||
uri: NetUtil.newURI(aSourceUrl || httpUrl("source.txt")),
|
||||
visits: [{
|
||||
transitionType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD,
|
||||
visitDate: getExpirablePRTime(),
|
||||
}]
|
||||
},
|
||||
{
|
||||
handleError: function handleError(aResultCode, aPlaceInfo) {
|
||||
let ex = new Components.Exception("Unexpected error in adding visits.",
|
||||
aResultCode);
|
||||
deferred.reject(ex);
|
||||
return new Promise((resolve, reject) => {
|
||||
PlacesUtils.asyncHistory.updatePlaces(
|
||||
{
|
||||
uri: NetUtil.newURI(aSourceUrl || httpUrl("source.txt")),
|
||||
visits: [{
|
||||
transitionType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD,
|
||||
visitDate: getExpirablePRTime(),
|
||||
}]
|
||||
},
|
||||
handleResult() {},
|
||||
handleCompletion: function handleCompletion() {
|
||||
deferred.resolve();
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
{
|
||||
handleError: function handleError(aResultCode, aPlaceInfo) {
|
||||
let ex = new Components.Exception("Unexpected error in adding visits.",
|
||||
aResultCode);
|
||||
reject(ex);
|
||||
},
|
||||
handleResult() {},
|
||||
handleCompletion: function handleCompletion() {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Tests
|
||||
|
@ -13,31 +13,31 @@ function run_test() {
|
||||
|
||||
add_task(function() {
|
||||
let worker = new ChromeWorker(WORKER_SOURCE_URI);
|
||||
let deferred = Promise.defer();
|
||||
worker.onmessage = function(event) {
|
||||
let data = event.data;
|
||||
switch (data.kind) {
|
||||
case "do_check_true":
|
||||
try {
|
||||
do_check_true(data.args[0]);
|
||||
} catch (ex) {
|
||||
// Ignore errors
|
||||
}
|
||||
return;
|
||||
case "do_test_complete":
|
||||
deferred.resolve();
|
||||
worker.terminate();
|
||||
break;
|
||||
case "do_print":
|
||||
do_print(data.args[0]);
|
||||
}
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
deferred.reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
worker.onmessage = function(event) {
|
||||
let data = event.data;
|
||||
switch (data.kind) {
|
||||
case "do_check_true":
|
||||
try {
|
||||
do_check_true(data.args[0]);
|
||||
} catch (ex) {
|
||||
// Ignore errors
|
||||
}
|
||||
return;
|
||||
case "do_test_complete":
|
||||
resolve();
|
||||
worker.terminate();
|
||||
break;
|
||||
case "do_print":
|
||||
do_print(data.args[0]);
|
||||
}
|
||||
};
|
||||
worker.onerror = function(event) {
|
||||
let error = new Error(event.message, event.filename, event.lineno);
|
||||
worker.terminate();
|
||||
reject(error);
|
||||
};
|
||||
worker.postMessage("START");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,21 +50,21 @@ this.read = function(path, options = {}) {
|
||||
return Promise.reject(new TypeError("Invalid type for option bytes"));
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
Internals.read(path,
|
||||
options,
|
||||
function onSuccess(success) {
|
||||
success.QueryInterface(Ci.nsINativeOSFileResult);
|
||||
if ("outExecutionDuration" in options) {
|
||||
options.outExecutionDuration =
|
||||
success.executionDurationMS +
|
||||
(options.outExecutionDuration || 0);
|
||||
return new Promise((resolve, reject) => {
|
||||
Internals.read(path,
|
||||
options,
|
||||
function onSuccess(success) {
|
||||
success.QueryInterface(Ci.nsINativeOSFileResult);
|
||||
if ("outExecutionDuration" in options) {
|
||||
options.outExecutionDuration =
|
||||
success.executionDurationMS +
|
||||
(options.outExecutionDuration || 0);
|
||||
}
|
||||
resolve(success.result);
|
||||
},
|
||||
function onError(operation, oserror) {
|
||||
reject(new SysAll.Error(operation, oserror, path));
|
||||
}
|
||||
deferred.resolve(success.result);
|
||||
},
|
||||
function onError(operation, oserror) {
|
||||
deferred.reject(new SysAll.Error(operation, oserror, path));
|
||||
}
|
||||
);
|
||||
return deferred.promise;
|
||||
);
|
||||
});
|
||||
};
|
||||
|
@ -86,31 +86,31 @@ var maketest = function(prefix, test) {
|
||||
*/
|
||||
var reference_fetch_file = function reference_fetch_file(path, test) {
|
||||
test.info("Fetching file " + path);
|
||||
let promise = Promise.defer();
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
promise.reject(status);
|
||||
return;
|
||||
}
|
||||
let result, reject;
|
||||
try {
|
||||
result = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
} catch (x) {
|
||||
reject = x;
|
||||
}
|
||||
stream.close();
|
||||
if (reject) {
|
||||
promise.reject(reject);
|
||||
} else {
|
||||
promise.resolve(result);
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
reject(status);
|
||||
return;
|
||||
}
|
||||
let result, reject;
|
||||
try {
|
||||
result = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
} catch (x) {
|
||||
reject = x;
|
||||
}
|
||||
stream.close();
|
||||
if (reject) {
|
||||
reject(reject);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
|
||||
return promise.promise;
|
||||
});
|
||||
};
|
||||
|
||||
var reference_dir_contents = function reference_dir_contents(path) {
|
||||
|
@ -51,31 +51,31 @@ function add_test_pair(generator) {
|
||||
*/
|
||||
function reference_fetch_file(path, test) {
|
||||
do_print("Fetching file " + path);
|
||||
let deferred = Promise.defer();
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
deferred.reject(status);
|
||||
return;
|
||||
}
|
||||
let result, reject;
|
||||
try {
|
||||
result = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
} catch (x) {
|
||||
reject = x;
|
||||
}
|
||||
stream.close();
|
||||
if (reject) {
|
||||
deferred.reject(reject);
|
||||
} else {
|
||||
deferred.resolve(result);
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
reject(status);
|
||||
return;
|
||||
}
|
||||
let result, reject;
|
||||
try {
|
||||
result = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
} catch (x) {
|
||||
reject = x;
|
||||
}
|
||||
stream.close();
|
||||
if (reject) {
|
||||
reject(reject);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -26,31 +26,31 @@ var EXISTING_FILE = "test_osfile_async_copy.js";
|
||||
* @resolves {string} The contents of the file.
|
||||
*/
|
||||
var reference_fetch_file = function reference_fetch_file(path) {
|
||||
let promise = Promise.defer();
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
promise.reject(status);
|
||||
return;
|
||||
}
|
||||
let result, reject;
|
||||
try {
|
||||
result = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
} catch (x) {
|
||||
reject = x;
|
||||
}
|
||||
stream.close();
|
||||
if (reject) {
|
||||
promise.reject(reject);
|
||||
} else {
|
||||
promise.resolve(result);
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
reject(status);
|
||||
return;
|
||||
}
|
||||
let result, reject;
|
||||
try {
|
||||
result = NetUtil.readInputStreamToString(stream, stream.available());
|
||||
} catch (x) {
|
||||
reject = x;
|
||||
}
|
||||
stream.close();
|
||||
if (reject) {
|
||||
reject(reject);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
|
||||
return promise.promise;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1604,23 +1604,23 @@ this.PlacesUtils = {
|
||||
* @return {Promise}
|
||||
*/
|
||||
setCharsetForURI: function PU_setCharsetForURI(aURI, aCharset) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
// Delaying to catch issues with asynchronous behavior while waiting
|
||||
// to implement asynchronous annotations in bug 699844.
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
if (aCharset && aCharset.length > 0) {
|
||||
PlacesUtils.annotations.setPageAnnotation(
|
||||
aURI, PlacesUtils.CHARSET_ANNO, aCharset, 0,
|
||||
Ci.nsIAnnotationService.EXPIRE_NEVER);
|
||||
} else {
|
||||
PlacesUtils.annotations.removePageAnnotation(
|
||||
aURI, PlacesUtils.CHARSET_ANNO);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
|
||||
// Delaying to catch issues with asynchronous behavior while waiting
|
||||
// to implement asynchronous annotations in bug 699844.
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
if (aCharset && aCharset.length > 0) {
|
||||
PlacesUtils.annotations.setPageAnnotation(
|
||||
aURI, PlacesUtils.CHARSET_ANNO, aCharset, 0,
|
||||
Ci.nsIAnnotationService.EXPIRE_NEVER);
|
||||
} else {
|
||||
PlacesUtils.annotations.removePageAnnotation(
|
||||
aURI, PlacesUtils.CHARSET_ANNO);
|
||||
}
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1631,20 +1631,20 @@ this.PlacesUtils = {
|
||||
* @resolve a character-set or null.
|
||||
*/
|
||||
getCharsetForURI: function PU_getCharsetForURI(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
let charset = null;
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
let charset = null;
|
||||
|
||||
try {
|
||||
charset = PlacesUtils.annotations.getPageAnnotation(aURI,
|
||||
PlacesUtils.CHARSET_ANNO);
|
||||
} catch (ex) { }
|
||||
try {
|
||||
charset = PlacesUtils.annotations.getPageAnnotation(aURI,
|
||||
PlacesUtils.CHARSET_ANNO);
|
||||
} catch (ex) { }
|
||||
|
||||
resolve(charset);
|
||||
});
|
||||
|
||||
deferred.resolve(charset);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1655,21 +1655,21 @@ this.PlacesUtils = {
|
||||
* @resolves to the place info object handed to handleResult.
|
||||
*/
|
||||
promisePlaceInfo: function PU_promisePlaceInfo(aPlaceIdentifier) {
|
||||
let deferred = Promise.defer();
|
||||
PlacesUtils.asyncHistory.getPlacesInfo(aPlaceIdentifier, {
|
||||
_placeInfo: null,
|
||||
handleResult: function handleResult(aPlaceInfo) {
|
||||
this._placeInfo = aPlaceInfo;
|
||||
},
|
||||
handleError: function handleError(aResultCode, aPlaceInfo) {
|
||||
deferred.reject(new Components.Exception("Error", aResultCode));
|
||||
},
|
||||
handleCompletion() {
|
||||
deferred.resolve(this._placeInfo);
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
PlacesUtils.asyncHistory.getPlacesInfo(aPlaceIdentifier, {
|
||||
_placeInfo: null,
|
||||
handleResult: function handleResult(aPlaceInfo) {
|
||||
this._placeInfo = aPlaceInfo;
|
||||
},
|
||||
handleError: function handleError(aResultCode, aPlaceInfo) {
|
||||
reject(new Components.Exception("Error", aResultCode));
|
||||
},
|
||||
handleCompletion() {
|
||||
resolve(this._placeInfo);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1681,19 +1681,19 @@ this.PlacesUtils = {
|
||||
* @rejects JavaScript exception if the given url has no associated favicon.
|
||||
*/
|
||||
promiseFaviconData(aPageUrl) {
|
||||
let deferred = Promise.defer();
|
||||
PlacesUtils.favicons.getFaviconDataForPage(NetUtil.newURI(aPageUrl),
|
||||
function(aURI, aDataLen, aData, aMimeType) {
|
||||
if (aURI) {
|
||||
deferred.resolve({ uri: aURI,
|
||||
dataLen: aDataLen,
|
||||
data: aData,
|
||||
mimeType: aMimeType });
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
PlacesUtils.favicons.getFaviconDataForPage(NetUtil.newURI(aPageUrl),
|
||||
function(aURI, aDataLen, aData, aMimeType) {
|
||||
if (aURI) {
|
||||
resolve({ uri: aURI,
|
||||
dataLen: aDataLen,
|
||||
data: aData,
|
||||
mimeType: aMimeType });
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1704,19 +1704,19 @@ this.PlacesUtils = {
|
||||
* @rejects if the given url has no associated favicon.
|
||||
*/
|
||||
promiseFaviconLinkUrl(aPageUrl) {
|
||||
let deferred = Promise.defer();
|
||||
if (!(aPageUrl instanceof Ci.nsIURI))
|
||||
aPageUrl = NetUtil.newURI(aPageUrl);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!(aPageUrl instanceof Ci.nsIURI))
|
||||
aPageUrl = NetUtil.newURI(aPageUrl);
|
||||
|
||||
PlacesUtils.favicons.getFaviconURLForPage(aPageUrl, uri => {
|
||||
if (uri) {
|
||||
uri = PlacesUtils.favicons.getFaviconLinkForIcon(uri);
|
||||
deferred.resolve(uri);
|
||||
} else {
|
||||
deferred.reject("favicon not found for uri");
|
||||
}
|
||||
PlacesUtils.favicons.getFaviconURLForPage(aPageUrl, uri => {
|
||||
if (uri) {
|
||||
uri = PlacesUtils.favicons.getFaviconLinkForIcon(uri);
|
||||
resolve(uri);
|
||||
} else {
|
||||
reject("favicon not found for uri");
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -67,18 +67,18 @@ add_task(async function maintenance_foreign_count_test() {
|
||||
await PlacesTestUtils.addVisits(T_URI);
|
||||
|
||||
// Adjust the foreign_count for the added entry to an incorrect value
|
||||
let deferred = Promise.defer();
|
||||
let stmt = DBConn().createAsyncStatement(
|
||||
`UPDATE moz_places SET foreign_count = 10 WHERE url_hash = hash(:t_url)
|
||||
AND url = :t_url `);
|
||||
stmt.params.t_url = T_URI.spec;
|
||||
stmt.executeAsync({
|
||||
handleCompletion() {
|
||||
deferred.resolve();
|
||||
}
|
||||
await new Promise(resolve => {
|
||||
let stmt = DBConn().createAsyncStatement(
|
||||
`UPDATE moz_places SET foreign_count = 10 WHERE url_hash = hash(:t_url)
|
||||
AND url = :t_url `);
|
||||
stmt.params.t_url = T_URI.spec;
|
||||
stmt.executeAsync({
|
||||
handleCompletion() {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
stmt.finalize();
|
||||
});
|
||||
stmt.finalize();
|
||||
await deferred.promise;
|
||||
Assert.equal((await getForeignCountForURL(conn, T_URI)), 10);
|
||||
|
||||
// Run maintenance
|
||||
|
@ -72,24 +72,24 @@ add_task(async function test_add_visit() {
|
||||
|
||||
// Add a visit to the bookmark and wait for the observer.
|
||||
let visitId;
|
||||
let deferUpdatePlaces = Promise.defer();
|
||||
PlacesUtils.asyncHistory.updatePlaces({
|
||||
uri: NetUtil.newURI("http://book.ma.rk/"),
|
||||
visits: [{ transitionType: TRANSITION_TYPED, visitDate: NOW }]
|
||||
}, {
|
||||
handleError: function TAV_handleError() {
|
||||
deferUpdatePlaces.reject(new Error("Unexpected error in adding visit."));
|
||||
},
|
||||
handleResult(aPlaceInfo) {
|
||||
visitId = aPlaceInfo.visits[0].visitId;
|
||||
},
|
||||
handleCompletion: function TAV_handleCompletion() {
|
||||
deferUpdatePlaces.resolve();
|
||||
}
|
||||
});
|
||||
await new Promise((resolve, reject) => {
|
||||
PlacesUtils.asyncHistory.updatePlaces({
|
||||
uri: NetUtil.newURI("http://book.ma.rk/"),
|
||||
visits: [{ transitionType: TRANSITION_TYPED, visitDate: NOW }]
|
||||
}, {
|
||||
handleError: function TAV_handleError() {
|
||||
reject(new Error("Unexpected error in adding visit."));
|
||||
},
|
||||
handleResult(aPlaceInfo) {
|
||||
visitId = aPlaceInfo.visits[0].visitId;
|
||||
},
|
||||
handleCompletion: function TAV_handleCompletion() {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for both the observer and the asynchronous update, in any order.
|
||||
await deferUpdatePlaces.promise;
|
||||
// Wait for both the observer and the asynchronous update, in any order.
|
||||
});
|
||||
await observerPromise;
|
||||
|
||||
// Check that both asynchronous results are consistent.
|
||||
@ -127,24 +127,24 @@ add_task(async function shutdown() {
|
||||
// places-connection-closed.
|
||||
// Notice this code is not using helpers cause it depends on a very specific
|
||||
// order, a change in the helpers code could make this test useless.
|
||||
let deferred = Promise.defer();
|
||||
await new Promise(resolve => {
|
||||
|
||||
Services.obs.addObserver(function onNotification() {
|
||||
Services.obs.removeObserver(onNotification, "places-will-close-connection");
|
||||
do_check_true(true, "Observed fake places shutdown");
|
||||
Services.obs.addObserver(function onNotification() {
|
||||
Services.obs.removeObserver(onNotification, "places-will-close-connection");
|
||||
do_check_true(true, "Observed fake places shutdown");
|
||||
|
||||
Services.tm.dispatchToMainThread(() => {
|
||||
// WARNING: this is very bad, never use out of testing code.
|
||||
PlacesUtils.bookmarks.QueryInterface(Ci.nsINavHistoryObserver)
|
||||
.onPageChanged(NetUtil.newURI("http://book.ma.rk/"),
|
||||
Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON,
|
||||
"test", "test");
|
||||
deferred.resolve(promiseTopicObserved("places-connection-closed"));
|
||||
});
|
||||
}, "places-will-close-connection");
|
||||
shutdownPlaces();
|
||||
Services.tm.dispatchToMainThread(() => {
|
||||
// WARNING: this is very bad, never use out of testing code.
|
||||
PlacesUtils.bookmarks.QueryInterface(Ci.nsINavHistoryObserver)
|
||||
.onPageChanged(NetUtil.newURI("http://book.ma.rk/"),
|
||||
Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON,
|
||||
"test", "test");
|
||||
resolve(promiseTopicObserved("places-connection-closed"));
|
||||
});
|
||||
}, "places-will-close-connection");
|
||||
shutdownPlaces();
|
||||
|
||||
await deferred.promise;
|
||||
});
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
|
@ -53,31 +53,31 @@ add_task(async function test_annos_expire_session() {
|
||||
items = as.getItemsWithAnnotation("test2");
|
||||
do_check_eq(items.length, 10);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
waitForConnectionClosed(function() {
|
||||
let stmt = DBConn(true).createAsyncStatement(
|
||||
`SELECT id FROM moz_annos
|
||||
UNION ALL
|
||||
SELECT id FROM moz_items_annos
|
||||
WHERE expiration = :expiration`
|
||||
);
|
||||
stmt.params.expiration = as.EXPIRE_SESSION;
|
||||
stmt.executeAsync({
|
||||
handleResult(aResultSet) {
|
||||
dump_table("moz_annos");
|
||||
dump_table("moz_items_annos");
|
||||
do_throw("Should not find any leftover session annotations");
|
||||
},
|
||||
handleError(aError) {
|
||||
do_throw("Error code " + aError.result + " with message '" +
|
||||
aError.message + "' returned.");
|
||||
},
|
||||
handleCompletion(aReason) {
|
||||
do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
|
||||
deferred.resolve();
|
||||
}
|
||||
await new Promise(resolve => {
|
||||
waitForConnectionClosed(function() {
|
||||
let stmt = DBConn(true).createAsyncStatement(
|
||||
`SELECT id FROM moz_annos
|
||||
UNION ALL
|
||||
SELECT id FROM moz_items_annos
|
||||
WHERE expiration = :expiration`
|
||||
);
|
||||
stmt.params.expiration = as.EXPIRE_SESSION;
|
||||
stmt.executeAsync({
|
||||
handleResult(aResultSet) {
|
||||
dump_table("moz_annos");
|
||||
dump_table("moz_items_annos");
|
||||
do_throw("Should not find any leftover session annotations");
|
||||
},
|
||||
handleError(aError) {
|
||||
do_throw("Error code " + aError.result + " with message '" +
|
||||
aError.message + "' returned.");
|
||||
},
|
||||
handleCompletion(aReason) {
|
||||
do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
stmt.finalize();
|
||||
});
|
||||
stmt.finalize();
|
||||
});
|
||||
await deferred.promise;
|
||||
});
|
||||
|
@ -69,20 +69,20 @@ add_task(async function test_replaceFaviconData_validHistoryURI() {
|
||||
iconsvc.replaceFaviconData(favicon.uri, favicon.data, favicon.data.length,
|
||||
favicon.mimetype);
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_validHistoryURI_check(aURI, aDataLen, aData, aMimeType) {
|
||||
dump("GOT " + aMimeType + "\n");
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconData_validHistoryURI_callback() {
|
||||
favicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, systemPrincipal);
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_validHistoryURI_check(aURI, aDataLen, aData, aMimeType) {
|
||||
dump("GOT " + aMimeType + "\n");
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconData_validHistoryURI_callback() {
|
||||
favicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, systemPrincipal);
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -100,21 +100,21 @@ add_task(async function test_replaceFaviconData_overrideDefaultFavicon() {
|
||||
firstFavicon.uri, secondFavicon.data, secondFavicon.data.length,
|
||||
secondFavicon.mimetype);
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, systemPrincipal);
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, systemPrincipal);
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -128,30 +128,30 @@ add_task(async function test_replaceFaviconData_replaceExisting() {
|
||||
let firstFavicon = createFavicon("favicon4.png");
|
||||
let secondFavicon = createFavicon("favicon5.png");
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_replaceExisting_firstSet_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, firstFavicon.mimetype, firstFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, firstFavicon.mimetype, firstFavicon.data,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_firstCallback() {
|
||||
iconsvc.replaceFaviconData(
|
||||
firstFavicon.uri, secondFavicon.data, secondFavicon.data.length,
|
||||
secondFavicon.mimetype);
|
||||
PlacesTestUtils.promiseAsyncUpdates().then(() => {
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_secondCallback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
}, systemPrincipal);
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_replaceExisting_firstSet_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, firstFavicon.mimetype, firstFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, firstFavicon.mimetype, firstFavicon.data,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_firstCallback() {
|
||||
iconsvc.replaceFaviconData(
|
||||
firstFavicon.uri, secondFavicon.data, secondFavicon.data.length,
|
||||
secondFavicon.mimetype);
|
||||
PlacesTestUtils.promiseAsyncUpdates().then(() => {
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconData_overrideDefaultFavicon_secondCallback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
}, systemPrincipal);
|
||||
});
|
||||
});
|
||||
});
|
||||
}, systemPrincipal);
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
}, systemPrincipal);
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -169,21 +169,21 @@ add_task(async function test_replaceFaviconData_unrelatedReplace() {
|
||||
unrelatedFavicon.uri, unrelatedFavicon.data, unrelatedFavicon.data.length,
|
||||
unrelatedFavicon.mimetype);
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_unrelatedReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconData_unrelatedReplace_callback() {
|
||||
favicon.file.remove(false);
|
||||
unrelatedFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, systemPrincipal);
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_unrelatedReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconData_unrelatedReplace_callback() {
|
||||
favicon.file.remove(false);
|
||||
unrelatedFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, systemPrincipal);
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -225,21 +225,21 @@ add_task(async function test_replaceFaviconData_twiceReplace() {
|
||||
firstFavicon.uri, secondFavicon.data, secondFavicon.data.length,
|
||||
secondFavicon.mimetype);
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_twiceReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconData_twiceReplace_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
}, systemPrincipal);
|
||||
}, systemPrincipal);
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconData_twiceReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconData_twiceReplace_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
}, systemPrincipal);
|
||||
}, systemPrincipal);
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
|
@ -72,19 +72,19 @@ add_task(async function test_replaceFaviconDataFromDataURL_validHistoryURI() {
|
||||
iconsvc.replaceFaviconDataFromDataURL(favicon.uri, createDataURLForFavicon(favicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_validHistoryURI_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_validHistoryURI_callback() {
|
||||
favicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_validHistoryURI_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_validHistoryURI_callback() {
|
||||
favicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -101,21 +101,21 @@ add_task(async function test_replaceFaviconDataFromDataURL_overrideDefaultFavico
|
||||
iconsvc.replaceFaviconDataFromDataURL(firstFavicon.uri, createDataURLForFavicon(secondFavicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_overrideDefaultFavicon_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -129,27 +129,27 @@ add_task(async function test_replaceFaviconDataFromDataURL_replaceExisting() {
|
||||
let firstFavicon = createFavicon("favicon4.png");
|
||||
let secondFavicon = createFavicon("favicon5.png");
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_replaceExisting_firstSet_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, firstFavicon.mimetype, firstFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, firstFavicon.mimetype, firstFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_replaceExisting_firstCallback() {
|
||||
iconsvc.replaceFaviconDataFromDataURL(firstFavicon.uri, createDataURLForFavicon(secondFavicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_replaceExisting_secondCallback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_replaceExisting_firstSet_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, firstFavicon.mimetype, firstFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, firstFavicon.mimetype, firstFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_replaceExisting_firstCallback() {
|
||||
iconsvc.replaceFaviconDataFromDataURL(firstFavicon.uri, createDataURLForFavicon(secondFavicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_replaceExisting_secondCallback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -166,21 +166,21 @@ add_task(async function test_replaceFaviconDataFromDataURL_unrelatedReplace() {
|
||||
iconsvc.replaceFaviconDataFromDataURL(unrelatedFavicon.uri, createDataURLForFavicon(unrelatedFavicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_unrelatedReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_unrelatedReplace_callback() {
|
||||
favicon.file.remove(false);
|
||||
unrelatedFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, favicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_unrelatedReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, favicon.mimetype, favicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, favicon.mimetype, favicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_unrelatedReplace_callback() {
|
||||
favicon.file.remove(false);
|
||||
unrelatedFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -229,21 +229,21 @@ add_task(async function test_replaceFaviconDataFromDataURL_twiceReplace() {
|
||||
iconsvc.replaceFaviconDataFromDataURL(firstFavicon.uri, createDataURLForFavicon(secondFavicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_twiceReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_twiceReplace_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_twiceReplace_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_twiceReplace_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -263,21 +263,21 @@ add_task(async function test_replaceFaviconDataFromDataURL_afterRegularAssign()
|
||||
iconsvc.replaceFaviconDataFromDataURL(firstFavicon.uri, createDataURLForFavicon(secondFavicon), 0,
|
||||
Services.scriptSecurityManager.getSystemPrincipal());
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_afterRegularAssign_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_afterRegularAssign_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_afterRegularAssign_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_afterRegularAssign_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
@ -297,21 +297,21 @@ add_task(async function test_replaceFaviconDataFromDataURL_beforeRegularAssign()
|
||||
firstFavicon.uri, secondFavicon.data, secondFavicon.data.length,
|
||||
secondFavicon.mimetype);
|
||||
|
||||
let deferSetAndFetchFavicon = Promise.defer();
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_beforeRegularAssign_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_beforeRegularAssign_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
deferSetAndFetchFavicon.resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
await deferSetAndFetchFavicon.promise;
|
||||
await new Promise(resolve => {
|
||||
iconsvc.setAndFetchFaviconForPage(
|
||||
pageURI, firstFavicon.uri, true,
|
||||
PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
|
||||
function test_replaceFaviconDataFromDataURL_beforeRegularAssign_check(aURI, aDataLen, aData, aMimeType) {
|
||||
checkCallbackSucceeded(aMimeType, aData, secondFavicon.mimetype, secondFavicon.data);
|
||||
checkFaviconDataForPage(
|
||||
pageURI, secondFavicon.mimetype, secondFavicon.data,
|
||||
function test_replaceFaviconDataFromDataURL_beforeRegularAssign_callback() {
|
||||
firstFavicon.file.remove(false);
|
||||
secondFavicon.file.remove(false);
|
||||
resolve();
|
||||
});
|
||||
}, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
});
|
||||
|
@ -808,13 +808,13 @@ NavHistoryResultObserver.prototype = {
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseIsURIVisited(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
resolve(aIsVisited);
|
||||
});
|
||||
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
deferred.resolve(aIsVisited);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function checkBookmarkObject(info) {
|
||||
|
@ -226,37 +226,37 @@ add_task(async function test_frecency() {
|
||||
do_check_eq(numSearchesStarted, 1);
|
||||
};
|
||||
|
||||
let deferred = Promise.defer();
|
||||
input.onSearchComplete = function() {
|
||||
do_check_eq(numSearchesStarted, 1);
|
||||
do_check_eq(controller.searchStatus,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
|
||||
await new Promise(resolve => {
|
||||
input.onSearchComplete = function() {
|
||||
do_check_eq(numSearchesStarted, 1);
|
||||
do_check_eq(controller.searchStatus,
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH);
|
||||
|
||||
// test that all records with non-zero frecency were matched
|
||||
do_check_eq(controller.matchCount, results.length);
|
||||
// test that all records with non-zero frecency were matched
|
||||
do_check_eq(controller.matchCount, results.length);
|
||||
|
||||
// test that matches are sorted by frecency
|
||||
for (var i = 0; i < controller.matchCount; i++) {
|
||||
let searchURL = controller.getValueAt(i);
|
||||
let expectURL = results[i][0].spec;
|
||||
if (searchURL == expectURL) {
|
||||
do_check_eq(controller.getValueAt(i), results[i][0].spec);
|
||||
do_check_eq(controller.getCommentAt(i), results[i][2]);
|
||||
} else {
|
||||
// If the results didn't match exactly, perhaps it's still the right
|
||||
// frecency just in the wrong "order" (order of same frecency is
|
||||
// undefined), so check if frecency matches. This is okay because we
|
||||
// can still ensure the correct number of expected frecencies.
|
||||
let getFrecency = aURL => aURL.match(/frecency:(-?\d+)$/)[1];
|
||||
print("### checking for same frecency between '" + searchURL +
|
||||
"' and '" + expectURL + "'");
|
||||
do_check_eq(getFrecency(searchURL), getFrecency(expectURL));
|
||||
// test that matches are sorted by frecency
|
||||
for (var i = 0; i < controller.matchCount; i++) {
|
||||
let searchURL = controller.getValueAt(i);
|
||||
let expectURL = results[i][0].spec;
|
||||
if (searchURL == expectURL) {
|
||||
do_check_eq(controller.getValueAt(i), results[i][0].spec);
|
||||
do_check_eq(controller.getCommentAt(i), results[i][2]);
|
||||
} else {
|
||||
// If the results didn't match exactly, perhaps it's still the right
|
||||
// frecency just in the wrong "order" (order of same frecency is
|
||||
// undefined), so check if frecency matches. This is okay because we
|
||||
// can still ensure the correct number of expected frecencies.
|
||||
let getFrecency = aURL => aURL.match(/frecency:(-?\d+)$/)[1];
|
||||
print("### checking for same frecency between '" + searchURL +
|
||||
"' and '" + expectURL + "'");
|
||||
do_check_eq(getFrecency(searchURL), getFrecency(expectURL));
|
||||
}
|
||||
}
|
||||
}
|
||||
deferred.resolve();
|
||||
};
|
||||
resolve();
|
||||
};
|
||||
|
||||
controller.startSearch(searchTerm);
|
||||
controller.startSearch(searchTerm);
|
||||
|
||||
await deferred.promise;
|
||||
});
|
||||
});
|
||||
|
@ -113,21 +113,21 @@ add_task(async function test_parseSubmissionURL_basic() {
|
||||
});
|
||||
|
||||
function promiseDefaultSearchEngine() {
|
||||
let deferred = Promise.defer();
|
||||
Services.search.init( () => {
|
||||
deferred.resolve(Services.search.defaultEngine);
|
||||
return new Promise(resolve => {
|
||||
Services.search.init( () => {
|
||||
resolve(Services.search.defaultEngine);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseSearchTopic(expectedVerb) {
|
||||
let deferred = Promise.defer();
|
||||
Services.obs.addObserver( function observe(subject, topic, verb) {
|
||||
do_print("browser-search-engine-modified: " + verb);
|
||||
if (verb == expectedVerb) {
|
||||
Services.obs.removeObserver(observe, "browser-search-engine-modified");
|
||||
deferred.resolve();
|
||||
}
|
||||
}, "browser-search-engine-modified");
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
Services.obs.addObserver( function observe(subject, topic, verb) {
|
||||
do_print("browser-search-engine-modified: " + verb);
|
||||
if (verb == expectedVerb) {
|
||||
Services.obs.removeObserver(observe, "browser-search-engine-modified");
|
||||
resolve();
|
||||
}
|
||||
}, "browser-search-engine-modified");
|
||||
});
|
||||
}
|
||||
|
@ -58,27 +58,27 @@ add_task(async function test_nsNavHistory_DecayFrecency_and_nsNavHistory_FixInva
|
||||
});
|
||||
|
||||
function onFrecencyChanged(expectedURI) {
|
||||
let deferred = Promise.defer();
|
||||
let obs = new NavHistoryObserver();
|
||||
obs.onFrecencyChanged =
|
||||
(uri, newFrecency, guid, hidden, visitDate) => {
|
||||
PlacesUtils.history.removeObserver(obs);
|
||||
do_check_true(!!uri);
|
||||
do_check_true(uri.equals(expectedURI));
|
||||
deferred.resolve();
|
||||
};
|
||||
PlacesUtils.history.addObserver(obs);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let obs = new NavHistoryObserver();
|
||||
obs.onFrecencyChanged =
|
||||
(uri, newFrecency, guid, hidden, visitDate) => {
|
||||
PlacesUtils.history.removeObserver(obs);
|
||||
do_check_true(!!uri);
|
||||
do_check_true(uri.equals(expectedURI));
|
||||
resolve();
|
||||
};
|
||||
PlacesUtils.history.addObserver(obs);
|
||||
});
|
||||
}
|
||||
|
||||
function onManyFrecenciesChanged() {
|
||||
let deferred = Promise.defer();
|
||||
let obs = new NavHistoryObserver();
|
||||
obs.onManyFrecenciesChanged = () => {
|
||||
PlacesUtils.history.removeObserver(obs);
|
||||
do_check_true(true);
|
||||
deferred.resolve();
|
||||
};
|
||||
PlacesUtils.history.addObserver(obs);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
let obs = new NavHistoryObserver();
|
||||
obs.onManyFrecenciesChanged = () => {
|
||||
PlacesUtils.history.removeObserver(obs);
|
||||
do_check_true(true);
|
||||
resolve();
|
||||
};
|
||||
PlacesUtils.history.addObserver(obs);
|
||||
});
|
||||
}
|
||||
|
@ -2,23 +2,23 @@
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function promiseGetPlacesInfo(aPlacesIdentifiers) {
|
||||
let deferred = Promise.defer();
|
||||
PlacesUtils.asyncHistory.getPlacesInfo(aPlacesIdentifiers, {
|
||||
_results: [],
|
||||
_errors: [],
|
||||
return new Promise(resolve => {
|
||||
PlacesUtils.asyncHistory.getPlacesInfo(aPlacesIdentifiers, {
|
||||
_results: [],
|
||||
_errors: [],
|
||||
|
||||
handleResult: function handleResult(aPlaceInfo) {
|
||||
this._results.push(aPlaceInfo);
|
||||
},
|
||||
handleError: function handleError(aResultCode, aPlaceInfo) {
|
||||
this._errors.push({ resultCode: aResultCode, info: aPlaceInfo });
|
||||
},
|
||||
handleCompletion: function handleCompletion() {
|
||||
resolve({ errors: this._errors, results: this._results });
|
||||
}
|
||||
});
|
||||
|
||||
handleResult: function handleResult(aPlaceInfo) {
|
||||
this._results.push(aPlaceInfo);
|
||||
},
|
||||
handleError: function handleError(aResultCode, aPlaceInfo) {
|
||||
this._errors.push({ resultCode: aResultCode, info: aPlaceInfo });
|
||||
},
|
||||
handleCompletion: function handleCompletion() {
|
||||
deferred.resolve({ errors: this._errors, results: this._results });
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function ensurePlacesInfoObjectsAreEqual(a, b) {
|
||||
|
@ -7,28 +7,28 @@
|
||||
var mDBConn = DBConn();
|
||||
|
||||
function promiseOnClearHistoryObserved() {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let historyObserver = {
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisit() {},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI(aURI) {},
|
||||
onPageChanged() {},
|
||||
onDeleteVisits() {},
|
||||
let historyObserver = {
|
||||
onBeginUpdateBatch() {},
|
||||
onEndUpdateBatch() {},
|
||||
onVisit() {},
|
||||
onTitleChanged() {},
|
||||
onDeleteURI(aURI) {},
|
||||
onPageChanged() {},
|
||||
onDeleteVisits() {},
|
||||
|
||||
onClearHistory() {
|
||||
PlacesUtils.history.removeObserver(this, false);
|
||||
deferred.resolve();
|
||||
},
|
||||
onClearHistory() {
|
||||
PlacesUtils.history.removeObserver(this, false);
|
||||
resolve();
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsINavHistoryObserver,
|
||||
])
|
||||
}
|
||||
PlacesUtils.history.addObserver(historyObserver);
|
||||
return deferred.promise;
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsINavHistoryObserver,
|
||||
])
|
||||
}
|
||||
PlacesUtils.history.addObserver(historyObserver);
|
||||
});
|
||||
}
|
||||
|
||||
// This global variable is a promise object, initialized in run_test and waited
|
||||
|
@ -10,17 +10,17 @@ const NHQO = Ci.nsINavHistoryQueryOptions;
|
||||
* Waits for onItemVisited notifications to be received.
|
||||
*/
|
||||
function promiseOnItemVisited() {
|
||||
let defer = Promise.defer();
|
||||
let bookmarksObserver = {
|
||||
__proto__: NavBookmarkObserver.prototype,
|
||||
onItemVisited: function BO_onItemVisited() {
|
||||
PlacesUtils.bookmarks.removeObserver(this);
|
||||
// Enqueue to be sure that all onItemVisited notifications ran.
|
||||
do_execute_soon(defer.resolve);
|
||||
}
|
||||
};
|
||||
PlacesUtils.bookmarks.addObserver(bookmarksObserver);
|
||||
return defer.promise;
|
||||
return new Promise(resolve => {
|
||||
let bookmarksObserver = {
|
||||
__proto__: NavBookmarkObserver.prototype,
|
||||
onItemVisited: function BO_onItemVisited() {
|
||||
PlacesUtils.bookmarks.removeObserver(this);
|
||||
// Enqueue to be sure that all onItemVisited notifications ran.
|
||||
do_execute_soon(resolve);
|
||||
}
|
||||
};
|
||||
PlacesUtils.bookmarks.addObserver(bookmarksObserver);
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
@ -78,9 +78,9 @@ function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
|
||||
}
|
||||
|
||||
function promiseWaitForCondition(aConditionFn) {
|
||||
let deferred = Promise.defer();
|
||||
waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass.");
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
waitForCondition(aConditionFn, resolve, "Condition didn't pass.");
|
||||
});
|
||||
}
|
||||
|
||||
function is_element_visible(element, msg) {
|
||||
|
@ -8,42 +8,42 @@ var dbConnection; // used for deleted table tests
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
function countDeletedEntries(expected) {
|
||||
let deferred = Promise.defer();
|
||||
let stmt = dbConnection.createAsyncStatement("SELECT COUNT(*) AS numEntries FROM moz_deleted_formhistory");
|
||||
stmt.executeAsync({
|
||||
handleResult(resultSet) {
|
||||
do_check_eq(expected, resultSet.getNextRow().getResultByName("numEntries"));
|
||||
deferred.resolve();
|
||||
},
|
||||
handleError(error) {
|
||||
do_throw("Error occurred counting deleted entries: " + error);
|
||||
deferred.reject();
|
||||
},
|
||||
handleCompletion() {
|
||||
stmt.finalize();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
let stmt = dbConnection.createAsyncStatement("SELECT COUNT(*) AS numEntries FROM moz_deleted_formhistory");
|
||||
stmt.executeAsync({
|
||||
handleResult(resultSet) {
|
||||
do_check_eq(expected, resultSet.getNextRow().getResultByName("numEntries"));
|
||||
resolve();
|
||||
},
|
||||
handleError(error) {
|
||||
do_throw("Error occurred counting deleted entries: " + error);
|
||||
reject();
|
||||
},
|
||||
handleCompletion() {
|
||||
stmt.finalize();
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function checkTimeDeleted(guid, checkFunction) {
|
||||
let deferred = Promise.defer();
|
||||
let stmt = dbConnection.createAsyncStatement("SELECT timeDeleted FROM moz_deleted_formhistory WHERE guid = :guid");
|
||||
stmt.params.guid = guid;
|
||||
stmt.executeAsync({
|
||||
handleResult(resultSet) {
|
||||
checkFunction(resultSet.getNextRow().getResultByName("timeDeleted"));
|
||||
deferred.resolve();
|
||||
},
|
||||
handleError(error) {
|
||||
do_throw("Error occurred getting deleted entries: " + error);
|
||||
deferred.reject();
|
||||
},
|
||||
handleCompletion() {
|
||||
stmt.finalize();
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
let stmt = dbConnection.createAsyncStatement("SELECT timeDeleted FROM moz_deleted_formhistory WHERE guid = :guid");
|
||||
stmt.params.guid = guid;
|
||||
stmt.executeAsync({
|
||||
handleResult(resultSet) {
|
||||
checkFunction(resultSet.getNextRow().getResultByName("timeDeleted"));
|
||||
resolve();
|
||||
},
|
||||
handleError(error) {
|
||||
do_throw("Error occurred getting deleted entries: " + error);
|
||||
reject();
|
||||
},
|
||||
handleCompletion() {
|
||||
stmt.finalize();
|
||||
}
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseUpdateEntry(op, name, value) {
|
||||
@ -73,23 +73,23 @@ function promiseUpdate(change) {
|
||||
}
|
||||
|
||||
function promiseSearchEntries(terms, params) {
|
||||
let deferred = Promise.defer();
|
||||
let results = [];
|
||||
FormHistory.search(terms, params,
|
||||
{ handleResult: result => results.push(result),
|
||||
handleError(error) {
|
||||
do_throw("Error occurred searching form history: " + error);
|
||||
deferred.reject(error);
|
||||
},
|
||||
handleCompletion(reason) { if (!reason) deferred.resolve(results); }
|
||||
});
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let results = [];
|
||||
FormHistory.search(terms, params,
|
||||
{ handleResult: result => results.push(result),
|
||||
handleError(error) {
|
||||
do_throw("Error occurred searching form history: " + error);
|
||||
reject(error);
|
||||
},
|
||||
handleCompletion(reason) { if (!reason) resolve(results); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function promiseCountEntries(name, value, checkFn) {
|
||||
let deferred = Promise.defer();
|
||||
countEntries(name, value, function(result) { checkFn(result); deferred.resolve(); } );
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
countEntries(name, value, function(result) { checkFn(result); resolve(); } );
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
|
@ -1428,22 +1428,22 @@ Engine.prototype = {
|
||||
* succeeds.
|
||||
*/
|
||||
_retrieveSearchXMLData: function SRCH_ENG__retrieveSearchXMLData(aURL) {
|
||||
let deferred = Promise.defer();
|
||||
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
request.overrideMimeType("text/xml");
|
||||
request.onload = (aEvent) => {
|
||||
let responseXML = aEvent.target.responseXML;
|
||||
this._data = responseXML.documentElement;
|
||||
deferred.resolve();
|
||||
};
|
||||
request.onerror = function(aEvent) {
|
||||
deferred.resolve();
|
||||
};
|
||||
request.open("GET", aURL, true);
|
||||
request.send();
|
||||
return new Promise(resolve => {
|
||||
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
|
||||
createInstance(Ci.nsIXMLHttpRequest);
|
||||
request.overrideMimeType("text/xml");
|
||||
request.onload = (aEvent) => {
|
||||
let responseXML = aEvent.target.responseXML;
|
||||
this._data = responseXML.documentElement;
|
||||
resolve();
|
||||
};
|
||||
request.onerror = function(aEvent) {
|
||||
resolve();
|
||||
};
|
||||
request.open("GET", aURL, true);
|
||||
request.send();
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
_initFromURISync: function SRCH_ENG_initFromURISync(uri) {
|
||||
|
@ -78,16 +78,16 @@ add_task(async function add_test_engines() {
|
||||
// Begin tests
|
||||
|
||||
add_task(async function simple_no_result_callback() {
|
||||
let deferred = Promise.defer();
|
||||
let controller = new SearchSuggestionController((result) => {
|
||||
do_check_eq(result.term, "no remote");
|
||||
do_check_eq(result.local.length, 0);
|
||||
do_check_eq(result.remote.length, 0);
|
||||
deferred.resolve();
|
||||
});
|
||||
await new Promise(resolve => {
|
||||
let controller = new SearchSuggestionController((result) => {
|
||||
do_check_eq(result.term, "no remote");
|
||||
do_check_eq(result.local.length, 0);
|
||||
do_check_eq(result.remote.length, 0);
|
||||
resolve();
|
||||
});
|
||||
|
||||
controller.fetch("no remote", false, getEngine);
|
||||
await deferred.promise;
|
||||
controller.fetch("no remote", false, getEngine);
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function simple_no_result_callback_and_promise() {
|
||||
@ -551,21 +551,21 @@ add_task(async function test_userContextId() {
|
||||
// Helpers
|
||||
|
||||
function updateSearchHistory(operation, value) {
|
||||
let deferred = Promise.defer();
|
||||
FormHistory.update({
|
||||
op: operation,
|
||||
fieldname: "searchbar-history",
|
||||
value,
|
||||
},
|
||||
{
|
||||
handleError(error) {
|
||||
do_throw("Error occurred updating form history: " + error);
|
||||
deferred.reject(error);
|
||||
return new Promise((resolve, reject) => {
|
||||
FormHistory.update({
|
||||
op: operation,
|
||||
fieldname: "searchbar-history",
|
||||
value,
|
||||
},
|
||||
handleCompletion(reason) {
|
||||
if (!reason)
|
||||
deferred.resolve();
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
{
|
||||
handleError(error) {
|
||||
do_throw("Error occurred updating form history: " + error);
|
||||
reject(error);
|
||||
},
|
||||
handleCompletion(reason) {
|
||||
if (!reason)
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -82,17 +82,17 @@ const TaskUtils = {
|
||||
* @reject {DOMError} In case of error, the underlying DOMError.
|
||||
*/
|
||||
readBlob: function readBlob(blob) {
|
||||
let deferred = Promise.defer();
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = function onloadend() {
|
||||
if (reader.readyState != FileReader.DONE) {
|
||||
deferred.reject(reader.error);
|
||||
} else {
|
||||
deferred.resolve(reader.result);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(blob);
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = function onloadend() {
|
||||
if (reader.readyState != FileReader.DONE) {
|
||||
reject(reader.error);
|
||||
} else {
|
||||
resolve(reader.result);
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(blob);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -186,16 +186,16 @@ this.PageThumbs = {
|
||||
return null;
|
||||
}
|
||||
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let canvas = this.createCanvas(aBrowser.contentWindow);
|
||||
this.captureToCanvas(aBrowser, canvas, () => {
|
||||
canvas.toBlob(blob => {
|
||||
deferred.resolve(blob, this.contentType);
|
||||
let canvas = this.createCanvas(aBrowser.contentWindow);
|
||||
this.captureToCanvas(aBrowser, canvas, () => {
|
||||
canvas.toBlob(blob => {
|
||||
resolve(blob, this.contentType);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -307,55 +307,55 @@ this.PageThumbs = {
|
||||
* @return a promise
|
||||
*/
|
||||
_captureRemoteThumbnail(aBrowser, aWidth, aHeight, aArgs) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
// The index we send with the request so we can identify the
|
||||
// correct response.
|
||||
let index = gRemoteThumbId++;
|
||||
// The index we send with the request so we can identify the
|
||||
// correct response.
|
||||
let index = gRemoteThumbId++;
|
||||
|
||||
// Thumbnail request response handler
|
||||
let mm = aBrowser.messageManager;
|
||||
// Thumbnail request response handler
|
||||
let mm = aBrowser.messageManager;
|
||||
|
||||
// Browser:Thumbnail:Response handler
|
||||
let thumbFunc = function(aMsg) {
|
||||
// Ignore events unrelated to our request
|
||||
if (aMsg.data.id != index) {
|
||||
return;
|
||||
// Browser:Thumbnail:Response handler
|
||||
let thumbFunc = function(aMsg) {
|
||||
// Ignore events unrelated to our request
|
||||
if (aMsg.data.id != index) {
|
||||
return;
|
||||
}
|
||||
|
||||
mm.removeMessageListener("Browser:Thumbnail:Response", thumbFunc);
|
||||
let imageBlob = aMsg.data.thumbnail;
|
||||
let doc = aBrowser.parentElement.ownerDocument;
|
||||
let reader = new FileReader();
|
||||
reader.addEventListener("loadend", function() {
|
||||
let image = doc.createElementNS(PageThumbUtils.HTML_NAMESPACE, "img");
|
||||
image.onload = function() {
|
||||
let thumbnail = doc.createElementNS(PageThumbUtils.HTML_NAMESPACE, "canvas");
|
||||
thumbnail.width = image.naturalWidth;
|
||||
thumbnail.height = image.naturalHeight;
|
||||
let ctx = thumbnail.getContext("2d");
|
||||
ctx.drawImage(image, 0, 0);
|
||||
resolve({
|
||||
thumbnail
|
||||
});
|
||||
}
|
||||
image.src = reader.result;
|
||||
});
|
||||
// xxx wish there was a way to skip this encoding step
|
||||
reader.readAsDataURL(imageBlob);
|
||||
}
|
||||
|
||||
mm.removeMessageListener("Browser:Thumbnail:Response", thumbFunc);
|
||||
let imageBlob = aMsg.data.thumbnail;
|
||||
let doc = aBrowser.parentElement.ownerDocument;
|
||||
let reader = new FileReader();
|
||||
reader.addEventListener("loadend", function() {
|
||||
let image = doc.createElementNS(PageThumbUtils.HTML_NAMESPACE, "img");
|
||||
image.onload = function() {
|
||||
let thumbnail = doc.createElementNS(PageThumbUtils.HTML_NAMESPACE, "canvas");
|
||||
thumbnail.width = image.naturalWidth;
|
||||
thumbnail.height = image.naturalHeight;
|
||||
let ctx = thumbnail.getContext("2d");
|
||||
ctx.drawImage(image, 0, 0);
|
||||
deferred.resolve({
|
||||
thumbnail
|
||||
});
|
||||
}
|
||||
image.src = reader.result;
|
||||
// Send a thumbnail request
|
||||
mm.addMessageListener("Browser:Thumbnail:Response", thumbFunc);
|
||||
mm.sendAsyncMessage("Browser:Thumbnail:Request", {
|
||||
canvasWidth: aWidth,
|
||||
canvasHeight: aHeight,
|
||||
background: PageThumbUtils.THUMBNAIL_BG_COLOR,
|
||||
id: index,
|
||||
additionalArgs: aArgs
|
||||
});
|
||||
// xxx wish there was a way to skip this encoding step
|
||||
reader.readAsDataURL(imageBlob);
|
||||
}
|
||||
|
||||
// Send a thumbnail request
|
||||
mm.addMessageListener("Browser:Thumbnail:Response", thumbFunc);
|
||||
mm.sendAsyncMessage("Browser:Thumbnail:Request", {
|
||||
canvasWidth: aWidth,
|
||||
canvasHeight: aHeight,
|
||||
background: PageThumbUtils.THUMBNAIL_BG_COLOR,
|
||||
id: index,
|
||||
additionalArgs: aArgs
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -29,31 +29,31 @@ function readFileToString(aFilename) {
|
||||
// Registers a table for which to serve update chunks. Returns a promise that
|
||||
// resolves when that chunk has been downloaded.
|
||||
function registerTableUpdate(aTable, aFilename) {
|
||||
let deferred = Promise.defer();
|
||||
// If we haven't been given an update for this table yet, add it to the map
|
||||
if (!(aTable in gTables)) {
|
||||
gTables[aTable] = [];
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
// If we haven't been given an update for this table yet, add it to the map
|
||||
if (!(aTable in gTables)) {
|
||||
gTables[aTable] = [];
|
||||
}
|
||||
|
||||
// The number of chunks associated with this table.
|
||||
let numChunks = gTables[aTable].length + 1;
|
||||
let redirectPath = "/" + aTable + "-" + numChunks;
|
||||
let redirectUrl = "localhost:4444" + redirectPath;
|
||||
// The number of chunks associated with this table.
|
||||
let numChunks = gTables[aTable].length + 1;
|
||||
let redirectPath = "/" + aTable + "-" + numChunks;
|
||||
let redirectUrl = "localhost:4444" + redirectPath;
|
||||
|
||||
// Store redirect url for that table so we can return it later when we
|
||||
// process an update request.
|
||||
gTables[aTable].push(redirectUrl);
|
||||
// Store redirect url for that table so we can return it later when we
|
||||
// process an update request.
|
||||
gTables[aTable].push(redirectUrl);
|
||||
|
||||
gHttpServ.registerPathHandler(redirectPath, function(request, response) {
|
||||
do_print("Mock safebrowsing server handling request for " + redirectPath);
|
||||
let contents = readFileToString(aFilename);
|
||||
response.setHeader("Content-Type",
|
||||
"application/vnd.google.safebrowsing-update", false);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(contents, contents.length);
|
||||
deferred.resolve(contents);
|
||||
gHttpServ.registerPathHandler(redirectPath, function(request, response) {
|
||||
do_print("Mock safebrowsing server handling request for " + redirectPath);
|
||||
let contents = readFileToString(aFilename);
|
||||
response.setHeader("Content-Type",
|
||||
"application/vnd.google.safebrowsing-update", false);
|
||||
response.setStatusLine(request.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(contents, contents.length);
|
||||
resolve(contents);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Construct a response with redirect urls.
|
||||
|
@ -685,18 +685,18 @@ function promiseTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRel
|
||||
|
||||
// We must prompt for the file name explicitly.
|
||||
// If we must prompt because we were asked to...
|
||||
let deferred = Promise.defer();
|
||||
if (useDownloadDir) {
|
||||
// Keep async behavior in both branches
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
deferred.resolve(null);
|
||||
});
|
||||
} else {
|
||||
downloadLastDir.getFileAsync(aRelatedURI, function getFileAsyncCB(aFile) {
|
||||
deferred.resolve(aFile);
|
||||
});
|
||||
}
|
||||
let file = await deferred.promise;
|
||||
let file = await new Promise(resolve => {
|
||||
if (useDownloadDir) {
|
||||
// Keep async behavior in both branches
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
resolve(null);
|
||||
});
|
||||
} else {
|
||||
downloadLastDir.getFileAsync(aRelatedURI, function getFileAsyncCB(aFile) {
|
||||
resolve(aFile);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (file && (await OS.File.exists(file.path))) {
|
||||
dir = file;
|
||||
dirExists = true;
|
||||
@ -729,11 +729,11 @@ function promiseTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRel
|
||||
}
|
||||
}
|
||||
|
||||
let deferComplete = Promise.defer();
|
||||
fp.open(function(aResult) {
|
||||
deferComplete.resolve(aResult);
|
||||
let result = await new Promise(resolve => {
|
||||
fp.open(function(aResult) {
|
||||
resolve(aResult);
|
||||
});
|
||||
});
|
||||
let result = await deferComplete.promise;
|
||||
if (result == Components.interfaces.nsIFilePicker.returnCancel || !fp.file) {
|
||||
return false;
|
||||
}
|
||||
|
@ -198,43 +198,43 @@ add_task(async function() {
|
||||
});
|
||||
|
||||
function promiseFindFinished(searchText, highlightOn) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let findbar = gBrowser.getFindBar();
|
||||
findbar.startFind(findbar.FIND_NORMAL);
|
||||
let highlightElement = findbar.getElement("highlight");
|
||||
if (highlightElement.checked != highlightOn)
|
||||
highlightElement.click();
|
||||
executeSoon(() => {
|
||||
findbar._findField.value = searchText;
|
||||
let findbar = gBrowser.getFindBar();
|
||||
findbar.startFind(findbar.FIND_NORMAL);
|
||||
let highlightElement = findbar.getElement("highlight");
|
||||
if (highlightElement.checked != highlightOn)
|
||||
highlightElement.click();
|
||||
executeSoon(() => {
|
||||
findbar._findField.value = searchText;
|
||||
|
||||
let resultListener;
|
||||
// When highlighting is on the finder sends a second "FOUND" message after
|
||||
// the search wraps. This causes timing problems with e10s. waitMore
|
||||
// forces foundOrTimeout wait for the second "FOUND" message before
|
||||
// resolving the promise.
|
||||
let waitMore = highlightOn;
|
||||
let findTimeout = setTimeout(() => foundOrTimedout(null), 2000);
|
||||
let foundOrTimedout = function(aData) {
|
||||
if (aData !== null && waitMore) {
|
||||
waitMore = false;
|
||||
return;
|
||||
let resultListener;
|
||||
// When highlighting is on the finder sends a second "FOUND" message after
|
||||
// the search wraps. This causes timing problems with e10s. waitMore
|
||||
// forces foundOrTimeout wait for the second "FOUND" message before
|
||||
// resolving the promise.
|
||||
let waitMore = highlightOn;
|
||||
let findTimeout = setTimeout(() => foundOrTimedout(null), 2000);
|
||||
let foundOrTimedout = function(aData) {
|
||||
if (aData !== null && waitMore) {
|
||||
waitMore = false;
|
||||
return;
|
||||
}
|
||||
if (aData === null)
|
||||
info("Result listener not called, timeout reached.");
|
||||
clearTimeout(findTimeout);
|
||||
findbar.browser.finder.removeResultListener(resultListener);
|
||||
resolve();
|
||||
}
|
||||
if (aData === null)
|
||||
info("Result listener not called, timeout reached.");
|
||||
clearTimeout(findTimeout);
|
||||
findbar.browser.finder.removeResultListener(resultListener);
|
||||
deferred.resolve();
|
||||
}
|
||||
|
||||
resultListener = {
|
||||
onFindResult: foundOrTimedout
|
||||
};
|
||||
findbar.browser.finder.addResultListener(resultListener);
|
||||
findbar._find();
|
||||
resultListener = {
|
||||
onFindResult: foundOrTimedout
|
||||
};
|
||||
findbar.browser.finder.addResultListener(resultListener);
|
||||
findbar._find();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promiseRemotenessChange(tab, shouldBeRemote) {
|
||||
|
@ -27,9 +27,9 @@ function closeFindbarAndWait(findbar) {
|
||||
}
|
||||
|
||||
function pushPrefs(...aPrefs) {
|
||||
let deferred = Promise.defer();
|
||||
SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
SpecialPowers.pushPrefEnv({"set": aPrefs}, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,32 +49,32 @@ let observer = {
|
||||
// count of reflows isn't what is expected, it causes a test failure and logs
|
||||
// the stack trace of all seen reflows.
|
||||
function countReflows(testfn, expected) {
|
||||
let deferred = Promise.defer();
|
||||
observer.reflows = [];
|
||||
let docShell = panel.ownerGlobal
|
||||
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIWebNavigation)
|
||||
.QueryInterface(Components.interfaces.nsIDocShell);
|
||||
docShell.addWeakReflowObserver(observer);
|
||||
testfn().then(() => {
|
||||
docShell.removeWeakReflowObserver(observer);
|
||||
SimpleTest.is(observer.reflows.length, expected, "correct number of reflows");
|
||||
if (observer.reflows.length != expected) {
|
||||
SimpleTest.info("stack traces of reflows:\n" + observer.reflows.join("\n") + "\n");
|
||||
}
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
observer.reflows = [];
|
||||
let docShell = panel.ownerGlobal
|
||||
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIWebNavigation)
|
||||
.QueryInterface(Components.interfaces.nsIDocShell);
|
||||
docShell.addWeakReflowObserver(observer);
|
||||
testfn().then(() => {
|
||||
docShell.removeWeakReflowObserver(observer);
|
||||
SimpleTest.is(observer.reflows.length, expected, "correct number of reflows");
|
||||
if (observer.reflows.length != expected) {
|
||||
SimpleTest.info("stack traces of reflows:\n" + observer.reflows.join("\n") + "\n");
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
return deferred.promise
|
||||
}
|
||||
|
||||
function openPopup() {
|
||||
let deferred = Promise.defer();
|
||||
panel.addEventListener("popupshown", function popupshown() {
|
||||
panel.removeEventListener("popupshown", popupshown);
|
||||
deferred.resolve();
|
||||
return new Promise(resolve => {
|
||||
panel.addEventListener("popupshown", function popupshown() {
|
||||
panel.removeEventListener("popupshown", popupshown);
|
||||
resolve();
|
||||
});
|
||||
panel.openPopup(anchor, "before_start");
|
||||
});
|
||||
panel.openPopup(anchor, "before_start");
|
||||
return deferred.promise
|
||||
}
|
||||
|
||||
// ********************
|
||||
|
@ -23,24 +23,24 @@ add_task(async function test_main_process_crash() {
|
||||
Assert.ok(cm, "CrashManager available.");
|
||||
|
||||
let basename;
|
||||
let deferred = Promise.defer();
|
||||
do_crash(
|
||||
function() {
|
||||
// TelemetrySession setup will trigger the session annotation
|
||||
let scope = {};
|
||||
Components.utils.import("resource://gre/modules/TelemetryController.jsm", scope);
|
||||
scope.TelemetryController.testSetup();
|
||||
crashType = CrashTestUtils.CRASH_MOZ_CRASH;
|
||||
crashReporter.annotateCrashReport("ShutdownProgress", "event-test");
|
||||
},
|
||||
(minidump, extra) => {
|
||||
basename = minidump.leafName;
|
||||
cm._eventsDirs = [getEventDir()];
|
||||
cm.aggregateEventsFiles().then(deferred.resolve, deferred.reject);
|
||||
},
|
||||
true);
|
||||
let count = await new Promise((resolve, reject) => {
|
||||
do_crash(
|
||||
function() {
|
||||
// TelemetrySession setup will trigger the session annotation
|
||||
let scope = {};
|
||||
Components.utils.import("resource://gre/modules/TelemetryController.jsm", scope);
|
||||
scope.TelemetryController.testSetup();
|
||||
crashType = CrashTestUtils.CRASH_MOZ_CRASH;
|
||||
crashReporter.annotateCrashReport("ShutdownProgress", "event-test");
|
||||
},
|
||||
(minidump, extra) => {
|
||||
basename = minidump.leafName;
|
||||
cm._eventsDirs = [getEventDir()];
|
||||
cm.aggregateEventsFiles().then(resolve, reject);
|
||||
},
|
||||
true);
|
||||
|
||||
let count = await deferred.promise;
|
||||
});
|
||||
Assert.equal(count, 1, "A single crash event file was seen.");
|
||||
let crashes = await cm.getCrashes();
|
||||
Assert.equal(crashes.length, 1);
|
||||
|
@ -61,12 +61,12 @@ function uri(aURIString) {
|
||||
* @rejects JavaScript exception.
|
||||
*/
|
||||
function promiseIsURIVisited(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
deferred.resolve(aIsVisited);
|
||||
});
|
||||
return new Promise(resolve => {
|
||||
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
|
||||
resolve(aIsVisited);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,13 +209,13 @@ function check_permission_exists(aURI, aExists) {
|
||||
* The URI to add a preference for.
|
||||
*/
|
||||
function add_preference(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
let cp = Cc["@mozilla.org/content-pref/service;1"].
|
||||
getService(Ci.nsIContentPrefService2);
|
||||
cp.set(aURI.spec, PREFERENCE_NAME, "foo", null, {
|
||||
handleCompletion: () => deferred.resolve()
|
||||
return new Promise(resolve => {
|
||||
let cp = Cc["@mozilla.org/content-pref/service;1"].
|
||||
getService(Ci.nsIContentPrefService2);
|
||||
cp.set(aURI.spec, PREFERENCE_NAME, "foo", null, {
|
||||
handleCompletion: () => resolve()
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,15 +225,15 @@ function add_preference(aURI) {
|
||||
* The URI to check if a preference exists.
|
||||
*/
|
||||
function preference_exists(aURI) {
|
||||
let deferred = Promise.defer();
|
||||
let cp = Cc["@mozilla.org/content-pref/service;1"].
|
||||
getService(Ci.nsIContentPrefService2);
|
||||
let exists = false;
|
||||
cp.getByDomainAndName(aURI.spec, PREFERENCE_NAME, null, {
|
||||
handleResult: () => exists = true,
|
||||
handleCompletion: () => deferred.resolve(exists)
|
||||
return new Promise(resolve => {
|
||||
let cp = Cc["@mozilla.org/content-pref/service;1"].
|
||||
getService(Ci.nsIContentPrefService2);
|
||||
let exists = false;
|
||||
cp.getByDomainAndName(aURI.spec, PREFERENCE_NAME, null, {
|
||||
handleResult: () => exists = true,
|
||||
handleCompletion: () => resolve(exists)
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Test Functions
|
||||
@ -374,22 +374,22 @@ async function test_permission_manager_not_cleared_with_uri_contains_domain() {
|
||||
}
|
||||
|
||||
function waitForPurgeNotification() {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let observer = {
|
||||
observe(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(observer, "browser:purge-domain-data");
|
||||
// test_storage_cleared needs this extra executeSoon because
|
||||
// the DOMStorage clean-up is also listening to this same observer
|
||||
// which is run synchronously.
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
deferred.resolve();
|
||||
});
|
||||
}
|
||||
};
|
||||
Services.obs.addObserver(observer, "browser:purge-domain-data");
|
||||
let observer = {
|
||||
observe(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(observer, "browser:purge-domain-data");
|
||||
// test_storage_cleared needs this extra executeSoon because
|
||||
// the DOMStorage clean-up is also listening to this same observer
|
||||
// which is run synchronously.
|
||||
Services.tm.dispatchToMainThread(function() {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
};
|
||||
Services.obs.addObserver(observer, "browser:purge-domain-data");
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
// Content Preferences
|
||||
|
@ -38,54 +38,54 @@ const EXTRACTION_BUFFER = 1024 * 512;
|
||||
* The open OS.File instance to write to.
|
||||
*/
|
||||
function saveStreamAsync(aPath, aStream, aFile) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// Read the input stream on a background thread
|
||||
let sts = Cc["@mozilla.org/network/stream-transport-service;1"].
|
||||
getService(Ci.nsIStreamTransportService);
|
||||
let transport = sts.createInputTransport(aStream, -1, -1, true);
|
||||
let input = transport.openInputStream(0, 0, 0)
|
||||
.QueryInterface(Ci.nsIAsyncInputStream);
|
||||
let source = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
source.setInputStream(input);
|
||||
// Read the input stream on a background thread
|
||||
let sts = Cc["@mozilla.org/network/stream-transport-service;1"].
|
||||
getService(Ci.nsIStreamTransportService);
|
||||
let transport = sts.createInputTransport(aStream, -1, -1, true);
|
||||
let input = transport.openInputStream(0, 0, 0)
|
||||
.QueryInterface(Ci.nsIAsyncInputStream);
|
||||
let source = Cc["@mozilla.org/binaryinputstream;1"].
|
||||
createInstance(Ci.nsIBinaryInputStream);
|
||||
source.setInputStream(input);
|
||||
|
||||
|
||||
function readFailed(error) {
|
||||
try {
|
||||
aStream.close();
|
||||
} catch (e) {
|
||||
Cu.reportError("Failed to close JAR stream for " + aPath);
|
||||
function readFailed(error) {
|
||||
try {
|
||||
aStream.close();
|
||||
} catch (e) {
|
||||
Cu.reportError("Failed to close JAR stream for " + aPath);
|
||||
}
|
||||
|
||||
aFile.close().then(function() {
|
||||
reject(error);
|
||||
}, function(e) {
|
||||
Cu.reportError("Failed to close file for " + aPath);
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
aFile.close().then(function() {
|
||||
deferred.reject(error);
|
||||
}, function(e) {
|
||||
Cu.reportError("Failed to close file for " + aPath);
|
||||
deferred.reject(error);
|
||||
});
|
||||
}
|
||||
function readData() {
|
||||
try {
|
||||
let count = Math.min(source.available(), EXTRACTION_BUFFER);
|
||||
let data = new Uint8Array(count);
|
||||
source.readArrayBuffer(count, data.buffer);
|
||||
|
||||
function readData() {
|
||||
try {
|
||||
let count = Math.min(source.available(), EXTRACTION_BUFFER);
|
||||
let data = new Uint8Array(count);
|
||||
source.readArrayBuffer(count, data.buffer);
|
||||
|
||||
aFile.write(data, { bytes: count }).then(function() {
|
||||
input.asyncWait(readData, 0, 0, Services.tm.currentThread);
|
||||
}, readFailed);
|
||||
} catch (e) {
|
||||
if (e.result == Cr.NS_BASE_STREAM_CLOSED)
|
||||
deferred.resolve(aFile.close());
|
||||
else
|
||||
readFailed(e);
|
||||
aFile.write(data, { bytes: count }).then(function() {
|
||||
input.asyncWait(readData, 0, 0, Services.tm.currentThread);
|
||||
}, readFailed);
|
||||
} catch (e) {
|
||||
if (e.result == Cr.NS_BASE_STREAM_CLOSED)
|
||||
resolve(aFile.close());
|
||||
else
|
||||
readFailed(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input.asyncWait(readData, 0, 0, Services.tm.currentThread);
|
||||
input.asyncWait(readData, 0, 0, Services.tm.currentThread);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,9 +28,9 @@ const T = 100;
|
||||
* Waits for the specified timeout before resolving the returned promise.
|
||||
*/
|
||||
function promiseTimeout(aTimeoutMs) {
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(aTimeoutMs, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
do_timeout(aTimeoutMs, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
@ -16,18 +16,18 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://services-common/async.js");
|
||||
|
||||
function sleep(ms) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let timer = Cc["@mozilla.org/timer;1"]
|
||||
.createInstance(Ci.nsITimer);
|
||||
let timer = Cc["@mozilla.org/timer;1"]
|
||||
.createInstance(Ci.nsITimer);
|
||||
|
||||
timer.initWithCallback({
|
||||
notify() {
|
||||
deferred.resolve();
|
||||
},
|
||||
}, ms, timer.TYPE_ONE_SHOT);
|
||||
timer.initWithCallback({
|
||||
notify() {
|
||||
resolve();
|
||||
},
|
||||
}, ms, timer.TYPE_ONE_SHOT);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
// When testing finalization, use this to tell Sqlite.jsm to not throw
|
||||
@ -255,16 +255,16 @@ add_task(async function test_close_cached() {
|
||||
add_task(async function test_execute_invalid_statement() {
|
||||
let c = await getDummyDatabase("invalid_statement");
|
||||
|
||||
let deferred = Promise.defer();
|
||||
await new Promise(resolve => {
|
||||
|
||||
do_check_eq(c._connectionData._anonymousStatements.size, 0);
|
||||
do_check_eq(c._connectionData._anonymousStatements.size, 0);
|
||||
|
||||
c.execute("SELECT invalid FROM unknown").then(do_throw, function onError(error) {
|
||||
resolve();
|
||||
});
|
||||
|
||||
c.execute("SELECT invalid FROM unknown").then(do_throw, function onError(error) {
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
await deferred.promise;
|
||||
|
||||
// Ensure we don't leak the statement instance.
|
||||
do_check_eq(c._connectionData._anonymousStatements.size, 0);
|
||||
|
||||
|
@ -42,18 +42,18 @@ async function getDummyDatabase(name, extraOptions = {}) {
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
let timer = Cc["@mozilla.org/timer;1"]
|
||||
.createInstance(Ci.nsITimer);
|
||||
let timer = Cc["@mozilla.org/timer;1"]
|
||||
.createInstance(Ci.nsITimer);
|
||||
|
||||
timer.initWithCallback({
|
||||
notify() {
|
||||
deferred.resolve();
|
||||
},
|
||||
}, ms, timer.TYPE_ONE_SHOT);
|
||||
timer.initWithCallback({
|
||||
notify() {
|
||||
resolve();
|
||||
},
|
||||
}, ms, timer.TYPE_ONE_SHOT);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
@ -27,9 +27,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
* posted on the event loop of the main thread is processed.
|
||||
*/
|
||||
function promiseResolvedLater(aValue) {
|
||||
let deferred = Promise.defer();
|
||||
Services.tm.dispatchToMainThread(() => deferred.resolve(aValue));
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
Services.tm.dispatchToMainThread(() => resolve(aValue));
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -39,50 +39,50 @@ this.AddonManagerTesting = {
|
||||
* @return Promise<restartRequired>
|
||||
*/
|
||||
uninstallAddonByID(id) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
AddonManager.getAddonByID(id, (addon) => {
|
||||
if (!addon) {
|
||||
deferred.reject(new Error("Add-on is not known: " + id));
|
||||
return;
|
||||
}
|
||||
AddonManager.getAddonByID(id, (addon) => {
|
||||
if (!addon) {
|
||||
reject(new Error("Add-on is not known: " + id));
|
||||
return;
|
||||
}
|
||||
|
||||
let listener = {
|
||||
onUninstalling(addon, needsRestart) {
|
||||
if (addon.id != id) {
|
||||
return;
|
||||
}
|
||||
let listener = {
|
||||
onUninstalling(addon, needsRestart) {
|
||||
if (addon.id != id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (needsRestart) {
|
||||
AddonManager.removeAddonListener(listener);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
|
||||
onUninstalled(addon) {
|
||||
if (addon.id != id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (needsRestart) {
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve(true);
|
||||
}
|
||||
},
|
||||
resolve(false);
|
||||
},
|
||||
|
||||
onUninstalled(addon) {
|
||||
if (addon.id != id) {
|
||||
return;
|
||||
}
|
||||
onOperationCancelled(addon) {
|
||||
if (addon.id != id) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve(false);
|
||||
},
|
||||
AddonManager.removeAddonListener(listener);
|
||||
reject(new Error("Uninstall cancelled."));
|
||||
},
|
||||
};
|
||||
|
||||
onOperationCancelled(addon) {
|
||||
if (addon.id != id) {
|
||||
return;
|
||||
}
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.uninstall();
|
||||
});
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.reject(new Error("Uninstall cancelled."));
|
||||
},
|
||||
};
|
||||
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.uninstall();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -91,25 +91,25 @@ this.AddonManagerTesting = {
|
||||
* @return Promise<addon>
|
||||
*/
|
||||
installXPIFromURL(url, hash, name, iconURL, version) {
|
||||
let deferred = Promise.defer();
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
AddonManager.getInstallForURL(url, (install) => {
|
||||
let fail = () => { deferred.reject(new Error("Add-on install failed.")) };
|
||||
AddonManager.getInstallForURL(url, (install) => {
|
||||
let fail = () => { reject(new Error("Add-on install failed.")) };
|
||||
|
||||
let listener = {
|
||||
onDownloadCancelled: fail,
|
||||
onDownloadFailed: fail,
|
||||
onInstallCancelled: fail,
|
||||
onInstallFailed: fail,
|
||||
onInstallEnded(install, addon) {
|
||||
deferred.resolve(addon);
|
||||
},
|
||||
};
|
||||
let listener = {
|
||||
onDownloadCancelled: fail,
|
||||
onDownloadFailed: fail,
|
||||
onInstallCancelled: fail,
|
||||
onInstallFailed: fail,
|
||||
onInstallEnded(install, addon) {
|
||||
resolve(addon);
|
||||
},
|
||||
};
|
||||
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
}, "application/x-xpinstall", hash, name, iconURL, version);
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
}, "application/x-xpinstall", hash, name, iconURL, version);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -46,19 +46,19 @@ var ao10 = { file: "browser_bug557956_10", id: "bug557956-10@tests.mozilla.org"}
|
||||
|
||||
// Return a promise that resolves after the specified delay in MS
|
||||
function delayMS(aDelay) {
|
||||
let deferred = Promise.defer();
|
||||
setTimeout(deferred.resolve, aDelay);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, aDelay);
|
||||
});
|
||||
}
|
||||
|
||||
// Return a promise that resolves when the specified observer topic is notified
|
||||
function promise_observer(aTopic) {
|
||||
let deferred = Promise.defer();
|
||||
Services.obs.addObserver(function observe(aSubject, aObsTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee, aObsTopic);
|
||||
deferred.resolve([aSubject, aData]);
|
||||
}, aTopic);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
Services.obs.addObserver(function observe(aSubject, aObsTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee, aObsTopic);
|
||||
resolve([aSubject, aData]);
|
||||
}, aTopic);
|
||||
});
|
||||
}
|
||||
|
||||
// Install a set of addons using a bogus update URL so that we can force
|
||||
@ -66,135 +66,135 @@ function promise_observer(aTopic) {
|
||||
// @param aUpdateURL The real update URL to use after the add-ons are installed
|
||||
function promise_install_test_addons(aAddonList, aUpdateURL) {
|
||||
info("Starting add-on installs");
|
||||
let deferred = Promise.defer();
|
||||
return new Promise(resolve => {
|
||||
|
||||
// Use a blank update URL
|
||||
Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "missing.rdf");
|
||||
// Use a blank update URL
|
||||
Services.prefs.setCharPref(PREF_UPDATEURL, TESTROOT + "missing.rdf");
|
||||
|
||||
let installPromises = Promise.all(
|
||||
aAddonList.map(addon => AddonManager.getInstallForURL(`${TESTROOT}addons/${addon.file}.xpi`,
|
||||
null, "application/x-xpinstall")));
|
||||
let installPromises = Promise.all(
|
||||
aAddonList.map(addon => AddonManager.getInstallForURL(`${TESTROOT}addons/${addon.file}.xpi`,
|
||||
null, "application/x-xpinstall")));
|
||||
|
||||
installPromises.then(installs => {
|
||||
var listener = {
|
||||
installCount: 0,
|
||||
installPromises.then(installs => {
|
||||
var listener = {
|
||||
installCount: 0,
|
||||
|
||||
onInstallEnded() {
|
||||
this.installCount++;
|
||||
if (this.installCount == installs.length) {
|
||||
info("Done add-on installs");
|
||||
// Switch to the test update URL
|
||||
Services.prefs.setCharPref(PREF_UPDATEURL, aUpdateURL);
|
||||
deferred.resolve();
|
||||
onInstallEnded() {
|
||||
this.installCount++;
|
||||
if (this.installCount == installs.length) {
|
||||
info("Done add-on installs");
|
||||
// Switch to the test update URL
|
||||
Services.prefs.setCharPref(PREF_UPDATEURL, aUpdateURL);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (let install of installs) {
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
for (let install of installs) {
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promise_addons_by_ids(aAddonIDs) {
|
||||
info("promise_addons_by_ids " + aAddonIDs.toSource());
|
||||
let deferred = Promise.defer();
|
||||
AddonManager.getAddonsByIDs(aAddonIDs, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
AddonManager.getAddonsByIDs(aAddonIDs, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
async function promise_uninstall_test_addons() {
|
||||
info("Starting add-on uninstalls");
|
||||
let addons = await promise_addons_by_ids([ao1.id, ao2.id, ao3.id, ao4.id, ao5.id,
|
||||
ao6.id, ao7.id, ao8.id, ao9.id, ao10.id]);
|
||||
let deferred = Promise.defer();
|
||||
let uninstallCount = addons.length;
|
||||
let listener = {
|
||||
onUninstalled(aAddon) {
|
||||
if (aAddon) {
|
||||
info("Finished uninstalling " + aAddon.id);
|
||||
}
|
||||
if (--uninstallCount == 0) {
|
||||
info("Done add-on uninstalls");
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve();
|
||||
}
|
||||
}};
|
||||
AddonManager.addAddonListener(listener);
|
||||
for (let addon of addons) {
|
||||
if (addon)
|
||||
addon.uninstall();
|
||||
else
|
||||
listener.onUninstalled(null);
|
||||
}
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
let uninstallCount = addons.length;
|
||||
let listener = {
|
||||
onUninstalled(aAddon) {
|
||||
if (aAddon) {
|
||||
info("Finished uninstalling " + aAddon.id);
|
||||
}
|
||||
if (--uninstallCount == 0) {
|
||||
info("Done add-on uninstalls");
|
||||
AddonManager.removeAddonListener(listener);
|
||||
resolve();
|
||||
}
|
||||
}};
|
||||
AddonManager.addAddonListener(listener);
|
||||
for (let addon of addons) {
|
||||
if (addon)
|
||||
addon.uninstall();
|
||||
else
|
||||
listener.onUninstalled(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Returns promise{window}, resolves with a handle to the compatibility
|
||||
// check window
|
||||
function promise_open_compatibility_window(aInactiveAddonIds) {
|
||||
let deferred = Promise.defer();
|
||||
// This will reset the longer timeout multiplier to 2 which will give each
|
||||
// test that calls open_compatibility_window a minimum of 60 seconds to
|
||||
// complete.
|
||||
requestLongerTimeout(2);
|
||||
return new Promise(resolve => {
|
||||
// This will reset the longer timeout multiplier to 2 which will give each
|
||||
// test that calls open_compatibility_window a minimum of 60 seconds to
|
||||
// complete.
|
||||
requestLongerTimeout(2);
|
||||
|
||||
var variant = Cc["@mozilla.org/variant;1"].
|
||||
createInstance(Ci.nsIWritableVariant);
|
||||
variant.setFromVariant(aInactiveAddonIds);
|
||||
var variant = Cc["@mozilla.org/variant;1"].
|
||||
createInstance(Ci.nsIWritableVariant);
|
||||
variant.setFromVariant(aInactiveAddonIds);
|
||||
|
||||
// Cannot be modal as we want to interract with it, shouldn't cause problems
|
||||
// with testing though.
|
||||
var features = "chrome,centerscreen,dialog,titlebar";
|
||||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
||||
getService(Ci.nsIWindowWatcher);
|
||||
var win = ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant);
|
||||
// Cannot be modal as we want to interract with it, shouldn't cause problems
|
||||
// with testing though.
|
||||
var features = "chrome,centerscreen,dialog,titlebar";
|
||||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
||||
getService(Ci.nsIWindowWatcher);
|
||||
var win = ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant);
|
||||
|
||||
win.addEventListener("load", function() {
|
||||
function page_shown(aEvent) {
|
||||
if (aEvent.target.pageid)
|
||||
info("Page " + aEvent.target.pageid + " shown");
|
||||
}
|
||||
win.addEventListener("load", function() {
|
||||
function page_shown(aEvent) {
|
||||
if (aEvent.target.pageid)
|
||||
info("Page " + aEvent.target.pageid + " shown");
|
||||
}
|
||||
|
||||
win.removeEventListener("load", arguments.callee);
|
||||
win.removeEventListener("load", arguments.callee);
|
||||
|
||||
info("Compatibility dialog opened");
|
||||
info("Compatibility dialog opened");
|
||||
|
||||
win.addEventListener("pageshow", page_shown);
|
||||
win.addEventListener("unload", function() {
|
||||
win.removeEventListener("pageshow", page_shown);
|
||||
dump("Compatibility dialog closed\n");
|
||||
}, {once: true});
|
||||
win.addEventListener("pageshow", page_shown);
|
||||
win.addEventListener("unload", function() {
|
||||
win.removeEventListener("pageshow", page_shown);
|
||||
dump("Compatibility dialog closed\n");
|
||||
}, {once: true});
|
||||
|
||||
deferred.resolve(win);
|
||||
resolve(win);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promise_window_close(aWindow) {
|
||||
let deferred = Promise.defer();
|
||||
aWindow.addEventListener("unload", function() {
|
||||
deferred.resolve(aWindow);
|
||||
}, {once: true});
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
aWindow.addEventListener("unload", function() {
|
||||
resolve(aWindow);
|
||||
}, {once: true});
|
||||
});
|
||||
}
|
||||
|
||||
function promise_page(aWindow, aPageId) {
|
||||
let deferred = Promise.defer();
|
||||
var page = aWindow.document.getElementById(aPageId);
|
||||
if (aWindow.document.getElementById("updateWizard").currentPage === page) {
|
||||
deferred.resolve(aWindow);
|
||||
} else {
|
||||
page.addEventListener("pageshow", function() {
|
||||
executeSoon(function() {
|
||||
deferred.resolve(aWindow);
|
||||
});
|
||||
}, {once: true});
|
||||
}
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
var page = aWindow.document.getElementById(aPageId);
|
||||
if (aWindow.document.getElementById("updateWizard").currentPage === page) {
|
||||
resolve(aWindow);
|
||||
} else {
|
||||
page.addEventListener("pageshow", function() {
|
||||
executeSoon(function() {
|
||||
resolve(aWindow);
|
||||
});
|
||||
}, {once: true});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// These add-ons became inactive during the upgrade
|
||||
@ -263,9 +263,9 @@ add_task(async function cancel_during_repopulate() {
|
||||
ok(!repo.AddonRepository.isSearching, "Background installs are done");
|
||||
|
||||
// There should be no active updates
|
||||
let getInstalls = Promise.defer();
|
||||
AddonManager.getAllInstalls(getInstalls.resolve);
|
||||
let installs = await getInstalls.promise;
|
||||
let installs = await new Promise(resolve => {
|
||||
AddonManager.getAllInstalls(resolve);
|
||||
});
|
||||
is(installs.length, 0, "There should be no active installs after background installs are done");
|
||||
|
||||
// addon8 should have updated in the background,
|
||||
@ -332,9 +332,9 @@ add_task(async function cancel_during_findUpdates() {
|
||||
ok(!a8.isCompatible, "addon8 should not have been upgraded");
|
||||
ok(a9.isCompatible, "addon9 should have been upgraded");
|
||||
|
||||
let getInstalls = Promise.defer();
|
||||
AddonManager.getAllInstalls(getInstalls.resolve);
|
||||
let installs = await getInstalls.promise;
|
||||
let installs = await new Promise(resolve => {
|
||||
AddonManager.getAllInstalls(resolve);
|
||||
});
|
||||
is(installs.length, 0, "There should be no active installs after the dialog is cancelled 2");
|
||||
|
||||
info("findUpdates done");
|
||||
@ -393,9 +393,9 @@ add_task(async function cancel_mismatch() {
|
||||
ok(a9.isCompatible, "addon9 should have been upgraded");
|
||||
|
||||
// Make sure there are no pending addon installs
|
||||
let pInstalls = Promise.defer();
|
||||
AddonManager.getAllInstalls(pInstalls.resolve);
|
||||
let installs = await pInstalls.promise;
|
||||
let installs = await new Promise(resolve => {
|
||||
AddonManager.getAllInstalls(resolve);
|
||||
});
|
||||
ok(installs.length == 0, "No remaining add-on installs (" + installs.toSource() + ")");
|
||||
|
||||
await promise_uninstall_test_addons();
|
||||
@ -440,9 +440,9 @@ add_task(async function cancel_mismatch_no_updates() {
|
||||
ok(a6.isCompatible, "addon6 should have become compatible");
|
||||
|
||||
// Make sure there are no pending addon installs
|
||||
let pInstalls = Promise.defer();
|
||||
AddonManager.getAllInstalls(pInstalls.resolve);
|
||||
let installs = await pInstalls.promise;
|
||||
let installs = await new Promise(resolve => {
|
||||
AddonManager.getAllInstalls(resolve);
|
||||
});
|
||||
ok(installs.length == 0, "No remaining add-on installs (" + installs.toSource() + ")");
|
||||
|
||||
await promise_uninstall_test_addons();
|
||||
|
@ -19,11 +19,11 @@ const SEC_IN_ONE_DAY = 24 * 60 * 60;
|
||||
const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000;
|
||||
|
||||
function getExperimentAddons() {
|
||||
let deferred = Promise.defer();
|
||||
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
||||
deferred.resolve(addons);
|
||||
return new Promise(resolve => {
|
||||
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
||||
resolve(addons);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function patchPolicy(policy, data) {
|
||||
@ -47,9 +47,9 @@ function openDetailsView(aId) {
|
||||
EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
|
||||
EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
wait_for_view_load(gManagerWindow, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
wait_for_view_load(gManagerWindow, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function clickRemoveButton(addonElement) {
|
||||
@ -279,19 +279,19 @@ add_task(async function testActivateExperiment() {
|
||||
await gExperiments.updateManifest();
|
||||
info("Experiments update complete.");
|
||||
|
||||
let deferred = Promise.defer();
|
||||
gHttpServer.stop(() => {
|
||||
gHttpServer = null;
|
||||
await new Promise(resolve => {
|
||||
gHttpServer.stop(() => {
|
||||
gHttpServer = null;
|
||||
|
||||
info("getting experiment by ID");
|
||||
AddonManager.getAddonByID("test-experiment1@experiments.mozilla.org", (addon) => {
|
||||
Assert.ok(addon, "Add-on installed via Experiments manager.");
|
||||
info("getting experiment by ID");
|
||||
AddonManager.getAddonByID("test-experiment1@experiments.mozilla.org", (addon) => {
|
||||
Assert.ok(addon, "Add-on installed via Experiments manager.");
|
||||
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
await deferred.promise;
|
||||
});
|
||||
|
||||
Assert.ok(gCategoryUtilities.isTypeVisible, "experiment", "Experiment tab visible.");
|
||||
await gCategoryUtilities.openType("experiment");
|
||||
@ -318,11 +318,11 @@ add_task(async function testDeactivateExperiment() {
|
||||
Assert.equal(experiments[0].active, false, "Experiment is not active.");
|
||||
|
||||
// We should have a previous experiment in the add-ons manager.
|
||||
let deferred = Promise.defer();
|
||||
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
||||
deferred.resolve(addons);
|
||||
let addons = await new Promise(resolve => {
|
||||
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
||||
resolve(addons);
|
||||
});
|
||||
});
|
||||
let addons = await deferred.promise;
|
||||
Assert.equal(addons.length, 1, "1 experiment add-on known.");
|
||||
Assert.ok(addons[0].appDisabled, "It is a previous experiment.");
|
||||
Assert.equal(addons[0].id, "experiment-1", "Add-on ID matches expected.");
|
||||
|
@ -68,9 +68,9 @@ function openDetailsView(aId) {
|
||||
EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
|
||||
EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
wait_for_view_load(gManagerWindow, deferred.resolve);
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
wait_for_view_load(gManagerWindow, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function initializeState() {
|
||||
@ -245,16 +245,16 @@ add_task(async function testInstalledDetails() {
|
||||
el = doc.getElementsByTagName("setting")[0];
|
||||
|
||||
let contextMenu = doc.getElementById("addonitem-popup");
|
||||
let deferred = Promise.defer();
|
||||
let listener = () => {
|
||||
contextMenu.removeEventListener("popupshown", listener);
|
||||
deferred.resolve();
|
||||
};
|
||||
contextMenu.addEventListener("popupshown", listener);
|
||||
el = doc.getElementsByClassName("detail-view-container")[0];
|
||||
EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
|
||||
EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
let listener = () => {
|
||||
contextMenu.removeEventListener("popupshown", listener);
|
||||
resolve();
|
||||
};
|
||||
contextMenu.addEventListener("popupshown", listener);
|
||||
el = doc.getElementsByClassName("detail-view-container")[0];
|
||||
EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
|
||||
EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
|
||||
});
|
||||
let menuSep = doc.getElementById("addonitem-menuseparator");
|
||||
is_element_hidden(menuSep, "Menu separator is hidden.");
|
||||
contextMenu.hidePopup();
|
||||
@ -303,9 +303,9 @@ add_task(async function testPreferencesButton() {
|
||||
|
||||
let button = doc.getAnonymousElementByAttribute(item, "anonid", "preferences-btn");
|
||||
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
|
||||
let deferred = Promise.defer();
|
||||
wait_for_view_load(gManagerWindow, deferred.resolve);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
wait_for_view_load(gManagerWindow, resolve);
|
||||
});
|
||||
|
||||
is(gOptionsObserver.lastDisplayed, addon.id);
|
||||
}
|
||||
@ -333,9 +333,9 @@ add_task(async function testUpdateButton() {
|
||||
|
||||
let button = doc.getAnonymousElementByAttribute(item, "anonid", "preferences-btn");
|
||||
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
|
||||
let deferred = Promise.defer();
|
||||
wait_for_view_load(gManagerWindow, deferred.resolve);
|
||||
await deferred.promise;
|
||||
await new Promise(resolve => {
|
||||
wait_for_view_load(gManagerWindow, resolve);
|
||||
});
|
||||
|
||||
button = doc.getElementById("detail-findUpdates-btn");
|
||||
Assert.ok(button != null, "Got detail-findUpdates-btn");
|
||||
|
@ -44,50 +44,50 @@ ARContext.ServiceRequest = function() {
|
||||
// Returns promise{window}, resolves with a handle to the compatibility
|
||||
// check window
|
||||
function promise_open_compatibility_window(aInactiveAddonIds) {
|
||||
let deferred = Promise.defer();
|
||||
// This will reset the longer timeout multiplier to 2 which will give each
|
||||
// test that calls open_compatibility_window a minimum of 60 seconds to
|
||||
// complete.
|
||||
requestLongerTimeout(2);
|
||||
return new Promise(resolve => {
|
||||
// This will reset the longer timeout multiplier to 2 which will give each
|
||||
// test that calls open_compatibility_window a minimum of 60 seconds to
|
||||
// complete.
|
||||
requestLongerTimeout(2);
|
||||
|
||||
var variant = Cc["@mozilla.org/variant;1"].
|
||||
createInstance(Ci.nsIWritableVariant);
|
||||
variant.setFromVariant(aInactiveAddonIds);
|
||||
var variant = Cc["@mozilla.org/variant;1"].
|
||||
createInstance(Ci.nsIWritableVariant);
|
||||
variant.setFromVariant(aInactiveAddonIds);
|
||||
|
||||
// Cannot be modal as we want to interract with it, shouldn't cause problems
|
||||
// with testing though.
|
||||
var features = "chrome,centerscreen,dialog,titlebar";
|
||||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
||||
getService(Ci.nsIWindowWatcher);
|
||||
var win = ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant);
|
||||
// Cannot be modal as we want to interract with it, shouldn't cause problems
|
||||
// with testing though.
|
||||
var features = "chrome,centerscreen,dialog,titlebar";
|
||||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
||||
getService(Ci.nsIWindowWatcher);
|
||||
var win = ww.openWindow(null, URI_EXTENSION_UPDATE_DIALOG, "", features, variant);
|
||||
|
||||
win.addEventListener("load", function() {
|
||||
function page_shown(aEvent) {
|
||||
if (aEvent.target.pageid)
|
||||
info("Page " + aEvent.target.pageid + " shown");
|
||||
}
|
||||
win.addEventListener("load", function() {
|
||||
function page_shown(aEvent) {
|
||||
if (aEvent.target.pageid)
|
||||
info("Page " + aEvent.target.pageid + " shown");
|
||||
}
|
||||
|
||||
win.removeEventListener("load", arguments.callee);
|
||||
win.removeEventListener("load", arguments.callee);
|
||||
|
||||
info("Compatibility dialog opened");
|
||||
info("Compatibility dialog opened");
|
||||
|
||||
win.addEventListener("pageshow", page_shown);
|
||||
win.addEventListener("unload", function() {
|
||||
win.removeEventListener("pageshow", page_shown);
|
||||
dump("Compatibility dialog closed\n");
|
||||
}, {once: true});
|
||||
win.addEventListener("pageshow", page_shown);
|
||||
win.addEventListener("unload", function() {
|
||||
win.removeEventListener("pageshow", page_shown);
|
||||
dump("Compatibility dialog closed\n");
|
||||
}, {once: true});
|
||||
|
||||
deferred.resolve(win);
|
||||
resolve(win);
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function promise_window_close(aWindow) {
|
||||
let deferred = Promise.defer();
|
||||
aWindow.addEventListener("unload", function() {
|
||||
deferred.resolve(aWindow);
|
||||
}, {once: true});
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
aWindow.addEventListener("unload", function() {
|
||||
resolve(aWindow);
|
||||
}, {once: true});
|
||||
});
|
||||
}
|
||||
|
||||
// Start the compatibility update dialog, but use the mock XHR to respond with
|
||||
|
@ -100,46 +100,46 @@ function setQuickMockTimer() {
|
||||
* is called
|
||||
*/
|
||||
function setPromiseMockTimer() {
|
||||
let waiter = Promise.defer();
|
||||
let mockTimer = {
|
||||
callback: null,
|
||||
delay: null,
|
||||
type: null,
|
||||
isCancelled: false,
|
||||
return new Promise(resolve => {
|
||||
let mockTimer = {
|
||||
callback: null,
|
||||
delay: null,
|
||||
type: null,
|
||||
isCancelled: false,
|
||||
|
||||
initWithCallback(aFunction, aDelay, aType) {
|
||||
do_print("Starting timer, delay = " + aDelay);
|
||||
this.callback = aFunction;
|
||||
this.delay = aDelay;
|
||||
this.type = aType;
|
||||
// cancelled timers can be re-used
|
||||
this.isCancelled = false;
|
||||
waiter.resolve(this);
|
||||
},
|
||||
cancel() {
|
||||
do_print("Cancelled mock timer");
|
||||
this.callback = null;
|
||||
this.delay = null;
|
||||
this.type = null;
|
||||
this.isCancelled = true;
|
||||
// If initWithCallback was never called, resolve to let tests check for cancel
|
||||
waiter.resolve(this);
|
||||
}
|
||||
};
|
||||
DSContext.MakeTimer = () => {
|
||||
do_print("Creating mock timer");
|
||||
return mockTimer;
|
||||
};
|
||||
return waiter.promise;
|
||||
initWithCallback(aFunction, aDelay, aType) {
|
||||
do_print("Starting timer, delay = " + aDelay);
|
||||
this.callback = aFunction;
|
||||
this.delay = aDelay;
|
||||
this.type = aType;
|
||||
// cancelled timers can be re-used
|
||||
this.isCancelled = false;
|
||||
resolve(this);
|
||||
},
|
||||
cancel() {
|
||||
do_print("Cancelled mock timer");
|
||||
this.callback = null;
|
||||
this.delay = null;
|
||||
this.type = null;
|
||||
this.isCancelled = true;
|
||||
// If initWithCallback was never called, resolve to let tests check for cancel
|
||||
resolve(this);
|
||||
}
|
||||
};
|
||||
DSContext.MakeTimer = () => {
|
||||
do_print("Creating mock timer");
|
||||
return mockTimer;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Promise<null> that resolves after the specified number of milliseconds
|
||||
*/
|
||||
function delay(aDelayMS) {
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(aDelayMS, () => deferred.resolve(null));
|
||||
return deferred.promise;
|
||||
return new Promise(resolve => {
|
||||
do_timeout(aDelayMS, () => resolve(null));
|
||||
});
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
@ -250,24 +250,24 @@ add_task(async function dirty_while_writing() {
|
||||
let thirdData = "Third data";
|
||||
let firstCallback_happened = false;
|
||||
let secondCallback_happened = false;
|
||||
let writeStarted = Promise.defer();
|
||||
let writer = await new Promise(resolve => {
|
||||
|
||||
function writeCallback(aTester) {
|
||||
writeStarted.resolve(aTester.waDeferred);
|
||||
}
|
||||
function writeCallback(aTester) {
|
||||
resolve(aTester.waDeferred);
|
||||
}
|
||||
|
||||
setQuickMockTimer();
|
||||
do_print("First save");
|
||||
tester.save(firstData, writeCallback).then(
|
||||
count => {
|
||||
do_check_false(firstCallback_happened);
|
||||
do_check_false(secondCallback_happened);
|
||||
do_check_eq(tester.writtenData, firstData);
|
||||
firstCallback_happened = true;
|
||||
}, do_report_unexpected_exception);
|
||||
setQuickMockTimer();
|
||||
do_print("First save");
|
||||
tester.save(firstData, writeCallback).then(
|
||||
count => {
|
||||
do_check_false(firstCallback_happened);
|
||||
do_check_false(secondCallback_happened);
|
||||
do_check_eq(tester.writtenData, firstData);
|
||||
firstCallback_happened = true;
|
||||
}, do_report_unexpected_exception);
|
||||
|
||||
do_print("waiting for writer");
|
||||
let writer = await writeStarted.promise;
|
||||
do_print("waiting for writer");
|
||||
});
|
||||
do_print("Write started");
|
||||
|
||||
// Delay a bit, modify the data and call saveChanges, delay a bit more,
|
||||
@ -331,20 +331,20 @@ add_task(async function flush_during_write() {
|
||||
let tester = DeferredSaveTester();
|
||||
let dataToSave = "Flush during write";
|
||||
let firstCallback_happened = false;
|
||||
let writeStarted = Promise.defer();
|
||||
let writer = await new Promise(resolve => {
|
||||
|
||||
function writeCallback(aTester) {
|
||||
writeStarted.resolve(aTester.waDeferred);
|
||||
}
|
||||
function writeCallback(aTester) {
|
||||
resolve(aTester.waDeferred);
|
||||
}
|
||||
|
||||
setQuickMockTimer();
|
||||
tester.save(dataToSave, writeCallback).then(
|
||||
count => {
|
||||
do_check_false(firstCallback_happened);
|
||||
firstCallback_happened = true;
|
||||
}, do_report_unexpected_exception);
|
||||
setQuickMockTimer();
|
||||
tester.save(dataToSave, writeCallback).then(
|
||||
count => {
|
||||
do_check_false(firstCallback_happened);
|
||||
firstCallback_happened = true;
|
||||
}, do_report_unexpected_exception);
|
||||
|
||||
let writer = await writeStarted.promise;
|
||||
});
|
||||
|
||||
// call flush with the write callback disabled, delay a bit more, complete in-progress write
|
||||
let flushing = tester.flush(disabled_write_callback);
|
||||
|
@ -159,24 +159,24 @@ add_task(async function init() {
|
||||
"addon4@tests.mozilla.org",
|
||||
"addon7@tests.mozilla.org",
|
||||
"theme2@tests.mozilla.org"]);
|
||||
let deferredUpdateFinished = Promise.defer();
|
||||
// Set up the initial state
|
||||
a2.userDisabled = true;
|
||||
a4.userDisabled = true;
|
||||
a7.userDisabled = true;
|
||||
t2.userDisabled = false;
|
||||
a3.findUpdates({
|
||||
onUpdateFinished() {
|
||||
a4.findUpdates({
|
||||
onUpdateFinished() {
|
||||
// Let the updates finish before restarting the manager
|
||||
deferredUpdateFinished.resolve();
|
||||
}
|
||||
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
}
|
||||
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
await new Promise(resolve => {
|
||||
// Set up the initial state
|
||||
a2.userDisabled = true;
|
||||
a4.userDisabled = true;
|
||||
a7.userDisabled = true;
|
||||
t2.userDisabled = false;
|
||||
a3.findUpdates({
|
||||
onUpdateFinished() {
|
||||
a4.findUpdates({
|
||||
onUpdateFinished() {
|
||||
// Let the updates finish before restarting the manager
|
||||
resolve();
|
||||
}
|
||||
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
}
|
||||
}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
|
||||
await deferredUpdateFinished.promise;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user