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