r109545 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109544‎ | r109545 | r109546 >
Date:16:30, 19 January 2012
Author:amire80
Status:ok (Comments)
Tags:
Comment:
Using the browser checking function from mw.webfonts. Converting the font-family string to an array to allow cross-browser testing.
Modified paths:
  • /trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js
@@ -3,7 +3,8 @@
44 test( '-- Initial check', function() {
55 expect(1);
66
7 - if ( browserIsBlacklisted() ) {
 7+
 8+ if ( !mw.webfonts.isBrowserSupported ) {
89 ok( mw.webfonts === undefined, 'mw.webfonts is not defined because we are running in a blacklisted browser' );
910 } else {
1011 ok( mw.webfonts, 'mw.webfonts is defined and the browser is supported' );
@@ -11,7 +12,7 @@
1213 } );
1314
1415 test( '-- Application of a web font to the page and its removal', function() {
15 - if ( browserIsBlacklisted() ) {
 16+ if ( !mw.webfonts.isBrowserSupported ) {
1617 return;
1718 }
1819
@@ -45,11 +46,15 @@
4647 deepEqual( oldConfig, mw.webfonts.oldconfig, 'Previous body css was saved properly' );
4748
4849 // 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' );
5459
5560 // Reset everything
5661 ok( mw.webfonts.set( false ) === undefined, 'Reset body after testing font application' );
@@ -70,7 +75,7 @@
7176 } );
7277
7378 test( '-- Dynamic font loading', function() {
74 - if ( browserIsBlacklisted() ) {
 79+ if ( !mw.webfonts.isBrowserSupported ) {
7580 return;
7681 }
7782
@@ -90,7 +95,7 @@
9196 } );
9297
9398 test( '-- Dynamic font loading based on lang attribute', function() {
94 - if ( browserIsBlacklisted() ) {
 99+ if ( !mw.webfonts.isBrowserSupported ) {
95100 return;
96101 }
97102
@@ -130,7 +135,7 @@
131136 } );
132137
133138 test( '-- Dynamic font loading based on font-family style attribute', function() {
134 - if ( browserIsBlacklisted() ) {
 139+ if ( !mw.webfonts.isBrowserSupported ) {
135140 return;
136141 }
137142
@@ -166,7 +171,7 @@
167172 } );
168173
169174 test( '-- Build the menu', function() {
170 - if ( browserIsBlacklisted() ) {
 175+ if ( !mw.webfonts.isBrowserSupported ) {
171176 return;
172177 }
173178
@@ -208,13 +213,18 @@
209214 return false;
210215 }
211216
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( /["']$/, '' );
218228 }
219229
220 - return false;
 230+ return fontList;
221231 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r109677[WebFonts.tests] Fixes...krinkle06:21, 21 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109454Added function browserIsBlacklisted, to avoid running tests on blacklisted br...amire8023:24, 18 January 2012

Comments

#Comment by Krinkle (talk | contribs)   06:40, 21 January 2012
+fontFamilyList = function( fontFamilyString ) {

implied global, spotted in r109677. Just noting here for reference.

Status & tagging log