r109610 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109609‎ | r109610 | r109611 >
Date:10:23, 20 January 2012
Author:amire80
Status:ok
Tags:
Comment:
A little more cleanup in blacklisted browser test. Test the cookie and the reset link.
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
@@ -1,3 +1,12 @@
 2+/**
 3+ * QUnit tests for WebFonts
 4+ *
 5+ * @file
 6+ * @author Santhosh Thottingal, Amir E. Aharoni
 7+ * @copyright Copyright © 2012 Santhosh Thottingal, Amir E. Aharoni
 8+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 9+ */
 10+
211 module( 'ext.webfonts', QUnit.newMwEnvironment() );
312
413 test( '-- Initial check', function() {
@@ -7,9 +16,10 @@
817 // TODO: need a better way to test this
918 ok( mw.webfonts, 'The WebFonts extension is not supposed to run in a blacklisted browser - '
1019 + navigator.appName + ' ' + navigator.userAgent );
11 - } else {
12 - ok( mw.webfonts, 'mw.webfonts is defined and the browser is supported' );
 20+ return;
1321 }
 22+
 23+ ok( mw.webfonts, 'mw.webfonts is defined and the browser is supported' );
1424 } );
1525
1626 test( '-- Application of a web font to the page and its removal', function() {
@@ -17,7 +27,7 @@
1828 return;
1929 }
2030
21 - expect( 25 );
 31+ expect( 27 );
2232
2333 var invalidFont = 'NonExistingFont';
2434 assertTrue( mw.webfonts.set( invalidFont ) === undefined, 'A non-existent font is not initialized' );
@@ -57,6 +67,9 @@
5868 deepEqual( fontFamilyList( $textareaElement.css( 'font-family' ) ),
5969 expectedFontFamilyValue, 'The web font was applied to font-family of textarea' );
6070
 71+ // Cookie set
 72+ equals( $.cookie( 'webfonts-font' ), teluguFont, 'Correct cookie for the font was set' );
 73+
6174 // Reset everything
6275 ok( mw.webfonts.set( false ) === undefined, 'Reset body after testing font application' );
6376 equals( $body.css( 'font-family' ), oldConfig.fontFamily, 'Previous font-family for body was restored' );
@@ -72,6 +85,9 @@
7386 ok( $selectElement.remove(), 'The select test element was removed from body' );
7487 ok( $textareaElement.remove(), 'The textarea test element was removed from body' );
7588
 89+ // Cookie set
 90+ equals( $.cookie( 'webfonts-font' ), 'none', 'The cookie was removed' );
 91+
7692 $body.attr( 'lang', bodyLang );
7793 } );
7894
@@ -86,11 +102,11 @@
87103 mw.webfonts.fonts = [];
88104 var cssRulesLength = document.styleSheets.length;
89105 assertTrue( mw.webfonts.addFont( validFontName ), 'Add a Devanagari font' );
90 - assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0 , 'Devanagari font loaded' );
 106+ assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0, 'Devanagari font loaded' );
91107 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' );
92108 var loadedFontsSize = mw.webfonts.fonts.length;
93109 assertTrue( mw.webfonts.addFont( validFontName ), 'Add the Devanagari font again' );
94 - assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'A font that is already loaded is not loaded again' );
 110+ assertTrue( loadedFontsSize === mw.webfonts.fonts.length, 'A font that is already loaded is not loaded again' );
95111 assertFalse( mw.webfonts.addFont( 'Some non-existing font' ), 'addFont returns false if the font was not found' );
96112 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'Loading the font does not add new css rules' );
97113 } );
@@ -117,15 +133,15 @@
118134 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute' );
119135 assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' );
120136
121 - ok( $testElement.attr( 'lang' , 'en' ), 'The lang attribute of the test element was set to en (English)' );
 137+ ok( $testElement.attr( 'lang', 'en' ), 'The lang attribute of the test element was set to en (English)' );
122138 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute en' );
123139 assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has no webfonts-lang-attr class since en lang has no fonts available' );
124140
125141 var tamilFont = mw.webfonts.config.languages.ta[0];
126 - ok( $testElement.attr( 'lang' , 'ta' ), 'Set lang attribute to ta (Tamil)' );
 142+ ok( $testElement.attr( 'lang', 'ta' ), 'Set lang attribute to ta (Tamil)' );
127143 ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute ta' );
128144 assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has webfonts-lang-attr class' );
129 - assertTrue( $.inArray( tamilFont, mw.webfonts.fonts ) >= 0 , 'Tamil font loaded' );
 145+ assertTrue( $.inArray( tamilFont, mw.webfonts.fonts ) >= 0, 'Tamil font loaded' );
