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