mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
"added tests for getColorStopsFromGradient"
This commit is contained in:
parent
8350f278fc
commit
cd008b6c05
@ -38,12 +38,12 @@ _html2canvas.Generate.getColorStopsFromGradient = function(css, bounds) {
|
|||||||
case '-webkit-linear-gradient':
|
case '-webkit-linear-gradient':
|
||||||
|
|
||||||
gradient = {
|
gradient = {
|
||||||
type: 'linear',
|
type: 'linear',
|
||||||
x0: 0,
|
x0: 0,
|
||||||
y0: 0,
|
y0: 0,
|
||||||
x1: 0,
|
x1: 0,
|
||||||
y1: 0,
|
y1: 0,
|
||||||
colorStops: []
|
colorStops: []
|
||||||
};
|
};
|
||||||
|
|
||||||
// get coordinates
|
// get coordinates
|
||||||
|
@ -10,7 +10,101 @@ var test = test || function(){},
|
|||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
var propsToTest = {},
|
var propsToTest = {},
|
||||||
numDivs = {};
|
numDivs = {},
|
||||||
|
expected = {};
|
||||||
|
|
||||||
|
propsToTest['Generate.getColorStopsFromGradient'] = ["backgroundImage"];
|
||||||
|
numDivs['Generate.getColorStopsFromGradient'] = $('#backgroundGradients div').length;
|
||||||
|
expected['Generate.getColorStopsFromGradient'] = [
|
||||||
|
{
|
||||||
|
type: 'linear',
|
||||||
|
x0: 0,
|
||||||
|
y0: 0,
|
||||||
|
x1: 50,
|
||||||
|
y1: 0,
|
||||||
|
colorStops: [
|
||||||
|
{
|
||||||
|
color: "rgb(255, 0, 0)",
|
||||||
|
stop: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(255, 255, 0)",
|
||||||
|
stop: 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(0, 255, 0)",
|
||||||
|
stop: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'linear',
|
||||||
|
x0: 0,
|
||||||
|
y0: 0,
|
||||||
|
x1: 50,
|
||||||
|
y1: 0,
|
||||||
|
colorStops: [
|
||||||
|
{
|
||||||
|
color: "rgb(206, 219, 233)",
|
||||||
|
stop: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(170, 197, 222)",
|
||||||
|
stop: 0.17
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(97, 153, 199)",
|
||||||
|
stop: 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(58, 132, 195)",
|
||||||
|
stop: 0.51
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(65, 154, 214)",
|
||||||
|
stop: 0.59
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(75, 184, 240)",
|
||||||
|
stop: 0.71
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(58, 139, 194)",
|
||||||
|
stop: 0.84
|
||||||
|
},
|
||||||
|
{
|
||||||
|
color: "rgb(38, 85, 139)",
|
||||||
|
stop: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
test('Generate.getColorStopsFromGradient', propsToTest['Generate.getColorStopsFromGradient'].length * numDivs['Generate.getColorStopsFromGradient'], function() {
|
||||||
|
|
||||||
|
$('#backgroundGradients div').each(function(i, el) {
|
||||||
|
$.each(propsToTest['Generate.getColorStopsFromGradient'], function(s, prop) {
|
||||||
|
var src, gradient, exptd;
|
||||||
|
|
||||||
|
src = _html2canvas.Util.getCSS(el, prop);
|
||||||
|
|
||||||
|
if (/^(-webkit|-o|-moz|-ms|linear)-/.test(src)) {
|
||||||
|
|
||||||
|
gradient = _html2canvas.Generate.getColorStopsFromGradient(src, {
|
||||||
|
width: 50,
|
||||||
|
height: 50
|
||||||
|
});
|
||||||
|
|
||||||
|
// compare
|
||||||
|
exptd = expected['Generate.getColorStopsFromGradient'][i];
|
||||||
|
|
||||||
|
QUnit.deepEqual(gradient, exptd, 'Parsed gradient; got: ' + JSON.stringify(gradient));
|
||||||
|
} else {
|
||||||
|
QUnit.ok(true, 'No CSS Background Gradient support');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
propsToTest['Generate.Gradient'] = ["backgroundImage"];
|
propsToTest['Generate.Gradient'] = ["backgroundImage"];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user