~ubuntu-branches/ubuntu/trusty/mediawiki/trusty

« back to all changes in this revision

Viewing changes to tests/qunit/suites/resources/jquery/jquery.client.test.js

  • Committer: Package Import Robot
  • Author(s): Thorsten Glaser
  • Date: 2014-03-28 09:56:29 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20140328095629-1526y9tchdd507id
Tags: 1:1.19.14+dfsg-1
* New upstream security fix release (Closes: #742857):
  - (bug 62497) SECURITY: Add CSRF token on Special:ChangePassword
  - (bug 62467) Set a title for the context during import on the cli
* Use upstream-provided signing key bundle

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        };
 
210
        $.each( uas, function() { uacount++ });
 
211
        return uas;
 
212
})();
 
213
 
 
214
test( 'profile userAgent support', function() {
 
215
        expect(uacount);
 
216
 
 
217
        // Generate a client profile object and compare recursively
 
218
        var uaTest = function( rawUserAgent, data ) {
 
219
                var ret = $.client.profile( {
 
220
                        userAgent: rawUserAgent,
 
221
                        platform: data.platform
 
222
                } );
 
223
                deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
 
224
        };
 
225
 
 
226
        // Loop through and run tests
 
227
        $.each( uas, uaTest );
 
228
} );
 
229
 
 
230
test( 'profile return validation for current user agent', function() {
 
231
        expect(7);
 
232
        var p = $.client.profile();
 
233
        var unknownOrType = function( val, type, summary ) {
 
234
                return ok( typeof val === type || val === 'unknown', summary );
 
235
        };
 
236
 
 
237
        equal( typeof p, 'object', 'profile returns an object' );
 
238
        unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
 
239
        unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
 
240
        unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
 
241
        unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
 
242
        unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
 
243
        equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
 
244
});
 
245
 
 
246
// Example from WikiEditor
 
247
// Make sure to use raw numbers, a string like "7.0" would fail on a
 
248
// version 10 browser since in string comparaison "10" is before "7.0" :)
 
249
var testMap = {
 
250
        'ltr': {
 
251
                'msie': [['>=', 7.0]],
 
252
                'firefox': [['>=', 2]],
 
253
                'opera': [['>=', 9.6]],
 
254
                'safari': [['>=', 3]],
 
255
                'chrome': [['>=', 3]],
 
256
                'netscape': [['>=', 9]],
 
257
                'blackberry': false,
 
258
                'ipod': false,
 
259
                'iphone': false
 
260
        },
 
261
        'rtl': {
 
262
                'msie': [['>=', 8]],
 
263
                'firefox': [['>=', 2]],
 
264
                'opera': [['>=', 9.6]],
 
265
                'safari': [['>=', 3]],
 
266
                'chrome': [['>=', 3]],
 
267
                'netscape': [['>=', 9]],
 
268
                'blackberry': false,
 
269
                'ipod': false,
 
270
                'iphone': false
 
271
        }
 
272
};
 
273
 
 
274
test( 'test', function() {
 
275
        expect(1);
 
276
 
 
277
        // .test() uses eval, make sure no exceptions are thrown
 
278
        // then do a basic return value type check
 
279
        var testMatch = $.client.test( testMap );
 
280
 
 
281
        equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
 
282
 
 
283
});
 
284
 
 
285
test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
 
286
        expect( uacount * 2 ); // double since we test both LTR and RTL
 
287
 
 
288
        var     $body = $( 'body' ),
 
289
                bodyClasses = $body.attr( 'class' );
 
290
 
 
291
        // Loop through and run tests
 
292
        $.each( uas, function ( agent, data ) {
 
293
                $.each( ['ltr', 'rtl'], function ( i, dir ) {
 
294
                        $body.removeClass( 'ltr rtl' ).addClass( dir );
 
295
                        var profile = $.client.profile( {
 
296
                                userAgent: agent,
 
297
                                platform: data.platform
 
298
                        } );
 
299
                        var testMatch = $.client.test( testMap, profile );
 
300
                        $body.removeClass( dir );
 
301
 
 
302
                        equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
 
303
                });
 
304
        });
 
305
 
 
306
        // Restore body classes
 
307
        $body.attr( 'class', bodyClasses );
 
308
});
 
309