layout/reftests/svg/smil/smil-grid.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /* Javascript library for dynamically generating a simple SVG/SMIL reftest
michael@0 8 * with several copies of the same animation, each seeked to a different time.
michael@0 9 */
michael@0 10
michael@0 11 // Global variables
michael@0 12 const START_TIMES = [ "4.0s", "3.0s", "2.7s",
michael@0 13 "2.25s", "2.01s", "1.5s",
michael@0 14 "1.4s", "1.0s", "0.5s" ];
michael@0 15
michael@0 16 const X_POSNS = [ "20px", "70px", "120px",
michael@0 17 "20px", "70px", "120px",
michael@0 18 "20px", "70px", "120px" ];
michael@0 19
michael@0 20 const Y_POSNS = [ "20px", "20px", "20px",
michael@0 21 "70px", "70px", "70px",
michael@0 22 "120px", "120px", "120px" ];
michael@0 23
michael@0 24 const DURATION = "2s";
michael@0 25 const SNAPSHOT_TIME ="3";
michael@0 26 const SVGNS = "http://www.w3.org/2000/svg";
michael@0 27
michael@0 28 // Convenience wrapper using testAnimatedGrid to make 15pt-by-15pt rects
michael@0 29 function testAnimatedRectGrid(animationTagName, animationAttrHashList) {
michael@0 30 var targetTagName = "rect";
michael@0 31 var targetAttrHash = {"width" : "15px",
michael@0 32 "height" : "15px" };
michael@0 33 testAnimatedGrid(targetTagName, targetAttrHash,
michael@0 34 animationTagName, animationAttrHashList);
michael@0 35 }
michael@0 36
michael@0 37 // Convenience wrapper using testAnimatedGrid to make grid of text
michael@0 38 function testAnimatedTextGrid(animationTagName, animationAttrHashList) {
michael@0 39 var targetTagName = "text";
michael@0 40 var targetAttrHash = { };
michael@0 41 testAnimatedGrid(targetTagName, targetAttrHash,
michael@0 42 animationTagName, animationAttrHashList);
michael@0 43 }
michael@0 44
michael@0 45 // Generates a visual grid of elements of type "targetTagName", with the
michael@0 46 // attribute values given in targetAttrHash. Each generated element has
michael@0 47 // exactly one child -- an animation element of type "animationTagName", with
michael@0 48 // the attribute values given in animationAttrHash.
michael@0 49 function testAnimatedGrid(targetTagName, targetAttrHash,
michael@0 50 animationTagName, animationAttrHashList) {
michael@0 51 // SANITY CHECK
michael@0 52 const numElementsToMake = START_TIMES.length;
michael@0 53 if (X_POSNS.length != numElementsToMake ||
michael@0 54 Y_POSNS.length != numElementsToMake) {
michael@0 55 return;
michael@0 56 }
michael@0 57
michael@0 58 for (var i = 0; i < animationAttrHashList.length; i++) {
michael@0 59 var animationAttrHash = animationAttrHashList[i];
michael@0 60 // Default to fill="freeze" so we can test the final value of the animation
michael@0 61 if (!animationAttrHash["fill"]) {
michael@0 62 animationAttrHash["fill"] = "freeze";
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 // Build the grid!
michael@0 67 var svg = document.documentElement;
michael@0 68 for (var i = 0; i < numElementsToMake; i++) {
michael@0 69 // Build target & animation elements
michael@0 70 var targetElem = buildElement(targetTagName, targetAttrHash);
michael@0 71 for (var j = 0; j < animationAttrHashList.length; j++) {
michael@0 72 var animationAttrHash = animationAttrHashList[j];
michael@0 73 var animElem = buildElement(animationTagName, animationAttrHash);
michael@0 74
michael@0 75 // Customize them using global constant values
michael@0 76 targetElem.setAttribute("x", X_POSNS[i]);
michael@0 77 targetElem.setAttribute("y", Y_POSNS[i]);
michael@0 78 animElem.setAttribute("begin", START_TIMES[i]);
michael@0 79 animElem.setAttribute("dur", DURATION);
michael@0 80
michael@0 81 // Append to target
michael@0 82 targetElem.appendChild(animElem);
michael@0 83 }
michael@0 84 // Insert target into DOM
michael@0 85 svg.appendChild(targetElem);
michael@0 86 }
michael@0 87
michael@0 88 // Take snapshot
michael@0 89 setTimeAndSnapshot(SNAPSHOT_TIME, true);
michael@0 90 }
michael@0 91
michael@0 92 function buildElement(tagName, attrHash) {
michael@0 93 var elem = document.createElementNS(SVGNS, tagName);
michael@0 94 for (var attrName in attrHash) {
michael@0 95 var attrValue = attrHash[attrName];
michael@0 96 elem.setAttribute(attrName, attrValue);
michael@0 97 }
michael@0 98 // If we're creating a text node, populate it with some text.
michael@0 99 if (tagName == "text") {
michael@0 100 elem.appendChild(document.createTextNode("abc"));
michael@0 101 }
michael@0 102 return elem;
michael@0 103 }

mercurial