]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix NPE when removing FileDownloader (#10198) 85/285/2
authorArtur Signell <artur@vaadin.com>
Fri, 16 Nov 2012 15:24:54 +0000 (17:24 +0200)
committerArtur Signell <artur@vaadin.com>
Mon, 19 Nov 2012 10:33:26 +0000 (12:33 +0200)
Change-Id: I2423e3fbe88becfd76ed17c15d911d9253bf6e35

client/src/com/vaadin/client/extensions/FileDownloaderConnector.java
uitest/src/com/vaadin/tests/components/FileDownloaderTest.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/FileDownloaderTest.java

index 6308de9c055a855dc3105f0ef07eff4556f5778f..61a8bee9d34f5d0a584093c9fffcf3ebfbda20b3 100644 (file)
@@ -69,7 +69,7 @@ public class FileDownloaderConnector extends AbstractExtensionConnector
     @Override
     public void setParent(ServerConnector parent) {
         super.setParent(parent);
-        if (parent == null) {
+        if (parent == null && iframe != null) {
             iframe.removeFromParent();
         }
     }
diff --git a/uitest/src/com/vaadin/tests/components/FileDownloaderTest.html b/uitest/src/com/vaadin/tests/components/FileDownloaderTest.html
new file mode 100644 (file)
index 0000000..bfe8709
--- /dev/null
@@ -0,0 +1,36 @@
+<?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="http://arturwin.office.itmill.com:8888/" />
+<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.components.FileDownloaderTest?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsFileDownloaderTest::PID_Scom.vaadin.ui.ButtonDynamicimage/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsFileDownloaderTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsFileDownloaderTest::PID_Scom.vaadin.ui.ButtonDynamicimage/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+</tbody></table>
+</body>
+</html>
index e773c8c75bc103481e97d2e4099c999caac629c1..55d2afd32d469ee1d831eb894939a879b1ae5e74 100644 (file)
@@ -37,6 +37,7 @@ import com.vaadin.server.StreamResource;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinResponse;
 import com.vaadin.tests.components.embedded.EmbeddedPdf;
+import com.vaadin.tests.util.Log;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.Button.ClickEvent;
@@ -45,12 +46,18 @@ import com.vaadin.ui.Component;
 import com.vaadin.ui.CssLayout;
 import com.vaadin.ui.HorizontalLayout;
 import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
 import com.vaadin.ui.NativeButton;
 
 public class FileDownloaderTest extends AbstractTestUI {
 
+    private AbstractComponent firstDownloadComponent;
+    private Log log = new Log(5);
+
     @Override
     protected void setup(VaadinRequest request) {
+        addComponent(log);
+
         List<Class<? extends Component>> components = new ArrayList<Class<? extends Component>>();
         components.add(Button.class);
         components.add(NativeButton.class);
@@ -104,6 +111,29 @@ public class FileDownloaderTest extends AbstractTestUI {
         // addComponents(resource, components);
         resource = new ClassResource(new EmbeddedPdf().getClass(), "test.pdf");
         addComponents("Class resource pdf", resource, components);
+
+        addComponent(new Button("Remove first download button",
+                new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        Layout parent = (Layout) firstDownloadComponent
+                                .getParent();
+                        parent.removeComponent(firstDownloadComponent);
+                    }
+                }));
+        addComponent(new Button(
+                "Detach FileDownloader from first download button",
+                new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        FileDownloader e = (FileDownloader) firstDownloadComponent
+                                .getExtensions().iterator().next();
+                        e.removeFromTarget();
+                        log.log("FileDownload detached");
+                    }
+                }));
     }
 
     public void addComponents(String caption, ConnectorResource resource,
@@ -113,7 +143,11 @@ public class FileDownloaderTest extends AbstractTestUI {
         for (Class<? extends Component> cls : components) {
             try {
                 AbstractComponent c = (AbstractComponent) cls.newInstance();
-                c.setId(cls.getName());
+                if (firstDownloadComponent == null) {
+                    firstDownloadComponent = c;
+                }
+
+                c.setId(cls.getName() + caption.replace(" ", ""));
                 c.setCaption(cls.getName());
                 c.setDescription(resource.getMIMEType() + " / "
                         + resource.getClass());