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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-fillPath-pattern-shadow.html

Issue 2678493002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Addressing comments 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-fillPath-pattern-shadow.js"></script> 4 <script>
5 var aCanvas = document.createElement('canvas');
6 aCanvas.setAttribute('width', '50');
7 aCanvas.setAttribute('height', '50');
8
9 var aCtx = aCanvas.getContext('2d');
10 aCtx.fillStyle = 'rgba(0, 0, 255, 0.5)';
11 aCtx.fillRect(0, 0, 50, 50);
12
13 var pattern = aCtx.createPattern(aCanvas, 'repeat');
14
15 var canvas = document.createElement('canvas');
16 document.body.appendChild(canvas);
17 canvas.setAttribute('width', '600');
18 canvas.setAttribute('height', '1100');
19 var ctx = canvas.getContext('2d');
20
21 ctx.save();
22 ctx.fillStyle = pattern;
23 ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
24 ctx.shadowOffsetX = 250;
25
26 function fillShape(x, y) {
27 ctx.beginPath();
28 ctx.arc(x, y, 100, 0, Math.PI*2, true);
29 ctx.arc(x, y, 50, 0, Math.PI*2, false);
30 ctx.fill();
31 }
32
33 // Alpha shadow.
34 ctx.shadowBlur = 0;
35 fillShape(150, 150);
36
37 // Blurry shadow.
38 ctx.shadowBlur = 10;
39 fillShape(150, 400);
40
41 ctx.rotate(Math.PI/2);
42
43 // Rotated alpha shadow.
44 ctx.shadowBlur = 0;
45 fillShape(650, -150);
46
47 // Rotated blurry shadow.
48 ctx.shadowBlur = 10;
49 fillShape(900, -150);
50
51 ctx.restore();
52 ctx.fillStyle = 'black';
53
54 function testPixelShadow(pixel, reference, alphaApprox) {
55 var testPassed = true;
56 for(i = 0; i < 3; i++)
57 if(pixel[i] != reference[i]) {
58 testPassed = false;
59 break;
60 }
61 assert_true(testPassed);
62 assert_approx_equals(pixel[3], reference[3], alphaApprox);
63 }
64
65 testScenarios =
66 [
67 ['TestAlphaShadow 1', ctx.getImageData(400, 150, 1, 1).data, [ 0, 0, 0, 0, 0], 0],
68 ['TestAlphaShadow 2', ctx.getImageData(400, 75, 1, 1).data, [ 255, 0, 0, 64], 15],
69 ['TestAlphaShadow 3', ctx.getImageData(400, 225, 1, 1).data, [ 255, 0, 0, 64], 15],
70 ['TestAlphaShadow 4', ctx.getImageData(325, 150, 1, 1).data, [ 255, 0, 0, 64], 15],
71 ['TestAlphaShadow 5', ctx.getImageData(475, 150, 1, 1).data, [ 255, 0, 0, 64], 15],
72
73 ['TestBlurryShadow 1', ctx.getImageData(400, 400, 1, 1).data, [ 0, 0 , 0, 0, 0], 0],
74 ['TestBlurryShadow 2', ctx.getImageData(400, 300, 1, 1).data, [ 255, 0, 0, 31], 15],
75 ['TestBlurryShadow 3', ctx.getImageData(400, 500, 1, 1).data, [ 255, 0, 0, 31], 15],
76 ['TestBlurryShadow 4', ctx.getImageData(300, 400, 1, 1).data, [ 255, 0, 0, 31], 15],
77 ['TestBlurryShadow 5', ctx.getImageData(500, 400, 1, 1).data, [ 255, 0, 0, 31], 15],
78
79 ['TestRotatedAlphaShadow 1', ctx.getImageData(400, 650, 1, 1).data, [ 0, 0, 0, 0, 0], 0],
80 ['TestRotatedAlphaShadow 2', ctx.getImageData(400, 575, 1, 1).data, [ 255, 0, 0, 64], 15],
81 ['TestRotatedAlphaShadow 3', ctx.getImageData(400, 725, 1, 1).data, [ 255, 0, 0, 64], 15],
82 ['TestRotatedAlphaShadow 4', ctx.getImageData(325, 650, 1, 1).data, [ 255, 0, 0, 64], 15],
83 ['TestRotatedAlphaShadow 5', ctx.getImageData(475, 650, 1, 1).data, [ 255, 0, 0, 64], 15],
84
85 ['TestRotatedBlurryShadow 1', ctx.getImageData(400, 900, 1, 1).data, [ 0, 0, 0, 0, 0], 0],
86 ['TestRotatedBlurryShadow 2', ctx.getImageData(400, 800, 1, 1).data, [ 255, 0, 0, 31], 15],
87 ['TestRotatedBlurryShadow 3', ctx.getImageData(400, 1000, 1, 1).data , [ 255, 0, 0, 31], 15],
88 ['TestRotatedBlurryShadow 4', ctx.getImageData(300, 900, 1, 1).data, [ 255, 0, 0, 31], 15],
89 ['TestRotatedBlurryShadow 5', ctx.getImageData(500, 900, 1, 1).data, [ 255, 0, 0, 31], 15],
90 ];
91
92 generate_tests(testPixelShadow, testScenarios);
93
94 </script>
8 </body> 95 </body>
9 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698