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