From c44d88eb09ae0996b08f4058d0f036b14756973e Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 16 Sep 2012 21:45:58 -0300 Subject: [PATCH] - Add some automatic tests to detect user agent. --- .../filter/SupportedUserAgent.java | 3 +-- .../wisemapping/test/model/UserAgentTest.java | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/filter/SupportedUserAgent.java b/wise-webapp/src/main/java/com/wisemapping/filter/SupportedUserAgent.java index 0e97c355..ff4af213 100644 --- a/wise-webapp/src/main/java/com/wisemapping/filter/SupportedUserAgent.java +++ b/wise-webapp/src/main/java/com/wisemapping/filter/SupportedUserAgent.java @@ -73,8 +73,7 @@ public class SupportedUserAgent implements Serializable { final Version version = userAgent.getBrowserVersion(); final OperatingSystem os = userAgent.getOperatingSystem(); - - return browser == Browser.IE8 && os == OperatingSystem.WINDOWS && !header.contains("chromeframe"); + return (browser == Browser.IE8 || browser == Browser.IE && Integer.parseInt(version.getMajorVersion()) == 8) && !header.contains("chromeframe"); } public static SupportedUserAgent create(@NotNull final String userAgent) { diff --git a/wise-webapp/src/test/java/com/wisemapping/test/model/UserAgentTest.java b/wise-webapp/src/test/java/com/wisemapping/test/model/UserAgentTest.java index 9b280655..6333f4f5 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/model/UserAgentTest.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/model/UserAgentTest.java @@ -7,8 +7,8 @@ import org.testng.annotations.Test; @Test public class UserAgentTest { - @Test - public void validations() { + + public void isBrowserSupported() { final SupportedUserAgent firefox15 = SupportedUserAgent.create("Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15"); Assert.assertEquals(firefox15.isBrowserSupported(), true); @@ -31,6 +31,9 @@ public class UserAgentTest { final SupportedUserAgent ie9 = SupportedUserAgent.create("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; .NET4.0C; Tablet PC 2.0)"); Assert.assertEquals(ie9.isBrowserSupported(), true); + final SupportedUserAgent ie8 = SupportedUserAgent.create("Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"); + Assert.assertEquals(ie8.isBrowserSupported(), true); + final SupportedUserAgent safari = SupportedUserAgent.create("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"); Assert.assertEquals(safari.isBrowserSupported(), true); @@ -48,5 +51,19 @@ public class UserAgentTest { } + + public void isGCFRequired() { + + final SupportedUserAgent ie10 = SupportedUserAgent.create("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; SV1; .NET CLR 2.0.50727; WOW64)"); + Assert.assertEquals(ie10.needsGCF(), false); + + final SupportedUserAgent ie8 = SupportedUserAgent.create("Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"); + Assert.assertEquals(ie8.needsGCF(), true); + + final SupportedUserAgent ie8WithGCF = SupportedUserAgent.create("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; SV1) chromeframe/11.0.660.0"); + Assert.assertEquals(ie8WithGCF.needsGCF(), false); + + } + }