diff options
12 files changed, 381 insertions, 40 deletions
diff --git a/WebContent/VAADIN/themes/reindeer/tabsheet/tabsheet-normal-style.scss b/WebContent/VAADIN/themes/reindeer/tabsheet/tabsheet-normal-style.scss index b62791e4ce..e6b1a669c6 100644 --- a/WebContent/VAADIN/themes/reindeer/tabsheet/tabsheet-normal-style.scss +++ b/WebContent/VAADIN/themes/reindeer/tabsheet/tabsheet-normal-style.scss @@ -143,6 +143,7 @@ } .v-sa & .#{$primaryStyleName}-tabs .v-captiontext { display: inline-block; + vertical-align: middle; } .#{$primaryStyleName}-tabs .v-icon { width: 16px !important; diff --git a/client/src/com/vaadin/client/LayoutManager.java b/client/src/com/vaadin/client/LayoutManager.java index 4fb656b16d..fbf540273f 100644 --- a/client/src/com/vaadin/client/LayoutManager.java +++ b/client/src/com/vaadin/client/LayoutManager.java @@ -75,6 +75,15 @@ public class LayoutManager { } /** + * Returns the application connection for this layout manager. + * + * @return connection + */ + protected ApplicationConnection getConnection() { + return connection; + } + + /** * Gets the layout manager associated with the given * {@link ApplicationConnection}. * diff --git a/client/src/com/vaadin/client/LayoutManagerIE8.java b/client/src/com/vaadin/client/LayoutManagerIE8.java index a692f126a2..b7973310db 100644 --- a/client/src/com/vaadin/client/LayoutManagerIE8.java +++ b/client/src/com/vaadin/client/LayoutManagerIE8.java @@ -19,8 +19,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Node; import com.google.gwt.user.client.ui.RootPanel; /** @@ -39,6 +39,12 @@ public class LayoutManagerIE8 extends LayoutManager { private Map<Element, MeasuredSize> measuredSizes = new HashMap<Element, MeasuredSize>(); + // this method is needed to test for memory leaks (see + // LayoutMemoryUsageIE8ExtensionConnector) but can be private + private int getMeasuredSizesMapSize() { + return measuredSizes.size(); + } + @Override protected void setMeasuredSize(Element element, MeasuredSize measuredSize) { if (measuredSize != null) { @@ -62,12 +68,18 @@ public class LayoutManagerIE8 extends LayoutManager { @Override protected void cleanMeasuredSizes() { Profiler.enter("LayoutManager.cleanMeasuredSizes"); - Document document = RootPanel.get().getElement().getOwnerDocument(); + + // #12688: IE8 was leaking memory when adding&removing components. + // Uses IE specific logic to figure if an element has been removed from + // DOM or not. For this the parent element of the current UI is needed. + // For removed elements the measured size is discarded. + Node rootNode = getConnection().getUIConnector().getWidget() + .getElement().getParentNode(); Iterator<Element> i = measuredSizes.keySet().iterator(); while (i.hasNext()) { Element e = i.next(); - if (e.getOwnerDocument() != document) { + if (!rootNode.isOrHasChild(e)) { i.remove(); } } diff --git a/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java b/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java index ba661e3f32..9109162a31 100644 --- a/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java +++ b/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java @@ -19,11 +19,70 @@ import java.io.Serializable; import java.lang.annotation.ElementType; import java.lang.annotation.Target; +/** + * Signals that the property value from a state class should be forwarded to the + * Widget of the corresponding connector instance. + * <p> + * When this annotation is present on a field or on a setter method, the + * framework will call the corresponding setter in the Connector's Widget + * instance with the current state property value whenever it has been changed. + * This is happens after firing + * {@link com.vaadin.client.ConnectorHierarchyChangeEvent}s but before firing + * any {@link com.vaadin.client.communication.StateChangeEvent}. + * <p> + * Take for example a state class looking like this: + * + * <pre> + * public class MyComponentState extends AbstractComponentState { + * @DelegateToWidget + * public String myProperty; + * } + * </pre> + * + * Whenever <code>myProperty</code> is changed, the framework will call code + * like this: + * + * <pre> + * connector.getWidget().setMyProperty(connector.getState().myProperty); + * </pre> + * + * <p> + * By default, the Widget method to call is derived from the property name, but + * {@link #value()} in the annotation can be used to provide a custom method + * name, e.g. {@code @DelegateToWidget("someSpecialName")}. + * + * @since 7.0.0 + * @author Vaadin Ltd + */ @Target({ ElementType.METHOD, ElementType.FIELD }) public @interface DelegateToWidget { + /** + * Defines the name of the Widget method to call when the annotated state + * property has changed. If no value is defined, the method name will be + * derived from the property name, so e.g. a field named + * <code>myProperty</code> will delegate to a method named + * <code>setMyProperty</code>. + * + * @return the name of the method to delegate to, or empty string to use the + * default name + */ public String value() default ""; + /** + * Internal helper for handling default values in a uniform way both at + * runtime and during widgetset compilation. + */ public static class Helper implements Serializable { + /** + * Gets the name of the method to delegate to for a given property name + * and annotation value. + * + * @param propertyName + * the name of the delegated property + * @param annotationValue + * the {@link DelegateToWidget#value()} of the annotation + * @return the name of the method to delegate to + */ public static String getDelegateTarget(String propertyName, String annotationValue) { String name = annotationValue; diff --git a/uitest/src/com/vaadin/tests/VerifyJreVersion.html b/uitest/src/com/vaadin/tests/VerifyJreVersion.html deleted file mode 100644 index abf53883c1..0000000000 --- a/uitest/src/com/vaadin/tests/VerifyJreVersion.html +++ /dev/null @@ -1,26 +0,0 @@ -<?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>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.VerifyJreVersion?restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestsVerifyJreVersion::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td> - <td>Using Java 1.6.0_32 by Sun Microsystems Inc.</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/VerifyJreVersion.java b/uitest/src/com/vaadin/tests/VerifyJreVersion.java index fe3e4bd870..a41955f826 100644 --- a/uitest/src/com/vaadin/tests/VerifyJreVersion.java +++ b/uitest/src/com/vaadin/tests/VerifyJreVersion.java @@ -29,7 +29,10 @@ public class VerifyJreVersion extends AbstractTestUI { protected void setup(VaadinRequest request) { String jreVersion = "Using Java " + System.getProperty("java.version") + " by " + System.getProperty("java.vendor"); - addComponent(new Label(jreVersion)); + Label jreVersionLabel = new Label(jreVersion); + jreVersionLabel.setId("jreVersionLabel"); + + addComponent(jreVersionLabel); } @Override diff --git a/uitest/src/com/vaadin/tests/VerifyJreVersionTest.java b/uitest/src/com/vaadin/tests/VerifyJreVersionTest.java new file mode 100644 index 0000000000..aba120ac0b --- /dev/null +++ b/uitest/src/com/vaadin/tests/VerifyJreVersionTest.java @@ -0,0 +1,38 @@ +/* + * 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; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class VerifyJreVersionTest extends MultiBrowserTest { + + @Test + public void verifyJreVersion() { + openTestURL(); + + WebElement jreVersionLabel = vaadinElementById("jreVersionLabel"); + + assertThat(jreVersionLabel.getText(), + is("Using Java 1.6.0_45 by Sun Microsystems Inc.")); + } + +} diff --git a/uitest/src/com/vaadin/tests/extensions/LayoutMemoryUsageIE8Extension.java b/uitest/src/com/vaadin/tests/extensions/LayoutMemoryUsageIE8Extension.java new file mode 100644 index 0000000000..c69c2b4d30 --- /dev/null +++ b/uitest/src/com/vaadin/tests/extensions/LayoutMemoryUsageIE8Extension.java @@ -0,0 +1,36 @@ +/* + * 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.extensions; + +import com.vaadin.server.AbstractExtension; +import com.vaadin.ui.UI; + +/** + * Test extension for finding out the size of the measuredSizes map of + * LayoutManagerIE8. + * + * This UI extension uses JSNI to register a JavaScript method + * window.vaadin.getMeasuredSizesCount() that can be used to query the size of + * the internal map of the layout manager. It should only be used on IE8. + * + * @since 7.1.13 + * @author Vaadin Ltd + */ +public class LayoutMemoryUsageIE8Extension extends AbstractExtension { + public void extend(UI target) { + super.extend(target); + } +} diff --git a/uitest/src/com/vaadin/tests/layouts/IE8MeasuredSizeMemoryLeak.java b/uitest/src/com/vaadin/tests/layouts/IE8MeasuredSizeMemoryLeak.java new file mode 100644 index 0000000000..7da9e46653 --- /dev/null +++ b/uitest/src/com/vaadin/tests/layouts/IE8MeasuredSizeMemoryLeak.java @@ -0,0 +1,111 @@ +/* + * 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.layouts; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.extensions.LayoutMemoryUsageIE8Extension; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.HasComponents; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class IE8MeasuredSizeMemoryLeak extends AbstractTestUI { + + private boolean state = false; + + private HasComponents component1 = new VerticalLayout() { + { + for (int i = 1; i <= 200; i++) { + String idText = "ID:" + i; + Label c = new Label(idText); + c.setId(idText); + addComponent(c); + } + } + }; + + private HasComponents component2 = new VerticalLayout() { + { + for (int i = 201; i <= 400; i++) { + String idText = "ID:" + i; + Label c = new Label(idText); + c.setId(idText); + addComponent(c); + } + } + }; + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + new LayoutMemoryUsageIE8Extension().extend(this); + + VerticalLayout layout = new VerticalLayout(); + setContent(layout); + + final VerticalLayout contentLayout = new VerticalLayout(); + + Button button = new Button("Toggle"); + button.setId("toggle"); + button.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + contentLayout.removeAllComponents(); + if (state) { + contentLayout.addComponent(component1); + } else { + contentLayout.addComponent(component2); + } + state = !state; + } + + }); + + layout.addComponent(button); + layout.addComponent(contentLayout); + + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "IE8 leaks memory when components are added and removed"; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 12688; + } +} diff --git a/uitest/src/com/vaadin/tests/layouts/IE8MeasuredSizeMemoryLeakTest.java b/uitest/src/com/vaadin/tests/layouts/IE8MeasuredSizeMemoryLeakTest.java new file mode 100644 index 0000000000..c9bd64c881 --- /dev/null +++ b/uitest/src/com/vaadin/tests/layouts/IE8MeasuredSizeMemoryLeakTest.java @@ -0,0 +1,54 @@ +/* + * 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.layouts; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class IE8MeasuredSizeMemoryLeakTest extends MultiBrowserTest { + + @Test + public void testMeasuredSizesMapCleaned() { + openTestURL(); + Assert.assertEquals("No extra measured sizes in the beginning", 3, + getMeasuredSizesMapSize()); + vaadinElementById("toggle").click(); + Assert.assertEquals("Measured sizes after single toggle", 204, + getMeasuredSizesMapSize()); + vaadinElementById("toggle").click(); + Assert.assertEquals("Measured sizes cleaned on toggle", 204, + getMeasuredSizesMapSize()); + } + + private int getMeasuredSizesMapSize() { + JavascriptExecutor jsExec = (JavascriptExecutor) getDriver(); + Number result = (Number) jsExec + .executeScript("return window.vaadin.getMeasuredSizesCount();"); + return result.intValue(); + } + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + return Collections.singletonList(Browser.IE8.getDesiredCapabilities()); + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java index 543484fc14..400a2fe429 100644 --- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java +++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java @@ -120,20 +120,19 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { Enumeration<NetworkInterface> interfaces = NetworkInterface .getNetworkInterfaces(); while (interfaces.hasMoreElements()) { - NetworkInterface current = interfaces.nextElement(); - if (!current.isUp() || current.isLoopback() - || current.isVirtual()) { + NetworkInterface nwInterface = interfaces.nextElement(); + if (!nwInterface.isUp() || nwInterface.isLoopback() + || nwInterface.isVirtual()) { continue; } - Enumeration<InetAddress> addresses = current.getInetAddresses(); + Enumeration<InetAddress> addresses = nwInterface.getInetAddresses(); while (addresses.hasMoreElements()) { - InetAddress current_addr = addresses.nextElement(); - if (current_addr.isLoopbackAddress()) { + InetAddress address = addresses.nextElement(); + if (address.isLoopbackAddress()) { continue; } - String hostAddress = current_addr.getHostAddress(); - if (hostAddress.startsWith("192.168.")) { - return hostAddress; + if (address.isSiteLocalAddress()) { + return address.getHostAddress(); } } } @@ -142,7 +141,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { } throw new RuntimeException( - "No compatible (192.168.*) ip address found."); + "No compatible (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) ip address found."); } /* diff --git a/uitest/src/com/vaadin/tests/widgetset/client/LayoutMemoryUsageIE8ExtensionConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/LayoutMemoryUsageIE8ExtensionConnector.java new file mode 100644 index 0000000000..c92e688520 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/LayoutMemoryUsageIE8ExtensionConnector.java @@ -0,0 +1,45 @@ +/* + * 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.widgetset.client; + +import com.vaadin.client.BrowserInfo; +import com.vaadin.client.LayoutManager; +import com.vaadin.client.LayoutManagerIE8; +import com.vaadin.client.ServerConnector; +import com.vaadin.client.extensions.AbstractExtensionConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.extensions.LayoutMemoryUsageIE8Extension; + +@Connect(LayoutMemoryUsageIE8Extension.class) +public class LayoutMemoryUsageIE8ExtensionConnector extends + AbstractExtensionConnector { + + @Override + protected void extend(ServerConnector target) { + if (BrowserInfo.get().isIE8()) { + LayoutManagerIE8 manager = (LayoutManagerIE8) LayoutManager + .get(getConnection()); + configureGetMapSizeJS(manager); + } + } + + private native void configureGetMapSizeJS(LayoutManagerIE8 manager) + /*-{ + $wnd.vaadin.getMeasuredSizesCount = function() { + return manager.@com.vaadin.client.LayoutManagerIE8::getMeasuredSizesMapSize()(); + }; + }-*/; +} |