Author: mgrigorov Date: Sat May 7 16:42:16 2011 New Revision: 1100566 URL: http://svn.apache.org/viewvc?rev=1100566&view=rev Log: WICKET-3679 Improve WebClientInfo logic to extract the exact browser version
Added: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java Modified: wicket/trunk/pom.xml wicket/trunk/wicket-core/pom.xml wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java Modified: wicket/trunk/pom.xml URL: http://svn.apache.org/viewvc/wicket/trunk/pom.xml?rev=1100566&r1=1100565&r2=1100566&view=diff ============================================================================== --- wicket/trunk/pom.xml (original) +++ wicket/trunk/pom.xml Sat May 7 16:42:16 2011 @@ -348,6 +348,18 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>1.2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + <version>1.2.1</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.8.5</version> Modified: wicket/trunk/wicket-core/pom.xml URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/pom.xml?rev=1100566&r1=1100565&r2=1100566&view=diff ============================================================================== --- wicket/trunk/wicket-core/pom.xml (original) +++ wicket/trunk/wicket-core/pom.xml Sat May 7 16:42:16 2011 @@ -57,6 +57,16 @@ <artifactId>mockito-all</artifactId> <scope>provided</scope> <!-- provided because of the -test jar we build? --> </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + <scope>provided</scope> + </dependency> </dependencies> <build> <plugins> Added: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java?rev=1100566&view=auto ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java (added) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java Sat May 7 16:42:16 2011 @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.protocol.http.request; + +import java.util.Arrays; +import java.util.List; + +import org.apache.wicket.util.string.Strings; + +/** + * UserAgent + */ +enum UserAgent { + + MOZILLA("Opera,AppleWebKit,Konqueror", Arrays.asList("Mozilla", "Gecko")), + + FIREFOX("Opera,AppleWebKit,Konqueror", Arrays.asList("Mozilla", "Gecko", "Firefox")), + + INTERNET_EXPLORER("Opera", Arrays.asList("Mozilla", "MSIE", "Windows"), Arrays.asList( + "Mozilla", "MSIE", "Trident"), Arrays.asList("Mozilla", "MSIE", "Mac_PowerPC")), + + OPERA(Arrays.asList("Opera")), + + CHROME(Arrays.asList("Mozilla", "Chrome", "AppleWebKit", "Safari")), + + SAFARI("Chrome", Arrays.asList("Mozilla", "AppleWebKit", "Safari")), + + KONQUEROR(Arrays.asList("Konqueror")); + + /** + * Comma separated list with values which are not allowed in the user agent. + */ + private final String notAllowed; + + /** + * A list with strings which has to be in the user agent string. + */ + private final List<String>[] detectionStrings; + + /** + * Construct. + * + * @param notAllowed + * comma separated list with values which are not allowed in the user agent + * @param detectionStrings + * a list with strings which has to be in the user agent string + */ + UserAgent(String notAllowed, List<String>... detectionStrings) + { + this.notAllowed = notAllowed; + this.detectionStrings = detectionStrings; + } + + /** + * Construct. + * + * @param detectionStrings + * list with string which has to be in the user agent string + */ + UserAgent(List<String>... detectionStrings) + { + this(null, detectionStrings); + } + + /** + * @param userAgent + * The user agent string + * @return Whether the user agent matches this enum or not + */ + public boolean matches(String userAgent) + { + if (Strings.isEmpty(notAllowed) == false) + { + String[] notAllowedList = Strings.split(notAllowed, ','); + for (String value : notAllowedList) + { + if (userAgent.contains(value)) + { + return false; + } + } + } + + for (List<String> detectionGroup : detectionStrings) + { + for (String detectionString : detectionGroup) + { + if (!userAgent.contains(detectionString)) + { + return false; + } + } + + return true; + } + + return false; + } +} \ No newline at end of file Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java?rev=1100566&r1=1100565&r2=1100566&view=diff ============================================================================== --- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java (original) +++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java Sat May 7 16:42:16 2011 @@ -21,6 +21,7 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; +import org.apache.wicket.markup.html.pages.BrowserInfoPage; import org.apache.wicket.protocol.http.ClientProperties; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; import org.apache.wicket.request.ClientInfo; @@ -38,14 +39,12 @@ public class WebClientInfo extends Clien { private static final long serialVersionUID = 1L; - /** log. */ private static final Logger log = LoggerFactory.getLogger(WebClientInfo.class); /** * The user agent string from the User-Agent header, app. Theoretically, this might differ from - * {@link ClientProperties#isJavaEnabled()} property, which is not set until an actual reply - * from a browser (e.g. using {@link org.apache.wicket.markup.html.pages.BrowserInfoPage} is - * set. + * {@link org.apache.wicket.protocol.http.ClientProperties#isJavaEnabled()} property, which is + * not set until an actual reply from a browser (e.g. using {@link BrowserInfoPage} is set. */ private final String userAgent; @@ -60,12 +59,8 @@ public class WebClientInfo extends Clien */ public WebClientInfo(RequestCycle requestCycle) { - super(); - ServletWebRequest request = (ServletWebRequest)requestCycle.getRequest(); - HttpServletRequest httpServletRequest = request.getContainerRequest(); - userAgent = httpServletRequest.getHeader("User-Agent"); - properties.setRemoteAddress(getRemoteAddr(requestCycle)); - init(); + this(requestCycle, ((ServletWebRequest)requestCycle.getRequest()).getContainerRequest() + .getHeader("User-Agent")); } /** @@ -74,11 +69,12 @@ public class WebClientInfo extends Clien * @param requestCycle * the request cycle * @param userAgent - * the user agent + * The User-Agent string */ - public WebClientInfo(RequestCycle requestCycle, String userAgent) + public WebClientInfo(final RequestCycle requestCycle, final String userAgent) { super(); + this.userAgent = userAgent; properties.setRemoteAddress(getRemoteAddr(requestCycle)); init(); @@ -95,7 +91,7 @@ public class WebClientInfo extends Clien } /** - * Gets the user agent string. + * returns the user agent string. * * @return the user agent string */ @@ -105,6 +101,16 @@ public class WebClientInfo extends Clien } /** + * returns the user agent string (lower case). + * + * @return the user agent string + */ + private String getUserAgentStringLc() + { + return (getUserAgent() != null) ? getUserAgent().toLowerCase() : ""; + } + + /** * When using ProxyPass, requestCycle().getHttpServletRequest(). getRemoteAddr() returns the IP * of the machine forwarding the request. In order to maintain the clients ip address, the * server places it in the <a @@ -145,77 +151,130 @@ public class WebClientInfo extends Clien */ private final void init() { - String userAgent = (getUserAgent() != null) ? getUserAgent().toLowerCase() : ""; - - boolean browserChrome = userAgent.contains("chrome"); - boolean browserOpera = userAgent.contains("opera"); - boolean browserKonqueror = userAgent.contains("konqueror"); - - // Note deceptive user agent fields: - // - Konqueror and Chrome UA fields contain "like Gecko" - // - Opera UA field typically contains "MSIE" - // - Chrome UA field contains "Safari" - boolean deceptiveUserAgent = browserOpera || browserKonqueror || browserChrome; - - boolean browserSafari = !deceptiveUserAgent && userAgent.contains("safari"); - - // -Safari UA fields contain "like Gecko" - deceptiveUserAgent = deceptiveUserAgent || browserSafari; + setInternetExplorerProperties(); + setOperaProperties(); + setMozillaProperties(); + setKonquerorProperties(); + setChromeProperties(); + setSafariProperties(); - boolean browserMozilla = !deceptiveUserAgent && userAgent.contains("gecko"); - boolean browserFireFox = userAgent.contains("firefox"); - boolean browserInternetExplorer = !deceptiveUserAgent && userAgent.contains("msie"); - - int majorVersion = -1, minorVersion = -1; - - // Store browser information. - if (browserOpera) - { - properties.setBrowserOpera(true); - } - else if (browserKonqueror) + if (log.isDebugEnabled()) { - properties.setBrowserKonqueror(true); + log.debug("determined user agent: " + properties); } - else if (browserSafari) + } + + /** + * sets the konqueror specific properties + */ + private void setKonquerorProperties() + { + properties.setBrowserKonqueror(UserAgent.KONQUEROR.matches(getUserAgent())); + + if (properties.isBrowserKonqueror()) { - properties.setBrowserSafari(true); + // e.g.: Mozilla/5.0 (compatible; Konqueror/4.2; Linux) KHTML/4.2.96 (like Gecko) + setMajorMinorVersionByPattern("konqueror/(\\d+)\\.(\\d+)"); } - else if (browserChrome) + } + + /** + * sets the chrome specific properties + */ + private void setChromeProperties() + { + properties.setBrowserChrome(UserAgent.CHROME.matches(getUserAgent())); + + if (properties.isBrowserChrome()) { - properties.setBrowserChrome(true); + // e.g.: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) +// Chrome/12.0.702.0 Safari/534.24 + setMajorMinorVersionByPattern("chrome/(\\d+)\\.(\\d+)"); } - else if (browserMozilla) + } + + /** + * sets the safari specific properties + */ + private void setSafariProperties() + { + properties.setBrowserSafari(UserAgent.SAFARI.matches(getUserAgent())); + + if (properties.isBrowserSafari()) { - properties.setBrowserMozilla(true); - if (browserFireFox) + String userAgent = getUserAgentStringLc(); + + if (userAgent.contains("version/")) { - properties.setBrowserMozillaFirefox(true); + // e.g.: Mozilla/5.0 (Windows; U; Windows NT 6.1; sv-SE) AppleWebKit/533.19.4 +// (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4 + setMajorMinorVersionByPattern("version/(\\d+)\\.(\\d+)"); } } - else if (browserInternetExplorer) + } + + /** + * sets the mozilla/firefox specific properties + */ + private void setMozillaProperties() + { + properties.setBrowserMozillaFirefox(UserAgent.FIREFOX.matches(getUserAgent())); + properties.setBrowserMozilla(UserAgent.MOZILLA.matches(getUserAgent())); + + if (properties.isBrowserMozilla()) { - properties.setBrowserInternetExplorer(true); - Matcher matcher = Pattern.compile("msie (\\d+)").matcher(userAgent); - if (matcher.find()) + properties.setQuirkMozillaTextInputRepaint(true); + properties.setQuirkMozillaPerformanceLargeDomRemove(true); + + if (properties.isBrowserMozillaFirefox()) { - majorVersion = Integer.parseInt(matcher.group(1)); + // e.g.: Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 +// Ubuntu/9.25 (jaunty) Firefox/3.8 + setMajorMinorVersionByPattern("firefox/(\\d+)\\.(\\d+)"); } } + } - if (majorVersion != -1) - { - properties.setBrowserVersionMajor(majorVersion); - } + /** + * sets the opera specific properties + */ + private void setOperaProperties() + { + properties.setBrowserOpera(UserAgent.OPERA.matches(getUserAgent())); - if (minorVersion != -1) + if (properties.isBrowserOpera()) { - properties.setBrowserVersionMinor(minorVersion); + String userAgent = getUserAgentStringLc(); + + if (userAgent.startsWith("opera/") && userAgent.contains("version/")) + { + // e.g.: Opera/9.80 (Windows NT 6.0; U; nl) Presto/2.6.30 Version/10.60 + setMajorMinorVersionByPattern("version/(\\d+)\\.(\\d+)"); + } + else if (userAgent.startsWith("opera/") && !userAgent.contains("version/")) + { + // e.g.: Opera/9.80 (Windows NT 6.0; U; nl) Presto/2.6.30 + setMajorMinorVersionByPattern("opera/(\\d+)\\.(\\d+)"); + } + else + { + // e.g.: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 6.0; tr) Opera 10.10 + setMajorMinorVersionByPattern("opera (\\d+)\\.(\\d+)"); + } } + } + + /** + * sets the ie specific properties + */ + private void setInternetExplorerProperties() + { + properties.setBrowserInternetExplorer(UserAgent.INTERNET_EXPLORER.matches(getUserAgent())); - // Set quirk flags. - if (browserInternetExplorer) + if (properties.isBrowserInternetExplorer()) { + setMajorMinorVersionByPattern("msie (\\d+)\\.(\\d+)"); + properties.setProprietaryIECssExpressionsSupported(true); properties.setQuirkCssPositioningOneSideOnly(true); properties.setQuirkIERepaint(true); @@ -227,20 +286,29 @@ public class WebClientInfo extends Clien properties.setQuirkCssBackgroundAttachmentUseFixed(true); properties.setQuirkCssBorderCollapseInside(true); properties.setQuirkCssBorderCollapseFor0Padding(true); - if (majorVersion < 7) + + if (properties.getBrowserVersionMajor() < 7) { properties.setProprietaryIEPngAlphaFilterRequired(true); } } - if (browserMozilla) - { - properties.setQuirkMozillaTextInputRepaint(true); - properties.setQuirkMozillaPerformanceLargeDomRemove(true); - } + } - if (log.isDebugEnabled()) + /** + * extracts the major and minor version out of the userAgentString string. + * + * @param patternString + * The pattern must contain two matching groups + */ + private void setMajorMinorVersionByPattern(String patternString) + { + String userAgent = getUserAgentStringLc(); + Matcher matcher = Pattern.compile(patternString).matcher(userAgent); + + if (matcher.find()) { - log.debug("determined user agent: " + properties); + properties.setBrowserVersionMajor(Integer.parseInt(matcher.group(1))); + properties.setBrowserVersionMinor(Integer.parseInt(matcher.group(2))); } } } Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java?rev=1100566&view=auto ============================================================================== --- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java (added) +++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java Sat May 7 16:42:16 2011 @@ -0,0 +1,732 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.protocol.http.request; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Arrays; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.wicket.protocol.http.servlet.ServletWebRequest; +import org.apache.wicket.request.cycle.RequestCycle; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests the WebClientInfo class + */ +public class WebClientInfoTest +{ + private RequestCycle requestCycleMock; + + /** + * Prepare RequestCycle to be able to extract the remote address of the client + */ + @Before + public void before() + { + requestCycleMock = mock(RequestCycle.class); + + ServletWebRequest webRequest = mock(ServletWebRequest.class); + when(requestCycleMock.getRequest()).thenReturn(webRequest); + + HttpServletRequest servletRequest = mock(HttpServletRequest.class); + when(webRequest.getContainerRequest()).thenReturn(servletRequest); + } + + /** + * Test IE 6.x user-agent strings + */ + @Test + public void internetExplorer6() + { + List<String> userAgents = Arrays.asList( + "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", + "Mozilla/4.0 (compatible; MSIE 6.01; Windows NT 6.0)", + "Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", + "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)", + "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.2; WOW64; .NET CLR 2.0.50727)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(6))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + } + } + + /** + * Test IE 7.x user-agent strings + */ + @Test + public void internetExplorer7() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; c .NET CLR 3.0.04506; .NET CLR 3.5.30707; InfoPath.1; el-GR)", + "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)", + "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)", + "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; YPC 3.2.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618)", + "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; .NET CLR 2.0.50727)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(7))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + } + } + + /** + * Test IE 8.x user-agent strings + */ + @Test + public void internetExplorer8() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)", + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8)", + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; .NET4.0C; .NET4.0E; Zune 4.7)", + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; Media Center PC 6.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C)", + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; MS-RTC LM 8; Zune 4.7)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(8))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + } + } + + /** + * Test IE 9.x user-agent strings + */ + @Test + public void internetExplorer9() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))", + "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7)", + "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)", + "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.0; YPC 3.2.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618)", + "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(9))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + } + } + + /** + * Test Opera 9.64 user-agent strings + */ + @Test + public void opera964() + { + List<String> userAgents = Arrays.asList( + "Opera/9.64 (Windows NT 6.1; U; MRA 5.5 (build 02842); ru) Presto/2.1.1", + "Opera/9.64 (X11; Linux i686; U; Linux Mint; it) Presto/2.1.1"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(9))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(), + is(equalTo(64))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Opera 10.x user-agent strings + */ + @Test + public void opera10() + { + List<String> userAgents = Arrays.asList( + "Opera/9.80 (X11; Linux i686; U; Debian; pl) Presto/2.2.15 Version/10.00", + "Opera/9.80 (X11; Linux x86_64; U; en-GB) Presto/2.2.15 Version/10.01", + "Mozilla/5.0 (Windows NT 6.0; U; tr; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 10.10", + "Opera/9.80 (S60; SymbOS; Opera Tablet/9174; U; en) Presto/2.7.81 Version/10.5", + "Mozilla/4.0 (compatible; MSIE 8.0; Linux i686; en) Opera 10.51", + "Mozilla/5.0 (Windows NT 5.1; U; zh-cn; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Opera 10.70"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(10))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Opera 11.x user-agent strings + */ + @Test + public void opera11() + { + List<String> userAgents = Arrays.asList("Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.8.131 Version/11.10"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(11))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Safari <3 user-agent strings + */ + @Test + public void safariLessThan3() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; es) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; fr) AppleWebKit/312.5.2 (KHTML, like Gecko) Safari/312.3.3", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/85.8.5 (KHTML, like Gecko) Safari/85.8.1"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(lessThan(3))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Safari3 user-agent strings + */ + @Test + public void safari3() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; fr-fr) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1", + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-gb) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/522.11 (KHTML, like Gecko) Version/3.0.2 Safari/522.12"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(3))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Safari user-agent strings + */ + @Test + public void safari4() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows; U; Windows NT 6.0; en) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16", + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; nl-nl) AppleWebKit/533.16 (KHTML, like Gecko) Version/4.1 Safari/533.16", + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-gb) AppleWebKit/528.4+ (KHTML, like Gecko) Version/4.0dp1 Safari/526.11.2"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(4))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Safari5 user-agent strings + */ + @Test + public void safari5() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows; U; Windows NT 6.1; ja-JP) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16", + "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; fr) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5", + "Mozilla/5.0 (Windows; U; Windows NT 6.0; nb-NO) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5", + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; de-de) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(5))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Chrome0 user-agent strings + */ + @Test + public void chrome0() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13", + "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.31 Safari/525.19", + "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.3.154.6 Safari/525.19"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(0))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Chrome 8.x user-agent strings + */ + @Test + public void chrome8() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10", + "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Ubuntu/10.10 Chromium/8.0.552.237 Chrome/8.0.552.237 Safari/534.10", + "Mozilla/5.0 (X11; U; CrOS i686 0.9.128; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.339 Safari/534.10"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(8))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Chrome 12.x user-agent strings + */ + @Test + public void chrome12() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/12.0.702.0 Safari/534.24", + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Ubuntu/10.10 Chromium/12.0.703.0 Chrome/12.0.703.0 Safari/534.24", + "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.25 (KHTML, like Gecko) Chrome/12.0.706.0 Safari/534.25"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(12))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test Konqueror user-agent strings + */ + @Test + public void konqueror() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (compatible; Konqueror/3.2; FreeBSD) (KHTML, like Gecko)", + "Mozilla/5.0 (compatible; Konqueror/3.5; Linux; i686; U; it-IT) KHTML/3.5.5 (like Gecko) (Debian)", + "Mozilla/5.0 (compatible; Konqueror/4.3; Linux 2.6.31-16-generic; X11) KHTML/4.3.2 (like Gecko)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test FF 4.x user-agent strings + */ + @Test + public void firefox40() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b8pre) Gecko/20101213 Firefox/4.0b8pre", + "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(4))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(), + is(equalTo(0))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test FF3.8 user-agent strings + */ + @Test + public void firefox38() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.9.0.2) Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.8", + "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.8"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(3))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(), + is(equalTo(8))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test FF 3.6 user-agent strings + */ + @Test + public void firefox36() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 ( .NET CLR 3.5.30729; .NET CLR 4.0.20506)", + "Mozilla/5.0 (X11; U; FreeBSD i386; de-CH; rv:1.9.2.8) Gecko/20100729 Firefox/3.6.8"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(3))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(), + is(equalTo(6))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } + + /** + * Test FF 2.x user-agent strings + */ + @Test + public void firefox20() + { + List<String> userAgents = Arrays.asList( + "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071105 Fedora/2.0.0.9-1.fc7 Firefox/2.0.0.9", + "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)"); + + for (String userAgent : userAgents) + { + WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent); + + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), + is(equalTo(2))); + assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(), + is(equalTo(0))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(), + is(equalTo(true))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(), + is(equalTo(true))); + + assertThat(userAgent, webClientInfo.getProperties().isBrowserOpera(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserChrome(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserKonqueror(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserSafari(), + is(equalTo(false))); + assertThat(userAgent, webClientInfo.getProperties().isBrowserInternetExplorer(), + is(equalTo(false))); + } + } +}