2015-01-11 14:54:26 +00:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
// Tests that selections in the flame graph widget work properly.
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var TEST_DATA = [{ color: "#f00", blocks: [{ x: 0, y: 0, width: 50, height: 20, text: "FOO" }, { x: 50, y: 0, width: 100, height: 20, text: "BAR" }] }, { color: "#00f", blocks: [{ x: 0, y: 30, width: 30, height: 20, text: "BAZ" }] }];
|
|
|
|
var TEST_BOUNDS = { startTime: 0, endTime: 150 };
|
|
|
|
var TEST_WIDTH = 200;
|
|
|
|
var TEST_HEIGHT = 100;
|
2015-01-11 14:54:26 +00:00
|
|
|
|
2015-09-21 17:04:18 +00:00
|
|
|
var {FlameGraph} = require("devtools/client/shared/widgets/FlameGraph");
|
2015-01-11 14:54:26 +00:00
|
|
|
|
2015-01-26 07:33:00 +00:00
|
|
|
add_task(function*() {
|
2015-11-10 19:48:51 +00:00
|
|
|
yield addTab("about:blank");
|
2015-01-11 14:54:26 +00:00
|
|
|
yield performTest();
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
});
|
|
|
|
|
|
|
|
function* performTest() {
|
|
|
|
let [host, win, doc] = yield createHost();
|
|
|
|
doc.body.setAttribute("style", "position: fixed; width: 100%; height: 100%; margin: 0;");
|
|
|
|
|
|
|
|
let graph = new FlameGraph(doc.body, 1);
|
|
|
|
graph.fixedWidth = TEST_WIDTH;
|
|
|
|
graph.fixedHeight = TEST_HEIGHT;
|
2015-03-11 20:01:19 +00:00
|
|
|
graph.horizontalPanThreshold = 0;
|
|
|
|
graph.verticalPanThreshold = 0;
|
2015-01-11 14:54:26 +00:00
|
|
|
|
|
|
|
yield graph.ready();
|
|
|
|
|
|
|
|
testGraph(graph);
|
|
|
|
|
2015-02-27 00:08:28 +00:00
|
|
|
yield graph.destroy();
|
2015-01-11 14:54:26 +00:00
|
|
|
host.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGraph(graph) {
|
2015-01-22 17:20:55 +00:00
|
|
|
graph.setData({ data: TEST_DATA, bounds: TEST_BOUNDS });
|
2015-01-11 14:54:26 +00:00
|
|
|
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime, 0,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (1).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime, 150,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (1).");
|
|
|
|
|
|
|
|
scroll(graph, 200, HORIZONTAL_AXIS, 10);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 75,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (2).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 150,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (2).");
|
|
|
|
|
|
|
|
scroll(graph, -200, HORIZONTAL_AXIS, 10);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 37,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (3).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 112,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (3).");
|
|
|
|
|
|
|
|
scroll(graph, 200, VERTICAL_AXIS, TEST_WIDTH / 2);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 34,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (4).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 115,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (4).");
|
|
|
|
|
|
|
|
scroll(graph, -200, VERTICAL_AXIS, TEST_WIDTH / 2);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 37,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (5).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 112,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (5).");
|
|
|
|
|
|
|
|
dragStart(graph, TEST_WIDTH / 2);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 37,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (6).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 112,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (6).");
|
|
|
|
|
|
|
|
hover(graph, TEST_WIDTH / 2 - 10);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 41,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (7).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 116,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (7).");
|
|
|
|
|
|
|
|
dragStop(graph, 10);
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().startTime | 0, 71,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection start boundary is correct (8).");
|
2015-01-22 17:20:55 +00:00
|
|
|
is(graph.getViewRange().endTime | 0, 145,
|
2015-01-11 14:54:26 +00:00
|
|
|
"The selection end boundary is correct (8).");
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventUtils just doesn't work!
|
|
|
|
|
|
|
|
function hover(graph, x, y = 1) {
|
|
|
|
x /= window.devicePixelRatio;
|
|
|
|
y /= window.devicePixelRatio;
|
2015-05-05 18:47:33 +00:00
|
|
|
graph._onMouseMove({ testX: x, testY: y });
|
2015-01-11 14:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragStart(graph, x, y = 1) {
|
|
|
|
x /= window.devicePixelRatio;
|
|
|
|
y /= window.devicePixelRatio;
|
2015-05-05 18:47:33 +00:00
|
|
|
graph._onMouseMove({ testX: x, testY: y });
|
|
|
|
graph._onMouseDown({ testX: x, testY: y });
|
2015-01-11 14:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragStop(graph, x, y = 1) {
|
|
|
|
x /= window.devicePixelRatio;
|
|
|
|
y /= window.devicePixelRatio;
|
2015-05-05 18:47:33 +00:00
|
|
|
graph._onMouseMove({ testX: x, testY: y });
|
|
|
|
graph._onMouseUp({ testX: x, testY: y });
|
2015-01-11 14:54:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var HORIZONTAL_AXIS = 1;
|
|
|
|
var VERTICAL_AXIS = 2;
|
2015-01-11 14:54:26 +00:00
|
|
|
|
|
|
|
function scroll(graph, wheel, axis, x, y = 1) {
|
|
|
|
x /= window.devicePixelRatio;
|
|
|
|
y /= window.devicePixelRatio;
|
2015-05-05 18:47:33 +00:00
|
|
|
graph._onMouseMove({ testX: x, testY: y });
|
|
|
|
graph._onMouseWheel({ testX: x, testY: y, axis, detail: wheel, axis,
|
2015-01-11 14:54:26 +00:00
|
|
|
HORIZONTAL_AXIS,
|
|
|
|
VERTICAL_AXIS
|
|
|
|
});
|
|
|
|
}
|