diff options
author | Artur Signell <artur@vaadin.com> | 2016-02-03 10:59:46 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-05-22 10:24:02 +0300 |
commit | 25e824aea4c0cf65dbea784446ec2b7a521b7a08 (patch) | |
tree | 3aa8d790498140b7aec70919f7f092a7e2bd75e4 | |
parent | 9b048703e112eb213e4c604428603bde92bd40ae (diff) | |
download | vaadin-framework-25e824aea4c0cf65dbea784446ec2b7a521b7a08.tar.gz vaadin-framework-25e824aea4c0cf65dbea784446ec2b7a521b7a08.zip |
Correctly detect PhantomJS 2.1
Change-Id: I9b1df949b831b84aa05bf611b0128eb2414bbbae
3 files changed, 45 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/BrowserInfo.java b/client/src/main/java/com/vaadin/client/BrowserInfo.java index 8dcefddcf5..d1592c95f4 100644 --- a/client/src/main/java/com/vaadin/client/BrowserInfo.java +++ b/client/src/main/java/com/vaadin/client/BrowserInfo.java @@ -165,6 +165,14 @@ public class BrowserInfo { minorVersionClass = majorVersionClass + browserDetails.getBrowserMinorVersion(); browserEngineClass = ENGINE_WEBKIT; + } else if (browserDetails.isPhantomJS()) { + // Safari needed for theme + browserIdentifier = BROWSER_SAFARI; + majorVersionClass = browserIdentifier + + getBrowserMajorVersion(); + minorVersionClass = majorVersionClass + + browserDetails.getBrowserMinorVersion(); + browserEngineClass = ENGINE_WEBKIT; } else if (browserDetails.isIE()) { browserIdentifier = BROWSER_IE; majorVersionClass = browserIdentifier diff --git a/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java b/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java index 5522b8e2bc..41e675cb3a 100644 --- a/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java +++ b/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java @@ -61,6 +61,8 @@ public class VBrowserDetailsUserAgentParserTest { private static final String EDGE_WINDOWS_10 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240"; + private static final String PHANTOMJS_211_MAC = "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"; + @Test public void testSafari3() { VBrowserDetails bd = new VBrowserDetails(SAFARI3_WINDOWS); @@ -471,6 +473,16 @@ public class VBrowserDetailsUserAgentParserTest { assertWindows(bd, false); } + @Test + public void testPhantomJs211() { + VBrowserDetails bd = new VBrowserDetails(PHANTOMJS_211_MAC); + assertPhantomJS(bd); + assertWebKit(bd); + assertBrowserMajorVersion(bd, 2); + assertBrowserMinorVersion(bd, 1); + assertMacOSX(bd); + } + /* * Helper methods below */ @@ -525,6 +537,17 @@ public class VBrowserDetailsUserAgentParserTest { assertFalse(browserDetails.isTrident()); } + private void assertPhantomJS(VBrowserDetails browserDetails) { + // Browser + assertFalse(browserDetails.isFirefox()); + assertFalse(browserDetails.isChrome()); + assertFalse(browserDetails.isIE()); + assertFalse(browserDetails.isOpera()); + assertFalse(browserDetails.isSafari()); + assertFalse(browserDetails.isEdge()); + assertTrue(browserDetails.isPhantomJS()); + } + private void assertFirefox(VBrowserDetails browserDetails) { // Browser assertTrue(browserDetails.isFirefox()); @@ -533,6 +556,7 @@ public class VBrowserDetailsUserAgentParserTest { assertFalse(browserDetails.isOpera()); assertFalse(browserDetails.isSafari()); assertFalse(browserDetails.isEdge()); + assertFalse(browserDetails.isPhantomJS()); } private void assertChrome(VBrowserDetails browserDetails) { @@ -543,6 +567,7 @@ public class VBrowserDetailsUserAgentParserTest { assertFalse(browserDetails.isOpera()); assertFalse(browserDetails.isSafari()); assertFalse(browserDetails.isEdge()); + assertFalse(browserDetails.isPhantomJS()); } private void assertIE(VBrowserDetails browserDetails) { @@ -553,6 +578,7 @@ public class VBrowserDetailsUserAgentParserTest { assertFalse(browserDetails.isOpera()); assertFalse(browserDetails.isSafari()); assertFalse(browserDetails.isEdge()); + assertFalse(browserDetails.isPhantomJS()); } private void assertOpera(VBrowserDetails browserDetails) { @@ -563,6 +589,7 @@ public class VBrowserDetailsUserAgentParserTest { assertTrue(browserDetails.isOpera()); assertFalse(browserDetails.isSafari()); assertFalse(browserDetails.isEdge()); + assertFalse(browserDetails.isPhantomJS()); } private void assertSafari(VBrowserDetails browserDetails) { @@ -573,6 +600,7 @@ public class VBrowserDetailsUserAgentParserTest { assertFalse(browserDetails.isOpera()); assertTrue(browserDetails.isSafari()); assertFalse(browserDetails.isEdge()); + assertFalse(browserDetails.isPhantomJS()); } private void assertEdge(VBrowserDetails browserDetails) { @@ -583,6 +611,7 @@ public class VBrowserDetailsUserAgentParserTest { assertFalse(browserDetails.isOpera()); assertFalse(browserDetails.isSafari()); assertTrue(browserDetails.isEdge()); + assertFalse(browserDetails.isPhantomJS()); } private void assertMacOSX(VBrowserDetails browserDetails) { diff --git a/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java b/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java index a7426d2022..32299a22d1 100644 --- a/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java +++ b/shared/src/main/java/com/vaadin/shared/VBrowserDetails.java @@ -86,9 +86,10 @@ public class VBrowserDetails implements Serializable { // IE 11 no longer contains MSIE in the user agent isIE = isIE || isTrident; - isSafari = !isChrome && !isIE && userAgent.indexOf("safari") != -1; - isFirefox = userAgent.indexOf(" firefox/") != -1; isPhantomJS = userAgent.indexOf("phantomjs/") != -1; + isSafari = !isChrome && !isIE && !isPhantomJS + && userAgent.indexOf("safari") != -1; + isFirefox = userAgent.indexOf(" firefox/") != -1; if (userAgent.indexOf(" edge/") != -1) { isEdge = true; isChrome = false; @@ -98,6 +99,7 @@ public class VBrowserDetails implements Serializable { isFirefox = false; isWebKit = false; isGecko = false; + isPhantomJS = false; } // chromeframe @@ -174,6 +176,10 @@ public class VBrowserDetails implements Serializable { } else if (isEdge) { int i = userAgent.indexOf(" edge/") + 6; parseVersionString(safeSubstring(userAgent, i, i + 8)); + } else if (isPhantomJS) { + String prefix = " phantomjs/"; + int i = userAgent.indexOf(prefix) + prefix.length(); + parseVersionString(safeSubstring(userAgent, i, i + 5)); } } catch (Exception e) { // Browser version parsing failed |