01: package org.apache.turbine.util;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import org.apache.turbine.test.BaseTestCase;
23:
24: /**
25: * Testing of the BrowserDetector class.
26: *
27: * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
28: * @version $Id$
29: */
30: public class BrowserDetectorTest extends BaseTestCase {
31: public BrowserDetectorTest(String name) throws Exception {
32: super (name);
33: }
34:
35: public void testFirefox() {
36: String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5";
37: BrowserDetector bd = new BrowserDetector(userAgent);
38: assertEquals(BrowserDetector.MOZILLA, bd.getBrowserName());
39: // Should this really be 5?
40: assertEquals(5f, bd.getBrowserVersion(), 0.0f);
41: assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
42: }
43:
44: public void testOpera() {
45: String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02";
46: BrowserDetector bd = new BrowserDetector(userAgent);
47: assertEquals(BrowserDetector.OPERA, bd.getBrowserName());
48: assertEquals(8.02f, bd.getBrowserVersion(), 0.0f);
49: assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
50:
51: userAgent = "Opera/7.51 (Windows NT 5.1; U) [en]";
52: bd = new BrowserDetector(userAgent);
53: assertEquals(BrowserDetector.OPERA, bd.getBrowserName());
54: assertEquals(7.51f, bd.getBrowserVersion(), 0.0f);
55: assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
56: }
57:
58: public void testIE() {
59: String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
60: BrowserDetector bd = new BrowserDetector(userAgent);
61: assertEquals(BrowserDetector.MSIE, bd.getBrowserName());
62: assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
63: assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
64:
65: userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
66: bd = new BrowserDetector(userAgent);
67: assertEquals(BrowserDetector.MSIE, bd.getBrowserName());
68: assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
69: assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
70: }
71: }
|