gecko-dev/devtools/client/performance/test/browser_timeline-waterfall-workers.js
Alexandre Poirot a8c68f2955 Bug 1387123 - Replace all usages of require(promise).defer by require(devtools/shared/defer).defer. r=tromey
In prevision of Promise.jsm removal, use defer helper module instead of Promise.jsm
as that's the only one feature that DOM Promise don't support.

PART2: Substitutes promise.defer usages with defer
$ sed -i 's/promise.defer/defer/gI' $(egrep -lir "promise.defer\(\)" devtools)
  Reset modification to the following files as they are using deprecated syncable promises as we don't want to touch them.
  http://searchfox.org/mozilla-central/search?q=deprecated-sync-thenables&case=true&regexp=false&path=
$ git checkout devtools/client/debugger/test/mochitest/
$ git checkout devtools/shared/client/main.js
$ git checkout devtools/client/debugger/
$ git checkout devtools/server/main.js

MozReview-Commit-ID: DGN5ae68wtn

--HG--
extra : rebase_source : 57602d89b0bcc1c905bee7723e30f87fa434c6d9
2017-08-08 15:24:04 +02:00

98 lines
2.8 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* eslint-disable */
/**
* Tests if the sidebar is properly updated with worker markers.
*/
function* spawnTest() {
let { panel } = yield initPerformance(WORKER_URL);
let { $$, $, PerformanceController } = panel.panelWin;
loadFrameScripts();
yield startRecording(panel);
ok(true, "Recording has started.");
evalInDebuggee("performWork()");
yield waitUntil(() => {
// Wait until we get the worker markers.
let markers = PerformanceController.getCurrentRecording().getMarkers();
if (!markers.some(m => m.name == "Worker") ||
!markers.some(m => m.workerOperation == "serializeDataOffMainThread") ||
!markers.some(m => m.workerOperation == "serializeDataOnMainThread") ||
!markers.some(m => m.workerOperation == "deserializeDataOffMainThread") ||
!markers.some(m => m.workerOperation == "deserializeDataOnMainThread")) {
return false;
}
testWorkerMarkerData(markers.find(m => m.name == "Worker"));
return true;
});
yield stopRecording(panel);
ok(true, "Recording has ended.");
for (let node of $$(".waterfall-marker-name[value=Worker")) {
testWorkerMarkerUI(node.parentNode.parentNode);
}
yield teardown(panel);
finish();
}
function testWorkerMarkerData(marker) {
ok(true, "Found a worker marker.");
ok("start" in marker,
"The start time is specified in the worker marker.");
ok("end" in marker,
"The end time is specified in the worker marker.");
ok("workerOperation" in marker,
"The worker operation is specified in the worker marker.");
ok("processType" in marker,
"The process type is specified in the worker marker.");
ok("isOffMainThread" in marker,
"The thread origin is specified in the worker marker.");
}
function testWorkerMarkerUI(node) {
is(node.className, "waterfall-tree-item",
"The marker node has the correct class name.");
ok(node.hasAttribute("otmt"),
"The marker node specifies if it is off the main thread or not.");
}
/**
* Takes a string `script` and evaluates it directly in the content
* in potentially a different process.
*/
function evalInDebuggee(script) {
let { generateUUID } = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
let deferred = defer();
if (!mm) {
throw new Error("`loadFrameScripts()` must be called when using MessageManager.");
}
let id = generateUUID().toString();
mm.sendAsyncMessage("devtools:test:eval", { script: script, id: id });
mm.addMessageListener("devtools:test:eval:response", handler);
function handler({ data }) {
if (id !== data.id) {
return;
}
mm.removeMessageListener("devtools:test:eval:response", handler);
deferred.resolve(data.value);
}
return deferred.promise;
}
/* eslint-enable */