dom/plugins/test/reftest/plugin-background.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // The including script sets this for us
     2 //var NUM_STEPS;
     4 var plugin;
     5 var left = 1, top = 1, width = 199, height = 199;
     6 function movePluginTo(x, y, w, h) {
     7     left = x; top = y;  width = w; height = h;
     8     plugin.width = w;
     9     plugin.height = h;
    10     plugin.style.left = left + "px";
    11     plugin.style.top = top + "px";
    12 }
    13 function deltaInBounds(dx,dy, dw,dh) {
    14     var l = dx + left;
    15     var r = l + width + dw;
    16     var t = dy + top;
    17     var b = t + height + dh;
    18     return (0 <= l && l <= 20 &&
    19             0 <= t && t <= 20 &&
    20             200 <= r && r <= 220 &&
    21             200 <= b && b <= 220);
    22 }
    24 var initialFrame;
    25 function start() {
    26     window.removeEventListener("MozReftestInvalidate", start, false);
    28     window.addEventListener("MozAfterPaint", step, false);
    29     window.addEventListener("MozPaintWaitFinished", step, false);
    31     initialFrame = window.mozPaintCount;
    32     plugin = document.getElementById("plugin");
    34     movePluginTo(0,0, 200,200);
    35 }
    37 var steps = 0;
    38 var which = "move"; // or "grow"
    39 var dx = 1, dy = 1, dw = 1, dh = 1;
    40 function step() {
    41     if (++steps >= NUM_STEPS) {
    42         window.removeEventListener("MozAfterPaint", step, false);
    43         window.removeEventListener("MozPaintWaitFinished", step, false);
    44         return finish();
    45     }
    47     var didSomething = false;
    48     if (which == "grow") {
    49         if (deltaInBounds(0,0, dw,dh)) {
    50             movePluginTo(left,top, width+dw, height+dh);
    51             didSomething = true;
    52         } else {
    53             dw = -dw;  dh = -dh;
    54         }
    55     } else {
    56         // "move"
    57         if (deltaInBounds(dx,dy, 0,0)) {
    58             movePluginTo(left+dx,top+dy, width, height);
    59             didSomething = true;
    60         } else {
    61             dx = -dx;  dy = -dy;
    62         }
    63     }
    64     which = (which == "grow") ? "move" : "grow";
    66     if (!didSomething) {
    67         step();
    68     }
    69 }
    71 function finish() {
    72     document.documentElement.removeAttribute("class");
    73 }
    75 window.addEventListener("MozReftestInvalidate", start, false);

mercurial