diff options
Diffstat (limited to 'tests')
3 files changed, 314 insertions, 6 deletions
diff --git a/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java b/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java new file mode 100644 index 0000000000..8daee1ba65 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java @@ -0,0 +1,179 @@ +package com.vaadin.tests.server.component.window;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import com.vaadin.Application;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+import org.junit.Test;
+
+public class AttachDetachWindow {
+
+ private Application testApp = new Application() {
+ @Override
+ public void init() {
+ }
+ };
+
+ private class TestWindow extends Window {
+ boolean windowAttachCalled = false;
+ boolean contentAttachCalled = false;
+ boolean childAttachCalled = false;
+ boolean windowDetachCalled = false;
+ boolean contentDetachCalled = false;
+ boolean childDetachCalled = false;
+
+ TestWindow() {
+ setContent(new VerticalLayout() {
+ @Override
+ public void attach() {
+ super.attach();
+ contentAttachCalled = true;
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ contentDetachCalled = true;
+ }
+ });
+ addComponent(new Label() {
+ @Override
+ public void attach() {
+ super.attach();
+ childAttachCalled = true;
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ childDetachCalled = true;
+ }
+ });
+ }
+
+ Component getChild() {
+ return getComponentIterator().next();
+ }
+
+ @Override
+ public void attach() {
+ super.attach();
+ windowAttachCalled = true;
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ windowDetachCalled = true;
+ }
+ }
+
+ TestWindow main = new TestWindow();
+ TestWindow sub = new TestWindow();
+
+ @Test
+ public void addSubWindowBeforeAttachingMainWindow() {
+ assertUnattached(main);
+ assertUnattached(sub);
+
+ main.addWindow(sub);
+ assertUnattached(main);
+ assertUnattached(sub);
+
+ // attaching main should recurse to sub
+ testApp.setMainWindow(main);
+ assertAttached(main);
+ assertAttached(sub);
+ }
+
+ @Test
+ public void addSubWindowAfterAttachingMainWindow() {
+ assertUnattached(main);
+ assertUnattached(sub);
+
+ testApp.setMainWindow(main);
+ assertAttached(main);
+ assertUnattached(sub);
+
+ // main is already attached, so attach should be called for sub
+ main.addWindow(sub);
+ assertAttached(main);
+ assertAttached(sub);
+ }
+
+ @Test
+ public void removeSubWindowBeforeDetachingMainWindow() {
+ testApp.addWindow(main);
+ main.addWindow(sub);
+
+ // sub should be detached when removing from attached main
+ main.removeWindow(sub);
+ assertAttached(main);
+ assertDetached(sub);
+
+ // main detach should recurse to sub
+ testApp.removeWindow(main);
+ assertDetached(main);
+ assertDetached(sub);
+ }
+
+ @Test
+ public void removeSubWindowAfterDetachingMainWindow() {
+ testApp.addWindow(main);
+ main.addWindow(sub);
+
+ // main detach should recurse to sub
+ testApp.removeWindow(main);
+ assertDetached(main);
+ assertDetached(sub);
+
+ main.removeWindow(sub);
+ assertDetached(main);
+ assertDetached(sub);
+ }
+
+ /**
+ * Asserts that win and its children are attached to testApp and their
+ * attach() methods have been called.
+ */
+ private void assertAttached(TestWindow win) {
+ assertTrue("window attach not called", win.windowAttachCalled);
+ assertTrue("window content attach not called", win.contentAttachCalled);
+ assertTrue("window child attach not called", win.childAttachCalled);
+
+ assertSame("window not attached", win.getApplication(), testApp);
+ assertSame("window content not attached", win.getContent()
+ .getApplication(), testApp);
+ assertSame("window children not attached", win.getChild()
+ .getApplication(), testApp);
+ }
+
+ /**
+ * Asserts that win and its children are not attached.
+ */
+ private void assertUnattached(TestWindow win) {
+ assertSame("window not detached", win.getApplication(), null);
+ assertSame("window content not detached", win.getContent()
+ .getApplication(), null);
+ assertSame("window children not detached", win.getChild()
+ .getApplication(), null);
+ }
+
+ /**
+ * Asserts that win and its children are unattached and their detach()
+ * methods have been been called.
+ *
+ * @param win
+ */
+ private void assertDetached(TestWindow win) {
+ assertUnattached(win);
+ assertTrue("window detach not called", win.windowDetachCalled);
+ assertTrue("window content detach not called", win.contentDetachCalled);
+ assertTrue("window child detach not called", win.childDetachCalled);
+ }
+}
diff --git a/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java b/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java index a893739bff..df5b275a8e 100644 --- a/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java +++ b/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java @@ -19,10 +19,9 @@ public class TextChangeEventsWithNonImmediateValueChange extends TestBase { TextChangeListener inputEventListener = new TextChangeListener() { public void textChange(TextChangeEvent event) { - l.log("Text change event for " - + event.getComponent().getCaption() - + ", text content currently:'" + event.getText() - + "' Cursor at index:" + event.getCursorPosition()); + l.log("Text change event, text content currently:'" + + event.getText() + "' Cursor at index:" + + event.getCursorPosition()); } }; @@ -33,7 +32,7 @@ public class TextChangeEventsWithNonImmediateValueChange extends TestBase { tf.addListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - l.log("Value change:" + event.getProperty().toString()); + l.log("Value change: '" + event.getProperty().toString() + "'"); } }); @@ -44,7 +43,8 @@ public class TextChangeEventsWithNonImmediateValueChange extends TestBase { @Override protected String getDescription() { - return "Type a, pause for a second, type ENTER, type a. Text field should not forget the last textchange event right after valuechange (enter)."; + return "Type a, pause for a second, type ENTER, type a. Text field should not forget the last textchange event right after valuechange (enter)." + + "<br />Then press backspace. The text field should send a text change event even though the text in the field is the same as the field's value"; } @Override diff --git a/tests/testbench/com/vaadin/tests/components/window/AttachShouldBeCalledForSubWindows.java b/tests/testbench/com/vaadin/tests/components/window/AttachShouldBeCalledForSubWindows.java new file mode 100644 index 0000000000..a6040c06d3 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/window/AttachShouldBeCalledForSubWindows.java @@ -0,0 +1,129 @@ +package com.vaadin.tests.components.window;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
+import com.vaadin.tests.components.AbstractTestCase;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Window;
+
+public class AttachShouldBeCalledForSubWindows extends AbstractTestCase
+ implements HttpServletRequestListener {
+ private static final long serialVersionUID = 1L;
+
+ private Log log = new Log(20);
+
+ boolean addSubWindowBeforeMainWindow = true;
+
+ @Override
+ public void init() {
+
+ Window mainWindow = new Window() {
+ @Override
+ public void attach() {
+ log(this);
+ super.attach();
+ }
+
+ @Override
+ public void addWindow(Window w) {
+ log.log("Adding sub window");
+ super.addWindow(w);
+ log.log("Sub window added");
+
+ }
+ };
+ mainWindow.setCaption("Main window");
+ mainWindow.addComponent(log);
+ mainWindow.getContent().setSizeFull();
+ Label label = new Label("This is the main app") {
+ @Override
+ public void attach() {
+ log(this);
+ super.attach();
+ }
+ };
+
+ mainWindow.addComponent(label);
+ Window loginWindow = createSubWindow();
+ if (addSubWindowBeforeMainWindow) {
+ mainWindow.addWindow(loginWindow);
+ }
+
+ log.log("Setting main window");
+ setMainWindow(mainWindow); // At this point
+ log.log("Main window set");
+
+ if (!addSubWindowBeforeMainWindow) {
+ mainWindow.addWindow(loginWindow);
+ }
+ }
+
+ private Window createSubWindow() {
+ Window w = new Window("Sub window") {
+ @Override
+ public void attach() {
+ log(this);
+ super.attach();
+ }
+ };
+ Button okButton = new Button("OK") {
+ @Override
+ public void attach() {
+ super.attach();
+ log(this);
+ }
+ };
+ okButton.addListener(new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ log.log("Button clicked");
+
+ }
+ });
+ okButton.setClickShortcut(KeyCode.ENTER);
+ w.addComponent(okButton);
+ w.center();
+ return w;
+ }
+
+ public void log(Component c) {
+ Class<?> cls = c.getClass();
+ if (cls.isAnonymousClass()) {
+ cls = cls.getSuperclass();
+ }
+ log.log(cls.getName() + " '" + c.getCaption()
+ + "' attached to application");
+ }
+
+ @Override
+ protected String getDescription() {
+ return "By default attaches a sub window with a button to the main window and then set the main window to the application. Use ?attachMainFirst to reverse the order. In both cases attach events should be sent for the components in the sub window";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 8170;
+ }
+
+ public void onRequestStart(HttpServletRequest request,
+ HttpServletResponse response) {
+ if (request.getParameter("attachMainFirst") != null) {
+ addSubWindowBeforeMainWindow = false;
+ }
+
+ }
+
+ public void onRequestEnd(HttpServletRequest request,
+ HttpServletResponse response) {
+ // TODO Auto-generated method stub
+
+ }
+}
|