[PathKit] Add more correctness tests to gold
Bug: skia:8216
Change-Id: I549f59f165e01ef2e827cf389a5412c123314a90
Reviewed-on: https://skia-review.googlesource.com/147817
Reviewed-by: Stephan Altmueller <stephana@google.com>
diff --git a/experimental/pathkit/tests/effects.spec.js b/experimental/pathkit/tests/effects.spec.js
index a332c6e..cb1087a 100644
--- a/experimental/pathkit/tests/effects.spec.js
+++ b/experimental/pathkit/tests/effects.spec.js
@@ -39,12 +39,13 @@
expect(dashed === notACopy).toBe(true);
expect(dashed.equals(phased)).toBe(false);
expect(dashed.equals(orig)).toBe(false);
- // TODO(store to Gold), dashed_no_phase, dashed_with_phase
- orig.delete();
- dashed.delete();
- phased.delete();
- done();
+ reportPath(dashed, 'dashed_no_phase', () => {
+ reportPath(phased, 'dashed_with_phase', done);
+ orig.delete();
+ dashed.delete();
+ phased.delete();
+ });
});
});
});
@@ -62,12 +63,13 @@
expect(trimmed.equals(orig)).toBe(false);
expect(complement.equals(orig)).toBe(false);
- // TODO(store to Gold), trimmed, trimmed_complement
+ reportPath(trimmed, 'trimmed_non_complement', () => {
+ reportPath(complement, 'trimmed_complement', done);
+ orig.delete();
+ trimmed.delete();
+ complement.delete();
+ });
- orig.delete();
- trimmed.delete();
- complement.delete();
- done();
});
});
});
@@ -89,12 +91,12 @@
expect(scaled.equals(scaled2)).toBe(true);
expect(scaled.equals(orig)).toBe(false);
- // TODO(store to Gold), transformed, transformed_more
-
- orig.delete();
- scaled.delete();
- scaled2.delete();
- done();
+ reportPath(scaled, 'transformed_scale', () => {
+ reportPath(scaled2, 'transformed_scale2', done);
+ orig.delete();
+ scaled.delete();
+ scaled2.delete();
+ });
});
});
});
@@ -123,12 +125,12 @@
expect(stroked.equals(rounded)).toBe(false);
expect(stroked.equals(orig)).toBe(false);
- // TODO(store to Gold), stroked, rounded
-
- orig.delete();
- stroked.delete();
- rounded.delete();
- done();
+ reportPath(stroked, 'stroke_bevel_butt', () => {
+ reportPath(rounded, 'stroke_round_square', done);
+ orig.delete();
+ stroked.delete();
+ rounded.delete();
+ });
});
});
});
diff --git a/experimental/pathkit/tests/path2d.spec.js b/experimental/pathkit/tests/path2d.spec.js
index 33fcec9..f1eae3a 100644
--- a/experimental/pathkit/tests/path2d.spec.js
+++ b/experimental/pathkit/tests/path2d.spec.js
@@ -65,11 +65,25 @@
canvasCtx.fillStyle = 'blue';
canvasCtx.stroke(path.toPath2D());
+ let svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
+ svgPath.setAttribute('stroke', 'black');
+ svgPath.setAttribute('fill', 'rgba(255,255,255,0.0)');
+ svgPath.setAttribute('transform', 'scale(3.0, 3.0)');
+ svgPath.setAttribute('d', path.toSVGString());
+
+ let newSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
+ newSVG.appendChild(svgPath);
+ newSVG.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
+ newSVG.setAttribute('width', 600);
+ newSVG.setAttribute('height', 600);
+
path.delete();
secondPath.delete();
reportCanvas(canvas, 'path2D_api_example').then(() => {
- done();
+ reportSVG(newSVG, 'path2D_api_example').then(() => {
+ done();
+ }).catch(reportError(done));
}).catch(reportError(done));
});
});
@@ -142,10 +156,9 @@
0, 3, 0,
0, 0, 1);
- // TODO(kjlubick): Do svg and canvas gm helper function
+ reportPath(basePath, 'add_path_3x', done);
basePath.delete();
otherPath.delete();
- done();
});
});
diff --git a/experimental/pathkit/tests/testReporter.js b/experimental/pathkit/tests/testReporter.js
index add6634..d1dcd7b 100644
--- a/experimental/pathkit/tests/testReporter.js
+++ b/experimental/pathkit/tests/testReporter.js
@@ -54,6 +54,23 @@
return reportSVG(newSVG, testname);
}
+// Reports a canvas and then an SVG of this path. Puts it on a standard size canvas.
+function reportPath(path, testname, done) {
+ let canvas = document.createElement('canvas');
+ let canvasCtx = canvas.getContext('2d');
+ // Set canvas size and make it a bit bigger to zoom in on the lines
+ standardizedCanvasSize(canvasCtx);
+ canvasCtx.stroke(path.toPath2D());
+
+ let svgStr = path.toSVGString();
+
+ return reportCanvas(canvas, testname).then(() => {
+ reportSVGString(svgStr, testname).then(() => {
+ done();
+ }).catch(reportError(done));
+ }).catch(reportError(done));
+}
+
function _report(data, outputType, testname) {
return fetch(REPORT_URL, {
method: 'POST',