diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-04-03 13:24:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 13:24:11 +0300 |
commit | 240cdce985bfc08a6e2869d1de52718227706640 (patch) | |
tree | d0696afd50c4d71e8304f0dbc0e1ed3f0fec7e40 /uitest/src/main/java/com | |
parent | 52013fc6c6ccc0891df79b7fa2c7cce1b9a4f036 (diff) | |
download | vaadin-framework-240cdce985bfc08a6e2869d1de52718227706640.tar.gz vaadin-framework-240cdce985bfc08a6e2869d1de52718227706640.zip |
Prevent upload if no file is selected. (#11939)
Fixes #10419
Diffstat (limited to 'uitest/src/main/java/com')
4 files changed, 58 insertions, 1 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/ui/MultiFileUploadTest.java b/uitest/src/main/java/com/vaadin/tests/components/ui/MultiFileUploadTest.java index 1e97980bc7..b4c0f1c038 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/ui/MultiFileUploadTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/ui/MultiFileUploadTest.java @@ -68,6 +68,7 @@ public class MultiFileUploadTest extends AbstractTestUIWithLog { private Upload createUpload() { Upload upload = new Upload(); + upload.setImmediateMode(false); upload.addChangeListener(changeListener); return upload; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/upload/UploadNoSelection.java b/uitest/src/main/java/com/vaadin/tests/components/upload/UploadNoSelection.java index 81aeb03e0d..2267dec90f 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/upload/UploadNoSelection.java +++ b/uitest/src/main/java/com/vaadin/tests/components/upload/UploadNoSelection.java @@ -3,11 +3,16 @@ package com.vaadin.tests.components.upload; import java.io.ByteArrayOutputStream; import java.io.OutputStream; +import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.server.upload.AllowUploadWithoutFilenameExtension; +import com.vaadin.ui.Button; import com.vaadin.ui.Upload; import com.vaadin.ui.Upload.Receiver; +@Widgetset(TestingWidgetSet.NAME) public class UploadNoSelection extends AbstractTestUIWithLog implements Receiver { @@ -27,7 +32,10 @@ public class UploadNoSelection extends AbstractTestUIWithLog @Override protected String getTestDescription() { - return "Uploading an empty selection (no file) will trigger FinishedEvent with 0-length file size and empty filename."; + return "Uploading an empty selection (no file) should not be possible by " + + "default. If the default behavior is overridden with a custom " + + "extension the upload attempt will trigger FinishedEvent with " + + "0-length file size and empty filename."; } @Override @@ -49,6 +57,16 @@ public class UploadNoSelection extends AbstractTestUIWithLog log(FILE_LENGTH_PREFIX + " " + event.getLength()); log(FILE_NAME_PREFIX + " " + event.getFilename()); }); + + Button progButton = new Button("Upload programmatically", + e -> u.submitUpload()); + progButton.setId("programmatic"); + addComponent(progButton); + + Button extButton = new Button("Allow upload without filename", + e -> AllowUploadWithoutFilenameExtension.wrap(u)); + extButton.setId("extend"); + addComponent(extButton); } @Override diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/upload/AllowUploadWithoutFilenameConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/upload/AllowUploadWithoutFilenameConnector.java new file mode 100644 index 0000000000..d8e9b41610 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/upload/AllowUploadWithoutFilenameConnector.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.widgetset.client.upload; + +import com.vaadin.client.ServerConnector; +import com.vaadin.client.extensions.AbstractExtensionConnector; +import com.vaadin.client.ui.VUpload; +import com.vaadin.client.ui.upload.UploadConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.upload.AllowUploadWithoutFilenameExtension; + +@Connect(AllowUploadWithoutFilenameExtension.class) +public class AllowUploadWithoutFilenameConnector + extends AbstractExtensionConnector { + + @Override + protected void extend(ServerConnector target) { + UploadConnector connector = ((UploadConnector) target); + allowUploadWithoutFilename(connector.getWidget()); + } + + private native void allowUploadWithoutFilename(VUpload upload) + /*-{ + upload.@com.vaadin.client.ui.VUpload::allowUploadWithoutFilename = true; + }-*/; + +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/server/upload/AllowUploadWithoutFilenameExtension.java b/uitest/src/main/java/com/vaadin/tests/widgetset/server/upload/AllowUploadWithoutFilenameExtension.java new file mode 100644 index 0000000000..8f6620b43b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/server/upload/AllowUploadWithoutFilenameExtension.java @@ -0,0 +1,13 @@ +package com.vaadin.tests.widgetset.server.upload; + +import com.vaadin.server.AbstractExtension; +import com.vaadin.ui.Upload; + +public class AllowUploadWithoutFilenameExtension extends AbstractExtension { + + public static AllowUploadWithoutFilenameExtension wrap(Upload upload) { + AllowUploadWithoutFilenameExtension extension = new AllowUploadWithoutFilenameExtension(); + extension.extend(upload); + return extension; + } +} |