Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / core / test / unit / spec / env / Environment.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 describe("Ext.Browser and Ext.OS", function() {
16     var profiles = {
17         Safari_502_Mac: {
18             platform: 'MacIntel',
19             userAgent: 'Safari_5533.18.5Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5',
20             expect: {
21                 browser: {
22                     name: 'Safari',
23                     flags: ['Safari', 'Safari5', 'Safari502', 'WebKit', 'WebKit533', 'WebKit533181'],
24                     version: '5.0.2'
25                 },
26                 os: {
27                     name: 'MacOSX',
28                     flags: ['MacOSX'],
29                     version: ''
30                 }
31             }
32         },
33
34         Chrome_70517_Mac: {
35             platform: 'MacIntel',
36             userAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7',
37             expect: {
38                 browser: {
39                     name: 'Chrome',
40                     flags: ['Chrome', 'Chrome7', 'Chrome7051744', 'WebKit', 'WebKit5347', 'WebKit534'],
41                     version: '7.0.517.44'
42                 },
43                 os: {
44                     name: 'MacOSX',
45                     flags: ['MacOSX'],
46                     version: ''
47                 }
48             }
49         },
50
51         Opera_980_Mac: {
52             platform: 'MacIntel',
53             userAgent: 'Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.6.30 Version/10.63',
54             expect: {
55                 browser: {
56                     name: 'Opera',
57                     flags: ['Opera', 'Opera9', 'Opera980', 'Presto', 'Presto2630', 'Presto2'],
58                     version: '9.80'
59                 },
60                 os: {
61                     name: 'MacOSX',
62                     flags: ['MacOSX'],
63                     version: ''
64                 }
65             }
66         },
67
68         IE_8_Win7: {
69             platform: 'Win32',
70             userAgent: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET CLR 3.5.30729)',
71             expect: {
72                 browser: {
73                     name: 'IE',
74                     flags: ['IE', 'IE8', 'IE80', 'Trident', 'Trident4', 'Trident40'],
75                     version: '8.0'
76                 },
77                 os: {
78                     name: 'Windows',
79                     flags: ['Windows'],
80                     version: ''
81                 }
82             }
83         },
84
85         IE_7_WinVista: {
86             platform: 'Win32',
87             userAgent: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',
88             expect: {
89                 browser: {
90                     name: 'IE',
91                     flags: ['IE', 'IE7', 'IE70', 'Other'],
92                     version: '7.0'
93                 },
94                 os: {
95                     name: 'Windows',
96                     flags: ['Windows'],
97                     version: ''
98                 }
99             }
100         },
101
102         IE_61_WinXP: {
103             platform: 'Win32',
104             userAgent: 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)',
105             expect: {
106                 browser: {
107                     name: 'IE',
108                     flags: ['IE', 'IE6', 'IE61', 'Other'],
109                     version: '6.1'
110                 },
111                 os: {
112                     name: 'Windows',
113                     flags: ['Windows'],
114                     version: ''
115                 }
116             }
117         },
118
119         iPad_32: {
120             platform: 'iPad',
121             userAgent: 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10',
122             expect: {
123                 browser: {
124                     name: 'Safari',
125                     flags: ['Safari', 'Safari4', 'Safari404', 'WebKit', 'WebKit531', 'WebKit5312110'],
126                     version: '4.0.4'
127                 },
128                 os: {
129                     name: 'iOS',
130                     flags: ['iOS', 'iOS3', 'iOS32', 'iPad'],
131                     version: '3.2'
132                 }
133             }
134         },
135
136         iPhone_31: {
137             platform: 'iPhone',
138             userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16',
139             expect: {
140                 browser: {
141                     name: 'Safari',
142                     flags: ['Safari', 'Safari4', 'Safari40', 'WebKit', 'WebKit528', 'WebKit52818'],
143                     version: '4.0'
144                 },
145                 os: {
146                     name: 'iOS',
147                     flags: ['iOS', 'iOS3', 'iOS313', 'iPhone'],
148                     version: '3.1.3'
149                 }
150             }
151         },
152
153         iPod_41: {
154             platform: 'iPod',
155             userAgent: 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B118 Safari/6531.22.7',
156             expect: {
157                 browser: {
158                     name: 'Safari',
159                     flags: ['Safari', 'Safari4', 'Safari405', 'WebKit', 'WebKit532', 'WebKit5329'],
160                     version: '4.0.5'
161                 },
162                 os: {
163                     name: 'iOS',
164                     flags: ['iOS', 'iOS4', 'iOS41', 'iPod'],
165                     version: '4.1'
166                 }
167             }
168         },
169
170         iPod_31: {
171             platform: 'iPod',
172             userAgent: 'Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16',
173             expect: {
174                 browser: {
175                     name: 'Safari',
176                     flags: ['Safari', 'Safari4', 'Safari40', 'WebKit', 'WebKit528', 'WebKit52818'],
177                     version: '4.0'
178                 },
179                 os: {
180                     name: 'iOS',
181                     flags: ['iOS', 'iOS3', 'iOS313', 'iPod'],
182                     version: '3.1.3'
183                 }
184             }
185         },
186
187         Android_22_G2: {
188             platform: 'Linux armv7l',
189             userAgent: ' Mozilla/5.0 (Linux; U; Android 2.2; en-us; T-Mobile G2 Build/ FRF91) AppleWebKit/533.1(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
190             expect: {
191                 browser: {
192                     name: 'Safari',
193                     flags: ['Safari', 'Safari4', 'Safari40', 'WebKit', 'WebKit533', 'WebKit5331'],
194                     version: '4.0'
195                 },
196                 os: {
197                     name: 'Android',
198                     flags: ['Android', 'Android2', 'Android22'],
199                     version: '2.2'
200                 }
201             }
202         },
203
204         Android_22_Desire: {
205             platform: 'Linux armv7l',
206             userAgent: 'Mozilla/5.0 (Linux; U; Android 2.2; en-vn; Desire_A8181 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
207             expect: {
208                 browser: {
209                     name: 'Safari',
210                     flags: ['Safari', 'Safari4', 'Safari40', 'WebKit', 'WebKit533', 'WebKit5331'],
211                     version: '4.0'
212                 },
213                 os: {
214                     name: 'Android',
215                     flags: ['Android', 'Android2', 'Android22'],
216                     version: '2.2'
217                 }
218             }
219         },
220
221         Android_22_NexusOne: {
222             platform: 'Linux armv7l',
223             userAgent: 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/ FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
224             expect: {
225                 browser: {
226                     name: 'Safari',
227                     flags: ['Safari', 'Safari4', 'Safari40', 'WebKit', 'WebKit533', 'WebKit5331'],
228                     version: '4.0'
229                 },
230                 os: {
231                     name: 'Android',
232                     flags: ['Android', 'Android2', 'Android22'],
233                     version: '2.2'
234                 }
235             }
236         },
237
238         Android_21_GalaxyS: {
239             platform: 'Linux armv7l',
240             userAgent: 'Mozilla/5.0 (Linux; U; Android 2.1-update1; fr-fr; GT-I9000 Build/ECLAIR) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17',
241             expect: {
242                 browser: {
243                     name: 'Safari',
244                     flags: ['Safari', 'Safari4', 'Safari40', 'WebKit', 'WebKit530', 'WebKit53017'],
245                     version: '4.0'
246                 },
247                 os: {
248                     name: 'Android',
249                     flags: ['Android', 'Android2', 'Android21'],
250                     version: '2.1update1'
251                 }
252             }
253         },
254
255         Android_21_Evo: {
256             platform: 'Linux armv7l',
257             userAgent: 'Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Sprint APA9292KT Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko)',
258             expect: {
259                 browser: {
260                     name: 'Other',
261                     flags: ['WebKit', 'WebKit530', 'WebKit53017'],
262                     version: ''
263                 },
264                 os: {
265                     name: 'Android',
266                     flags: ['Android', 'Android2', 'Android21'],
267                     version: '2.1update1'
268                 }
269             }
270         },
271
272         BlackBerry_Torch: {
273             platform: 'BlackBerry',
274             userAgent: 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-US) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+',
275             expect: {
276                 browser: {
277                     name: 'Safari',
278                     flags: ['WebKit', 'WebKit534', 'WebKit5341', 'Safari', 'Safari6', 'Safari600246'],
279                     version: '6.0.0.246'
280                 },
281                 os: {
282                     name: 'BlackBerry',
283                     flags: ['BlackBerry', 'BlackBerry6', 'BlackBerry600246'],
284                     version: '6.0.0.246'
285                 }
286             }
287         }
288     };
289     
290     var mockGlobal = {
291             document: {
292                 compatMode: ""
293             },
294             location: {
295                 protocol: "http:"
296             }
297         },
298         profile,
299         expected,
300         flags;
301
302     //~ Ext.each(profiles, function(name) {
303         //~ console.log(arguments);
304     specFor(profiles, function(name) {
305         describe(name, function() {
306             beforeEach(function() {
307                 profile = profiles[name];
308
309                 Ext.global = Ext.merge({}, mockGlobal, {
310                     navigator: {
311                         platform: profile.platform,
312                         userAgent: profile.userAgent
313                     }
314                 });
315
316                 expected = profile.expect;
317             });
318
319             afterEach(function() {
320                 Ext.global = window;
321             });
322
323             it("Ext.env.Browser", function() {
324                 var browserEnv = new Ext.env.Browser();
325
326                 expect(browserEnv.name).toBe(expected.browser.name);
327
328                 expect(browserEnv.version.toString()).toBe(expected.browser.version);
329
330                 flags = [];
331
332                 for (var k in browserEnv.is) {
333                     if (!browserEnv.is.hasOwnProperty(k)) {
334                         continue;
335                     }
336
337                     if (browserEnv.is[k] === true) {
338                         flags.push(k);
339                     }
340                 }
341
342                 expect(flags.sort()).toEqual(expected.browser.flags.sort());
343             });
344
345             it("Ext.env.OS", function() {
346                 var platformEnv = new Ext.env.OS();
347
348                 expect(platformEnv.name).toBe(expected.os.name);
349
350                 expect(platformEnv.version.toString()).toBe(expected.os.version);
351
352                 flags = [];
353
354                 for (var k in platformEnv.is) {
355                     if (!platformEnv.is.hasOwnProperty(k)) {
356                         continue;
357                     }
358
359                     if (platformEnv.is[k] === true) {
360                         flags.push(k);
361                     }
362                 }
363
364                 expect(flags.sort()).toEqual(expected.os.flags.sort());
365             });
366         });
367
368
369     });
370         
371 });
372