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