130146 assertTrue( isFontFaceLoaded( tamilFont ), 'New css rule font-face was added to the document for Tamil font' );
131147
132148 ok( mw.webfonts.reset(), 'Reset webfonts after testing application by lang' );
@@ -150,22 +166,22 @@
151167 var latinWebFont = 'RufScript';
152168 var fallbackFonts = 'Helvetica, Arial, sans-serif';
153169 $testElement.attr( 'style','font-family: ' + latinWebFont + ', ' + fallbackFonts );
154 - assertTrue( $.inArray( latinWebFont, mw.webfonts.fonts ) === -1 , 'Latin font not loaded yet' );
 170+ assertTrue( $.inArray( latinWebFont, mw.webfonts.fonts ) === -1, 'Latin font not loaded yet' );
155171 ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Loaded fonts from font-family' );
156 - assertTrue( $.inArray( latinWebFont, mw.webfonts.fonts ) >= 0 , 'Latin font loaded' );
 172+ assertTrue( $.inArray( latinWebFont, mw.webfonts.fonts ) >= 0, 'Latin font loaded' );
157173 assertTrue( isFontFaceLoaded( latinWebFont ), 'New css rule added to the document for Latin' );
158174
159175 var invalidFont = 'NonExistingFont';
160176 $testElement.attr( 'style','font-family: ' + invalidFont + ', ' + fallbackFonts );
161177 ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Attempted to load non-existing fonts specified in font-family' );
162 - assertTrue( $.inArray( invalidFont, mw.webfonts.fonts ) === -1 , 'Font not loaded since it is not existing, including fallback fonts' );
 178+ assertTrue( $.inArray( invalidFont, mw.webfonts.fonts ) === -1, 'Font not loaded since it is not existing, including fallback fonts' );
163179 assertFalse( isFontFaceLoaded( invalidFont ), 'No new css rule added to the document since the font does not exist' );
164180
165181 var malayalamFont = mw.webfonts.config.languages.ml[0];
166182 $testElement.attr( 'style', 'font-family: ' + invalidFont + ', ' + malayalamFont + ', ' + fallbackFonts );
167 - assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) === -1 , 'Fallback font not loaded yet' );
 183+ assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) === -1, 'Fallback font not loaded yet' );
168184 ok( mw.webfonts.loadFontsForFontFamilyStyle(), 'Loading fonts from font-family' );
169 - assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) >= 0 , 'A fallback font was loaded' );
 185+ assertTrue( $.inArray( malayalamFont, mw.webfonts.fonts ) >= 0, 'A fallback font was loaded' );
170186 assertTrue( isFontFaceLoaded( malayalamFont ), 'New css rule added to the document for fallback font' );
171187
172188 ok( $testElement.remove() );
@@ -176,18 +192,19 @@
177193 return;
178194 }
179195
180 - expect( 8 );
 196+ expect( 9 );
181197
182198 var oldFonts = mw.webfonts.fonts;
183199 var fonts = [];
184200 assertFalse( mw.webfonts.buildMenu( fonts ), 'Build the menu with empty fonts list' );
185201 fonts = mw.webfonts.config.languages.hi;
186 - ok( mw.webfonts.buildMenu( fonts ) , 'Build the menu with Hindi fonts list' );
187 - equals( $( 'li#pt-webfont' ).length , 1, 'There should be one and only one menu at any time' );
188 - ok( mw.webfonts.buildMenu( fonts ) , 'Build the menu with Hindi fonts list again' );
189 - equals( $( 'li#pt-webfont' ).length , 1, 'There should be one and only one menu at any time' );
 202+ ok( mw.webfonts.buildMenu( fonts ), 'Build the menu with Hindi fonts list' );
 203+ equals( $( 'li#pt-webfont' ).length, 1, 'There should be one and only one menu at any time' );
 204+ ok( mw.webfonts.buildMenu( fonts ), 'Build the menu with Hindi fonts list again' );
 205+ equals( $( 'li#pt-webfont' ).length, 1, 'There should be one and only one menu at any time' );
190206 equals( $( 'ul#webfonts-fontsmenu li' ).length, fonts.length + 2, 'Number of menu items is number of availables fonts, a help link and reset item' );
191 - equals ( $( 'li.webfont-help-item').length, 1, 'Help link exists' );
 207+ equals( $( 'li.webfont-help-item').length, 1, 'Help link exists' );
 208+ equals( $( 'input#webfont-none' ).length, 1, 'Reset link exists' );
192209 if (oldFonts.length) {
193210 assertTrue( mw.webfonts.buildMenu( oldFonts ), 'Restore the menu' );
194211 } else {

Status & tagging log