* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / qunit / suites / resources / jquery / jquery.colorUtil.js
blob9ac289d3aed5178549c4873e4bbbfa0e4af8f326
1 module( 'jquery.colorUtil.js' );
3 test( '-- Initial check', function(){
4         expect(1);
5         ok( jQuery.colorUtil, 'jQuery.colorUtil defined' );
6 });
8 test( 'getRGB', function(){
9         expect(18);
11         equal( typeof jQuery.colorUtil.getRGB(), 'undefined', 'No arguments' );
12         equal( typeof jQuery.colorUtil.getRGB( '' ), 'undefined', 'Empty string' );
13         deepEqual( jQuery.colorUtil.getRGB( [0, 100, 255] ), [0, 100, 255], 'Array' );
14         deepEqual( jQuery.colorUtil.getRGB( 'rgb(0,100,255)' ), [0, 100, 255], 'Parse simple string' );
15         deepEqual( jQuery.colorUtil.getRGB( 'rgb(0, 100, 255)' ), [0, 100, 255], 'Parse simple string (whitespace)' );
16         deepEqual( jQuery.colorUtil.getRGB( 'rgb(0%,20%,40%)' ), [0, 51, 102], 'Parse percentages string' );
17         deepEqual( jQuery.colorUtil.getRGB( 'rgb(0%, 20%, 40%)' ), [0, 51, 102], 'Parse percentages string (whitespace)' );
18         deepEqual( jQuery.colorUtil.getRGB( '#f2ddee' ), [242, 221, 238], 'Hex string: 6 char lowercase' );
19         deepEqual( jQuery.colorUtil.getRGB( '#f2DDEE' ), [242, 221, 238], 'Hex string: 6 char uppercase' );
20         deepEqual( jQuery.colorUtil.getRGB( '#f2DdEe' ), [242, 221, 238], 'Hex string: 6 char mixed' );
21         deepEqual( jQuery.colorUtil.getRGB( '#eee' ), [238, 238, 238], 'Hex string: 3 char lowercase' );
22         deepEqual( jQuery.colorUtil.getRGB( '#EEE' ), [238, 238, 238], 'Hex string: 3 char uppercase' );
23         deepEqual( jQuery.colorUtil.getRGB( '#eEe' ), [238, 238, 238], 'Hex string: 3 char mixed' );
24         deepEqual( jQuery.colorUtil.getRGB( 'rgba(0, 0, 0, 0)' ), [255, 255, 255], 'Zero rgba for Safari 3; Transparent (whitespace)' );
25         // Perhaps this is a bug in colorUtil, but it is the current behaviour so, let's keep track
26         // would that ever change
27         equal( typeof jQuery.colorUtil.getRGB( 'rgba(0,0,0,0)' ), 'undefined', 'Zero rgba without whitespace' );
28         
29         deepEqual( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (lightGreen)' );
30         deepEqual( jQuery.colorUtil.getRGB( 'lightGreen' ), [144, 238, 144], 'Color names (transparent)' );
31         equal( typeof jQuery.colorUtil.getRGB( 'mediaWiki' ), 'undefined', 'Inexisting color name' );
33 });
35 test( 'rgbToHsl', function(){
36         expect(4);
38         var hsl = jQuery.colorUtil.rgbToHsl( 144, 238, 144 );
39         var dualDecimals = function(a,b){
40                 return Math.round(a*100)/100;
41         };
43         ok( hsl, 'Basic return evaluation' );
44         deepEqual( dualDecimals(hsl[0]) , 0.33, 'rgb(144, 238, 144): H 0.33' );
45         deepEqual( dualDecimals(hsl[1]) , 0.73, 'rgb(144, 238, 144): S 0.73' );
46         deepEqual( dualDecimals(hsl[2]) , 0.75, 'rgb(144, 238, 144): L 0.75' );
48 });
50 test( 'hslToRgb', function(){
51         expect(4);
53         var rgb = jQuery.colorUtil.hslToRgb( 0.3, 0.7, 0.8 );
55         ok( rgb, 'Basic return evaluation' );
56         deepEqual( Math.round(rgb[0]) , 183, 'hsl(0.3, 0.7, 0.8): R 183' );
57         deepEqual( Math.round(rgb[1]) , 240, 'hsl(0.3, 0.7, 0.8): G 240' );
58         deepEqual( Math.round(rgb[2]) , 168, 'hsl(0.3, 0.7, 0.8): B 168' );
60 });
62 test( 'getColorBrightness', function(){
63         expect(2);
65         var a = jQuery.colorUtil.getColorBrightness( 'red', +0.1 );
67         equal( a, 'rgb(255,50,50)', 'Start with named color, brighten 10%' );
68         
69         var b = jQuery.colorUtil.getColorBrightness( 'rgb(200,50,50)', -0.2 );
70         
71         equal( b, 'rgb(118,29,29)', 'Start with rgb string, darken 10%' );
73 });