OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> |
| 3 <head> |
| 4 <link rel="help" href="http://www.w3.org/TR/2013/WD-2dcontext2-20130528/#dom-con
text-2d-setlinedash"> |
| 5 <script src="../js/resources/js-test-pre.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 <script> |
| 9 description("Test that setLineDash converts input argument into a Web IDL sequen
ce"); |
| 10 |
| 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'); |
| 16 |
| 17 var arrayValues = [5, 15, 25]; |
| 18 |
| 19 function createTestArray(arrayType) { |
| 20 var array; |
| 21 if (arrayType == Object) { |
| 22 // Test a "sequence" (Object with length property). |
| 23 array = {length: arrayValues.length}; |
| 24 } else { |
| 25 array = new arrayType(arrayValues.length); |
| 26 } |
| 27 |
| 28 for (var i = 0; i < arrayValues.length; ++i) |
| 29 array[i] = arrayValues[i] |
| 30 return array; |
| 31 } |
| 32 |
| 33 var lineDash; |
| 34 var inputArray; |
| 35 function checkLineDash(testArray, shouldFail) { |
| 36 inputArray = testArray; |
| 37 // Reset line dash. |
| 38 ctx.setLineDash([]); |
| 39 // Set line dash. |
| 40 if (shouldFail) { |
| 41 shouldThrow("ctx.setLineDash(inputArray)", "'TypeError: Type error'"); |
| 42 } else { |
| 43 ctx.setLineDash(inputArray); |
| 44 lineDash = ctx.getLineDash(); |
| 45 for (var i = 0; i < arrayValues.length; ++i) |
| 46 shouldBe("lineDash[" + i + "]", "" + arrayValues[i]); |
| 47 } |
| 48 } |
| 49 |
| 50 var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Ar
ray, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object]; |
| 51 |
| 52 // Success cases. |
| 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); |
| 56 } |
| 57 |
| 58 // Failure cases. |
| 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); |
| 75 </script> |
| 76 <script src="../js/resources/js-test-post.js"></script> |
| 77 </body> |
| 78 </html> |
OLD | NEW |