summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilInvalidValues.html
blob: 29ddfad39a0c0a00ebf04292d462f36b9a187c52 (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
<!doctype html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=941315
-->
<head>
  <meta charset="utf-8">
  <title>Test invalid values cause the model to be updated (bug 941315)</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=941315">Mozilla Bug 941315</a>
<p id="display"></p>
<div id="content" style="display: none">
<svg width="100%" height="1" onload="this.pauseAnimations()">
  <rect>
    <animate id="a" dur="100s"/>
    <animate id="b" dur="5s" begin="a.end"/>
  </rect>
  <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
  var a = $('a'),
      b = $('b');

  // Animation doesn't start until onload
  SimpleTest.waitForExplicitFinish();
  window.addEventListener("load", runTests);

  // Make testing getStartTime easier
  SVGAnimationElement.prototype.safeGetStartTime = function() {
    try {
      return this.getStartTime();
    } catch(e) {
      if (e.name == "InvalidStateError" &&
          e.code == DOMException.INVALID_STATE_ERR) {
        return 'none';
      } else {
        ok(false, "Unexpected exception: " + e);
        return null;
      }
    }
  };

  function runTests() {
    [testSimpleDuration, testSimpleDuration2, testMin, testMax, testRepeatDur, testRepeatCount]
      .forEach(function(test) {
        is(b.getStartTime(), 100, "initial state before running " + test.name);
        test();
        is(b.getStartTime(), 100, "final state after running " + test.name);
      });
    SimpleTest.finish();
  }

  function testSimpleDuration() {
    // Verify a valid value updates as expected
    a.setAttribute("dur", "50s");
    is(b.safeGetStartTime(), 50, "valid simple duration");

    // Check an invalid value also causes the model to be updated
    a.setAttribute("dur", "abc"); // -> indefinite
    is(b.safeGetStartTime(), "none", "invalid simple duration");

    // Restore state
    a.setAttribute("dur", "100s");
  }

  function testSimpleDuration2() {
    // Check an invalid value causes the model to be updated
    a.setAttribute("dur", "-.1s"); // -> indefinite
    is(b.safeGetStartTime(), "none", "invalid simple duration");

    // Restore state
    a.setAttribute("dur", "100s");
  }

  function testMin() {
    a.setAttribute("min", "200s");
    is(b.safeGetStartTime(), 200, "valid min duration");

    a.setAttribute("min", "abc"); // -> indefinite
    is(b.safeGetStartTime(), 100, "invalid min duration");

    a.removeAttribute("min");
  }

  function testMax() {
    a.setAttribute("max", "50s");
    is(b.safeGetStartTime(), 50, "valid max duration");

    a.setAttribute("max", "abc"); // -> indefinite
    is(b.safeGetStartTime(), 100, "invalid max duration");

    a.removeAttribute("max");
  }

  function testRepeatDur() {
    a.setAttribute("repeatDur", "200s");
    is(b.safeGetStartTime(), 200, "valid repeatDur duration");

    a.setAttribute("repeatDur", "abc"); // -> indefinite
    is(b.safeGetStartTime(), 100, "invalid repeatDur duration");

    a.removeAttribute("repeatDur");
  }

  function testRepeatCount() {
    a.setAttribute("repeatCount", "2");
    is(b.safeGetStartTime(), 200, "valid repeatCount duration");

    a.setAttribute("repeatCount", "abc"); // -> indefinite
    is(b.safeGetStartTime(), 100, "invalid repeatCount duration");

    a.removeAttribute("repeatCount");
  }
</script>
</pre>
</body>
</html>