1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/bidi_numeral_test.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +// Canvas related code stolen from http://developer.mozilla.org/en/docs/Code_snippets:Canvas 1.5 +var RemoteCanvas = function(url, id) { 1.6 + this.url = url; 1.7 + this.id = id; 1.8 + this.snapshot = null; 1.9 +}; 1.10 + 1.11 +RemoteCanvas.CANVAS_WIDTH = 200; 1.12 +RemoteCanvas.CANVAS_HEIGHT = 100; 1.13 + 1.14 +RemoteCanvas.prototype.compare = function(otherCanvas, expected) { 1.15 + return compareSnapshots(this.snapshot, otherCanvas.snapshot, expected)[0]; 1.16 +} 1.17 + 1.18 +RemoteCanvas.prototype.load = function(callback) { 1.19 + var iframe = document.createElement("iframe"); 1.20 + iframe.id = this.id + "-iframe"; 1.21 + iframe.width = RemoteCanvas.CANVAS_WIDTH + "px"; 1.22 + iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px"; 1.23 + iframe.src = this.url; 1.24 + var me = this; 1.25 + iframe.addEventListener("load", function() { 1.26 + me.remotePageLoaded(callback); 1.27 + }, false); 1.28 + window.document.body.appendChild(iframe); 1.29 +}; 1.30 + 1.31 +RemoteCanvas.prototype.remotePageLoaded = function(callback) { 1.32 + var ldrFrame = document.getElementById(this.id + "-iframe"); 1.33 + this.snapshot = snapshotWindow(ldrFrame.contentWindow); 1.34 + callback(this); 1.35 +}; 1.36 + 1.37 +function bidiNumeral(val) { 1.38 + if (typeof val == "undefined") 1.39 + return SpecialPowers.getIntPref("bidi.numeral"); 1.40 + else 1.41 + SpecialPowers.setIntPref("bidi.numeral", val); 1.42 +} 1.43 + 1.44 +var bidiNumeralDefault = bidiNumeral(); 1.45 + 1.46 +var currentPass = 0; 1.47 + 1.48 +function run() 1.49 +{ 1.50 + SimpleTest.waitForExplicitFinish(); 1.51 + 1.52 + do_test(); 1.53 +} 1.54 + 1.55 +function do_test() 1.56 +{ 1.57 + var canvases = []; 1.58 + function callbackTestCanvas(canvas) 1.59 + { 1.60 + canvases.push(canvas); 1.61 + 1.62 + if (canvases.length == 2) { // when both canvases are loaded 1.63 + if (passes[currentPass].op == "==") { 1.64 + ok(canvases[0].compare(canvases[1], true), "Rendering of reftest " + fileprefix + passes[currentPass].file + 1.65 + " is different with bidi.numeral == " + passes[currentPass].bidiNumeralValue); 1.66 + } else if (passes[currentPass].op == "!=") { 1.67 + ok(canvases[0].compare(canvases[1], false), "Rendering of reftest " + fileprefix + passes[currentPass].file + 1.68 + " is not different with bidi.numeral == " + passes[currentPass].bidiNumeralValue); 1.69 + } 1.70 + 1.71 + bidiNumeral(bidiNumeralDefault); 1.72 + 1.73 + if (currentPass < passes.length - 1) { 1.74 + ++currentPass; 1.75 + do_test(); 1.76 + } else { 1.77 + SimpleTest.finish(); 1.78 + } 1.79 + } 1.80 + } 1.81 + 1.82 + var fileprefix = passes[currentPass].prefix + "-"; 1.83 + var file = passes[currentPass].file; 1.84 + 1.85 + var header = document.createElement("p"); 1.86 + header.appendChild(document.createTextNode("Testing reftest " + fileprefix + file + 1.87 + " with bidi.numeral == " + passes[currentPass].bidiNumeralValue + 1.88 + " expecting " + passes[currentPass].op)); 1.89 + document.body.appendChild(header); 1.90 + 1.91 + bidiNumeral(passes[currentPass].bidiNumeralValue); 1.92 + 1.93 + var testCanvas = new RemoteCanvas(fileprefix + file + ".html", "test-" + currentPass); 1.94 + testCanvas.load(callbackTestCanvas); 1.95 + 1.96 + var refCanvas = new RemoteCanvas(fileprefix + file + "-ref.html", "ref-" + currentPass); 1.97 + refCanvas.load(callbackTestCanvas); 1.98 +} 1.99 + 1.100 +run();