View Javadoc

    1   package org.apache.turbine.util;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "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 static org.junit.Assert.assertEquals;
    23
    24  import org.apache.turbine.test.BaseTestCase;
    25  import org.junit.Test;
    26
    27  /**
    28   * Testing of the BrowserDetector class.
    29   *
    30   * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
    31   * @version $Id$
    32   */
    33  public class BrowserDetectorTest extends BaseTestCase
    34  {
    35
    36
    37      @Test public void testFirefox()
    38      {
    39          String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5";
    40          BrowserDetector bd = new BrowserDetector(userAgent);
    41          assertEquals(BrowserDetector.MOZILLA, bd.getBrowserName());
    42          // Should this really be 5?
    43          assertEquals(5f, bd.getBrowserVersion(), 0.0f);
    44          assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
    45      }
    46
    47      @Test public void testOpera()
    48      {
    49          String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02";
    50          BrowserDetector bd = new BrowserDetector(userAgent);
    51          assertEquals(BrowserDetector.OPERA, bd.getBrowserName());
    52          assertEquals(8.02f, bd.getBrowserVersion(), 0.0f);
    53          assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
    54
    55          userAgent = "Opera/7.51 (Windows NT 5.1; U) [en]";
    56          bd = new BrowserDetector(userAgent);
    57          assertEquals(BrowserDetector.OPERA, bd.getBrowserName());
    58          assertEquals(7.51f, bd.getBrowserVersion(), 0.0f);
    59          assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
    60      }
    61
    62      @Test public void testIE()
    63      {
    64          String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    65          BrowserDetector bd = new BrowserDetector(userAgent);
    66          assertEquals(BrowserDetector.MSIE, bd.getBrowserName());
    67          assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
    68          assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
    69
    70          userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
    71          bd = new BrowserDetector(userAgent);
    72          assertEquals(BrowserDetector.MSIE, bd.getBrowserName());
    73          assertEquals(6.0f, bd.getBrowserVersion(), 0.0f);
    74          assertEquals(BrowserDetector.WINDOWS, bd.getBrowserPlatform());
    75      }
    76  }