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

Unified Diff: LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.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: Reorder IDL, so that the stricter check for Path comes before the less strict check for an enum. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js b/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js
new file mode 100644
index 0000000000000000000000000000000000000000..d3f711fec6675953b1e6712876c209ab482023be
--- /dev/null
+++ b/LayoutTests/fast/canvas/script-tests/canvas-path-context-stroke.js
@@ -0,0 +1,53 @@
+description("Series of tests to ensure stroke() works with optional path parameter.");
+
+var ctx = document.getElementById('canvas').getContext('2d');
+
+function pixelDataAtPoint() {
+ return ctx.getImageData(75, 75, 1, 1).data;
+}
+
+function checkResult(expectedColors, sigma) {
+ for (var i = 0; i < 4; i++)
+ shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i], sigma);
+}
+
+function drawRectangleOn(contextOrPath) {
+ contextOrPath.rect(25, 25, 50, 50);
+}
+
+function formatName(path) {
+ return 'stroke(' + (path ? 'path' : '') + ')';
+}
+
+function testStrokeWith(path) {
+ debug('Testing ' + formatName(path));
+ ctx.fillStyle = 'rgb(255,0,0)';
+ ctx.beginPath();
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.strokeStyle = 'rgb(0,255,0)';
+ ctx.lineWidth = 5;
+ if (path) {
+ ctx.stroke(path);
+ } else {
+ ctx.beginPath();
+ drawRectangleOn(ctx);
+ ctx.stroke();
+ }
+ debug('');
+ checkResult([0, 255, 0, 255], 5);
+}
+
+// Execute test.
+function prepareTestScenario() {
+ var path = new Path();
+ drawRectangleOn(path);
+
+ testStrokeWith();
+ testStrokeWith(path);
+
+ // Test exception cases.
+ shouldThrow("ctx.stroke(null)");
+}
+
+// Run test and allow variation of results.
+prepareTestScenario();

Powered by Google App Engine
This is Rietveld 408576698