Index: LayoutTests/fast/canvas/canvas-lineDash-input-sequence.html |
diff --git a/LayoutTests/fast/canvas/canvas-lineDash-input-sequence.html b/LayoutTests/fast/canvas/canvas-lineDash-input-sequence.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9960dd2b4e2e977164eec342f03f2d6ca6b3bb2b |
--- /dev/null |
+++ b/LayoutTests/fast/canvas/canvas-lineDash-input-sequence.html |
@@ -0,0 +1,78 @@ |
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
+<html> |
+<head> |
+<link rel="help" href="http://www.w3.org/TR/2013/WD-2dcontext2-20130528/#dom-context-2d-setlinedash"> |
+<script src="../js/resources/js-test-pre.js"></script> |
+</head> |
+<body> |
+<script> |
+description("Test that setLineDash converts input argument into a Web IDL sequence"); |
+ |
+var canvas = document.createElement('canvas'); |
+document.body.appendChild(canvas); |
+canvas.setAttribute('width', '700'); |
+canvas.setAttribute('height', '700'); |
+var ctx = canvas.getContext('2d'); |
+ |
+var arrayValues = [5, 15, 25]; |
+ |
+function createTestArray(arrayType) { |
+ var array; |
+ if (arrayType == Object) { |
+ // Test a "sequence" (Object with length property). |
+ array = {length: arrayValues.length}; |
+ } else { |
+ array = new arrayType(arrayValues.length); |
+ } |
+ |
+ for (var i = 0; i < arrayValues.length; ++i) |
+ array[i] = arrayValues[i] |
+ return array; |
+} |
+ |
+var lineDash; |
+var inputArray; |
+function checkLineDash(testArray, shouldFail) { |
+ inputArray = testArray; |
+ // Reset line dash. |
+ ctx.setLineDash([]); |
+ // Set line dash. |
+ if (shouldFail) { |
+ shouldThrow("ctx.setLineDash(inputArray)", "'TypeError: Type error'"); |
+ } else { |
+ ctx.setLineDash(inputArray); |
+ lineDash = ctx.getLineDash(); |
+ for (var i = 0; i < arrayValues.length; ++i) |
+ shouldBe("lineDash[" + i + "]", "" + arrayValues[i]); |
+ } |
+} |
+ |
+var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object]; |
+ |
+// Success cases. |
+for (var i = 0; i < arrayTypes.length; ++i) { |
+ debug("* Test passing a " + arrayTypes[i].name + " as input."); |
+ checkLineDash(createTestArray(arrayTypes[i]), false); |
+} |
+ |
+// Failure cases. |
+debug("* Test passing a Date as input."); |
+checkLineDash(new Date(), true); |
+debug("* Test passing a RegExp as input."); |
+checkLineDash(new RegExp(), true); |
+debug("* Test passing an Object without length as input."); |
+checkLineDash({test: 1}, true); |
+debug("* Test passing a Number as input."); |
+checkLineDash(3, true); |
+debug("* Test passing a String as input."); |
+checkLineDash("Test", true); |
+debug("* Test passing a Boolean as input."); |
+checkLineDash(true, true); |
+debug("* Test passing null as input."); |
+checkLineDash(null, true); |
+debug("* Test passing undefined as input."); |
+checkLineDash(undefined, true); |
+</script> |
+<script src="../js/resources/js-test-post.js"></script> |
+</body> |
+</html> |