Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / core / test / unit / spec / Support.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.Support", function() {
16         describe("Ext.is", function() {
17
18                 var platform     = {
19                         detect: function(navigatorObject) {
20                                 var result     = [];
21
22                                 Ext.is.init(navigatorObject);
23
24                                 if (Ext.is.Desktop) {
25                                         result.push('Desktop');
26                                 }
27                                 if (Ext.is.Tablet) {
28                                         result.push('Tablet');
29                                 }
30                                 if (Ext.is.Phone) {
31                                         result.push('Phone');
32                                 }
33
34                                 if (Ext.is.iPad) {
35                                         result.push('iPad');
36                                 }
37                                 if (Ext.is.iPhone) {
38                                         result.push('iPhone');
39                                 }
40                                 if (Ext.is.iPod) {
41                                         result.push('iPod');
42                                 }
43
44                                 if (Ext.is.Mac) {
45                                         result.push('Mac');
46                                 }
47                                 if (Ext.is.Windows) {
48                                         result.push('Windows');
49                                 }
50                                 if (Ext.is.Linux) {
51                                         result.push('Linux');
52                                 }
53                                 if (Ext.is.Android) {
54                                         result.push('Android');
55                                 }
56                                 if (Ext.is.iOS) {
57                                         result.push('iOS');
58                                 }
59                                 if (Ext.is.Blackberry) {
60                                         result.push('BlackBerry');
61                                 }
62
63                                 // Reset back to use actual navigator host object
64                                 Ext.is.init(window.navigator);
65
66                                 return result.join(' ');
67                         },
68
69                         data: {
70                                 'Desktop Mac': {
71                                         Safari_502_Mac: {
72                                                 platform: 'MacIntel',
73                                                 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'
74                                         },
75
76                                         Chrome_70517_Mac: {
77                                                 platform: 'MacIntel',
78                                                 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'
79                                         },
80
81                                         Opera_1063_Mac: {
82                                                 platform: 'MacIntel',
83                                                 userAgent: 'Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.6.30 Version/10.63'
84                                         }
85                                 },
86                                 'Desktop Windows': {
87                                         IE_9Beta_Win7: {
88                                                 platform: 'Win32',
89                                                 userAgent: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; Media Center PC 6.0)'
90                                         },
91
92                                         IE_8_Win7: {
93                                                 platform: 'Win32',
94                                                 userAgent: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET CLR 3.5.30729)'
95                                         },
96
97                                         IE_7_WinVista: {
98                                                 platform: 'Win32',
99                                                 userAgent: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)'
100                                         },
101
102                                         IE_61_WinXP: {
103                                                 platform: 'Win32',
104                                                 userAgent: 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)'
105                                         },
106
107                                         Firefox_36_XP: {
108                                                 platform: 'Win32',
109                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'
110                                         },
111
112                                         Firefox_35_XP: {
113                                                 platform: 'Win32',
114                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.15) Gecko/20101026 Firefox/3.5.15'
115                                         },
116
117                                         Firefox_3_XP: {
118                                                 platform: 'Win32',
119                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 Firefox/3.0.19'
120                                         },
121
122                                         Opera_1054_XP: {
123                                                 platform: 'Win32',
124                                                 userAgent: 'Opera/9.80 (Windows NT 5.1; U; en) Presto/2.5.24 Version/10.54'
125                                         },
126
127                                         Opera_964_XP: {
128                                                 platform: 'Win32',
129                                                 userAgent: 'Opera/9.64 (Windows NT 5.1; U; en) Presto/2.1.1'
130                                         },
131
132                                         Safari_5_XP: {
133                                                 platform: 'Win32',
134                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4'
135                                         },
136
137                                         Safari_4_XP: {
138                                                 platform: 'Win32',
139                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.29'
140                                         },
141
142                                         Safari_3_XP: {
143                                                 platform: 'Win32',
144                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.29'
145                                         },
146
147                                         Chrome_8_Win7: {
148                                                 platform: 'Win32',
149                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10'
150                                         },
151
152                                         Chrome_7_XP: {
153                                                 platform: 'Win32',
154                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7'
155                                         },
156
157                                         Chrome_6_XP: {
158                                                 platform: 'Win32',
159                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.2 (KHTML, like Gecko) Chrome/6.0.453.1 Safari/534.2'
160                                         },
161
162                                         Chrome_5_XP: {
163                                                 platform: 'Win32',
164                                                 userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4'
165                                         }
166                                 },
167                                 'Tablet iPad iOS': {
168                                         iPad_32: {
169                                                 platform: 'iPad',
170                                                 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'
171                                         }
172                                 },
173                                 'Phone iPhone iOS': {
174                                         iPhone_31: {
175                                                 platform: 'iPhone',
176                                                 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'
177                                         }
178                                 },
179                                 'Phone iPod iOS': {
180                                         iPod_41: {
181                                                 platform: 'iPod',
182                                                 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'
183                                         },
184
185                                         iPod_31: {
186                                                 platform: 'iPod',
187                                                 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'
188                                         }
189                                 },
190                                 'Phone Linux Android': {
191                                         Android_22_G2: {
192                                                 platform: 'Linux armv7l',
193                                                 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'
194                                         },
195
196                                         Android_22_Desire: {
197                                                 platform: 'Linux armv7l',
198                                                 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'
199                                         },
200
201                                         Android_22_NexusOne: {
202                                                 platform: 'Linux armv7l',
203                                                 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'
204                                         },
205
206                                         Android_21_GalaxyS: {
207                                                 platform: 'Linux armv7l',
208                                                 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'
209                                         },
210
211                                         Android_21_Evo: {
212                                                 platform: 'Linux armv7l',
213                                                 userAgent: 'Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Sprint APA9292KT Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko)'
214                                         }
215                                 },
216                                 'Phone BlackBerry': {
217                                         BlackBerry_Torch: {
218                                                 platform: 'BlackBerry',
219                                                 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+'
220                                         }
221                                 }
222                         }
223                 },
224                 generateSpecsFor = function(type) {
225                         for (var data in platform.data[type]) {
226                                 if (platform.data.hasOwnProperty(type)) {
227                                         it("should detect " + data + " as " + type, function() {
228                                                 expect(platform.detect(platform.data[type][data])).toEqual(type);
229                                         });
230                                 }
231                         }
232                 };
233
234                 generateSpecsFor('Desktop Mac');
235                 generateSpecsFor('Desktop Windows');
236                 generateSpecsFor('Tablet iPad iOS');
237                 generateSpecsFor('Phone iPhone iOS');
238                 generateSpecsFor('Phone iPod iOS');
239                 generateSpecsFor('Phone Linux Android');
240                 generateSpecsFor('Phone BlackBerry');
241         });
242
243         describe("Ext.supports", function() {
244
245                 describe("OrientationChange", function() {
246                         it("should return true when supported", function() {
247                                 expect(Ext.supports.OrientationChange).toBe((typeof window.orientation != 'undefined') && ('onorientationchange' in window));
248                         });
249                 });
250
251                 describe("DeviceMotion", function() {
252                         it("should return true when supported", function() {
253                                 expect(Ext.supports.DeviceMotion).toBe('ondevicemotion' in window);
254                         });
255                 });
256
257                 describe("Touch", function() {
258                         it("should return true when supported", function() {
259                                 expect(Ext.supports.Touch).toBe(('ontouchstart' in window) && (!Ext.is.Desktop));
260                         });
261                 });
262
263         });
264 });
265