1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/reftests/canvas/dash-sanity.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +<html> 1.5 +<head> 1.6 + <script type="text/javascript"> 1.7 +function assert(cond, msg) { if (!cond) { throw msg; } } 1.8 +window.onload = function() { 1.9 + try { 1.10 + var ctx = document.getElementById("c1").getContext("2d"); 1.11 + 1.12 + assert(null === ctx.mozDash, 1.13 + "Default dash is null (no dash)"); 1.14 + assert(0 == ctx.mozDashOffset, 1.15 + "Default dashOffset is 0 (no dash)"); 1.16 + 1.17 + ctx.mozDash = [ 2 ]; 1.18 + assert(1 == ctx.mozDash.length && 2 == ctx.mozDash[0], 1.19 + "dash = [ 2 ] works"); 1.20 + ctx.mozDash = null; 1.21 + assert(null === ctx.mozDash, 1.22 + "dash = null resets to null"); 1.23 + ctx.mozDash = [ 2 ]; 1.24 + ctx.mozDash = undefined; 1.25 + assert(null === ctx.mozDash, 1.26 + "dash = undefined resets to null"); 1.27 + ctx.mozDash = [ 2 ]; 1.28 + ctx.mozDash = [ ]; 1.29 + assert(null === ctx.mozDash, 1.30 + "dash = [] resets to null"); 1.31 + 1.32 + ctx.mozDash = [ 2 ]; 1.33 + assert(0 == ctx.mozDashOffset, "dashOffset is 0"); 1.34 + ctx.mozDashOffset = 1; 1.35 + assert(1 == ctx.mozDashOffset, "Setting dashOffset succeeded"); 1.36 + ctx.mozDash = null; 1.37 + assert(0 == ctx.mozDashOffset, "Disabling dash resets dashOffset"); 1.38 + ctx.mozDash = [ 2 ]; 1.39 + assert(0 == ctx.mozDashOffset, "Previous dashOffset isn't remembered"); 1.40 + ctx.mozDash = null; 1.41 + 1.42 + // NB: might want to add a |.dash = number| special case, 1.43 + // don't test that it fails here. Might also want to add a 1.44 + // |.dash = [0]| special case for resetting, so don't test 1.45 + // that either. 1.46 + var badVals = [ -1, 1.47 + "string", 1.48 + /* According to the WebIDL sequence-ifying 1.49 + * (really they mean array-ifying here) 1.50 + * algorithm, objects without .length 1.51 + * properties convert to a 0-length arrays. 1.52 + * This seems ... odd, since by the book we're 1.53 + * forced to accept |ctx.dash = Function|, 1.54 + * e.g., but there it is. 1.55 + */ 1.56 + // { obj: true }, 1.57 + [ "array of string" ], 1.58 + [ -1 ], 1.59 + [ 0, 0, 0 ], 1.60 + [ 2, "string" ], 1.61 + ]; 1.62 + ctx.mozDash = [ 2 ]; 1.63 + for (var i = 0; i < badVals.length; ++i) { 1.64 + var error = false; 1.65 + try { ctx.mozDash = badVals[i]; } 1.66 + catch(e) { error = true; } 1.67 + assert(error && 1 == ctx.mozDash.length && 2 == ctx.mozDash[0], 1.68 + "Expected |dash = "+ badVals[i] +"| to throw exception and not change .dash"); 1.69 + } 1.70 + ctx.mozDash = null; 1.71 + 1.72 + ctx.save(); 1.73 + ctx.mozDash = [ 2 ]; 1.74 + ctx.restore(); 1.75 + assert(null === ctx.mozDash, 1.76 + "dash was saved then restored"); 1.77 + } catch (e) { 1.78 + document.body.innerHTML = "FAIL: "+ e.toString(); 1.79 + return; 1.80 + } 1.81 + document.body.innerHTML = "Pass"; 1.82 +} 1.83 + </script> 1.84 +</head> 1.85 +<body> 1.86 + <div><canvas id="c1" width="300" height="300"></canvas></div> 1.87 +</body> 1.88 +</html>