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  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.params.ParameterizedTest;
24  import org.junit.jupiter.params.provider.Arguments;
25  import org.junit.jupiter.params.provider.MethodSource;
26  
27  import java.util.stream.Stream;
28  
29  public class UserAgentUnitTest {
30  
31    @ParameterizedTest
32    @MethodSource("data")
33    public void test(final String title, final UserAgent agent, final String headerString) {
34      Assertions.assertEquals(agent, UserAgent.getInstance(headerString));
35    }
36  
37    public static Stream<Arguments> data() {
38      return Stream.of(
39          Arguments.of("Internet Explorer 6 - Windows 2000",
40              UserAgent.MSIE_6_0,
41              "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0"),
42  
43          Arguments.of("Internet Explorer 6 - Windows XP",
44              UserAgent.MSIE_6_0,
45              "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'"),
46  
47          Arguments.of("Internet Explorer 7 - Windows XP",
48              UserAgent.MSIE_7_0,
49              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"),
50  
51          Arguments.of("Internet Explorer 8 - Windows XP",
52              UserAgent.MSIE_8_0,
53              "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727;"
54                  + " .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"),
55  
56          Arguments.of("Internet Explorer 8 - Compatibility Mode - Windows XP",
57              UserAgent.MSIE_7_0_COMPAT,
58              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0)"),
59  
60          Arguments.of("Internet Explorer 9 preview - Windows 7",
61              UserAgent.MSIE_9_0,
62              "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"),
63  
64          Arguments.of("Internet Explorer 9 - Windows 7",
65              UserAgent.MSIE_9_0,
66              "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"),
67  
68          Arguments.of("Internet Explorer 9 - Compatibility Mode - Windows 7",
69              UserAgent.MSIE_7_0_COMPAT,
70              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/5.0; "
71                  + ".NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"),
72  
73          Arguments.of("Internet Explorer 10 - Windows 8 - Developer Preview",
74              UserAgent.MSIE_10_0,
75              "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"),
76  
77          Arguments.of("Internet Explorer 10 - Compatibility Mode - Windows 8 - Developer Preview",
78              UserAgent.MSIE_7_0_COMPAT,
79              "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C)"),
80  
81          Arguments.of("Internet Explorer 11 - Windows 7",
82              UserAgent.MSIE_11_0,
83              "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; "
84                  + ".NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; "
85                  + ".NET4.0C; .NET4.0E; rv:11.0) like Gecko"),
86  
87          Arguments.of("Firefox 3.6 - Ubuntu 10.4",
88              UserAgent.GECKO_1_9,
89              "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100308 Ubuntu/10.04 (lucid) Firefox/3.6"),
90  
91          Arguments.of("Firefox 3.6 - Ubuntu 9.10",
92              UserAgent.GECKO_1_9,
93              "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3pre) Gecko/20100328 Ubuntu/9.10 (karmic) "
94                  + "Namoroka/3.6.3pre"),
95  
96          Arguments.of("Firefox 23.0 - Mac OS X Mountain Lion",
97              UserAgent.GECKO_23_0,
98              "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0"),
99  
100         Arguments.of("Firefox 5.0 - Mac OS X Snow Leopard",
101             UserAgent.GECKO_2_0,
102             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0"),
103 
104         Arguments.of("Firefox 4.0 beta 2 - Mac OS X Snow Leopard",
105             UserAgent.GECKO_2_0,
106             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b2) Gecko/20100720 Firefox/4.0b2"),
107 
108         Arguments.of("Firefox 3.6 - Mac OS X Snow Leopard",
109             UserAgent.GECKO_1_9,
110             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"),
111 
112         Arguments.of("Firefox 3.5 - Mac OS X Snow Leopard",
113             UserAgent.GECKO_1_9,
114             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9"),
115 
116         Arguments.of("Firefox 3.0 - Mac OS X Snow Leopard",
117             UserAgent.GECKO_1_9,
118             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.0.19) Gecko/2010031218 Firefox/3.0.19"),
119 
120         Arguments.of("Firefox 2.0 - Mac OS X Snow Leopard",
121             UserAgent.GECKO_1_8,
122             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20"),
123 
124         Arguments.of("Opera 10.61 - Windows 7",
125             UserAgent.PRESTO,
126             "Opera/9.80 (Windows NT 6.1; U; de) Presto/2.6.30 Version/10.61"),
127 
128         Arguments.of("Opera 10.10 - Mac OS X Snow Leopard",
129             UserAgent.PRESTO,
130             "Opera/9.80 (Macintosh; Intel Mac OS X; U; de) Presto/2.2.15 Version/10.10"),
131 
132         Arguments.of("Opera 10.51 - Ubuntu 9.10",
133             UserAgent.PRESTO,
134             "Opera/9.80 (X11; Linux i686; U; en) Presto/2.5.22 Version/10.51"),
135 
136         Arguments.of("Chrome 4.1 - Windows 7",
137             UserAgent.WEBKIT,
138             "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko)"
139                 + " Chrome/4.1.249.1042 Safari/532.5"),
140 
141         Arguments.of("Chrome 5 - Mac OS X Snow Leopard",
142             UserAgent.WEBKIT,
143             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko)"
144                 + " Chrome/5.0.375.127 Safari/533.4"),
145 
146         Arguments.of("Chrome 5 - Ubuntu 9.10",
147             UserAgent.WEBKIT,
148             "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.3 (KHTML, like Gecko)"
149                 + " Chrome/5.0.360.0 Safari/533.3"),
150 
151         Arguments.of("Chromium 5 - Ubuntu 9.10",
152             UserAgent.WEBKIT,
153             "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.3 (KHTML, like Gecko)"
154                 + " Chrome/5.0.365.0 Safari/533.3"),
155 
156         Arguments.of("Safari 5 - Mac OS X Snow Leopard",
157             UserAgent.WEBKIT,
158             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; de-de) AppleWebKit/533.17.8 (KHTML, like Gecko) "
159                 + "Version/5.0.1 Safari/533.17.8"),
160 
161         Arguments.of("Safari 4 - Mac OS X Snow Leopard",
162             UserAgent.WEBKIT,
163             "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-de) AppleWebKit/531.22.7 (KHTML, like Gecko) "
164                 + "Version/4.0.5 Safari/531.22.7"),
165 
166         Arguments.of("Safari 4 - iPad",
167             UserAgent.WEBKIT,
168             "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; de-de) AppleWebKit/531.21.10 (KHTML, like Gecko) "
169                 + "Version/4.0.4 Mobile/7B405 Safari/531.21.10"),
170 
171         Arguments.of("Web-Browser for S60 - Symbian - Nokia E51",
172             UserAgent.WEBKIT,
173             "Mozilla/5.0 "
174                 + "(SymbianOS/9.2; U; Series60/3.1 NokiaE51-1/300.34.56; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) "
175                 + "AppleWebKit/413 (KHTML, like Gecko) Safari/413")
176     );
177   }
178 }