1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
4 <link rel="help" href="http://www.w3.org/TR/2013/WD-2dcontext2-20130528/#dom-context-2d-setlinedash">
5 <script src="../../resources/js-test.js"></script>
9 description("Test that setLineDash converts input argument into a Web IDL sequence");
11 var canvas = document.createElement('canvas');
12 document.body.appendChild(canvas);
13 canvas.setAttribute('width', '700');
14 canvas.setAttribute('height', '700');
15 var ctx = canvas.getContext('2d');
17 var arrayValues = [5, 15, 25];
19 function createTestArray(arrayType) {
21 if (arrayType == Object) {
22 // Test a "sequence" (Object with length property).
23 array = {length: arrayValues.length};
25 array = new arrayType(arrayValues.length);
28 for (var i = 0; i < arrayValues.length; ++i)
29 array[i] = arrayValues[i]
35 function checkLineDash(testArray, shouldFail) {
36 inputArray = testArray;
41 shouldThrow("ctx.setLineDash(inputArray)", "'TypeError: Failed to execute \\'setLineDash\\' on \\'CanvasRenderingContext2D\\': The 1st argument is neither an array, nor does it have indexed properties.'");
43 ctx.setLineDash(inputArray);
44 lineDash = ctx.getLineDash();
45 for (var i = 0; i < arrayValues.length; ++i)
46 shouldBe("lineDash[" + i + "]", "" + arrayValues[i]);
50 var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object];
53 for (var i = 0; i < arrayTypes.length; ++i) {
54 debug("* Test passing a " + arrayTypes[i].name + " as input.");
55 checkLineDash(createTestArray(arrayTypes[i]), false);
59 debug("* Test passing a Date as input.");
60 checkLineDash(new Date(), true);
61 debug("* Test passing a RegExp as input.");
62 checkLineDash(new RegExp(), true);
63 debug("* Test passing an Object without length as input.");
64 checkLineDash({test: 1}, true);
65 debug("* Test passing a Number as input.");
66 checkLineDash(3, true);
67 debug("* Test passing a String as input.");
68 checkLineDash("Test", true);
69 debug("* Test passing a Boolean as input.");
70 checkLineDash(true, true);
71 debug("* Test passing null as input.");
72 checkLineDash(null, true);
73 debug("* Test passing undefined as input.");
74 checkLineDash(undefined, true);