add tests for resizeBounds

This commit is contained in:
Andy Edinborough 2013-01-02 10:47:36 -06:00
parent 85706166cc
commit 67ccb33dd5
2 changed files with 31 additions and 4 deletions

View File

@ -245,7 +245,7 @@ _html2canvas.Util.getCSS = function (el, attribute, index) {
return val;
};
function resize(current_width, current_height, target_width, target_height, stretch_mode){
_html2canvas.Util.resizeBounds = function( current_width, current_height, target_width, target_height, stretch_mode ){
var target_ratio = target_width / target_height,
current_ratio = current_width / current_height,
output_width, output_height;
@ -265,7 +265,7 @@ function resize(current_width, current_height, target_width, target_height, stre
}
return { width: output_width, height: output_height };
}
};
function backgroundBoundsFactory( prop, el, bounds, image, imageIndex ) {
// TODO add support for multi image backgrounds
@ -299,7 +299,7 @@ function backgroundBoundsFactory( prop, el, bounds, image, imageIndex ) {
if(left === undefined) {
if(bgposition[0].match(/contain|cover/)) {
var resized = resize( image.width, image.height, bounds.width, bounds.height, bgposition[0] );
var resized = _html2canvas.Util.resizeBounds( image.width, image.height, bounds.width, bounds.height, bgposition[0] );
left = resized.width;
topPos = resized.height;
} else {
@ -336,7 +336,6 @@ _html2canvas.Util.BackgroundSize = function( el, bounds, image, imageIndex ) {
var result = backgroundBoundsFactory( 'backgroundSize', el, bounds, image, imageIndex );
return { width: result[0], height: result[1] };
};
window._html2canvas = _html2canvas;
_html2canvas.Util.Extend = function (options, defaults) {
for (var key in options) {

View File

@ -14,5 +14,33 @@ $(function() {
// text nodes differ
QUnit.equal( _html2canvas.Util.Children(el[0]), arr, "Util.Children === jQuery.children()" );
});
test('resizeBounds', function(){
QUnit.deepEqual(
_html2canvas.Util.resizeBounds(100, 100, 100, 100),
{ width: 100, height: 100 },
'no resize'
);
QUnit.deepEqual(
_html2canvas.Util.resizeBounds(100, 100, 2, 100),
{ width: 20, height: 100 },
'stretch'
);
QUnit.deepEqual(
_html2canvas.Util.resizeBounds(100, 100, 2, 100, 'contain'),
{ width: 2, height: 2 },
'contain'
);
QUnit.deepEqual(
_html2canvas.Util.resizeBounds(100, 100, 2, 100, 'cover'),
{ width: 100, height: 100 },
'contain'
);
});
});