You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2013/10/28 09:16:48 UTC

[32/47] git commit: WICKET-5362 Add support for parsing IE 11 user agent

WICKET-5362 Add support for parsing IE 11 user agent


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d1570dbe
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d1570dbe
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d1570dbe

Branch: refs/heads/wicket-4997
Commit: d1570dbe76926459e7b036ab3e457a54fbeebbe8
Parents: 53b335e
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Sep 23 14:01:40 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Sep 23 14:02:10 2013 +0200

----------------------------------------------------------------------
 .../wicket/protocol/http/request/UserAgent.java | 13 +++--
 .../protocol/http/request/WebClientInfo.java    | 10 +++-
 .../http/request/WebClientInfoTest.java         | 58 ++++++++++++++++++++
 3 files changed, 75 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/d1570dbe/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
index 1f42b04..da121cc 100644
--- 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
@@ -26,12 +26,15 @@ import org.apache.wicket.util.string.Strings;
  */
 enum UserAgent {
 
-	MOZILLA("Opera,AppleWebKit,Konqueror", Arrays.asList("Mozilla", "Gecko")),
+	MOZILLA("Opera,AppleWebKit,Konqueror,Trident", Arrays.asList("Mozilla", "Gecko")),
 
-	FIREFOX("Opera,AppleWebKit,Konqueror", Arrays.asList("Mozilla", "Gecko", "Firefox")),
+	FIREFOX("Opera,AppleWebKit,Konqueror,Trident", Arrays.asList("Mozilla", "Gecko", "Firefox")),
 
-	INTERNET_EXPLORER("Opera", Arrays.asList("Mozilla", "MSIE", "Windows"), Arrays.asList(
-		"Mozilla", "MSIE", "Trident"), Arrays.asList("Mozilla", "MSIE", "Mac_PowerPC")),
+	INTERNET_EXPLORER("Opera",
+		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")),
 
@@ -118,4 +121,4 @@ enum UserAgent {
 
 		return false;
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/d1570dbe/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 7dcc1eb..6af463a 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
@@ -286,7 +286,15 @@ public class WebClientInfo extends ClientInfo
 
 		if (properties.isBrowserInternetExplorer())
 		{
-			setMajorMinorVersionByPattern("msie (\\d+)\\.(\\d+)");
+			// modern IE browsers (>=IE11) uses new user agent format
+			if (getUserAgentStringLc().contains("like gecko"))
+			{
+				setMajorMinorVersionByPattern("rv:(\\d+)\\.(\\d+)");
+			}
+			else
+			{
+				setMajorMinorVersionByPattern("msie (\\d+)\\.(\\d+)");
+			}
 
 			properties.setProprietaryIECssExpressionsSupported(true);
 			properties.setQuirkCssPositioningOneSideOnly(true);

http://git-wip-us.apache.org/repos/asf/wicket/blob/d1570dbe/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 b35a5f0..eab2831 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
@@ -17,6 +17,7 @@
 package org.apache.wicket.protocol.http.request;
 
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.lessThan;
 import static org.junit.Assert.assertThat;
@@ -208,6 +209,63 @@ public class WebClientInfoTest
 	}
 
 	/**
+	 * 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)));
+		}
+	}
+
+	/**
+	 * 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)));
+		}
+	}
+
+	/**
 	 * Test Opera 9.64 user-agent strings
 	 */
 	@Test