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