Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <!-- |
michael@0 | 3 | https://bugzilla.mozilla.org/show_bug.cgi?id=436418 |
michael@0 | 4 | --> |
michael@0 | 5 | <head> |
michael@0 | 6 | <title>Test for animateMotion acceptance of invalid values</title> |
michael@0 | 7 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | <script type="text/javascript" src="smilTestUtils.js" /> |
michael@0 | 9 | <script type="text/javascript" src="smilAnimateMotionValueLists.js" /> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=436418">Mozilla Bug 436418</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="visibility: hidden"> |
michael@0 | 16 | <svg xmlns="http://www.w3.org/2000/svg" id="svg" |
michael@0 | 17 | width="200px" height="200px" |
michael@0 | 18 | onload="this.pauseAnimations()"> |
michael@0 | 19 | <rect id="rect" x="20" y="20" width="200" height="200"/> |
michael@0 | 20 | </svg> |
michael@0 | 21 | </div> |
michael@0 | 22 | <pre id="test"> |
michael@0 | 23 | <script class="testbody" type="text/javascript"> |
michael@0 | 24 | <![CDATA[ |
michael@0 | 25 | |
michael@0 | 26 | // Constant strings (& string-arrays) |
michael@0 | 27 | const SVGNS = "http://www.w3.org/2000/svg"; |
michael@0 | 28 | const XLINKNS = "http://www.w3.org/1999/xlink"; |
michael@0 | 29 | |
michael@0 | 30 | // Constant objects |
michael@0 | 31 | const gSvg = document.getElementById("svg"); |
michael@0 | 32 | const gRect = document.getElementById("rect"); |
michael@0 | 33 | const gUnAnimatedCTM = gRect.getCTM(); |
michael@0 | 34 | |
michael@0 | 35 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 36 | |
michael@0 | 37 | function createAnim() |
michael@0 | 38 | { |
michael@0 | 39 | var anim = document.createElementNS(SVGNS, "animateMotion"); |
michael@0 | 40 | anim.setAttribute("dur", "2s"); |
michael@0 | 41 | return gRect.appendChild(anim); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function removeElem(aElem) |
michael@0 | 45 | { |
michael@0 | 46 | aElem.parentNode.removeChild(aElem); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function testAttr(aAttrName, aAttrValueArray, aIsValid) |
michael@0 | 50 | { |
michael@0 | 51 | var componentsToCheck; |
michael@0 | 52 | |
michael@0 | 53 | for (var i in aAttrValueArray) { |
michael@0 | 54 | var curVal = aAttrValueArray[i]; |
michael@0 | 55 | var anim = createAnim(); |
michael@0 | 56 | anim.setAttribute(aAttrName, curVal); |
michael@0 | 57 | if (aAttrName == "rotate") { |
michael@0 | 58 | // Apply a diagonal translation (so rotate='auto' will have an effect) |
michael@0 | 59 | // and just test the rotation matrix components |
michael@0 | 60 | anim.setAttribute("values", "0 0; 50 50"); |
michael@0 | 61 | componentsToCheck = CTMUtil.CTM_COMPONENTS_ROTATE; |
michael@0 | 62 | } else { |
michael@0 | 63 | // Apply a supplementary rotation to make sure that we don't apply it if |
michael@0 | 64 | // our value is rejected. |
michael@0 | 65 | anim.setAttribute("rotate", Math.PI/4); |
michael@0 | 66 | componentsToCheck = CTMUtil.CTM_COMPONENTS_ALL; |
michael@0 | 67 | if (aAttrName == "keyPoints") { |
michael@0 | 68 | // Add three times so we can test a greater range of values for |
michael@0 | 69 | // keyPoints |
michael@0 | 70 | anim.setAttribute("values", "0 0; 25 25; 50 50"); |
michael@0 | 71 | anim.setAttribute("keyTimes", "0; 0.5; 1"); |
michael@0 | 72 | anim.setAttribute("calcMode", "discrete"); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | var curCTM = gRect.getCTM(); |
michael@0 | 77 | if (aIsValid) { |
michael@0 | 78 | var errMsg = "CTM should have changed when applying animateMotion " + |
michael@0 | 79 | "with '" + aAttrName + "' set to valid value '" + curVal + "'"; |
michael@0 | 80 | CTMUtil.assertCTMNotEqual(curCTM, gUnAnimatedCTM, componentsToCheck, |
michael@0 | 81 | errMsg, false); |
michael@0 | 82 | } else { |
michael@0 | 83 | var errMsg = "CTM should not have changed when applying animateMotion " + |
michael@0 | 84 | "with '" + aAttrName + "' set to invalid value '" + curVal + "'"; |
michael@0 | 85 | CTMUtil.assertCTMEqual(curCTM, gUnAnimatedCTM, componentsToCheck, |
michael@0 | 86 | errMsg, false); |
michael@0 | 87 | } |
michael@0 | 88 | removeElem(anim); |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function createPath(aPathDescription) |
michael@0 | 93 | { |
michael@0 | 94 | var path = document.createElementNS(SVGNS, "path"); |
michael@0 | 95 | path.setAttribute("d", aPathDescription); |
michael@0 | 96 | path.setAttribute("id", "thePath"); |
michael@0 | 97 | return gSvg.appendChild(path); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function createMpath(aAnimElement) |
michael@0 | 101 | { |
michael@0 | 102 | var mpath = document.createElementNS(SVGNS, "mpath"); |
michael@0 | 103 | mpath.setAttributeNS(XLINKNS, "href", "#thePath"); |
michael@0 | 104 | return aAnimElement.appendChild(mpath); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function testMpathElem(aPathValueArray, aIsValid) |
michael@0 | 108 | { |
michael@0 | 109 | for (var i in aPathValueArray) { |
michael@0 | 110 | var curVal = aPathValueArray[i]; |
michael@0 | 111 | var anim = createAnim(); |
michael@0 | 112 | var mpath = createMpath(anim); |
michael@0 | 113 | var path = createPath(curVal); |
michael@0 | 114 | |
michael@0 | 115 | // Apply a supplementary rotation to make sure that we don't apply it if |
michael@0 | 116 | // our value is rejected. |
michael@0 | 117 | anim.setAttribute("rotate", Math.PI/4); |
michael@0 | 118 | componentsToCheck = CTMUtil.CTM_COMPONENTS_ALL; |
michael@0 | 119 | |
michael@0 | 120 | if (aIsValid) { |
michael@0 | 121 | var errMsg = "CTM should have changed when applying animateMotion " + |
michael@0 | 122 | "with mpath linking to a path with valid value '" + curVal + "'"; |
michael@0 | 123 | |
michael@0 | 124 | CTMUtil.assertCTMNotEqual(gRect.getCTM(), gUnAnimatedCTM, |
michael@0 | 125 | componentsToCheck, errMsg, false); |
michael@0 | 126 | } else { |
michael@0 | 127 | var errMsg = "CTM should not have changed when applying animateMotion " + |
michael@0 | 128 | "with mpath linking to a path with invalid value '" + curVal + "'"; |
michael@0 | 129 | CTMUtil.assertCTMEqual(gRect.getCTM(), gUnAnimatedCTM, |
michael@0 | 130 | componentsToCheck, errMsg, false); |
michael@0 | 131 | } |
michael@0 | 132 | removeElem(anim); |
michael@0 | 133 | removeElem(path); |
michael@0 | 134 | removeElem(mpath); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // Main Function |
michael@0 | 139 | function main() |
michael@0 | 140 | { |
michael@0 | 141 | // Start out with document paused |
michael@0 | 142 | var svg = SMILUtil.getSVGRoot(); |
michael@0 | 143 | ok(svg.animationsPaused(), "should be paused by <svg> load handler"); |
michael@0 | 144 | is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
michael@0 | 145 | |
michael@0 | 146 | testAttr("values", gValidValues, true); |
michael@0 | 147 | testAttr("values", gInvalidValues, false); |
michael@0 | 148 | |
michael@0 | 149 | testAttr("rotate", gValidRotate, true); |
michael@0 | 150 | testAttr("rotate", gInvalidRotate, false); |
michael@0 | 151 | |
michael@0 | 152 | testAttr("to", gValidToBy, true); |
michael@0 | 153 | testAttr("to", gInvalidToBy, false); |
michael@0 | 154 | |
michael@0 | 155 | testAttr("by", gValidToBy, true); |
michael@0 | 156 | testAttr("by", gInvalidToBy, false); |
michael@0 | 157 | |
michael@0 | 158 | testAttr("path", gValidPath, true); |
michael@0 | 159 | testAttr("path", gInvalidPath, false); |
michael@0 | 160 | testAttr("path", gValidPathWithErrors, true); |
michael@0 | 161 | |
michael@0 | 162 | testAttr("keyPoints", gValidKeyPoints, true); |
michael@0 | 163 | testAttr("keyPoints", gInvalidKeyPoints, false); |
michael@0 | 164 | |
michael@0 | 165 | testMpathElem(gValidPath, true); |
michael@0 | 166 | testMpathElem(gInvalidPath, false); |
michael@0 | 167 | |
michael@0 | 168 | SimpleTest.finish(); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | window.addEventListener("load", main, false); |
michael@0 | 172 | ]]> |
michael@0 | 173 | </script> |
michael@0 | 174 | </pre> |
michael@0 | 175 | </body> |
michael@0 | 176 | </html> |