From 91800a4420d4ce1afc6904f0e77bd1e170cee763 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 7 Sep 2015 14:01:18 +0300 Subject: Test to validate that resynchronize/repaintAll actually resynchronizes Change-Id: Ib68f73e01fc0f545e0042a358d95a2b7185476ac --- .../vaadin/tests/application/ResynchronizeUI.java | 39 +++++++++++++ .../tests/application/ResynchronizeUITest.java | 65 ++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/application/ResynchronizeUI.java create mode 100644 uitest/src/com/vaadin/tests/application/ResynchronizeUITest.java (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/application/ResynchronizeUI.java b/uitest/src/com/vaadin/tests/application/ResynchronizeUI.java new file mode 100644 index 0000000000..62331ec95e --- /dev/null +++ b/uitest/src/com/vaadin/tests/application/ResynchronizeUI.java @@ -0,0 +1,39 @@ +/* + * 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.tests.application; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; + +public class ResynchronizeUI extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Button b = new Button("Resynchronize", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + // Theme change is currently the only operation which always + // does resynchronize + setTheme("runo"); + log("Set theme to runo"); + } + }); + addComponent(b); + } +} diff --git a/uitest/src/com/vaadin/tests/application/ResynchronizeUITest.java b/uitest/src/com/vaadin/tests/application/ResynchronizeUITest.java new file mode 100644 index 0000000000..4dd8292e23 --- /dev/null +++ b/uitest/src/com/vaadin/tests/application/ResynchronizeUITest.java @@ -0,0 +1,65 @@ +/* + * 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.tests.application; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.StaleElementReferenceException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ResynchronizeUITest extends SingleBrowserTest { + + @Override + public List getBrowsersToTest() { + // PhantomJS does not send onload events for styles + return Collections.singletonList(Browser.FIREFOX + .getDesiredCapabilities()); + } + + @Test + public void ensureResynchronizeRecreatesDOM() { + openTestURL(); + ButtonElement button = $(ButtonElement.class).first(); + button.click(); + // Click causes repaint, after this the old button element should no + // longer be available + // Ensure that the theme has changed + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver input) { + WebElement app = input.findElement(By.className("v-app")); + return hasCssClass(app, "runo"); + } + }); + try { + button.click(); + Assert.fail("The old button element should have been removed by the click and replaced by a new one."); + } catch (StaleElementReferenceException e) { + // This is what should happen + } + } +} -- cgit v1.2.3