2 var uacount
, uas
, testMap
;
4 QUnit
.module( 'jquery.client', QUnit
.newMwEnvironment() );
6 /** Number of user-agent defined */
11 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
12 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
14 // Internet Explorer 6
15 // Internet Explorer 7
16 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
17 title
: 'Internet Explorer 7',
22 layoutVersion
: 'unknown',
33 // Internet Explorer 8
34 // Internet Explorer 9
35 // Internet Explorer 10
36 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
37 title
: 'Internet Explorer 10',
42 layoutVersion
: 'unknown', // should be able to report 6?
55 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
61 layoutVersion
: 20110420,
73 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
75 platform
: 'Linux i686',
79 layoutVersion
: 20110422,
91 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
97 layoutVersion
: 20100101,
108 // Firefox 10 nightly build
109 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
110 title
: 'Firefox 10 nightly',
115 layoutVersion
: 20111103,
129 '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': {
131 platform
: 'MacIntel',
146 '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': {
173 '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': {
175 platform
: 'MacIntel',
181 version
: '12.0.742.112',
190 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
192 platform
: 'Linux i686',
198 version
: '12.0.742.68',
208 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
210 platform
: 'Linux i686',
218 versionNumber
: 534.34
226 $.each( uas
, function () {
232 QUnit
.test( 'profile userAgent support', uacount
, function ( assert
) {
233 // Generate a client profile object and compare recursively
234 var uaTest = function( rawUserAgent
, data
) {
235 var ret
= $.client
.profile( {
236 userAgent
: rawUserAgent
,
237 platform
: data
.platform
239 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
242 // Loop through and run tests
243 $.each( uas
, uaTest
);
246 QUnit
.test( 'profile return validation for current user agent', 7, function ( assert
) {
247 var p
= $.client
.profile();
248 function unknownOrType( val
, type
, summary
) {
249 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
252 assert
.equal( typeof p
, 'object', 'profile returns an object' );
253 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
254 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
255 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
256 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
257 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
258 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
261 // Example from WikiEditor
262 // Make sure to use raw numbers, a string like "7.0" would fail on a
263 // version 10 browser since in string comparaison "10" is before "7.0" :)
266 'msie': [['>=', 7.0]],
267 'firefox': [['>=', 2]],
268 'opera': [['>=', 9.6]],
269 'safari': [['>=', 3]],
270 'chrome': [['>=', 3]],
271 'netscape': [['>=', 9]],
278 'firefox': [['>=', 2]],
279 'opera': [['>=', 9.6]],
280 'safari': [['>=', 3]],
281 'chrome': [['>=', 3]],
282 'netscape': [['>=', 9]],
289 QUnit
.test( 'test', 1, function ( assert
) {
290 // .test() uses eval, make sure no exceptions are thrown
291 // then do a basic return value type check
292 var testMatch
= $.client
.test( testMap
);
294 assert
.equal( typeof testMatch
, 'boolean', 'test returns a boolean value' );
298 QUnit
.test( 'User-agent matches against WikiEditor\'s compatibility map', uacount
* 2, function ( assert
) {
299 var $body
= $( 'body' ),
300 bodyClasses
= $body
.attr( 'class' );
302 // Loop through and run tests
303 $.each( uas
, function ( agent
, data
) {
304 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
305 var profile
, testMatch
;
306 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
307 profile
= $.client
.profile( {
309 platform
: data
.platform
311 testMatch
= $.client
.test( testMap
, profile
);
312 $body
.removeClass( dir
);
314 assert
.equal( testMatch
, data
.wikiEditor
[dir
], 'testing comparison based on ' + dir
+ ', ' + agent
);
318 // Restore body classes
319 $body
.attr( 'class', bodyClasses
);