Issue #533: Fix drawing tests cross-browser/OS issues

This commit is contained in:
juliandescottes 2016-08-31 00:53:29 +02:00
parent 4d12908363
commit a2d5e6ff04
3 changed files with 23 additions and 19 deletions

View File

@ -15,7 +15,7 @@
ns.DrawingTestPlayer.prototype.start = function () {
this.setupInitialState_();
this.createMouseShim_();
this.regenerateReferencePng().then(function () {
this.regenerateReferencePng(function () {
this.playEvent_(0);
}.bind(this));
};
@ -45,21 +45,13 @@
return piskel;
};
ns.DrawingTestPlayer.prototype.regenerateReferencePng = function () {
ns.DrawingTestPlayer.prototype.regenerateReferencePng = function (callback) {
var image = new Image();
var then = function () {};
image.onload = function () {
this.referencePng = pskl.utils.CanvasUtils.createFromImage(image).toDataURL();
then();
this.referenceCanvas = pskl.utils.CanvasUtils.createFromImage(image);
callback();
}.bind(this);
image.src = this.referencePng;
return {
then : function (cb) {
then = cb;
}
};
};
/**
@ -164,14 +156,26 @@
ns.DrawingTestPlayer.prototype.onTestEnd_ = function () {
this.removeMouseShim_();
// Retrieve the imageData corresponding to the spritesheet created by the test.
var renderer = new pskl.rendering.PiskelRenderer(pskl.app.piskelController);
var png = renderer.renderAsCanvas().toDataURL();
var canvas = renderer.renderAsCanvas();
var testData = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
var success = png === this.referencePng;
// Retrieve the reference imageData corresponding to the reference data-url png stored for this test.
var refCanvas = this.referenceCanvas;
this.referenceData = refCanvas.getContext('2d').getImageData(0, 0, refCanvas.width, refCanvas.height);
$.publish(Events.TEST_RECORD_END, [success, png, this.referencePng]);
// Compare the two imageData arrays.
var success = true;
for (var i = 0 ; i < this.referenceData.data.length ; i++) {
if (this.referenceData.data[i] != testData.data[i]) {
success = false;
}
}
$.publish(Events.TEST_RECORD_END, [success]);
this.callbacks.forEach(function (callback) {
callback(success, png, this.referencePng);
callback(success);
});
};

View File

@ -14,11 +14,11 @@
}.bind(this));
};
ns.DrawingTestRunner.prototype.onTestRecordEnd_ = function (evt, success, png) {
ns.DrawingTestRunner.prototype.onTestRecordEnd_ = function (evt, success) {
var testResult = document.createElement('div');
testResult.id = 'drawing-test-result';
testResult.setAttribute('data-test-name', this.testName);
testResult.innerHTML = success ? 'OK' : ('KO:' + png);
testResult.innerHTML = success ? 'OK' : 'KO';
document.body.appendChild(testResult);
};
})();

View File

@ -44,7 +44,7 @@
testPlayer.start();
};
ns.DrawingTestSuiteRunner.prototype.onTestEnd_ = function (success, png, referencePng) {
ns.DrawingTestSuiteRunner.prototype.onTestEnd_ = function (success) {
var path = this.testPaths[this.currentIndex];
this.testStatus[path] = success;
$.publish(Events.TEST_CASE_END, [path, success]);