Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.client.test.js
1 ( function ( $ ) {
2 var uacount, uas, testMap;
3
4 QUnit.module( 'jquery.client', QUnit.newMwEnvironment() );
5
6 /** Number of user-agent defined */
7 uacount = 0;
8
9 uas = ( function () {
10
11 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
12 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
13 var uas = {
14 // Internet Explorer 6
15 // Internet Explorer 7
16 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
17 title: 'Internet Explorer 7',
18 platform: 'Win32',
19 profile: {
20 name: 'msie',
21 layout: 'trident',
22 layoutVersion: 'unknown',
23 platform: 'win',
24 version: '7.0',
25 versionBase: '7',
26 versionNumber: 7
27 },
28 wikiEditor: {
29 ltr: true,
30 rtl: false
31 }
32 },
33 // Internet Explorer 8
34 // Internet Explorer 9
35 // Internet Explorer 10
36 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
37 title: 'Internet Explorer 10',
38 platform: 'Win32',
39 profile: {
40 name: 'msie',
41 layout: 'trident',
42 layoutVersion: 'unknown', // should be able to report 6?
43 platform: 'win',
44 version: '10.0',
45 versionBase: '10',
46 versionNumber: 10
47 },
48 wikiEditor: {
49 ltr: true,
50 rtl: true
51 }
52 },
53 // Firefox 2
54 // Firefox 3.5
55 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
56 title: 'Firefox 3.5',
57 platform: 'MacIntel',
58 profile: {
59 name: 'firefox',
60 layout: 'gecko',
61 layoutVersion: 20110420,
62 platform: 'mac',
63 version: '3.5.19',
64 versionBase: '3',
65 versionNumber: 3.5
66 },
67 wikiEditor: {
68 ltr: true,
69 rtl: true
70 }
71 },
72 // Firefox 3.6
73 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
74 title: 'Firefox 3.6',
75 platform: 'Linux i686',
76 profile: {
77 name: 'firefox',
78 layout: 'gecko',
79 layoutVersion: 20110422,
80 platform: 'linux',
81 version: '3.6.17',
82 versionBase: '3',
83 versionNumber: 3.6
84 },
85 wikiEditor: {
86 ltr: true,
87 rtl: true
88 }
89 },
90 // Firefox 4
91 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
92 title: 'Firefox 4',
93 platform: 'Win32',
94 profile: {
95 name: 'firefox',
96 layout: 'gecko',
97 layoutVersion: 20100101,
98 platform: 'win',
99 version: '4.0.1',
100 versionBase: '4',
101 versionNumber: 4
102 },
103 wikiEditor: {
104 ltr: true,
105 rtl: true
106 }
107 },
108 // Firefox 10 nightly build
109 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
110 title: 'Firefox 10 nightly',
111 platform: 'Linux',
112 profile: {
113 name: 'firefox',
114 layout: 'gecko',
115 layoutVersion: 20111103,
116 platform: 'linux',
117 version: '10.0a1',
118 versionBase: '10',
119 versionNumber: 10
120 },
121 wikiEditor: {
122 ltr: true,
123 rtl: true
124 }
125 },
126 // Firefox 5
127 // Safari 3
128 // Safari 4
129 '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': {
130 title: 'Safari 4',
131 platform: 'MacIntel',
132 profile: {
133 name: 'safari',
134 layout: 'webkit',
135 layoutVersion: 531,
136 platform: 'mac',
137 version: '4.0.5',
138 versionBase: '4',
139 versionNumber: 4
140 },
141 wikiEditor: {
142 ltr: true,
143 rtl: true
144 }
145 },
146 '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': {
147 title: 'Safari 4',
148 platform: 'Win32',
149 profile: {
150 name: 'safari',
151 layout: 'webkit',
152 layoutVersion: 533,
153 platform: 'win',
154 version: '4.0.5',
155 versionBase: '4',
156 versionNumber: 4
157 },
158 wikiEditor: {
159 ltr: true,
160 rtl: true
161 }
162 },
163 // Safari 5
164 // Opera 10
165 // Chrome 5
166 // Chrome 6
167 // Chrome 7
168 // Chrome 8
169 // Chrome 9
170 // Chrome 10
171 // Chrome 11
172 // Chrome 12
173 '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': {
174 title: 'Chrome 12',
175 platform: 'MacIntel',
176 profile: {
177 name: 'chrome',
178 layout: 'webkit',
179 layoutVersion: 534,
180 platform: 'mac',
181 version: '12.0.742.112',
182 versionBase: '12',
183 versionNumber: 12
184 },
185 wikiEditor: {
186 ltr: true,
187 rtl: true
188 }
189 },
190 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
191 title: 'Chrome 12',
192 platform: 'Linux i686',
193 profile: {
194 name: 'chrome',
195 layout: 'webkit',
196 layoutVersion: 534,
197 platform: 'linux',
198 version: '12.0.742.68',
199 versionBase: '12',
200 versionNumber: 12
201 },
202 wikiEditor: {
203 ltr: true,
204 rtl: true
205 }
206 },
207 // Bug #34924
208 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': {
209 title: 'Rekonq',
210 platform: 'Linux i686',
211 profile: {
212 name: 'rekonq',
213 layout: 'webkit',
214 layoutVersion: 534,
215 platform: 'linux',
216 version: '534.34',
217 versionBase: '534',
218 versionNumber: 534.34
219 },
220 wikiEditor: {
221 ltr: true,
222 rtl: true
223 }
224 }
225 };
226 $.each( uas, function () {
227 uacount++;
228 });
229 return uas;
230 }() );
231
232 QUnit.test( 'profile userAgent support', uacount, function ( assert ) {
233 // Generate a client profile object and compare recursively
234 var uaTest = function( rawUserAgent, data ) {
235 var ret = $.client.profile( {
236 userAgent: rawUserAgent,
237 platform: data.platform
238 } );
239 assert.deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
240 };
241
242 // Loop through and run tests
243 $.each( uas, uaTest );
244 } );
245
246 QUnit.test( 'profile return validation for current user agent', 7, function ( assert ) {
247 var p = $.client.profile();
248 function unknownOrType( val, type, summary ) {
249 assert.ok( typeof val === type || val === 'unknown', summary );
250 }
251
252 assert.equal( typeof p, 'object', 'profile returns an object' );
253 unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
254 unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
255 unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
256 unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
257 unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
258 assert.equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
259 });
260
261 // Example from WikiEditor
262 // Make sure to use raw numbers, a string like "7.0" would fail on a
263 // version 10 browser since in string comparaison "10" is before "7.0" :)
264 testMap = {
265 'ltr': {
266 'msie': [['>=', 7.0]],
267 'firefox': [['>=', 2]],
268 'opera': [['>=', 9.6]],
269 'safari': [['>=', 3]],
270 'chrome': [['>=', 3]],
271 'netscape': [['>=', 9]],
272 'blackberry': false,
273 'ipod': false,
274 'iphone': false
275 },
276 'rtl': {
277 'msie': [['>=', 8]],
278 'firefox': [['>=', 2]],
279 'opera': [['>=', 9.6]],
280 'safari': [['>=', 3]],
281 'chrome': [['>=', 3]],
282 'netscape': [['>=', 9]],
283 'blackberry': false,
284 'ipod': false,
285 'iphone': false
286 }
287 };
288
289 QUnit.test( 'test', 1, function ( assert ) {
290 // .test() uses eval, make sure no exceptions are thrown
291 // then do a basic return value type check
292 var testMatch = $.client.test( testMap );
293
294 assert.equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
295
296 });
297
298 QUnit.test( 'User-agent matches against WikiEditor\'s compatibility map', uacount * 2, function ( assert ) {
299 var $body = $( 'body' ),
300 bodyClasses = $body.attr( 'class' );
301
302 // Loop through and run tests
303 $.each( uas, function ( agent, data ) {
304 $.each( ['ltr', 'rtl'], function ( i, dir ) {
305 var profile, testMatch;
306 $body.removeClass( 'ltr rtl' ).addClass( dir );
307 profile = $.client.profile( {
308 userAgent: agent,
309 platform: data.platform
310 } );
311 testMatch = $.client.test( testMap, profile );
312 $body.removeClass( dir );
313
314 assert.equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
315 });
316 });
317
318 // Restore body classes
319 $body.attr( 'class', bodyClasses );
320 });
321 }( jQuery ) );