dom/smil/test/test_smilHyperlinking.xhtml
author Mike Hommey <mh+mozilla@glandium.org>
Fri, 02 Jun 2017 15:07:58 +0900
changeset 410640 f360dd9d411e7ba61531bed2c32a0981cc6c418a
parent 378281 a9d172aa441447396884068a7d01561843cdf596
child 528458 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Bug 1369622 - Restore static asserts for lack of arguments on some macros. r=froydnj Bug 1368932 removed MOZ_STATIC_ASSERT_VALID_ARG_COUNT because it didn't actually work for large numbers of arguments. But it was kind of useful for macros that expand to something broken when they are given no variadic argument at all. Now that we have a macro that doesn't require tricks to count empty arguments lists, however, we can use straightforward static_asserts instead of a generic macro, which has the side effect of providing more context in the error message.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for hyperlinking</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display:none">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
     onload="this.pauseAnimations()">
  <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for SMIL keySplines **/

/* Global Variables */
const SVGNS="http://www.w3.org/2000/svg";
var gSvg = document.getElementById("svg");
var gAnim;

var gTestStages =
  [ testActive,
    testSeekToFirst,
    testKickStart,
    testKickStartWithUnresolved,
    testFiltering
  ];

SimpleTest.waitForExplicitFinish();

function continueTest()
{
  if (gTestStages.length == 0) {
    SimpleTest.finish();
    return;
  }

  window.location.hash = "";
  if (gAnim) {
    gAnim.remove();
  }
  gAnim = createAnim();
  gSvg.setCurrentTime(0);
  gTestStages.shift()();
}

function createAnim() {
  var anim = document.createElementNS(SVGNS,'animate');
  anim.setAttribute('attributeName','cx');
  anim.setAttribute('from','0');
  anim.setAttribute('to','100');
  anim.setAttribute('dur','1s');
  anim.setAttribute('begin','indefinite');
  anim.setAttribute('id','anim');
  return document.getElementById('circle').appendChild(anim);
}

// Traversing a hyperlink, condition 1:
// 
// "If the target element is active, seek the document time back to the
// (current) begin time of the element. If there are multiple begin times, use
// the begin time that corresponds to the current "begin instance"."
//
function testActive() {
  gAnim.setAttribute('begin','2s; 4s');
  gSvg.setCurrentTime(2.5);
  fireLink(rewindActiveInterval1);
}

function rewindActiveInterval1() {
  is(gSvg.getCurrentTime(), 2,
     "Unexpected time after activating link to animation in the middle of " +
     "first active interval");

  // Seek to second interval
  gSvg.setCurrentTime(4.5);
  fireLink(rewindActiveInterval2);
}

function rewindActiveInterval2() {
  is(gSvg.getCurrentTime(), 4,
     "Unexpected time after activating link to animation in the middle of " +
     "second active interval");

  // Try a negative time
  gAnim.setAttribute("begin", "-0.5");
  gSvg.setCurrentTime(0.2);
  fireLink(rewindActiveIntervalAtZero);
}

function rewindActiveIntervalAtZero() {
  is(gSvg.getCurrentTime(), 0,
     "Unexpected time after activating link to animation in the middle of " +
     "an active interval that overlaps zero");

  continueTest();
}

// Traversing a hyperlink, condition 2:
// 
// "Else if the target element begin time is resolved (i.e., there is any
// resolved time in the list of begin times, or if the begin time was forced by
// an earlier hyperlink or a beginElement() method call), seek the document time
// (forward or back, as needed) to the earliest resolved begin time of the
// target element. Note that the begin time may be resolved as a result of an
// earlier hyperlink, DOM or event activation. Once the begin time is resolved,
// hyperlink traversal always seeks."
//
function testSeekToFirst() {
  // Seek forwards
  gAnim.setAttribute('begin','2s');
  gSvg.setCurrentTime(0);
  fireLink(forwardToInterval1);
}

function forwardToInterval1() {
  is(gSvg.getCurrentTime(), 2,
     "Unexpected time after activating link to animation scheduled to start " +
     "the future");

  // Seek backwards
  gSvg.setCurrentTime(3.5);
  fireLink(backwardToInterval1);
}

function backwardToInterval1() {
  is(gSvg.getCurrentTime(), 2,
     "Unexpected time after activating link to animation that ran in the past");

  // What if the first begin instance is negative?
  gAnim.setAttribute('begin','-0.5s');
  gSvg.setCurrentTime(1);
  fireLink(backwardToZero);
}

function backwardToZero() {
  is(gSvg.getCurrentTime(), 0,
     "Unexpected time after activating link to animation that ran in the " +
     "past with a negative time");

  continueTest();
}

// Traversing a hyperlink, condition 3:
// 
// "Else (animation begin time is unresolved) just resolve the target animation
// begin time at current document time. Disregard the sync-base or event base of
// the animation, and do not "back-propagate" any timing logic to resolve the
// child, but rather treat it as though it were defined with begin="indefinite"
// and just resolve begin time to the current document time."
//
function testKickStart() {
  gSvg.setCurrentTime(1);
  fireLink(startedAt1s);
}

function startedAt1s() {
  is(gSvg.getCurrentTime(), 1,
     "Unexpected time after kick-starting animation with indefinite start " +
     "by hyperlink");
  is(gAnim.getStartTime(), 1,
     "Unexpected start time for kick-started animation");

  continueTest();
}

function testKickStartWithUnresolved() {
  gAnim.setAttribute("begin", "circle.click");
  gSvg.setCurrentTime(3);
  fireLink(startedAt3s);
}

function startedAt3s() {
  is(gSvg.getCurrentTime(), 3,
     "Unexpected time after kick-starting animation with unresolved start " +
     "by hyperlink");
  is(gAnim.getStartTime(), 3,
     "Unexpected start time for kick-started animation with unresolved begin " +
     "condition");

  continueTest();
}

function testFiltering() {
  gAnim.setAttribute('begin','-3s; 1s; 2s; 3s; 4s; 5s; 6s; 7s; 8s; 9s; 10s');
  gSvg.setCurrentTime(12);
  fireLink(rewindToFirst);
}

function rewindToFirst() {
  is(gSvg.getCurrentTime(), 1,
     "Unexpected time after triggering animation with a hyperlink after " +
     "numerous intervals have passed");

  continueTest();
}

function fireLink(callback) {
  // First we need to reset the hash because otherwise the redundant hashchange
  // events will be suppressed
  if (window.location.hash === '') {
    fireLinkPart2(callback);
  } else {
    window.location.hash = '';
    window.addEventListener("hashchange",
      function() {
        window.setTimeout(fireLinkPart2, 0, callback);
      }, {once: true});
  }
}

function fireLinkPart2(callback) {
  window.addEventListener("hashchange",
    function() {
      window.setTimeout(callback, 0);
    }, {once: true});
  window.location.hash = '#anim';
}

window.addEventListener("load", continueTest);
]]>
</script>
</pre>
</body>
</html>