You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/06/25 16:00:50 UTC
wicket git commit: WICKET-6544 removed UserAgent
Repository: wicket
Updated Branches:
refs/heads/master abac74030 -> f840a2b45
WICKET-6544 removed UserAgent
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f840a2b4
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f840a2b4
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f840a2b4
Branch: refs/heads/master
Commit: f840a2b454d48ad85f66d17c06e4ef11793becfe
Parents: abac740
Author: Sven Meier <sv...@apache.org>
Authored: Mon Jun 25 17:59:37 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Mon Jun 25 17:59:37 2018 +0200
----------------------------------------------------------------------
.../wicket/protocol/http/ClientProperties.java | 214 -----
.../wicket/protocol/http/request/UserAgent.java | 126 ---
.../protocol/http/request/WebClientInfo.java | 171 ----
.../DynamicJQueryResourceReference.java | 99 ---
.../resource/JQueryPluginResourceReference.java | 2 +-
.../protocol/http/request/UserAgentTest.java | 78 --
.../http/request/WebClientInfoTest.java | 810 -------------------
7 files changed, 1 insertion(+), 1499 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
index fd162b0..2c2550d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
@@ -57,16 +57,6 @@ public class ClientProperties implements IClusterable
private static final long serialVersionUID = 1L;
private int browserHeight = -1;
- private boolean browserInternetExplorer;
- private boolean browserKonqueror;
- private boolean browserMozilla;
- private boolean browserMozillaFirefox;
- private boolean browserOpera;
- private boolean browserSafari;
- private boolean browserChrome;
- private boolean browserEdge;
- private int browserVersionMajor = -1;
- private int browserVersionMinor = -1;
private int browserWidth = -1;
private boolean navigatorCookieEnabled;
private boolean navigatorJavaEnabled;
@@ -98,22 +88,6 @@ public class ClientProperties implements IClusterable
}
/**
- * @return The major version number of the browser.
- */
- public int getBrowserVersionMajor()
- {
- return browserVersionMajor;
- }
-
- /**
- * @return The minor version number of the browser.
- */
- public int getBrowserVersionMinor()
- {
- return browserVersionMinor;
- }
-
- /**
* @return The browser width at the time it was measured
*/
public int getBrowserWidth()
@@ -365,87 +339,6 @@ public class ClientProperties implements IClusterable
}
/**
- * Flag indicating that the browser is a derivative of the Microsoft Internet Explorer browser
- * platform.
- *
- * @return True if a derivative of the Microsoft Internet Explorer browser platform.
- */
- public boolean isBrowserInternetExplorer()
- {
- return browserInternetExplorer;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the KDE Konqueror browser platform.
- *
- * @return True if a derivative of the KDE Konqueror browser platform.
- */
- public boolean isBrowserKonqueror()
- {
- return browserKonqueror;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Mozilla 1.0-1.8+ browser platform.
- *
- * @return True if a derivative of the Mozilla 1.0-1.8+ browser platform.
- */
- public boolean isBrowserMozilla()
- {
- return browserMozilla;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Mozilla Firefox 1.0+ browser
- * platform.
- *
- * @return True if a derivative of the Mozilla Firefox 1.0+ browser platform.
- */
- public boolean isBrowserMozillaFirefox()
- {
- return browserMozillaFirefox;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Opera browser platform.
- *
- * @return True if a derivative of the Opera browser platform.
- */
- public boolean isBrowserOpera()
- {
- return browserOpera;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Apple Safari browser platform.
- *
- * @return True if a derivative of the Apple Safari browser platform.
- */
- public boolean isBrowserSafari()
- {
- return browserSafari;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Chrome browser platform.
- *
- * @return True if a derivative of the Chrome browser platform.
- */
- public boolean isBrowserChrome()
- {
- return browserChrome;
- }
- /**
- * Flag indicating that the browser is a derivative of the Microsoft Edge browser platform.
- *
- * @return True if a derivative of the Microsoft Edge browser platform.
- */
- public boolean isBrowserEdge()
- {
- return browserEdge;
- }
-
- /**
*
*
* @return The client's navigator.cookieEnabled property.
@@ -478,113 +371,6 @@ public class ClientProperties implements IClusterable
}
/**
- * Flag indicating that the browser is a derivative of the Microsoft Internet Explorer browser
- * platform.
- *
- * @param browserInternetExplorer
- * True if a derivative of the Microsoft Internet Explorer browser platform.
- */
- public void setBrowserInternetExplorer(boolean browserInternetExplorer)
- {
- this.browserInternetExplorer = browserInternetExplorer;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the KDE Konqueror browser platform.
- *
- * @param browserKonqueror
- * True if a derivative of the KDE Konqueror browser platform.
- */
- public void setBrowserKonqueror(boolean browserKonqueror)
- {
- this.browserKonqueror = browserKonqueror;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Mozilla 1.0-1.8+ browser platform.
- *
- * @param browserMozilla
- * True if a derivative of the Mozilla 1.0-1.8+ browser platform.
- */
- public void setBrowserMozilla(boolean browserMozilla)
- {
- this.browserMozilla = browserMozilla;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Mozilla Firefox 1.0+ browser
- * platform.
- *
- * @param browserMozillaFirefox
- * True if a derivative of the Mozilla Firefox 1.0+ browser platform.
- */
- public void setBrowserMozillaFirefox(boolean browserMozillaFirefox)
- {
- this.browserMozillaFirefox = browserMozillaFirefox;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Opera browser platform.
- *
- * @param browserOpera
- * True if a derivative of the Opera browser platform.
- */
- public void setBrowserOpera(boolean browserOpera)
- {
- this.browserOpera = browserOpera;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Apple Safari browser platform.
- *
- * @param browserSafari
- * True if a derivative of the Apple Safari browser platform.
- */
- public void setBrowserSafari(boolean browserSafari)
- {
- this.browserSafari = browserSafari;
- }
-
- /**
- * Flag indicating that the browser is a derivative of the Chrome browser platform.
- *
- * @param browserChrome
- * True if a derivative of the Chrome browser platform.
- */
- public void setBrowserChrome(boolean browserChrome)
- {
- this.browserChrome = browserChrome;
- }
- /**
- * Flag indicating that the browser is a derivative of the Microsoft Edge browser platform.
- *
- * @param browserEdge
- * True if a derivative of the Microsoft Edge browser platform.
- */
- public void setBrowserEdge(boolean browserEdge)
- {
- this.browserEdge = browserEdge;
- }
-
- /**
- * @param browserVersionMajor
- * The major version number of the browser.
- */
- public void setBrowserVersionMajor(int browserVersionMajor)
- {
- this.browserVersionMajor = browserVersionMajor;
- }
-
- /**
- * @param browserVersionMinor
- * The minor version number of the browser.
- */
- public void setBrowserVersionMinor(int browserVersionMinor)
- {
- this.browserVersionMinor = browserVersionMinor;
- }
-
- /**
* @param browserWidth
* The browser width
*/
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
deleted file mode 100644
index e198166..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/UserAgent.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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,Trident", Arrays.asList("Mozilla", "Gecko")),
-
- FIREFOX("Opera,AppleWebKit,Konqueror,Trident,Edge", Arrays.asList("Mozilla", "Gecko", "Firefox")),
-
- INTERNET_EXPLORER("Opera,Edge",
- Arrays.asList("Mozilla", "MSIE", "Windows"),
- Arrays.asList("Mozilla", "MSIE", "Trident"),
- Arrays.asList("Mozilla", "MSIE", "Mac_PowerPC"),
- Arrays.asList("Mozilla", "Windows", "Trident", "like Gecko")),
-
- OPERA(Arrays.asList("Opera")),
-
- CHROME("Edge", Arrays.asList("Mozilla", "Chrome", "AppleWebKit", "Safari")),
-
- SAFARI("Chrome,Edge", Arrays.asList("Mozilla", "AppleWebKit", "Safari")),
-
- KONQUEROR(Arrays.asList("Konqueror")),
-
- EDGE("Opera,Konqueror,Trident", Arrays.asList("Edge", "Mozilla", "Chrome", "Safari"));
-
- /**
- * The values which are not allowed in the user agent.
- */
- private final String[] notAllowedList;
-
- /**
- * 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)
- {
- notAllowedList = Strings.split(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 (userAgent == null)
- {
- return false;
- }
-
- if (notAllowedList != null)
- {
- for (String value : notAllowedList)
- {
- if (userAgent.contains(value))
- {
- return false;
- }
- }
- }
-
- for (List<String> detectionGroup : detectionStrings)
- {
- boolean groupPassed = true;
- for (String detectionString : detectionGroup)
- {
- if (!userAgent.contains(detectionString))
- {
- groupPassed = false;
- break;
- }
- }
- if (groupPassed)
- {
- return true;
- }
- }
-
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
index c0fb2a6..e73bcdd 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
@@ -18,8 +18,6 @@ package org.apache.wicket.protocol.http.request;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
@@ -108,8 +106,6 @@ public class WebClientInfo extends ClientInfo
this.properties = properties;
properties.setRemoteAddress(getRemoteAddr(requestCycle));
-
- init();
}
/**
@@ -187,171 +183,4 @@ public class WebClientInfo extends ClientInfo
}
return remoteAddr;
}
-
- /**
- * Initialize the client properties object
- */
- private void init()
- {
- setInternetExplorerProperties();
- setOperaProperties();
- setMozillaProperties();
- setKonquerorProperties();
- setChromeProperties();
- setEdgeProperties();
- setSafariProperties();
-
- log.debug("determined user agent: {}", properties);
- }
-
- /**
- * sets the konqueror specific properties
- */
- private void setKonquerorProperties()
- {
- properties.setBrowserKonqueror(UserAgent.KONQUEROR.matches(getUserAgent()));
-
- if (properties.isBrowserKonqueror())
- {
- // e.g.: Mozilla/5.0 (compatible; Konqueror/4.2; Linux) KHTML/4.2.96 (like Gecko)
- setMajorMinorVersionByPattern("konqueror/(\\d+)\\.(\\d+)");
- }
- }
-
- /**
- * sets the chrome specific properties
- */
- private void setChromeProperties()
- {
- properties.setBrowserChrome(UserAgent.CHROME.matches(getUserAgent()));
-
- if (properties.isBrowserChrome())
- {
- // 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+)");
- }
- }
-
- /**
- * sets the Edge specific properties
- */
- private void setEdgeProperties()
- {
- properties.setBrowserEdge(UserAgent.EDGE.matches(getUserAgent()));
-
- if (properties.isBrowserEdge())
- {
- // e.g.: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
- // Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
- setMajorMinorVersionByPattern("edge/(\\d+)\\.(\\d+)");
- }
- }
-
- /**
- * sets the safari specific properties
- */
- private void setSafariProperties()
- {
- properties.setBrowserSafari(UserAgent.SAFARI.matches(getUserAgent()));
-
- if (properties.isBrowserSafari())
- {
- String userAgent = getUserAgentStringLc();
-
- if (userAgent.contains("version/"))
- {
- // e.g.: Mozilla/5.0 (Windows; U; Windows NT 6.1; sv-SE) AppleWebKit/533.19
- // (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4
- setMajorMinorVersionByPattern("version/(\\d+)\\.(\\d+)");
- }
- }
- }
-
- /**
- * sets the mozilla/firefox specific properties
- */
- private void setMozillaProperties()
- {
- properties.setBrowserMozillaFirefox(UserAgent.FIREFOX.matches(getUserAgent()));
- properties.setBrowserMozilla(UserAgent.MOZILLA.matches(getUserAgent()));
-
- if (properties.isBrowserMozilla())
- {
- if (properties.isBrowserMozillaFirefox())
- {
- // 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+)");
- }
- }
- }
-
- /**
- * sets the opera specific properties
- */
- private void setOperaProperties()
- {
- properties.setBrowserOpera(UserAgent.OPERA.matches(getUserAgent()));
-
- if (properties.isBrowserOpera())
- {
- 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()));
-
- if (properties.isBrowserInternetExplorer())
- {
- // modern IE browsers (>=IE11) uses new user agent format
- if (getUserAgentStringLc().contains("like gecko"))
- {
- setMajorMinorVersionByPattern("rv:(\\d+)\\.(\\d+)");
- }
- else
- {
- setMajorMinorVersionByPattern("msie (\\d+)\\.(\\d+)");
- }
- }
- }
-
- /**
- * 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())
- {
- properties.setBrowserVersionMajor(Integer.parseInt(matcher.group(1)));
- properties.setBrowserVersionMinor(Integer.parseInt(matcher.group(2)));
- }
- }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/main/java/org/apache/wicket/resource/DynamicJQueryResourceReference.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/DynamicJQueryResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/resource/DynamicJQueryResourceReference.java
deleted file mode 100644
index 65768e5..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/resource/DynamicJQueryResourceReference.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.resource;
-
-import org.apache.wicket.MetaDataKey;
-import org.apache.wicket.Session;
-import org.apache.wicket.protocol.http.ClientProperties;
-import org.apache.wicket.protocol.http.WebSession;
-import org.apache.wicket.protocol.http.request.WebClientInfo;
-import org.apache.wicket.request.cycle.RequestCycle;
-
-
-/**
- * A resource reference that calculates which version of jQuery JavaScript library to use depending
- * on the user agent. For IE 6/7/8 jQuery ver. 1.x will be used, for any other browser - ver. 2.x.
- *
- * To use this resource reference do:
- * <code>
- * app.getJavaScriptLibrarySettings().setJQueryReference(new DynamicJQueryResourceReference())
- * </code>
- *
- * @since 6.9.0
- */
-public class DynamicJQueryResourceReference extends JQueryResourceReference
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * The key for the metadata that is used as a cache to calculate the name
- * only once
- */
- private static final MetaDataKey<String> KEY = new MetaDataKey<String>()
- {
- };
-
- public DynamicJQueryResourceReference()
- {
- super(VERSION_2);
- }
-
- @Override
- public String getName()
- {
- RequestCycle requestCycle = RequestCycle.get();
- String name = requestCycle.getMetaData(KEY);
- if (name == null)
- {
- WebClientInfo clientInfo;
- name = getVersion2();
- if (Session.exists())
- {
- WebSession session = WebSession.get();
- clientInfo = session.getClientInfo();
- }
- else
- {
- clientInfo = new WebClientInfo(requestCycle);
- }
- ClientProperties clientProperties = clientInfo.getProperties();
- if (clientProperties.isBrowserInternetExplorer() && clientProperties.getBrowserVersionMajor() < 9)
- {
- name = getVersion1();
- }
-
- requestCycle.setMetaData(KEY, name);
- }
- return name;
- }
-
- protected String getVersion1()
- {
- return VERSION_1;
- }
-
- protected String getVersion2()
- {
- return VERSION_2;
- }
-
- @Override
- public Class<?> getScope()
- {
- return getClass();
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/main/java/org/apache/wicket/resource/JQueryPluginResourceReference.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/JQueryPluginResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/resource/JQueryPluginResourceReference.java
index 30abada..ede35d2 100644
--- a/wicket-core/src/main/java/org/apache/wicket/resource/JQueryPluginResourceReference.java
+++ b/wicket-core/src/main/java/org/apache/wicket/resource/JQueryPluginResourceReference.java
@@ -80,7 +80,7 @@ public class JQueryPluginResourceReference extends JavaScriptResourceReference
}
else
{
- backingLibraryReference = DynamicJQueryResourceReference.get();
+ backingLibraryReference = JQueryResourceReference.INSTANCE_2;
}
List<HeaderItem> dependencies = super.getDependencies();
dependencies.add(JavaScriptHeaderItem.forReference(backingLibraryReference));
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/UserAgentTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/UserAgentTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/UserAgentTest.java
deleted file mode 100644
index 5f2bcf0..0000000
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/UserAgentTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Tests for {@link UserAgent}
- */
-public class UserAgentTest
-{
-
- /**
- * Tests for {@link UserAgent#matches(String)} based on the blacklisted entries
- */
- @Test
- public void notAllowedList()
- {
- // check single blacklisted entry - Opera
- assertFalse(UserAgent.INTERNET_EXPLORER.matches("Something that contains Opera"));
-
- // check comma separated list of entries - Konqueror,Opera
- assertFalse(UserAgent.MOZILLA.matches("Something that contains Konqueror"));
- assertFalse(UserAgent.MOZILLA.matches("Something that contains Opera"));
-
- // check blacklisted for EDGE
- assertFalse(UserAgent.EDGE.matches("Something that contains Opera"));
- assertFalse(UserAgent.EDGE.matches("Something that contains Konqueror"));
- assertFalse(UserAgent.EDGE.matches("Something that contains Trident"));
- }
-
- /**
- * Tests for {@link UserAgent#matches(String)} based on the detection groups
- */
- @Test
- public void detectionGroups()
- {
- // IE always send the agent header, if don't:
- assertFalse(UserAgent.INTERNET_EXPLORER.matches(null));
-
- // no blacklisted entries, but not full match in a detection group
- assertFalse(UserAgent.INTERNET_EXPLORER.matches("Mozilla MSIE"));
-
- // full match in detection group 1
- assertTrue(UserAgent.INTERNET_EXPLORER.matches("Mozilla MSIE Trident"));
-
- // full match in detection group 2
- assertTrue(UserAgent.INTERNET_EXPLORER.matches("Mozilla MSIE Mac_PowerPC"));
-
- // check Edge
- final String userAgentEdge
- = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063";
- assertTrue(UserAgent.EDGE.matches(userAgentEdge));
- assertFalse(UserAgent.FIREFOX.matches(userAgentEdge));
- assertFalse(UserAgent.INTERNET_EXPLORER.matches(userAgentEdge));
- assertFalse(UserAgent.SAFARI.matches(userAgentEdge));
- assertFalse(UserAgent.CHROME.matches(userAgentEdge));
- assertFalse(UserAgent.OPERA.matches(userAgentEdge));
- assertFalse(UserAgent.KONQUEROR.matches(userAgentEdge));
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/f840a2b4/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
index 11a7db2..ca7089f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java
@@ -61,816 +61,6 @@ public class WebClientInfoTest
}
/**
- * 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- is(equalTo(false)));
- }
- }
-
- /**
- * Test IE 10.x user-agent strings
- */
- @Test
- public void internetExplorer10()
- {
- List<String> userAgents = Arrays.asList(
- "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
- "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
- "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)",
- "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; SV1; .NET CLR 2.0.50727; WOW64)",
- "Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)",
- "Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)",
- "Mozilla/1.22 (compatible; MSIE 10.0; Windows 3.1)");
-
- for (String userAgent : userAgents)
- {
- WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent);
-
- assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), is(equalTo(10)));
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(), is(equalTo(false)));
- }
- }
-
- /**
- * Test IE 11.x user-agent strings
- */
- @Test
- public void internetExplorer11()
- {
- List<String> userAgents = Arrays.asList(
- "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
- "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.1) like Gecko");
-
- for (String userAgent : userAgents)
- {
- WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent);
-
- assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(), is(equalTo(11)));
- assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(), is(greaterThan(-1)));
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(), 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- is(equalTo(false)));
- }
- }
-
- /**
- * Test Microsoft Edge user-agent strings
- */
- @Test
- public void edge15()
- {
- List<String> userAgents = Arrays.asList(
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063");
-
- for (String userAgent : userAgents)
- {
- WebClientInfo webClientInfo = new WebClientInfo(requestCycleMock, userAgent);
-
- assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMajor(),
- is(equalTo(15)));
- assertThat(userAgent, webClientInfo.getProperties().getBrowserVersionMinor(),
- is(equalTo(15063)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserMozillaFirefox(),
- is(equalTo(false)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserMozilla(),
- is(equalTo(false)));
-
- 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)));
- assertThat(userAgent, webClientInfo.getProperties().isBrowserEdge(),
- is(equalTo(true)));
- }
- }
-
-
- /**
* Test X-Forwarded-For ip address extraction.
*/
@Test