Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js |
— | — | @@ -3,22 +3,23 @@ |
4 | 4 | test( '-- Initial check', function() { |
5 | 5 | expect(1); |
6 | 6 | |
7 | | - ok( mw.webfonts, 'mw.webfonts defined' ); |
| 7 | + ok( mw.webfonts, 'mw.webfonts is defined' ); |
8 | 8 | } ); |
9 | 9 | |
10 | 10 | test( '-- Dynamic font loading', function() { |
11 | 11 | expect( 7 ); |
12 | | - |
| 12 | + |
| 13 | + var validFontName = 'Lohit Devanagari'; |
13 | 14 | mw.webfonts.fonts = []; |
14 | 15 | var cssRulesLength = document.styleSheets.length; |
15 | | - assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font' ); |
16 | | - assertTrue( $.inArray( 'Lohit Devanagari', mw.webfonts.fonts ) >= 0 , 'Font loaded' ); |
| 16 | + assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the ' + validFontName + ' font' ); |
| 17 | + assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0 , validFontName + ' font loaded' ); |
17 | 18 | assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' ); |
18 | 19 | var loadedFontsSize = mw.webfonts.fonts.length; |
19 | | - assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font again' ); |
20 | | - assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'Already loaded fonts not loaded again.' ); |
21 | | - assertFalse( mw.webfonts.addFont( 'Some Non existing font' ), 'addFont should return false if font not found' ); |
22 | | - assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'No new css rules added at this stage' ); |
| 20 | + assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the ' + validFontName + ' font again' ); |
| 21 | + assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'A font that is already loaded is not loaded again' ); |
| 22 | + assertFalse( mw.webfonts.addFont( 'Some non-existing font' ), 'addFont returns false if the font was not found' ); |
| 23 | + assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'Loading the font does not add new css rules' ); |
23 | 24 | } ); |
24 | 25 | |
25 | 26 | test( '-- Dynamic font loading based on lang attribute', function() { |
— | — | @@ -32,27 +33,28 @@ |
33 | 34 | wgPageContentLanguage: "en", |
34 | 35 | } ); |
35 | 36 | |
36 | | - ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some Content</p>") ); |
| 37 | + ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some content</p>"), ' A testing element was appended to <body>' ); |
37 | 38 | $testElement = $( 'p.webfonts-testing-lang-attr' ) |
38 | | - assertTrue( $testElement !== [], 'Test element added' ) ; |
| 39 | + assertTrue( $testElement !== [], 'The test element is defined' ); |
39 | 40 | |
40 | | - ok( mw.webfonts.loadFontsForLangAttr() ); |
41 | | - assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' ) ; |
| 41 | + ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute' ); |
| 42 | + assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' ); |
42 | 43 | |
43 | | - ok( $testElement.attr( 'lang' , 'en' ) , 'Set lang attribute as english' ); |
44 | | - ok( mw.webfonts.loadFontsForLangAttr() ); |
45 | | - assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since en lang has no fonts available' ) ; |
| 44 | + ok( $testElement.attr( 'lang' , 'en' ) , 'The lang attribute of the test element was set to en (English)' ); |
| 45 | + ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute en' ); |
| 46 | + assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has no webfonts-lang-attr class since en lang has no fonts available' ); |
46 | 47 | |
47 | | - ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute as Tamil' ); |
48 | | - ok( mw.webfonts.loadFontsForLangAttr() ); |
49 | | - assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has webfonts-lang-attr class' ) ; |
50 | | - assertTrue( $.inArray( 'Lohit Tamil', mw.webfonts.fonts ) >= 0 , 'Font loaded' ); |
51 | | - assertTrue( isFontFaceLoaded( 'Lohit Tamil' ), 'New css rule added to the document for font Lohit Tamil' ); |
| 48 | + var tamilFont = 'Lohit Tamil'; |
| 49 | + ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute to ta (Tamil)' ); |
| 50 | + ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute ta' ); |
| 51 | + 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 | 54 | |
53 | | - ok( mw.webfonts.reset() ); |
54 | | - assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' ) ; |
| 55 | + ok( mw.webfonts.reset(), 'Reset webfonts' ); |
| 56 | + assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' ); |
55 | 57 | |
56 | | - ok( $testElement.remove() ); |
| 58 | + ok( $testElement.remove(), 'The test element was removed from <body>' ); |
57 | 59 | } ); |
58 | 60 | |
59 | 61 | test( '-- Dynamic font loading based on font-family style attribute', function() { |
— | — | @@ -61,7 +63,7 @@ |
62 | 64 | mw.webfonts.fonts = []; |
63 | 65 | ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some Content</p>" ) ); |
64 | 66 | var $testElement = $( 'p.webfonts-testing-font-family-style' ); |
65 | | - assertTrue( $testElement !== [], 'Test element added' ) ; |
| 67 | + assertTrue( $testElement !== [], 'Test element added' ); |
66 | 68 | |
67 | 69 | $testElement.attr( 'style','font-family: RufScript, Arial, Helvetica, sans' ); |
68 | 70 | assertTrue( $.inArray( 'RufScript', mw.webfonts.fonts ) === -1 , 'RufScript Font not loaded yet' ); |
— | — | @@ -86,10 +88,10 @@ |
87 | 89 | isFontFaceLoaded = function(fontFamilyName){ |
88 | 90 | var lastStyleIndex = document.styleSheets.length-1; |
89 | 91 | // Iterate from last. |
90 | | - for( var styleIndex = lastStyleIndex; styleIndex > 0 ; styleIndex-- ){ |
| 92 | + for( var styleIndex = lastStyleIndex; styleIndex > 0; styleIndex-- ){ |
91 | 93 | var lastStyleSheet = document.styleSheets[styleIndex]; |
92 | | - if ( !lastStyleSheet ) continue ; |
93 | | - if ( !lastStyleSheet.cssRules[0] ) continue ; |
| 94 | + if ( !lastStyleSheet ) continue; |
| 95 | + if ( !lastStyleSheet.cssRules[0] ) continue; |
94 | 96 | var cssText = lastStyleSheet.cssRules[0].cssText; |
95 | 97 | if ( cssText.indexOf( '@font-face' ) >= 0 && cssText.indexOf( fontFamilyName ) >= 0 ){ |
96 | 98 | return true; |