r109138 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109137‎ | r109138 | r109139 >
Date:12:14, 17 January 2012
Author:santhosh
Status:resolved
Tags:i18nreview 
Comment:
More test cases for webfonts
- Dynamic font loading based on lang attribute
- Dynamic font loading based on font-family style attribute

Some minor fixes in ext.webfonts.js to make methods 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
@@ -4,18 +4,76 @@
55 expect(1);
66
77 ok( mw.webfonts, 'mw.webfonts defined' );
8 -});
 8+} );
99
1010 test( '-- Dynamic font loading', function() {
1111 expect( 7 );
1212 var cssRulesLength = document.styleSheets.length;
1313 assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font' );
1414 assertTrue( $.inArray( 'Lohit Devanagari', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
15 - assertTrue( cssRulesLength +1 === document.styleSheets.length, 'New css rule added to the document' );
 15+ assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' );
1616 var loadedFontsSize = mw.webfonts.fonts.length;
1717 assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font again' );
1818 assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'Already loaded fonts not loaded again.' );
1919 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 -});
 20+ assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'No new css rules added at this stage' );
 21+} );
2222
 23+test( '-- Dynamic font loading based on lang attribute', function() {
 24+ expect( 15 );
 25+
 26+ ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some Content</p>") );
 27+ $testElement = $( 'p.webfonts-testing-lang-attr' )
 28+ assertTrue( $testElement !== undefined, 'Test element added' ) ;
 29+
 30+ ok( mw.webfonts.loadFontsForLangAttr() );
 31+ assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' ) ;
 32+
 33+ ok( $testElement.attr( 'lang' , 'en' ) , 'Set lang attribute as english' );
 34+ ok( mw.webfonts.loadFontsForLangAttr() );
 35+ assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is en lang has no fonts available' ) ;
 36+
 37+ ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute as Tamil' );
 38+ var cssRulesLength = document.styleSheets.length;
 39+ ok( mw.webfonts.loadFontsForLangAttr() );
 40+ assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has webfonts-lang-attr class' ) ;
 41+ assertTrue( $.inArray( 'Lohit Tamil', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
 42+ assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' );
 43+
 44+ ok( mw.webfonts.reset() );
 45+ assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' ) ;
 46+
 47+ ok( $testElement.remove() );
 48+} );
 49+
 50+test( '-- Dynamic font loading based on font-family style attribute', function() {
 51+ expect( 14 )
 52+
 53+ ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some Content</p>") );
 54+ var $testElement = $( 'p.webfonts-testing-font-family-style' );
 55+ assertTrue( $testElement !== undefined, 'Test element added' ) ;
 56+
 57+ $testElement.css( 'font-family', 'RufScript, Arial, Helvetica, sans');
 58+ var cssRulesLength = document.styleSheets.length;
 59+ assertTrue( $.inArray( 'RufScript', mw.webfonts.fonts ) === -1 , 'RufScript Font not loaded yet' );
 60+ ok( mw.webfonts.loadFontsForFontFamilyStyle() );
 61+ assertTrue( $.inArray( 'RufScript', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
 62+ assertTrue( cssRulesLength +1 === document.styleSheets.length, 'New css rule added to the document' );
 63+
 64+ $testElement.css( 'font-family', 'NonExistingFont, Arial, Helvetica, sans' );
 65+ cssRulesLength = document.styleSheets.length;
 66+ ok( mw.webfonts.loadFontsForFontFamilyStyle() );
 67+ assertTrue( $.inArray( 'NonExistingFont', mw.webfonts.fonts ) === -1 , 'Font not loaded since it is not existing, including fallback fonts' );
 68+ assertTrue( cssRulesLength === document.styleSheets.length, 'No new css rule added to the document' );
 69+
 70+ $testElement.css( 'font-family', 'NonExistingFont, AnjaliOldLipi, Arial, Helvetica, sans');
 71+ cssRulesLength = document.styleSheets.length;
 72+ assertTrue( $.inArray( 'AnjaliOldLipi', mw.webfonts.fonts ) === -1 , 'Fallback font AnjaliOldLipi not loaded yet' );
 73+ ok( mw.webfonts.loadFontsForFontFamilyStyle() );
 74+ assertTrue( $.inArray( 'AnjaliOldLipi', mw.webfonts.fonts ) >= 0 , 'Fallback font AnjaliOldLipi loaded' );
 75+ assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document for fallbackfont' );
 76+
 77+ ok( $testElement.remove() );
 78+} );
 79+
 80+
Index: trunk/extensions/WebFonts/resources/ext.webfonts.js
@@ -73,6 +73,7 @@
7474
7575 // Remove the cookie
7676 $.cookie( 'webfonts-font', 'none', { 'path': '/', 'expires': 30 } );
 77+ return true;
7778 },
7879
7980 /**
@@ -255,6 +256,7 @@
256257 }
257258 }
258259 });
 260+ return true;
259261 },
260262
261263 /**
@@ -273,6 +275,7 @@
274276 });
275277 }
276278 });
 279+ return true;
277280 },
278281
279282 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r109144Modify directly the style attr, .css didn't work - more tests passing now...nikerabbit13:51, 17 January 2012
r109145Tests found a bug, fallback fonts were not loaded because the spaces was not ...nikerabbit13:53, 17 January 2012
r109677[WebFonts.tests] Fixes...krinkle06:21, 21 January 2012

Status & tagging log