1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
package com.vaadin.client;
import com.vaadin.shared.VBrowserDetails;
import junit.framework.TestCase;
public class TestVBrowserDetailsUserAgentParser extends TestCase {
private static final String FIREFOX30_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
private static final String FIREFOX30_LINUX = "Mozilla/5.0 (X11; U; Linux x86_64; es-ES; rv:1.9.0.12) Gecko/2009070811 Ubuntu/9.04 (jaunty) Firefox/3.0.12";
private static final String FIREFOX35_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729) FirePHP/0.4";
private static final String FIREFOX36_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)";
private static final String FIREFOX36B_MAC = "UAString mozilla/5.0 (macintosh; u; intel mac os x 10.6; en-us; rv:1.9.2) gecko/20100115 firefox/3.6";
private static final String FIREFOX_30B5_MAC = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5";
private static final String FIREFOX_40B7_WIN = "Mozilla/5.0 (Windows NT 5.1; rv:2.0b7) Gecko/20100101 Firefox/4.0b7";
private static final String FIREFOX_40B11_WIN = "Mozilla/5.0 (Windows NT 5.1; rv:2.0b11) Gecko/20100101 Firefox/4.0b11";
private static final String KONQUEROR_LINUX = "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Exabot-Thumbnails)";
private static final String IE6_WINDOWS = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
private static final String IE7_WINDOWS = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
private static final String IE8_WINDOWS = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
private static final String IE8_IN_IE7_MODE_WINDOWS = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
private static final String IE9_BETA_IN_IE7_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)";
private static final String IE9_BETA_IN_IE8_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)";
private static final String IE9_BETA_WINDOWS_7 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
// "Version/" was added in 10.00
private static final String OPERA964_WINDOWS = "Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1";
private static final String OPERA1010_WINDOWS = "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10";
private static final String OPERA1050_WINDOWS = "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.5.22 Version/10.50";
private static final String CHROME3_MAC = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.198 Safari/532.0";
private static final String CHROME4_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5";
private static final String SAFARI3_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 5.1; cs-CZ) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.29";
private static final String SAFARI4_MAC = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_8; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7";
private static final String IPHONE_IOS_5_1 = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3";
private static final String IPHONE_IOS_4_0 = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
private static final String IPAD_IOS_4_3_1 = "Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5";
private static final String ANDROID_HTC_2_1 = "Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; ADR6300 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17";
private static final String ANDROID_GOOGLE_NEXUS_2_2 = "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";
private static final String ANDROID_MOTOROLA_3_0 = "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13";
private static final String ANDROID_GALAXY_NEXUS_4_0_4_CHROME = "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19";
public void testSafari3() {
VBrowserDetails bd = new VBrowserDetails(SAFARI3_WINDOWS);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 2);
assertEngineVersion(bd, 525.0f);
assertWindows(bd);
}
public void testSafari4() {
VBrowserDetails bd = new VBrowserDetails(SAFARI4_MAC);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 531f);
assertMacOSX(bd);
}
public void testIPhoneIOS5() {
VBrowserDetails bd = new VBrowserDetails(IPHONE_IOS_5_1);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 5);
assertBrowserMinorVersion(bd, 1);
assertEngineVersion(bd, 534f);
assertIOS(bd, 5, 1);
}
public void testIPhoneIOS4() {
VBrowserDetails bd = new VBrowserDetails(IPHONE_IOS_4_0);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 532f);
assertIOS(bd, 4, 0);
}
public void testIPadIOS4() {
VBrowserDetails bd = new VBrowserDetails(IPAD_IOS_4_3_1);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 5);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 533f);
assertIOS(bd, 4, 3);
}
public void testAndroid21() {
VBrowserDetails bd = new VBrowserDetails(ANDROID_HTC_2_1);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 530f);
assertAndroid(bd, 2, 1);
}
public void testAndroid22() {
VBrowserDetails bd = new VBrowserDetails(ANDROID_GOOGLE_NEXUS_2_2);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 533f);
assertAndroid(bd, 2, 2);
}
public void testAndroid30() {
VBrowserDetails bd = new VBrowserDetails(ANDROID_MOTOROLA_3_0);
assertWebKit(bd);
assertSafari(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 534f);
assertAndroid(bd, 3, 0);
}
public void testAndroid40Chrome() {
VBrowserDetails bd = new VBrowserDetails(
ANDROID_GALAXY_NEXUS_4_0_4_CHROME);
assertWebKit(bd);
assertChrome(bd);
assertBrowserMajorVersion(bd, 18);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 535f);
assertAndroid(bd, 4, 0);
}
private void assertOSMajorVersion(VBrowserDetails bd, int i) {
assertEquals(i, bd.getOperatingSystemMajorVersion());
}
private void assertOSMinorVersion(VBrowserDetails bd, int i) {
assertEquals(i, bd.getOperatingSystemMinorVersion());
}
public void testChrome3() {
VBrowserDetails bd = new VBrowserDetails(CHROME3_MAC);
assertWebKit(bd);
assertChrome(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 532.0f);
assertMacOSX(bd);
}
public void testChrome4() {
VBrowserDetails bd = new VBrowserDetails(CHROME4_WINDOWS);
assertWebKit(bd);
assertChrome(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 532f);
assertWindows(bd);
}
public void testFirefox3() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX30_WINDOWS);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 1.9f);
assertWindows(bd);
bd = new VBrowserDetails(FIREFOX30_LINUX);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 1.9f);
assertLinux(bd);
}
public void testFirefox35() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX35_WINDOWS);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 5);
assertEngineVersion(bd, 1.9f);
assertWindows(bd);
}
public void testFirefox36() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX36_WINDOWS);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 6);
assertEngineVersion(bd, 1.9f);
assertWindows(bd);
}
public void testFirefox30b5() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX_30B5_MAC);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 1.9f);
assertMacOSX(bd);
}
public void testFirefox40b11() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX_40B11_WIN);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 2.0f);
assertWindows(bd);
}
public void testFirefox40b7() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX_40B7_WIN);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 4);
assertBrowserMinorVersion(bd, 0);
assertEngineVersion(bd, 2.0f);
assertWindows(bd);
}
public void testKonquerorLinux() {
// Just ensure detection does not crash
VBrowserDetails bd = new VBrowserDetails(KONQUEROR_LINUX);
assertLinux(bd);
}
public void testFirefox36b() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX36B_MAC);
assertGecko(bd);
assertFirefox(bd);
assertBrowserMajorVersion(bd, 3);
assertBrowserMinorVersion(bd, 6);
assertEngineVersion(bd, 1.9f);
assertMacOSX(bd);
}
public void testOpera964() {
VBrowserDetails bd = new VBrowserDetails(OPERA964_WINDOWS);
assertPresto(bd);
assertOpera(bd);
assertBrowserMajorVersion(bd, 9);
assertBrowserMinorVersion(bd, 64);
assertWindows(bd);
}
public void testOpera1010() {
VBrowserDetails bd = new VBrowserDetails(OPERA1010_WINDOWS);
assertPresto(bd);
assertOpera(bd);
assertBrowserMajorVersion(bd, 10);
assertBrowserMinorVersion(bd, 10);
assertWindows(bd);
}
public void testOpera1050() {
VBrowserDetails bd = new VBrowserDetails(OPERA1050_WINDOWS);
assertPresto(bd);
assertOpera(bd);
assertBrowserMajorVersion(bd, 10);
assertBrowserMinorVersion(bd, 50);
assertWindows(bd);
}
public void testIE6() {
VBrowserDetails bd = new VBrowserDetails(IE6_WINDOWS);
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 6);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
public void testIE7() {
VBrowserDetails bd = new VBrowserDetails(IE7_WINDOWS);
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 7);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
public void testIE8() {
VBrowserDetails bd = new VBrowserDetails(IE8_WINDOWS);
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 8);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
public void testIE8CompatibilityMode() {
VBrowserDetails bd = new VBrowserDetails(IE8_IN_IE7_MODE_WINDOWS);
bd.setIEMode(7);
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 7);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
public void testIE9() {
VBrowserDetails bd = new VBrowserDetails(IE9_BETA_WINDOWS_7);
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 9);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
public void testIE9InIE7CompatibilityMode() {
VBrowserDetails bd = new VBrowserDetails(IE9_BETA_IN_IE7_MODE_WINDOWS_7);
// bd.setIE8InCompatibilityMode();
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 7);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
public void testIE9InIE8CompatibilityMode() {
VBrowserDetails bd = new VBrowserDetails(IE9_BETA_IN_IE8_MODE_WINDOWS_7);
// bd.setIE8InCompatibilityMode();
// assertTrident(bd);
assertIE(bd);
assertBrowserMajorVersion(bd, 8);
assertBrowserMinorVersion(bd, 0);
assertWindows(bd);
}
/*
* Helper methods below
*/
private void assertEngineVersion(VBrowserDetails browserDetails,
float version) {
assertEquals(version, browserDetails.getBrowserEngineVersion());
}
private void assertBrowserMajorVersion(VBrowserDetails browserDetails,
int version) {
assertEquals(version, browserDetails.getBrowserMajorVersion());
}
private void assertBrowserMinorVersion(VBrowserDetails browserDetails,
int version) {
assertEquals(version, browserDetails.getBrowserMinorVersion());
}
private void assertGecko(VBrowserDetails browserDetails) {
// Engine
assertTrue(browserDetails.isGecko());
assertFalse(browserDetails.isWebKit());
assertFalse(browserDetails.isPresto());
}
private void assertPresto(VBrowserDetails browserDetails) {
// Engine
assertFalse(browserDetails.isGecko());
assertFalse(browserDetails.isWebKit());
assertTrue(browserDetails.isPresto());
}
private void assertWebKit(VBrowserDetails browserDetails) {
// Engine
assertFalse(browserDetails.isGecko());
assertTrue(browserDetails.isWebKit());
assertFalse(browserDetails.isPresto());
}
private void assertFirefox(VBrowserDetails browserDetails) {
// Browser
assertTrue(browserDetails.isFirefox());
assertFalse(browserDetails.isChrome());
assertFalse(browserDetails.isIE());
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
}
private void assertChrome(VBrowserDetails browserDetails) {
// Browser
assertFalse(browserDetails.isFirefox());
assertTrue(browserDetails.isChrome());
assertFalse(browserDetails.isIE());
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
}
private void assertIE(VBrowserDetails browserDetails) {
// Browser
assertFalse(browserDetails.isFirefox());
assertFalse(browserDetails.isChrome());
assertTrue(browserDetails.isIE());
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
}
private void assertOpera(VBrowserDetails browserDetails) {
// Browser
assertFalse(browserDetails.isFirefox());
assertFalse(browserDetails.isChrome());
assertFalse(browserDetails.isIE());
assertTrue(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
}
private void assertSafari(VBrowserDetails browserDetails) {
// Browser
assertFalse(browserDetails.isFirefox());
assertFalse(browserDetails.isChrome());
assertFalse(browserDetails.isIE());
assertFalse(browserDetails.isOpera());
assertTrue(browserDetails.isSafari());
}
private void assertMacOSX(VBrowserDetails browserDetails) {
assertFalse(browserDetails.isLinux());
assertFalse(browserDetails.isWindows());
assertTrue(browserDetails.isMacOSX());
assertFalse(browserDetails.isAndroid());
}
private void assertAndroid(VBrowserDetails browserDetails,
int majorVersion, int minorVersion) {
assertFalse(browserDetails.isLinux());
assertFalse(browserDetails.isWindows());
assertFalse(browserDetails.isMacOSX());
assertFalse(browserDetails.isIOS());
assertTrue(browserDetails.isAndroid());
assertOSMajorVersion(browserDetails, majorVersion);
assertOSMinorVersion(browserDetails, minorVersion);
}
private void assertIOS(VBrowserDetails browserDetails, int majorVersion,
int minorVersion) {
assertFalse(browserDetails.isLinux());
assertFalse(browserDetails.isWindows());
assertFalse(browserDetails.isMacOSX());
assertTrue(browserDetails.isIOS());
assertFalse(browserDetails.isAndroid());
assertOSMajorVersion(browserDetails, majorVersion);
assertOSMinorVersion(browserDetails, minorVersion);
}
private void assertWindows(VBrowserDetails browserDetails) {
assertFalse(browserDetails.isLinux());
assertTrue(browserDetails.isWindows());
assertFalse(browserDetails.isMacOSX());
assertFalse(browserDetails.isIOS());
assertFalse(browserDetails.isAndroid());
}
private void assertLinux(VBrowserDetails browserDetails) {
assertTrue(browserDetails.isLinux());
assertFalse(browserDetails.isWindows());
assertFalse(browserDetails.isMacOSX());
assertFalse(browserDetails.isIOS());
assertFalse(browserDetails.isAndroid());
}
}
|