mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Use comparePixels() instead of compareCanvas()
This commit is contained in:
parent
2cb55a839d
commit
da137fa8e4
3 changed files with 24 additions and 25 deletions
|
@ -88,6 +88,10 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
}
|
||||
},
|
||||
|
||||
getContext: function() {
|
||||
return this._context;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the provide size in any of the units allowed in the browser to
|
||||
* pixels.
|
||||
|
|
|
@ -345,25 +345,24 @@ var compareItem = function(actual, expected, message, options, properties) {
|
|||
* @param {function} actualCallback the function producing the actual result
|
||||
* @param {number} tolerance between 0 and 1
|
||||
*/
|
||||
var compareCanvas = function(width, height, expectedCallback, actualCallback,
|
||||
tolerance) {
|
||||
var compareCanvas = function(width, height, expected, actual, tolerance) {
|
||||
function getImageData(width, height, callback) {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
var project = new Project(canvas);
|
||||
var view = project.view;
|
||||
callback();
|
||||
project.view.update();
|
||||
var context = canvas.getContext('2d');
|
||||
var imageData = context.getImageData(0, 0, width, height);
|
||||
canvas.remove();
|
||||
view.update();
|
||||
var imageData = view.context.getImageData(0, 0, width, height);
|
||||
project.remove();
|
||||
canvas.remove();
|
||||
return imageData;
|
||||
}
|
||||
|
||||
compareImageData(
|
||||
getImageData(width, height, expectedCallback),
|
||||
getImageData(width, height, actualCallback),
|
||||
getImageData(width, height, expected),
|
||||
getImageData(width, height, actual),
|
||||
tolerance
|
||||
);
|
||||
|
||||
|
|
|
@ -137,21 +137,17 @@ test('group.addChildren()', function() {
|
|||
});
|
||||
|
||||
test('group.setSelectedColor() with selected bound and position', function() {
|
||||
compareCanvas(100, 100,
|
||||
function() {
|
||||
// working: set selected color first then add child
|
||||
var group = new Group();
|
||||
group.bounds.selected = true;
|
||||
group.position.selected = true;
|
||||
group.selectedColor = 'black';
|
||||
group.addChild(new Path.Circle([50, 50], 40));
|
||||
}, function() {
|
||||
// failing: add child first then set selected color
|
||||
var group = new Group();
|
||||
group.bounds.selected = true;
|
||||
group.position.selected = true;
|
||||
group.addChild(new Path.Circle([50, 50], 40));
|
||||
group.selectedColor = 'black';
|
||||
}
|
||||
);
|
||||
// Working: Set selected color first then add child.
|
||||
var group1 = new Group();
|
||||
group1.bounds.selected = true;
|
||||
group1.position.selected = true;
|
||||
group1.selectedColor = 'black';
|
||||
group1.addChild(new Path.Circle([50, 50], 40));
|
||||
// Failing: Add child first then set selected color.
|
||||
var group2 = new Group();
|
||||
group2.bounds.selected = true;
|
||||
group2.position.selected = true;
|
||||
group2.addChild(new Path.Circle([50, 50], 40));
|
||||
group2.selectedColor = 'black';
|
||||
comparePixels(group1, group2);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue