summaryrefslogtreecommitdiffstats
path: root/client/src/test/java
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-03-18 12:07:17 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2016-03-18 15:39:22 +0200
commit18fe7aa260fae72511d1612b16eeff79b42f98f3 (patch)
treec21fd8a986b65368c387d806248c1743ac75dc8c /client/src/test/java
parentab189ea14e32abb614ab9c0b0e059633ffc07bad (diff)
downloadvaadin-framework-18fe7aa260fae72511d1612b16eeff79b42f98f3.tar.gz
vaadin-framework-18fe7aa260fae72511d1612b16eeff79b42f98f3.zip
Build vaadin-client with maven
Change-Id: I36c426086a2b957f6f738d17470c499a01ddac3b
Diffstat (limited to 'client/src/test/java')
-rw-r--r--client/src/test/java/com/vaadin/client/ApplicationConnectionURLGenerationTest.java74
-rwxr-xr-xclient/src/test/java/com/vaadin/client/DateTimeServiceTest.java122
-rw-r--r--client/src/test/java/com/vaadin/client/LocatorUtilTest.java80
-rw-r--r--client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java651
-rw-r--r--client/src/test/java/com/vaadin/client/communication/ServerMessageHandlerTest.java54
-rw-r--r--client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java192
-rw-r--r--client/src/test/java/com/vaadin/client/ui/grid/PartitioningTest.java104
7 files changed, 1277 insertions, 0 deletions
diff --git a/client/src/test/java/com/vaadin/client/ApplicationConnectionURLGenerationTest.java b/client/src/test/java/com/vaadin/client/ApplicationConnectionURLGenerationTest.java
new file mode 100644
index 0000000000..4dd2ddbaa4
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/ApplicationConnectionURLGenerationTest.java
@@ -0,0 +1,74 @@
+package com.vaadin.client;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.vaadin.shared.util.SharedUtil;
+
+public class ApplicationConnectionURLGenerationTest {
+
+ private static final String[] URIS = new String[] {
+ "http://demo.vaadin.com/", //
+ "https://demo.vaadin.com/",
+ "http://demo.vaadin.com/foo",
+ "http://demo.vaadin.com/foo?f",
+ "http://demo.vaadin.com/foo?f=1",
+ "http://demo.vaadin.com:1234/foo?a",
+ "http://demo.vaadin.com:1234/foo#frag?fakeparam",
+ // Jetspeed
+ "http://localhost:8080/jetspeed/portal/_ns:Z3RlbXBsYXRlLXRvcDJfX3BhZ2UtdGVtcGxhdGVfX2RwLTFfX1AtMTJjNTRkYjdlYjUtMTAwMDJ8YzB8ZDF8aVVJREx8Zg__",
+ // Liferay generated url
+ "http://vaadin.com/directory?p_p_id=Directory_WAR_Directory&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=UIDL&p_p_cacheability=cacheLevelPage&p_p_col_id=row-1&p_p_col_count=1",
+
+ };
+ private static final String[] URIS_WITH_ABCD_PARAM = new String[] {
+ "http://demo.vaadin.com/?a=b&c=d",
+ "https://demo.vaadin.com/?a=b&c=d",
+ "http://demo.vaadin.com/foo?a=b&c=d",
+ "http://demo.vaadin.com/foo?f&a=b&c=d",
+ "http://demo.vaadin.com/foo?f=1&a=b&c=d",
+ "http://demo.vaadin.com:1234/foo?a&a=b&c=d",
+ "http://demo.vaadin.com:1234/foo?a=b&c=d#frag?fakeparam",
+ "http://localhost:8080/jetspeed/portal/_ns:Z3RlbXBsYXRlLXRvcDJfX3BhZ2UtdGVtcGxhdGVfX2RwLTFfX1AtMTJjNTRkYjdlYjUtMTAwMDJ8YzB8ZDF8aVVJREx8Zg__?a=b&c=d",
+ "http://vaadin.com/directory?p_p_id=Directory_WAR_Directory&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=UIDL&p_p_cacheability=cacheLevelPage&p_p_col_id=row-1&p_p_col_count=1&a=b&c=d",
+
+ };
+
+ private static final String[] URIS_WITH_ABCD_PARAM_AND_FRAGMENT = new String[] {
+ "http://demo.vaadin.com/?a=b&c=d#fragment",
+ "https://demo.vaadin.com/?a=b&c=d#fragment",
+ "http://demo.vaadin.com/foo?a=b&c=d#fragment",
+ "http://demo.vaadin.com/foo?f&a=b&c=d#fragment",
+ "http://demo.vaadin.com/foo?f=1&a=b&c=d#fragment",
+ "http://demo.vaadin.com:1234/foo?a&a=b&c=d#fragment",
+ "",
+ "http://localhost:8080/jetspeed/portal/_ns:Z3RlbXBsYXRlLXRvcDJfX3BhZ2UtdGVtcGxhdGVfX2RwLTFfX1AtMTJjNTRkYjdlYjUtMTAwMDJ8YzB8ZDF8aVVJREx8Zg__?a=b&c=d#fragment",
+ "http://vaadin.com/directory?p_p_id=Directory_WAR_Directory&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=UIDL&p_p_cacheability=cacheLevelPage&p_p_col_id=row-1&p_p_col_count=1&a=b&c=d#fragment",
+
+ };
+
+ @Test
+ public void testParameterAdding() {
+ for (int i = 0; i < URIS.length; i++) {
+ // Adding nothing
+ assertEquals(URIS[i], SharedUtil.addGetParameters(URIS[i], ""));
+
+ // Adding a=b&c=d
+ assertEquals(URIS_WITH_ABCD_PARAM[i],
+ SharedUtil.addGetParameters(URIS[i], "a=b&c=d"));
+
+ // Fragments
+ if (URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i].length() > 0) {
+ assertEquals(URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i],
+ SharedUtil.addGetParameters(URIS[i] + "#fragment",
+ "a=b&c=d"));
+
+ // Empty fragment
+ assertEquals(URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i].replace(
+ "#fragment", "#"), SharedUtil.addGetParameters(URIS[i]
+ + "#", "a=b&c=d"));
+ }
+ }
+ }
+}
diff --git a/client/src/test/java/com/vaadin/client/DateTimeServiceTest.java b/client/src/test/java/com/vaadin/client/DateTimeServiceTest.java
new file mode 100755
index 0000000000..e5e6cbd7db
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/DateTimeServiceTest.java
@@ -0,0 +1,122 @@
+package com.vaadin.client;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DateTimeServiceTest {
+
+ final long MILLISECONDS_PER_DAY = 24 * 3600 * 1000;
+
+ static Map<Date, Integer> isoWeekNumbers = new HashMap<Date, Integer>();
+ static {
+ isoWeekNumbers.put(getDate(2005, 02, 02), 5);
+
+ isoWeekNumbers.put(getDate(2005, 1, 1), 53);
+ isoWeekNumbers.put(getDate(2005, 1, 2), 53);
+ isoWeekNumbers.put(getDate(2005, 1, 3), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 4), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 5), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 6), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 7), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 8), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 9), 1);
+ isoWeekNumbers.put(getDate(2005, 1, 10), 2);
+ isoWeekNumbers.put(getDate(2005, 12, 31), 52);
+ isoWeekNumbers.put(getDate(2005, 12, 30), 52);
+ isoWeekNumbers.put(getDate(2005, 12, 29), 52);
+ isoWeekNumbers.put(getDate(2005, 12, 28), 52);
+ isoWeekNumbers.put(getDate(2005, 12, 27), 52);
+ isoWeekNumbers.put(getDate(2005, 12, 26), 52);
+ isoWeekNumbers.put(getDate(2005, 12, 25), 51);
+ isoWeekNumbers.put(getDate(2007, 1, 1), 1);
+ isoWeekNumbers.put(getDate(2007, 12, 30), 52);
+ isoWeekNumbers.put(getDate(2007, 12, 31), 1);
+ isoWeekNumbers.put(getDate(2008, 1, 1), 1);
+ isoWeekNumbers.put(getDate(2008, 12, 28), 52);
+ isoWeekNumbers.put(getDate(2008, 12, 29), 1);
+ isoWeekNumbers.put(getDate(2008, 12, 30), 1);
+ isoWeekNumbers.put(getDate(2008, 12, 31), 1);
+ isoWeekNumbers.put(getDate(2009, 1, 1), 1);
+ isoWeekNumbers.put(getDate(2009, 12, 31), 53);
+ isoWeekNumbers.put(getDate(2010, 1, 1), 53);
+ isoWeekNumbers.put(getDate(2010, 1, 2), 53);
+ isoWeekNumbers.put(getDate(2010, 1, 3), 53);
+ isoWeekNumbers.put(getDate(2010, 1, 4), 1);
+ isoWeekNumbers.put(getDate(2010, 1, 5), 1);
+ isoWeekNumbers.put(getDate(2010, 10, 10), 40);
+ isoWeekNumbers.put(getDate(2015, 3, 24), 13);
+ isoWeekNumbers.put(getDate(2015, 3, 31), 14);
+ isoWeekNumbers.put(getDate(2015, 10, 13), 42);
+ isoWeekNumbers.put(getDate(2015, 10, 20), 43);
+ isoWeekNumbers.put(getDate(2015, 10, 27), 44);
+ isoWeekNumbers.put(getDate(2026, 3, 24), 13);
+ isoWeekNumbers.put(getDate(2026, 3, 31), 14);
+ isoWeekNumbers.put(getDate(2026, 10, 13), 42);
+ isoWeekNumbers.put(getDate(2026, 10, 20), 43);
+ isoWeekNumbers.put(getDate(2026, 10, 27), 44);
+
+ }
+
+ /**
+ * Test all dates from 1990-1992 + some more and see that {@link Calendar}
+ * calculates the ISO week number like we do.
+ *
+ */
+ @Test
+ public void testISOWeekNumbers() {
+ Calendar c = Calendar.getInstance();
+ c.set(1990, 1, 1);
+ long start = c.getTimeInMillis();
+
+ for (int i = 0; i < 1000; i++) {
+ Date d = new Date(start + i * MILLISECONDS_PER_DAY);
+ int expected = getCalendarISOWeekNr(d);
+ int calculated = DateTimeService.getISOWeekNumber(d);
+ Assert.assertEquals(d + " should be week " + expected, expected,
+ calculated);
+
+ }
+ }
+
+ /**
+ * Verify that special cases are handled correctly by us (and
+ * {@link Calendar}).
+ *
+ */
+ @Test
+ public void testSampleISOWeekNumbers() {
+ for (Date d : isoWeekNumbers.keySet()) {
+ // System.out.println("Sample: " + d);
+ int expected = isoWeekNumbers.get(d);
+ int calculated = DateTimeService.getISOWeekNumber(d);
+ Assert.assertEquals(d + " should be week " + expected
+ + " (Java Calendar is wrong?)", expected,
+ getCalendarISOWeekNr(d));
+ Assert.assertEquals(d + " should be week " + expected, expected,
+ calculated);
+
+ }
+ }
+
+ private int getCalendarISOWeekNr(Date d) {
+ Calendar c = Calendar.getInstance();
+ c.setFirstDayOfWeek(Calendar.MONDAY);
+ c.setMinimalDaysInFirstWeek(4);
+ c.setTime(d);
+
+ return c.get(Calendar.WEEK_OF_YEAR);
+ }
+
+ private static Date getDate(int year, int month, int date) {
+ Calendar c = Calendar.getInstance();
+ c.clear();
+ c.set(year, month - 1, date);
+ return c.getTime();
+ }
+
+}
diff --git a/client/src/test/java/com/vaadin/client/LocatorUtilTest.java b/client/src/test/java/com/vaadin/client/LocatorUtilTest.java
new file mode 100644
index 0000000000..971688e1c5
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/LocatorUtilTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.client.componentlocator.LocatorUtil;
+
+/*
+ * Test LocatorUtil.isUIElement() & isNotificaitonElement methods
+ */
+public class LocatorUtilTest {
+
+ @Test
+ public void testIsUI1() {
+ boolean isUI = LocatorUtil.isUIElement("com.vaadin.ui.UI");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsUI2() {
+ boolean isUI = LocatorUtil.isUIElement("/com.vaadin.ui.UI");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsUI3() {
+ boolean isUI = LocatorUtil
+ .isUIElement("//com.vaadin.ui.UI[RandomString");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsUI4() {
+ boolean isUI = LocatorUtil.isUIElement("//com.vaadin.ui.UI[0]");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsNotification1() {
+ boolean isUI = LocatorUtil
+ .isNotificationElement("com.vaadin.ui.VNotification");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsNotification2() {
+ boolean isUI = LocatorUtil
+ .isNotificationElement("com.vaadin.ui.Notification");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsNotification3() {
+ boolean isUI = LocatorUtil
+ .isNotificationElement("/com.vaadin.ui.VNotification[");
+ Assert.assertTrue(isUI);
+ }
+
+ @Test
+ public void testIsNotification4() {
+ boolean isUI = LocatorUtil
+ .isNotificationElement("//com.vaadin.ui.VNotification[0]");
+ Assert.assertTrue(isUI);
+ }
+}
diff --git a/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java b/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java
new file mode 100644
index 0000000000..5522b8e2bc
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/VBrowserDetailsUserAgentParserTest.java
@@ -0,0 +1,651 @@
+package com.vaadin.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.shared.VBrowserDetails;
+
+public class VBrowserDetailsUserAgentParserTest {
+
+ private static final String FIREFOX30_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
+ private static final String FIREFOX30_LINUX = "Mozilla/5.0 (X11; U; Linux x86_64; es-ES; rv:1.9.0.12) Gecko/2009070811 Ubuntu/9.04 (jaunty) Firefox/3.0.12";
+ private static final String FIREFOX33_ANDROID = "Mozilla/5.0 (Android; Tablet; rv:33.0) Gecko/33.0 Firefox/33.0";
+ private static final String FIREFOX35_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729) FirePHP/0.4";
+ private static final String FIREFOX36_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)";
+ private static final String FIREFOX36B_MAC = "UAString mozilla/5.0 (macintosh; u; intel mac os x 10.6; en-us; rv:1.9.2) gecko/20100115 firefox/3.6";
+ private static final String FIREFOX_30B5_MAC = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5";
+ private static final String FIREFOX_40B7_WIN = "Mozilla/5.0 (Windows NT 5.1; rv:2.0b7) Gecko/20100101 Firefox/4.0b7";
+ private static final String FIREFOX_40B11_WIN = "Mozilla/5.0 (Windows NT 5.1; rv:2.0b11) Gecko/20100101 Firefox/4.0b11";
+ private static final String KONQUEROR_LINUX = "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Exabot-Thumbnails)";
+
+ private static final String IE6_WINDOWS = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
+ private static final String IE7_WINDOWS = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
+
+ private static final String IE8_WINDOWS = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
+ private static final String IE8_IN_IE7_MODE_WINDOWS = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
+
+ private static final String IE9_IN_IE7_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 7.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; .NET4.0C)";
+ private static final String IE9_BETA_IN_IE8_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)";
+ private static final String IE9_BETA_WINDOWS_7 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
+
+ private static final String IE10_WINDOWS_8 = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
+ private static final String IE11_WINDOWS_7 = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; rv:11.0) like Gecko";
+ private static final String IE11_WINDOWS_PHONE_8_1_UPDATE = "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 920) Like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537";
+
+ // "Version/" was added in 10.00
+ private static final String OPERA964_WINDOWS = "Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1";
+ private static final String OPERA1010_WINDOWS = "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.10";
+ private static final String OPERA1050_WINDOWS = "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.5.22 Version/10.50";
+
+ private static final String CHROME3_MAC = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.198 Safari/532.0";
+ private static final String CHROME4_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5";
+
+ private static final String SAFARI3_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 5.1; cs-CZ) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.29";
+ private static final String SAFARI4_MAC = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_8; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7";
+
+ private static final String IPHONE_IOS_5_1 = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3";
+ private static final String IPHONE_IOS_4_0 = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
+ private static final String IPAD_IOS_4_3_1 = "Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5";
+
+ // application on the home screen, without Safari in user agent
+ private static final String IPHONE_IOS_6_1_HOMESCREEN_SIMULATOR = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B141";
+
+ private static final String ANDROID_HTC_2_1 = "Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; ADR6300 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17";
+ private static final String ANDROID_GOOGLE_NEXUS_2_2 = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
+ private static final String ANDROID_MOTOROLA_3_0 = "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13";
+ private static final String ANDROID_GALAXY_NEXUS_4_0_4_CHROME = "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19";
+
+ 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";
+
+ @Test
+ public void testSafari3() {
+ VBrowserDetails bd = new VBrowserDetails(SAFARI3_WINDOWS);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 2);
+ assertEngineVersion(bd, 525.0f);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testSafari4() {
+ VBrowserDetails bd = new VBrowserDetails(SAFARI4_MAC);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 531f);
+ assertMacOSX(bd);
+ }
+
+ @Test
+ public void testIPhoneIOS6Homescreen() {
+ VBrowserDetails bd = new VBrowserDetails(
+ IPHONE_IOS_6_1_HOMESCREEN_SIMULATOR);
+ assertWebKit(bd);
+ // not identified as Safari, no browser version available
+ // assertSafari(bd);
+ // assertBrowserMajorVersion(bd, 6);
+ // assertBrowserMinorVersion(bd, 1);
+ assertEngineVersion(bd, 536f);
+ assertIOS(bd, 6, 1);
+ assertIPhone(bd);
+ }
+
+ @Test
+ public void testIPhoneIOS5() {
+ VBrowserDetails bd = new VBrowserDetails(IPHONE_IOS_5_1);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 5);
+ assertBrowserMinorVersion(bd, 1);
+ assertEngineVersion(bd, 534f);
+ assertIOS(bd, 5, 1);
+ assertIPhone(bd);
+ }
+
+ @Test
+ public void testIPhoneIOS4() {
+ VBrowserDetails bd = new VBrowserDetails(IPHONE_IOS_4_0);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 532f);
+ assertIOS(bd, 4, 0);
+ assertIPhone(bd);
+ }
+
+ @Test
+ public void testIPadIOS4() {
+ VBrowserDetails bd = new VBrowserDetails(IPAD_IOS_4_3_1);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 5);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 533f);
+ assertIOS(bd, 4, 3);
+ assertIPad(bd);
+ }
+
+ @Test
+ public void testAndroid21() {
+ VBrowserDetails bd = new VBrowserDetails(ANDROID_HTC_2_1);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 530f);
+ assertAndroid(bd, 2, 1);
+
+ }
+
+ @Test
+ public void testAndroid22() {
+ VBrowserDetails bd = new VBrowserDetails(ANDROID_GOOGLE_NEXUS_2_2);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 533f);
+ assertAndroid(bd, 2, 2);
+ }
+
+ @Test
+ public void testAndroid30() {
+ VBrowserDetails bd = new VBrowserDetails(ANDROID_MOTOROLA_3_0);
+ assertWebKit(bd);
+ assertSafari(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 534f);
+ assertAndroid(bd, 3, 0);
+ }
+
+ @Test
+ public void testAndroid40Chrome() {
+ VBrowserDetails bd = new VBrowserDetails(
+ ANDROID_GALAXY_NEXUS_4_0_4_CHROME);
+ assertWebKit(bd);
+ assertChrome(bd);
+ assertBrowserMajorVersion(bd, 18);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 535f);
+ assertAndroid(bd, 4, 0);
+ }
+
+ private void assertOSMajorVersion(VBrowserDetails bd, int i) {
+ assertEquals(i, bd.getOperatingSystemMajorVersion());
+ }
+
+ private void assertOSMinorVersion(VBrowserDetails bd, int i) {
+ assertEquals(i, bd.getOperatingSystemMinorVersion());
+ }
+
+ @Test
+ public void testChrome3() {
+ VBrowserDetails bd = new VBrowserDetails(CHROME3_MAC);
+ assertWebKit(bd);
+ assertChrome(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 532.0f);
+ assertMacOSX(bd);
+ }
+
+ @Test
+ public void testChrome4() {
+ VBrowserDetails bd = new VBrowserDetails(CHROME4_WINDOWS);
+ assertWebKit(bd);
+ assertChrome(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 532f);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testFirefox3() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX30_WINDOWS);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 1.9f);
+ assertWindows(bd);
+
+ bd = new VBrowserDetails(FIREFOX30_LINUX);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 1.9f);
+ assertLinux(bd);
+ }
+
+ @Test
+ public void testFirefox33Android() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX33_ANDROID);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 33);
+ assertBrowserMinorVersion(bd, 0);
+ assertAndroid(bd, -1, -1);
+ }
+
+ @Test
+ public void testFirefox35() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX35_WINDOWS);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 5);
+ assertEngineVersion(bd, 1.9f);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testFirefox36() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX36_WINDOWS);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 6);
+ assertEngineVersion(bd, 1.9f);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testFirefox30b5() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX_30B5_MAC);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 1.9f);
+ assertMacOSX(bd);
+ }
+
+ @Test
+ public void testFirefox40b11() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX_40B11_WIN);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 2.0f);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testFirefox40b7() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX_40B7_WIN);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 4);
+ assertBrowserMinorVersion(bd, 0);
+ assertEngineVersion(bd, 2.0f);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testKonquerorLinux() {
+ // Just ensure detection does not crash
+ VBrowserDetails bd = new VBrowserDetails(KONQUEROR_LINUX);
+ assertLinux(bd);
+ }
+
+ @Test
+ public void testFirefox36b() {
+ VBrowserDetails bd = new VBrowserDetails(FIREFOX36B_MAC);
+ assertGecko(bd);
+ assertFirefox(bd);
+ assertBrowserMajorVersion(bd, 3);
+ assertBrowserMinorVersion(bd, 6);
+ assertEngineVersion(bd, 1.9f);
+ assertMacOSX(bd);
+ }
+
+ @Test
+ public void testOpera964() {
+ VBrowserDetails bd = new VBrowserDetails(OPERA964_WINDOWS);
+ assertPresto(bd);
+ assertOpera(bd);
+ assertBrowserMajorVersion(bd, 9);
+ assertBrowserMinorVersion(bd, 64);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testOpera1010() {
+ VBrowserDetails bd = new VBrowserDetails(OPERA1010_WINDOWS);
+ assertPresto(bd);
+ assertOpera(bd);
+ assertBrowserMajorVersion(bd, 10);
+ assertBrowserMinorVersion(bd, 10);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testOpera1050() {
+ VBrowserDetails bd = new VBrowserDetails(OPERA1050_WINDOWS);
+ assertPresto(bd);
+ assertOpera(bd);
+ assertBrowserMajorVersion(bd, 10);
+ assertBrowserMinorVersion(bd, 50);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE6() {
+ VBrowserDetails bd = new VBrowserDetails(IE6_WINDOWS);
+ assertEngineVersion(bd, -1);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 6);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE7() {
+ VBrowserDetails bd = new VBrowserDetails(IE7_WINDOWS);
+ assertEngineVersion(bd, -1);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 7);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE8() {
+ VBrowserDetails bd = new VBrowserDetails(IE8_WINDOWS);
+ assertTrident(bd);
+ assertEngineVersion(bd, 4);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 8);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE8CompatibilityMode() {
+ VBrowserDetails bd = new VBrowserDetails(IE8_IN_IE7_MODE_WINDOWS);
+ bd.setIEMode(7);
+
+ assertTrident(bd);
+ assertEngineVersion(bd, 4);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 7);
+ assertBrowserMinorVersion(bd, 0);
+
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE9() {
+ VBrowserDetails bd = new VBrowserDetails(IE9_BETA_WINDOWS_7);
+ assertTrident(bd);
+ assertEngineVersion(bd, 5);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 9);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE9InIE7CompatibilityMode() {
+ VBrowserDetails bd = new VBrowserDetails(IE9_IN_IE7_MODE_WINDOWS_7);
+ // bd.setIE8InCompatibilityMode();
+
+ assertTrident(bd);
+ assertEngineVersion(bd, 5);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 7);
+ assertBrowserMinorVersion(bd, 0);
+
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE9InIE8CompatibilityMode() {
+ VBrowserDetails bd = new VBrowserDetails(IE9_BETA_IN_IE8_MODE_WINDOWS_7);
+ // bd.setIE8InCompatibilityMode();
+
+ /*
+ * Trident/4.0 in example user agent string based on beta even though it
+ * should be Trident/5.0 in real (non-beta) user agent strings
+ */
+ assertTrident(bd);
+ assertEngineVersion(bd, 4);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 8);
+ assertBrowserMinorVersion(bd, 0);
+
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE10() {
+ VBrowserDetails bd = new VBrowserDetails(IE10_WINDOWS_8);
+ assertTrident(bd);
+ assertEngineVersion(bd, 6);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 10);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE11() {
+ VBrowserDetails bd = new VBrowserDetails(IE11_WINDOWS_7);
+ assertTrident(bd);
+ assertEngineVersion(bd, 7);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 11);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd);
+ }
+
+ @Test
+ public void testIE11WindowsPhone81Update() {
+ VBrowserDetails bd = new VBrowserDetails(IE11_WINDOWS_PHONE_8_1_UPDATE);
+ assertTrident(bd);
+ assertEngineVersion(bd, 7);
+ assertIE(bd);
+ assertBrowserMajorVersion(bd, 11);
+ assertBrowserMinorVersion(bd, 0);
+ assertWindows(bd, true);
+ }
+
+ @Test
+ public void testEdgeWindows10() {
+ VBrowserDetails bd = new VBrowserDetails(EDGE_WINDOWS_10);
+ assertEdge(bd);
+ assertBrowserMajorVersion(bd, 12);
+ assertBrowserMinorVersion(bd, 10240);
+ assertWindows(bd, false);
+ }
+
+ /*
+ * Helper methods below
+ */
+
+ private void assertEngineVersion(VBrowserDetails browserDetails,
+ float version) {
+ assertEquals(version, browserDetails.getBrowserEngineVersion(), 0.01d);
+
+ }
+
+ private void assertBrowserMajorVersion(VBrowserDetails browserDetails,
+ int version) {
+ assertEquals(version, browserDetails.getBrowserMajorVersion());
+
+ }
+
+ private void assertBrowserMinorVersion(VBrowserDetails browserDetails,
+ int version) {
+ assertEquals(version, browserDetails.getBrowserMinorVersion());
+
+ }
+
+ private void assertGecko(VBrowserDetails browserDetails) {
+ // Engine
+ assertTrue(browserDetails.isGecko());
+ assertFalse(browserDetails.isWebKit());
+ assertFalse(browserDetails.isPresto());
+ assertFalse(browserDetails.isTrident());
+ }
+
+ private void assertPresto(VBrowserDetails browserDetails) {
+ // Engine
+ assertFalse(browserDetails.isGecko());
+ assertFalse(browserDetails.isWebKit());
+ assertTrue(browserDetails.isPresto());
+ assertFalse(browserDetails.isTrident());
+ }
+
+ private void assertTrident(VBrowserDetails browserDetails) {
+ // Engine
+ assertFalse(browserDetails.isGecko());
+ assertFalse(browserDetails.isWebKit());
+ assertFalse(browserDetails.isPresto());
+ assertTrue(browserDetails.isTrident());
+ }
+
+ private void assertWebKit(VBrowserDetails browserDetails) {
+ // Engine
+ assertFalse(browserDetails.isGecko());
+ assertTrue(browserDetails.isWebKit());
+ assertFalse(browserDetails.isPresto());
+ assertFalse(browserDetails.isTrident());
+ }
+
+ private void assertFirefox(VBrowserDetails browserDetails) {
+ // Browser
+ assertTrue(browserDetails.isFirefox());
+ assertFalse(browserDetails.isChrome());
+ assertFalse(browserDetails.isIE());
+ assertFalse(browserDetails.isOpera());
+ assertFalse(browserDetails.isSafari());
+ assertFalse(browserDetails.isEdge());
+ }
+
+ private void assertChrome(VBrowserDetails browserDetails) {
+ // Browser
+ assertFalse(browserDetails.isFirefox());
+ assertTrue(browserDetails.isChrome());
+ assertFalse(browserDetails.isIE());
+ assertFalse(browserDetails.isOpera());
+ assertFalse(browserDetails.isSafari());
+ assertFalse(browserDetails.isEdge());
+ }
+
+ private void assertIE(VBrowserDetails browserDetails) {
+ // Browser
+ assertFalse(browserDetails.isFirefox());
+ assertFalse(browserDetails.isChrome());
+ assertTrue(browserDetails.isIE());
+ assertFalse(browserDetails.isOpera());
+ assertFalse(browserDetails.isSafari());
+ assertFalse(browserDetails.isEdge());
+ }
+
+ private void assertOpera(VBrowserDetails browserDetails) {
+ // Browser
+ assertFalse(browserDetails.isFirefox());
+ assertFalse(browserDetails.isChrome());
+ assertFalse(browserDetails.isIE());
+ assertTrue(browserDetails.isOpera());
+ assertFalse(browserDetails.isSafari());
+ assertFalse(browserDetails.isEdge());
+ }
+
+ private void assertSafari(VBrowserDetails browserDetails) {
+ // Browser
+ assertFalse(browserDetails.isFirefox());
+ assertFalse(browserDetails.isChrome());
+ assertFalse(browserDetails.isIE());
+ assertFalse(browserDetails.isOpera());
+ assertTrue(browserDetails.isSafari());
+ assertFalse(browserDetails.isEdge());
+ }
+
+ private void assertEdge(VBrowserDetails browserDetails) {
+ // Browser
+ assertFalse(browserDetails.isFirefox());
+ assertFalse(browserDetails.isChrome());
+ assertFalse(browserDetails.isIE());
+ assertFalse(browserDetails.isOpera());
+ assertFalse(browserDetails.isSafari());
+ assertTrue(browserDetails.isEdge());
+ }
+
+ private void assertMacOSX(VBrowserDetails browserDetails) {
+ assertFalse(browserDetails.isLinux());
+ assertFalse(browserDetails.isWindows());
+ assertTrue(browserDetails.isMacOSX());
+ assertFalse(browserDetails.isAndroid());
+ }
+
+ private void assertAndroid(VBrowserDetails browserDetails,
+ int majorVersion, int minorVersion) {
+ assertFalse(browserDetails.isLinux());
+ assertFalse(browserDetails.isWindows());
+ assertFalse(browserDetails.isMacOSX());
+ assertFalse(browserDetails.isIOS());
+ assertTrue(browserDetails.isAndroid());
+
+ assertOSMajorVersion(browserDetails, majorVersion);
+ assertOSMinorVersion(browserDetails, minorVersion);
+ }
+
+ private void assertIOS(VBrowserDetails browserDetails, int majorVersion,
+ int minorVersion) {
+ assertFalse(browserDetails.isLinux());
+ assertFalse(browserDetails.isWindows());
+ assertFalse(browserDetails.isMacOSX());
+ assertTrue(browserDetails.isIOS());
+ assertFalse(browserDetails.isAndroid());
+
+ assertOSMajorVersion(browserDetails, majorVersion);
+ assertOSMinorVersion(browserDetails, minorVersion);
+ }
+
+ private void assertIPhone(VBrowserDetails browserDetails) {
+ assertTrue(browserDetails.isIPhone());
+ assertFalse(browserDetails.isIPad());
+ }
+
+ private void assertIPad(VBrowserDetails browserDetails) {
+ assertFalse(browserDetails.isIPhone());
+ assertTrue(browserDetails.isIPad());
+ }
+
+ 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) {
+ assertTrue(browserDetails.isLinux());
+ assertFalse(browserDetails.isWindows());
+ assertFalse(browserDetails.isMacOSX());
+ assertFalse(browserDetails.isIOS());
+ assertFalse(browserDetails.isAndroid());
+ }
+
+}
diff --git a/client/src/test/java/com/vaadin/client/communication/ServerMessageHandlerTest.java b/client/src/test/java/com/vaadin/client/communication/ServerMessageHandlerTest.java
new file mode 100644
index 0000000000..c2752f1953
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/communication/ServerMessageHandlerTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.communication;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ServerMessageHandlerTest {
+
+ @Test
+ public void unwrapValidJson() {
+ String payload = "{'foo': 'bar'}";
+ Assert.assertEquals(payload,
+ MessageHandler.stripJSONWrapping("for(;;);[" + payload + "]"));
+
+ }
+
+ @Test
+ public void unwrapUnwrappedJson() {
+ String payload = "{'foo': 'bar'}";
+ Assert.assertNull(MessageHandler.stripJSONWrapping(payload));
+
+ }
+
+ @Test
+ public void unwrapNull() {
+ Assert.assertNull(MessageHandler.stripJSONWrapping(null));
+
+ }
+
+ @Test
+ public void unwrapEmpty() {
+ Assert.assertNull(MessageHandler.stripJSONWrapping(""));
+
+ }
+}
diff --git a/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java b/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java
new file mode 100644
index 0000000000..24ccd6c57e
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.ui.grid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import com.vaadin.client.data.DataChangeHandler;
+import com.vaadin.client.widget.grid.datasources.ListDataSource;
+
+public class ListDataSourceTest {
+
+ @Test
+ public void testDataSourceConstruction() throws Exception {
+
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+
+ assertEquals(4, ds.size());
+ assertEquals(0, (int) ds.getRow(0));
+ assertEquals(1, (int) ds.getRow(1));
+ assertEquals(2, (int) ds.getRow(2));
+ assertEquals(3, (int) ds.getRow(3));
+
+ ds = new ListDataSource<Integer>(Arrays.asList(0, 1, 2, 3));
+
+ assertEquals(4, ds.size());
+ assertEquals(0, (int) ds.getRow(0));
+ assertEquals(1, (int) ds.getRow(1));
+ assertEquals(2, (int) ds.getRow(2));
+ assertEquals(3, (int) ds.getRow(3));
+ }
+
+ @Test
+ public void testListAddOperation() throws Exception {
+
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+
+ DataChangeHandler handler = EasyMock
+ .createNiceMock(DataChangeHandler.class);
+ ds.setDataChangeHandler(handler);
+
+ handler.dataAdded(4, 1);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(handler);
+
+ ds.asList().add(4);
+
+ assertEquals(5, ds.size());
+ assertEquals(0, (int) ds.getRow(0));
+ assertEquals(1, (int) ds.getRow(1));
+ assertEquals(2, (int) ds.getRow(2));
+ assertEquals(3, (int) ds.getRow(3));
+ assertEquals(4, (int) ds.getRow(4));
+ }
+
+ @Test
+ public void testListAddAllOperation() throws Exception {
+
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+
+ DataChangeHandler handler = EasyMock
+ .createNiceMock(DataChangeHandler.class);
+ ds.setDataChangeHandler(handler);
+
+ handler.dataAdded(4, 3);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(handler);
+
+ ds.asList().addAll(Arrays.asList(4, 5, 6));
+
+ assertEquals(7, ds.size());
+ assertEquals(0, (int) ds.getRow(0));
+ assertEquals(1, (int) ds.getRow(1));
+ assertEquals(2, (int) ds.getRow(2));
+ assertEquals(3, (int) ds.getRow(3));
+ assertEquals(4, (int) ds.getRow(4));
+ assertEquals(5, (int) ds.getRow(5));
+ assertEquals(6, (int) ds.getRow(6));
+ }
+
+ @Test
+ public void testListRemoveOperation() throws Exception {
+
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+
+ DataChangeHandler handler = EasyMock
+ .createNiceMock(DataChangeHandler.class);
+ ds.setDataChangeHandler(handler);
+
+ handler.dataRemoved(3, 1);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(handler);
+
+ ds.asList().remove(2);
+
+ assertEquals(3, ds.size());
+ assertEquals(0, (int) ds.getRow(0));
+ assertEquals(1, (int) ds.getRow(1));
+ assertEquals(3, (int) ds.getRow(2));
+ }
+
+ @Test
+ public void testListRemoveAllOperation() throws Exception {
+
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+
+ DataChangeHandler handler = EasyMock
+ .createNiceMock(DataChangeHandler.class);
+ ds.setDataChangeHandler(handler);
+
+ handler.dataRemoved(0, 3);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(handler);
+
+ ds.asList().removeAll(Arrays.asList(0, 2, 3));
+
+ assertEquals(1, ds.size());
+ assertEquals(1, (int) ds.getRow(0));
+ }
+
+ @Test
+ public void testListClearOperation() throws Exception {
+
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+
+ DataChangeHandler handler = EasyMock
+ .createNiceMock(DataChangeHandler.class);
+ ds.setDataChangeHandler(handler);
+
+ handler.dataRemoved(0, 4);
+ EasyMock.expectLastCall();
+
+ EasyMock.replay(handler);
+
+ ds.asList().clear();
+
+ assertEquals(0, ds.size());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testFetchingNonExistantItem() {
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+ ds.ensureAvailability(5, 1);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUnsupportedIteratorRemove() {
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(0, 1, 2, 3);
+ ds.asList().iterator().remove();
+ }
+
+ @Test
+ public void sortColumn() {
+ ListDataSource<Integer> ds = new ListDataSource<Integer>(3, 4, 2, 3, 1);
+
+ // TODO Should be simplified to sort(). No point in providing these
+ // trivial comparators.
+ ds.sort(new Comparator<Integer>() {
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ return o1.compareTo(o2);
+ }
+ });
+
+ assertTrue(Arrays.equals(ds.asList().toArray(), new Integer[] { 1, 2,
+ 3, 3, 4 }));
+ }
+
+}
diff --git a/client/src/test/java/com/vaadin/client/ui/grid/PartitioningTest.java b/client/src/test/java/com/vaadin/client/ui/grid/PartitioningTest.java
new file mode 100644
index 0000000000..e97bb339e4
--- /dev/null
+++ b/client/src/test/java/com/vaadin/client/ui/grid/PartitioningTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.client.ui.grid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.grid.Range;
+
+@SuppressWarnings("static-method")
+public class PartitioningTest {
+
+ @Test
+ public void selfRangeTest() {
+ final Range range = Range.between(0, 10);
+ final Range[] partitioning = range.partitionWith(range);
+
+ assertTrue("before is empty", partitioning[0].isEmpty());
+ assertTrue("inside is self", partitioning[1].equals(range));
+ assertTrue("after is empty", partitioning[2].isEmpty());
+ }
+
+ @Test
+ public void beforeRangeTest() {
+ final Range beforeRange = Range.between(0, 10);
+ final Range afterRange = Range.between(10, 20);
+ final Range[] partitioning = beforeRange.partitionWith(afterRange);
+
+ assertTrue("before is self", partitioning[0].equals(beforeRange));
+ assertTrue("inside is empty", partitioning[1].isEmpty());
+ assertTrue("after is empty", partitioning[2].isEmpty());
+ }
+
+ @Test
+ public void afterRangeTest() {
+ final Range beforeRange = Range.between(0, 10);
+ final Range afterRange = Range.between(10, 20);
+ final Range[] partitioning = afterRange.partitionWith(beforeRange);
+
+ assertTrue("before is empty", partitioning[0].isEmpty());
+ assertTrue("inside is empty", partitioning[1].isEmpty());
+ assertTrue("after is self", partitioning[2].equals(afterRange));
+ }
+
+ @Test
+ public void beforeAndInsideRangeTest() {
+ final Range beforeRange = Range.between(0, 10);
+ final Range afterRange = Range.between(5, 15);
+ final Range[] partitioning = beforeRange.partitionWith(afterRange);
+
+ assertEquals("before", Range.between(0, 5), partitioning[0]);
+ assertEquals("inside", Range.between(5, 10), partitioning[1]);
+ assertTrue("after is empty", partitioning[2].isEmpty());
+ }
+
+ @Test
+ public void insideRangeTest() {
+ final Range fullRange = Range.between(0, 20);
+ final Range insideRange = Range.between(5, 15);
+ final Range[] partitioning = insideRange.partitionWith(fullRange);
+
+ assertTrue("before is empty", partitioning[0].isEmpty());
+ assertEquals("inside", Range.between(5, 15), partitioning[1]);
+ assertTrue("after is empty", partitioning[2].isEmpty());
+ }
+
+ @Test
+ public void insideAndBelowTest() {
+ final Range beforeRange = Range.between(0, 10);
+ final Range afterRange = Range.between(5, 15);
+ final Range[] partitioning = afterRange.partitionWith(beforeRange);
+
+ assertTrue("before is empty", partitioning[0].isEmpty());
+ assertEquals("inside", Range.between(5, 10), partitioning[1]);
+ assertEquals("after", Range.between(10, 15), partitioning[2]);
+ }
+
+ @Test
+ public void aboveAndBelowTest() {
+ final Range fullRange = Range.between(0, 20);
+ final Range insideRange = Range.between(5, 15);
+ final Range[] partitioning = fullRange.partitionWith(insideRange);
+
+ assertEquals("before", Range.between(0, 5), partitioning[0]);
+ assertEquals("inside", Range.between(5, 15), partitioning[1]);
+ assertEquals("after", Range.between(15, 20), partitioning[2]);
+ }
+}