Bug 1083989 - Adapt Devtools tests that expect Promise.jsm in the scope. r=paul

This commit is contained in:
David Rajchenbach-Teller 2014-10-27 22:45:03 +01:00
parent 25a9c4bf37
commit 34fd8ab0dc
5 changed files with 184 additions and 192 deletions

View File

@ -35,9 +35,8 @@ function addTab(aURL, aCallback)
}
function promiseTab(aURL) {
let deferred = Promise.defer();
addTab(aURL, deferred.resolve);
return deferred.promise;
return new Promise(resolve =>
addTab(aURL, resolve));
}
registerCleanupFunction(function tearDown() {
@ -138,11 +137,11 @@ function* createHost(type = "bottom", src = "data:text/html;charset=utf-8,") {
let host = new Hosts[type](gBrowser.selectedTab);
let iframe = yield host.create();
let loaded = Promise.defer();
let domHelper = new DOMHelpers(iframe.contentWindow);
iframe.setAttribute("src", src);
domHelper.onceDOMReady(loaded.resolve);
yield loaded.promise;
yield new Promise(resolve => {
let domHelper = new DOMHelpers(iframe.contentWindow);
iframe.setAttribute("src", src);
domHelper.onceDOMReady(resolve);
});
return [host, iframe.contentWindow, iframe.contentDocument];
}

View File

@ -128,177 +128,177 @@ function testReload() {
let shouldBeEmptyFirst = Cu.cloneInto(beforeReload, {});
let shouldBeEmptyLast = Cu.cloneInto(beforeReload, {});
let reloaded = Promise.defer();
return new Promise(resolve => {
let onStoresUpdate = data => {
info("in stores update of testReload");
// This might be second time stores update is happening, in which case,
// data.deleted will be null.
// OR.. This might be the first time on a super slow machine where both
// data.deleted and data.added is missing in the first update.
if (data.deleted) {
markOutMatched(shouldBeEmptyFirst, data.deleted, true);
}
let onStoresUpdate = data => {
info("in stores update of testReload");
// This might be second time stores update is happening, in which case,
// data.deleted will be null.
// OR.. This might be the first time on a super slow machine where both
// data.deleted and data.added is missing in the first update.
if (data.deleted) {
markOutMatched(shouldBeEmptyFirst, data.deleted, true);
}
if (!Object.keys(shouldBeEmptyFirst).length) {
info("shouldBeEmptyFirst is empty now");
}
if (!Object.keys(shouldBeEmptyFirst).length) {
info("shouldBeEmptyFirst is empty now");
}
// stores-update call might not have data.added for the first time on slow
// machines, in which case, data.added will be null
if (data.added) {
markOutMatched(shouldBeEmptyLast, data.added);
}
// stores-update call might not have data.added for the first time on slow
// machines, in which case, data.added will be null
if (data.added) {
markOutMatched(shouldBeEmptyLast, data.added);
}
if (!Object.keys(shouldBeEmptyLast).length) {
info("Everything to be received is received.");
endTestReloaded();
}
};
if (!Object.keys(shouldBeEmptyLast).length) {
info("Everything to be received is received.");
endTestReloaded();
}
};
let endTestReloaded = () => {
gFront.off("stores-update", onStoresUpdate);
reloaded.resolve();
};
let endTestReloaded = () => {
gFront.off("stores-update", onStoresUpdate);
resolve();
};
gFront.on("stores-update", onStoresUpdate);
gFront.on("stores-update", onStoresUpdate);
content.location.reload();
return reloaded.promise;
content.location.reload();
});
}
function testAddIframe() {
info("Testing if new iframe addition works properly");
let reloaded = Promise.defer();
return new Promise(resolve => {
let shouldBeEmpty = {
localStorage: {
"https://sectest1.example.org": ["iframe-s-ls1"]
},
sessionStorage: {
"https://sectest1.example.org": ["iframe-s-ss1"]
},
cookies: {
"sectest1.example.org": ["sc1"]
},
indexedDB: {
// empty because indexed db creation happens after the page load, so at
// the time of window-ready, there was no indexed db present.
"https://sectest1.example.org": []
}
};
let shouldBeEmpty = {
localStorage: {
"https://sectest1.example.org": ["iframe-s-ls1"]
},
sessionStorage: {
"https://sectest1.example.org": ["iframe-s-ss1"]
},
cookies: {
"sectest1.example.org": ["sc1"]
},
indexedDB: {
// empty because indexed db creation happens after the page load, so at
// the time of window-ready, there was no indexed db present.
"https://sectest1.example.org": []
}
};
let onStoresUpdate = data => {
info("checking if the hosts list is correct for this iframe addition");
let onStoresUpdate = data => {
info("checking if the hosts list is correct for this iframe addition");
markOutMatched(shouldBeEmpty, data.added);
markOutMatched(shouldBeEmpty, data.added);
ok(!data.changed || !data.changed.cookies ||
!data.changed.cookies["https://sectest1.example.org"],
"Nothing got changed for cookies");
ok(!data.changed || !data.changed.localStorage ||
!data.changed.localStorage["https://sectest1.example.org"],
"Nothing got changed for local storage");
ok(!data.changed || !data.changed.sessionStorage ||
!data.changed.sessionStorage["https://sectest1.example.org"],
"Nothing got changed for session storage");
ok(!data.changed || !data.changed.indexedDB ||
!data.changed.indexedDB["https://sectest1.example.org"],
"Nothing got changed for indexed db");
ok(!data.changed || !data.changed.cookies ||
!data.changed.cookies["https://sectest1.example.org"],
"Nothing got changed for cookies");
ok(!data.changed || !data.changed.localStorage ||
!data.changed.localStorage["https://sectest1.example.org"],
"Nothing got changed for local storage");
ok(!data.changed || !data.changed.sessionStorage ||
!data.changed.sessionStorage["https://sectest1.example.org"],
"Nothing got changed for session storage");
ok(!data.changed || !data.changed.indexedDB ||
!data.changed.indexedDB["https://sectest1.example.org"],
"Nothing got changed for indexed db");
ok(!data.deleted || !data.deleted.cookies ||
!data.deleted.cookies["https://sectest1.example.org"],
"Nothing got deleted for cookies");
ok(!data.deleted || !data.deleted.localStorage ||
!data.deleted.localStorage["https://sectest1.example.org"],
"Nothing got deleted for local storage");
ok(!data.deleted || !data.deleted.sessionStorage ||
!data.deleted.sessionStorage["https://sectest1.example.org"],
"Nothing got deleted for session storage");
ok(!data.deleted || !data.deleted.indexedDB ||
!data.deleted.indexedDB["https://sectest1.example.org"],
"Nothing got deleted for indexed db");
ok(!data.deleted || !data.deleted.cookies ||
!data.deleted.cookies["https://sectest1.example.org"],
"Nothing got deleted for cookies");
ok(!data.deleted || !data.deleted.localStorage ||
!data.deleted.localStorage["https://sectest1.example.org"],
"Nothing got deleted for local storage");
ok(!data.deleted || !data.deleted.sessionStorage ||
!data.deleted.sessionStorage["https://sectest1.example.org"],
"Nothing got deleted for session storage");
ok(!data.deleted || !data.deleted.indexedDB ||
!data.deleted.indexedDB["https://sectest1.example.org"],
"Nothing got deleted for indexed db");
if (!Object.keys(shouldBeEmpty).length) {
info("Everything to be received is received.");
endTestReloaded();
}
};
if (!Object.keys(shouldBeEmpty).length) {
info("Everything to be received is received.");
endTestReloaded();
}
};
let endTestReloaded = () => {
gFront.off("stores-update", onStoresUpdate);
reloaded.resolve();
};
let endTestReloaded = () => {
gFront.off("stores-update", onStoresUpdate);
resolve();
};
gFront.on("stores-update", onStoresUpdate);
gFront.on("stores-update", onStoresUpdate);
let iframe = content.document.createElement("iframe");
iframe.src = ALT_DOMAIN_SECURED + "storage-secured-iframe.html";
content.document.querySelector("body").appendChild(iframe);
return reloaded.promise;
let iframe = content.document.createElement("iframe");
iframe.src = ALT_DOMAIN_SECURED + "storage-secured-iframe.html";
content.document.querySelector("body").appendChild(iframe);
});
}
function testRemoveIframe() {
info("Testing if iframe removal works properly");
let reloaded = Promise.defer();
return new Promise(resolve => {
let shouldBeEmpty = {
localStorage: {
"http://sectest1.example.org": []
},
sessionStorage: {
"http://sectest1.example.org": []
let shouldBeEmpty = {
localStorage: {
"http://sectest1.example.org": []
},
sessionStorage: {
"http://sectest1.example.org": []
}
};
let onStoresUpdate = data => {
info("checking if the hosts list is correct for this iframe deletion");
markOutMatched(shouldBeEmpty, data.deleted, true);
ok(!data.deleted.cookies || !data.deleted.cookies["sectest1.example.org"],
"Nothing got deleted for Cookies as the same hostname is still present");
ok(!data.changed || !data.changed.cookies ||
!data.changed.cookies["http://sectest1.example.org"],
"Nothing got changed for cookies");
ok(!data.changed || !data.changed.localStorage ||
!data.changed.localStorage["http://sectest1.example.org"],
"Nothing got changed for local storage");
ok(!data.changed || !data.changed.sessionStorage ||
!data.changed.sessionStorage["http://sectest1.example.org"],
"Nothing got changed for session storage");
ok(!data.added || !data.added.cookies ||
!data.added.cookies["http://sectest1.example.org"],
"Nothing got added for cookies");
ok(!data.added || !data.added.localStorage ||
!data.added.localStorage["http://sectest1.example.org"],
"Nothing got added for local storage");
ok(!data.added || !data.added.sessionStorage ||
!data.added.sessionStorage["http://sectest1.example.org"],
"Nothing got added for session storage");
if (!Object.keys(shouldBeEmpty).length) {
info("Everything to be received is received.");
endTestReloaded();
}
};
let endTestReloaded = () => {
gFront.off("stores-update", onStoresUpdate);
resolve();
};
gFront.on("stores-update", onStoresUpdate);
for (let iframe of content.document.querySelectorAll("iframe")) {
if (iframe.src.startsWith("http:")) {
iframe.remove();
break;
}
}
};
let onStoresUpdate = data => {
info("checking if the hosts list is correct for this iframe deletion");
markOutMatched(shouldBeEmpty, data.deleted, true);
ok(!data.deleted.cookies || !data.deleted.cookies["sectest1.example.org"],
"Nothing got deleted for Cookies as the same hostname is still present");
ok(!data.changed || !data.changed.cookies ||
!data.changed.cookies["http://sectest1.example.org"],
"Nothing got changed for cookies");
ok(!data.changed || !data.changed.localStorage ||
!data.changed.localStorage["http://sectest1.example.org"],
"Nothing got changed for local storage");
ok(!data.changed || !data.changed.sessionStorage ||
!data.changed.sessionStorage["http://sectest1.example.org"],
"Nothing got changed for session storage");
ok(!data.added || !data.added.cookies ||
!data.added.cookies["http://sectest1.example.org"],
"Nothing got added for cookies");
ok(!data.added || !data.added.localStorage ||
!data.added.localStorage["http://sectest1.example.org"],
"Nothing got added for local storage");
ok(!data.added || !data.added.sessionStorage ||
!data.added.sessionStorage["http://sectest1.example.org"],
"Nothing got added for session storage");
if (!Object.keys(shouldBeEmpty).length) {
info("Everything to be received is received.");
endTestReloaded();
}
};
let endTestReloaded = () => {
gFront.off("stores-update", onStoresUpdate);
reloaded.resolve();
};
gFront.on("stores-update", onStoresUpdate);
for (let iframe of content.document.querySelectorAll("iframe")) {
if (iframe.src.startsWith("http:")) {
iframe.remove();
break;
}
}
return reloaded.promise;
});
}
function test() {

View File

@ -59,11 +59,10 @@ let test = asyncTest(function*() {
*/
function waitUntil(predicate, interval = 10) {
if (predicate()) {
return promise.resolve(true);
return Promise.resolve(true);
}
let deferred = promise.defer();
setTimeout(function() {
waitUntil(predicate).then(() => deferred.resolve(true));
}, interval);
return deferred.promise;
return new Promise(resolve =>
setTimeout(function() {
waitUntil(predicate).then(() => resolve(true));
}, interval));
}

View File

@ -35,7 +35,6 @@ let test = asyncTest(function*() {
});
function wait(ms) {
let def = promise.defer();
setTimeout(def.resolve, ms);
return def.promise;
return new Promise(resolve =>
setTimeout(resolve, ms));
}

View File

@ -8,7 +8,6 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
const {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
const {devtools: {require}} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
const {DebuggerClient} = Cu.import("resource://gre/modules/devtools/dbg-client.jsm", {});
const {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
@ -43,11 +42,10 @@ let addTab = Task.async(function* (url) {
info("URL '" + url + "' loading complete");
let def = promise.defer();
let isBlank = url == "about:blank";
waitForFocus(def.resolve, content, isBlank);
yield def.promise;
yield new Promise(resolve => {
let isBlank = url == "about:blank";
waitForFocus(resolve, content, isBlank);
});;
return tab.linkedBrowser.contentWindow.document;
});
@ -69,13 +67,13 @@ function initDebuggerServer() {
* connected.
*/
function connectDebuggerClient(client) {
let def = promise.defer();
client.connect(() => {
client.listTabs(tabs => {
def.resolve(tabs.tabs[tabs.selected]);
return new Promise(resolve => {
client.connect(() => {
client.listTabs(tabs => {
resolve(tabs.tabs[tabs.selected]);
});
});
});
return def.promise;
}
/**
@ -84,9 +82,7 @@ function connectDebuggerClient(client) {
* @return {Promise} Resolves when the connection is closed.
*/
function closeDebuggerClient(client) {
let def = promise.defer();
client.close(def.resolve);
return def.promise;
return new Promise(resolve => client.close(resolve));
}
/**
@ -100,24 +96,23 @@ function closeDebuggerClient(client) {
function once(target, eventName, useCapture=false) {
info("Waiting for event: '" + eventName + "' on " + target + ".");
let deferred = promise.defer();
return new Promise(resolve => {
for (let [add, remove] of [
["addEventListener", "removeEventListener"],
["addListener", "removeListener"],
["on", "off"]
]) {
if ((add in target) && (remove in target)) {
target[add](eventName, function onEvent(...aArgs) {
info("Got event: '" + eventName + "' on " + target + ".");
target[remove](eventName, onEvent, useCapture);
deferred.resolve.apply(deferred, aArgs);
}, useCapture);
break;
for (let [add, remove] of [
["addEventListener", "removeEventListener"],
["addListener", "removeListener"],
["on", "off"]
]) {
if ((add in target) && (remove in target)) {
target[add](eventName, function onEvent(...aArgs) {
info("Got event: '" + eventName + "' on " + target + ".");
target[remove](eventName, onEvent, useCapture);
resolve(...aArgs);
}, useCapture);
break;
}
}
}
return deferred.promise;
});
}
/**