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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-scale-drawImage-shadow.html

Issue 2696023002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Rebaseline 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"> 1 <script src="../../resources/testharness.js"></script>
2 <html> 2 <script src="../../resources/testharnessreport.js"></script>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body> 3 <body>
7 <script src="script-tests/canvas-scale-drawImage-shadow.js"></script> 4 <script>
5 async_test(t => {
6 // Create auxiliary canvas to draw to and create an image from.
7 // This is done instead of simply loading an image from the file system
8 // because that would throw a SECURITY_ERR DOM Exception.
9 var aCanvas = document.createElement('canvas');
10 aCanvas.width = aCanvas.height = 10;
11 var aCtx = aCanvas.getContext('2d');
12 aCtx.fillStyle = 'rgba(0, 0, 255, 1)';
13 aCtx.fillRect(0, 0, 50, 50);
14
15 // Create the image object to be drawn on the master canvas.
16 var img = new Image();
17 img.onload = drawImageToCanvasAndCheckPixels;
18 img.src = aCanvas.toDataURL(); // set a data URI of the base64 encoded image as the source
19
20 aCanvas.width = 10;
21 aCtx.fillStyle = 'rgba(0, 0, 255, 0.5)';
22 aCtx.fillRect(0, 0, 50, 50);
23 // Create the image object to be drawn on the master canvas.
24 var transparentImg = new Image();
25 transparentImg.onload = drawImageToCanvasAndCheckPixels;
26 transparentImg.src = aCanvas.toDataURL(); // set a data URI of the base64 en coded image as the source
27
28 // Create master canvas.
29 var canvas = document.createElement('canvas');
30 document.body.appendChild(canvas);
31 canvas.width = 150;
32 canvas.height = 110;
33 var ctx = canvas.getContext('2d');
34
35 function testPixelShadow(x, y, color)
36 {
37 assert_array_equals(ctx.getImageData(x, y, 1, 1).data, color);
38 }
39
40 function testPixelShadowAlpha(x, y, color)
41 {
42 var data = ctx.getImageData(x, y, 1, 1).data;
43 assert_array_equals(data.slice(0,3), color.slice(0,3));
44 assert_approx_equals(data[3], color[3], 10);
45 }
46
47 var testPixelShadowScenarios = [
48 ['Verify solid shadow 1', 40, 40, [255, 0, 0, 255]],
49 ['Verify solid shadow 2', 59, 59, [255, 0, 0, 255]],
50 ];
51
52 var testPixelShadowAlphaScenarios = [
53 ['Verify solid alpha shadow 1', 41, 81, [255, 0, 0, 76]],
54 ['Verify solid alpha shadow 2', 59, 99, [255, 0, 0, 76]],
55
56 ['Verify blurry shadow 1', 90, 39, [255, 0, 0, 114]],
57 ['Verify blurry shadow 2', 90, 60, [255, 0, 0, 114]],
58 ['Verify blurry shadow 3', 79, 50, [255, 0, 0, 114]],
59 ['Verify blurry shadow 4', 100, 50, [255, 0, 0, 114]],
60
61 ['Verify blurry alpha shadow 1', 90, 79, [255, 0, 0, 34]],
62 ['Verify blurry alpha shadow 2', 90, 100, [255, 0, 0, 34]],
63 ['Verify blurry alpha shadow 3', 79, 90, [255, 0, 0, 34]],
64 ['Verify blurry alpha shadow 4', 100, 90, [255, 0, 0, 34]],
65
66 ['Verify blurry shadow of image with alpha 1', 130, 39, [255, 0, 0, 57]] ,
67 ['Verify blurry shadow of image with alpha 2', 130, 60, [255, 0, 0, 57]] ,
68 ['Verify blurry shadow of image with alpha 3', 119, 50, [255, 0, 0, 57]] ,
69 ['Verify blurry shadow of image with alpha 4', 140, 50, [255, 0, 0, 57]] ,
70
71 ['Verify blurry alpha shadow of image with alpha 1', 130, 79, [255, 0, 0 , 17]],
72 ['Verify blurry alpha shadow of image with alpha 2', 130, 100, [255, 0, 0, 17]],
73 ['Verify blurry alpha shadow of image with alpha 3', 119, 90, [255, 0, 0 , 17]],
74 ['Verify blurry alpha shadow of image with alpha 4', 140, 90, [255, 0, 0 , 17]],
75 ];
76
77 var imagesLoaded = 0;
78 function drawImageToCanvasAndCheckPixels() {
79 imagesLoaded = imagesLoaded + 1;
80 if (imagesLoaded == 2) {
81 ctx.scale(2, 2);
82 ctx.shadowOffsetX = 20;
83 ctx.shadowOffsetY = 20;
84 ctx.fillStyle = 'rgba(0, 0, 255, 1)';
85
86 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
87 ctx.drawImage(img, 10, 10);
88
89 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
90 ctx.drawImage(img, 10, 30);
91
92 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
93 ctx.shadowBlur = 10;
94 ctx.drawImage(img, 30, 10);
95
96 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
97 ctx.drawImage(img, 30, 30);
98
99 ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
100 ctx.drawImage(transparentImg, 50, 10);
101
102 ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
103 ctx.drawImage(transparentImg, 50, 30);
104
105 t.step(runTests);
106 t.done();
107
108 }
109 }
110
111 function runTests() {
112 for (var i = 0; i < testPixelShadowScenarios.length; i++)
113 testPixelShadow(testPixelShadowScenarios[i][1],
114 testPixelShadowScenarios[i][2],
115 testPixelShadowScenarios[i][3]);
116
117 for (var i = 0; i < testPixelShadowAlphaScenarios.length; i++)
118 testPixelShadowAlpha(testPixelShadowAlphaScenarios[i][1],
119 testPixelShadowAlphaScenarios[i][2],
120 testPixelShadowAlphaScenarios[i][3]);
121 }
122
123 }, 'Ensure correct behavior of canvas with drawImage+shadow after scaling. A blu e and red checkered pattern should be displayed.');
124 </script>
8 </body> 125 </body>
9 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698