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

mercurial