Merge "Installer: Remove wgResourceLoaderMaxQueryLength in LocalSettings"
[mediawiki.git] / tests / qunit / suites / resources / jquery / jquery.client.test.js
blobb2a6fd5b9c47bf305da9b4f9e2a7bca19fa46f70
1 ( function ( $ ) {
3         QUnit.module( 'jquery.client', QUnit.newMwEnvironment() );
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: 'unknown', // should be able to report 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                         // Firefox 2
49                         // Firefox 3.5
50                         'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
51                                 title: 'Firefox 3.5',
52                                 platform: 'MacIntel',
53                                 profile: {
54                                         name: 'firefox',
55                                         layout: 'gecko',
56                                         layoutVersion: 20110420,
57                                         platform: 'mac',
58                                         version: '3.5.19',
59                                         versionBase: '3',
60                                         versionNumber: 3.5
61                                 },
62                                 wikiEditor: {
63                                         ltr: true,
64                                         rtl: true
65                                 }
66                         },
67                         // Firefox 3.6
68                         'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
69                                 title: 'Firefox 3.6',
70                                 platform: 'Linux i686',
71                                 profile: {
72                                         name: 'firefox',
73                                         layout: 'gecko',
74                                         layoutVersion: 20110422,
75                                         platform: 'linux',
76                                         version: '3.6.17',
77                                         versionBase: '3',
78                                         versionNumber: 3.6
79                                 },
80                                 wikiEditor: {
81                                         ltr: true,
82                                         rtl: true
83                                 }
84                         },
85                         // Firefox 4
86                         'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
87                                 title: 'Firefox 4',
88                                 platform: 'Win32',
89                                 profile: {
90                                         name: 'firefox',
91                                         layout: 'gecko',
92                                         layoutVersion: 20100101,
93                                         platform: 'win',
94                                         version: '4.0.1',
95                                         versionBase: '4',
96                                         versionNumber: 4
97                                 },
98                                 wikiEditor: {
99                                         ltr: true,
100                                         rtl: true
101                                 }
102                         },
103                         // Firefox 10 nightly build
104                         'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
105                                 title: 'Firefox 10 nightly',
106                                 platform: 'Linux',
107                                 profile: {
108                                         name: 'firefox',
109                                         layout: 'gecko',
110                                         layoutVersion: 20111103,
111                                         platform: 'linux',
112                                         version: '10.0a1',
113                                         versionBase: '10',
114                                         versionNumber: 10
115                                 },
116                                 wikiEditor: {
117                                         ltr: true,
118                                         rtl: true
119                                 }
120                         },
121                         // Iceweasel 10.0.6
122                         'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': {
123                                 title: 'Iceweasel 10.0.6',
124                                 platform: 'Linux',
125                                 profile: {
126                                         name: 'iceweasel',
127                                         layout: 'gecko',
128                                         layoutVersion: 20100101,
129                                         platform: 'linux',
130                                         version: '10.0.6',
131                                         versionBase: '10',
132                                         versionNumber: 10
133                                 },
134                                 wikiEditor: {
135                                         ltr: true,
136                                         rtl: true
137                                 }
138                         },
139                         // Iceweasel 15.0.1
140                         'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': {
141                                 title: 'Iceweasel 15.0.1',
142                                 platform: 'Linux',
143                                 profile: {
144                                         name: 'iceweasel',
145                                         layout: 'gecko',
146                                         layoutVersion: 20100101,
147                                         platform: 'linux',
148                                         version: '15.0.1',
149                                         versionBase: '15',
150                                         versionNumber: 15
151                                 },
152                                 wikiEditor: {
153                                         ltr: true,
154                                         rtl: true
155                                 }
156                         },
157                         // Firefox 5
158                         // Safari 3
159                         // Safari 4
160                         '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': {
161                                 title: 'Safari 4',
162                                 platform: 'MacIntel',
163                                 profile: {
164                                         name: 'safari',
165                                         layout: 'webkit',
166                                         layoutVersion: 531,
167                                         platform: 'mac',
168                                         version: '4.0.5',
169                                         versionBase: '4',
170                                         versionNumber: 4
171                                 },
172                                 wikiEditor: {
173                                         ltr: true,
174                                         rtl: true
175                                 }
176                         },
177                         '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': {
178                                 title: 'Safari 4',
179                                 platform: 'Win32',
180                                 profile: {
181                                         name: 'safari',
182                                         layout: 'webkit',
183                                         layoutVersion: 533,
184                                         platform: 'win',
185                                         version: '4.0.5',
186                                         versionBase: '4',
187                                         versionNumber: 4
188                                 },
189                                 wikiEditor: {
190                                         ltr: true,
191                                         rtl: true
192                                 }
193                         },
194                         // Safari 5
195                         // Safari 6
196                         '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': {
197                                 title: 'Safari 6',
198                                 platform: 'MacIntel',
199                                 profile: {
200                                         name: 'safari',
201                                         layout: 'webkit',
202                                         layoutVersion: 536,
203                                         platform: 'mac',
204                                         version: '6.0.4',
205                                         versionBase: '6',
206                                         versionNumber: 6
207                                 },
208                                 wikiEditor: {
209                                         ltr: true,
210                                         rtl: true
211                                 }
212                         },
213                         // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko")
214                         'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': {
215                                 title: 'Safari 6',
216                                 platform: 'MacIntel',
217                                 profile: {
218                                         name: 'safari',
219                                         layout: 'webkit',
220                                         layoutVersion: 536,
221                                         platform: 'mac',
222                                         version: '6.0.5',
223                                         versionBase: '6',
224                                         versionNumber: 6
225                                 },
226                                 wikiEditor: {
227                                         ltr: true,
228                                         rtl: true
229                                 }
230                         },
231                         // Opera 10+
232                         'Opera/9.80 (Windows NT 5.1)': {
233                                 title: 'Opera 10+ (exact version unspecified)',
234                                 platform: 'Win32',
235                                 profile: {
236                                         name: 'opera',
237                                         layout: 'presto',
238                                         layoutVersion: 'unknown',
239                                         platform: 'win',
240                                         version: '10',
241                                         versionBase: '10',
242                                         versionNumber: 10
243                                 },
244                                 wikiEditor: {
245                                         ltr: true,
246                                         rtl: true
247                                 }
248                         },
249                         // Opera 12
250                         'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': {
251                                 title: 'Opera 12',
252                                 platform: 'Win32',
253                                 profile: {
254                                         name: 'opera',
255                                         layout: 'presto',
256                                         layoutVersion: 'unknown',
257                                         platform: 'win',
258                                         version: '12.11',
259                                         versionBase: '12',
260                                         versionNumber: 12.11
261                                 },
262                                 wikiEditor: {
263                                         ltr: true,
264                                         rtl: true
265                                 }
266                         },
267                         // Chrome 5
268                         // Chrome 6
269                         // Chrome 7
270                         // Chrome 8
271                         // Chrome 9
272                         // Chrome 10
273                         // Chrome 11
274                         // Chrome 12
275                         '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': {
276                                 title: 'Chrome 12',
277                                 platform: 'MacIntel',
278                                 profile: {
279                                         name: 'chrome',
280                                         layout: 'webkit',
281                                         layoutVersion: 534,
282                                         platform: 'mac',
283                                         version: '12.0.742.112',
284                                         versionBase: '12',
285                                         versionNumber: 12
286                                 },
287                                 wikiEditor: {
288                                         ltr: true,
289                                         rtl: true
290                                 }
291                         },
292                         'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
293                                 title: 'Chrome 12',
294                                 platform: 'Linux i686',
295                                 profile: {
296                                         name: 'chrome',
297                                         layout: 'webkit',
298                                         layoutVersion: 534,
299                                         platform: 'linux',
300                                         version: '12.0.742.68',
301                                         versionBase: '12',
302                                         versionNumber: 12
303                                 },
304                                 wikiEditor: {
305                                         ltr: true,
306                                         rtl: true
307                                 }
308                         },
309                         // Android WebKit Browser 2.3
310                         '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': {
311                                 title: 'Android WebKit Browser 2.3',
312                                 platform: 'Linux armv7l',
313                                 profile: {
314                                         name: 'android',
315                                         layout: 'webkit',
316                                         layoutVersion: 533,
317                                         platform: 'linux',
318                                         version: '2.3.5',
319                                         versionBase: '2',
320                                         versionNumber: 2.3
321                                 },
322                                 wikiEditor: {
323                                         ltr: true,
324                                         rtl: true
325                                 }
326                         },
327                         // Bug #34924
328                         'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
329                                 title: 'Rekonq',
330                                 platform: 'Linux i686',
331                                 profile: {
332                                         name: 'rekonq',
333                                         layout: 'webkit',
334                                         layoutVersion: 534,
335                                         platform: 'linux',
336                                         version: '534.34',
337                                         versionBase: '534',
338                                         versionNumber: 534.34
339                                 },
340                                 wikiEditor: {
341                                         ltr: true,
342                                         rtl: true
343                                 }
344                         }
345                 },
346                 testMap = {
347                         // Example from WikiEditor
348                         // Make sure to use raw numbers, a string like "7.0" would fail on a
349                         // version 10 browser since in string comparaison "10" is before "7.0" :)
350                         'ltr': {
351                                 'msie': [['>=', 7.0]],
352                                 'firefox': [['>=', 2]],
353                                 'opera': [['>=', 9.6]],
354                                 'safari': [['>=', 3]],
355                                 'chrome': [['>=', 3]],
356                                 'netscape': [['>=', 9]],
357                                 'blackberry': false,
358                                 'ipod': false,
359                                 'iphone': false
360                         },
361                         'rtl': {
362                                 'msie': [['>=', 8]],
363                                 'firefox': [['>=', 2]],
364                                 'opera': [['>=', 9.6]],
365                                 'safari': [['>=', 3]],
366                                 'chrome': [['>=', 3]],
367                                 'netscape': [['>=', 9]],
368                                 'blackberry': false,
369                                 'ipod': false,
370                                 'iphone': false
371                         }
372                 }
373         ;
375         // Count test cases
376         $.each( uas, function () {
377                 uacount++;
378         } );
380         QUnit.test( 'profile( navObject )', 7, function ( assert ) {
381                 var p = $.client.profile();
383                 function unknownOrType( val, type, summary ) {
384                         assert.ok( typeof val === type || val === 'unknown', summary );
385                 }
387                 assert.equal( typeof p, 'object', 'profile returns an object' );
388                 unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
389                 unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
390                 unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
391                 unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
392                 unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
393                 assert.equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
394         } );
396         QUnit.test( 'profile( navObject ) - samples', uacount, function ( assert ) {
397                 // Loop through and run tests
398                 $.each( uas, function ( rawUserAgent, data ) {
399                         // Generate a client profile object and compare recursively
400                         var ret = $.client.profile( {
401                                 userAgent: rawUserAgent,
402                                 platform: data.platform
403                         } );
404                         assert.deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
405                 } );
406         } );
408         QUnit.test( 'test( testMap )', 4, function ( assert ) {
409                 // .test() uses eval, make sure no exceptions are thrown
410                 // then do a basic return value type check
411                 var testMatch = $.client.test( testMap ),
412                         ie7Profile = $.client.profile( {
413                                 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
414                                 'platform': ''
415                         } );
417                 assert.equal( typeof testMatch, 'boolean', 'map with ltr/rtl split returns a boolean value' );
419                 testMatch = $.client.test( testMap.ltr );
421                 assert.equal( typeof testMatch, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' );
423                 assert.equal( $.client.test( {
424                         'msie': null
425                 }, ie7Profile ), true, 'returns true if any version of a browser are allowed (null)' );
427                 assert.equal( $.client.test( {
428                         'msie': false
429                 }, ie7Profile ), false, 'returns false if all versions of a browser are not allowed (false)' );
430         } );
432         QUnit.test( 'test( testMap, exactMatchOnly )', 2, function ( assert ) {
433                 var ie7Profile = $.client.profile( {
434                         'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
435                         'platform': ''
436                 } );
438                 assert.equal( $.client.test( {
439                         'firefox': [['>=', 2]]
440                 }, ie7Profile, false ), true, 'returns true if browser not found and exactMatchOnly not set' );
442                 assert.equal( $.client.test( {
443                         'firefox': [['>=', 2]]
444                 }, ie7Profile, true ), false, 'returns false if browser not found and exactMatchOnly is set' );
445         } );
447         QUnit.test( 'test( testMap) - WikiEditor sample', uacount * 2, function ( assert ) {
448                 var $body = $( 'body' ),
449                         bodyClasses = $body.attr( 'class' );
451                 // Loop through and run tests
452                 $.each( uas, function ( agent, data ) {
453                         $.each( ['ltr', 'rtl'], function ( i, dir ) {
454                                 var profile, testMatch;
455                                 $body.removeClass( 'ltr rtl' ).addClass( dir );
456                                 profile = $.client.profile( {
457                                         userAgent: agent,
458                                         platform: data.platform
459                                 } );
460                                 testMatch = $.client.test( testMap, profile );
461                                 $body.removeClass( dir );
463                                 assert.equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
464                         } );
465                 } );
467                 // Restore body classes
468                 $body.attr( 'class', bodyClasses );
469         } );
470 }( jQuery ) );