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',
48 // Internet Explorer 11
49 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko': {
50 title
: 'Internet Explorer 11',
66 // Internet Explorer 11 - Windows 8.1 x64 Modern UI
67 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; rv:11.0) like Gecko': {
68 title
: 'Internet Explorer 11',
84 // Internet Explorer 11 - Windows 8.1 x64 desktop UI
85 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko': {
86 title
: 'Internet Explorer 11',
104 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
105 title
: 'Firefox 3.5',
106 platform
: 'MacIntel',
110 layoutVersion
: 20110420,
122 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
123 title
: 'Firefox 3.6',
124 platform
: 'Linux i686',
128 layoutVersion
: 20110422,
140 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
146 layoutVersion
: 20100101,
157 // Firefox 10 nightly build
158 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
159 title
: 'Firefox 10 nightly',
164 layoutVersion
: 20111103,
176 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
177 title
: 'Iceweasel 10.0.6',
182 layoutVersion
: 20100101,
194 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': {
195 title
: 'Iceweasel 15.0.1',
200 layoutVersion
: 20100101,
214 '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': {
216 platform
: 'MacIntel',
231 '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': {
250 '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': {
252 platform
: 'MacIntel',
267 // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko")
268 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': {
270 platform
: 'MacIntel',
286 'Opera/9.80 (Windows NT 5.1)': {
287 title
: 'Opera 10+ (exact version unspecified)',
292 layoutVersion
: 'unknown',
304 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
310 layoutVersion
: 'unknown',
321 // Opera 15 (WebKit-based)
322 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.130': {
330 version
: '15.0.1147.130',
347 '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': {
349 platform
: 'MacIntel',
355 version
: '12.0.742.112',
364 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
366 platform
: 'Linux i686',
372 version
: '12.0.742.68',
381 // Android WebKit Browser 2.3
382 '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': {
383 title
: 'Android WebKit Browser 2.3',
384 platform
: 'Linux armv7l',
400 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
402 platform
: 'Linux i686',
410 versionNumber
: 534.34
419 // Example from WikiEditor
420 // Make sure to use raw numbers, a string like "7.0" would fail on a
421 // version 10 browser since in string comparaison "10" is before "7.0" :)
423 'msie': [['>=', 7.0]],
424 'firefox': [['>=', 2]],
425 'opera': [['>=', 9.6]],
426 'safari': [['>=', 3]],
427 'chrome': [['>=', 3]],
428 'netscape': [['>=', 9]],
435 'firefox': [['>=', 2]],
436 'opera': [['>=', 9.6]],
437 'safari': [['>=', 3]],
438 'chrome': [['>=', 3]],
439 'netscape': [['>=', 9]],
448 $.each( uas
, function () {
452 QUnit
.test( 'profile( navObject )', 7, function ( assert
) {
453 var p
= $.client
.profile();
455 function unknownOrType( val
, type
, summary
) {
456 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
459 assert
.equal( typeof p
, 'object', 'profile returns an object' );
460 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
461 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
462 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
463 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
464 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
465 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
468 QUnit
.test( 'profile( navObject ) - samples', uacount
, function ( assert
) {
469 // Loop through and run tests
470 $.each( uas
, function ( rawUserAgent
, data
) {
471 // Generate a client profile object and compare recursively
472 var ret
= $.client
.profile( {
473 userAgent
: rawUserAgent
,
474 platform
: data
.platform
476 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
480 QUnit
.test( 'test( testMap )', 4, function ( assert
) {
481 // .test() uses eval, make sure no exceptions are thrown
482 // then do a basic return value type check
483 var testMatch
= $.client
.test( testMap
),
484 ie7Profile
= $.client
.profile( {
485 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
489 assert
.equal( typeof testMatch
, 'boolean', 'map with ltr/rtl split returns a boolean value' );
491 testMatch
= $.client
.test( testMap
.ltr
);
493 assert
.equal( typeof testMatch
, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
495 assert
.equal( $.client
.test( {
497 }, ie7Profile
), true, 'returns true if any version of a browser are allowed (null)' );
499 assert
.equal( $.client
.test( {
501 }, ie7Profile
), false, 'returns false if all versions of a browser are not allowed (false)' );
504 QUnit
.test( 'test( testMap, exactMatchOnly )', 2, function ( assert
) {
505 var ie7Profile
= $.client
.profile( {
506 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
510 assert
.equal( $.client
.test( {
511 'firefox': [['>=', 2]]
512 }, ie7Profile
, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
514 assert
.equal( $.client
.test( {
515 'firefox': [['>=', 2]]
516 }, ie7Profile
, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
519 QUnit
.test( 'test( testMap) - WikiEditor sample', uacount
* 2, function ( assert
) {
520 var $body
= $( 'body' ),
521 bodyClasses
= $body
.attr( 'class' );
523 // Loop through and run tests
524 $.each( uas
, function ( agent
, data
) {
525 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
526 var profile
, testMatch
;
527 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
528 profile
= $.client
.profile( {
530 platform
: data
.platform
532 testMatch
= $.client
.test( testMap
, profile
);
533 $body
.removeClass( dir
);
535 assert
.equal( testMatch
, data
.wikiEditor
[dir
], 'testing comparison based on ' + dir
+ ', ' + agent
);
539 // Restore body classes
540 $body
.attr( 'class', bodyClasses
);