r109133 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109132‎ | r109133 | r109134 >
Date:10:19, 17 January 2012
Author:santhosh
Status:ok
Tags:i18nreview 
Comment:
More qunit testcases for webfonts.
Make addFont function testable.
Modified paths:
  • /trunk/extensions/WebFonts/resources/ext.webfonts.js (modified) (history)
  • /trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js
@@ -6,4 +6,16 @@
77 ok( mw.webfonts, 'mw.webfonts defined' );
88 });
99
 10+test( '-- Dynamic font loading', function() {
 11+ expect( 7 );
 12+ var cssRulesLength = document.styleSheets.length;
 13+ assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font' );
 14+ assertTrue( $.inArray( 'Lohit Devanagari', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
 15+ assertTrue( cssRulesLength +1 === document.styleSheets.length, 'New css rule added to the document' );
 16+ var loadedFontsSize = mw.webfonts.fonts.length;
 17+ assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font again' );
 18+ assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'Already loaded fonts not loaded again.' );
 19+ assertFalse( mw.webfonts.addFont( 'Some Non existing font' ), 'addFont should return false if font not found' );
 20+ assertTrue( cssRulesLength +1 === document.styleSheets.length, 'No new css rules added at this stage' );
 21+});
1022
Index: trunk/extensions/WebFonts/resources/ext.webfonts.js
@@ -148,6 +148,7 @@
149149 * This method ensures that css are not duplicated and
150150 * keep track of added fonts.
151151 * @param fontFamilyName {String} The font-family name
 152+ * @return boolean False if font not found. True if loaded.
152153 */
153154 addFont: function( fontFamilyName ) {
154155 // Avoid duplicate loading
@@ -156,8 +157,11 @@
157158 if ( mw.webfonts.config.fonts[fontFamilyName] !== undefined ) {
158159 mw.webfonts.loadCSS( fontFamilyName );
159160 mw.webfonts.fonts.push( fontFamilyName );
 161+ } else {
 162+ return false;
160163 }
161164 }
 165+ return true;
162166 },
163167
164168 /**

Status & tagging log