diff options
author | jcgregorio@google.com <jcgregorio@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2014-02-24 22:12:36 +0000 |
---|---|---|
committer | jcgregorio@google.com <jcgregorio@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2014-02-24 22:12:36 +0000 |
commit | ae658d99dda0ea37f60d1fa33814b08aedd0716b (patch) | |
tree | 57a4d066be5e81d06fbcbe28dc089fb778957707 /third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js | |
parent | c6f6a302ede5467a8c5e1f02d8763309c152223a (diff) | |
download | chromium_src-ae658d99dda0ea37f60d1fa33814b08aedd0716b.zip chromium_src-ae658d99dda0ea37f60d1fa33814b08aedd0716b.tar.gz chromium_src-ae658d99dda0ea37f60d1fa33814b08aedd0716b.tar.bz2 |
Add versions of stroke, fill, and clip to CanvasRenderingContext2D that take a Path parameter.
The spec reference is:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-fill
This partially addresses bug 330506. The rest of these functions need to be added to completely close that bug, which I plan to do in a following CL:
- drawSystemFocusRing(path, element);
- drawCustomFocusRing(path, element);
- isPointInPath(path, x, y);
- isPointInStroke(path, x, y);
- scrollPathIntoView(path);
BUG=330506
Review URL: https://codereview.chromium.org/137353004
git-svn-id: svn://svn.chromium.org/blink/trunk@167705 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js')
-rw-r--r-- | third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js new file mode 100644 index 0000000..c394d6b --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-path-context-fill.js @@ -0,0 +1,70 @@ +description("Series of tests to ensure fill() works with path and winding rule parameters."); + +var ctx = document.getElementById('canvas').getContext('2d'); + +function pixelDataAtPoint() { + return ctx.getImageData(50, 50, 1, 1).data; +} + +function checkResult(expectedColors, sigma) { + for (var i = 0; i < 4; i++) + shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma); +} + +function drawRectanglesOn(contextOrPath) { + contextOrPath.rect(0, 0, 100, 100); + contextOrPath.rect(25, 25, 50, 50); +} + +function formatName(fillRule, path) { + return 'fill(' + (path ? 'path' : '') + (fillRule && path ? ', ' : '') + + (fillRule ? '"' + fillRule + '"' : '') + ')'; +} + +function testFillWith(fillRule, path) { + debug('Testing ' + formatName(fillRule, path)); + ctx.fillStyle = 'rgb(255,0,0)'; + ctx.beginPath(); + ctx.fillRect(0, 0, 100, 100); + ctx.fillStyle = 'rgb(0,255,0)'; + if (path) { + if (fillRule) { + ctx.fill(path, fillRule); + } else { + ctx.fill(path); + } + } else { + ctx.beginPath(); + drawRectanglesOn(ctx); + if (fillRule) { + ctx.fill(fillRule); + } else { + ctx.fill(); + } + } + if (fillRule == 'evenodd') { + checkResult([255, 0, 0, 255], 5); + } else { + checkResult([0, 255, 0, 255], 5); + } + debug(''); +} + +// Execute test. +function prepareTestScenario() { + fillRules = [undefined, 'nonzero', 'evenodd']; + var path = new Path(); + drawRectanglesOn(path); + + for (var i = 0; i < fillRules.length; i++) { + testFillWith(fillRules[i]); + testFillWith(fillRules[i], path); + } + + // Test exception cases. + shouldThrow("ctx.fill(null)"); + shouldThrow("ctx.fill(null, null)"); +} + +// Run test and allow variation of results. +prepareTestScenario(); |