toolkit/content/tests/widgets/videocontrols_direction_test.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/widgets/videocontrols_direction_test.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +var RemoteCanvas = function(url, id) {
     1.5 +  this.url = url;
     1.6 +  this.id = id;
     1.7 +  this.snapshot = null;
     1.8 +};
     1.9 +
    1.10 +RemoteCanvas.CANVAS_WIDTH = 200;
    1.11 +RemoteCanvas.CANVAS_HEIGHT = 200;
    1.12 +
    1.13 +RemoteCanvas.prototype.compare = function(otherCanvas, expected) {
    1.14 +  return compareSnapshots(this.snapshot, otherCanvas.snapshot, expected)[0];
    1.15 +}
    1.16 +
    1.17 +RemoteCanvas.prototype.load = function(callback) {
    1.18 +  var iframe = document.createElement("iframe");
    1.19 +  iframe.id = this.id + "-iframe";
    1.20 +  iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
    1.21 +  iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
    1.22 +  iframe.src = this.url;
    1.23 +  var me = this;
    1.24 +  iframe.addEventListener("load", function() {
    1.25 +    var m = iframe.contentDocument.getElementById("av");
    1.26 +    m.addEventListener("progress", function(aEvent) {
    1.27 +      var v = aEvent.target;
    1.28 +      var b = v.buffered;
    1.29 +      if (b.length == 1 && b.end(0) == v.duration) {
    1.30 +        m.removeEventListener("progress", arguments.callee, false);
    1.31 +        setTimeout(function() {
    1.32 +          me.remotePageLoaded(callback);
    1.33 +        }, 0);
    1.34 +      }
    1.35 +    }, false);
    1.36 +    m.src = m.getAttribute("source");
    1.37 +  }, false);
    1.38 +  window.document.body.appendChild(iframe);
    1.39 +};
    1.40 +
    1.41 +RemoteCanvas.prototype.remotePageLoaded = function(callback) {
    1.42 +  var ldrFrame = document.getElementById(this.id + "-iframe");
    1.43 +  this.snapshot = snapshotWindow(ldrFrame.contentWindow);
    1.44 +  this.snapshot.id = this.id + "-canvas";
    1.45 +  window.document.body.appendChild(this.snapshot);
    1.46 +  callback(this);
    1.47 +};
    1.48 +
    1.49 +RemoteCanvas.prototype.cleanup = function() {
    1.50 +  var iframe = document.getElementById(this.id + "-iframe");
    1.51 +  iframe.parentNode.removeChild(iframe);
    1.52 +  var canvas = document.getElementById(this.id + "-canvas");
    1.53 +  canvas.parentNode.removeChild(canvas);
    1.54 +};
    1.55 +
    1.56 +function runTest(index) {
    1.57 +  var canvases = [];
    1.58 +  function testCallback(canvas) {
    1.59 +    canvases.push(canvas);
    1.60 +
    1.61 +    if (canvases.length == 2) { // when both canvases are loaded
    1.62 +      var expectedEqual = currentTest.op == "==";
    1.63 +      var result = canvases[0].compare(canvases[1], expectedEqual);
    1.64 +      ok(result, "Rendering of reftest " + currentTest.test + " should " +
    1.65 +        (expectedEqual ? "not " : "") + "be different to the reference");
    1.66 +
    1.67 +      if (result) {
    1.68 +        canvases[0].cleanup();
    1.69 +        canvases[1].cleanup();
    1.70 +      }
    1.71 +      else {
    1.72 +        ok(true, "Snapshot of canvas 1: " + canvases[0].snapshot.toDataURL());
    1.73 +        ok(true, "Snapshot of canvas 2: " + canvases[1].snapshot.toDataURL());
    1.74 +      }
    1.75 +
    1.76 +      if (index < tests.length - 1)
    1.77 +        runTest(index + 1);
    1.78 +      else
    1.79 +        SimpleTest.finish();
    1.80 +    }
    1.81 +  }
    1.82 +
    1.83 +  var currentTest = tests[index];
    1.84 +  var testCanvas = new RemoteCanvas(currentTest.test, "test-" + index);
    1.85 +  testCanvas.load(testCallback);
    1.86 +
    1.87 +  var refCanvas = new RemoteCanvas(currentTest.ref, "ref-" + index);
    1.88 +  refCanvas.load(testCallback);
    1.89 +}
    1.90 +
    1.91 +SimpleTest.waitForExplicitFinish();
    1.92 +
    1.93 +window.addEventListener("load", function() {
    1.94 +  SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, function(){ runTest(0); });
    1.95 +}, true);

mercurial