diff options
7 files changed, 75 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VUpload.java b/client/src/main/java/com/vaadin/client/ui/VUpload.java index ad50ca3115..681eaaf2f2 100644 --- a/client/src/main/java/com/vaadin/client/ui/VUpload.java +++ b/client/src/main/java/com/vaadin/client/ui/VUpload.java @@ -25,6 +25,7 @@ import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.FormElement; +import com.google.gwt.dom.client.InputElement; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.FileUpload; @@ -405,4 +406,12 @@ public class VUpload extends SimplePanel { private static Logger getLogger() { return Logger.getLogger(VUpload.class.getName()); } + + public void setAcceptMimeTypes(String acceptMimeTypes) { + if (acceptMimeTypes == null || acceptMimeTypes.isEmpty()) { + InputElement.as(fu.getElement()).setAccept(null); + } else { + InputElement.as(fu.getElement()).setAccept(acceptMimeTypes); + } + } } diff --git a/server/src/main/java/com/vaadin/ui/Upload.java b/server/src/main/java/com/vaadin/ui/Upload.java index 7f5727f078..0e64654d38 100644 --- a/server/src/main/java/com/vaadin/ui/Upload.java +++ b/server/src/main/java/com/vaadin/ui/Upload.java @@ -1198,4 +1198,35 @@ public class Upload extends AbstractComponent protected UploadState getState(boolean markAsDirty) { return (UploadState) super.getState(markAsDirty); } + + /** + * Returns the component's list of accepted content-types. According to RFC + * 1867, the attributeis present, the browser might constrain the file + * patterns prompted for to match those with the corresponding appropriate + * file extensions for the platform. + * + * @return comma-separated list of desired mime types to be uploaded + * @see #setAcceptMimeTypes + * @since + */ + public String getAcceptMimeTypes() { + return getState(false).acceptMimeTypes; + } + + /** + * Sets the component's list of accepted content-types. According to RFC + * 1867, the attributeis present, the browser might constrain the file + * patterns prompted for to match those with the corresponding appropriate + * file extensions for the platform. Good examples are: {@code image/*} or + * {@code image/png,text/plain} + * + * @param acceptMimeTypes + * comma-separated list of desired mime types to be uploaded + * @see #getAcceptMimeTypes + * @since + */ + public void setAcceptMimeTypes(String acceptMimeTypes) { + getState().acceptMimeTypes = acceptMimeTypes; + } + } diff --git a/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java b/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java index 70217c28a5..217946391c 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java @@ -16,6 +16,8 @@ package com.vaadin.shared.ui.upload; import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; +import com.vaadin.shared.annotations.NoLayout; /** * Shared state for the Upload component. @@ -30,4 +32,8 @@ public class UploadState extends AbstractComponentState { { primaryStyleName = "v-upload"; } + + @DelegateToWidget + @NoLayout + public String acceptMimeTypes; } diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java index 32602d40ad..f84aeca14c 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java @@ -6,6 +6,8 @@ import com.vaadin.ui.Upload; public class ImmediateUpload extends AbstractTestUI { + public static final String TEST_MIME_TYPE = "image/png"; + /* * (non-Javadoc) * @@ -18,6 +20,7 @@ public class ImmediateUpload extends AbstractTestUI { // by default is in immediate mode (since 8.0) Upload immediateUpload = new Upload(); immediateUpload.setId("immediateupload"); + immediateUpload.setAcceptMimeTypes(TEST_MIME_TYPE); addComponent(immediateUpload); Upload upload = new Upload(); diff --git a/uitest/src/test/java/com/vaadin/tests/resources/FrontendInitialResourceUITest.java b/uitest/src/test/java/com/vaadin/tests/resources/FrontendInitialResourceUITest.java index 7f2748461c..a387b89486 100644 --- a/uitest/src/test/java/com/vaadin/tests/resources/FrontendInitialResourceUITest.java +++ b/uitest/src/test/java/com/vaadin/tests/resources/FrontendInitialResourceUITest.java @@ -1,15 +1,24 @@ package com.vaadin.tests.resources; +import java.util.List; + import static org.junit.Assert.assertEquals; import org.junit.Test; import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; +import com.vaadin.testbench.parallel.Browser; import com.vaadin.testbench.parallel.BrowserUtil; import com.vaadin.tests.tb3.MultiBrowserTest; public class FrontendInitialResourceUITest extends MultiBrowserTest { + @Override + protected List<DesiredCapabilities> getBrowserCapabilities(Browser... browsers) { + return getBrowsersExcludingPhantomJS(); + } + @Test public void correctEs5Es6FileImportedThroughFrontend() { openTestURL(); diff --git a/uitest/src/test/java/com/vaadin/tests/resources/FrontendLaterLoadedResourceUITest.java b/uitest/src/test/java/com/vaadin/tests/resources/FrontendLaterLoadedResourceUITest.java index f2e1583f15..2f3223317f 100644 --- a/uitest/src/test/java/com/vaadin/tests/resources/FrontendLaterLoadedResourceUITest.java +++ b/uitest/src/test/java/com/vaadin/tests/resources/FrontendLaterLoadedResourceUITest.java @@ -1,16 +1,25 @@ package com.vaadin.tests.resources; +import java.util.List; + import static org.junit.Assert.assertEquals; import org.junit.Test; import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.Browser; import com.vaadin.testbench.parallel.BrowserUtil; import com.vaadin.tests.tb3.MultiBrowserTest; public class FrontendLaterLoadedResourceUITest extends MultiBrowserTest { + @Override + protected List<DesiredCapabilities> getBrowserCapabilities(Browser... browsers) { + return getBrowsersExcludingPhantomJS(); + } + @Test public void correctEs5Es6FileImportedThroughFrontend() { openTestURL(); diff --git a/uitest/src/test/java/com/vaadin/tests/themes/valo/ImmediateUploadTest.java b/uitest/src/test/java/com/vaadin/tests/themes/valo/ImmediateUploadTest.java index f97b8e9b09..511c1a430c 100644 --- a/uitest/src/test/java/com/vaadin/tests/themes/valo/ImmediateUploadTest.java +++ b/uitest/src/test/java/com/vaadin/tests/themes/valo/ImmediateUploadTest.java @@ -1,5 +1,6 @@ package com.vaadin.tests.themes.valo; +import static com.vaadin.tests.themes.valo.ImmediateUpload.TEST_MIME_TYPE; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -74,4 +75,11 @@ public class ImmediateUploadTest extends MultiBrowserTest { // don't show the upload window, not at least in firefox. assertThat(input.getCssValue("z-index"), is("-1")); } + + @Test + public void testAcceptAttribute() + { + WebElement input = getUploadFileInput("immediateupload"); + assertThat(input.getAttribute("accept"),is(TEST_MIME_TYPE)); + } } |