1 module( 'jquery.client', QUnit.newMwEnvironment() );
3 test( '-- Initial check', function() {
5 ok( jQuery.client, 'jQuery.client defined' );
8 /** Number of user-agent defined */
11 var uas = (function() {
13 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
14 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
16 // Internet Explorer 6
17 // Internet Explorer 7
18 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
19 title: 'Internet Explorer 7',
24 "layoutVersion": "unknown",
35 // Internet Explorer 8
36 // Internet Explorer 9
37 // Internet Explorer 10
38 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
39 title: 'Internet Explorer 10',
44 "layoutVersion": "unknown", // should be able to report 6?
57 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
63 "layoutVersion": 20110420,
75 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
77 platform: 'Linux i686',
81 "layoutVersion": 20110422,
93 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
99 "layoutVersion": 20100101,
110 // Firefox 10 nightly build
111 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
112 title: 'Firefox 10 nightly',
117 "layoutVersion": 20111103,
131 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; nl-nl) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': {
133 platform: 'MacIntel',
137 "layoutVersion": 531,
148 'Mozilla/5.0 (Windows; U; Windows NT 6.0; cs-CZ) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': {
154 "layoutVersion": 533,
175 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30': {
177 platform: 'MacIntel',
181 "layoutVersion": 534,
183 "version": "12.0.742.112",
192 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
194 platform: 'Linux i686',
198 "layoutVersion": 534,
200 "version": "12.0.742.68",
210 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
212 platform: 'Linux i686',
216 "layoutVersion": 534,
219 "versionBase": "534",
220 "versionNumber": 534.34
228 $.each( uas, function() { uacount++ });
232 test( 'profile userAgent support', function() {
235 // Generate a client profile object and compare recursively
236 var uaTest = function( rawUserAgent, data ) {
237 var ret = $.client.profile( {
238 userAgent: rawUserAgent,
239 platform: data.platform
241 deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
244 // Loop through and run tests
245 $.each( uas, uaTest );
248 test( 'profile return validation for current user agent', function() {
250 var p = $.client.profile();
251 var unknownOrType = function( val, type, summary ) {
252 return ok( typeof val === type || val === 'unknown', summary );
255 equal( typeof p, 'object', 'profile returns an object' );
256 unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
257 unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
258 unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
259 unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
260 unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
261 equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
264 // Example from WikiEditor
265 // Make sure to use raw numbers, a string like "7.0" would fail on a
266 // version 10 browser since in string comparaison "10" is before "7.0" :)
269 'msie': [['>=', 7.0]],
270 'firefox': [['>=', 2]],
271 'opera': [['>=', 9.6]],
272 'safari': [['>=', 3]],
273 'chrome': [['>=', 3]],
274 'netscape': [['>=', 9]],
281 'firefox': [['>=', 2]],
282 'opera': [['>=', 9.6]],
283 'safari': [['>=', 3]],
284 'chrome': [['>=', 3]],
285 'netscape': [['>=', 9]],
292 test( 'test', function() {
295 // .test() uses eval, make sure no exceptions are thrown
296 // then do a basic return value type check
297 var testMatch = $.client.test( testMap );
299 equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
303 test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
304 expect( uacount * 2 ); // double since we test both LTR and RTL
306 var $body = $( 'body' ),
307 bodyClasses = $body.attr( 'class' );
309 // Loop through and run tests
310 $.each( uas, function ( agent, data ) {
311 $.each( ['ltr', 'rtl'], function ( i, dir ) {
312 $body.removeClass( 'ltr rtl' ).addClass( dir );
313 var profile = $.client.profile( {
315 platform: data.platform
317 var testMatch = $.client.test( testMap, profile );
318 $body.removeClass( dir );
320 equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
324 // Restore body classes
325 $body.attr( 'class', bodyClasses );