gecko-dev/devtools/client/shared/test/browser_flame-graph-utils-01.js
J. Ryan Stinnett efe328f1b2 Bug 912121 - Rewrite require / import to match source tree. rs=devtools
In a following patch, all DevTools moz.build files will use DevToolsModules to
install JS modules at a path that corresponds directly to their source tree
location.  Here we rewrite all require and import calls to match the new
location that these files are installed to.

--HG--
extra : commitid : F2ItGm8ptRz
extra : rebase_source : b082fe4bf77e22e297e303fc601165ceff1c4cbc
2015-09-21 12:04:18 -05:00

255 lines
4.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that text metrics and data conversion from profiler samples
// widget work properly in the flame graph.
var {FlameGraphUtils} = require("devtools/client/shared/widgets/FlameGraph");
var {PALLETTE_SIZE} = require("devtools/client/shared/widgets/FlameGraph");
add_task(function*() {
yield promiseTab("about:blank");
yield performTest();
gBrowser.removeCurrentTab();
});
function* performTest() {
let out = FlameGraphUtils.createFlameGraphDataFromThread(TEST_DATA);
ok(out, "Some data was outputted properly");
is(out.length, PALLETTE_SIZE, "The outputted length is correct.");
info("Got flame graph data:\n" + out.toSource() + "\n");
for (let i = 0; i < out.length; i++) {
let found = out[i];
let expected = EXPECTED_OUTPUT[i];
is(found.blocks.length, expected.blocks.length,
"The correct number of blocks were found in this bucket.");
for (let j = 0; j < found.blocks.length; j++) {
is(found.blocks[j].x, expected.blocks[j].x,
"The expected block X position is correct for this frame.");
is(found.blocks[j].y, expected.blocks[j].y,
"The expected block Y position is correct for this frame.");
is(found.blocks[j].width, expected.blocks[j].width,
"The expected block width is correct for this frame.");
is(found.blocks[j].height, expected.blocks[j].height,
"The expected block height is correct for this frame.");
is(found.blocks[j].text, expected.blocks[j].text,
"The expected block text is correct for this frame.");
}
}
}
var TEST_DATA = synthesizeProfileForTest([{
frames: [{
location: "M"
}, {
location: "N",
}, {
location: "P"
}],
time: 50,
}, {
frames: [{
location: "A"
}, {
location: "B",
}, {
location: "C"
}],
time: 100,
}, {
frames: [{
location: "A"
}, {
location: "B",
}, {
location: "D"
}],
time: 210,
}, {
frames: [{
location: "A"
}, {
location: "E",
}, {
location: "F"
}],
time: 330,
}, {
frames: [{
location: "A"
}, {
location: "B",
}, {
location: "C"
}],
time: 460,
}, {
frames: [{
location: "X"
}, {
location: "Y",
}, {
location: "Z"
}],
time: 500
}]);
var EXPECTED_OUTPUT = [{
blocks: []
}, {
blocks: []
}, {
blocks: [{
startTime: 50,
frameKey: "A",
x: 50,
y: 0,
width: 410,
height: 15,
text: "A"
}]
}, {
blocks: [{
startTime: 50,
frameKey: "B",
x: 50,
y: 15,
width: 160,
height: 15,
text: "B"
}, {
startTime: 330,
frameKey: "B",
x: 330,
y: 15,
width: 130,
height: 15,
text: "B"
}]
}, {
blocks: [{
startTime: 50,
frameKey: "C",
x: 50,
y: 30,
width: 50,
height: 15,
text: "C"
}, {
startTime: 330,
frameKey: "C",
x: 330,
y: 30,
width: 130,
height: 15,
text: "C"
}]
}, {
blocks: [{
startTime: 100,
frameKey: "D",
x: 100,
y: 30,
width: 110,
height: 15,
text: "D"
}, {
startTime: 460,
frameKey: "X",
x: 460,
y: 0,
width: 40,
height: 15,
text: "X"
}]
}, {
blocks: [{
startTime: 210,
frameKey: "E",
x: 210,
y: 15,
width: 120,
height: 15,
text: "E"
}, {
startTime: 460,
frameKey: "Y",
x: 460,
y: 15,
width: 40,
height: 15,
text: "Y"
}]
}, {
blocks: [{
startTime: 210,
frameKey: "F",
x: 210,
y: 30,
width: 120,
height: 15,
text: "F"
}, {
startTime: 460,
frameKey: "Z",
x: 460,
y: 30,
width: 40,
height: 15,
text: "Z"
}]
}, {
blocks: []
}, {
blocks: []
}, {
blocks: []
}, {
blocks: []
}, {
blocks: []
}, {
blocks: []
}, {
blocks: [{
startTime: 0,
frameKey: "M",
x: 0,
y: 0,
width: 50,
height: 15,
text: "M"
}]
}, {
blocks: [{
startTime: 0,
frameKey: "N",
x: 0,
y: 15,
width: 50,
height: 15,
text: "N"
}]
}, {
blocks: []
}, {
blocks: [{
startTime: 0,
frameKey: "P",
x: 0,
y: 30,
width: 50,
height: 15,
text: "P"
}]
}, {
blocks: []
}, {
blocks: []
}];