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)
10 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
11 title
: 'Internet Explorer 7',
16 layoutVersion
: 'unknown',
27 // Internet Explorer 8
28 // Internet Explorer 9
29 // Internet Explorer 10
30 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
31 title
: 'Internet Explorer 10',
47 // Internet Explorer 11
48 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko': {
49 title
: 'Internet Explorer 11',
65 // Internet Explorer 11 - Windows 8.1 x64 Modern UI
66 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; rv:11.0) like Gecko': {
67 title
: 'Internet Explorer 11',
83 // Internet Explorer 11 - Windows 8.1 x64 desktop UI
84 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko': {
85 title
: 'Internet Explorer 11',
103 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
104 title
: 'Firefox 3.5',
105 platform
: 'MacIntel',
109 layoutVersion
: 20110420,
121 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
122 title
: 'Firefox 3.6',
123 platform
: 'Linux i686',
127 layoutVersion
: 20110422,
139 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
145 layoutVersion
: 20100101,
156 // Firefox 10 nightly build
157 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
158 title
: 'Firefox 10 nightly',
163 layoutVersion
: 20111103,
175 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
176 title
: 'Iceweasel 10.0.6',
181 layoutVersion
: 20100101,
193 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': {
194 title
: 'Iceweasel 15.0.1',
199 layoutVersion
: 20100101,
213 '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': {
215 platform
: 'MacIntel',
230 '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': {
249 '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': {
251 platform
: 'MacIntel',
266 // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko")
267 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': {
269 platform
: 'MacIntel',
285 'Opera/9.80 (Windows NT 5.1)': {
286 title
: 'Opera 10+ (exact version unspecified)',
291 layoutVersion
: 'unknown',
303 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
309 layoutVersion
: 'unknown',
320 // Opera 15 (WebKit-based)
321 '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': {
329 version
: '15.0.1147.130',
346 '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': {
348 platform
: 'MacIntel',
354 version
: '12.0.742.112',
363 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
365 platform
: 'Linux i686',
371 version
: '12.0.742.68',
380 // Android WebKit Browser 2.3
381 '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': {
382 title
: 'Android WebKit Browser 2.3',
383 platform
: 'Linux armv7l',
398 // Rekonq (bug 34924)
399 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
401 platform
: 'Linux i686',
409 versionNumber
: 534.34
417 'Mozilla/5.0 (X11; Linux i686) KHTML/4.9.1 (like Gecko) Konqueror/4.9': {
419 platform
: 'Linux i686',
423 layoutVersion
: 'unknown',
430 // '4.9' is less than '4.11'.
435 // The check is missing in legacyTestMap
441 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.13.81_10003810) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true': {
449 version
: '1.0.13.81_10003810',
458 'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.1 Mobile Safari/535.19 Silk-Accelerated=true': {
477 // Example from WikiEditor, modified to provide version identifiers as strings and with
478 // Konqueror 4.11 check added.
480 'msie': [['>=', '7.0']],
481 'firefox': [['>=', '2']],
482 'opera': [['>=', '9.6']],
483 'safari': [['>=', '3']],
484 'chrome': [['>=', '3']],
485 'netscape': [['>=', '9']],
486 'konqueror': [['>=', '4.11']],
492 'msie': [['>=', '8']],
493 'firefox': [['>=', '2']],
494 'opera': [['>=', '9.6']],
495 'safari': [['>=', '3']],
496 'chrome': [['>=', '3']],
497 'netscape': [['>=', '9']],
498 'konqueror': [['>=', '4.11']],
505 // Original example from WikiEditor.
506 // This is using the old, but still supported way of providing version identifiers as numbers
507 // instead of strings; with this method, 4.9 would be considered larger than 4.11.
509 'msie': [['>=', 7.0]],
510 'firefox': [['>=', 2]],
511 'opera': [['>=', 9.6]],
512 'safari': [['>=', 3]],
513 'chrome': [['>=', 3]],
514 'netscape': [['>=', 9]],
521 'firefox': [['>=', 2]],
522 'opera': [['>=', 9.6]],
523 'safari': [['>=', 3]],
524 'chrome': [['>=', 3]],
525 'netscape': [['>=', 9]],
534 $.each( uas
, function () {
538 QUnit
.test( 'profile( navObject )', 7, function ( assert
) {
539 var p
= $.client
.profile();
541 function unknownOrType( val
, type
, summary
) {
542 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
545 assert
.equal( typeof p
, 'object', 'profile returns an object' );
546 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
547 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
548 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
549 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
550 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
551 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
554 QUnit
.test( 'profile( navObject ) - samples', uacount
, function ( assert
) {
555 // Loop through and run tests
556 $.each( uas
, function ( rawUserAgent
, data
) {
557 // Generate a client profile object and compare recursively
558 var ret
= $.client
.profile( {
559 userAgent
: rawUserAgent
,
560 platform
: data
.platform
562 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
566 QUnit
.test( 'test( testMap )', 4, function ( assert
) {
567 // .test() uses eval, make sure no exceptions are thrown
568 // then do a basic return value type check
569 var testMatch
= $.client
.test( testMap
),
570 ie7Profile
= $.client
.profile( {
571 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
575 assert
.equal( typeof testMatch
, 'boolean', 'map with ltr/rtl split returns a boolean value' );
577 testMatch
= $.client
.test( testMap
.ltr
);
579 assert
.equal( typeof testMatch
, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
581 assert
.equal( $.client
.test( {
583 }, ie7Profile
), true, 'returns true if any version of a browser are allowed (null)' );
585 assert
.equal( $.client
.test( {
587 }, ie7Profile
), false, 'returns false if all versions of a browser are not allowed (false)' );
590 QUnit
.test( 'test( testMap, exactMatchOnly )', 2, function ( assert
) {
591 var ie7Profile
= $.client
.profile( {
592 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
596 assert
.equal( $.client
.test( {
597 'firefox': [['>=', 2]]
598 }, ie7Profile
, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
600 assert
.equal( $.client
.test( {
601 'firefox': [['>=', 2]]
602 }, ie7Profile
, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
605 QUnit
.test( 'test( testMap ), test( legacyTestMap ) - WikiEditor sample', uacount
* 2 * 2, function ( assert
) {
606 var $body
= $( 'body' ),
607 bodyClasses
= $body
.attr( 'class' );
609 // Loop through and run tests
610 $.each( uas
, function ( agent
, data
) {
611 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
612 var profile
, testMatch
, legacyTestMatch
;
613 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
614 profile
= $.client
.profile( {
616 platform
: data
.platform
618 testMatch
= $.client
.test( testMap
, profile
);
619 legacyTestMatch
= $.client
.test( legacyTestMap
, profile
);
620 $body
.removeClass( dir
);
624 data
.wikiEditor
[dir
],
625 'testing comparison based on ' + dir
+ ', ' + agent
629 data
.wikiEditorLegacy
? data
.wikiEditorLegacy
[dir
] : data
.wikiEditor
[dir
],
630 'testing comparison based on ' + dir
+ ', ' + agent
+ ' (legacyTestMap)'
635 // Restore body classes
636 $body
.attr( 'class', bodyClasses
);