2015-03-23 15:01:00 +03:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Tests the integration between CubicBezierWidget and CubicBezierPresets
|
|
|
|
|
|
|
|
const {
|
|
|
|
CubicBezierWidget,
|
2015-09-21 20:04:18 +03:00
|
|
|
} = require("devtools/client/shared/widgets/CubicBezierWidget");
|
|
|
|
const {
|
|
|
|
PRESETS,
|
|
|
|
} = require("devtools/client/shared/widgets/CubicBezierPresets");
|
2015-03-23 15:01:00 +03:00
|
|
|
|
2017-07-10 09:46:23 +03:00
|
|
|
const TEST_URI = CHROME_URL_ROOT + "doc_cubic-bezier-01.html";
|
2016-07-11 11:26:02 +03:00
|
|
|
|
2018-03-11 13:05:00 +03:00
|
|
|
add_task(async function() {
|
2018-06-01 13:36:09 +03:00
|
|
|
const [host, win, doc] = await createHost("bottom", TEST_URI);
|
2015-03-23 15:01:00 +03:00
|
|
|
|
2018-06-01 13:36:09 +03:00
|
|
|
const container = doc.querySelector("#cubic-bezier-container");
|
|
|
|
const w = new CubicBezierWidget(
|
|
|
|
container,
|
2015-03-23 15:01:00 +03:00
|
|
|
PRESETS["ease-in"]["ease-in-sine"]
|
|
|
|
);
|
|
|
|
w.presets.refreshMenu(PRESETS["ease-in"]["ease-in-sine"]);
|
|
|
|
|
2018-06-01 13:36:09 +03:00
|
|
|
const rect = w.curve.getBoundingClientRect();
|
2015-03-23 15:01:00 +03:00
|
|
|
rect.graphTop = rect.height * w.bezierCanvas.padding[0];
|
|
|
|
|
2018-03-11 13:05:00 +03:00
|
|
|
await adjustingBezierUpdatesPreset(w, win, doc, rect);
|
|
|
|
await selectingPresetUpdatesBezier(w, win, doc, rect);
|
2015-03-23 15:01:00 +03:00
|
|
|
|
|
|
|
w.destroy();
|
|
|
|
host.destroy();
|
|
|
|
});
|
|
|
|
|
2018-03-11 13:05:00 +03:00
|
|
|
function adjustingBezierUpdatesPreset(widget, win, doc, rect) {
|
2015-03-23 15:01:00 +03:00
|
|
|
info("Checking that changing the bezier refreshes the preset menu");
|
|
|
|
|
|
|
|
is(
|
|
|
|
widget.presets.activeCategory,
|
|
|
|
doc.querySelector("#ease-in"),
|
|
|
|
"The selected category is ease-in"
|
|
|
|
);
|
|
|
|
|
|
|
|
is(
|
|
|
|
widget.presets._activePreset,
|
|
|
|
doc.querySelector("#ease-in-sine"),
|
|
|
|
"The selected preset is ease-in-sine"
|
|
|
|
);
|
|
|
|
|
|
|
|
info("Generating custom bezier curve by dragging");
|
|
|
|
widget._onPointMouseDown({ target: widget.p1 });
|
|
|
|
doc.onmousemove({ pageX: rect.left, pageY: rect.graphTop });
|
|
|
|
doc.onmouseup();
|
|
|
|
|
|
|
|
is(
|
|
|
|
widget.presets.activeCategory,
|
|
|
|
doc.querySelector("#ease-in"),
|
|
|
|
"The selected category is still ease-in"
|
|
|
|
);
|
|
|
|
|
|
|
|
is(widget.presets._activePreset, null, "There is no active preset");
|
2016-05-17 21:25:54 +03:00
|
|
|
}
|
2015-03-23 15:01:00 +03:00
|
|
|
|
2018-03-11 13:05:00 +03:00
|
|
|
async function selectingPresetUpdatesBezier(widget, win, doc, rect) {
|
2015-03-23 15:01:00 +03:00
|
|
|
info("Checking that selecting a preset updates bezier curve");
|
|
|
|
|
|
|
|
info("Listening for the new coordinates event");
|
2018-06-01 13:36:09 +03:00
|
|
|
const onNewCoordinates = widget.presets.once("new-coordinates");
|
|
|
|
const onUpdated = widget.once("updated");
|
2015-03-23 15:01:00 +03:00
|
|
|
|
|
|
|
info("Click a preset");
|
2018-06-01 13:36:09 +03:00
|
|
|
const preset = doc.querySelector("#ease-in-sine");
|
2015-03-23 15:01:00 +03:00
|
|
|
widget.presets._onPresetClick({ currentTarget: preset });
|
|
|
|
|
2018-03-11 13:05:00 +03:00
|
|
|
await onNewCoordinates;
|
2015-03-23 15:01:00 +03:00
|
|
|
ok(true, "The preset widget fired the new-coordinates event");
|
|
|
|
|
2018-06-01 13:36:09 +03:00
|
|
|
const bezier = await onUpdated;
|
2015-03-23 15:01:00 +03:00
|
|
|
ok(true, "The bezier canvas fired the updated event");
|
|
|
|
|
|
|
|
is(
|
|
|
|
bezier.P1[0],
|
|
|
|
preset.coordinates[0],
|
|
|
|
"The new P1 time coordinate is correct"
|
|
|
|
);
|
|
|
|
is(
|
|
|
|
bezier.P1[1],
|
|
|
|
preset.coordinates[1],
|
|
|
|
"The new P1 progress coordinate is correct"
|
|
|
|
);
|
|
|
|
is(bezier.P2[0], preset.coordinates[2], "P2 time coordinate is correct ");
|
|
|
|
is(bezier.P2[1], preset.coordinates[3], "P2 progress coordinate is correct");
|
|
|
|
}
|