001package 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 022import static org.junit.Assert.assertEquals; 023 024import org.apache.turbine.test.BaseTestCase; 025import org.junit.Test; 026 027/** 028 * Testing of the BrowserDetector class. 029 * 030 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a> 031 * @version $Id$ 032 */ 033public class BrowserDetectorTest extends BaseTestCase 034{ 035 036 037 @Test 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("Firefox", bd.getBrowserName()); 042 assertEquals(1.5f, bd.getBrowserVersion(), 0.0f); 043 assertEquals("Windows", bd.getBrowserPlatform()); 044 } 045 046 @Test public void testOpera() 047 { 048 String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.02"; 049 BrowserDetector bd = new BrowserDetector(userAgent); 050 assertEquals("Opera", bd.getBrowserName()); 051 assertEquals(8.02f, bd.getBrowserVersion(), 0.0f); 052 assertEquals("Windows", bd.getBrowserPlatform()); 053 054 userAgent = "Opera/7.51 (Windows NT 5.1; U) [en]"; 055 bd = new BrowserDetector(userAgent); 056 assertEquals("Opera", bd.getBrowserName()); 057 assertEquals(7.51f, bd.getBrowserVersion(), 0.0f); 058 assertEquals("Windows", bd.getBrowserPlatform()); 059 } 060 061 @Test public void testIE() 062 { 063 String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; 064 BrowserDetector bd = new BrowserDetector(userAgent); 065 assertEquals("IE", bd.getBrowserName()); 066 assertEquals(6.0f, bd.getBrowserVersion(), 0.0f); 067 assertEquals("Windows", bd.getBrowserPlatform()); 068 069 userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"; 070 bd = new BrowserDetector(userAgent); 071 assertEquals("IE", bd.getBrowserName()); 072 assertEquals(6.0f, bd.getBrowserVersion(), 0.0f); 073 assertEquals("Windows", bd.getBrowserPlatform()); 074 } 075}