@@ -5,11 +5,15 @@ var test = test || function(){},
55
66
77module ( "CSS" ) ;
8- $ ( function ( ) {
8+ $ ( function ( ) {
9+
10+ var propsToTest = { } ,
11+ numDivs = { } ;
12+
913
1014
11- var propsToTest = [ "borderTopWidth" , "borderRightWidth" , "borderBottomWidth" , "borderLeftWidth" ] ,
12- numDivs = $ ( '#borders div' ) . length ;
15+ propsToTest [ 'border-width' ] = [ "borderTopWidth" , "borderRightWidth" , "borderBottomWidth" , "borderLeftWidth" ] ,
16+ numDivs [ 'border-width' ] = $ ( '#borders div' ) . length ;
1317 /*
1418 expecting = [
1519 // #1
@@ -62,10 +66,10 @@ $(function() {
6266 ];
6367 */
6468
65- test ( 'border-width' , propsToTest . length * numDivs , function ( ) {
69+ test ( 'border-width' , propsToTest [ 'border-width' ] . length * numDivs [ 'border-width' ] , function ( ) {
6670
6771 $ ( '#borders div' ) . each ( function ( i , el ) {
68- $ . each ( propsToTest , function ( s , prop ) {
72+ $ . each ( propsToTest [ 'border-width' ] , function ( s , prop ) {
6973 var expect = $ ( el ) . css ( prop ) ;
7074
7175 // older IE's don't necessarily return px even with jQuery
@@ -82,32 +86,28 @@ $(function() {
8286 } ) ;
8387 } ) ;
8488
85- var propsToTest2 = [ "paddingTop" , "paddingRight" , "paddingBottom" , "paddingLeft" ] ,
86- numDivs2 = $ ( '#padding div' ) . length ;
89+ propsToTest [ 'padding width' ] = [ "paddingTop" , "paddingRight" , "paddingBottom" , "paddingLeft" ] ;
90+ numDivs [ 'padding width' ] = $ ( '#padding div' ) . length ;
8791
88- test ( 'padding width' , propsToTest2 . length * numDivs2 * 2 , function ( ) {
92+ test ( 'padding width' , propsToTest [ 'padding width' ] . length * numDivs [ 'padding width' ] * 2 , function ( ) {
8993
9094 $ ( '#padding div' ) . each ( function ( i , el ) {
91- $ . each ( propsToTest2 , function ( s , prop ) {
95+ $ . each ( propsToTest [ 'padding width' ] , function ( s , prop ) {
9296 var isPx = _html2canvas . Util . getCSS ( el , prop ) . indexOf ( "px" ) ;
9397 QUnit . notEqual ( isPx , - 1 , "div #" + ( i + 1 ) + " property " + prop + " is in pixels" ) ;
9498 QUnit . equal ( _html2canvas . Util . getCSS ( el , prop ) , $ ( el ) . css ( prop ) , "div #" + ( i + 1 ) + " property " + prop + " equals " + $ ( el ) . css ( prop ) ) ;
9599 } ) ;
96100
97101 } ) ;
98- } ) ;
99-
100-
101-
102-
102+ } ) ;
103103
104- var propsToTest3 = [ "backgroundPosition" ] ,
105- numDivs3 = $ ( '#backgroundPosition div' ) . length ;
104+ propsToTest [ 'background-position' ] = [ "backgroundPosition" ] ;
105+ numDivs [ 'background-position' ] = $ ( '#backgroundPosition div' ) . length ;
106106
107- test ( 'background-position' , propsToTest3 . length * numDivs3 * 2 , function ( ) {
107+ test ( 'background-position' , propsToTest [ 'background-position' ] . length * numDivs [ 'background-position' ] * 2 , function ( ) {
108108
109109 $ ( '#backgroundPosition div' ) . each ( function ( i , el ) {
110- $ . each ( propsToTest3 , function ( s , prop ) {
110+ $ . each ( propsToTest [ 'background-position' ] , function ( s , prop ) {
111111 var img = new Image ( ) ;
112112 img . width = 50 ;
113113 img . height = 50 ;
@@ -145,4 +145,45 @@ $(function() {
145145 } ) ;
146146
147147// TODO add backgroundPosition % tests
148+
149+ propsToTest [ 'background-gradient' ] = [ "backgroundImage" ] ;
150+ numDivs [ 'background-gradient' ] = $ ( '#backgroundGradients div' ) . length ;
151+
152+ test ( 'background-gradient' , propsToTest [ 'background-gradient' ] . length * numDivs [ 'background-gradient' ] , function ( ) {
153+
154+ $ ( '#backgroundGradients div' ) . each ( function ( i , el ) {
155+ $ . each ( propsToTest [ 'background-gradient' ] , function ( s , prop ) {
156+ var src , img , canvas , ctx , id , data , len , red , green , blue , overallColor = 0 ;
157+
158+ src = _html2canvas . Util . getCSS ( el , prop ) ,
159+ img = _html2canvas . Generate . Gradient ( src , {
160+ width : 50 ,
161+ height : 50
162+ } , img ) ;
163+
164+ canvas = document . createElement ( 'canvas' ) ;
165+ canvas . width = 50 ;
166+ canvas . height = 50 ;
167+ ctx = canvas . getContext ( '2d' ) ;
168+ ctx . drawImage ( img , 0 , 0 ) ;
169+ id = ctx . getImageData ( 0 , 0 , 50 , 50 ) ;
170+ data = id . data ;
171+ len = data . length ;
172+
173+ //console.log(img);
174+
175+ for ( var i = 0 ; i < len ; i += 4 ) {
176+ red = data [ i ] ; // red
177+ green = data [ i + 1 ] ; // green
178+ blue = data [ i + 2 ] ; // blue
179+ // i+3 is alpha (the fourth element)
180+
181+ overallColor += ( red + green + blue ) / 3 ;
182+ }
183+ overallColor /= len ;
184+
185+ QUnit . notEqual ( overallColor , 255 , 'No Background Gradient - CSS was ' + src ) ;
186+ } ) ;
187+ } ) ;
188+ } ) ;
148189} ) ;
0 commit comments