Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js |
— | — | @@ -3,7 +3,8 @@ |
4 | 4 | test( '-- Initial check', function() { |
5 | 5 | expect(1); |
6 | 6 | |
7 | | - if ( browserIsBlacklisted() ) { |
| 7 | + |
| 8 | + if ( !mw.webfonts.isBrowserSupported ) { |
8 | 9 | ok( mw.webfonts === undefined, 'mw.webfonts is not defined because we are running in a blacklisted browser' ); |
9 | 10 | } else { |
10 | 11 | ok( mw.webfonts, 'mw.webfonts is defined and the browser is supported' ); |
— | — | @@ -11,7 +12,7 @@ |
12 | 13 | } ); |
13 | 14 | |
14 | 15 | test( '-- Application of a web font to the page and its removal', function() { |
15 | | - if ( browserIsBlacklisted() ) { |
| 16 | + if ( !mw.webfonts.isBrowserSupported ) { |
16 | 17 | return; |
17 | 18 | } |
18 | 19 | |
— | — | @@ -45,11 +46,15 @@ |
46 | 47 | deepEqual( oldConfig, mw.webfonts.oldconfig, 'Previous body css was saved properly' ); |
47 | 48 | |
48 | 49 | // Font application |
49 | | - var expectedFontFamilyValue = "'" + teluguFont + "', " + fallbackFonts; |
50 | | - equal( $body.css( 'font-family' ), expectedFontFamilyValue, 'The web font was applied to font-family of body' ); |
51 | | - equal( $inputElement.css( 'font-family' ), expectedFontFamilyValue, 'The web font was applied to font-family of input' ); |
52 | | - equal( $selectElement.css( 'font-family' ), expectedFontFamilyValue, 'The web font was applied to font-family of select' ); |
53 | | - equal( $textareaElement.css( 'font-family' ), expectedFontFamilyValue, 'The web font was applied to font-family of textarea' ); |
| 50 | + var expectedFontFamilyValue = fontFamilyList( "'" + teluguFont + "', " + fallbackFonts ); |
| 51 | + deepEqual( fontFamilyList( $body.css( 'font-family' ) ), |
| 52 | + expectedFontFamilyValue, 'The web font was applied to font-family of body' ); |
| 53 | + deepEqual( fontFamilyList( $inputElement.css( 'font-family' ) ), |
| 54 | + expectedFontFamilyValue, 'The web font was applied to font-family of input' ); |
| 55 | + deepEqual( fontFamilyList( $selectElement.css( 'font-family' ) ), |
| 56 | + expectedFontFamilyValue, 'The web font was applied to font-family of select' ); |
| 57 | + deepEqual( fontFamilyList( $textareaElement.css( 'font-family' ) ), |
| 58 | + expectedFontFamilyValue, 'The web font was applied to font-family of textarea' ); |
54 | 59 | |
55 | 60 | // Reset everything |
56 | 61 | ok( mw.webfonts.set( false ) === undefined, 'Reset body after testing font application' ); |
— | — | @@ -70,7 +75,7 @@ |
71 | 76 | } ); |
72 | 77 | |
73 | 78 | test( '-- Dynamic font loading', function() { |
74 | | - if ( browserIsBlacklisted() ) { |
| 79 | + if ( !mw.webfonts.isBrowserSupported ) { |
75 | 80 | return; |
76 | 81 | } |
77 | 82 | |
— | — | @@ -90,7 +95,7 @@ |
91 | 96 | } ); |
92 | 97 | |
93 | 98 | test( '-- Dynamic font loading based on lang attribute', function() { |
94 | | - if ( browserIsBlacklisted() ) { |
| 99 | + if ( !mw.webfonts.isBrowserSupported ) { |
95 | 100 | return; |
96 | 101 | } |
97 | 102 | |
— | — | @@ -130,7 +135,7 @@ |
131 | 136 | } ); |
132 | 137 | |
133 | 138 | test( '-- Dynamic font loading based on font-family style attribute', function() { |
134 | | - if ( browserIsBlacklisted() ) { |
| 139 | + if ( !mw.webfonts.isBrowserSupported ) { |
135 | 140 | return; |
136 | 141 | } |
137 | 142 | |
— | — | @@ -166,7 +171,7 @@ |
167 | 172 | } ); |
168 | 173 | |
169 | 174 | test( '-- Build the menu', function() { |
170 | | - if ( browserIsBlacklisted() ) { |
| 175 | + if ( !mw.webfonts.isBrowserSupported ) { |
171 | 176 | return; |
172 | 177 | } |
173 | 178 | |
— | — | @@ -208,13 +213,18 @@ |
209 | 214 | return false; |
210 | 215 | } |
211 | 216 | |
212 | | -browserIsBlacklisted = function() { |
213 | | - var ua = navigator.userAgent; |
214 | | - if ( ( /MSIE 6/i.test( ua ) ) |
215 | | - || ( /MSIE 8/i.test( ua ) && /Windows NT 5.1/i.test( ua ) ) ) |
216 | | - { |
217 | | - return true; |
| 217 | +// Convert a font-family string to an array. This is needed |
| 218 | +// because browsers change the string by adding or removing spaces, |
| 219 | +// so the string cannot be compared in a uniform way. |
| 220 | +fontFamilyList = function( fontFamilyString ) { |
| 221 | + // Create a list |
| 222 | + var fontList = fontFamilyString.split( /, */ ); |
| 223 | + |
| 224 | + // Remove the quotes from font names |
| 225 | + for ( var fontIndex = 0; fontIndex < fontList.length; ++fontIndex) { |
| 226 | + fontList[fontIndex] = fontList[fontIndex].replace( /^["']/, '' ); |
| 227 | + fontList[fontIndex] = fontList[fontIndex].replace( /["']$/, '' ); |
218 | 228 | } |
219 | 229 | |
220 | | - return false; |
| 230 | + return fontList; |
221 | 231 | } |