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