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

Side by Side Diff: LayoutTests/fast/canvas/script-tests/canvas-path-context-clip.js

Issue 137353004: Add versions of stroke, fill, and clip that take a Path parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: clean up idl Created 6 years, 11 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
(Empty)
1 description("Series of tests to ensure clip() works with path and winding rule p arameters.");
2
3 var ctx = document.getElementById('canvas').getContext('2d');
4
5 function pixelDataAtPoint() {
6 return ctx.getImageData(50, 50, 1, 1).data;
7 }
8
9 function checkResult(expectedColors, sigma) {
10 for (var i = 0; i < 4; i++)
11 shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma) ;
12 }
13
14 function drawRectanglesOn(contextOrPath) {
15 contextOrPath.rect(0, 0, 100, 100);
16 contextOrPath.rect(25, 25, 50, 50);
17 }
18
19 function formatName(fillRule, path) {
20 return 'clip(' + (path ? 'path' : '') + (fillRule && path ? ', ' : '') +
21 (fillRule ? '"' + fillRule + '"' : '') + ')';
22 }
23
24 function testClipWith(fillRule, path) {
25 debug('Testing ' + formatName(fillRule, path));
26 ctx.fillStyle = 'rgb(255,0,0)';
27 ctx.beginPath();
28 ctx.fillRect(0, 0, 100, 100);
29 ctx.fillStyle = 'rgb(0,255,0)';
30 if (path) {
31 if (fillRule) {
32 ctx.clip(path, fillRule);
33 } else {
34 ctx.clip(path);
35 }
36 } else {
37 ctx.beginPath();
38 drawRectanglesOn(ctx);
39 if (fillRule) {
40 ctx.clip(fillRule);
41 } else {
42 ctx.clip();
43 }
44 }
45 ctx.beginPath();
46 ctx.fillRect(0, 0, 100, 100);
47 if (fillRule == 'evenodd') {
48 checkResult([255, 0, 0, 255], 5);
49 } else {
50 checkResult([0, 255, 0, 255], 5);
51 }
52 debug('');
53 }
54
55 // Execute test.
56 function prepareTestScenario() {
57 fillRules = [undefined, 'nonzero', 'evenodd'];
58 var path = new Path();
59 drawRectanglesOn(path);
60
61 for (var i = 0; i < fillRules.length; i++) {
62 testClipWith(fillRules[i]);
63 testClipWith(fillRules[i], path);
64 }
65 }
66
67 // Run test and allow variation of results.
68 prepareTestScenario();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698