diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-11-23 20:11:33 +0300 |
---|---|---|
committer | Denis Anisimov <denis@vaadin.com> | 2016-11-29 16:03:31 +0300 |
commit | 8ba529503b6caee2d7755f292fb1f9f985943e78 (patch) | |
tree | a84eae038a6f6944947835ac5e121decaef0927b /uitest | |
parent | d2ce5362fffe4d85b95762a02f5e68a980af7789 (diff) | |
download | vaadin-framework-8ba529503b6caee2d7755f292fb1f9f985943e78.tar.gz vaadin-framework-8ba529503b6caee2d7755f292fb1f9f985943e78.zip |
Provide access to window order position in windows stack (#14325).
Change-Id: I259c659987b5b15b354e16d0be1523f4ede809f0
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/window/WindowOrder.java | 175 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/window/WindowOrderTest.java | 182 |
2 files changed, 357 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/window/WindowOrder.java b/uitest/src/main/java/com/vaadin/tests/components/window/WindowOrder.java new file mode 100644 index 0000000000..d3a17006ba --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/window/WindowOrder.java @@ -0,0 +1,175 @@ +/* + * 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.window; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; +import com.vaadin.ui.Window.WindowOrderChangeEvent; +import com.vaadin.ui.Window.WindowOrderChangeListener; + +/** + * Test UI for accessing to window order position. + * + * @author Vaadin Ltd + */ +public class WindowOrder extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + w1 = new Window(); + w1.setCaption("Window1"); + w1.addStyleName("window1"); + + w2 = new Window(); + w2.setCaption("Window2"); + w2.addStyleName("window2"); + + w3 = new Window(); + w3.setCaption("Window3"); + w3.addStyleName("window3"); + + getUI().addWindow(w1); + getUI().addWindow(w2); + getUI().addWindow(w3); + OrderListener listener = new OrderListener(); + for (Window window : getUI().getWindows()) { + window.addWindowOrderChangeListener(listener); + } + + w4 = new Window(); + w4.setCaption("Window4"); + w4.addStyleName("window4"); + w4.addWindowOrderChangeListener(listener); + + infoLabel = createLabel("info-label"); + uiLabel = createLabel("ui-label"); + + getUI().addWindowOrderUpdateListener(new WindowOrderListener()); + + addComponent(infoLabel); + addComponent(uiLabel); + + Button first = new Button("Bring first to front", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + w1.bringToFront(); + } + }); + first.addStyleName("bring-to-front-first"); + addComponent(first); + getLayout().setComponentAlignment(first, Alignment.MIDDLE_RIGHT); + + Button all = new Button("Bring to front all windows", + new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + w3.bringToFront(); + w1.bringToFront(); + w2.bringToFront(); + } + }); + all.addStyleName("bring-to-front-all"); + addComponent(all); + getLayout().setComponentAlignment(all, Alignment.MIDDLE_RIGHT); + + Button detach = new Button("Detach last window", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + getUI().removeWindow(w3); + } + }); + detach.addStyleName("detach-window"); + addComponent(detach); + getLayout().setComponentAlignment(detach, Alignment.MIDDLE_RIGHT); + + Button add = new Button("Add new window", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + getUI().addWindow(w4); + } + }); + add.addStyleName("add-window"); + addComponent(add); + getLayout().setComponentAlignment(add, Alignment.MIDDLE_RIGHT); + } + + @Override + protected String getTestDescription() { + return "Window order position access and listeners for order change events."; + } + + @Override + protected Integer getTicketNumber() { + return 14325; + } + + private Label createLabel(String style) { + Label label = new Label(); + label.addStyleName(style); + return label; + } + + private class OrderListener implements WindowOrderChangeListener { + + @Override + public void windowOrderChanged(WindowOrderChangeEvent event) { + infoLabel.removeStyleName("w4--1"); + infoLabel.addStyleName("w4-" + w4.getOrderPosition()); + + if (event.getWindow() == w3 && event.getOrder() == -1) { + Label detached = new Label("Window 3 is detached"); + detached.addStyleName("w3-detached"); + detached.addStyleName("w3-" + w3.getOrderPosition()); + addComponent(detached); + } + + Window window = event.getWindow(); + Label label = new Label(String.valueOf(window.getOrderPosition())); + label.addStyleName("event-order" + event.getOrder()); + window.setContent(label); + } + } + + private class WindowOrderListener implements WindowOrderUpdateListener { + + @Override + public void windowOrderUpdated(WindowOrderUpdateEvent event) { + uiLabel.removeStyleName(infoLabel.getStyleName()); + for (Window window : event.getWindows()) { + uiLabel.addStyleName( + window.getStyleName() + "-" + window.getOrderPosition()); + } + } + } + + private Window w1; + private Window w2; + private Window w3; + private Window w4; + private Label infoLabel; + + private Label uiLabel; +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/WindowOrderTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/WindowOrderTest.java new file mode 100644 index 0000000000..c3faea3d39 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/window/WindowOrderTest.java @@ -0,0 +1,182 @@ +/* + * 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.window; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for window order position access. + * + * @author Vaadin Ltd + */ +public class WindowOrderTest extends MultiBrowserTest { + + @Test + public void orderGetterTest() { + openTestURL(); + + checkPositionsAfterFirstWindowActivation(); + + checkPositionsAfterActivationThirdFirstSecond(); + + checkPositionsAfterDetachingThirdWindow(); + + checkPositionsAfterNewWindowAttach(); + } + + private void checkPositionsAfterFirstWindowActivation() { + // Bring the first window to front and check order positions of the + // windows + findElement(By.className("bring-to-front-first")).click(); + Assert.assertTrue( + "The first window has wrong order position after bring first to front", + hasOrder("window1", 2)); + Assert.assertTrue( + "The first window position is incorrectly updated via UI listener after bring first to front", + hasOrderInUi("window1", 2)); + Assert.assertTrue( + "The second window has wrong order position after bring first to front", + hasOrder("window2", 0)); + Assert.assertTrue( + "The second window position is incorrectly updated via UI after bring first to front", + hasOrderInUi("window2", 0)); + Assert.assertTrue( + "The third window has wrong order position after bring first to front", + hasOrder("window3", 1)); + Assert.assertTrue( + "The third window position is incorrectly updated via UI after bring first to front", + hasOrderInUi("window3", 1)); + Assert.assertTrue( + "Last window is not attached and should have '-1' position, but hasn't.", + lastWindowHasOrder(-1)); + } + + private void checkPositionsAfterActivationThirdFirstSecond() { + // Bring third, first and second window at once (exactly in this order) + // to front and check order positions of the + // windows + findElement(By.className("bring-to-front-all")).click(); + + Assert.assertTrue( + "The first window has wrong order position after bring all to front", + hasOrder("window2", 2)); + Assert.assertTrue( + "The first window position is incorrectly updated via UI after bring all to front", + hasOrderInUi("window2", 2)); + Assert.assertTrue( + "The second window has wrong order position after bring all to front", + hasOrder("window1", 1)); + Assert.assertTrue( + "The second window position is incorrectly updated via UI after bring all to front", + hasOrderInUi("window1", 1)); + Assert.assertTrue( + "The third window has wrong order position after bring all to front", + hasOrder("window3", 0)); + Assert.assertTrue( + "The third window position is incorrectly updated via UI after bring all to front", + hasOrderInUi("window3", 0)); + Assert.assertTrue( + "Last window is not attached and should have '-1' position, but hasn't.", + lastWindowHasOrder(-1)); + } + + private void checkPositionsAfterDetachingThirdWindow() { + // Detach third window and check order positions of the + // windows + findElement(By.className("detach-window")).click(); + + Assert.assertTrue( + "The first window has wrong order position after detach last window", + hasOrder("window2", 1)); + Assert.assertTrue( + "The first window position is incorrectly updated after detach last window", + hasOrderInUi("window2", 1)); + Assert.assertTrue( + "The second window has wrong order position after detach last window", + hasOrder("window1", 0)); + Assert.assertTrue( + "The second window position is incorrectly updated after detach last window", + hasOrderInUi("window1", 0)); + WebElement thirdWindowInfo = findElement(By.className("w3-detached")); + Assert.assertTrue("The third window has wrong order after detach", + thirdWindowInfo.getAttribute("class").contains("w3--1")); + Assert.assertTrue( + "The third window position is incorrectly updated after detach last window", + hasOrderInUi("window3", -1)); + Assert.assertTrue( + "Last window is not attached and should have '-1' position, but hasn't.", + lastWindowHasOrder(-1)); + } + + private void checkPositionsAfterNewWindowAttach() { + // Attach new window and check order positions of the + // windows + findElement(By.className("add-window")).click(); + + Assert.assertTrue( + "The first window has wrong order position after add new window", + hasOrder("window2", 1)); + Assert.assertTrue( + "The first window position is incorrectly updated after add new window", + hasOrderInUi("window2", 1)); + Assert.assertTrue( + "The second window has wrong order position after add new window", + hasOrder("window1", 0)); + Assert.assertTrue( + "The second window position is incorrectly updated after add new window", + hasOrderInUi("window1", 0)); + Assert.assertTrue( + "The last window has wrong order position after add new window", + hasOrder("window4", 2)); + Assert.assertTrue( + "The last window position is incorrectly updated after add new window", + hasOrderInUi("window4", 2)); + } + + private WebElement findElement(String styleName) { + return findElement(By.className(styleName)); + } + + private boolean hasOrder(String window, int order) { + WebElement win = findElement(window); + WebElement content = win.findElement(By.className("v-label")); + return content.getText().equals(String.valueOf(order)) && content + .getAttribute("class").contains("event-order" + order); + } + + private boolean hasOrderInUi(String window, int order) { + WebElement uiLabel = findElement(By.className("ui-label")); + return uiLabel.getAttribute("class").contains(window + '-' + order); + } + + private boolean lastWindowHasOrder(int order) { + WebElement info = findElement("info-label"); + String clazz = info.getAttribute("class"); + String style = "w4-" + order; + boolean hasOrder = clazz.contains(style); + if (!hasOrder) { + return false; + } + clazz = clazz.replace(style, ""); + return !clazz.contains("w4"); + } + +} |