View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.context;
21  
22  
23  import org.apache.myfaces.tobago.util.Parameterized;
24  import org.junit.Assert;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  
28  import java.util.Arrays;
29  import java.util.List;
30  
31  @RunWith(Parameterized.class)
32  public class UserAgentUnitTest {
33  
34    private UserAgent agent;
35    private String headerString;
36  
37    public UserAgentUnitTest(String title, UserAgent agent, String headerString) {
38      this.agent = agent;
39      this.headerString = headerString;
40    }
41  
42    @Test
43    public void test() {
44      Assert.assertEquals(agent, UserAgent.getInstance(headerString));
45    }
46  
47    @Parameterized.Parameters
48    public static List<Object[]> data() {
49      return Arrays.asList(new Object[][]{
50  
51          {"Internet Explorer 6 - Windows 2000",
52              UserAgent.MSIE_6_0,
53              "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0"},
54  
55          {"Internet Explorer 6 - Windows XP",
56              UserAgent.MSIE_6_0,
57              "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'"},
58  
59          {"Internet Explorer 7 - Windows XP",
60              UserAgent.MSIE_7_0,
61              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"},
62  
63          {"Internet Explorer 8 - Windows XP",
64              UserAgent.MSIE_8_0,
65              "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727;"
66              + " .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"},
67  
68          {"Internet Explorer 8 - Compatibility Mode - Windows XP",
69              UserAgent.MSIE_7_0_COMPAT,
70              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0)"},
71  
72          {"Internet Explorer 9 preview - Windows 7",
73              UserAgent.MSIE_9_0,
74              "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"},
75  
76          {"Internet Explorer 9 - Windows 7",
77              UserAgent.MSIE_9_0,
78              "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"},
79  
80          {"Internet Explorer 9 - Compatibility Mode - Windows 7",
81              UserAgent.MSIE_7_0_COMPAT,
82              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/5.0; "
83                  + ".NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"},
84  
85          {"Internet Explorer 10 - Windows 8 - Developer Preview",
86              UserAgent.MSIE_10_0,
87              "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"},
88  
89          {"Internet Explorer 10 - Compatibility Mode - Windows 8 - Developer Preview",
90              UserAgent.MSIE_7_0_COMPAT,
91              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C)"},
92  
93          {"Firefox 3.6 - Ubuntu 10.4",
94              UserAgent.GECKO_1_9,
95              "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100308 Ubuntu/10.04 (lucid) Firefox/3.6"},
96  
97          {"Firefox 3.6 - Ubuntu 9.10",
98              UserAgent.GECKO_1_9,
99              "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3pre) Gecko/20100328 Ubuntu/9.10 (karmic) "
100                 + "Namoroka/3.6.3pre"},
101 
102         {"Firefox 23.0 - Mac OS X Mountain Lion",
103             UserAgent.GECKO_23_0,
104             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0"},
105 
106         {"Firefox 5.0 - Mac OS X Snow Leopard",
107             UserAgent.GECKO_2_0,
108             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0"},
109 
110         {"Firefox 4.0 beta 2 - Mac OS X Snow Leopard",
111             UserAgent.GECKO_2_0,
112             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b2) Gecko/20100720 Firefox/4.0b2"},
113 
114         {"Firefox 3.6 - Mac OS X Snow Leopard",
115             UserAgent.GECKO_1_9,
116             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"},
117 
118         {"Firefox 3.5 - Mac OS X Snow Leopard",
119             UserAgent.GECKO_1_9,
120             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9"},
121 
122         {"Firefox 3.0 - Mac OS X Snow Leopard",
123             UserAgent.GECKO_1_9,
124             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.0.19) Gecko/2010031218 Firefox/3.0.19"},
125 
126         {"Firefox 2.0 - Mac OS X Snow Leopard",
127             UserAgent.GECKO_1_8,
128             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20"},
129 
130         {"Opera 10.61 - Windows 7",
131             UserAgent.PRESTO,
132             "Opera/9.80 (Windows NT 6.1; U; de) Presto/2.6.30 Version/10.61"},
133 
134         {"Opera 10.10 - Mac OS X Snow Leopard",
135             UserAgent.PRESTO,
136             "Opera/9.80 (Macintosh; Intel Mac OS X; U; de) Presto/2.2.15 Version/10.10"},
137 
138         {"Opera 10.51 - Ubuntu 9.10",
139             UserAgent.PRESTO,
140             "Opera/9.80 (X11; Linux i686; U; en) Presto/2.5.22 Version/10.51"},
141 
142         {"Chrome 4.1 - Windows 7",
143             UserAgent.WEBKIT,
144             "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko)"
145             + " Chrome/4.1.249.1042 Safari/532.5"},
146 
147         {"Chrome 5 - Mac OS X Snow Leopard",
148             UserAgent.WEBKIT,
149             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko)"
150             + " Chrome/5.0.375.127 Safari/533.4"},
151 
152         {"Chrome 5 - Ubuntu 9.10",
153             UserAgent.WEBKIT,
154             "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.3 (KHTML, like Gecko)"
155             + " Chrome/5.0.360.0 Safari/533.3"},
156 
157         {"Chromium 5 - Ubuntu 9.10",
158             UserAgent.WEBKIT,
159             "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.3 (KHTML, like Gecko)"
160             + " Chrome/5.0.365.0 Safari/533.3"},
161 
162         {"Safari 5 - Mac OS X Snow Leopard",
163             UserAgent.WEBKIT,
164             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; de-de) AppleWebKit/533.17.8 (KHTML, like Gecko) "
165             + "Version/5.0.1 Safari/533.17.8"},
166 
167         {"Safari 4 - Mac OS X Snow Leopard",
168             UserAgent.WEBKIT,
169             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-de) AppleWebKit/531.22.7 (KHTML, like Gecko) "
170             + "Version/4.0.5 Safari/531.22.7"},
171 
172         {"Safari 4 - iPad",
173             UserAgent.WEBKIT,
174             "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; de-de) AppleWebKit/531.21.10 (KHTML, like Gecko) "
175                 + "Version/4.0.4 Mobile/7B405 Safari/531.21.10"},
176 
177         {"Web-Browser for S60 - Symbian - Nokia E51",
178             UserAgent.WEBKIT,
179             "Mozilla/5.0 "
180                 + "(SymbianOS/9.2; U; Series60/3.1 NokiaE51-1/300.34.56; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) "
181                 + "AppleWebKit/413 (KHTML, like Gecko) Safari/413"},
182     });
183   }
184 }