diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-10-10 12:49:52 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2013-10-10 12:49:52 +0300 |
commit | fd48caf6896d63a1bc4f42738e69bfb3b2d37cef (patch) | |
tree | d76385457b90a95c9b878b90299e37b4d5dd0fa4 | |
parent | 333d6515eded5f819eb2fd5b39255b5042e667f5 (diff) | |
parent | 07ca622a6b2edcf7a253762cf222155bdf460a88 (diff) | |
download | vaadin-framework-fd48caf6896d63a1bc4f42738e69bfb3b2d37cef.tar.gz vaadin-framework-fd48caf6896d63a1bc4f42738e69bfb3b2d37cef.zip |
Merge changes from origin/7.1
ffb33be Update slider client-side state object on value change (#12676)
b8828e7 Only publish files actually produced by this test/browser
5966f01 reduce reflow and calculation in VOverlay (#12566)
600f5f3 Do not try to focus invisible components which not present in UIDL #12654
d0e604f Only print testbench failure TeamCity messages when running in TC
0e9ff32 Ported regression fixes in 6.8 for #12407 to 7.1 branch
267a4ca Fix OptionGroup elements losing focus on value change (#10451)
07ca622 Fixes #12564 (HorizontalLayout breaks w/ alignment & error indicator)
Change-Id: I73bd688d390bcec9ea3c92a2ede4cad3c9daf7dc
13 files changed, 450 insertions, 88 deletions
diff --git a/client/src/com/vaadin/client/ui/VOptionGroup.java b/client/src/com/vaadin/client/ui/VOptionGroup.java index a4c8b6733c..455c7669f5 100644 --- a/client/src/com/vaadin/client/ui/VOptionGroup.java +++ b/client/src/com/vaadin/client/ui/VOptionGroup.java @@ -95,11 +95,29 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, } /* - * Return true if no elements were changed, false otherwise. + * Try to update content of existing elements, rebuild panel entirely + * otherwise */ @Override public void buildOptions(UIDL uidl) { - panel.clear(); + /* + * In order to retain focus, we need to update values rather than + * recreate panel from scratch (#10451). However, the panel will be + * rebuilt (losing focus) if number of elements or their order is + * changed. + */ + HashMap<String, CheckBox> keysToOptions = new HashMap<String, CheckBox>(); + for (Map.Entry<CheckBox, String> entry : optionsToKeys.entrySet()) { + keysToOptions.put(entry.getValue(), entry.getKey()); + } + ArrayList<Widget> existingwidgets = new ArrayList<Widget>(); + ArrayList<Widget> newwidgets = new ArrayList<Widget>(); + + // Get current order of elements + for (Widget wid : panel) { + existingwidgets.add(wid); + } + optionsEnabled.clear(); if (isMultiselect()) { @@ -110,7 +128,6 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) { final UIDL opUidl = (UIDL) it.next(); - CheckBox op; String itemHtml = opUidl.getStringAttribute("caption"); if (!htmlContentAllowed) { @@ -124,32 +141,48 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler, + Icon.CLASSNAME + "\" alt=\"\" />" + itemHtml; } - if (isMultiselect()) { - op = new VCheckBox(); - op.setHTML(itemHtml); - } else { - op = new RadioButton(paintableId, itemHtml, true); - op.setStyleName("v-radiobutton"); - } + String key = opUidl.getStringAttribute("key"); + CheckBox op = keysToOptions.get(key); + if (op == null) { + // Create a new element + if (isMultiselect()) { + op = new VCheckBox(); + } else { + op = new RadioButton(paintableId); + op.setStyleName("v-radiobutton"); + } + if (icon != null && icon.length() != 0) { + Util.sinkOnloadForImages(op.getElement()); + op.addHandler(iconLoadHandler, LoadEvent.getType()); + } - if (icon != null && icon.length() != 0) { - Util.sinkOnloadForImages(op.getElement()); - op.addHandler(iconLoadHandler, LoadEvent.getType()); + op.addStyleName(CLASSNAME_OPTION); + op.addClickHandler(this); + + optionsToKeys.put(op, key); } - op.addStyleName(CLASSNAME_OPTION); + op.setHTML(itemHtml); op.setValue(opUidl.getBooleanAttribute("selected")); boolean optionEnabled = !opUidl .getBooleanAttribute(OptionGroupConstants.ATTRIBUTE_OPTION_DISABLED); boolean enabled = optionEnabled && !isReadonly() && isEnabled(); op.setEnabled(enabled); optionsEnabled.add(optionEnabled); + setStyleName(op.getElement(), ApplicationConnection.DISABLED_CLASSNAME, !(optionEnabled && isEnabled())); - op.addClickHandler(this); - optionsToKeys.put(op, opUidl.getStringAttribute("key")); - panel.add(op); + + newwidgets.add(op); + } + + if (!newwidgets.equals(existingwidgets)) { + // Rebuild the panel, losing focus + panel.clear(); + for (Widget wid : newwidgets) { + panel.add(wid); + } } } diff --git a/client/src/com/vaadin/client/ui/VOverlay.java b/client/src/com/vaadin/client/ui/VOverlay.java index 206e26b960..72c92d94ef 100644 --- a/client/src/com/vaadin/client/ui/VOverlay.java +++ b/client/src/com/vaadin/client/ui/VOverlay.java @@ -248,10 +248,6 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> { return isShadowEnabled() && shadow.getParentElement() != null; } - private boolean isShimElementAttached() { - return shimElement != null && shimElement.hasParentElement(); - } - private void adjustZIndex() { setZIndex(Z_INDEX); } @@ -469,36 +465,51 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> { getOffsetWidth(); } - PositionAndSize positionAndSize = new PositionAndSize(getActualLeft(), - getActualTop(), getOffsetWidth(), getOffsetHeight()); + if (isShadowEnabled() || needsShimElement()) { + + PositionAndSize positionAndSize = new PositionAndSize( + getActualLeft(), getActualTop(), getOffsetWidth(), + getOffsetHeight()); + + // Animate the size + positionAndSize.setAnimationFromCenterProgress(progress); + + Element container = getElement().getParentElement().cast(); - // Animate the size - positionAndSize.setAnimationFromCenterProgress(progress); + if (isShadowEnabled()) { + updateShadowPosition(progress, zIndex, positionAndSize); + if (shadow.getParentElement() == null) { + container.insertBefore(shadow, getElement()); + sinkShadowEvents(); + } + } + + if (needsShimElement()) { + updateShimPosition(positionAndSize); + if (shimElement.getParentElement() == null) { + container.insertBefore(shimElement, getElement()); + } + } + } + } + private void updateShadowPosition(final double progress, String zIndex, + PositionAndSize positionAndSize) { // Opera needs some shaking to get parts of the shadow showing - // properly - // (ticket #2704) - if (BrowserInfo.get().isOpera() && isShadowEnabled()) { + // properly (ticket #2704) + if (BrowserInfo.get().isOpera()) { // Clear the height of all middle elements DOM.getChild(shadow, 3).getStyle().setProperty("height", "auto"); DOM.getChild(shadow, 4).getStyle().setProperty("height", "auto"); DOM.getChild(shadow, 5).getStyle().setProperty("height", "auto"); } - // Update correct values - if (isShadowEnabled()) { - updatePositionAndSize(shadow, positionAndSize); - DOM.setStyleAttribute(shadow, "zIndex", zIndex); - DOM.setStyleAttribute(shadow, "display", progress < 0.9 ? "none" - : ""); - } - if (needsShimElement()) { - updatePositionAndSize((Element) Element.as(getShimElement()), - positionAndSize); - } + updatePositionAndSize(shadow, positionAndSize); + DOM.setStyleAttribute(shadow, "zIndex", zIndex); + DOM.setStyleAttribute(shadow, "display", progress < 0.9 ? "none" : ""); // Opera fix, part 2 (ticket #2704) - if (BrowserInfo.get().isOpera() && isShadowEnabled()) { + if (BrowserInfo.get().isOpera()) { // We'll fix the height of all the middle elements DOM.getChild(shadow, 3) .getStyle() @@ -513,17 +524,11 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> { .setPropertyPx("height", DOM.getChild(shadow, 5).getOffsetHeight()); } + } - Element container = getElement().getParentElement().cast(); - // Attach to dom if not there already - if (isShadowEnabled() && !isShadowAttached()) { - container.insertBefore(shadow, getElement()); - sinkShadowEvents(); - } - if (needsShimElement() && !isShimElementAttached()) { - container.insertBefore(getShimElement(), getElement()); - } - + private void updateShimPosition(PositionAndSize positionAndSize) { + updatePositionAndSize((Element) Element.as(getShimElement()), + positionAndSize); } /** diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index b5a3086add..6b2893f2bb 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -1113,14 +1113,16 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private ScheduledCommand lazyScroller = new ScheduledCommand() { @Override public void execute() { - if (firstvisibleOnLastPage > -1) { - scrollBodyPanel - .setScrollPosition(measureRowHeightOffset(firstvisibleOnLastPage)); - } else { - scrollBodyPanel - .setScrollPosition(measureRowHeightOffset(firstvisible)); + if (firstvisible > 0) { + firstRowInViewPort = firstvisible; + if (firstvisibleOnLastPage > -1) { + scrollBodyPanel + .setScrollPosition(measureRowHeightOffset(firstvisibleOnLastPage)); + } else { + scrollBodyPanel + .setScrollPosition(measureRowHeightOffset(firstvisible)); + } } - firstRowInViewPort = firstvisible; } }; @@ -1131,17 +1133,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets, firstvisibleOnLastPage = uidl.hasVariable("firstvisibleonlastpage") ? uidl .getIntVariable("firstvisibleonlastpage") : -1; if (firstvisible != lastRequestedFirstvisible && scrollBody != null) { - // received 'surprising' firstvisible from server: scroll there - firstRowInViewPort = firstvisible; + // Update lastRequestedFirstvisible right away here // (don't rely on update in the timer which could be cancelled). lastRequestedFirstvisible = firstRowInViewPort; - /* - * Schedule the scrolling to be executed last so no updates to the - * rows affect scrolling measurements. - */ - Scheduler.get().scheduleFinally(lazyScroller); + // Only scroll if the first visible changes from the server side. + // Else we might unintentionally scroll even when the scroll + // position has not changed. + Scheduler.get().scheduleDeferred(lazyScroller); } } @@ -2160,7 +2160,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, isNewBody = false; - Scheduler.get().scheduleFinally(lazyScroller); + if (firstvisible > 0) { + Scheduler.get().scheduleDeferred(lazyScroller); + } if (enabled) { // Do we need cache rows diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index e0dc0d51df..ec4307e50b 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -19,6 +19,7 @@ import java.util.List; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorHierarchyChangeEvent; @@ -611,13 +612,14 @@ public abstract class AbstractOrderedLayoutConnector extends LayoutManager layoutManager = getLayoutManager(); for (ComponentConnector child : getChildComponents()) { - Slot slot = getWidget().getSlot(child.getWidget()); + Widget childWidget = child.getWidget(); + Slot slot = getWidget().getSlot(childWidget); Element captionElement = slot.getCaptionElement(); - CaptionPosition pos = slot.getCaptionPosition(); + CaptionPosition captionPosition = slot.getCaptionPosition(); - Element childElement = child.getWidget().getElement(); - int h = layoutManager.getOuterHeight(childElement); - if (h == -1) { + int pixelHeight = layoutManager.getOuterHeight(childWidget + .getElement()); + if (pixelHeight == -1) { // Height has not yet been measured -> postpone actions that // depend on the max height return -1; @@ -625,14 +627,10 @@ public abstract class AbstractOrderedLayoutConnector extends boolean hasRelativeHeight = slot.hasRelativeHeight(); + boolean captionSizeShouldBeAddedtoComponentHeight = captionPosition == CaptionPosition.TOP + || captionPosition == CaptionPosition.BOTTOM; boolean includeCaptionHeight = captionElement != null - && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM); - if (!hasRelativeHeight && !includeCaptionHeight - && captionElement != null) { - String sHeight = childElement.getStyle().getHeight(); - includeCaptionHeight = (sHeight == null || !sHeight - .endsWith("%")); - } + && captionSizeShouldBeAddedtoComponentHeight; if (includeCaptionHeight) { int captionHeight = layoutManager @@ -643,16 +641,16 @@ public abstract class AbstractOrderedLayoutConnector extends // depend on the max height return -1; } - h += captionHeight; + pixelHeight += captionHeight; } if (!hasRelativeHeight) { - if (h > highestNonRelative) { - highestNonRelative = h; + if (pixelHeight > highestNonRelative) { + highestNonRelative = pixelHeight; } } else { - if (h > highestRelative) { - highestRelative = h; + if (pixelHeight > highestRelative) { + highestRelative = pixelHeight; } } } diff --git a/client/src/com/vaadin/client/ui/slider/SliderConnector.java b/client/src/com/vaadin/client/ui/slider/SliderConnector.java index e6e3e0467d..71462d69f0 100644 --- a/client/src/com/vaadin/client/ui/slider/SliderConnector.java +++ b/client/src/com/vaadin/client/ui/slider/SliderConnector.java @@ -52,6 +52,7 @@ public class SliderConnector extends AbstractFieldConnector implements @Override public void onValueChange(ValueChangeEvent<Double> event) { + getState().value = event.getValue(); rpc.valueChanged(event.getValue()); } diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 45005ddd9f..903a2cc3fb 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -315,6 +315,11 @@ public class UIConnector extends AbstractSingleComponentContainerConnector ComponentConnector paintable = (ComponentConnector) uidl .getPaintableAttribute("focused", getConnection()); + if (paintable == null) { + // Do not try to focus invisible components which not present in UIDL + return; + } + final Widget toBeFocused = paintable.getWidget(); /* * Two types of Widgets can be focused, either implementing diff --git a/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroupRetainFocusKeyboardValueChange.html b/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroupRetainFocusKeyboardValueChange.html new file mode 100644 index 0000000000..046cac0e30 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroupRetainFocusKeyboardValueChange.html @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title>OptionGroupRetainFocusKeyboardValueChange</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">OptionGroupRetainFocusKeyboardValueChange</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/OptionGroupRetainFocusKeyboardValueChange?restartApplication</td> + <td></td> +</tr> +<tr> + <td>pressSpecialKey</td> + <td>vaadin=runOptionGroupRetainFocusKeyboardValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VOptionGroup[0]/domChild[0]/domChild[0]</td> + <td>space</td> +</tr> +<!-- The element 'A' should be selected and focused --> +<tr> + <td>screenCapture</td> + <td></td> + <td></td> +</tr> +<tr> + <td>pressSpecialKey</td> + <td>vaadin=runOptionGroupRetainFocusKeyboardValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VOptionGroup[0]/domChild[0]/domChild[0]</td> + <td>down</td> +</tr> +<!-- The element 'B' should be selected and focused, the caption of first element is changed from 'A' to 'A+' --> +<tr> + <td>screenCapture</td> + <td></td> + <td></td> +</tr> +<tr> + <td>pressSpecialKey</td> + <td>vaadin=runOptionGroupRetainFocusKeyboardValueChange::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VOptionGroup[0]/domChild[1]/domChild[0]</td> + <td>down</td> +</tr> +<!-- Elements 'B' and 'C' should be swapped; 'C' selected but not focused --> +<tr> + <td>screenCapture</td> + <td></td> + <td></td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroupRetainFocusKeyboardValueChange.java b/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroupRetainFocusKeyboardValueChange.java new file mode 100644 index 0000000000..570a300cb3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/optiongroup/OptionGroupRetainFocusKeyboardValueChange.java @@ -0,0 +1,70 @@ +/* + * 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.tests.components.optiongroup; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.OptionGroup; + +/** + * Testcase for #10451 + * + * @author Vaadin Ltd + */ +public class OptionGroupRetainFocusKeyboardValueChange extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final OptionGroup optiongroup = new OptionGroup(); + optiongroup.addItem(1); + optiongroup.addItem(2); + optiongroup.addItem(3); + optiongroup.setItemCaption(1, "A"); + optiongroup.setItemCaption(2, "B"); + optiongroup.setItemCaption(3, "C"); + optiongroup.setImmediate(true); + + optiongroup.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + if (optiongroup.isSelected(2)) { + optiongroup.setItemCaption(1, "A+"); + } else if (optiongroup.isSelected(3)) { + optiongroup.removeItem(2); + optiongroup.addItem(2); + optiongroup.setItemCaption(2, "B"); + } + } + }); + + addComponent(optiongroup); + + optiongroup.focus(); + } + + @Override + protected String getTestDescription() { + return "OptionGroup should retain focus after it's value being changed with keyboard"; + } + + @Override + protected Integer getTicketNumber() { + return 10451; + } +} diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java new file mode 100644 index 0000000000..25675e07c5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutFullsizeContentWithErrorMsg.java @@ -0,0 +1,96 @@ +package com.vaadin.tests.components.orderedlayout; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; + +import com.vaadin.server.UserError; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.tb3.MultiBrowserTest; +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.HorizontalLayout; +import com.vaadin.ui.TextField; + +public class HorizontalLayoutFullsizeContentWithErrorMsg extends AbstractTestUI { + + private static final String FIELD_ID = "f"; + private static final String BUTTON_ID = "b"; + private TextField tf; + + @Override + protected Integer getTicketNumber() { + return 12564; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + HorizontalLayout hl = new HorizontalLayout(); + hl.setWidth("500px"); + + tf = new TextField(); + tf.setId(FIELD_ID); + tf.setWidth("100%"); + hl.addComponent(tf); + hl.setExpandRatio(tf, 1); + hl.setComponentAlignment(tf, Alignment.MIDDLE_CENTER); + + Button toggleError = new Button("Toggle error"); + toggleError.setId(BUTTON_ID); + toggleError.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + tf.setComponentError(tf.getComponentError() == null ? new UserError( + "foo") : null); + } + }); + hl.addComponent(toggleError); + + addComponent(hl); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "TextField should remain at same level vertically, horizontally width should adjust to fit error indicator."; + } + + public static class TbTest extends MultiBrowserTest { + + @Test + public void test() { + openTestURL(); + WebElement element = getDriver().findElement(By.id(FIELD_ID)); + Point location = element.getLocation(); + + WebElement errorToggleButton = getDriver().findElement( + By.id(BUTTON_ID)); + + errorToggleButton.click(); + + Assert.assertEquals(location, element.getLocation()); + + errorToggleButton.click(); + + Assert.assertEquals(location, element.getLocation()); + + } + + } + +} diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java b/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java new file mode 100644 index 0000000000..ea29a1657c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/slider/SliderDisable.java @@ -0,0 +1,81 @@ +/* + * 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.tests.components.slider; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Slider; +import com.vaadin.ui.VerticalLayout; + +public class SliderDisable extends AbstractTestUI { + + public static class SliderDisableTest extends MultiBrowserTest { + @Test + public void disableSlider() throws IOException { + openTestURL(); + WebElement element = vaadinElement("/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]"); + new Actions(driver).dragAndDropBy(element, 112, 0).perform(); + compareScreen("enabled"); + vaadinElementById("disableButton").click(); + compareScreen("disabled"); + } + } + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout content = new VerticalLayout(); + content.setMargin(true); + content.setSpacing(true); + + final Slider slider = new Slider(0, 5); + slider.setWidth(200, Unit.PIXELS); + slider.setValue(1.0D); + + Button disableButton = new Button("Disable slider"); + disableButton.setId("disableButton"); + disableButton.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + slider.setEnabled(false); + } + }); + + content.addComponent(slider); + content.addComponent(disableButton); + setContent(content); + } + + @Override + protected String getTestDescription() { + return "The apparent value of the slider should not change when the slider is disabled"; + } + + @Override + protected Integer getTicketNumber() { + return 12676; + } + +} diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index 565d04fdb9..94bcebde84 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -72,9 +72,11 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { protected void failed(Throwable e, Description description) { // Notify Teamcity of failed test - System.out.print("##teamcity[publishArtifacts '"); - System.out.println(getScreenshotErrorDirectory() + "/" - + getScreenshotBaseName() + "* => screenshot-errors']"); + if (!System.getProperty("teamcity.version", "").equals("")) { + System.out.print("##teamcity[publishArtifacts '"); + System.out.println(getScreenshotErrorBaseName() + + "* => screenshot-errors']"); + } } }; diff --git a/uitest/tb3test.xml b/uitest/tb3test.xml index 92008ff9f3..de69e0ebe6 100644 --- a/uitest/tb3test.xml +++ b/uitest/tb3test.xml @@ -19,12 +19,21 @@ <target name="run-tb3-suite"> <fail unless="junit.test.suite" message="Define suite to run using junit.test.suite" /> <fail unless="com.vaadin.testbench.screenshot.directory" message="Define screenshot directory using -Dcom.vaadin.testbench.screenshot.directory" /> + + <!-- Ensure teamcity.version is set to something --> + <condition property="teamcity.version" value=""> + <not> + <isset property="teamcity.version" /> + </not> + </condition> + <junit printsummary="withOutAndErr" fork="yes"> <formatter usefile="false" type="plain" /> <classpath refid="classpath.tb3" /> <jvmarg value="-Dcom.vaadin.testbench.screenshot.directory=${com.vaadin.testbench.screenshot.directory}" /> <jvmarg value="-Djava.awt.headless=true" /> + <jvmarg value="-Dteamcity.version=${teamcity.version}" /> <test name="${junit.test.suite}" /> </junit> diff --git a/uitest/test.xml b/uitest/test.xml index 88b5238c09..c534d676b9 100644 --- a/uitest/test.xml +++ b/uitest/test.xml @@ -134,12 +134,18 @@ </batchtest> </junit> - <!-- Have teamcity publish each test error artifact immediatly if there are any --> - <basename property="basename" file="${target}" suffix="java" /> - <echo>##teamcity[publishArtifacts '${com.vaadin.testbench.screenshot.directory}/errors/${basename}* => screenshot-errors']</echo> + <antcall target="notify-teamcity-of-build-artifact"> + <param name="file" value="${target}" /> + </antcall> </target> + <!-- Have teamcity publish each test error artifact immediatly if there are any --> + <target name="notify-teamcity-of-build-artifact" if="teamcity.version"> + <basename property="basename" file="${file}" suffix="java" /> + <echo>##teamcity[publishArtifacts '${com.vaadin.testbench.screenshot.directory}/errors/${basename}* => screenshot-errors']</echo> + </target> + <!-- Remove temporary source and compiled java files --> <target name="remove-temp-testclasses"> <delete failonerror="false"> |