Merge "Add ability to pre-render thumbnails at upload time"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.client.test.js
1 ( function ( $ ) {
2
3 QUnit.module( 'jquery.client', QUnit.newMwEnvironment() );
4
5 var uacount = 0,
6 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
7 uas = {
8 // Internet Explorer 6
9 // Internet Explorer 7
10 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
11 title: 'Internet Explorer 7',
12 platform: 'Win32',
13 profile: {
14 name: 'msie',
15 layout: 'trident',
16 layoutVersion: 'unknown',
17 platform: 'win',
18 version: '7.0',
19 versionBase: '7',
20 versionNumber: 7
21 },
22 wikiEditor: {
23 ltr: true,
24 rtl: false
25 }
26 },
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',
32 platform: 'Win32',
33 profile: {
34 name: 'msie',
35 layout: 'trident',
36 layoutVersion: 6,
37 platform: 'win',
38 version: '10.0',
39 versionBase: '10',
40 versionNumber: 10
41 },
42 wikiEditor: {
43 ltr: true,
44 rtl: true
45 }
46 },
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',
50 platform: 'Win32',
51 profile: {
52 name: 'msie',
53 layout: 'trident',
54 layoutVersion: 7,
55 platform: 'win',
56 version: '11.0',
57 versionBase: '11',
58 versionNumber: 11
59 },
60 wikiEditor: {
61 ltr: true,
62 rtl: true
63 }
64 },
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',
68 platform: 'Win64',
69 profile: {
70 name: 'msie',
71 layout: 'trident',
72 layoutVersion: 7,
73 platform: 'win',
74 version: '11.0',
75 versionBase: '11',
76 versionNumber: 11
77 },
78 wikiEditor: {
79 ltr: true,
80 rtl: true
81 }
82 },
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',
86 platform: 'WOW64',
87 profile: {
88 name: 'msie',
89 layout: 'trident',
90 layoutVersion: 7,
91 platform: 'win',
92 version: '11.0',
93 versionBase: '11',
94 versionNumber: 11
95 },
96 wikiEditor: {
97 ltr: true,
98 rtl: true
99 }
100 },
101 // Firefox 2
102 // Firefox 3.5
103 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
104 title: 'Firefox 3.5',
105 platform: 'MacIntel',
106 profile: {
107 name: 'firefox',
108 layout: 'gecko',
109 layoutVersion: 20110420,
110 platform: 'mac',
111 version: '3.5.19',
112 versionBase: '3',
113 versionNumber: 3.5
114 },
115 wikiEditor: {
116 ltr: true,
117 rtl: true
118 }
119 },
120 // Firefox 3.6
121 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
122 title: 'Firefox 3.6',
123 platform: 'Linux i686',
124 profile: {
125 name: 'firefox',
126 layout: 'gecko',
127 layoutVersion: 20110422,
128 platform: 'linux',
129 version: '3.6.17',
130 versionBase: '3',
131 versionNumber: 3.6
132 },
133 wikiEditor: {
134 ltr: true,
135 rtl: true
136 }
137 },
138 // Firefox 4
139 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
140 title: 'Firefox 4',
141 platform: 'Win32',
142 profile: {
143 name: 'firefox',
144 layout: 'gecko',
145 layoutVersion: 20100101,
146 platform: 'win',
147 version: '4.0.1',
148 versionBase: '4',
149 versionNumber: 4
150 },
151 wikiEditor: {
152 ltr: true,
153 rtl: true
154 }
155 },
156 // Firefox 10 nightly build
157 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
158 title: 'Firefox 10 nightly',
159 platform: 'Linux',
160 profile: {
161 name: 'firefox',
162 layout: 'gecko',
163 layoutVersion: 20111103,
164 platform: 'linux',
165 version: '10.0a1',
166 versionBase: '10',
167 versionNumber: 10
168 },
169 wikiEditor: {
170 ltr: true,
171 rtl: true
172 }
173 },
174 // Iceweasel 10.0.6
175 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
176 title: 'Iceweasel 10.0.6',
177 platform: 'Linux',
178 profile: {
179 name: 'iceweasel',
180 layout: 'gecko',
181 layoutVersion: 20100101,
182 platform: 'linux',
183 version: '10.0.6',
184 versionBase: '10',
185 versionNumber: 10
186 },
187 wikiEditor: {
188 ltr: true,
189 rtl: true
190 }
191 },
192 // Iceweasel 15.0.1
193 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': {
194 title: 'Iceweasel 15.0.1',
195 platform: 'Linux',
196 profile: {
197 name: 'iceweasel',
198 layout: 'gecko',
199 layoutVersion: 20100101,
200 platform: 'linux',
201 version: '15.0.1',
202 versionBase: '15',
203 versionNumber: 15
204 },
205 wikiEditor: {
206 ltr: true,
207 rtl: true
208 }
209 },
210 // Firefox 5
211 // Safari 3
212 // Safari 4
213 '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': {
214 title: 'Safari 4',
215 platform: 'MacIntel',
216 profile: {
217 name: 'safari',
218 layout: 'webkit',
219 layoutVersion: 531,
220 platform: 'mac',
221 version: '4.0.5',
222 versionBase: '4',
223 versionNumber: 4
224 },
225 wikiEditor: {
226 ltr: true,
227 rtl: true
228 }
229 },
230 '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': {
231 title: 'Safari 4',
232 platform: 'Win32',
233 profile: {
234 name: 'safari',
235 layout: 'webkit',
236 layoutVersion: 533,
237 platform: 'win',
238 version: '4.0.5',
239 versionBase: '4',
240 versionNumber: 4
241 },
242 wikiEditor: {
243 ltr: true,
244 rtl: true
245 }
246 },
247 // Safari 5
248 // Safari 6
249 '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': {
250 title: 'Safari 6',
251 platform: 'MacIntel',
252 profile: {
253 name: 'safari',
254 layout: 'webkit',
255 layoutVersion: 536,
256 platform: 'mac',
257 version: '6.0.4',
258 versionBase: '6',
259 versionNumber: 6
260 },
261 wikiEditor: {
262 ltr: true,
263 rtl: true
264 }
265 },
266 // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko")
267 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': {
268 title: 'Safari 6',
269 platform: 'MacIntel',
270 profile: {
271 name: 'safari',
272 layout: 'webkit',
273 layoutVersion: 536,
274 platform: 'mac',
275 version: '6.0.5',
276 versionBase: '6',
277 versionNumber: 6
278 },
279 wikiEditor: {
280 ltr: true,
281 rtl: true
282 }
283 },
284 // Opera 10+
285 'Opera/9.80 (Windows NT 5.1)': {
286 title: 'Opera 10+ (exact version unspecified)',
287 platform: 'Win32',
288 profile: {
289 name: 'opera',
290 layout: 'presto',
291 layoutVersion: 'unknown',
292 platform: 'win',
293 version: '10',
294 versionBase: '10',
295 versionNumber: 10
296 },
297 wikiEditor: {
298 ltr: true,
299 rtl: true
300 }
301 },
302 // Opera 12
303 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
304 title: 'Opera 12',
305 platform: 'Win32',
306 profile: {
307 name: 'opera',
308 layout: 'presto',
309 layoutVersion: 'unknown',
310 platform: 'win',
311 version: '12.11',
312 versionBase: '12',
313 versionNumber: 12.11
314 },
315 wikiEditor: {
316 ltr: true,
317 rtl: true
318 }
319 },
320 // Opera 15 (WebKit-based)
321 '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': {
322 title: 'Opera 15',
323 platform: 'Win32',
324 profile: {
325 name: 'opera',
326 layout: 'webkit',
327 layoutVersion: 537,
328 platform: 'win',
329 version: '15.0.1147.130',
330 versionBase: '15',
331 versionNumber: 15
332 },
333 wikiEditor: {
334 ltr: true,
335 rtl: true
336 }
337 },
338 // Chrome 5
339 // Chrome 6
340 // Chrome 7
341 // Chrome 8
342 // Chrome 9
343 // Chrome 10
344 // Chrome 11
345 // Chrome 12
346 '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': {
347 title: 'Chrome 12',
348 platform: 'MacIntel',
349 profile: {
350 name: 'chrome',
351 layout: 'webkit',
352 layoutVersion: 534,
353 platform: 'mac',
354 version: '12.0.742.112',
355 versionBase: '12',
356 versionNumber: 12
357 },
358 wikiEditor: {
359 ltr: true,
360 rtl: true
361 }
362 },
363 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
364 title: 'Chrome 12',
365 platform: 'Linux i686',
366 profile: {
367 name: 'chrome',
368 layout: 'webkit',
369 layoutVersion: 534,
370 platform: 'linux',
371 version: '12.0.742.68',
372 versionBase: '12',
373 versionNumber: 12
374 },
375 wikiEditor: {
376 ltr: true,
377 rtl: true
378 }
379 },
380 // Android WebKit Browser 2.3
381 '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': {
382 title: 'Android WebKit Browser 2.3',
383 platform: 'Linux armv7l',
384 profile: {
385 name: 'android',
386 layout: 'webkit',
387 layoutVersion: 533,
388 platform: 'linux',
389 version: '2.3.5',
390 versionBase: '2',
391 versionNumber: 2.3
392 },
393 wikiEditor: {
394 ltr: true,
395 rtl: true
396 }
397 },
398 // Rekonq (bug 34924)
399 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
400 title: 'Rekonq',
401 platform: 'Linux i686',
402 profile: {
403 name: 'rekonq',
404 layout: 'webkit',
405 layoutVersion: 534,
406 platform: 'linux',
407 version: '534.34',
408 versionBase: '534',
409 versionNumber: 534.34
410 },
411 wikiEditor: {
412 ltr: true,
413 rtl: true
414 }
415 },
416 // Konqueror
417 'Mozilla/5.0 (X11; Linux i686) KHTML/4.9.1 (like Gecko) Konqueror/4.9': {
418 title: 'Konqueror',
419 platform: 'Linux i686',
420 profile: {
421 name: 'konqueror',
422 layout: 'khtml',
423 layoutVersion: 'unknown',
424 platform: 'linux',
425 version: '4.9.1',
426 versionBase: '4',
427 versionNumber: 4.9
428 },
429 wikiEditor: {
430 // '4.9' is less than '4.11'.
431 ltr: false,
432 rtl: false
433 },
434 wikiEditorLegacy: {
435 // The check is missing in legacyTestMap
436 ltr: true,
437 rtl: true
438 }
439 },
440 // Amazon Silk
441 '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': {
442 title: 'Silk',
443 platform: 'Desktop',
444 profile: {
445 name: 'silk',
446 layout: 'webkit',
447 layoutVersion: 533,
448 platform: 'unknown',
449 version: '1.0.13.81_10003810',
450 versionBase: '1',
451 versionNumber: 1
452 },
453 wikiEditor: {
454 ltr: true,
455 rtl: true
456 }
457 },
458 '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': {
459 title: 'Silk',
460 platform: 'Mobile',
461 profile: {
462 name: 'silk',
463 layout: 'webkit',
464 layoutVersion: 535,
465 platform: 'unknown',
466 version: '2.1',
467 versionBase: '2',
468 versionNumber: 2.1
469 },
470 wikiEditor: {
471 ltr: true,
472 rtl: true
473 }
474 }
475 },
476 testMap = {
477 // Example from WikiEditor, modified to provide version identifiers as strings and with
478 // Konqueror 4.11 check added.
479 'ltr': {
480 'msie': [['>=', '7.0']],
481 'firefox': [['>=', '2']],
482 'opera': [['>=', '9.6']],
483 'safari': [['>=', '3']],
484 'chrome': [['>=', '3']],
485 'netscape': [['>=', '9']],
486 'konqueror': [['>=', '4.11']],
487 'blackberry': false,
488 'ipod': false,
489 'iphone': false
490 },
491 'rtl': {
492 'msie': [['>=', '8']],
493 'firefox': [['>=', '2']],
494 'opera': [['>=', '9.6']],
495 'safari': [['>=', '3']],
496 'chrome': [['>=', '3']],
497 'netscape': [['>=', '9']],
498 'konqueror': [['>=', '4.11']],
499 'blackberry': false,
500 'ipod': false,
501 'iphone': false
502 }
503 },
504 legacyTestMap = {
505 // Original example from WikiEditor.
506 // This is using the old, but still supported way of providing version identifiers as numbers
507 // instead of strings; with this method, 4.9 would be considered larger than 4.11.
508 'ltr': {
509 'msie': [['>=', 7.0]],
510 'firefox': [['>=', 2]],
511 'opera': [['>=', 9.6]],
512 'safari': [['>=', 3]],
513 'chrome': [['>=', 3]],
514 'netscape': [['>=', 9]],
515 'blackberry': false,
516 'ipod': false,
517 'iphone': false
518 },
519 'rtl': {
520 'msie': [['>=', 8]],
521 'firefox': [['>=', 2]],
522 'opera': [['>=', 9.6]],
523 'safari': [['>=', 3]],
524 'chrome': [['>=', 3]],
525 'netscape': [['>=', 9]],
526 'blackberry': false,
527 'ipod': false,
528 'iphone': false
529 }
530 }
531 ;
532
533 // Count test cases
534 $.each( uas, function () {
535 uacount++;
536 } );
537
538 QUnit.test( 'profile( navObject )', 7, function ( assert ) {
539 var p = $.client.profile();
540
541 function unknownOrType( val, type, summary ) {
542 assert.ok( typeof val === type || val === 'unknown', summary );
543 }
544
545 assert.equal( typeof p, 'object', 'profile returns an object' );
546 unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
547 unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
548 unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
549 unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
550 unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
551 assert.equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
552 } );
553
554 QUnit.test( 'profile( navObject ) - samples', uacount, function ( assert ) {
555 // Loop through and run tests
556 $.each( uas, function ( rawUserAgent, data ) {
557 // Generate a client profile object and compare recursively
558 var ret = $.client.profile( {
559 userAgent: rawUserAgent,
560 platform: data.platform
561 } );
562 assert.deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
563 } );
564 } );
565
566 QUnit.test( 'test( testMap )', 4, function ( assert ) {
567 // .test() uses eval, make sure no exceptions are thrown
568 // then do a basic return value type check
569 var testMatch = $.client.test( testMap ),
570 ie7Profile = $.client.profile( {
571 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
572 'platform': ''
573 } );
574
575 assert.equal( typeof testMatch, 'boolean', 'map with ltr/rtl split returns a boolean value' );
576
577 testMatch = $.client.test( testMap.ltr );
578
579 assert.equal( typeof testMatch, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
580
581 assert.equal( $.client.test( {
582 'msie': null
583 }, ie7Profile ), true, 'returns true if any version of a browser are allowed (null)' );
584
585 assert.equal( $.client.test( {
586 'msie': false
587 }, ie7Profile ), false, 'returns false if all versions of a browser are not allowed (false)' );
588 } );
589
590 QUnit.test( 'test( testMap, exactMatchOnly )', 2, function ( assert ) {
591 var ie7Profile = $.client.profile( {
592 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
593 'platform': ''
594 } );
595
596 assert.equal( $.client.test( {
597 'firefox': [['>=', 2]]
598 }, ie7Profile, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
599
600 assert.equal( $.client.test( {
601 'firefox': [['>=', 2]]
602 }, ie7Profile, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
603 } );
604
605 QUnit.test( 'test( testMap ), test( legacyTestMap ) - WikiEditor sample', uacount * 2 * 2, function ( assert ) {
606 var $body = $( 'body' ),
607 bodyClasses = $body.attr( 'class' );
608
609 // Loop through and run tests
610 $.each( uas, function ( agent, data ) {
611 $.each( ['ltr', 'rtl'], function ( i, dir ) {
612 var profile, testMatch, legacyTestMatch;
613 $body.removeClass( 'ltr rtl' ).addClass( dir );
614 profile = $.client.profile( {
615 userAgent: agent,
616 platform: data.platform
617 } );
618 testMatch = $.client.test( testMap, profile );
619 legacyTestMatch = $.client.test( legacyTestMap, profile );
620 $body.removeClass( dir );
621
622 assert.equal(
623 testMatch,
624 data.wikiEditor[dir],
625 'testing comparison based on ' + dir + ', ' + agent
626 );
627 assert.equal(
628 legacyTestMatch,
629 data.wikiEditorLegacy ? data.wikiEditorLegacy[dir] : data.wikiEditor[dir],
630 'testing comparison based on ' + dir + ', ' + agent + ' (legacyTestMap)'
631 );
632 } );
633 } );
634
635 // Restore body classes
636 $body.attr( 'class', bodyClasses );
637 } );
638 }( jQuery ) );