michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Javascript library for dynamically generating a simple SVG/SMIL reftest michael@0: * with several copies of the same animation, each seeked to a different time. michael@0: */ michael@0: michael@0: // Global variables michael@0: const START_TIMES = [ "4.0s", "3.0s", "2.7s", michael@0: "2.25s", "2.01s", "1.5s", michael@0: "1.4s", "1.0s", "0.5s" ]; michael@0: michael@0: const X_POSNS = [ "20px", "70px", "120px", michael@0: "20px", "70px", "120px", michael@0: "20px", "70px", "120px" ]; michael@0: michael@0: const Y_POSNS = [ "20px", "20px", "20px", michael@0: "70px", "70px", "70px", michael@0: "120px", "120px", "120px" ]; michael@0: michael@0: const DURATION = "2s"; michael@0: const SNAPSHOT_TIME ="3"; michael@0: const SVGNS = "http://www.w3.org/2000/svg"; michael@0: michael@0: // Convenience wrapper using testAnimatedGrid to make 15pt-by-15pt rects michael@0: function testAnimatedRectGrid(animationTagName, animationAttrHashList) { michael@0: var targetTagName = "rect"; michael@0: var targetAttrHash = {"width" : "15px", michael@0: "height" : "15px" }; michael@0: testAnimatedGrid(targetTagName, targetAttrHash, michael@0: animationTagName, animationAttrHashList); michael@0: } michael@0: michael@0: // Convenience wrapper using testAnimatedGrid to make grid of text michael@0: function testAnimatedTextGrid(animationTagName, animationAttrHashList) { michael@0: var targetTagName = "text"; michael@0: var targetAttrHash = { }; michael@0: testAnimatedGrid(targetTagName, targetAttrHash, michael@0: animationTagName, animationAttrHashList); michael@0: } michael@0: michael@0: // Generates a visual grid of elements of type "targetTagName", with the michael@0: // attribute values given in targetAttrHash. Each generated element has michael@0: // exactly one child -- an animation element of type "animationTagName", with michael@0: // the attribute values given in animationAttrHash. michael@0: function testAnimatedGrid(targetTagName, targetAttrHash, michael@0: animationTagName, animationAttrHashList) { michael@0: // SANITY CHECK michael@0: const numElementsToMake = START_TIMES.length; michael@0: if (X_POSNS.length != numElementsToMake || michael@0: Y_POSNS.length != numElementsToMake) { michael@0: return; michael@0: } michael@0: michael@0: for (var i = 0; i < animationAttrHashList.length; i++) { michael@0: var animationAttrHash = animationAttrHashList[i]; michael@0: // Default to fill="freeze" so we can test the final value of the animation michael@0: if (!animationAttrHash["fill"]) { michael@0: animationAttrHash["fill"] = "freeze"; michael@0: } michael@0: } michael@0: michael@0: // Build the grid! michael@0: var svg = document.documentElement; michael@0: for (var i = 0; i < numElementsToMake; i++) { michael@0: // Build target & animation elements michael@0: var targetElem = buildElement(targetTagName, targetAttrHash); michael@0: for (var j = 0; j < animationAttrHashList.length; j++) { michael@0: var animationAttrHash = animationAttrHashList[j]; michael@0: var animElem = buildElement(animationTagName, animationAttrHash); michael@0: michael@0: // Customize them using global constant values michael@0: targetElem.setAttribute("x", X_POSNS[i]); michael@0: targetElem.setAttribute("y", Y_POSNS[i]); michael@0: animElem.setAttribute("begin", START_TIMES[i]); michael@0: animElem.setAttribute("dur", DURATION); michael@0: michael@0: // Append to target michael@0: targetElem.appendChild(animElem); michael@0: } michael@0: // Insert target into DOM michael@0: svg.appendChild(targetElem); michael@0: } michael@0: michael@0: // Take snapshot michael@0: setTimeAndSnapshot(SNAPSHOT_TIME, true); michael@0: } michael@0: michael@0: function buildElement(tagName, attrHash) { michael@0: var elem = document.createElementNS(SVGNS, tagName); michael@0: for (var attrName in attrHash) { michael@0: var attrValue = attrHash[attrName]; michael@0: elem.setAttribute(attrName, attrValue); michael@0: } michael@0: // If we're creating a text node, populate it with some text. michael@0: if (tagName == "text") { michael@0: elem.appendChild(document.createTextNode("abc")); michael@0: } michael@0: return elem; michael@0: }