toolkit/content/tests/widgets/videocontrols_direction_test.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var RemoteCanvas = function(url, id) {
michael@0 2 this.url = url;
michael@0 3 this.id = id;
michael@0 4 this.snapshot = null;
michael@0 5 };
michael@0 6
michael@0 7 RemoteCanvas.CANVAS_WIDTH = 200;
michael@0 8 RemoteCanvas.CANVAS_HEIGHT = 200;
michael@0 9
michael@0 10 RemoteCanvas.prototype.compare = function(otherCanvas, expected) {
michael@0 11 return compareSnapshots(this.snapshot, otherCanvas.snapshot, expected)[0];
michael@0 12 }
michael@0 13
michael@0 14 RemoteCanvas.prototype.load = function(callback) {
michael@0 15 var iframe = document.createElement("iframe");
michael@0 16 iframe.id = this.id + "-iframe";
michael@0 17 iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
michael@0 18 iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
michael@0 19 iframe.src = this.url;
michael@0 20 var me = this;
michael@0 21 iframe.addEventListener("load", function() {
michael@0 22 var m = iframe.contentDocument.getElementById("av");
michael@0 23 m.addEventListener("progress", function(aEvent) {
michael@0 24 var v = aEvent.target;
michael@0 25 var b = v.buffered;
michael@0 26 if (b.length == 1 && b.end(0) == v.duration) {
michael@0 27 m.removeEventListener("progress", arguments.callee, false);
michael@0 28 setTimeout(function() {
michael@0 29 me.remotePageLoaded(callback);
michael@0 30 }, 0);
michael@0 31 }
michael@0 32 }, false);
michael@0 33 m.src = m.getAttribute("source");
michael@0 34 }, false);
michael@0 35 window.document.body.appendChild(iframe);
michael@0 36 };
michael@0 37
michael@0 38 RemoteCanvas.prototype.remotePageLoaded = function(callback) {
michael@0 39 var ldrFrame = document.getElementById(this.id + "-iframe");
michael@0 40 this.snapshot = snapshotWindow(ldrFrame.contentWindow);
michael@0 41 this.snapshot.id = this.id + "-canvas";
michael@0 42 window.document.body.appendChild(this.snapshot);
michael@0 43 callback(this);
michael@0 44 };
michael@0 45
michael@0 46 RemoteCanvas.prototype.cleanup = function() {
michael@0 47 var iframe = document.getElementById(this.id + "-iframe");
michael@0 48 iframe.parentNode.removeChild(iframe);
michael@0 49 var canvas = document.getElementById(this.id + "-canvas");
michael@0 50 canvas.parentNode.removeChild(canvas);
michael@0 51 };
michael@0 52
michael@0 53 function runTest(index) {
michael@0 54 var canvases = [];
michael@0 55 function testCallback(canvas) {
michael@0 56 canvases.push(canvas);
michael@0 57
michael@0 58 if (canvases.length == 2) { // when both canvases are loaded
michael@0 59 var expectedEqual = currentTest.op == "==";
michael@0 60 var result = canvases[0].compare(canvases[1], expectedEqual);
michael@0 61 ok(result, "Rendering of reftest " + currentTest.test + " should " +
michael@0 62 (expectedEqual ? "not " : "") + "be different to the reference");
michael@0 63
michael@0 64 if (result) {
michael@0 65 canvases[0].cleanup();
michael@0 66 canvases[1].cleanup();
michael@0 67 }
michael@0 68 else {
michael@0 69 ok(true, "Snapshot of canvas 1: " + canvases[0].snapshot.toDataURL());
michael@0 70 ok(true, "Snapshot of canvas 2: " + canvases[1].snapshot.toDataURL());
michael@0 71 }
michael@0 72
michael@0 73 if (index < tests.length - 1)
michael@0 74 runTest(index + 1);
michael@0 75 else
michael@0 76 SimpleTest.finish();
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 var currentTest = tests[index];
michael@0 81 var testCanvas = new RemoteCanvas(currentTest.test, "test-" + index);
michael@0 82 testCanvas.load(testCallback);
michael@0 83
michael@0 84 var refCanvas = new RemoteCanvas(currentTest.ref, "ref-" + index);
michael@0 85 refCanvas.load(testCallback);
michael@0 86 }
michael@0 87
michael@0 88 SimpleTest.waitForExplicitFinish();
michael@0 89
michael@0 90 window.addEventListener("load", function() {
michael@0 91 SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, function(){ runTest(0); });
michael@0 92 }, true);

mercurial