diff options
author | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-04-05 10:38:28 +0000 |
---|---|---|
committer | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-04-05 10:38:28 +0000 |
commit | 2a88c95e39bdca3e779ff4e9eb44208dfbe3e8d3 (patch) | |
tree | dde74f29de9f872215f44c7c6ea5d4e7ac5bdaaf /tests/server-side/com/vaadin | |
parent | c48774888da8fc7b073d715c97a0ee08aa52cf8c (diff) | |
download | vaadin-framework-2a88c95e39bdca3e779ff4e9eb44208dfbe3e8d3.tar.gz vaadin-framework-2a88c95e39bdca3e779ff4e9eb44208dfbe3e8d3.zip |
Fixed #6155: stop listening to Property value change and read only status change events on detach to avoid a potential memory leak, resume listening on attach
svn changeset:23406/svn branch:6.8
Diffstat (limited to 'tests/server-side/com/vaadin')
-rw-r--r-- | tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java b/tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java new file mode 100644 index 0000000000..32b80e0bcd --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java @@ -0,0 +1,72 @@ +package com.vaadin.tests.server.component.abstractfield; + +import static org.junit.Assert.assertEquals; + +import com.vaadin.data.Property; +import com.vaadin.data.util.AbstractProperty; +import com.vaadin.ui.AbstractField; + +import org.junit.Test; + +public class RemoveListenersOnDetach { + + int numValueChanges = 0; + int numReadOnlyChanges = 0; + + AbstractField field = new AbstractField() { + @Override + public Class<?> getType() { + return null; + } + + @Override + public void valueChange(Property.ValueChangeEvent event) { + super.valueChange(event); + numValueChanges++; + } + + @Override + public void readOnlyStatusChange( + Property.ReadOnlyStatusChangeEvent event) { + super.readOnlyStatusChange(event); + numReadOnlyChanges++; + } + }; + + Property property = new AbstractProperty() { + public Object getValue() { + return null; + } + + public void setValue(Object newValue) throws ReadOnlyException, + ConversionException { + fireValueChange(); + } + + public Class<?> getType() { + return null; + } + }; + + @Test + public void testAttachDetach() { + field.setPropertyDataSource(property); + + property.setValue(null); + property.setReadOnly(true); + assertEquals(1, numValueChanges); + assertEquals(1, numReadOnlyChanges); + + field.attach(); + property.setValue(null); + property.setReadOnly(false); + assertEquals(2, numValueChanges); + assertEquals(2, numReadOnlyChanges); + + field.detach(); + property.setValue(null); + property.setReadOnly(true); + assertEquals(2, numValueChanges); + assertEquals(2, numReadOnlyChanges); + } +} |