Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / canvas-lineDash-input-sequence.html
blob061d9f4afb282f7d9ccb2118a3cb9d647c868fa3
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-context-2d-setlinedash">
5 <script src="../../resources/js-test.js"></script>
6 </head>
7 <body>
8 <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) {
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);
28 for (var i = 0; i < arrayValues.length; ++i)
29 array[i] = arrayValues[i]
30 return array;
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: Failed to execute \\'setLineDash\\' on \\'CanvasRenderingContext2D\\': The 1st argument is neither an array, nor does it have indexed properties.'");
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]);
50 var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object];
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);
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 </body>
77 </html>