|
|
@@ -3,12 +3,17 @@ package com.vaadin.tests.server.component.window; |
|
|
|
import static org.junit.Assert.assertSame; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
import com.vaadin.server.ClientConnector; |
|
|
|
import com.vaadin.server.VaadinRequest; |
|
|
|
import com.vaadin.server.VaadinSession; |
|
|
|
import com.vaadin.tests.util.AlwaysLockedVaadinSession; |
|
|
|
import com.vaadin.ui.HasComponents.ComponentAttachEvent; |
|
|
|
import com.vaadin.ui.HasComponents.ComponentAttachListener; |
|
|
|
import com.vaadin.ui.HasComponents.ComponentDetachEvent; |
|
|
|
import com.vaadin.ui.HasComponents.ComponentDetachListener; |
|
|
|
import com.vaadin.ui.Label; |
|
|
|
import com.vaadin.ui.UI; |
|
|
|
import com.vaadin.ui.VerticalLayout; |
|
|
@@ -213,6 +218,45 @@ public class AttachDetachWindow { |
|
|
|
assertDetached(sub); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void addWindow_attachEventIsFired() { |
|
|
|
TestUI ui = new TestUI(); |
|
|
|
final Window window = new Window(); |
|
|
|
|
|
|
|
final boolean[] eventFired = new boolean[1]; |
|
|
|
ui.addComponentAttachListener(new ComponentAttachListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void componentAttachedToContainer(ComponentAttachEvent event) { |
|
|
|
eventFired[0] = event.getAttachedComponent().equals(window); |
|
|
|
} |
|
|
|
}); |
|
|
|
ui.addWindow(window); |
|
|
|
Assert.assertTrue("Attach event is not fired for added window", |
|
|
|
eventFired[0]); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void removeWindow_detachEventIsFired() { |
|
|
|
TestUI ui = new TestUI(); |
|
|
|
final Window window = new Window(); |
|
|
|
|
|
|
|
final boolean[] eventFired = new boolean[1]; |
|
|
|
ui.addComponentDetachListener(new ComponentDetachListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void componentDetachedFromContainer( |
|
|
|
ComponentDetachEvent event) { |
|
|
|
eventFired[0] = event.getDetachedComponent().equals(window); |
|
|
|
} |
|
|
|
}); |
|
|
|
ui.addWindow(window); |
|
|
|
ui.removeWindow(window); |
|
|
|
|
|
|
|
Assert.assertTrue("Detach event is not fired for removed window", |
|
|
|
eventFired[0]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Asserts that win and its children are attached to testApp and their |
|
|
|
* attach() methods have been called. |