2 var uacount
, uas
, testMap
;
4 QUnit
.module( 'jquery.client', QUnit
.newMwEnvironment() );
6 /** Number of user-agent defined */
11 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
12 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
14 // Internet Explorer 6
15 // Internet Explorer 7
16 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
17 title
: 'Internet Explorer 7',
22 layoutVersion
: 'unknown',
33 // Internet Explorer 8
34 // Internet Explorer 9
35 // Internet Explorer 10
36 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
37 title
: 'Internet Explorer 10',
42 layoutVersion
: 'unknown', // should be able to report 6?
55 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
61 layoutVersion
: 20110420,
73 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
75 platform
: 'Linux i686',
79 layoutVersion
: 20110422,
91 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
97 layoutVersion
: 20100101,
108 // Firefox 10 nightly build
109 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
110 title
: 'Firefox 10 nightly',
115 layoutVersion
: 20111103,
127 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
128 title
: 'Iceweasel 10.0.6',
133 layoutVersion
: 20100101,
147 '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': {
149 platform
: 'MacIntel',
164 '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': {
183 'Opera/9.80 (Windows NT 5.1)': {
184 title
: 'Opera 10+ (exact version unspecified)',
189 layoutVersion
: 'unknown',
201 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
207 layoutVersion
: 'unknown',
226 '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': {
228 platform
: 'MacIntel',
234 version
: '12.0.742.112',
243 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
245 platform
: 'Linux i686',
251 version
: '12.0.742.68',
261 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
263 platform
: 'Linux i686',
271 versionNumber
: 534.34
279 $.each( uas
, function () {
285 QUnit
.test( 'profile userAgent support', uacount
, function ( assert
) {
286 // Generate a client profile object and compare recursively
287 var uaTest = function ( rawUserAgent
, data
) {
288 var ret
= $.client
.profile( {
289 userAgent
: rawUserAgent
,
290 platform
: data
.platform
292 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
295 // Loop through and run tests
296 $.each( uas
, uaTest
);
299 QUnit
.test( 'profile return validation for current user agent', 7, function ( assert
) {
300 var p
= $.client
.profile();
302 function unknownOrType( val
, type
, summary
) {
303 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
306 assert
.equal( typeof p
, 'object', 'profile returns an object' );
307 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
308 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
309 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
310 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
311 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
312 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
315 // Example from WikiEditor
316 // Make sure to use raw numbers, a string like "7.0" would fail on a
317 // version 10 browser since in string comparaison "10" is before "7.0" :)
320 'msie': [['>=', 7.0]],
321 'firefox': [['>=', 2]],
322 'opera': [['>=', 9.6]],
323 'safari': [['>=', 3]],
324 'chrome': [['>=', 3]],
325 'netscape': [['>=', 9]],
332 'firefox': [['>=', 2]],
333 'opera': [['>=', 9.6]],
334 'safari': [['>=', 3]],
335 'chrome': [['>=', 3]],
336 'netscape': [['>=', 9]],
343 QUnit
.test( 'test', 1, function ( assert
) {
344 // .test() uses eval, make sure no exceptions are thrown
345 // then do a basic return value type check
346 var testMatch
= $.client
.test( testMap
);
348 assert
.equal( typeof testMatch
, 'boolean', 'test returns a boolean value' );
352 QUnit
.test( 'User-agent matches against WikiEditor\'s compatibility map', uacount
* 2, function ( assert
) {
353 var $body
= $( 'body' ),
354 bodyClasses
= $body
.attr( 'class' );
356 // Loop through and run tests
357 $.each( uas
, function ( agent
, data
) {
358 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
359 var profile
, testMatch
;
360 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
361 profile
= $.client
.profile( {
363 platform
: data
.platform
365 testMatch
= $.client
.test( testMap
, profile
);
366 $body
.removeClass( dir
);
368 assert
.equal( testMatch
, data
.wikiEditor
[dir
], 'testing comparison based on ' + dir
+ ', ' + agent
);
372 // Restore body classes
373 $body
.attr( 'class', bodyClasses
);