summaryrefslogtreecommitdiffstats
path: root/layout/reftests/canvas/dash-sanity.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /layout/reftests/canvas/dash-sanity.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'layout/reftests/canvas/dash-sanity.html')
-rw-r--r--layout/reftests/canvas/dash-sanity.html98
1 files changed, 98 insertions, 0 deletions
diff --git a/layout/reftests/canvas/dash-sanity.html b/layout/reftests/canvas/dash-sanity.html
new file mode 100644
index 000000000..779fbdeee
--- /dev/null
+++ b/layout/reftests/canvas/dash-sanity.html
@@ -0,0 +1,98 @@
+<html>
+<head>
+ <script type="text/javascript">
+function assert(cond, msg) { if (!cond) { throw msg; } }
+window.onload = function() {
+ try {
+ var ctx = document.getElementById("c1").getContext("2d");
+
+ assert(0 === ctx.getLineDash().length,
+ "Default dash is [ ] (none)");
+ assert(0 === ctx.lineDashOffset,
+ "Default dashOffset is 0 (none)");
+
+ ctx.setLineDash([ 2 ]);
+ assert(2 === ctx.getLineDash().length &&
+ 2 === ctx.getLineDash()[0] &&
+ 2 === ctx.getLineDash()[1],
+ "dash = [ 2 ] works");
+ ctx.setLineDash([ 2 ]);
+ ctx.setLineDash([ ]);
+ assert(0 === ctx.getLineDash().length,
+ "dash = [ ] works");
+ ctx.setLineDash([ 2 ]);
+ ctx.setLineDash([ 0, 0, 0 ]);
+ assert(6 === ctx.getLineDash().length,
+ 0 === ctx.getLineDash()[0] &&
+ 0 === ctx.getLineDash()[1] &&
+ 0 === ctx.getLineDash()[2] &&
+ 0 === ctx.getLineDash()[3] &&
+ 0 === ctx.getLineDash()[4] &&
+ 0 === ctx.getLineDash()[5],
+ "dash = [ 0, 0, 0 ] works");
+
+ ctx.setLineDash([ 2 ]);
+ assert(0 === ctx.lineDashOffset, "dashOffset is 0");
+ ctx.lineDashOffset = 1;
+ assert(1 === ctx.lineDashOffset, "Setting dashOffset succeeded");
+ ctx.setLineDash([ ]);
+ assert(1 === ctx.lineDashOffset, "Changing dash does not reset dashOffset");
+
+ // NB: might want to add a |.dash = number| special case,
+ // don't test that it fails here. Might also want to add a
+ // |.dash = [0]| special case for resetting, so don't test
+ // that either.
+ var badVals = [ -1,
+ null,
+ undefined,
+ "",
+ "string",
+ { obj: true },
+ function() {}
+ ]
+ ctx.setLineDash([ 2 ]);
+ for (var i = 0; i < badVals.length; ++i) {
+ var error = false;
+ try { ctx.setLineDash(badVals[i]); }
+ catch(e) { error = true; }
+ assert(error &&
+ 2 === ctx.getLineDash().length &&
+ 2 === ctx.getLineDash()[0] &&
+ 2 === ctx.getLineDash()[1],
+ "Expected setLineDash("+ badVals[i] +") to throw exception and not change dash");
+ }
+
+ var ignoredVals = [
+ [ "array of string" ],
+ [ -1 ],
+ [ 2, "string" ],
+ ];
+ ctx.setLineDash([ 2 ]);
+ for (var i = 0; i < ignoredVals.length; ++i) {
+ ctx.setLineDash(ignoredVals[i]);
+ assert(2 === ctx.getLineDash().length &&
+ 2 === ctx.getLineDash()[0] &&
+ 2 === ctx.getLineDash()[1],
+ "Expected |setLineDash(" + ignoredVals[i] + ") to not change dash");
+ }
+
+ ctx.setLineDash([ 2 ]);
+ ctx.save();
+ ctx.setLineDash([ 1, 1, 1, 1 ]);
+ ctx.restore();
+ assert(2 === ctx.getLineDash().length &&
+ 2 === ctx.getLineDash()[0] &&
+ 2 === ctx.getLineDash()[1],
+ "dash was saved then restored");
+ } catch (e) {
+ document.body.innerHTML = "FAIL: "+ e.toString();
+ return;
+ }
+ document.body.innerHTML = "Pass";
+}
+ </script>
+</head>
+<body>
+ <div><canvas id="c1" width="300" height="300"></canvas></div>
+</body>
+</html>