layout/generic/test/test_selection_underline.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/test/test_selection_underline.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,337 @@
     1.4 +<html>
     1.5 +
     1.6 +<head>
     1.7 +  <title>Test for selection underline</title>
     1.8 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +
    1.12 +<script type="text/javascript">
    1.13 +
    1.14 +// Canvas related code stolen from layout/base/tests/bidi_numeral_test.js which
    1.15 +// stole from http://developer.mozilla.org/en/docs/Code_snippets:Canvas
    1.16 +
    1.17 +var RemoteCanvas = function(aIFrame, aTest) {
    1.18 +  this.iframe = aIFrame;
    1.19 +  this.test = aTest;
    1.20 +  this.snapshot = null;
    1.21 +};
    1.22 +
    1.23 +RemoteCanvas.CANVAS_WIDTH = 200;
    1.24 +RemoteCanvas.CANVAS_HEIGHT = 100;
    1.25 +
    1.26 +RemoteCanvas.prototype.compare = function(otherCanvas, expected) {
    1.27 +  var ret = compareSnapshots(this.snapshot, otherCanvas.snapshot, expected);
    1.28 +  this.snapshotDataURL = ret[1];
    1.29 +  otherCanvas.snapshotDataURL = ret[2];
    1.30 +  return ret[0];
    1.31 +}
    1.32 +
    1.33 +RemoteCanvas.prototype.isReference = function() {
    1.34 +  return this.iframe && (this.iframe.id == "reference");
    1.35 +}
    1.36 +
    1.37 +RemoteCanvas.prototype.load = function(callback) {
    1.38 +  this.iframe.contentWindow.wrappedJSObject.init(this.test);
    1.39 +  var me = this;
    1.40 +  setTimeout(function () { me.remotePagePrepared(callback) }, 100);
    1.41 +}
    1.42 +
    1.43 +RemoteCanvas.prototype.remotePagePrepared = function(callback) {
    1.44 +  this.snapshot = snapshotWindow(this.iframe.contentWindow);
    1.45 +  callback(this);
    1.46 +}
    1.47 +
    1.48 +var gPrefs = [
    1.49 +  {
    1.50 +    name: "ui.SpellCheckerUnderline",
    1.51 +    type: "char",
    1.52 +    newValue: "#ff0000"
    1.53 +  },
    1.54 +  {
    1.55 +    name: "ui.IMERawInputBackground",
    1.56 +    type: "char",
    1.57 +    newValue: "transparent"
    1.58 +  },
    1.59 +  {
    1.60 +    name: "ui.IMERawInputForeground",
    1.61 +    type: "char",
    1.62 +    newValue: "#000000"
    1.63 +  },
    1.64 +  {
    1.65 +    name: "ui.IMERawInputUnderline",
    1.66 +    type: "char",
    1.67 +    newValue: "#00ff00"
    1.68 +  },
    1.69 +  {
    1.70 +    name: "ui.IMESelectedRawTextBackground",
    1.71 +    type: "char",
    1.72 +    newValue: "transparent"
    1.73 +  },
    1.74 +  {
    1.75 +    name: "ui.IMESelectedRawTextForeground",
    1.76 +    type: "char",
    1.77 +    newValue: "#000000"
    1.78 +  },
    1.79 +  {
    1.80 +    name: "ui.IMESelectedRawTextUnderline",
    1.81 +    type: "char",
    1.82 +    newValue: "#0000ff"
    1.83 +  },
    1.84 +  {
    1.85 +    name: "ui.IMEConvertedTextBackground",
    1.86 +    type: "char",
    1.87 +    newValue: "transparent"
    1.88 +  },
    1.89 +  {
    1.90 +    name: "ui.IMEConvertedTextForeground",
    1.91 +    type: "char",
    1.92 +    newValue: "#000000"
    1.93 +  },
    1.94 +  {
    1.95 +    name: "ui.IMEConvertedTextUnderline",
    1.96 +    type: "char",
    1.97 +    newValue: "#ffff00"
    1.98 +  },
    1.99 +  {
   1.100 +    name: "ui.IMESelectedConvertedTextBackground",
   1.101 +    type: "char",
   1.102 +    newValue: "transparent"
   1.103 +  },
   1.104 +  {
   1.105 +    name: "ui.IMESelectedConvertedTextForeground",
   1.106 +    type: "char",
   1.107 +    newValue: "#000000"
   1.108 +  },
   1.109 +  {
   1.110 +    name: "ui.IMESelectedConvertedTextUnderline",
   1.111 +    type: "char",
   1.112 +    newValue: "#00ffff"
   1.113 +  },
   1.114 +  {
   1.115 +    name: "ui.SpellCheckerUnderlineStyle",
   1.116 +    type: "int",
   1.117 +    newValue: 0
   1.118 +  },
   1.119 +  {
   1.120 +    name: "ui.IMERawInputUnderlineStyle",
   1.121 +    type: "int",
   1.122 +    newValue: 0
   1.123 +  },
   1.124 +  {
   1.125 +    name: "ui.IMESelectedRawTextUnderlineStyle",
   1.126 +    type: "int",
   1.127 +    newValue: 0
   1.128 +  },
   1.129 +  {
   1.130 +    name: "ui.IMEConvertedTextUnderlineStyle",
   1.131 +    type: "int",
   1.132 +    newValue: 0
   1.133 +  },
   1.134 +  {
   1.135 +    name: "ui.IMESelectedConvertedTextUnderlineStyle",
   1.136 +    type: "int",
   1.137 +    newValue: 0
   1.138 +  },
   1.139 +  {
   1.140 +    name: "ui.SpellCheckerUnderlineRelativeSize",
   1.141 +    type: "float",
   1.142 +    newValue: 1.0
   1.143 +  },
   1.144 +  {
   1.145 +    name: "ui.IMEUnderlineRelativeSize",
   1.146 +    type: "float",
   1.147 +    newValue: 1.0
   1.148 +  }
   1.149 +];
   1.150 +
   1.151 +const nsISelectionController = Components.interfaces.nsISelectionController;
   1.152 +
   1.153 +var gSelectionIndex = -1;
   1.154 +const kSelections = [
   1.155 +  { type: nsISelectionController.SELECTION_SPELLCHECK,
   1.156 +    typeName: "SpellCheck", isIME: false,
   1.157 +    decorationColor: "#ff0000" },
   1.158 +  { type: nsISelectionController.SELECTION_IME_RAWINPUT,
   1.159 +    typeName: "IME-RawInput", isIME: true,
   1.160 +    decorationColor: "#00ff00" },
   1.161 +  { type: nsISelectionController.SELECTION_IME_SELECTEDRAWTEXT,
   1.162 +    typeName: "IME-SelectedRawText", isIME: true,
   1.163 +    decorationColor: "#0000ff" },
   1.164 +  { type: nsISelectionController.SELECTION_IME_CONVERTEDTEXT,
   1.165 +    typeName: "IME-ConvertedText", isIME: true,
   1.166 +    decorationColor: "#ffff00" },
   1.167 +  { type: nsISelectionController.SELECTION_IME_SELECTEDCONVERTEDTEXT,
   1.168 +    typeName: "IME-SelectedConvertedText", isIME: true,
   1.169 +    decorationColor: "#00ffff" },
   1.170 +];
   1.171 +
   1.172 +const kFontName_Ahem = "AhemTest";
   1.173 +const kFontName_MPlus = "mplusTest";
   1.174 +
   1.175 +var gFontIndex = 0;
   1.176 +const kFonts = [
   1.177 +  { family: kFontName_Ahem, defaultSize: 16 },
   1.178 +  { family: kFontName_Ahem, defaultSize: 20 },
   1.179 +  { family: kFontName_Ahem, defaultSize: 32 },
   1.180 +  { family: kFontName_Ahem, defaultSize: 52 },
   1.181 +
   1.182 +  { family: kFontName_MPlus, defaultSize: 16 },
   1.183 +  { family: kFontName_MPlus, defaultSize: 20 },
   1.184 +  { family: kFontName_MPlus, defaultSize: 32 },
   1.185 +  { family: kFontName_MPlus, defaultSize: 52 },
   1.186 +];
   1.187 +
   1.188 +const kDecorationStyleNone   = 0;
   1.189 +const kDecorationStyleDotted = 1;
   1.190 +const kDecorationStyleDashed = 2;
   1.191 +const kDecorationStyleSolid  = 3;
   1.192 +const kDecorationStyleDouble = 4;
   1.193 +const kDecorationStyleWavy   = 5;
   1.194 +
   1.195 +var gDecorationIndex = 0;
   1.196 +const kDecorations = [
   1.197 +  { relativeSize: 1.0, style: kDecorationStyleNone,   styleName: "-moz-none" },
   1.198 +  { relativeSize: 1.0, style: kDecorationStyleSolid,  styleName: "solid"     },
   1.199 +  { relativeSize: 1.0, style: kDecorationStyleDotted, styleName: "dotted"    },
   1.200 +  { relativeSize: 1.0, style: kDecorationStyleDashed, styleName: "dashed"    },
   1.201 +  { relativeSize: 1.0, style: kDecorationStyleDouble, styleName: "double"    },
   1.202 +  { relativeSize: 1.0, style: kDecorationStyleWavy,   styleName: "wavy"      },
   1.203 +
   1.204 +// XXX relativeSize 2.0 cannot be tested by CSS3 text-decoration
   1.205 +
   1.206 +];
   1.207 +
   1.208 +function run()
   1.209 +{
   1.210 +  if (++gSelectionIndex == kSelections.length) {
   1.211 +    if (++gFontIndex == kFonts.length) {
   1.212 +      if (++gDecorationIndex == kDecorations.length) {
   1.213 +        SimpleTest.finish();
   1.214 +        cleanup();
   1.215 +        return;
   1.216 +      }
   1.217 +      gFontIndex = 0;
   1.218 +    }
   1.219 +    gSelectionIndex = 0;
   1.220 +    SpecialPowers.setIntPref("font.size.variable.x-western",
   1.221 +                             kFonts[gFontIndex].defaultSize);
   1.222 +  }
   1.223 +
   1.224 +  var test = {
   1.225 +    font: kFonts[gFontIndex],
   1.226 +    decoration: kDecorations[gDecorationIndex],
   1.227 +    selection: kSelections[gSelectionIndex],
   1.228 +  };
   1.229 +
   1.230 +  SpecialPowers.setIntPref("ui.SpellCheckerUnderlineRelativeSize",
   1.231 +                           test.decoration.relativeSize * 100);
   1.232 +  SpecialPowers.setIntPref("ui.IMEUnderlineRelativeSize",
   1.233 +                           test.decoration.relativeSize * 100);
   1.234 +  SpecialPowers.setIntPref("ui.SpellCheckerUnderlineStyle",
   1.235 +                           test.decoration.style);
   1.236 +  SpecialPowers.setIntPref("ui.IMERawInputUnderlineStyle",
   1.237 +                           test.decoration.style);
   1.238 +  SpecialPowers.setIntPref("ui.IMESelectedRawTextUnderlineStyle",
   1.239 +                           test.decoration.style);
   1.240 +  SpecialPowers.setIntPref("ui.IMEConvertedTextUnderlineStyle",
   1.241 +                           test.decoration.style);
   1.242 +  SpecialPowers.setIntPref("ui.IMESelectedConvertedTextUnderlineStyle",
   1.243 +                           test.decoration.style);
   1.244 +
   1.245 +  SimpleTest.executeSoon(function () { doTest(test); });
   1.246 +}
   1.247 +
   1.248 +function doTest(aTest)
   1.249 +{
   1.250 +
   1.251 +  var canvases = [];
   1.252 +  function callbackTestCanvas(canvas)
   1.253 +  {
   1.254 +    canvases.push(canvas);
   1.255 +
   1.256 +    if (canvases.length != 2)
   1.257 +      return;
   1.258 +
   1.259 +    var result = !canvases[0].isReference() ? canvases[0] : canvases[1];
   1.260 +    var reference = canvases[0].isReference() ? canvases[0] : canvases[1];
   1.261 +
   1.262 +    var description = "Rendering of reftest (" +
   1.263 +                        "selection: " + aTest.selection.typeName +
   1.264 +                        ", style: " + aTest.decoration.styleName +
   1.265 +                        ", relativeSize: " + aTest.decoration.relativeSize +
   1.266 +                        ", font: " + aTest.font.family +
   1.267 +                        ", default font size: " + aTest.font.defaultSize +
   1.268 +                        ") is different\n" +
   1.269 +                        "RESULT=" + result.snapshotDataURL + "\n" +
   1.270 +                        "REFERENCE=" + reference.snapshotDataURL + "\n";
   1.271 +
   1.272 +    if (result.compare(reference, true)) {
   1.273 +      ok(true, description);
   1.274 +    // If the decoration line is thick and the descender of the text isn't
   1.275 +    // enough for containing it, selection underline may be painted lower
   1.276 +    // if it's possible.  Then, we cannot test it with CSS3 text-decoration.
   1.277 +    } else if (aTest.decoration.style == kDecorationStyleDouble ||
   1.278 +               aTest.decoration.style == kDecorationStyleWavy) {
   1.279 +      todo(false, description);
   1.280 +    } else {
   1.281 +      ok(false, description);
   1.282 +    }
   1.283 +
   1.284 +    canvases = [];
   1.285 +
   1.286 +    run();
   1.287 +  }
   1.288 +
   1.289 +  var testCanvas = new RemoteCanvas(document.getElementById("result"), aTest);
   1.290 +  testCanvas.load(callbackTestCanvas);
   1.291 +
   1.292 +  var refCanvas = new RemoteCanvas(document.getElementById("reference"), aTest);
   1.293 +  refCanvas.load(callbackTestCanvas);
   1.294 +}
   1.295 +
   1.296 +function onLoad()
   1.297 +{
   1.298 +  for (var i = 0; i < gPrefs.length; i++) {
   1.299 +    if (gPrefs[i].type == "char") {
   1.300 +      SpecialPowers.setCharPref(gPrefs[i].name, gPrefs[i].newValue);
   1.301 +    } else if (gPrefs[i].type == "int") {
   1.302 +      SpecialPowers.setIntPref(gPrefs[i].name, gPrefs[i].newValue);
   1.303 +    } else if (gPrefs[i].type == "float") {
   1.304 +      SpecialPowers.setIntPref(gPrefs[i].name, gPrefs[i].newValue * 100);
   1.305 +    }
   1.306 +  }
   1.307 +
   1.308 +  var iframe = document.getElementById("result");
   1.309 +  iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
   1.310 +  iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
   1.311 +  iframe = document.getElementById("reference");
   1.312 +  iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
   1.313 +  iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
   1.314 +
   1.315 +  run();
   1.316 +}
   1.317 +
   1.318 +function cleanup()
   1.319 +{
   1.320 +  SpecialPowers.clearUserPref("font.size.variable.x-western");
   1.321 +  for (var i = 0; i < gPrefs.length; i++) {
   1.322 +    SpecialPowers.clearUserPref(gPrefs[i].name);
   1.323 +  }
   1.324 +}
   1.325 +
   1.326 +SimpleTest.waitForExplicitFinish();
   1.327 +SimpleTest.waitForFocus(onLoad, window);
   1.328 +
   1.329 +</script>
   1.330 +
   1.331 +</head>
   1.332 +<body>
   1.333 +
   1.334 +<iframe src="frame_selection_underline.xhtml" id="result"></iframe>
   1.335 +<iframe src="frame_selection_underline-ref.xhtml" id="reference"></iframe>
   1.336 +<pre id="test">
   1.337 +</pre>
   1.338 +
   1.339 +</body>
   1.340 +</html>

mercurial