dom/smil/test/test_smilAnimateMotionOverrideRules.xhtml

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <html xmlns="http://www.w3.org/1999/xhtml">
     2 <!--
     3 https://bugzilla.mozilla.org/show_bug.cgi?id=436418
     4 -->
     5 <head>
     6   <title>Test for overriding of path-defining attributes for animateMotion</title>
     7   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     8   <script type="text/javascript" src="smilTestUtils.js" />
     9   <script type="text/javascript" src="smilAnimateMotionValueLists.js" />
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=436418">Mozilla Bug 436418</a>
    14 <p id="display"></p>
    15 <div id="content" style="visibility: hidden">
    16 <svg xmlns="http://www.w3.org/2000/svg" id="svg"
    17      width="200px" height="200px"
    18      onload="this.pauseAnimations()">
    19   <!-- Paths for mpath to refer to -->
    20   <path id="validPathElem"   d="M10 10 h-10"/>
    21   <path id="invalidPathElem" d="abc"/>
    23   <!-- The rect whose motion is animated -->
    24   <rect id="rect" x="20" y="20" width="200" height="200"/>
    25 </svg>
    26 </div>
    27 <pre id="test">
    28 <script class="testbody" type="text/javascript">
    29 <![CDATA[
    31 // Constant strings (& string-arrays)
    32 const SVGNS   = "http://www.w3.org/2000/svg";
    33 const XLINKNS = "http://www.w3.org/1999/xlink";
    35 // Constant objects
    36 const gSvg = document.getElementById("svg");
    37 const gRect = document.getElementById("rect");
    38 const gUnAnimatedCTM = gRect.getCTM();
    40 // Values for path-defining attributes, and their expected
    41 // CTMs halfway through the animation
    42 var gMpathValidTarget    = "#validPathElem";
    43 var gMpathCTM = CTMUtil.generateCTM([ 5, 10, 0 ]);
    45 var gMpathInvalidTargetA = "#invalidPathElem";
    46 var gMpathInvalidTargetB = "#nonExistentElem";
    48 var gInvalidAttrValue = "i-am-invalid"; // Invalid for all tested attributes
    50 var gPathValidValue = "M20 20 h10";
    51 var gPathCTM = CTMUtil.generateCTM([ 25, 20, 0 ]);
    53 var gValuesValidValue = "30 30; 40 30"
    54 var gValuesCTM = CTMUtil.generateCTM([ 35, 30, 0 ]);
    56 var gFromValidValue = "50 50";
    58 var gByValidValue =   "10 2";
    59 var gPureByCTM = CTMUtil.generateCTM([  5,  1, 0 ]);
    60 var gFromByCTM = CTMUtil.generateCTM([ 55, 51, 0 ]);
    62 var gToValidValue =   "80 60";
    63 var gPureToCTM = CTMUtil.generateCTM([ 40, 30, 0 ]);
    64 var gFromToCTM = CTMUtil.generateCTM([ 65, 55, 0 ]);
    67 SimpleTest.waitForExplicitFinish();
    69 function createAnim()
    70 {
    71   var anim = document.createElementNS(SVGNS, "animateMotion");
    72   return gRect.appendChild(anim);
    73 }
    75 function removeElem(aElem)
    76 {
    77   aElem.parentNode.removeChild(aElem);
    78 }
    80 function createMpath(aAnimElement, aHrefVal)
    81 {
    82   var mpath = document.createElementNS(SVGNS, "mpath");
    83   mpath.setAttributeNS(XLINKNS, "href", aHrefVal);
    84   return aAnimElement.appendChild(mpath);
    85 }
    87 function runTest() {
    88   // Start out with valid values for all path-defining attributes
    89   var attrSettings = {
    90     "mpath"  : gMpathValidTarget,
    91     "path"   : gPathValidValue,
    92     "values" : gValuesValidValue,
    93     "from"   : gFromValidValue,
    94     "to"     : gToValidValue,
    95     "by"     : gByValidValue,
    96   };
    98   // Test that <mpath> overrides everything below it
    99   testAttrSettings(attrSettings, gMpathCTM,
   100                    "<mpath> should win");
   101   var mpathInvalidTargets = [gMpathInvalidTargetA, gMpathInvalidTargetB];
   102   for (var i in mpathInvalidTargets) {
   103     var curInvalidValue = mpathInvalidTargets[i];
   104     attrSettings["mpath"] = curInvalidValue;
   105     testAttrSettings(attrSettings, gUnAnimatedCTM,
   106                      "invalid <mpath> should block animation");
   107   }
   108   delete attrSettings["mpath"];
   110   // Test that 'path' overrides everything below it
   111   testAttrSettings(attrSettings, gPathCTM,
   112                    "'path' should win vs all but mpath");
   113   attrSettings["path"] = gInvalidAttrValue;
   114   testAttrSettings(attrSettings, gUnAnimatedCTM,
   115                    "invalid 'path' should block animation vs all but mpath");
   116   delete attrSettings["path"];
   118   // Test that 'values' overrides everything below it
   119   testAttrSettings(attrSettings, gValuesCTM,
   120                    "'values' should win vs from/by/to");
   121   attrSettings["values"] = gInvalidAttrValue;
   122   testAttrSettings(attrSettings, gUnAnimatedCTM,
   123                    "invalid 'values' should block animation vs from/by/to");
   124   delete attrSettings["values"];
   126   // Test that 'from' & 'to' overrides 'by'
   127   testAttrSettings(attrSettings, gFromToCTM,
   128                    "'from/to' should win vs 'by'");
   129   attrSettings["to"] = gInvalidAttrValue;
   130   testAttrSettings(attrSettings, gUnAnimatedCTM,
   131                    "invalid 'to' should block animation vs 'by'");
   132   delete attrSettings["to"];
   134   // Test that 'from' & 'by' are effective
   135   testAttrSettings(attrSettings, gFromByCTM,
   136                    "'from/by' should be visible");
   137   attrSettings["by"] = gInvalidAttrValue;
   138   testAttrSettings(attrSettings, gUnAnimatedCTM,
   139                    "invalid 'by' should block animation");
   140   delete attrSettings["from"];
   142   // REINSERT "to" & fix up "by" so we can test pure-"to" vs pure-"by"
   143   attrSettings["to"] = gToValidValue;
   144   attrSettings["by"] = gByValidValue;
   145   testAttrSettings(attrSettings, gPureToCTM,
   146                    "pure-'to' should be effective & beat pure-'by'");
   147   attrSettings["to"] = gInvalidAttrValue;
   148   testAttrSettings(attrSettings, gUnAnimatedCTM,
   149                    "invalid pure-'to' should block animation vs pure-'by'");
   150   delete attrSettings["to"];
   152   // Test that pure-"by" is effective
   153   testAttrSettings(attrSettings, gPureByCTM,
   154                    "pure-by should be visible");
   155   attrSettings["by"] = gInvalidAttrValue;
   156   testAttrSettings(attrSettings, gUnAnimatedCTM,
   157                    "invalid 'by' should block animation");
   158   delete attrSettings["by"];
   160   // Make sure that our hash is empty now.
   161   for (var unexpectedKey in attrSettings) {
   162     ok(false, "Unexpected mapping remains in attrSettings: " +
   163        unexpectedKey + "-->" + unexpectedValue);
   164   }
   165 }
   167 function testAttrSettings(aAttrValueHash, aExpectedCTM, aErrMsg)
   168 {
   169   var isDebug = false; // XXdholbert
   170   !isDebug || todo(false, "ENTERING testAttrSettings");
   171   // Set up animateMotion element
   172   var animElement = document.createElementNS(SVGNS, "animateMotion");
   173   animElement.setAttribute("dur", "2s");
   174   for (var attrName in aAttrValueHash) {
   175     !isDebug || todo(false, "setting '" + attrName +"' to '" +
   176                      aAttrValueHash[attrName] +"'");
   177     if (attrName == "mpath") {
   178       createMpath(animElement, aAttrValueHash[attrName]);
   179     } else {
   180       animElement.setAttribute(attrName, aAttrValueHash[attrName]);
   181     }
   182   }
   184   gRect.appendChild(animElement);
   186   // Seek to halfway through animation
   187   SMILUtil.getSVGRoot().setCurrentTime(1); // Seek halfway through animation
   189   // Check CTM against expected value
   190   CTMUtil.assertCTMEqual(gRect.getCTM(), aExpectedCTM,
   191                          CTMUtil.CTM_COMPONENTS_ALL, aErrMsg, false);
   193   // CLEAN UP
   194   SMILUtil.getSVGRoot().setCurrentTime(0);
   195   removeElem(animElement);
   196 }
   198 // Main Function
   199 function main()
   200 {
   201   // Start out with document paused
   202   var svg = SMILUtil.getSVGRoot();
   203   ok(svg.animationsPaused(), "should be paused by <svg> load handler");
   204   is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
   206   runTest();
   207   SimpleTest.finish();
   208 }
   210 window.addEventListener("load", main, false);
   211 ]]>
   212 </script>
   213 </pre>
   214 </body>
   215 </html>

mercurial