summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorMaciej PrzepiĆ³ra <maciej@przepiora.me>2019-01-17 11:46:49 +0100
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2019-01-17 12:46:49 +0200
commita1c1dfd1efd66c7949d6f217266e5fe80e8c6e5f (patch)
treee78231a15b8838b64c4718563ae44667f7495b4d /uitest
parent893524cda2b82bb0a1dbda47cb8fc6a9f182cb66 (diff)
downloadvaadin-framework-a1c1dfd1efd66c7949d6f217266e5fe80e8c6e5f.tar.gz
vaadin-framework-a1c1dfd1efd66c7949d6f217266e5fe80e8c6e5f.zip
Fix #11369 (#11403)
Clear contents of iframe clone that is in a Window so that when it's reattached to DOM we don't get 404
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404.java70
-rw-r--r--uitest/src/main/resources/sample.pdfbin0 -> 18123 bytes
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404Test.java39
3 files changed, 109 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404.java b/uitest/src/main/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404.java
new file mode 100644
index 0000000000..74c7938974
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404.java
@@ -0,0 +1,70 @@
+package com.vaadin.tests.components.window;
+
+import com.vaadin.server.StreamResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.*;
+import org.apache.commons.io.IOUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ClosingWindowWithBrowserFrameShouldntGenerate404
+ extends AbstractTestUI {
+
+ private VerticalLayout layout;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ layout = new VerticalLayout();
+
+ Button button = new Button("Click Me", e -> showPdfInAWindow());
+ layout.addComponent(button);
+ addComponent(layout);
+ }
+
+ private void showPdfInAWindow() {
+ try {
+ final String fileName = "sample.pdf";
+ final byte[] bytes = IOUtils
+ .toByteArray(getClass().getResource("/" + fileName));
+ StreamResource.StreamSource source = new StreamResource.StreamSource() {
+ @Override
+ public InputStream getStream() {
+ return new ByteArrayInputStream(bytes);
+ }
+ };
+
+ StreamResource resource = new StreamResource(source, fileName);
+
+ resource.setMIMEType("application/pdf");
+ resource.getStream().setParameter("Content-Disposition",
+ "attachment; filename=" + fileName);
+ resource.setCacheTime(-1);
+
+ // Use browser frame
+ BrowserFrame frame = new BrowserFrame();
+ frame.setSizeFull();
+ frame.setSource(resource);
+ frame.setHeight("650px");
+ Window pdfWindow = new Window("Sample PDF");
+ pdfWindow.center();
+ pdfWindow.setModal(true);
+ pdfWindow.setResizable(false);
+ pdfWindow.setHeight("700px");
+ pdfWindow.setWidth("900px");
+ pdfWindow.setContent(frame);
+
+ pdfWindow.addCloseListener(e -> {
+ layout.addComponent(new Label("PDF was sent"));
+
+ });
+
+ UI.getCurrent().addWindow(pdfWindow);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/uitest/src/main/resources/sample.pdf b/uitest/src/main/resources/sample.pdf
new file mode 100644
index 0000000000..758b45a2be
--- /dev/null
+++ b/uitest/src/main/resources/sample.pdf
Binary files differ
diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404Test.java b/uitest/src/test/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404Test.java
new file mode 100644
index 0000000000..a0a32cb77b
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/window/ClosingWindowWithBrowserFrameShouldntGenerate404Test.java
@@ -0,0 +1,39 @@
+package com.vaadin.tests.components.window;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.elements.WindowElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.logging.LogEntry;
+
+import java.util.List;
+
+public class ClosingWindowWithBrowserFrameShouldntGenerate404Test
+ extends MultiBrowserTest {
+
+ private static boolean contains404(LogEntry logEntry) {
+ return logEntry.getMessage().contains("404");
+ }
+
+ @Test
+ public void openWindowWithFrame_closeWindow_no404() {
+ openTestURL();
+ $(ButtonElement.class).first().click();
+
+ $(WindowElement.class).first().close();
+
+ $(LabelElement.class).exists();
+
+ List<LogEntry> logs = getDriver().manage().logs().get("browser")
+ .getAll();
+
+ Assert.assertTrue(theresNoLogWith404In(logs));
+ }
+
+ private boolean theresNoLogWith404In(List<LogEntry> logs) {
+ return !logs.stream().anyMatch(
+ ClosingWindowWithBrowserFrameShouldntGenerate404Test::contains404);
+ }
+}