browser_cubic-bezier-03.js (2594B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that coordinates can be changed programatically in the CubicBezierWidget 7 8 const { 9 CubicBezierWidget, 10 } = require("resource://devtools/client/shared/widgets/CubicBezierWidget.js"); 11 const { 12 PREDEFINED, 13 } = require("resource://devtools/client/shared/widgets/CubicBezierPresets.js"); 14 15 const TEST_URI = CHROME_URL_ROOT + "doc_cubic-bezier-01.html"; 16 17 add_task(async function () { 18 const { host, doc } = await createHost("bottom", TEST_URI); 19 20 const container = doc.querySelector("#cubic-bezier-container"); 21 const w = new CubicBezierWidget(container, PREDEFINED.linear); 22 23 await coordinatesCanBeChangedByProvidingAnArray(w); 24 await coordinatesCanBeChangedByProvidingAValue(w); 25 26 w.destroy(); 27 host.destroy(); 28 }); 29 30 async function coordinatesCanBeChangedByProvidingAnArray(widget) { 31 info("Listening for the update event"); 32 const onUpdated = widget.once("updated"); 33 34 info("Setting new coordinates"); 35 widget.coordinates = [0, 1, 1, 0]; 36 37 const bezier = await onUpdated; 38 ok(true, "The updated event was fired as a result of setting coordinates"); 39 40 is(bezier.P1[0], 0, "The new P1 time coordinate is correct"); 41 is(bezier.P1[1], 1, "The new P1 progress coordinate is correct"); 42 is(bezier.P2[0], 1, "The new P2 time coordinate is correct"); 43 is(bezier.P2[1], 0, "The new P2 progress coordinate is correct"); 44 } 45 46 async function coordinatesCanBeChangedByProvidingAValue(widget) { 47 info("Listening for the update event"); 48 let onUpdated = widget.once("updated"); 49 50 info("Setting linear css value"); 51 widget.cssCubicBezierValue = "linear"; 52 let bezier = await onUpdated; 53 ok(true, "The updated event was fired as a result of setting cssValue"); 54 55 is(bezier.P1[0], 0, "The new P1 time coordinate is correct"); 56 is(bezier.P1[1], 0, "The new P1 progress coordinate is correct"); 57 is(bezier.P2[0], 1, "The new P2 time coordinate is correct"); 58 is(bezier.P2[1], 1, "The new P2 progress coordinate is correct"); 59 60 info("Setting a custom cubic-bezier css value"); 61 onUpdated = widget.once("updated"); 62 widget.cssCubicBezierValue = "cubic-bezier(.25,-0.5, 1, 1.25)"; 63 bezier = await onUpdated; 64 ok(true, "The updated event was fired as a result of setting cssValue"); 65 66 is(bezier.P1[0], 0.25, "The new P1 time coordinate is correct"); 67 is(bezier.P1[1], -0.5, "The new P1 progress coordinate is correct"); 68 is(bezier.P2[0], 1, "The new P2 time coordinate is correct"); 69 is(bezier.P2[1], 1.25, "The new P2 progress coordinate is correct"); 70 }