summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilSyncbaseTarget.xhtml
blob: 496cb6751e8c5981e36835e6f9d6cb7ae2728fd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for syncbase targetting</title>
  <script 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="-20" cy="20" r="15" fill="blue" id="circle">
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="a"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" xml:id="b"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="あ"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="a.b"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="a-b"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="a:b"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="-a"/>
    <set attributeName="cx" to="0" begin="2s" dur="1s" id="0"/>
  </circle>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for syncbase targetting behavior  **/

SimpleTest.waitForExplicitFinish();

function main() {
  var svg = getElement("svg");
  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");

  testSpecs();
  testChangeId();
  testRemoveTimebase();

  SimpleTest.finish();
}

function testSpecs() {
  var anim = createAnim();

  // Sanity check--initial state
  ok(noStart(anim), "Unexpected initial value for indefinite start time.");

  var specs = [ [ 'a.begin', 2 ],
                [ 'b.begin', 'todo' ], // xml:id support, bug 275196
                [ 'あ.begin', 2 ],   // unicode id
                [ ' a.begin ', 2 ],  // whitespace
                [ 'a\\.b.begin', 2 ], // escaping
                [ 'a\\-b.begin', 2 ], // escaping
                [ 'a:b.begin', 2 ],
                // Invalid
                [ '-a.begin', 'notok' ], // invalid XML ID
                [ '\\-a.begin', 'notok' ], // invalid XML ID
                [ '0.begin', 'notok' ], // invalid XML ID
                [ '\xB7.begin', 'notok' ], // invalid XML ID
                [ '\x7B.begin', 'notok' ], // invalid XML ID
                [ '.begin', 'notok' ],
                [ '  .end  ', 'notok' ],
                [ 'a.begin-5a', 'notok' ],
                // Offsets
                [ ' a.begin + 1min', 2 + 60 ],
                [ ' a.begin-0.5s', 1.5 ],
              ];
  for (var i = 0; i < specs.length; i++) {
    var spec = specs[i][0];
    var expected = specs[i][1];
    anim.setAttribute('begin', spec);
    try {
      if (typeof(expected) == 'number') {
        is(anim.getStartTime(), expected,
           "Unexpected start time with spec: " + spec);
      } else if (expected == 'todo') {
        todo_is(anim.getStartTime(), 2,"Unexpected success with spec: " + spec);
      } else {
        anim.getStartTime();
        ok(false, "Unexpected success with spec: " + spec);
      }
    } catch(e) {
      if (e.name == "InvalidStateError" &&
          e.code == DOMException.INVALID_STATE_ERR) {
        if (typeof(expected) == 'number')
          ok(false, "Failed with spec: " + spec);
        else if (expected == 'todo')
          todo(false, "Yet to implement: " + spec);
        else
          ok(true);
      } else {
        ok(false, "Unexpected exception: " + e + "(with spec: " + spec + ")");
      }
    }
  }

  anim.remove();
}

function testChangeId() {
  var anim = createAnim();

  anim.setAttribute('begin', 'a.begin');
  is(anim.getStartTime(), 2, "Unexpected start time.");

  var a = getElement('a');
  a.setAttribute('id', 'a1');
  ok(noStart(anim), "Unexpected return value after changing target ID.");

  a.setAttribute('id', 'a');
  is(anim.getStartTime(), 2,
     "Unexpected start time after resetting target ID.");

  anim.remove();
}

function testRemoveTimebase() {
  var anim = createAnim();
  anim.setAttribute('begin', 'a.begin');
  ok(!noStart(anim), "Unexpected start time before removing timebase.");

  var circle = getElement('circle');
  var a = getElement('a');
  // Sanity check
  is(a, circle.firstElementChild, "Unexpected document structure");

  // Remove timebase
  a.remove();
  ok(noStart(anim), "Unexpected start time after removing timebase.");

  // Reinsert timebase
  circle.insertBefore(a, circle.firstElementChild);
  ok(!noStart(anim), "Unexpected start time after re-inserting timebase.");

  // Remove dependent element
  anim.remove();
  ok(noStart(anim), "Unexpected start time after removing dependent.");

  // Create a new dependent
  var anim2 = createAnim();
  anim2.setAttribute('begin', 'a.begin');
  is(anim2.getStartTime(), 2,
     "Unexpected start time after adding new dependent.");
}

function createAnim() {
  const svgns="http://www.w3.org/2000/svg";
  var anim = document.createElementNS(svgns,'animate');
  anim.setAttribute('attributeName','cx');
  anim.setAttribute('from','0');
  anim.setAttribute('to','100');
  anim.setAttribute('begin','indefinite');
  anim.setAttribute('dur','1s');
  return getElement('circle').appendChild(anim);
}

function noStart(elem) {
  var exceptionCaught = false;

  try {
    elem.getStartTime();
  } catch(e) {
    exceptionCaught = true;
    is (e.name, "InvalidStateError",
        "Unexpected exception from getStartTime.");
    is (e.code, DOMException.INVALID_STATE_ERR,
        "Unexpected exception code from getStartTime.");
  }

  return exceptionCaught;
}

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