OLD | NEW |
(Empty) | |
| 1 description("Test that setLineDash converts input argument into a Web IDL sequen
ce"); |
| 2 |
| 3 var canvas = document.createElement('canvas'); |
| 4 document.body.appendChild(canvas); |
| 5 canvas.setAttribute('width', '700'); |
| 6 canvas.setAttribute('height', '700'); |
| 7 var ctx = canvas.getContext('2d'); |
| 8 |
| 9 var arrayValues = [5, 15, 25]; |
| 10 |
| 11 function createTestArray(arrayType) { |
| 12 var array; |
| 13 if (arrayType == Object) { |
| 14 // Test a "sequence" (Object with length property). |
| 15 array = {length: arrayValues.length}; |
| 16 } else { |
| 17 array = new arrayType(arrayValues.length); |
| 18 } |
| 19 |
| 20 for (var i = 0; i < arrayValues.length; ++i) |
| 21 array[i] = arrayValues[i] |
| 22 return array; |
| 23 } |
| 24 |
| 25 var lineDash; |
| 26 var inputArray; |
| 27 function checkLineDash(testArray, shouldFail) { |
| 28 inputArray = testArray; |
| 29 // Reset line dash. |
| 30 ctx.setLineDash([]); |
| 31 // Set line dash. |
| 32 if (shouldFail) { |
| 33 shouldThrow("ctx.setLineDash(inputArray)", "'TypeError: Type error'"); |
| 34 } else { |
| 35 ctx.setLineDash(inputArray); |
| 36 lineDash = ctx.getLineDash(); |
| 37 for (var i = 0; i < arrayValues.length; ++i) |
| 38 shouldBe("lineDash[" + i + "]", "" + arrayValues[i]); |
| 39 } |
| 40 } |
| 41 |
| 42 var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Ar
ray, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object]; |
| 43 |
| 44 // Success cases. |
| 45 for (var i = 0; i < arrayTypes.length; ++i) { |
| 46 debug("* Test passing a " + arrayTypes[i].name + " as input."); |
| 47 checkLineDash(createTestArray(arrayTypes[i]), false); |
| 48 } |
| 49 |
| 50 // Failure cases. |
| 51 debug("* Test passing a Date as input."); |
| 52 checkLineDash(new Date(), true); |
| 53 debug("* Test passing a RegExp as input."); |
| 54 checkLineDash(new RegExp(), true); |
| 55 debug("* Test passing an Object without length as input."); |
| 56 checkLineDash({test: 1}, true); |
| 57 debug("* Test passing a Number as input."); |
| 58 checkLineDash(3, true); |
| 59 debug("* Test passing a String as input."); |
| 60 checkLineDash("Test", true); |
| 61 debug("* Test passing a Boolean as input."); |
| 62 checkLineDash(true, true); |
| 63 debug("* Test passing null as input."); |
| 64 checkLineDash(null, true); |
| 65 debug("* Test passing undefined as input."); |
| 66 checkLineDash(undefined, true); |
| 67 |
OLD | NEW |