r109170 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109169‎ | r109170 | r109171 >
Date:18:13, 17 January 2012
Author:amire80
Status:ok
Tags:i18nreview 
Comment:
Follow up to r109164 - more cleanup and restored test descriptions to be whole strings instead of lego for easier searching.
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
@@ -12,11 +12,11 @@
1313 var validFontName = 'Lohit Devanagari';
1414 mw.webfonts.fonts = [];
1515 var cssRulesLength = document.styleSheets.length;
16 - assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the ' + validFontName + ' font' );
17 - assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0 , validFontName + ' font loaded' );
 16+ assertTrue( mw.webfonts.addFont( validFontName ) , 'Add a Devanagari font' );
 17+ assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0 , 'Devanagari font loaded' );
1818 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' );
1919 var loadedFontsSize = mw.webfonts.fonts.length;
20 - assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the ' + validFontName + ' font again' );
 20+ assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the Devanagari font again' );
2121 assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'A font that is already loaded is not loaded again' );
2222 assertFalse( mw.webfonts.addFont( 'Some non-existing font' ), 'addFont returns false if the font was not found' );
2323 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'Loading the font does not add new css rules' );
@@ -33,7 +33,7 @@
3434 wgPageContentLanguage: "en",
3535 } );
3636
37 - ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some content</p>"), ' A testing element was appended to <body>' );
 37+ ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some content</p>"), ' A element for testing lang-based loading was appended to <body>' );
3838 $testElement = $( 'p.webfonts-testing-lang-attr' )
3939 assertTrue( $testElement !== [], 'The test element is defined' );
4040
@@ -48,8 +48,8 @@
4949 ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute to ta (Tamil)' );
5050 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute ta' );
5151 assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has webfonts-lang-attr class' );
52 - assertTrue( $.inArray( tamilFont, mw.webfonts.fonts ) >= 0 , tamilFont + ' font loaded' );
53 - assertTrue( isFontFaceLoaded( tamilFont ), 'New css rule font-face was added to the document for font ' + tamilFont );
 52+ assertTrue( $.inArray( tamilFont, mw.webfonts.fonts ) >= 0 , 'Tamil font loaded' );
 53+ assertTrue( isFontFaceLoaded( tamilFont ), 'New css rule font-face was added to the document for Tamil font' );
5454
5555 ok( mw.webfonts.reset(), 'Reset webfonts' );
5656 assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' );
@@ -61,41 +61,47 @@
6262 expect( 14 )
6363
6464 mw.webfonts.fonts = [];
65 - ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some Content</p>" ) );
 65+ ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some content</p>" ), 'An element for testing font-family loading was appended to <body>' );
6666 var $testElement = $( 'p.webfonts-testing-font-family-style' );
67 - assertTrue( $testElement !== [], 'Test element added' );
 67+ assertTrue( $testElement !== [], 'The test element is defined' );
6868
69 - $testElement.attr( 'style','font-family: RufScript, Arial, Helvetica, sans' );
70 - assertTrue( $.inArray( 'RufScript', mw.webfonts.fonts ) === -1 , 'RufScript Font not loaded yet' );
71 - ok( mw.webfonts.loadFontsForFontFamilyStyle() );
72 - assertTrue( $.inArray( 'RufScript', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
73 - assertTrue( isFontFaceLoaded('RufScript'), 'New css rule added to the document for RufScript' );
 69+ var latinWebFont = 'RufScript';
 70+ var fallbackFonts = ', Arial, Helvetica, sans';
 71+ $testElement.attr( 'style','font-family: ' + latinWebFont + fallbackFonts );
 72+ assertTrue( $.inArray( latinWebFont, mw.webfonts.fonts ) === -1 , 'Latin font not loaded yet' );
 73+ ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Loaded fonts from font-family' );
 74+ assertTrue( $.inArray( latinWebFont, mw.webfonts.fonts ) >= 0 , 'Latin font loaded' );
 75+ assertTrue( isFontFaceLoaded( latinWebFont ), 'New css rule added to the document for Latin' );
7476
75 - $testElement.attr( 'style','font-family: NonExistingFont, Arial, Helvetica, sans' );
76 - ok( mw.webfonts.loadFontsForFontFamilyStyle() );
77 - assertTrue( $.inArray( 'NonExistingFont', mw.webfonts.fonts ) === -1 , 'Font not loaded since it is not existing, including fallback fonts' );
78 - assertFalse( isFontFaceLoaded( 'NonExistingFont' ), 'No new css rule added to the document' );
79 -
80 - $testElement.attr( 'style','font-family: NonExistingFont, AnjaliOldLipi, Arial, Helvetica, sans' );
81 - assertTrue( $.inArray( 'AnjaliOldLipi', mw.webfonts.fonts ) === -1 , 'Fallback font AnjaliOldLipi not loaded yet' );
82 - ok( mw.webfonts.loadFontsForFontFamilyStyle() );
83 - assertTrue( $.inArray( 'AnjaliOldLipi', mw.webfonts.fonts ) >= 0 , 'Fallback font AnjaliOldLipi loaded' );
84 - assertTrue( isFontFaceLoaded('AnjaliOldLipi') , 'New css rule added to the document for fallbackfont AnjaliOldLipi' );
 77+ var invalidFont = 'NonExistingFont';
 78+ $testElement.attr( 'style','font-family: ' + invalidFont + fallbackFonts );
 79+ ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Attempted to load non-existing fonts specified in font-family' );
 80+ assertTrue( $.inArray( invalidFont, mw.webfonts.fonts ) === -1 , 'Font not loaded since it is not existing, including fallback fonts' );
 81+ assertFalse( isFontFaceLoaded( invalidFont ), 'No new css rule added to the document since the font does not exist' );
8582
 83+ var malayalamFont = 'AnjaliOldLipi';
 84+ $testElement.attr( 'style', 'font-family: ' + invalidFont + ', ' + malayalamFont + fallbackFonts );
 85+ assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) === -1 , 'Fallback font not loaded yet' );
 86+ ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Loading fonts from font-family' );
 87+ assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) >= 0 , 'A fallback font was loaded' );
 88+ assertTrue( isFontFaceLoaded( malayalamFont ) , 'New css rule added to the document for fallback font' );
 89+
8690 ok( $testElement.remove() );
8791 } );
8892
89 -isFontFaceLoaded = function(fontFamilyName){
90 - var lastStyleIndex = document.styleSheets.length-1;
 93+isFontFaceLoaded = function( fontFamilyName ) {
 94+ var lastStyleIndex = document.styleSheets.length - 1;
 95+
9196 // Iterate from last.
92 - for( var styleIndex = lastStyleIndex; styleIndex > 0; styleIndex-- ){
 97+ for( var styleIndex = lastStyleIndex; styleIndex > 0; styleIndex-- ) {
9398 var lastStyleSheet = document.styleSheets[styleIndex];
9499 if ( !lastStyleSheet ) continue;
95100 if ( !lastStyleSheet.cssRules[0] ) continue;
96101 var cssText = lastStyleSheet.cssRules[0].cssText;
97 - if ( cssText.indexOf( '@font-face' ) >= 0 && cssText.indexOf( fontFamilyName ) >= 0 ){
 102+ if ( cssText.indexOf( '@font-face' ) >= 0 && cssText.indexOf( fontFamilyName ) >= 0 ) {
98103 return true;
99104 }
100105 }
 106+
101107 return false;
102108 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109164Clearer test descriptions and constant font names.amire8017:10, 17 January 2012

Status & tagging log