summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-02-03 10:59:46 +0200
committerIlia Motornyi <elmot@vaadin.com>2016-06-23 11:41:17 +0000
commitb06ac4816eb3bc2ef3929057785552d0a94377d4 (patch)
tree836117db68d457835779bab249960e2387759974
parent03e159db26687350d7de9952dc04eb8323052c59 (diff)
downloadvaadin-framework-b06ac4816eb3bc2ef3929057785552d0a94377d4.tar.gz
vaadin-framework-b06ac4816eb3bc2ef3929057785552d0a94377d4.zip
Correctly detect PhantomJS 2.1
Change-Id: Iaa491c5cc8b9e684999eb45ff2033cc5605c1aa1
-rw-r--r--client/src/com/vaadin/client/BrowserInfo.java8
-rw-r--r--client/tests/src/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java31
-rw-r--r--shared/src/com/vaadin/shared/VBrowserDetails.java10
3 files changed, 47 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/BrowserInfo.java b/client/src/com/vaadin/client/BrowserInfo.java
index 8dcefddcf5..d1592c95f4 100644
--- a/client/src/com/vaadin/client/BrowserInfo.java
+++ b/client/src/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/tests/src/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java b/client/tests/src/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java
index 24bf9b6558..3f7a1d051f 100644
--- a/client/tests/src/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java
+++ b/client/tests/src/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java
@@ -3,6 +3,7 @@ package com.vaadin.client;
import junit.framework.TestCase;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.shared.VBrowserDetails;
@@ -58,6 +59,9 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
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);
assertWebKit(bd);
@@ -433,6 +437,16 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
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
*/
@@ -487,6 +501,17 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
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());
@@ -495,6 +520,7 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
assertFalse(browserDetails.isEdge());
+ assertFalse(browserDetails.isPhantomJS());
}
private void assertChrome(VBrowserDetails browserDetails) {
@@ -505,6 +531,7 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
assertFalse(browserDetails.isEdge());
+ assertFalse(browserDetails.isPhantomJS());
}
private void assertIE(VBrowserDetails browserDetails) {
@@ -515,6 +542,7 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
assertFalse(browserDetails.isEdge());
+ assertFalse(browserDetails.isPhantomJS());
}
private void assertOpera(VBrowserDetails browserDetails) {
@@ -525,6 +553,7 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
assertTrue(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
assertFalse(browserDetails.isEdge());
+ assertFalse(browserDetails.isPhantomJS());
}
private void assertSafari(VBrowserDetails browserDetails) {
@@ -535,6 +564,7 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
assertFalse(browserDetails.isOpera());
assertTrue(browserDetails.isSafari());
assertFalse(browserDetails.isEdge());
+ assertFalse(browserDetails.isPhantomJS());
}
private void assertEdge(VBrowserDetails browserDetails) {
@@ -545,6 +575,7 @@ public class VBrowserDetailsUserAgentParserTest extends TestCase {
assertFalse(browserDetails.isOpera());
assertFalse(browserDetails.isSafari());
assertTrue(browserDetails.isEdge());
+ assertFalse(browserDetails.isPhantomJS());
}
private void assertMacOSX(VBrowserDetails browserDetails) {
diff --git a/shared/src/com/vaadin/shared/VBrowserDetails.java b/shared/src/com/vaadin/shared/VBrowserDetails.java
index a7426d2022..32299a22d1 100644
--- a/shared/src/com/vaadin/shared/VBrowserDetails.java
+++ b/shared/src/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