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

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

Issue 2703803002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Addressing comments Created 3 years, 9 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> 1 <script src="../../resources/testharness.js"></script>
2 <title>putImageData(getImageData) pair test</title> 2 <script src="../../resources/testharnessreport.js"></script>
3 <body class="show_output"> 3
4 <h3>Test that putImageData(getImageData) pair leaves canvas ImageData the same.< /h3>
5 <canvas id="c" class="output" width="64" height="64"><p class="fallback">FAIL (f allback content)</p></canvas>
6 <br>
7 Result: <a id="result"></a>
8 <script> 4 <script>
9 if (window.testRunner) 5 var canvas = document.createElement('canvas');
10 testRunner.dumpAsText(); 6 var ctx = canvas.getContext('2d');
11 7
12 var canvas = document.getElementById("c"); 8 function getPutImageData(numIters, ctx, rgba) {
13 var ctx = canvas.getContext("2d");
14 var passed = getPutImageData(50, ctx, 0, 0, 0, 0.0);
15 passed |= getPutImageData(50, ctx, 0, 0, 0, 0.5);
16 passed |= getPutImageData(50, ctx, 0, 0, 0, 1.0);
17 passed |= getPutImageData(50, ctx, 127, 128, 129, 0.49);
18 passed |= getPutImageData(50, ctx, 127, 128, 129, 0.51);
19 passed |= getPutImageData(50, ctx, 127, 128, 129, 0.5);
20 passed |= getPutImageData(50, ctx, 128, 128, 128, 0.0);
21 passed |= getPutImageData(50, ctx, 128, 128, 128, 0.5);
22 passed |= getPutImageData(50, ctx, 128, 128, 128, 1.0);
23
24 var result_a = document.getElementById("result");
25 if (!passed)
26 result_a.innerHTML = "FAIL";
27 else
28 result_a.innerHTML = "PASS";
29
30 function getPutImageData(numIters, ctx, r, g, b, a) {
31 var x = 0, y = 0, w = ctx.canvas.width, h = ctx.canvas.height; 9 var x = 0, y = 0, w = ctx.canvas.width, h = ctx.canvas.height;
32 10
33 // Paint the canvas green to start 11 // Paint the canvas green to start
34 ctx.fillStyle = color; 12 ctx.fillStyle = color;
35 ctx.fillRect(x,y,w,h); 13 ctx.fillRect(x,y,w,h);
36 14
37 // Now paint the canvas a random hue of gray 15 // Now paint the canvas a random hue of gray
38 var color = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; 16 var color = 'rgba(' + rgba + ')';
39 ctx.fillStyle = color; 17 ctx.fillStyle = color;
40 ctx.fillRect(x,y,w,h); 18 ctx.fillRect(x,y,w,h);
41 19
42 // Get the current "original" image data 20 // Get the current "original" image data
43 var origImageData = ctx.getImageData(x, y, w, h); 21 var origImageData = ctx.getImageData(x, y, w, h);
44 ctx.putImageData(origImageData, x, y); 22 ctx.putImageData(origImageData, x, y);
45 23
46 // Get and put the image data 'numIters' times 24 // Get and put the image data 'numIters' times
47 for(var i = 0; i < numIters; i++) 25 for(var i = 0; i < numIters; i++)
48 ctx.putImageData(ctx.getImageData(x,y,w,h), x,y); 26 ctx.putImageData(ctx.getImageData(x, y, w, h), x,y);
49 27
50 // Grab new current image data 28 // Grab new current image data
51 var currImageData = ctx.getImageData(x, y, w, h); 29 var currImageData = ctx.getImageData(x, y, w, h);
52 30
53 // Verify that original and new current image datas are equal 31 // Verify that original and new current image datas are equal
54 for(var i = 0; i < currImageData.data.length; i++) { 32 var dataMatch = true;
55 var origSubpixel = origImageData.data[i]; 33 for(var i = 0; i < currImageData.data.length; i++)
56 var currSubpixel = currImageData.data[i]; 34 if (origImageData.data[i] != currImageData.data[i]) {
35 dataMatch = false;
36 break;
37 }
38 assert_true(dataMatch);
39 }
57 40
58 // If even 1 subpixel is off, return failure 41 var testScenarios = [
59 if (origSubpixel != currSubpixel) 42 ['GetPutImageDataTestCase ', 50, ctx, '0, 0, 0, 0.0'],
60 return false; 43 ['GetPutImageDataTestCase ', 50, ctx, '0, 0, 0, 0.5'],
61 } 44 ['GetPutImageDataTestCase ', 50, ctx, '0, 0, 0, 1.0'],
62 return true; 45 ['GetPutImageDataTestCase ', 50, ctx, '127, 128, 129, 0.49'],
63 } 46 ['GetPutImageDataTestCase ', 50, ctx, '127, 128, 129, 0.51'],
64 </script> 47 ['GetPutImageDataTestCase ', 50, ctx, '127, 128, 129, 0.5'],
48 ['GetPutImageDataTestCase ', 50, ctx, '128, 128, 128, 0.0'],
49 ['GetPutImageDataTestCase ', 50, ctx, '128, 128, 128, 0.5'],
50 ['GetPutImageDataTestCase ', 50, ctx, '128, 128, 128, 1.0'],
51 ];
52
53 generate_tests(getPutImageData, testScenarios);
54
55 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698