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',
399 // Rekonq (bug 34924)
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
418 'Mozilla/5.0 (X11; Linux i686) KHTML/4.9.1 (like Gecko) Konqueror/4.9': {
420 platform
: 'Linux i686',
424 layoutVersion
: 'unknown',
431 // '4.9' is less than '4.11'.
436 // The check is missing in legacyTestMap
442 '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': {
450 version
: '1.0.13.81_10003810',
459 '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': {
478 // Example from WikiEditor, modified to provide version identifiers as strings and with
479 // Konqueror 4.11 check added.
481 'msie': [['>=', '7.0']],
482 'firefox': [['>=', '2']],
483 'opera': [['>=', '9.6']],
484 'safari': [['>=', '3']],
485 'chrome': [['>=', '3']],
486 'netscape': [['>=', '9']],
487 'konqueror': [['>=', '4.11']],
493 'msie': [['>=', '8']],
494 'firefox': [['>=', '2']],
495 'opera': [['>=', '9.6']],
496 'safari': [['>=', '3']],
497 'chrome': [['>=', '3']],
498 'netscape': [['>=', '9']],
499 'konqueror': [['>=', '4.11']],
506 // Original example from WikiEditor.
507 // This is using the old, but still supported way of providing version identifiers as numbers
508 // instead of strings; with this method, 4.9 would be considered larger than 4.11.
510 'msie': [['>=', 7.0]],
511 'firefox': [['>=', 2]],
512 'opera': [['>=', 9.6]],
513 'safari': [['>=', 3]],
514 'chrome': [['>=', 3]],
515 'netscape': [['>=', 9]],
522 'firefox': [['>=', 2]],
523 'opera': [['>=', 9.6]],
524 'safari': [['>=', 3]],
525 'chrome': [['>=', 3]],
526 'netscape': [['>=', 9]],
535 $.each( uas
, function () {
539 QUnit
.test( 'profile( navObject )', 7, function ( assert
) {
540 var p
= $.client
.profile();
542 function unknownOrType( val
, type
, summary
) {
543 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
546 assert
.equal( typeof p
, 'object', 'profile returns an object' );
547 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
548 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
549 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
550 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
551 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
552 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
555 QUnit
.test( 'profile( navObject ) - samples', uacount
, function ( assert
) {
556 // Loop through and run tests
557 $.each( uas
, function ( rawUserAgent
, data
) {
558 // Generate a client profile object and compare recursively
559 var ret
= $.client
.profile( {
560 userAgent
: rawUserAgent
,
561 platform
: data
.platform
563 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
567 QUnit
.test( 'test( testMap )', 4, function ( assert
) {
568 // .test() uses eval, make sure no exceptions are thrown
569 // then do a basic return value type check
570 var testMatch
= $.client
.test( testMap
),
571 ie7Profile
= $.client
.profile( {
572 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
576 assert
.equal( typeof testMatch
, 'boolean', 'map with ltr/rtl split returns a boolean value' );
578 testMatch
= $.client
.test( testMap
.ltr
);
580 assert
.equal( typeof testMatch
, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
582 assert
.equal( $.client
.test( {
584 }, ie7Profile
), true, 'returns true if any version of a browser are allowed (null)' );
586 assert
.equal( $.client
.test( {
588 }, ie7Profile
), false, 'returns false if all versions of a browser are not allowed (false)' );
591 QUnit
.test( 'test( testMap, exactMatchOnly )', 2, function ( assert
) {
592 var ie7Profile
= $.client
.profile( {
593 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
597 assert
.equal( $.client
.test( {
598 'firefox': [['>=', 2]]
599 }, ie7Profile
, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
601 assert
.equal( $.client
.test( {
602 'firefox': [['>=', 2]]
603 }, ie7Profile
, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
606 QUnit
.test( 'test( testMap ), test( legacyTestMap ) - WikiEditor sample', uacount
* 2 * 2, function ( assert
) {
607 var $body
= $( 'body' ),
608 bodyClasses
= $body
.attr( 'class' );
610 // Loop through and run tests
611 $.each( uas
, function ( agent
, data
) {
612 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
613 var profile
, testMatch
, legacyTestMatch
;
614 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
615 profile
= $.client
.profile( {
617 platform
: data
.platform
619 testMatch
= $.client
.test( testMap
, profile
);
620 legacyTestMatch
= $.client
.test( legacyTestMap
, profile
);
621 $body
.removeClass( dir
);
625 data
.wikiEditor
[dir
],
626 'testing comparison based on ' + dir
+ ', ' + agent
630 data
.wikiEditorLegacy
? data
.wikiEditorLegacy
[dir
] : data
.wikiEditor
[dir
],
631 'testing comparison based on ' + dir
+ ', ' + agent
+ ' (legacyTestMap)'
636 // Restore body classes
637 $body
.attr( 'class', bodyClasses
);