mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 07:48:38 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
113
devtools/client/shared/test/browser_flame-graph-05.js
Normal file
113
devtools/client/shared/test/browser_flame-graph-05.js
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Tests that flame graph widget has proper keyboard support.
|
||||
|
||||
const 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" }
|
||||
]
|
||||
}
|
||||
];
|
||||
const TEST_BOUNDS = { startTime: 0, endTime: 150 };
|
||||
const TEST_DPI_DENSITIY = 2;
|
||||
|
||||
const KEY_CODE_UP = 38;
|
||||
const KEY_CODE_LEFT = 37;
|
||||
const KEY_CODE_RIGHT = 39;
|
||||
|
||||
var {FlameGraph} = require("devtools/client/shared/widgets/FlameGraph");
|
||||
|
||||
add_task(function* () {
|
||||
yield addTab("about:blank");
|
||||
yield performTest();
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
|
||||
function* performTest() {
|
||||
let [host,, doc] = yield createHost();
|
||||
doc.body.setAttribute("style",
|
||||
"position: fixed; width: 100%; height: 100%; margin: 0;");
|
||||
|
||||
let graph = new FlameGraph(doc.body, TEST_DPI_DENSITIY);
|
||||
yield graph.ready();
|
||||
|
||||
yield testGraph(host, graph);
|
||||
|
||||
yield graph.destroy();
|
||||
host.destroy();
|
||||
}
|
||||
|
||||
function* testGraph(host, graph) {
|
||||
graph.setData({ data: TEST_DATA, bounds: TEST_BOUNDS });
|
||||
|
||||
is(graph._selection.start, 0,
|
||||
"The graph's selection start value is initially correct.");
|
||||
is(graph._selection.end, TEST_BOUNDS.endTime * TEST_DPI_DENSITIY,
|
||||
"The graph's selection end value is initially correct.");
|
||||
|
||||
yield pressKeyForTime(graph, KEY_CODE_LEFT, 1000);
|
||||
|
||||
is(graph._selection.start, 0,
|
||||
"The graph's selection start value is correct after pressing LEFT.");
|
||||
ok(graph._selection.end < TEST_BOUNDS.endTime * TEST_DPI_DENSITIY,
|
||||
"The graph's selection end value is correct after pressing LEFT.");
|
||||
|
||||
graph._selection.start = 0;
|
||||
graph._selection.end = TEST_BOUNDS.endTime * TEST_DPI_DENSITIY;
|
||||
info("Graph selection was reset (1).");
|
||||
|
||||
yield pressKeyForTime(graph, KEY_CODE_RIGHT, 1000);
|
||||
|
||||
ok(graph._selection.start > 0,
|
||||
"The graph's selection start value is correct after pressing RIGHT.");
|
||||
is(graph._selection.end, TEST_BOUNDS.endTime * TEST_DPI_DENSITIY,
|
||||
"The graph's selection end value is correct after pressing RIGHT.");
|
||||
|
||||
graph._selection.start = 0;
|
||||
graph._selection.end = TEST_BOUNDS.endTime * TEST_DPI_DENSITIY;
|
||||
info("Graph selection was reset (2).");
|
||||
|
||||
yield pressKeyForTime(graph, KEY_CODE_UP, 1000);
|
||||
|
||||
ok(graph._selection.start > 0,
|
||||
"The graph's selection start value is correct after pressing UP.");
|
||||
ok(graph._selection.end < TEST_BOUNDS.endTime * TEST_DPI_DENSITIY,
|
||||
"The graph's selection end value is correct after pressing UP.");
|
||||
|
||||
let distanceLeft = graph._selection.start;
|
||||
let distanceRight = TEST_BOUNDS.endTime * TEST_DPI_DENSITIY - graph._selection.end;
|
||||
|
||||
ok(Math.abs(distanceRight - distanceLeft) < 0.1,
|
||||
"The graph zoomed correctly towards the center point.");
|
||||
}
|
||||
|
||||
function pressKeyForTime(graph, keyCode, ms) {
|
||||
graph._onKeyDown({
|
||||
keyCode,
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
});
|
||||
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
graph._onKeyUp({
|
||||
keyCode,
|
||||
preventDefault: () => {},
|
||||
stopPropagation: () => {},
|
||||
});
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue