Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-lineDash-input-sequence.html

Issue 2681423002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Adding exceptions to TestExpectations Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"> 1 <link rel="help" href="http://www.w3.org/TR/2013/WD-2dcontext2-20130528/#dom-con text-2d-setlinedash">
5 <script src="../../resources/js-test.js"></script> 2 <script src="../../resources/testharness.js"></script>
6 </head> 3 <script src="../../resources/testharnessreport.js"></script>
7 <body> 4 <body>
8 <script> 5 <script>
9 description("Test that setLineDash converts input argument into a Web IDL sequen ce"); 6 test(function(t) {
10 7
11 var canvas = document.createElement('canvas'); 8 var canvas = document.createElement('canvas');
12 document.body.appendChild(canvas); 9 document.body.appendChild(canvas);
13 canvas.setAttribute('width', '700'); 10 canvas.setAttribute('width', '700');
14 canvas.setAttribute('height', '700'); 11 canvas.setAttribute('height', '700');
15 var ctx = canvas.getContext('2d'); 12 var ctx = canvas.getContext('2d');
16 13
17 var arrayValues = [5, 15, 25]; 14 var arrayValues = [5, 15, 25];
18 15
19 function createTestArray(arrayType) { 16 function createTestArray(arrayType) {
20 var array; 17 var array;
21 if (arrayType == Object) { 18 if (arrayType == Object) {
22 // Test a "sequence" (Object with length property). 19 // Test a "sequence" (Object with length property).
23 array = {length: arrayValues.length}; 20 array = {length: arrayValues.length};
24 } else { 21 } else {
25 array = new arrayType(arrayValues.length); 22 array = new arrayType(arrayValues.length);
26 } 23 }
27 24
28 for (var i = 0; i < arrayValues.length; ++i) 25 for (var i = 0; i < arrayValues.length; ++i)
29 array[i] = arrayValues[i] 26 array[i] = arrayValues[i]
30 return array; 27 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: Failed to execut e \\'setLineDash\\' on \\'CanvasRenderingContext2D\\': The 1st argument is neith er 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]);
47 } 28 }
48 } 29
49 30 var lineDash;
50 var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Ar ray, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object]; 31 var inputArray;
51 32 function checkLineDash(testArray, shouldFail) {
52 // Success cases. 33 inputArray = testArray;
53 for (var i = 0; i < arrayTypes.length; ++i) { 34 // Reset line dash.
54 debug("* Test passing a " + arrayTypes[i].name + " as input."); 35 ctx.setLineDash([]);
55 checkLineDash(createTestArray(arrayTypes[i]), false); 36 // Set line dash.
56 } 37 if (shouldFail) {
57 38 assert_throws(null, function() {ctx.setLineDash(inputArray);}, "'Typ eError: Failed to execute \\'setLineDash\\' on \\'CanvasRenderingContext2D\\': T he 1st argument is neither an array, nor does it have indexed properties.'");
58 // Failure cases. 39 } else {
59 debug("* Test passing a Date as input."); 40 ctx.setLineDash(inputArray);
60 checkLineDash(new Date(), true); 41 lineDash = ctx.getLineDash();
61 debug("* Test passing a RegExp as input."); 42 for (var i = 0; i < arrayValues.length; ++i)
62 checkLineDash(new RegExp(), true); 43 assert_equals(lineDash[i], arrayValues[i]);
63 debug("* Test passing an Object without length as input."); 44 }
64 checkLineDash({test: 1}, true); 45 }
65 debug("* Test passing a Number as input."); 46
66 checkLineDash(3, true); 47 var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint 16Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object];
67 debug("* Test passing a String as input."); 48
68 checkLineDash("Test", true); 49 // Success cases.
69 debug("* Test passing a Boolean as input."); 50 for (var i = 0; i < arrayTypes.length; ++i) {
70 checkLineDash(true, true); 51 // Test passing a valid array time as input.
71 debug("* Test passing null as input."); 52 checkLineDash(createTestArray(arrayTypes[i]), false);
72 checkLineDash(null, true); 53 }
73 debug("* Test passing undefined as input."); 54
74 checkLineDash(undefined, true); 55 // Failure cases.
56 // Test passing a Date as input.
57 checkLineDash(new Date(), true);
58 // Test passing a RegExp as input.
59 checkLineDash(new RegExp(), true);
60 // Test passing an Object without length as input.
61 checkLineDash({test: 1}, true);
62 // Test passing a Number as input.
63 checkLineDash(3, true);
64 // Test passing a String as input.
65 checkLineDash("Test", true);
66 // Test passing a Boolean as input.
67 checkLineDash(true, true);
68 // Test passing null as input.
69 checkLineDash(null, true);
70 // Test passing undefined as input.
71 checkLineDash(undefined, true);
72
73 }, 'Test that setLineDash converts input argument into a Web IDL sequence');
75 </script> 74 </script>
76 </body> 75 </body>
77 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698