1 module( 'jquery.client', QUnit
.newMwEnvironment() );
3 test( '-- Initial check', function() {
5 ok( jQuery
.client
, 'jQuery.client defined' );
8 /** Number of user-agent defined */
11 var uas
= (function() {
13 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
14 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
16 // Internet Explorer 6
17 // Internet Explorer 7
18 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
19 title
: 'Internet Explorer 7',
24 "layoutVersion": "unknown",
35 // Internet Explorer 8
36 // Internet Explorer 9
37 // Internet Explorer 10
38 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
39 title
: 'Internet Explorer 10',
44 "layoutVersion": "unknown", // should be able to report 6?
57 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
63 "layoutVersion": 20110420,
75 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
77 platform
: 'Linux i686',
81 "layoutVersion": 20110422,
93 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
99 "layoutVersion": 20100101,
110 // Firefox 10 nightly build
111 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
112 title
: 'Firefox 10 nightly',
117 "layoutVersion": 20111103,
131 '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': {
133 platform
: 'MacIntel',
137 "layoutVersion": 531,
148 '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': {
154 "layoutVersion": 533,
175 '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': {
177 platform
: 'MacIntel',
181 "layoutVersion": 534,
183 "version": "12.0.742.112",
192 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
194 platform
: 'Linux i686',
198 "layoutVersion": 534,
200 "version": "12.0.742.68",
210 $.each( uas
, function() { uacount
++ });
214 test( 'profile userAgent support', function() {
217 // Generate a client profile object and compare recursively
218 var uaTest = function( rawUserAgent
, data
) {
219 var ret
= $.client
.profile( {
220 userAgent
: rawUserAgent
,
221 platform
: data
.platform
223 deepEqual( ret
, data
.profile
, 'Client profile support check for ' + data
.title
+ ' (' + data
.platform
+ '): ' + rawUserAgent
);
226 // Loop through and run tests
227 $.each( uas
, uaTest
);
230 test( 'profile return validation for current user agent', function() {
232 var p
= $.client
.profile();
233 var unknownOrType = function( val
, type
, summary
) {
234 return ok( typeof val
=== type
|| val
=== 'unknown', summary
);
237 equal( typeof p
, 'object', 'profile returns an object' );
238 unknownOrType( p
.layout
, 'string', 'p.layout is a string (or "unknown")' );
239 unknownOrType( p
.layoutVersion
, 'number', 'p.layoutVersion is a number (or "unknown")' );
240 unknownOrType( p
.platform
, 'string', 'p.platform is a string (or "unknown")' );
241 unknownOrType( p
.version
, 'string', 'p.version is a string (or "unknown")' );
242 unknownOrType( p
.versionBase
, 'string', 'p.versionBase is a string (or "unknown")' );
243 equal( typeof p
.versionNumber
, 'number', 'p.versionNumber is a number' );
246 // Example from WikiEditor
247 // Make sure to use raw numbers, a string like "7.0" would fail on a
248 // version 10 browser since in string comparaison "10" is before "7.0" :)
251 'msie': [['>=', 7.0]],
252 'firefox': [['>=', 2]],
253 'opera': [['>=', 9.6]],
254 'safari': [['>=', 3]],
255 'chrome': [['>=', 3]],
256 'netscape': [['>=', 9]],
263 'firefox': [['>=', 2]],
264 'opera': [['>=', 9.6]],
265 'safari': [['>=', 3]],
266 'chrome': [['>=', 3]],
267 'netscape': [['>=', 9]],
274 test( 'test', function() {
277 // .test() uses eval, make sure no exceptions are thrown
278 // then do a basic return value type check
279 var testMatch
= $.client
.test( testMap
);
281 equal( typeof testMatch
, 'boolean', 'test returns a boolean value' );
285 test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
286 expect( uacount
* 2 ); // double since we test both LTR and RTL
288 // Loop through and run tests
289 $.each( uas
, function( agent
, data
) {
290 $.each( ['ltr', 'rtl'], function( i
, dir
) {
291 $('body').addClass(dir
);
292 var profile
= $.client
.profile( {
294 platform
: data
.platform
296 var testMatch
= $.client
.test( testMap
, profile
);
297 $('body').removeClass(dir
);
299 equal( testMatch
, data
.wikiEditor
[dir
], 'testing comparison based on ' + dir
+ ', ' + agent
);