summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-07-06 22:26:45 +0300
committerVaadin Code Review <review@vaadin.com>2015-07-07 08:25:07 +0000
commit73d4e770751a3d78f9f177c82b2aa8c7281ec77f (patch)
tree13c81384d39a72bbdc8d25d9329027bcbd26a93e
parent8d2bbed0a53e8f46a9a613feaccd4e88d0c61a4e (diff)
downloadvaadin-framework-73d4e770751a3d78f9f177c82b2aa8c7281ec77f.tar.gz
vaadin-framework-73d4e770751a3d78f9f177c82b2aa8c7281ec77f.zip
Keep a reference to the file we are uploading to keep IE10 happy (#18372)
Change-Id: I2dc9b846e1c3ae123b26eac017082bea4ba6f7c3
-rw-r--r--client/src/com/vaadin/client/ui/VDragAndDropWrapper.java3
-rw-r--r--uitest/src/com/vaadin/tests/components/upload/DragAndDropUploadAndInteractions.java153
2 files changed, 156 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java
index defa27fbac..f3905f9e46 100644
--- a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java
+++ b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java
@@ -472,6 +472,9 @@ public class VDragAndDropWrapper extends VCustomComponent implements
/*-{
this.setRequestHeader('Content-Type', 'multipart/form-data');
+ // Seems like IE10 will loose the file if we don't keep a reference to it...
+ this.fileBeingUploaded = file;
+
this.send(file);
}-*/;
diff --git a/uitest/src/com/vaadin/tests/components/upload/DragAndDropUploadAndInteractions.java b/uitest/src/com/vaadin/tests/components/upload/DragAndDropUploadAndInteractions.java
new file mode 100644
index 0000000000..952fe08b79
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/upload/DragAndDropUploadAndInteractions.java
@@ -0,0 +1,153 @@
+package com.vaadin.tests.components.upload;
+
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.acceptcriteria.AcceptAll;
+import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
+import com.vaadin.server.StreamVariable;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.DragAndDropWrapper;
+import com.vaadin.ui.Html5File;
+import com.vaadin.ui.Panel;
+
+public class DragAndDropUploadAndInteractions extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ ComboBox comboBox = new ComboBox();
+ for (int i = 0; i < 10; i++) {
+ comboBox.addItem("Test " + i);
+ }
+ addComponent(comboBox);
+ Button b = new Button("Dummy");
+ addComponent(b);
+ Panel p = new Panel();
+ p.setHeight(200, Unit.PIXELS);
+ p.setWidth(200, Unit.PIXELS);
+ MyUploadPanel myUploadPanel = new MyUploadPanel(p);
+ addComponent(myUploadPanel);
+ }
+
+ class MyUploadPanel extends DragAndDropWrapper implements DropHandler {
+ private static final long serialVersionUID = 1L;
+
+ public MyUploadPanel(Component root) {
+ super(root);
+ setDropHandler(this);
+ }
+
+ @Override
+ public void drop(DragAndDropEvent event) {
+ WrapperTransferable tr = (WrapperTransferable) event
+ .getTransferable();
+ Html5File[] files = tr.getFiles();
+
+ if (files != null) {
+ List<Html5File> filesToUpload = Arrays.asList(files);
+ for (Html5File file : filesToUpload) {
+ file.setStreamVariable(new MyStreamVariable());
+ }
+ }
+ }
+
+ @Override
+ public AcceptCriterion getAcceptCriterion() {
+ return AcceptAll.get();
+ }
+
+ }
+
+ class MyStreamVariable implements StreamVariable {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public OutputStream getOutputStream() {
+ return new ByteArrayOutputStream();
+ }
+
+ @Override
+ public boolean listenProgress() {
+ return true;
+ }
+
+ long lastEvent = 0;
+ long lastTime = 0;
+
+ @Override
+ public void onProgress(StreamingProgressEvent event) {
+ long received = event.getBytesReceived() - lastEvent;
+ long now = new Date().getTime();
+ long time = now - lastTime;
+ lastTime = now;
+ lastEvent = event.getBytesReceived();
+ if (time == 0) {
+ return;
+ }
+ log("Received " + received + " bytes in " + time + "ms: "
+ + formatSize(received / (time / 1000.0)) + "/s");
+ log("Streaming OnProgress - ContentLength: "
+ + formatSize(event.getContentLength())
+ + " - Bytes Received: "
+ + formatSize(event.getBytesReceived()));
+ }
+
+ @Override
+ public void streamingStarted(StreamingStartEvent event) {
+ lastEvent = 0;
+ lastTime = new Date().getTime();
+ log("Streaming Started - ContentLength: "
+ + formatSize(event.getContentLength())
+ + " - Bytes Received: "
+ + formatSize(event.getBytesReceived()));
+ }
+
+ @Override
+ public void streamingFinished(StreamingEndEvent event) {
+ log("Streaming Finished - ContentLength: "
+ + formatSize(event.getContentLength())
+ + " - Bytes Received: "
+ + formatSize(event.getBytesReceived()));
+ }
+
+ @Override
+ public void streamingFailed(StreamingErrorEvent event) {
+ log("Streaming Failed - ContentLength: "
+ + formatSize(event.getContentLength())
+ + " - Bytes Received: "
+ + formatSize(event.getBytesReceived()));
+ }
+
+ @Override
+ public boolean isInterrupted() {
+ return false;
+ }
+
+ }
+
+ protected String formatSize(double contentLength) {
+ double d = contentLength;
+ int suffix = 0;
+ String[] suffixes = new String[] { "B", "KB", "MB", "GB", "TB" };
+ while (d > 1024) {
+ suffix++;
+ d /= 1024.0;
+ }
+ return String.format("%.1f %s", d, suffixes[suffix]);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Drop a large (100 MB) file using IE10 and interact with the application while uploading. Ensure the uploads succeeds even though you are interacting with the app.";
+ }
+}