1 QUnit
.module( 'jquery.client', QUnit
.newMwEnvironment() );
3 /** Number of user-agent defined */
6 var uas
= (function () {
8 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
9 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
11 // Internet Explorer 6
12 // Internet Explorer 7
13 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
14 title
: 'Internet Explorer 7',
19 "layoutVersion": "unknown",
30 // Internet Explorer 8
31 // Internet Explorer 9
32 // Internet Explorer 10
33 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
34 title
: 'Internet Explorer 10',
39 "layoutVersion": "unknown", // should be able to report 6?
52 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
58 "layoutVersion": 20110420,
70 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
72 platform
: 'Linux i686',
76 "layoutVersion": 20110422,
88 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
94 "layoutVersion": 20100101,
105 // Firefox 10 nightly build
106 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
107 title
: 'Firefox 10 nightly',
112 "layoutVersion": 20111103,
126 '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': {
128 platform
: 'MacIntel',
132 "layoutVersion": 531,
143 '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': {
149 "layoutVersion": 533,
170 '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': {
172 platform
: 'MacIntel',
176 "layoutVersion": 534,
178 "version": "12.0.742.112",
187 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
189 platform
: 'Linux i686',
193 "layoutVersion": 534,
195 "version": "12.0.742.68",
205 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
207 platform
: 'Linux i686',
211 "layoutVersion": 534,
214 "versionBase": "534",
215 "versionNumber": 534.34
223 $.each( uas
, function () {
229 QUnit
.test( 'profile userAgent support', uacount
, function ( assert
) {
230 // Generate a client profile object and compare recursively
231 var uaTest = function( rawUserAgent
, data
) {
232 var ret
= $.client
.profile( {
233 userAgent
: rawUserAgent
,
234 platform
: data
.platform
236 assert
.deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
239 // Loop through and run tests
240 $.each( uas
, uaTest
);
243 QUnit
.test( 'profile return validation for current user agent', 7, function ( assert
) {
244 var p
= $.client
.profile();
245 function unknownOrType( val
, type
, summary
) {
246 assert
.ok( typeof val
=== type
|| val
=== 'unknown', summary
);
249 assert
.equal( typeof p
, 'object', 'profile returns an object' );
250 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
251 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
252 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
253 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
254 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
255 assert
.equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
258 // Example from WikiEditor
259 // Make sure to use raw numbers, a string like "7.0" would fail on a
260 // version 10 browser since in string comparaison "10" is before "7.0" :)
263 'msie': [['>=', 7.0]],
264 'firefox': [['>=', 2]],
265 'opera': [['>=', 9.6]],
266 'safari': [['>=', 3]],
267 'chrome': [['>=', 3]],
268 'netscape': [['>=', 9]],
275 'firefox': [['>=', 2]],
276 'opera': [['>=', 9.6]],
277 'safari': [['>=', 3]],
278 'chrome': [['>=', 3]],
279 'netscape': [['>=', 9]],
286 QUnit
.test( 'test', 1, function ( assert
) {
287 // .test() uses eval, make sure no exceptions are thrown
288 // then do a basic return value type check
289 var testMatch
= $.client
.test( testMap
);
291 assert
.equal( typeof testMatch
, 'boolean', 'test returns a boolean value' );
295 QUnit
.test( 'User-agent matches against WikiEditor\'s compatibility map', uacount
* 2, function ( assert
) {
296 var $body
= $( 'body' ),
297 bodyClasses
= $body
.attr( 'class' );
299 // Loop through and run tests
300 $.each( uas
, function ( agent
, data
) {
301 $.each( ['ltr', 'rtl'], function ( i
, dir
) {
302 $body
.removeClass( 'ltr rtl' ).addClass( dir
);
303 var profile
= $.client
.profile( {
305 platform
: data
.platform
307 var testMatch
= $.client
.test( testMap
, profile
);
308 $body
.removeClass( dir
);
310 assert
.equal( testMatch
, data
.wikiEditor
[dir
], 'testing comparison based on ' + dir
+ ', ' + agent
);
314 // Restore body classes
315 $body
.attr( 'class', bodyClasses
);