summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/svg/script-tests/animation-events.js
blob: 35a859f2f6074e72df6d941c3c29c55b0c4f4950 (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
function getObject(interface) {
    switch(interface) {
        case "SVGAnimateElement":
            var e = document.createElementNS("http://www.w3.org/2000/svg", "animate");
            assert_true(e instanceof SVGAnimateElement);
            return e;
        case "SVGAnimateMotionElement":
            var e = document.createElementNS("http://www.w3.org/2000/svg", "animateMotion");
            assert_true(e instanceof SVGAnimateMotionElement);
            return e;
        case "SVGAnimateTransformElement":
            var e = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");
            assert_true(e instanceof SVGAnimateTransformElement);
            return e;
        case "SVGSetElement":
            var e = document.createElementNS("http://www.w3.org/2000/svg", "set");
            assert_true(e instanceof SVGSetElement);
            return e;
    }
    assert_unreached();
}
function testSet(interface, attribute) {
    test(function() {
        var object = getObject(interface);
        function nop() {}
        assert_equals(object[attribute], null, "Initially null");
        object[attribute] = nop;
        assert_equals(object[attribute], nop, "Return same function");
        object[attribute] = "";
        assert_equals(object[attribute], null, "Return null after setting string");
        object[attribute] = null;
        assert_equals(object[attribute], null, "Finally null");
    }, "Set " + interface + "." + attribute);
}
function testReflect(interface, attribute) {
    test(function() {
        var element = getObject(interface);
        assert_false(element.hasAttribute(attribute), "Initially missing");
        element.setAttribute(attribute, "return");
        assert_equals(element.getAttribute(attribute), "return", "Return same string");
        assert_equals(typeof element[attribute], "function", "Convert to function");
        element.removeAttribute(attribute);
    }, "Reflect " + interface + "." + attribute);
}
// Object.propertyIsEnumerable cannot be used because it doesn't
// work with properties inherited through the prototype chain.
function getEnumerable(interface) {
    var enumerable = {};
    for (var attribute in getObject(interface)) {
        enumerable[attribute] = true;
    }
    return enumerable;
}
function testEventHandlerMapping(attribute, eventname) {
    async_test(function(t) {
        var element = getObject("SVGAnimateElement");
        assert_false(element.hasAttribute(attribute), "Initially missing");
        element[attribute] = function() {
            t.step(function (){assert_true(true); t.done();});
        };
        var event = new CustomEvent(eventname);
        element.dispatchEvent(event);
    }, "Event " + eventname + " maps to " + attribute);
}
var enumerableCache = {};
function testEnumerate(interface, attribute) {
    if (!(interface in enumerableCache)) {
        enumerableCache[interface] = getEnumerable(interface);
    }
    test(function() {
        assert_true(enumerableCache[interface][attribute]);
    }, "Enumerate " + interface + "." + attribute);
}