import junit.framework.TestCase;
+import org.junit.Assert;
+
import com.vaadin.shared.VBrowserDetails;
public class TestVBrowserDetailsUserAgentParser extends TestCase {
assertIE(bd);
assertBrowserMajorVersion(bd, 11);
assertBrowserMinorVersion(bd, 0);
- assertWindows(bd);
+ assertWindows(bd, true);
}
/*
}
private void assertWindows(VBrowserDetails browserDetails) {
+ assertWindows(browserDetails, false);
+ }
+
+ private void assertWindows(VBrowserDetails browserDetails,
+ boolean isWindowsPhone) {
assertFalse(browserDetails.isLinux());
assertTrue(browserDetails.isWindows());
assertFalse(browserDetails.isMacOSX());
assertFalse(browserDetails.isIOS());
assertFalse(browserDetails.isAndroid());
+ Assert.assertEquals(isWindowsPhone, browserDetails.isWindowsPhone());
}
private void assertLinux(VBrowserDetails browserDetails) {
return browserDetails.isWindows();
}
+ /**
+ * Tests whether the user is using Windows Phone.
+ *
+ * @return true if the user is using Windows Phone, false if the user is not
+ * using Windows Phone or if no information on the browser is
+ * present
+ */
+ public boolean isWindowsPhone() {
+ return browserDetails.isWindowsPhone();
+ }
+
/**
* Tests if the browser is run on Android.
*
private boolean isOpera = false;
private boolean isIE = false;
+ private boolean isWindowsPhone;
+
private OperatingSystem os = OperatingSystem.UNKNOWN;
public enum OperatingSystem {
// Operating system
if (userAgent.contains("windows ")) {
os = OperatingSystem.WINDOWS;
+ isWindowsPhone = userAgent.contains("windows phone");
} else if (userAgent.contains("linux")) {
if (userAgent.contains("android")) {
os = OperatingSystem.ANDROID;
return os == OperatingSystem.WINDOWS;
}
+ /**
+ * Tests if the browser is run on Windows Phone.
+ *
+ * @return true if run on Windows Phone, false otherwise
+ */
+ public boolean isWindowsPhone() {
+ return isWindowsPhone;
+ }
+
/**
* Tests if the browser is run on Mac OSX.
*