3 QUnit
.module( 'jquery.client', QUnit
.newMwEnvironment() );
6 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
7 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
10 // Internet Explorer 7
11 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
12 title
: 'Internet Explorer 7',
17 layoutVersion
: 'unknown',
28 // Internet Explorer 8
29 // Internet Explorer 9
30 // Internet Explorer 10
31 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
32 title
: 'Internet Explorer 10',
37 layoutVersion
: 'unknown', // should be able to report 6?
50 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
56 layoutVersion
: 20110420,
68 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
70 platform
: 'Linux i686',
74 layoutVersion
: 20110422,
86 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
92 layoutVersion
: 20100101,
103 // Firefox 10 nightly build
104 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
105 title
: 'Firefox 10 nightly',
110 layoutVersion
: 20111103,
122 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
123 title
: 'Iceweasel 10.0.6',
128 layoutVersion
: 20100101,
140 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': {
141 title
: 'Iceweasel 15.0.1',
146 layoutVersion
: 20100101,
160 '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': {
162 platform
: 'MacIntel',
177 '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': {
196 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13': {
198 platform
: 'MacIntel',
213 // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko")
214 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': {
216 platform
: 'MacIntel',
232 'Opera/9.80 (Windows NT 5.1)': {
233 title
: 'Opera 10+ (exact version unspecified)',
238 layoutVersion
: 'unknown',
250 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
256 layoutVersion
: 'unknown',
275 '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': {
277 platform
: 'MacIntel',
283 version
: '12.0.742.112',
292 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
294 platform
: 'Linux i686',
300 version
: '12.0.742.68',
309 // Android WebKit Browser 2.3
310 'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1': {
311 title
: 'Android WebKit Browser 2.3',
312 platform
: 'Linux armv7l',
328 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
330 platform
: 'Linux i686',
338 versionNumber
: 534.34
347 // Example from WikiEditor
348 // Make sure to use raw numbers, a string like "7.0" would fail on a
349 // version 10 browser since in string comparaison "10" is before "7.0" :)
351 'msie': [['>=', 7.0]],
352 'firefox': [['>=', 2]],
353 'opera': [['>=', 9.6]],
354 'safari': [['>=', 3]],
355 'chrome': [['>=', 3]],
356 'netscape': [['>=', 9]],
363 'firefox': [['>=', 2]],
364 'opera': [['>=', 9.6]],
365 'safari': [['>=', 3]],
366 'chrome': [['>=', 3]],
367 'netscape': [['>=', 9]],
376 $.each( uas
, function () {
380 QUnit
.test( 'profile( navObject )', 7, function ( assert
) {
381 var p
= $.client
.profile();
383 function unknownOrType( val
, type
, summary
) {
384 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
387 assert
.equal( typeof p
, 'object', 'profile returns an object' );
388 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
389 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
390 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
391 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
392 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
393 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
396 QUnit
.test( 'profile( navObject ) - samples', uacount
, function ( assert
) {
397 // Loop through and run tests
398 $.each( uas
, function ( rawUserAgent
, data
) {
399 // Generate a client profile object and compare recursively
400 var ret
= $.client
.profile( {
401 userAgent
: rawUserAgent
,
402 platform
: data
.platform
404 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
408 QUnit
.test( 'test( testMap )', 4, function ( assert
) {
409 // .test() uses eval, make sure no exceptions are thrown
410 // then do a basic return value type check
411 var testMatch
= $.client
.test( testMap
),
412 ie7Profile
= $.client
.profile( {
413 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
417 assert
.equal( typeof testMatch
, 'boolean', 'map with ltr/rtl split returns a boolean value' );
419 testMatch
= $.client
.test( testMap
.ltr
);
421 assert
.equal( typeof testMatch
, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
423 assert
.equal( $.client
.test( {
425 }, ie7Profile
), true, 'returns true if any version of a browser are allowed (null)' );
427 assert
.equal( $.client
.test( {
429 }, ie7Profile
), false, 'returns false if all versions of a browser are not allowed (false)' );
432 QUnit
.test( 'test( testMap, exactMatchOnly )', 2, function ( assert
) {
433 var ie7Profile
= $.client
.profile( {
434 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
438 assert
.equal( $.client
.test( {
439 'firefox': [['>=', 2]]
440 }, ie7Profile
, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
442 assert
.equal( $.client
.test( {
443 'firefox': [['>=', 2]]
444 }, ie7Profile
, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
447 QUnit
.test( 'test( testMap) - WikiEditor sample', uacount
* 2, function ( assert
) {
448 var $body
= $( 'body' ),
449 bodyClasses
= $body
.attr( 'class' );
451 // Loop through and run tests
452 $.each( uas
, function ( agent
, data
) {
453 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
454 var profile
, testMatch
;
455 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
456 profile
= $.client
.profile( {
458 platform
: data
.platform
460 testMatch
= $.client
.test( testMap
, profile
);
461 $body
.removeClass( dir
);
463 assert
.equal( testMatch
, data
.wikiEditor
[dir
], 'testing comparison based on ' + dir
+ ', ' + agent
);
467 // Restore body classes
468 $body
.attr( 'class', bodyClasses
);