Bug 1366531 - convert uses of defer to 'new Promise' in client/jsonview
MozReview-Commit-ID: CDeyxYtCn4e
--- a/devtools/client/jsonview/test/head.js
+++ b/devtools/client/jsonview/test/head.js
@@ -22,43 +22,38 @@ registerCleanupFunction(() => {
// XXX move some API into devtools/framework/test/shared-head.js
/**
* Add a new test tab in the browser and load the given url.
* @param {String} url The url to be loaded in the new tab
* @return a promise that resolves to the tab object when the url is loaded
*/
-function addJsonViewTab(url) {
+async function addJsonViewTab(url) {
info("Adding a new JSON tab with URL: '" + url + "'");
- let deferred = promise.defer();
- addTab(url).then(tab => {
- let browser = tab.linkedBrowser;
+ const tab = await addTab(url);
+ let browser = tab.linkedBrowser;
- // Load devtools/shared/frame-script-utils.js
- getFrameScript();
-
- // Load frame script with helpers for JSON View tests.
- let rootDir = getRootDirectory(gTestPath);
- let frameScriptUrl = rootDir + "doc_frame_script.js";
- browser.messageManager.loadFrameScript(frameScriptUrl, false);
+ // Load devtools/shared/frame-script-utils.js
+ getFrameScript();
- // Resolve if the JSONView is fully loaded or wait
- // for an initialization event.
- if (content.window.wrappedJSObject.jsonViewInitialized) {
- deferred.resolve(tab);
- } else {
- waitForContentMessage("Test:JsonView:JSONViewInitialized").then(() => {
- deferred.resolve(tab);
- });
- }
- });
+ // Load frame script with helpers for JSON View tests.
+ let rootDir = getRootDirectory(gTestPath);
+ let frameScriptUrl = rootDir + "doc_frame_script.js";
+ browser.messageManager.loadFrameScript(frameScriptUrl, false);
- return deferred.promise;
+ // Resolve if the JSONView is fully loaded or wait
+ // for an initialization event.
+ if (content.window.wrappedJSObject.jsonViewInitialized) {
+ return tab;
+ }
+
+ await waitForContentMessage("Test:JsonView:JSONViewInitialized");
+ return tab;
}
/**
* Expanding a node in the JSON tree
*/
function clickJsonNode(selector) {
info("Expanding node: '" + selector + "'");
@@ -126,19 +121,19 @@ function sendString(str, selector) {
selector: selector,
str: str
};
return executeInContent("Test:JsonView:SendString", data);
}
function waitForTime(delay) {
- let deferred = promise.defer();
- setTimeout(deferred.resolve, delay);
- return deferred.promise;
+ return new Promise((resolve, reject) => {
+ setTimeout(resolve, delay);
+ });
}
function waitForFilter() {
return executeInContent("Test:JsonView:WaitForFilter");
}
function normalizeNewLines(value) {
return value.replace("(\r\n|\n)", "\n");