001    package org.apache.turbine.util;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.turbine.test.BaseTestCase;
023    
024    /**
025     * Testing of the BrowserDetector class.
026     *
027     * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
028     * @version $Id$
029     */
030    public class BrowserDetectorTest extends BaseTestCase
031    {
032        public BrowserDetectorTest(String name) throws Exception
033        {
034            super(name);
035        }
036    
037        public void testFirefox()
038        {
039            String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5";
040            BrowserDetector bd = new BrowserDetector(userAgent);
041            assertEquals(BrowserDetector.MOZILLA, bd.getBrowserName());
042            // Should this really be 5?
043            assertEquals(5f, bd.getBrowserVersion(), 0.0f);
044            assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
045        }
046    
047        public void testOpera()
048        {
049            String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02";
050            BrowserDetector bd = new BrowserDetector(userAgent);
051            assertEquals(BrowserDetector.OPERA, bd.getBrowserName());
052            assertEquals(8.02f, bd.getBrowserVersion(), 0.0f);
053            assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
054    
055            userAgent = "Opera/7.51 (Windows NT 5.1; U) [en]";
056            bd = new BrowserDetector(userAgent);
057            assertEquals(BrowserDetector.OPERA, bd.getBrowserName());
058            assertEquals(7.51f, bd.getBrowserVersion(), 0.0f);
059            assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
060        }
061    
062        public void testIE()
063        {
064            String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
065            BrowserDetector bd = new BrowserDetector(userAgent);
066            assertEquals(BrowserDetector.MSIE, bd.getBrowserName());
067            assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
068            assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
069    
070            userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
071            bd = new BrowserDetector(userAgent);
072            assertEquals(BrowserDetector.MSIE, bd.getBrowserName());
073            assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
074            assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
075        }
076    }