From 52d01a68e91ce73306b3a1747af97e928048ecdf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sun, 11 Sep 2016 22:14:51 +0300 Subject: Test for Firefox download disconnecting push channel Change-Id: Iacf2b04b96c237ad377dbd75ad07f86a00660319 --- .../vaadin/tests/resources/DownloadWithPush.java | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/resources/DownloadWithPush.java (limited to 'uitest') 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; + } + +} -- cgit v1.2.3