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',
101 // Internet Explorer 12
102 'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0': {
103 title
: 'Internet Explorer 12',
121 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
122 title
: 'Firefox 3.5',
123 platform
: 'MacIntel',
127 layoutVersion
: 20110420,
139 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
140 title
: 'Firefox 3.6',
141 platform
: 'Linux i686',
145 layoutVersion
: 20110422,
157 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
163 layoutVersion
: 20100101,
174 // Firefox 10 nightly build
175 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
176 title
: 'Firefox 10 nightly',
181 layoutVersion
: 20111103,
193 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
194 title
: 'Iceweasel 10.0.6',
199 layoutVersion
: 20100101,
211 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': {
212 title
: 'Iceweasel 15.0.1',
217 layoutVersion
: 20100101,
231 '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': {
233 platform
: 'MacIntel',
248 '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': {
267 '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': {
269 platform
: 'MacIntel',
284 // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko")
285 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': {
287 platform
: 'MacIntel',
303 'Opera/9.80 (Windows NT 5.1)': {
304 title
: 'Opera 10+ (exact version unspecified)',
309 layoutVersion
: 'unknown',
321 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
327 layoutVersion
: 'unknown',
338 // Opera 15 (WebKit-based)
339 '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': {
347 version
: '15.0.1147.130',
364 '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': {
366 platform
: 'MacIntel',
372 version
: '12.0.742.112',
381 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
383 platform
: 'Linux i686',
389 version
: '12.0.742.68',
398 // Android WebKit Browser 2.3
399 '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': {
400 title
: 'Android WebKit Browser 2.3',
401 platform
: 'Linux armv7l',
416 // Rekonq (bug 34924)
417 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
419 platform
: 'Linux i686',
427 versionNumber
: 534.34
435 'Mozilla/5.0 (X11; Linux i686) KHTML/4.9.1 (like Gecko) Konqueror/4.9': {
437 platform
: 'Linux i686',
441 layoutVersion
: 'unknown',
448 // '4.9' is less than '4.11'.
453 // The check is missing in legacyTestMap
459 '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': {
467 version
: '1.0.13.81_10003810',
476 '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': {
495 // Example from WikiEditor, modified to provide version identifiers as strings and with
496 // Konqueror 4.11 check added.
498 'msie': [['>=', '7.0']],
499 'firefox': [['>=', '2']],
500 'opera': [['>=', '9.6']],
501 'safari': [['>=', '3']],
502 'chrome': [['>=', '3']],
503 'netscape': [['>=', '9']],
504 'konqueror': [['>=', '4.11']],
510 'msie': [['>=', '8']],
511 'firefox': [['>=', '2']],
512 'opera': [['>=', '9.6']],
513 'safari': [['>=', '3']],
514 'chrome': [['>=', '3']],
515 'netscape': [['>=', '9']],
516 'konqueror': [['>=', '4.11']],
523 // Original example from WikiEditor.
524 // This is using the old, but still supported way of providing version identifiers as numbers
525 // instead of strings; with this method, 4.9 would be considered larger than 4.11.
527 'msie': [['>=', 7.0]],
528 'firefox': [['>=', 2]],
529 'opera': [['>=', 9.6]],
530 'safari': [['>=', 3]],
531 'chrome': [['>=', 3]],
532 'netscape': [['>=', 9]],
539 'firefox': [['>=', 2]],
540 'opera': [['>=', 9.6]],
541 'safari': [['>=', 3]],
542 'chrome': [['>=', 3]],
543 'netscape': [['>=', 9]],
552 $.each( uas
, function () {
556 QUnit
.test( 'profile( navObject )', 7, function ( assert
) {
557 var p
= $.client
.profile();
559 function unknownOrType( val
, type
, summary
) {
560 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
563 assert
.equal( typeof p
, 'object', 'profile returns an object' );
564 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
565 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
566 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
567 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
568 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
569 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
572 QUnit
.test( 'profile( navObject ) - samples', uacount
, function ( assert
) {
573 // Loop through and run tests
574 $.each( uas
, function ( rawUserAgent
, data
) {
575 // Generate a client profile object and compare recursively
576 var ret
= $.client
.profile( {
577 userAgent
: rawUserAgent
,
578 platform
: data
.platform
580 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
584 QUnit
.test( 'test( testMap )', 4, function ( assert
) {
585 // .test() uses eval, make sure no exceptions are thrown
586 // then do a basic return value type check
587 var testMatch
= $.client
.test( testMap
),
588 ie7Profile
= $.client
.profile( {
589 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
593 assert
.equal( typeof testMatch
, 'boolean', 'map with ltr/rtl split returns a boolean value' );
595 testMatch
= $.client
.test( testMap
.ltr
);
597 assert
.equal( typeof testMatch
, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
599 assert
.equal( $.client
.test( {
601 }, ie7Profile
), true, 'returns true if any version of a browser are allowed (null)' );
603 assert
.equal( $.client
.test( {
605 }, ie7Profile
), false, 'returns false if all versions of a browser are not allowed (false)' );
608 QUnit
.test( 'test( testMap, exactMatchOnly )', 2, function ( assert
) {
609 var ie7Profile
= $.client
.profile( {
610 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
614 assert
.equal( $.client
.test( {
615 'firefox': [['>=', 2]]
616 }, ie7Profile
, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
618 assert
.equal( $.client
.test( {
619 'firefox': [['>=', 2]]
620 }, ie7Profile
, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
623 QUnit
.test( 'test( testMap ), test( legacyTestMap ) - WikiEditor sample', uacount
* 2 * 2, function ( assert
) {
624 var $body
= $( 'body' ),
625 bodyClasses
= $body
.attr( 'class' );
627 // Loop through and run tests
628 $.each( uas
, function ( agent
, data
) {
629 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
630 var profile
, testMatch
, legacyTestMatch
;
631 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
632 profile
= $.client
.profile( {
634 platform
: data
.platform
636 testMatch
= $.client
.test( testMap
, profile
);
637 legacyTestMatch
= $.client
.test( legacyTestMap
, profile
);
638 $body
.removeClass( dir
);
642 data
.wikiEditor
[dir
],
643 'testing comparison based on ' + dir
+ ', ' + agent
647 data
.wikiEditorLegacy
? data
.wikiEditorLegacy
[dir
] : data
.wikiEditor
[dir
],
648 'testing comparison based on ' + dir
+ ', ' + agent
+ ' (legacyTestMap)'
653 // Restore body classes
654 $body
.attr( 'class', bodyClasses
);