@@ -24,30 +24,28 @@ suite('CSSImageValue', function() {
2424 assert . instanceOf ( new typedOM . internal . CSSImageValue ( new Image ( ) ) , CSSStyleValue ) ;
2525 } ) ;
2626
27- test ( 'CSSImageValue only accepts Image objects ' , function ( ) {
28- var imageErr = / i m a g e m u s t b e a n I m a g e o b j e c t / ;
27+ test ( 'CSSImageValue only accepts Image object or string URL ' , function ( ) {
28+ var imageErr = / ^ i m a g e m u s t b e a n I m a g e o b j e c t o r s t r i n g U R L $ / ;
2929 assert . throws ( function ( ) { new typedOM . internal . CSSImageValue ( ) ; } , TypeError , imageErr ) ;
3030 assert . throws ( function ( ) { new typedOM . internal . CSSImageValue ( 1 ) ; } , TypeError , imageErr ) ;
31- assert . throws ( function ( ) { new typedOM . internal . CSSImageValue ( "abc" ) ; } , TypeError , imageErr ) ;
3231 assert . throws ( function ( ) { new typedOM . internal . CSSImageValue ( [ ] ) ; } , TypeError , imageErr ) ;
3332 assert . throws ( function ( ) { new typedOM . internal . CSSImageValue ( { x : 1 , y : 2 } ) ; } , TypeError , imageErr ) ;
3433 } ) ;
3534
36- test ( 'State and dimensions are correct before and after loading' , function ( done ) {
37- var image = new typedOM . internal . CSSImageValue ( new Image ( ) ) ;
38- assert . strictEqual ( image . state , "unloaded" ) ;
39- assert . strictEqual ( image . intrinsicWidth , null ) ;
40- assert . strictEqual ( image . intrinsicHeight , null ) ;
41- assert . strictEqual ( image . intrinsicRatio , null ) ;
42- image . _image . src = "resources/1x1-green.png" ;
43- var oldOnload = image . _image . onload ;
44- image . _image . onload = function ( ) {
45- oldOnload ( ) ;
46- assert . strictEqual ( image . state , "loaded" ) ;
47- assert . strictEqual ( image . intrinsicWidth , 1 ) ;
48- assert . strictEqual ( image . intrinsicHeight , 1 ) ;
49- assert . strictEqual ( image . intrinsicRatio , 1 ) ;
35+
36+ test ( 'CSSImageValue\'s state and dimensions are correct before and after loaded' , function ( done ) {
37+ var iv = new typedOM . internal . CSSImageValue ( 'resources/1x1-green.png' ) ;
38+ assert . strictEqual ( iv . state , "unloaded" ) ;
39+ assert . strictEqual ( iv . intrinsicWidth , null ) ;
40+ assert . strictEqual ( iv . intrinsicHeight , null ) ;
41+ assert . strictEqual ( iv . intrinsicRatio , null ) ;
42+
43+ iv . _image . addEventListener ( 'load' , function ( ) {
44+ assert . strictEqual ( iv . state , "loaded" ) ;
45+ assert . strictEqual ( iv . intrinsicWidth , 1 ) ;
46+ assert . strictEqual ( iv . intrinsicHeight , 1 ) ;
47+ assert . strictEqual ( iv . intrinsicRatio , 1 ) ;
5048 done ( ) ;
51- } ;
49+ } ) ;
5250 } ) ;
5351} ) ;
0 commit comments