mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Issue #533: Fix drawing tests cross-browser/OS issues
This commit is contained in:
parent
4d12908363
commit
a2d5e6ff04
@ -15,7 +15,7 @@
|
|||||||
ns.DrawingTestPlayer.prototype.start = function () {
|
ns.DrawingTestPlayer.prototype.start = function () {
|
||||||
this.setupInitialState_();
|
this.setupInitialState_();
|
||||||
this.createMouseShim_();
|
this.createMouseShim_();
|
||||||
this.regenerateReferencePng().then(function () {
|
this.regenerateReferencePng(function () {
|
||||||
this.playEvent_(0);
|
this.playEvent_(0);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
@ -45,21 +45,13 @@
|
|||||||
return piskel;
|
return piskel;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingTestPlayer.prototype.regenerateReferencePng = function () {
|
ns.DrawingTestPlayer.prototype.regenerateReferencePng = function (callback) {
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
var then = function () {};
|
|
||||||
|
|
||||||
image.onload = function () {
|
image.onload = function () {
|
||||||
this.referencePng = pskl.utils.CanvasUtils.createFromImage(image).toDataURL();
|
this.referenceCanvas = pskl.utils.CanvasUtils.createFromImage(image);
|
||||||
then();
|
callback();
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
image.src = this.referencePng;
|
image.src = this.referencePng;
|
||||||
|
|
||||||
return {
|
|
||||||
then : function (cb) {
|
|
||||||
then = cb;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,14 +156,26 @@
|
|||||||
ns.DrawingTestPlayer.prototype.onTestEnd_ = function () {
|
ns.DrawingTestPlayer.prototype.onTestEnd_ = function () {
|
||||||
this.removeMouseShim_();
|
this.removeMouseShim_();
|
||||||
|
|
||||||
|
// Retrieve the imageData corresponding to the spritesheet created by the test.
|
||||||
var renderer = new pskl.rendering.PiskelRenderer(pskl.app.piskelController);
|
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) {
|
this.callbacks.forEach(function (callback) {
|
||||||
callback(success, png, this.referencePng);
|
callback(success);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingTestRunner.prototype.onTestRecordEnd_ = function (evt, success, png) {
|
ns.DrawingTestRunner.prototype.onTestRecordEnd_ = function (evt, success) {
|
||||||
var testResult = document.createElement('div');
|
var testResult = document.createElement('div');
|
||||||
testResult.id = 'drawing-test-result';
|
testResult.id = 'drawing-test-result';
|
||||||
testResult.setAttribute('data-test-name', this.testName);
|
testResult.setAttribute('data-test-name', this.testName);
|
||||||
testResult.innerHTML = success ? 'OK' : ('KO:' + png);
|
testResult.innerHTML = success ? 'OK' : 'KO';
|
||||||
document.body.appendChild(testResult);
|
document.body.appendChild(testResult);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
testPlayer.start();
|
testPlayer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingTestSuiteRunner.prototype.onTestEnd_ = function (success, png, referencePng) {
|
ns.DrawingTestSuiteRunner.prototype.onTestEnd_ = function (success) {
|
||||||
var path = this.testPaths[this.currentIndex];
|
var path = this.testPaths[this.currentIndex];
|
||||||
this.testStatus[path] = success;
|
this.testStatus[path] = success;
|
||||||
$.publish(Events.TEST_CASE_END, [path, success]);
|
$.publish(Events.TEST_CASE_END, [path, success]);
|
||||||
|
Loading…
Reference in New Issue
Block a user