Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!doctype html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=941315 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test invalid values cause the model to be updated (bug 941315)</title> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
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=941315">Mozilla Bug 941315</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | <svg width="100%" height="1" onload="this.pauseAnimations()"> |
michael@0 | 17 | <rect> |
michael@0 | 18 | <animate id="a" dur="100s"/> |
michael@0 | 19 | <animate id="b" dur="5s" begin="a.end"/> |
michael@0 | 20 | </rect> |
michael@0 | 21 | <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/> |
michael@0 | 22 | </svg> |
michael@0 | 23 | </div> |
michael@0 | 24 | <pre id="test"> |
michael@0 | 25 | <script class="testbody" type="text/javascript"> |
michael@0 | 26 | var a = $('a'), |
michael@0 | 27 | b = $('b'); |
michael@0 | 28 | |
michael@0 | 29 | // Animation doesn't start until onload |
michael@0 | 30 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 31 | window.addEventListener("load", runTests, false); |
michael@0 | 32 | |
michael@0 | 33 | // Make testing getStartTime easier |
michael@0 | 34 | SVGAnimationElement.prototype.safeGetStartTime = function() { |
michael@0 | 35 | try { |
michael@0 | 36 | return this.getStartTime(); |
michael@0 | 37 | } catch(e) { |
michael@0 | 38 | if (e.name == "InvalidStateError" && |
michael@0 | 39 | e.code == DOMException.INVALID_STATE_ERR) { |
michael@0 | 40 | return 'none'; |
michael@0 | 41 | } else { |
michael@0 | 42 | ok(false, "Unexpected exception: " + e); |
michael@0 | 43 | return null; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | }; |
michael@0 | 47 | |
michael@0 | 48 | function runTests() { |
michael@0 | 49 | [testSimpleDuration, testMin, testMax, testRepeatDur, testRepeatCount] |
michael@0 | 50 | .forEach(function(test) { |
michael@0 | 51 | ise(b.getStartTime(), 100, "initial state before running " + test.name); |
michael@0 | 52 | test(); |
michael@0 | 53 | ise(b.getStartTime(), 100, "final state after running " + test.name); |
michael@0 | 54 | }); |
michael@0 | 55 | SimpleTest.finish(); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function testSimpleDuration() { |
michael@0 | 59 | // Verify a valid value updates as expected |
michael@0 | 60 | a.setAttribute("dur", "50s"); |
michael@0 | 61 | ise(b.safeGetStartTime(), 50, "valid simple duration"); |
michael@0 | 62 | |
michael@0 | 63 | // Check an invalid value also causes the model to be updated |
michael@0 | 64 | a.setAttribute("dur", "abc"); // -> indefinite |
michael@0 | 65 | ise(b.safeGetStartTime(), "none", "invalid simple duration"); |
michael@0 | 66 | |
michael@0 | 67 | // Restore state |
michael@0 | 68 | a.setAttribute("dur", "100s"); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function testMin() { |
michael@0 | 72 | a.setAttribute("min", "200s"); |
michael@0 | 73 | ise(b.safeGetStartTime(), 200, "valid min duration"); |
michael@0 | 74 | |
michael@0 | 75 | a.setAttribute("min", "abc"); // -> indefinite |
michael@0 | 76 | ise(b.safeGetStartTime(), 100, "invalid min duration"); |
michael@0 | 77 | |
michael@0 | 78 | a.removeAttribute("min"); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function testMax() { |
michael@0 | 82 | a.setAttribute("max", "50s"); |
michael@0 | 83 | ise(b.safeGetStartTime(), 50, "valid max duration"); |
michael@0 | 84 | |
michael@0 | 85 | a.setAttribute("max", "abc"); // -> indefinite |
michael@0 | 86 | ise(b.safeGetStartTime(), 100, "invalid max duration"); |
michael@0 | 87 | |
michael@0 | 88 | a.removeAttribute("max"); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function testRepeatDur() { |
michael@0 | 92 | a.setAttribute("repeatDur", "200s"); |
michael@0 | 93 | ise(b.safeGetStartTime(), 200, "valid repeatDur duration"); |
michael@0 | 94 | |
michael@0 | 95 | a.setAttribute("repeatDur", "abc"); // -> indefinite |
michael@0 | 96 | ise(b.safeGetStartTime(), 100, "invalid repeatDur duration"); |
michael@0 | 97 | |
michael@0 | 98 | a.removeAttribute("repeatDur"); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | function testRepeatCount() { |
michael@0 | 102 | a.setAttribute("repeatCount", "2"); |
michael@0 | 103 | ise(b.safeGetStartTime(), 200, "valid repeatCount duration"); |
michael@0 | 104 | |
michael@0 | 105 | a.setAttribute("repeatCount", "abc"); // -> indefinite |
michael@0 | 106 | ise(b.safeGetStartTime(), 100, "invalid repeatCount duration"); |
michael@0 | 107 | |
michael@0 | 108 | a.removeAttribute("repeatCount"); |
michael@0 | 109 | } |
michael@0 | 110 | </script> |
michael@0 | 111 | </pre> |
michael@0 | 112 | </body> |
michael@0 | 113 | </html> |