summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-07-12 20:11:41 +0300
committerVaadin Code Review <review@vaadin.com>2015-09-09 05:35:29 +0000
commit53aea4ad61d3713f637c45c530842fca6b7f1d81 (patch)
treed43f75841f00a84fe4823086fe81ef2d158dacd9 /uitest
parent938d28fd942c4a1921631e9afab0b690b2b1fe74 (diff)
downloadvaadin-framework-53aea4ad61d3713f637c45c530842fca6b7f1d81.tar.gz
vaadin-framework-53aea4ad61d3713f637c45c530842fca6b7f1d81.zip
Always do layout if there are connectors pending layout or measure (#16992)
Change-Id: I6ca8f3a1ca9c0a2d537c694812f4831efdeb8e08
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java117
-rw-r--r--uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java48
-rw-r--r--uitest/src/com/vaadin/tests/customelements/CustomProgressBarElement.java56
3 files changed, 221 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java b/uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java
new file mode 100644
index 0000000000..9f63970f85
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java
@@ -0,0 +1,117 @@
+package com.vaadin.tests.components;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.ProgressBar;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+@SuppressWarnings("serial")
+@Theme("valo")
+public class NoLayoutUpdateWhichNeedsLayout extends UI {
+
+ private ProgressBar progressBar;
+ private Window w;
+
+ @Override
+ protected void init(VaadinRequest request) {
+ final VerticalLayout layout = new VerticalLayout();
+ layout.setMargin(true);
+ setContent(layout);
+
+ setPollInterval(1000);
+
+ Button button = new Button(
+ "1. Execute scheduled task and show progress in a window");
+ button.setId("openWindow");
+ button.addClickListener(new Button.ClickListener() {
+
+ private Window w2;
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ GridLayout glo = new GridLayout();
+ progressBar = new ProgressBar();
+ progressBar.setIndeterminate(false);
+ progressBar.setId("progress");
+ glo.addComponent(progressBar);
+
+ w2 = new Window("test");
+ w2.setWidth("600px");
+ w2.setHeight("200px");
+ w2.setContent(glo);
+ w2.center();
+ Button closeB = new Button(
+ "2. Click to close after the progress is updated");
+ closeB.setId("closeWindow");
+ closeB.addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ w2.close();
+ w2 = null;
+ }
+ });
+ glo.addComponent(closeB);
+ addWindow(w2);
+
+ scheduleTask();
+ }
+ });
+
+ Button openWin = new Button("3. Finally, Click to open a new Window");
+ openWin.addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ w = new Window("test");
+ w.setWidth("300px");
+ w.setHeight("300px");
+ w.setContent(new VerticalLayout(new Label(
+ "simple test label component")));
+ w.center();
+ getUI().addWindow(w);
+ }
+ });
+
+ Button stopPolling = new Button("Stop polling", new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ setPollInterval(-1);
+ }
+ });
+ layout.addComponents(button, openWin, stopPolling);
+ }
+
+ protected void scheduleTask() {
+ Thread t = new Thread() {
+
+ @Override
+ public void run() {
+ getUI().access(new Runnable() {
+ @Override
+ public void run() {
+ updateProgresBar(50);
+ }
+ });
+ }
+ };
+ ScheduledExecutorService worker = Executors
+ .newSingleThreadScheduledExecutor();
+ worker.schedule(t, 2, TimeUnit.SECONDS);
+ }
+
+ public void updateProgresBar(int pc) {
+ progressBar.setValue((float) (pc / 100.0));
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java b/uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java
new file mode 100644
index 0000000000..bc12919ccd
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.components;
+
+import org.junit.Test;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.customelements.CustomProgressBarElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class NoLayoutUpdateWhichNeedsLayoutTest extends SingleBrowserTest {
+
+ @Test
+ public void layoutRunForNoLayoutUpdate() {
+ openTestURL("debug");
+ ButtonElement open = $(ButtonElement.class).id("openWindow");
+ open.click();
+ final CustomProgressBarElement progress = $(
+ CustomProgressBarElement.class).first();
+ waitUntil(new ExpectedCondition<Boolean>() {
+ @Override
+ public Boolean apply(WebDriver input) {
+ double p = progress.getValue();
+ return Math.abs(p - 0.5) < 0.01;
+ }
+ });
+
+ ButtonElement close = $(ButtonElement.class).id("closeWindow");
+ close.click();
+
+ assertNoErrorNotifications();
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/customelements/CustomProgressBarElement.java b/uitest/src/com/vaadin/tests/customelements/CustomProgressBarElement.java
new file mode 100644
index 0000000000..d43b8a1b3f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/customelements/CustomProgressBarElement.java
@@ -0,0 +1,56 @@
+/*
+ * 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.customelements;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ProgressBarElement;
+import com.vaadin.testbench.elementsbase.ServerClass;
+
+@ServerClass("com.vaadin.ui.ProgressBar")
+public class CustomProgressBarElement extends ProgressBarElement {
+
+ public double getValue() {
+ WebElement indicator = findElement(By
+ .className("v-progressbar-indicator"));
+ String width = getStyleAttribute(indicator, "width");
+ if (!width.endsWith("%")) {
+ return 0;
+ }
+
+ return Double.parseDouble(width.replace("%", "")) / 100.0;
+ }
+
+ /**
+ * @since
+ * @param indicator
+ * @param string
+ * @return
+ */
+ private String getStyleAttribute(WebElement element, String styleName) {
+ String style = element.getAttribute("style");
+ String[] styles = style.split(";");
+ for (String s : styles) {
+ if (s.startsWith(styleName + ":")) {
+ return s.substring(styleName.length() + 1).trim();
+ }
+ }
+
+ return null;
+ }
+
+}