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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-putImageData.html

Issue 2771933002: Update createImageData/getImageData/putImageData from float to long (Closed)
Patch Set: Reset tests Created 3 years, 8 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 <script src="../../resources/testharness.js"></script> 1 <script src="../../resources/testharness.js"></script>
2 <script src="../../resources/testharnessreport.js"></script> 2 <script src="../../resources/testharnessreport.js"></script>
3 <canvas id="canvas" width="100" height="100"></canvas><br/> 3 <canvas id="canvas" width="100" height="100"></canvas><br/>
4 <script> 4 <script>
5 5
6 function fillRect(imageData, x, y, width, height, r, g, b, a) 6 function fillRect(imageData, x, y, width, height, r, g, b, a)
7 { 7 {
8 var bytesPerRow = imageData.width * 4; 8 var bytesPerRow = imageData.width * 4;
9 var data =imageData.data; 9 var data =imageData.data;
10 for (var i = 0; i < height; i++) { 10 for (var i = 0; i < height; i++) {
(...skipping 11 matching lines...) Expand all
22 22
23 var canvas = document.getElementById("canvas"); 23 var canvas = document.getElementById("canvas");
24 var context = canvas.getContext("2d"); 24 var context = canvas.getContext("2d");
25 25
26 if (!context.createImageData) 26 if (!context.createImageData)
27 context.createImageData = function(w, h) { 27 context.createImageData = function(w, h) {
28 var data = this.getImageData(0, 0, w, h); 28 var data = this.getImageData(0, 0, w, h);
29 for (var i = 0; i < data.data.length; i++) 29 for (var i = 0; i < data.data.length; i++)
30 data.data[i] = 0; 30 data.data[i] = 0;
31 } 31 }
32 32
33 var buffer = context.createImageData(100, 100); 33 var buffer = context.createImageData(100, 100);
34 // Fill top left corner 34 // Fill top left corner
35 fillRect(buffer, 0, 0, 50, 50, 0, 128, 0, 255); 35 fillRect(buffer, 0, 0, 50, 50, 0, 128, 0, 255);
36 36
37 function checkPixelColor(x, y, color) 37 function checkPixelColor(x, y, color)
38 { 38 {
39 data = context.getImageData(x, y, 1, 1).data; 39 data = context.getImageData(x, y, 1, 1).data;
40 for (i = 0; i < 4; i++) 40 for (i = 0; i < 4; i++)
41 if (data[i] != color [i]) 41 if (data[i] != color [i])
42 return false; 42 return false;
43 return true; 43 return true;
44 } 44 }
45 45
46 function pixelShouldBe(x, y, color) 46 function pixelShouldBe(x, y, color)
47 { 47 {
48 assert_array_equals(context.getImageData(x, y, 1, 1).data, color); 48 assert_array_equals(context.getImageData(x, y, 1, 1).data, color);
49 } 49 }
50 50
51 var pixelTests = [ 51 var pixelTests = [
52 // 0 - 6 52 // 0 - 6
53 ['PixelTestBasicDrawing 1', 25, 25, [0, 128, 0, 255]], 53 ['PixelTestBasicDrawing 1', 25, 25, [0, 128, 0, 255]],
54 ['PixelTestBasicDrawing 2', 49, 0, [0, 128, 0, 255]], 54 ['PixelTestBasicDrawing 2', 49, 0, [0, 128, 0, 255]],
55 ['PixelTestBasicDrawing 3', 0, 49, [0, 128, 0, 255]], 55 ['PixelTestBasicDrawing 3', 0, 49, [0, 128, 0, 255]],
56 ['PixelTestBasicDrawing 4', 49, 49, [0, 128, 0, 255]], 56 ['PixelTestBasicDrawing 4', 49, 49, [0, 128, 0, 255]],
57 ['PixelTestBasicDrawing 5', 50, 0, [0, 0, 0, 0]], 57 ['PixelTestBasicDrawing 5', 50, 0, [0, 0, 0, 0]],
58 ['PixelTestBasicDrawing 6', 0, 50, [0, 0, 0, 0]], 58 ['PixelTestBasicDrawing 6', 0, 50, [0, 0, 0, 0]],
59 ['PixelTestBasicDrawing 7', 50, 50, [0, 0, 0, 0]], 59 ['PixelTestBasicDrawing 7', 50, 50, [0, 0, 0, 0]],
60 // 7 - 11 60 // 7 - 11
61 ['PixelTestPositionedDrawing 1', 0, 50, [0, 128, 0, 255]], 61 ['PixelTestPositionedDrawing 1', 0, 50, [0, 128, 0, 255]],
62 ['PixelTestPositionedDrawing 2', 25, 75, [0, 128, 0, 255]], 62 ['PixelTestPositionedDrawing 2', 25, 75, [0, 128, 0, 255]],
63 ['PixelTestPositionedDrawing 3', 49, 50, [0, 128, 0, 255]], 63 ['PixelTestPositionedDrawing 3', 49, 50, [0, 128, 0, 255]],
64 ['PixelTestPositionedDrawing 4', 0, 99, [0, 128, 0, 255]], 64 ['PixelTestPositionedDrawing 4', 0, 99, [0, 128, 0, 255]],
65 ['PixelTestPositionedDrawing 5', 49, 99, [0, 128, 0, 255]], 65 ['PixelTestPositionedDrawing 5', 49, 99, [0, 128, 0, 255]],
66 // 12 - 15 66 // 12 - 15
67 ['PixelTestTranslation 1', 50, 50, [0, 128, 0, 255]], 67 ['PixelTestTranslation 1', 50, 50, [0, 128, 0, 255]],
68 ['PixelTestTranslation 2', 75, 75, [0, 128, 0, 255]], 68 ['PixelTestTranslation 2', 75, 75, [0, 128, 0, 255]],
69 ['PixelTestTranslation 3', 99, 99, [0, 128, 0, 255]], 69 ['PixelTestTranslation 3', 99, 99, [0, 128, 0, 255]],
70 ['PixelTestTranslation 4', 50, 49, [0, 0, 0, 0]], 70 ['PixelTestTranslation 4', 50, 49, [0, 0, 0, 0]],
71 // 16 - 27 71 // 16 - 27
72 ['PixelTestRegionIntersectLeftEdge 1', 0, 25, [0, 128, 0, 255]], 72 ['PixelTestRegionIntersectLeftEdge 1', 0, 25, [0, 128, 0, 255]],
73 ['PixelTestRegionIntersectLeftEdge 2', 0, 50, [0, 128, 0, 255]], 73 ['PixelTestRegionIntersectLeftEdge 2', 0, 50, [0, 128, 0, 255]],
74 ['PixelTestRegionIntersectLeftEdge 3', 0, 75, [0, 128, 0, 255]], 74 ['PixelTestRegionIntersectLeftEdge 3', 0, 75, [0, 128, 0, 255]],
75 ['PixelTestRegionIntersectRightEdge 1', 99, 25, [0, 128, 0, 255]], 75 ['PixelTestRegionIntersectRightEdge 1', 99, 25, [0, 128, 0, 255]],
76 ['PixelTestRegionIntersectRightEdge 2', 99, 50, [0, 128, 0, 255]], 76 ['PixelTestRegionIntersectRightEdge 2', 99, 50, [0, 128, 0, 255]],
77 ['PixelTestRegionIntersectRightEdge 3', 99, 75, [0, 128, 0, 255]], 77 ['PixelTestRegionIntersectRightEdge 3', 99, 75, [0, 128, 0, 255]],
78 ['PixelTestRegionIntersectTopEdge 1', 25, 0, [0, 128, 0, 255]], 78 ['PixelTestRegionIntersectTopEdge 1', 25, 0, [0, 128, 0, 255]],
79 ['PixelTestRegionIntersectTopEdge 2', 50, 0, [0, 128, 0, 255]], 79 ['PixelTestRegionIntersectTopEdge 2', 50, 0, [0, 128, 0, 255]],
80 ['PixelTestRegionIntersectTopEdge 3', 75, 0, [0, 128, 0, 255]], 80 ['PixelTestRegionIntersectTopEdge 3', 75, 0, [0, 128, 0, 255]],
81 ['PixelTestRegionIntersectBototmEdge 1', 25, 99, [0, 128, 0, 255]], 81 ['PixelTestRegionIntersectBototmEdge 1', 25, 99, [0, 128, 0, 255]],
82 ['PixelTestRegionIntersectBototmEdge 2', 50, 99, [0, 128, 0, 255]], 82 ['PixelTestRegionIntersectBototmEdge 2', 50, 99, [0, 128, 0, 255]],
83 ['PixelTestRegionIntersectBototmEdge 3', 75, 99, [0, 128, 0, 255]], 83 ['PixelTestRegionIntersectBototmEdge 3', 75, 99, [0, 128, 0, 255]],
84 // 28 - 51 84 // 28 - 51
85 ['PixelTestDirtyRegionIntersectLeftEdge 1', 0, 25, [0, 128, 0, 255]], 85 ['PixelTestDirtyRegionIntersectLeftEdge 1', 0, 25, [0, 128, 0, 255]],
86 ['PixelTestDirtyRegionIntersectLeftEdge 2', 0, 50, [0, 128, 0, 255]], 86 ['PixelTestDirtyRegionIntersectLeftEdge 2', 0, 50, [0, 128, 0, 255]],
87 ['PixelTestDirtyRegionIntersectLeftEdge 3', 0, 75, [0, 128, 0, 255]], 87 ['PixelTestDirtyRegionIntersectLeftEdge 3', 0, 75, [0, 128, 0, 255]],
88 ['PixelTestDirtyRegionIntersectLeftEdge 4', 10, 25, [0, 128, 0, 255]], 88 ['PixelTestDirtyRegionIntersectLeftEdge 4', 10, 25, [0, 128, 0, 255]],
89 ['PixelTestDirtyRegionIntersectLeftEdge 5', 10, 50, [0, 128, 0, 255]], 89 ['PixelTestDirtyRegionIntersectLeftEdge 5', 10, 50, [0, 128, 0, 255]],
90 ['PixelTestDirtyRegionIntersectLeftEdge 6', 10, 75, [0, 128, 0, 255]], 90 ['PixelTestDirtyRegionIntersectLeftEdge 6', 10, 75, [0, 128, 0, 255]],
91 ['PixelTestDirtyRegionIntersectRightEdge 1', 99, 25, [0, 128, 0, 255]], 91 ['PixelTestDirtyRegionIntersectRightEdge 1', 99, 25, [0, 128, 0, 255]],
92 ['PixelTestDirtyRegionIntersectRightEdge 2', 99, 50, [0, 128, 0, 255]], 92 ['PixelTestDirtyRegionIntersectRightEdge 2', 99, 50, [0, 128, 0, 255]],
93 ['PixelTestDirtyRegionIntersectRightEdge 3', 99, 75, [0, 128, 0, 255]], 93 ['PixelTestDirtyRegionIntersectRightEdge 3', 99, 75, [0, 128, 0, 255]],
94 ['PixelTestDirtyRegionIntersectRightEdge 4', 89, 25, [0, 128, 0, 255]], 94 ['PixelTestDirtyRegionIntersectRightEdge 4', 89, 25, [0, 128, 0, 255]],
95 ['PixelTestDirtyRegionIntersectRightEdge 5', 89, 50, [0, 128, 0, 255]], 95 ['PixelTestDirtyRegionIntersectRightEdge 5', 89, 50, [0, 128, 0, 255]],
96 ['PixelTestDirtyRegionIntersectRightEdge 6', 89, 75, [0, 128, 0, 255]], 96 ['PixelTestDirtyRegionIntersectRightEdge 6', 89, 75, [0, 128, 0, 255]],
97 ['PixelTestDirtyRegionIntersectTopEdge 1', 25, 0, [0, 128, 0, 255]], 97 ['PixelTestDirtyRegionIntersectTopEdge 1', 25, 0, [0, 128, 0, 255]],
98 ['PixelTestDirtyRegionIntersectTopEdge 2', 50, 0, [0, 128, 0, 255]], 98 ['PixelTestDirtyRegionIntersectTopEdge 2', 50, 0, [0, 128, 0, 255]],
99 ['PixelTestDirtyRegionIntersectTopEdge 3', 75, 0, [0, 128, 0, 255]], 99 ['PixelTestDirtyRegionIntersectTopEdge 3', 75, 0, [0, 128, 0, 255]],
100 ['PixelTestDirtyRegionIntersectTopEdge 4', 25, 10, [0, 128, 0, 255]], 100 ['PixelTestDirtyRegionIntersectTopEdge 4', 25, 10, [0, 128, 0, 255]],
101 ['PixelTestDirtyRegionIntersectTopEdge 5', 50, 10, [0, 128, 0, 255]], 101 ['PixelTestDirtyRegionIntersectTopEdge 5', 50, 10, [0, 128, 0, 255]],
102 ['PixelTestDirtyRegionIntersectTopEdge 6', 75, 10, [0, 128, 0, 255]], 102 ['PixelTestDirtyRegionIntersectTopEdge 6', 75, 10, [0, 128, 0, 255]],
103 ['PixelTestDirtyRegionIntersectBottomEdge 1', 25, 99, [0, 128, 0, 255]], 103 ['PixelTestDirtyRegionIntersectBottomEdge 1', 25, 99, [0, 128, 0, 255]],
104 ['PixelTestDirtyRegionIntersectBottomEdge 2', 50, 99, [0, 128, 0, 255]], 104 ['PixelTestDirtyRegionIntersectBottomEdge 2', 50, 99, [0, 128, 0, 255]],
105 ['PixelTestDirtyRegionIntersectBottomEdge 3', 75, 99, [0, 128, 0, 255]], 105 ['PixelTestDirtyRegionIntersectBottomEdge 3', 75, 99, [0, 128, 0, 255]],
106 ['PixelTestDirtyRegionIntersectBottomEdge 4', 25, 89, [0, 128, 0, 255]], 106 ['PixelTestDirtyRegionIntersectBottomEdge 4', 25, 89, [0, 128, 0, 255]],
107 ['PixelTestDirtyRegionIntersectBottomEdge 5', 50, 89, [0, 128, 0, 255]], 107 ['PixelTestDirtyRegionIntersectBottomEdge 5', 50, 89, [0, 128, 0, 255]],
108 ['PixelTestDirtyRegionIntersectBottomEdge 6', 75, 89, [0, 128, 0, 255]], 108 ['PixelTestDirtyRegionIntersectBottomEdge 6', 75, 89, [0, 128, 0, 255]],
109 ]; 109 ];
110 110
111 // Test basic drawing 111 // Test basic drawing
112 context.putImageData(buffer, 0, 0); 112 context.putImageData(buffer, 0, 0);
113 generate_tests(pixelShouldBe, pixelTests.slice(0,7)); 113 generate_tests(pixelShouldBe, pixelTests.slice(0,7));
114 114
115 // Test positioned drawing -- make bottom right green 115 // Test positioned drawing -- make bottom right green
116 context.putImageData(buffer, 0, 50); 116 context.putImageData(buffer, 0, 50);
117 generate_tests(pixelShouldBe, pixelTests.slice(7, 12)); 117 generate_tests(pixelShouldBe, pixelTests.slice(7, 12));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 //right edge 196 //right edge
197 context.putImageData(buffer, 0, 0, 90, 0, 100, 100); 197 context.putImageData(buffer, 0, 0, 90, 0, 100, 100);
198 generate_tests(pixelShouldBe, pixelTests.slice(34, 40)); 198 generate_tests(pixelShouldBe, pixelTests.slice(34, 40));
199 // top edge 199 // top edge
200 context.putImageData(buffer, 0, 0, 0, -90, 100, 100); 200 context.putImageData(buffer, 0, 0, 0, -90, 100, 100);
201 generate_tests(pixelShouldBe, pixelTests.slice(40, 46)); 201 generate_tests(pixelShouldBe, pixelTests.slice(40, 46));
202 //bottom edge 202 //bottom edge
203 context.putImageData(buffer, 0, 0, 0, 90, 100, 100); 203 context.putImageData(buffer, 0, 0, 0, 90, 100, 100);
204 generate_tests(pixelShouldBe, pixelTests.slice(46)); 204 generate_tests(pixelShouldBe, pixelTests.slice(46));
205 }, "Test drawing with only part of the dirty region intersecting the window."); 205 }, "Test drawing with only part of the dirty region intersecting the window.");
206 206
207 test(function(t) { 207 test(function(t) {
208 var smallbuffer = context.createImageData(10, 10); 208 var smallbuffer = context.createImageData(10, 10);
209 fillRect(smallbuffer, 0, 0, 10, 10, 255, 0, 0, 255); 209 fillRect(smallbuffer, 0, 0, 10, 10, 255, 0, 0, 255);
210 context.putImageData(smallbuffer, 1.5, 1); 210 context.putImageData(smallbuffer, 1.5, 1);
211 pixelShouldBe(11, 11, [0, 128, 0, 255]); 211 pixelShouldBe(11, 11, [0, 128, 0, 255]);
212 fillRect(smallbuffer, 0, 0, 10, 10, 0, 128, 0, 255); 212 fillRect(smallbuffer, 0, 0, 10, 10, 0, 128, 0, 255);
213 context.putImageData(smallbuffer, 1.5, 1); 213 context.putImageData(smallbuffer, 1.5, 1);
214 pixelShouldBe(1, 1, [0, 128, 0, 255]); 214 pixelShouldBe(1, 1, [0, 128, 0, 255]);
215 }, "Test clamping of dx/dy."); 215 }, "Test clamping of dx/dy.");
216 216
(...skipping 18 matching lines...) Expand all
235 pixelShouldBe(1, 1, [0, 128, 0, 255]); 235 pixelShouldBe(1, 1, [0, 128, 0, 255]);
236 pixelShouldBe(9, 9, [0, 128, 0, 255]); 236 pixelShouldBe(9, 9, [0, 128, 0, 255]);
237 context.fillRect(1, 1, 7, 7); 237 context.fillRect(1, 1, 7, 7);
238 context.putImageData(smallbuffer, 1, 1, 0.5, 0.5, 7.9, 7.9); 238 context.putImageData(smallbuffer, 1, 1, 0.5, 0.5, 7.9, 7.9);
239 pixelShouldBe(1, 1, [0, 128, 0, 255]); 239 pixelShouldBe(1, 1, [0, 128, 0, 255]);
240 pixelShouldBe(9, 9, [0, 128, 0, 255]); 240 pixelShouldBe(9, 9, [0, 128, 0, 255]);
241 }, "Test clamping of dirtyX/Y/Width/Height."); 241 }, "Test clamping of dirtyX/Y/Width/Height.");
242 242
243 var testInvalidParams = [ 243 var testInvalidParams = [
244 ['TestInvalidParam 1', null, function() {context.putImageData({}, 0, 0);}], 244 ['TestInvalidParam 1', null, function() {context.putImageData({}, 0, 0);}],
245 ['TestInvalidParam 2', null, function() {context.putImageData(buffer, NaN, 0 , 0, 0, 0, 0);}], 245 ['TestInvalidParam 2', null, function() {context.putImageData(null, 0, 0, 0, 0, 0, 0);}],
246 ['TestInvalidParam 3', null, function() {context.putImageData(buffer, 0, NaN , 0, 0, 0, 0);}], 246 ['TestInvalidParam 3', null, function() {context.putImageData(undefined, 0, 0, 0, 0, 0, 0);}],
247 ['TestInvalidParam 4', null, function() {context.putImageData(buffer, 0, 0, NaN, 0, 0, 0);}],
248 ['TestInvalidParam 5', null, function() {context.putImageData(buffer, 0, 0, 0, NaN, 0, 0);}],
249 ['TestInvalidParam 6', null, function() {context.putImageData(buffer, 0, 0, 0, 0, NaN, 0);}],
250 ['TestInvalidParam 7', null, function() {context.putImageData(buffer, 0, 0, 0, 0, 0, NaN);}],
251 ['TestInvalidParam 8', null, function() {context.putImageData(buffer, Infini ty, 0, 0, 0, 0, 0);}],
252 ['TestInvalidParam 9', null, function() {context.putImageData(buffer, 0, Inf inity, 0, 0, 0, 0);}],
253 ['TestInvalidParam 10', null, function() {context.putImageData(buffer, 0, 0, Infinity, 0, 0, 0);}],
254 ['TestInvalidParam 11', null, function() {context.putImageData(buffer, 0, 0, 0, Infinity, 0, 0);}],
255 ['TestInvalidParam 12', null, function() {context.putImageData(buffer, 0, 0, 0, 0, Infinity, 0);}],
256 ['TestInvalidParam 13', null, function() {context.putImageData(buffer, 0, 0, 0, 0, 0, Infinity);}],
257 ['TestInvalidParam 14', null, function() {context.putImageData(buffer, undef ined, 0, 0, 0, 0, 0);}],
258 ['TestInvalidParam 15', null, function() {context.putImageData(buffer, 0, un defined, 0, 0, 0, 0);}],
259 ['TestInvalidParam 16', null, function() {context.putImageData(buffer, 0, 0, undefined, 0, 0, 0);}],
260 ['TestInvalidParam 17', null, function() {context.putImageData(buffer, 0, 0, 0, undefined, 0, 0);}],
261 ['TestInvalidParam 18', null, function() {context.putImageData(buffer, 0, 0, 0, 0, undefined, 0);}],
262 ['TestInvalidParam 19', null, function() {context.putImageData(buffer, 0, 0, 0, 0, 0, undefined);}],
263 ['TestInvalidParam 20', null, function() {context.putImageData(null, 0, 0, 0 , 0, 0, 0);}],
264 ['TestInvalidParam 21', null, function() {context.putImageData(undefined, 0, 0, 0, 0, 0, 0);}],
265 247
266 ]; 248 ];
267 249
268 generate_tests(assert_throws, testInvalidParams); 250 generate_tests(assert_throws, testInvalidParams);
269 251
270 test(function(t) { 252 test(function(t) {
271 var smallbuffer = context.createImageData(10, 10); 253 var smallbuffer = context.createImageData(10, 10);
272 var rectcanvas = document.createElement("canvas"); 254 var rectcanvas = document.createElement("canvas");
273 rectcanvas.width = 20; 255 rectcanvas.width = 20;
274 rectcanvas.height = 10; 256 rectcanvas.height = 10;
275 var rectbuffer = rectcanvas.getContext("2d"); 257 var rectbuffer = rectcanvas.getContext("2d");
276 rectbuffer.putImageData(smallbuffer, 10, 0); 258 rectbuffer.putImageData(smallbuffer, 10, 0);
277 259
278 var rectcanvas = document.createElement("canvas"); 260 var rectcanvas = document.createElement("canvas");
279 rectcanvas.width = 10; 261 rectcanvas.width = 10;
280 rectcanvas.height = 20; 262 rectcanvas.height = 20;
281 var rectbuffer = rectcanvas.getContext("2d"); 263 var rectbuffer = rectcanvas.getContext("2d");
282 rectbuffer.putImageData(smallbuffer, 0, 10); 264 rectbuffer.putImageData(smallbuffer, 0, 10);
283 }, "Ensure we don't mess up bounds clipping checks."); 265 }, "Ensure we don't mess up bounds clipping checks.");
284 </script> 266 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698