From 74aa5c73811658782624b1cb761533ae2e8040d8 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Fri, 9 Jan 2015 18:34:28 +0200 Subject: Disallow layoutNow() while updating the state (#13611) Change-Id: Ic519cbfb6507566a46d0313455695c4a40de55b8 --- .../layoutmanager/LayoutDuringStateUpdate.java | 32 +++++++++++ .../layoutmanager/LayoutDuringStateUpdateTest.java | 36 +++++++++++++ .../client/LayoutDuringStateUpdateConnector.java | 62 ++++++++++++++++++++++ .../server/LayoutDuringStateUpdateComponent.java | 7 +++ 4 files changed, 137 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdate.java create mode 100644 uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdateTest.java create mode 100644 uitest/src/com/vaadin/tests/widgetset/client/LayoutDuringStateUpdateConnector.java create mode 100644 uitest/src/com/vaadin/tests/widgetset/server/LayoutDuringStateUpdateComponent.java (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdate.java b/uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdate.java new file mode 100644 index 0000000000..cfebfef004 --- /dev/null +++ b/uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdate.java @@ -0,0 +1,32 @@ +/* + * 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.layoutmanager; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.server.LayoutDuringStateUpdateComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class LayoutDuringStateUpdate extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(new LayoutDuringStateUpdateComponent()); + } + +} diff --git a/uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdateTest.java b/uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdateTest.java new file mode 100644 index 0000000000..8c71d460bb --- /dev/null +++ b/uitest/src/com/vaadin/tests/layoutmanager/LayoutDuringStateUpdateTest.java @@ -0,0 +1,36 @@ +/* + * 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.layoutmanager; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class LayoutDuringStateUpdateTest extends SingleBrowserTest { + + @Test + public void layoutDuringStateUpdate() { + openTestURL(); + + WebElement label = findElement(By.className("gwt-Label")); + + Assert.assertEquals("Layout phase count: 1", label.getText()); + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/LayoutDuringStateUpdateConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/LayoutDuringStateUpdateConnector.java new file mode 100644 index 0000000000..799fe9ebee --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/LayoutDuringStateUpdateConnector.java @@ -0,0 +1,62 @@ +/* + * 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.widgetset.client; + +import com.google.gwt.user.client.ui.Label; +import com.vaadin.client.communication.StateChangeEvent; +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.client.ui.PostLayoutListener; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.LayoutDuringStateUpdateComponent; + +@Connect(LayoutDuringStateUpdateComponent.class) +public class LayoutDuringStateUpdateConnector extends + AbstractComponentConnector implements PostLayoutListener { + private int layoutCount = 0; + + @Override + protected void init() { + super.init(); + updateLabelText(); + } + + @Override + public Label getWidget() { + return (Label) super.getWidget(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + try { + getLayoutManager().layoutNow(); + } catch (AssertionError e) { + // Ignore + } + } + + private void updateLabelText() { + getWidget().setText("Layout phase count: " + layoutCount); + } + + @Override + public void postLayout() { + layoutCount++; + updateLabelText(); + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/LayoutDuringStateUpdateComponent.java b/uitest/src/com/vaadin/tests/widgetset/server/LayoutDuringStateUpdateComponent.java new file mode 100644 index 0000000000..f12b8726cc --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/LayoutDuringStateUpdateComponent.java @@ -0,0 +1,7 @@ +package com.vaadin.tests.widgetset.server; + +import com.vaadin.ui.AbstractComponent; + +public class LayoutDuringStateUpdateComponent extends AbstractComponent { + +} -- cgit v1.2.3