KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > web > BrowserTest


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit.web;
14
15 import junit.framework.TestCase;
16
17
18 /**
19  * Test for Browser, parsing query strings for different browsers
20  *
21  * @author Eric Galluzzo
22  */

23 public class BrowserTest extends TestCase
24 {
25     public BrowserTest(String JavaDoc inName)
26     {
27         super(inName);
28     }
29
30
31     /**
32          *
33          */

34     public void testGaleonLinux()
35     {
36         Browser browser = new Browser(
37                 "Mozilla/5.0 Galeon/1.2.0 (X11; Linux i686; U;) Gecko/20020408");
38         assertEquals(Browser.MOZILLA_BROWSER, browser.getBrowserType());
39         assertEquals(Browser.UNIX_PLATFORM, browser.getPlatformType());
40         assertEquals("1.0.0", browser.getVersion());
41         assertEquals("1", browser.getMajorVersion());
42         assertEquals("0", browser.getMinorVersion());
43     }
44
45     /**
46          *
47          */

48     public void testLynxLinux()
49     {
50         Browser browser = new Browser("Lynx/2.8.5dev.3 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6c");
51         assertEquals(Browser.LYNX_BROWSER, browser.getBrowserType());
52         assertEquals(Browser.UNKNOWN_PLATFORM, browser.getPlatformType());
53         assertEquals("2.8.5dev.3", browser.getVersion());
54         assertEquals("2", browser.getMajorVersion());
55         assertEquals("8", browser.getMinorVersion());
56     }
57
58     /**
59          *
60          */

61     public void testMSIEMacOS9()
62     {
63         Browser browser = new Browser("Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)");
64         assertEquals(Browser.MSIE_BROWSER, browser.getBrowserType());
65         assertEquals(Browser.MAC_PLATFORM, browser.getPlatformType());
66         assertEquals("5.0", browser.getVersion());
67         assertEquals("5", browser.getMajorVersion());
68         assertEquals("0", browser.getMinorVersion());
69     }
70
71     /**
72          *
73          */

74     public void testMSIEMacOSX()
75     {
76         Browser browser = new Browser("Mozilla/4.0 (compatible; MSIE 5.14; Mac_PowerPC)");
77         assertEquals(Browser.MSIE_BROWSER, browser.getBrowserType());
78         assertEquals(Browser.MAC_PLATFORM, browser.getPlatformType());
79         assertEquals("5.14", browser.getVersion());
80         assertEquals("5", browser.getMajorVersion());
81         assertEquals("14", browser.getMinorVersion());
82     }
83
84     /**
85          *
86          */

87     public void testMSIEWinNT()
88     {
89         Browser browser = new Browser("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
90         assertEquals(Browser.MSIE_BROWSER, browser.getBrowserType());
91         assertEquals(Browser.WINDOWS_PLATFORM, browser.getPlatformType());
92         assertEquals("5.5", browser.getVersion());
93         assertEquals("5", browser.getMajorVersion());
94         assertEquals("5", browser.getMinorVersion());
95     }
96
97     /**
98          *
99          */

100     public void testMozillaLinux()
101     {
102         Browser browser = new Browser(
103                 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1b) Gecko/20020722");
104         assertEquals(Browser.MOZILLA_BROWSER, browser.getBrowserType());
105         assertEquals(Browser.UNIX_PLATFORM, browser.getPlatformType());
106         assertEquals("1.1b", browser.getVersion());
107         assertEquals("1", browser.getMajorVersion());
108         assertEquals("1b", browser.getMinorVersion());
109     }
110
111     /**
112          *
113          */

114     public void testMozillaMacOSX()
115     {
116         Browser browser = new Browser(
117                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.0) Gecko/20020529");
118         assertEquals(Browser.MOZILLA_BROWSER, browser.getBrowserType());
119         assertEquals(Browser.MAC_PLATFORM, browser.getPlatformType());
120         assertEquals("1.0.0", browser.getVersion());
121         assertEquals("1", browser.getMajorVersion());
122         assertEquals("0", browser.getMinorVersion());
123     }
124
125     /**
126          *
127          */

128     public void testMozillaWinNT()
129     {
130         Browser browser = new Browser(
131                 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.0) Gecko/20020530");
132         assertEquals(Browser.MOZILLA_BROWSER, browser.getBrowserType());
133         assertEquals(Browser.WINDOWS_PLATFORM, browser.getPlatformType());
134         assertEquals("1.0.0", browser.getVersion());
135         assertEquals("1", browser.getMajorVersion());
136         assertEquals("0", browser.getMinorVersion());
137     }
138
139     /**
140          *
141          */

142     public void testNetscape4OS9()
143     {
144         Browser browser = new Browser(
145                 "Mozilla/4.75C-CCK-MCD {C-UDP; EBM-APPLE} (Macintosh; U; PPC)");
146         assertEquals(Browser.NETSCAPE_BROWSER, browser.getBrowserType());
147         assertEquals(Browser.MAC_PLATFORM, browser.getPlatformType());
148         assertEquals("4.75C-CCK-MCD", browser.getVersion());
149         assertEquals("4", browser.getMajorVersion());
150         assertEquals("75C-CCK-MCD", browser.getMinorVersion());
151     }
152
153     /*
154        public void testMSIEMac()
155        {
156        }
157      */

158     public void testNetscape4WinNT()
159     {
160         Browser browser = new Browser("Mozilla/4.77 [en] (Windows NT 5.0; U)");
161         assertEquals(Browser.NETSCAPE_BROWSER, browser.getBrowserType());
162         assertEquals(Browser.WINDOWS_PLATFORM, browser.getPlatformType());
163         assertEquals("4.77", browser.getVersion());
164         assertEquals("4", browser.getMajorVersion());
165         assertEquals("77", browser.getMinorVersion());
166     }
167 }
168
Popular Tags