browser_animation_emitMutations.js (2331B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the AnimationsActor emits events about changed animations on a 7 // node after getAnimationPlayersForNode was called on that node. 8 9 add_task(async function () { 10 const { target, walker, animations } = await initAnimationsFrontForUrl( 11 MAIN_DOMAIN + "animation.html" 12 ); 13 14 info("Retrieve a non-animated node"); 15 const node = await walker.querySelector(walker.rootNode, ".not-animated"); 16 17 info("Retrieve the animation player for the node"); 18 const players = await animations.getAnimationPlayersForNode(node); 19 is(players.length, 0, "The node has no animation players"); 20 21 info("Listen for new animations"); 22 let onMutations = once(animations, "mutations"); 23 24 info("Add a couple of animation on the node"); 25 await node.modifyAttributes([ 26 { attributeName: "class", newValue: "multiple-animations" }, 27 ]); 28 let changes = await onMutations; 29 30 ok(true, "The mutations event was emitted"); 31 is(changes.length, 2, "There are 2 changes in the mutation event"); 32 ok( 33 changes.every(({ type }) => type === "added"), 34 "Both changes are additions" 35 ); 36 37 const names = changes.map(c => c.player.initialState.name).sort(); 38 is(names[0], "glow", "The animation 'glow' was added"); 39 is(names[1], "move", "The animation 'move' was added"); 40 41 info("Store the 2 new players for comparing later"); 42 const p1 = changes[0].player; 43 const p2 = changes[1].player; 44 45 info("Listen for removed animations"); 46 onMutations = once(animations, "mutations"); 47 48 info("Remove the animation css class on the node"); 49 await node.modifyAttributes([ 50 { attributeName: "class", newValue: "not-animated" }, 51 ]); 52 53 changes = await onMutations; 54 55 ok(true, "The mutations event was emitted"); 56 is(changes.length, 2, "There are 2 changes in the mutation event"); 57 ok( 58 changes.every(({ type }) => type === "removed"), 59 "Both are removals" 60 ); 61 ok( 62 changes[0].player === p1 || changes[0].player === p2, 63 "The first removed player was one of the previously added players" 64 ); 65 ok( 66 changes[1].player === p1 || changes[1].player === p2, 67 "The second removed player was one of the previously added players" 68 ); 69 70 await target.destroy(); 71 gBrowser.removeCurrentTab(); 72 });