summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/reftest/plugin-background.js
blob: 5d24562cff52232aeea905adef7d82cd28a693a8 (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
// The including script sets this for us
//var NUM_STEPS;

var plugin;
var left = 1, top = 1, width = 199, height = 199;
function movePluginTo(x, y, w, h) {
    left = x; top = y;  width = w; height = h;
    plugin.width = w;
    plugin.height = h;
    plugin.style.left = left + "px";
    plugin.style.top = top + "px";
}
function deltaInBounds(dx,dy, dw,dh) {
    var l = dx + left;
    var r = l + width + dw;
    var t = dy + top;
    var b = t + height + dh;
    return (0 <= l && l <= 20 &&
            0 <= t && t <= 20 &&
            200 <= r && r <= 220 &&
            200 <= b && b <= 220);
}

var initialFrame;
function start() {
    window.removeEventListener("MozReftestInvalidate", start, false);

    window.addEventListener("MozAfterPaint", step, false);
    window.addEventListener("MozPaintWaitFinished", step, false);

    initialFrame = window.mozPaintCount;
    plugin = document.getElementById("plugin");

    movePluginTo(0,0, 200,200);
}

var steps = 0;
var which = "move"; // or "grow"
var dx = 1, dy = 1, dw = 1, dh = 1;
function step() {
    if (++steps >= NUM_STEPS) {
        window.removeEventListener("MozAfterPaint", step, false);
        window.removeEventListener("MozPaintWaitFinished", step, false);
        return finish();
    }

    var didSomething = false;
    if (which == "grow") {
        if (deltaInBounds(0,0, dw,dh)) {
            movePluginTo(left,top, width+dw, height+dh);
            didSomething = true;
        } else {
            dw = -dw;  dh = -dh;
        }
    } else {
        // "move"
        if (deltaInBounds(dx,dy, 0,0)) {
            movePluginTo(left+dx,top+dy, width, height);
            didSomething = true;
        } else {
            dx = -dx;  dy = -dy;
        }
    }
    which = (which == "grow") ? "move" : "grow";

    if (!didSomething) {
        step();
    }
}

function finish() {
    document.documentElement.removeAttribute("class");
}

window.addEventListener("MozReftestInvalidate", start, false);