diff options
author | Artur Signell <artur@vaadin.com> | 2016-09-11 22:14:51 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-09-12 10:48:25 +0000 |
commit | 52d01a68e91ce73306b3a1747af97e928048ecdf (patch) | |
tree | 4866e7439ba7af50ba4929a059a0d2c19a56a615 /uitest | |
parent | c9ad48430be135d18fe9f30868e091dd51c57b94 (diff) | |
download | vaadin-framework-52d01a68e91ce73306b3a1747af97e928048ecdf.tar.gz vaadin-framework-52d01a68e91ce73306b3a1747af97e928048ecdf.zip |
Test for Firefox download disconnecting push channel
Change-Id: Iacf2b04b96c237ad377dbd75ad07f86a00660319
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/resources/DownloadWithPush.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/resources/DownloadWithPush.java b/uitest/src/main/java/com/vaadin/tests/resources/DownloadWithPush.java new file mode 100644 index 0000000000..9cbd8ed823 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/resources/DownloadWithPush.java @@ -0,0 +1,94 @@ +package com.vaadin.tests.resources; + +import java.io.IOException; +import java.io.InputStream; + +import com.vaadin.annotations.Push; +import com.vaadin.server.DownloadStream; +import com.vaadin.server.Resource; +import com.vaadin.server.StreamResource; +import com.vaadin.server.StreamResource.StreamSource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; + +@Push +public class DownloadWithPush extends AbstractTestUIWithLog { + + private static class GeneratedStream extends InputStream { + int read = 0; + int next = 'a'; + private final int size; + + public GeneratedStream(int size) { + this.size = size; + } + + @Override + public int read() throws IOException { + if (available() == 0) { + return -1; + } + + read++; + next++; + if (next > 'z') { + next = 'a'; + } + return next; + } + + @Override + public int available() throws IOException { + return size - read; + } + } + + private final class DownloadResoure extends StreamResource { + private DownloadResoure(StreamSource streamSource, String filename) { + super(streamSource, filename); + } + + @Override + public DownloadStream getStream() { + DownloadStream ds = super.getStream(); + ds.setParameter("Content-Disposition", + "attachment; filename=" + getFilename() + ";"); + return ds; + } + } + + private Resource hugeFileResource = createResource();; + private int fileSize = 300 * (1024 * 1024); + + @Override + protected void setup(VaadinRequest request) { + Button b = new Button("Download a " + + String.format("%.1f", fileSize / 1024.0 / 1024.0) + "MB file", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + getUI().getPage().open(hugeFileResource, "", false); + } + }); + addComponent(b); + } + + private Resource createResource() { + Resource hugeFileResource = new DownloadResoure(new StreamSource() { + @Override + public InputStream getStream() { + return new GeneratedStream(fileSize); + } + }, "hugefile.txt"); + return hugeFileResource; + } + + + @Override + protected Integer getTicketNumber() { + return 19709; + } + +} |