layout/generic/test/test_selection_underline.html

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 <html>
michael@0 2
michael@0 3 <head>
michael@0 4 <title>Test for selection underline</title>
michael@0 5 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8
michael@0 9 <script type="text/javascript">
michael@0 10
michael@0 11 // Canvas related code stolen from layout/base/tests/bidi_numeral_test.js which
michael@0 12 // stole from http://developer.mozilla.org/en/docs/Code_snippets:Canvas
michael@0 13
michael@0 14 var RemoteCanvas = function(aIFrame, aTest) {
michael@0 15 this.iframe = aIFrame;
michael@0 16 this.test = aTest;
michael@0 17 this.snapshot = null;
michael@0 18 };
michael@0 19
michael@0 20 RemoteCanvas.CANVAS_WIDTH = 200;
michael@0 21 RemoteCanvas.CANVAS_HEIGHT = 100;
michael@0 22
michael@0 23 RemoteCanvas.prototype.compare = function(otherCanvas, expected) {
michael@0 24 var ret = compareSnapshots(this.snapshot, otherCanvas.snapshot, expected);
michael@0 25 this.snapshotDataURL = ret[1];
michael@0 26 otherCanvas.snapshotDataURL = ret[2];
michael@0 27 return ret[0];
michael@0 28 }
michael@0 29
michael@0 30 RemoteCanvas.prototype.isReference = function() {
michael@0 31 return this.iframe && (this.iframe.id == "reference");
michael@0 32 }
michael@0 33
michael@0 34 RemoteCanvas.prototype.load = function(callback) {
michael@0 35 this.iframe.contentWindow.wrappedJSObject.init(this.test);
michael@0 36 var me = this;
michael@0 37 setTimeout(function () { me.remotePagePrepared(callback) }, 100);
michael@0 38 }
michael@0 39
michael@0 40 RemoteCanvas.prototype.remotePagePrepared = function(callback) {
michael@0 41 this.snapshot = snapshotWindow(this.iframe.contentWindow);
michael@0 42 callback(this);
michael@0 43 }
michael@0 44
michael@0 45 var gPrefs = [
michael@0 46 {
michael@0 47 name: "ui.SpellCheckerUnderline",
michael@0 48 type: "char",
michael@0 49 newValue: "#ff0000"
michael@0 50 },
michael@0 51 {
michael@0 52 name: "ui.IMERawInputBackground",
michael@0 53 type: "char",
michael@0 54 newValue: "transparent"
michael@0 55 },
michael@0 56 {
michael@0 57 name: "ui.IMERawInputForeground",
michael@0 58 type: "char",
michael@0 59 newValue: "#000000"
michael@0 60 },
michael@0 61 {
michael@0 62 name: "ui.IMERawInputUnderline",
michael@0 63 type: "char",
michael@0 64 newValue: "#00ff00"
michael@0 65 },
michael@0 66 {
michael@0 67 name: "ui.IMESelectedRawTextBackground",
michael@0 68 type: "char",
michael@0 69 newValue: "transparent"
michael@0 70 },
michael@0 71 {
michael@0 72 name: "ui.IMESelectedRawTextForeground",
michael@0 73 type: "char",
michael@0 74 newValue: "#000000"
michael@0 75 },
michael@0 76 {
michael@0 77 name: "ui.IMESelectedRawTextUnderline",
michael@0 78 type: "char",
michael@0 79 newValue: "#0000ff"
michael@0 80 },
michael@0 81 {
michael@0 82 name: "ui.IMEConvertedTextBackground",
michael@0 83 type: "char",
michael@0 84 newValue: "transparent"
michael@0 85 },
michael@0 86 {
michael@0 87 name: "ui.IMEConvertedTextForeground",
michael@0 88 type: "char",
michael@0 89 newValue: "#000000"
michael@0 90 },
michael@0 91 {
michael@0 92 name: "ui.IMEConvertedTextUnderline",
michael@0 93 type: "char",
michael@0 94 newValue: "#ffff00"
michael@0 95 },
michael@0 96 {
michael@0 97 name: "ui.IMESelectedConvertedTextBackground",
michael@0 98 type: "char",
michael@0 99 newValue: "transparent"
michael@0 100 },
michael@0 101 {
michael@0 102 name: "ui.IMESelectedConvertedTextForeground",
michael@0 103 type: "char",
michael@0 104 newValue: "#000000"
michael@0 105 },
michael@0 106 {
michael@0 107 name: "ui.IMESelectedConvertedTextUnderline",
michael@0 108 type: "char",
michael@0 109 newValue: "#00ffff"
michael@0 110 },
michael@0 111 {
michael@0 112 name: "ui.SpellCheckerUnderlineStyle",
michael@0 113 type: "int",
michael@0 114 newValue: 0
michael@0 115 },
michael@0 116 {
michael@0 117 name: "ui.IMERawInputUnderlineStyle",
michael@0 118 type: "int",
michael@0 119 newValue: 0
michael@0 120 },
michael@0 121 {
michael@0 122 name: "ui.IMESelectedRawTextUnderlineStyle",
michael@0 123 type: "int",
michael@0 124 newValue: 0
michael@0 125 },
michael@0 126 {
michael@0 127 name: "ui.IMEConvertedTextUnderlineStyle",
michael@0 128 type: "int",
michael@0 129 newValue: 0
michael@0 130 },
michael@0 131 {
michael@0 132 name: "ui.IMESelectedConvertedTextUnderlineStyle",
michael@0 133 type: "int",
michael@0 134 newValue: 0
michael@0 135 },
michael@0 136 {
michael@0 137 name: "ui.SpellCheckerUnderlineRelativeSize",
michael@0 138 type: "float",
michael@0 139 newValue: 1.0
michael@0 140 },
michael@0 141 {
michael@0 142 name: "ui.IMEUnderlineRelativeSize",
michael@0 143 type: "float",
michael@0 144 newValue: 1.0
michael@0 145 }
michael@0 146 ];
michael@0 147
michael@0 148 const nsISelectionController = Components.interfaces.nsISelectionController;
michael@0 149
michael@0 150 var gSelectionIndex = -1;
michael@0 151 const kSelections = [
michael@0 152 { type: nsISelectionController.SELECTION_SPELLCHECK,
michael@0 153 typeName: "SpellCheck", isIME: false,
michael@0 154 decorationColor: "#ff0000" },
michael@0 155 { type: nsISelectionController.SELECTION_IME_RAWINPUT,
michael@0 156 typeName: "IME-RawInput", isIME: true,
michael@0 157 decorationColor: "#00ff00" },
michael@0 158 { type: nsISelectionController.SELECTION_IME_SELECTEDRAWTEXT,
michael@0 159 typeName: "IME-SelectedRawText", isIME: true,
michael@0 160 decorationColor: "#0000ff" },
michael@0 161 { type: nsISelectionController.SELECTION_IME_CONVERTEDTEXT,
michael@0 162 typeName: "IME-ConvertedText", isIME: true,
michael@0 163 decorationColor: "#ffff00" },
michael@0 164 { type: nsISelectionController.SELECTION_IME_SELECTEDCONVERTEDTEXT,
michael@0 165 typeName: "IME-SelectedConvertedText", isIME: true,
michael@0 166 decorationColor: "#00ffff" },
michael@0 167 ];
michael@0 168
michael@0 169 const kFontName_Ahem = "AhemTest";
michael@0 170 const kFontName_MPlus = "mplusTest";
michael@0 171
michael@0 172 var gFontIndex = 0;
michael@0 173 const kFonts = [
michael@0 174 { family: kFontName_Ahem, defaultSize: 16 },
michael@0 175 { family: kFontName_Ahem, defaultSize: 20 },
michael@0 176 { family: kFontName_Ahem, defaultSize: 32 },
michael@0 177 { family: kFontName_Ahem, defaultSize: 52 },
michael@0 178
michael@0 179 { family: kFontName_MPlus, defaultSize: 16 },
michael@0 180 { family: kFontName_MPlus, defaultSize: 20 },
michael@0 181 { family: kFontName_MPlus, defaultSize: 32 },
michael@0 182 { family: kFontName_MPlus, defaultSize: 52 },
michael@0 183 ];
michael@0 184
michael@0 185 const kDecorationStyleNone = 0;
michael@0 186 const kDecorationStyleDotted = 1;
michael@0 187 const kDecorationStyleDashed = 2;
michael@0 188 const kDecorationStyleSolid = 3;
michael@0 189 const kDecorationStyleDouble = 4;
michael@0 190 const kDecorationStyleWavy = 5;
michael@0 191
michael@0 192 var gDecorationIndex = 0;
michael@0 193 const kDecorations = [
michael@0 194 { relativeSize: 1.0, style: kDecorationStyleNone, styleName: "-moz-none" },
michael@0 195 { relativeSize: 1.0, style: kDecorationStyleSolid, styleName: "solid" },
michael@0 196 { relativeSize: 1.0, style: kDecorationStyleDotted, styleName: "dotted" },
michael@0 197 { relativeSize: 1.0, style: kDecorationStyleDashed, styleName: "dashed" },
michael@0 198 { relativeSize: 1.0, style: kDecorationStyleDouble, styleName: "double" },
michael@0 199 { relativeSize: 1.0, style: kDecorationStyleWavy, styleName: "wavy" },
michael@0 200
michael@0 201 // XXX relativeSize 2.0 cannot be tested by CSS3 text-decoration
michael@0 202
michael@0 203 ];
michael@0 204
michael@0 205 function run()
michael@0 206 {
michael@0 207 if (++gSelectionIndex == kSelections.length) {
michael@0 208 if (++gFontIndex == kFonts.length) {
michael@0 209 if (++gDecorationIndex == kDecorations.length) {
michael@0 210 SimpleTest.finish();
michael@0 211 cleanup();
michael@0 212 return;
michael@0 213 }
michael@0 214 gFontIndex = 0;
michael@0 215 }
michael@0 216 gSelectionIndex = 0;
michael@0 217 SpecialPowers.setIntPref("font.size.variable.x-western",
michael@0 218 kFonts[gFontIndex].defaultSize);
michael@0 219 }
michael@0 220
michael@0 221 var test = {
michael@0 222 font: kFonts[gFontIndex],
michael@0 223 decoration: kDecorations[gDecorationIndex],
michael@0 224 selection: kSelections[gSelectionIndex],
michael@0 225 };
michael@0 226
michael@0 227 SpecialPowers.setIntPref("ui.SpellCheckerUnderlineRelativeSize",
michael@0 228 test.decoration.relativeSize * 100);
michael@0 229 SpecialPowers.setIntPref("ui.IMEUnderlineRelativeSize",
michael@0 230 test.decoration.relativeSize * 100);
michael@0 231 SpecialPowers.setIntPref("ui.SpellCheckerUnderlineStyle",
michael@0 232 test.decoration.style);
michael@0 233 SpecialPowers.setIntPref("ui.IMERawInputUnderlineStyle",
michael@0 234 test.decoration.style);
michael@0 235 SpecialPowers.setIntPref("ui.IMESelectedRawTextUnderlineStyle",
michael@0 236 test.decoration.style);
michael@0 237 SpecialPowers.setIntPref("ui.IMEConvertedTextUnderlineStyle",
michael@0 238 test.decoration.style);
michael@0 239 SpecialPowers.setIntPref("ui.IMESelectedConvertedTextUnderlineStyle",
michael@0 240 test.decoration.style);
michael@0 241
michael@0 242 SimpleTest.executeSoon(function () { doTest(test); });
michael@0 243 }
michael@0 244
michael@0 245 function doTest(aTest)
michael@0 246 {
michael@0 247
michael@0 248 var canvases = [];
michael@0 249 function callbackTestCanvas(canvas)
michael@0 250 {
michael@0 251 canvases.push(canvas);
michael@0 252
michael@0 253 if (canvases.length != 2)
michael@0 254 return;
michael@0 255
michael@0 256 var result = !canvases[0].isReference() ? canvases[0] : canvases[1];
michael@0 257 var reference = canvases[0].isReference() ? canvases[0] : canvases[1];
michael@0 258
michael@0 259 var description = "Rendering of reftest (" +
michael@0 260 "selection: " + aTest.selection.typeName +
michael@0 261 ", style: " + aTest.decoration.styleName +
michael@0 262 ", relativeSize: " + aTest.decoration.relativeSize +
michael@0 263 ", font: " + aTest.font.family +
michael@0 264 ", default font size: " + aTest.font.defaultSize +
michael@0 265 ") is different\n" +
michael@0 266 "RESULT=" + result.snapshotDataURL + "\n" +
michael@0 267 "REFERENCE=" + reference.snapshotDataURL + "\n";
michael@0 268
michael@0 269 if (result.compare(reference, true)) {
michael@0 270 ok(true, description);
michael@0 271 // If the decoration line is thick and the descender of the text isn't
michael@0 272 // enough for containing it, selection underline may be painted lower
michael@0 273 // if it's possible. Then, we cannot test it with CSS3 text-decoration.
michael@0 274 } else if (aTest.decoration.style == kDecorationStyleDouble ||
michael@0 275 aTest.decoration.style == kDecorationStyleWavy) {
michael@0 276 todo(false, description);
michael@0 277 } else {
michael@0 278 ok(false, description);
michael@0 279 }
michael@0 280
michael@0 281 canvases = [];
michael@0 282
michael@0 283 run();
michael@0 284 }
michael@0 285
michael@0 286 var testCanvas = new RemoteCanvas(document.getElementById("result"), aTest);
michael@0 287 testCanvas.load(callbackTestCanvas);
michael@0 288
michael@0 289 var refCanvas = new RemoteCanvas(document.getElementById("reference"), aTest);
michael@0 290 refCanvas.load(callbackTestCanvas);
michael@0 291 }
michael@0 292
michael@0 293 function onLoad()
michael@0 294 {
michael@0 295 for (var i = 0; i < gPrefs.length; i++) {
michael@0 296 if (gPrefs[i].type == "char") {
michael@0 297 SpecialPowers.setCharPref(gPrefs[i].name, gPrefs[i].newValue);
michael@0 298 } else if (gPrefs[i].type == "int") {
michael@0 299 SpecialPowers.setIntPref(gPrefs[i].name, gPrefs[i].newValue);
michael@0 300 } else if (gPrefs[i].type == "float") {
michael@0 301 SpecialPowers.setIntPref(gPrefs[i].name, gPrefs[i].newValue * 100);
michael@0 302 }
michael@0 303 }
michael@0 304
michael@0 305 var iframe = document.getElementById("result");
michael@0 306 iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
michael@0 307 iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
michael@0 308 iframe = document.getElementById("reference");
michael@0 309 iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
michael@0 310 iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
michael@0 311
michael@0 312 run();
michael@0 313 }
michael@0 314
michael@0 315 function cleanup()
michael@0 316 {
michael@0 317 SpecialPowers.clearUserPref("font.size.variable.x-western");
michael@0 318 for (var i = 0; i < gPrefs.length; i++) {
michael@0 319 SpecialPowers.clearUserPref(gPrefs[i].name);
michael@0 320 }
michael@0 321 }
michael@0 322
michael@0 323 SimpleTest.waitForExplicitFinish();
michael@0 324 SimpleTest.waitForFocus(onLoad, window);
michael@0 325
michael@0 326 </script>
michael@0 327
michael@0 328 </head>
michael@0 329 <body>
michael@0 330
michael@0 331 <iframe src="frame_selection_underline.xhtml" id="result"></iframe>
michael@0 332 <iframe src="frame_selection_underline-ref.xhtml" id="reference"></iframe>
michael@0 333 <pre id="test">
michael@0 334 </pre>
michael@0 335
michael@0 336 </body>
michael@0 337 </html>

mercurial