|
1 // Canvas related code stolen from http://developer.mozilla.org/en/docs/Code_snippets:Canvas |
|
2 var RemoteCanvas = function(url, id) { |
|
3 this.url = url; |
|
4 this.id = id; |
|
5 this.snapshot = null; |
|
6 }; |
|
7 |
|
8 RemoteCanvas.CANVAS_WIDTH = 200; |
|
9 RemoteCanvas.CANVAS_HEIGHT = 100; |
|
10 |
|
11 RemoteCanvas.prototype.compare = function(otherCanvas, expected) { |
|
12 return compareSnapshots(this.snapshot, otherCanvas.snapshot, expected)[0]; |
|
13 } |
|
14 |
|
15 RemoteCanvas.prototype.load = function(callback) { |
|
16 var iframe = document.createElement("iframe"); |
|
17 iframe.id = this.id + "-iframe"; |
|
18 iframe.width = RemoteCanvas.CANVAS_WIDTH + "px"; |
|
19 iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px"; |
|
20 iframe.src = this.url; |
|
21 var me = this; |
|
22 iframe.addEventListener("load", function() { |
|
23 me.remotePageLoaded(callback); |
|
24 }, false); |
|
25 window.document.body.appendChild(iframe); |
|
26 }; |
|
27 |
|
28 RemoteCanvas.prototype.remotePageLoaded = function(callback) { |
|
29 var ldrFrame = document.getElementById(this.id + "-iframe"); |
|
30 this.snapshot = snapshotWindow(ldrFrame.contentWindow); |
|
31 callback(this); |
|
32 }; |
|
33 |
|
34 function bidiNumeral(val) { |
|
35 if (typeof val == "undefined") |
|
36 return SpecialPowers.getIntPref("bidi.numeral"); |
|
37 else |
|
38 SpecialPowers.setIntPref("bidi.numeral", val); |
|
39 } |
|
40 |
|
41 var bidiNumeralDefault = bidiNumeral(); |
|
42 |
|
43 var currentPass = 0; |
|
44 |
|
45 function run() |
|
46 { |
|
47 SimpleTest.waitForExplicitFinish(); |
|
48 |
|
49 do_test(); |
|
50 } |
|
51 |
|
52 function do_test() |
|
53 { |
|
54 var canvases = []; |
|
55 function callbackTestCanvas(canvas) |
|
56 { |
|
57 canvases.push(canvas); |
|
58 |
|
59 if (canvases.length == 2) { // when both canvases are loaded |
|
60 if (passes[currentPass].op == "==") { |
|
61 ok(canvases[0].compare(canvases[1], true), "Rendering of reftest " + fileprefix + passes[currentPass].file + |
|
62 " is different with bidi.numeral == " + passes[currentPass].bidiNumeralValue); |
|
63 } else if (passes[currentPass].op == "!=") { |
|
64 ok(canvases[0].compare(canvases[1], false), "Rendering of reftest " + fileprefix + passes[currentPass].file + |
|
65 " is not different with bidi.numeral == " + passes[currentPass].bidiNumeralValue); |
|
66 } |
|
67 |
|
68 bidiNumeral(bidiNumeralDefault); |
|
69 |
|
70 if (currentPass < passes.length - 1) { |
|
71 ++currentPass; |
|
72 do_test(); |
|
73 } else { |
|
74 SimpleTest.finish(); |
|
75 } |
|
76 } |
|
77 } |
|
78 |
|
79 var fileprefix = passes[currentPass].prefix + "-"; |
|
80 var file = passes[currentPass].file; |
|
81 |
|
82 var header = document.createElement("p"); |
|
83 header.appendChild(document.createTextNode("Testing reftest " + fileprefix + file + |
|
84 " with bidi.numeral == " + passes[currentPass].bidiNumeralValue + |
|
85 " expecting " + passes[currentPass].op)); |
|
86 document.body.appendChild(header); |
|
87 |
|
88 bidiNumeral(passes[currentPass].bidiNumeralValue); |
|
89 |
|
90 var testCanvas = new RemoteCanvas(fileprefix + file + ".html", "test-" + currentPass); |
|
91 testCanvas.load(callbackTestCanvas); |
|
92 |
|
93 var refCanvas = new RemoteCanvas(fileprefix + file + "-ref.html", "ref-" + currentPass); |
|
94 refCanvas.load(callbackTestCanvas); |
|
95 } |
|
96 |
|
97 run(); |