diff options
author | Artur <artur@vaadin.com> | 2018-03-28 15:21:16 +0300 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-03-28 15:21:16 +0300 |
commit | 761bef8fb790258ac7a527f51a23da0bd1802dbe (patch) | |
tree | f7c6174a32affe0dbd9803143f09c5b9ddf959c3 /uitest | |
parent | 96efeccce765a2f12db71c9af2ac07fc4283c201 (diff) | |
download | vaadin-framework-761bef8fb790258ac7a527f51a23da0bd1802dbe.tar.gz vaadin-framework-761bef8fb790258ac7a527f51a23da0bd1802dbe.zip |
Support starting downloads and opening URLs from a menu item (#10478)
Diffstat (limited to 'uitest')
4 files changed, 153 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/MenuBarDownloadBrowserOpenerUI.java b/uitest/src/main/java/com/vaadin/tests/components/MenuBarDownloadBrowserOpenerUI.java new file mode 100644 index 0000000000..27ab5d2347 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/MenuBarDownloadBrowserOpenerUI.java @@ -0,0 +1,73 @@ +package com.vaadin.tests.components; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.BrowserWindowOpener; +import com.vaadin.server.ClassResource; +import com.vaadin.server.ConnectorResource; +import com.vaadin.server.ExternalResource; +import com.vaadin.server.FileDownloader; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.embedded.EmbeddedPdf; +import com.vaadin.tests.extensions.EventTriggerExtension; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.ui.Button; +import com.vaadin.ui.MenuBar; +import com.vaadin.ui.MenuBar.MenuItem; + +@Widgetset(TestingWidgetSet.NAME) +public class MenuBarDownloadBrowserOpenerUI extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + + ConnectorResource downloadResource = new ClassResource( + EmbeddedPdf.class, "test.pdf"); + ExternalResource openResource = new ExternalResource( + "https://vaadin.com"); + + MenuBar menuBar = new MenuBar(); + MenuItem download = menuBar.addItem("Download"); + MenuItem saveAsNoLog = download.addItem("Save as without logging..."); + MenuItem saveAsLog = download.addItem("Save as with logging...", + item -> log("Download triggered")); + FileDownloader fd = new FileDownloader(downloadResource); + fd.extend(saveAsNoLog); + FileDownloader fd2 = new FileDownloader(downloadResource); + fd2.extend(saveAsLog); + + MenuItem open = menuBar.addItem("Open"); + MenuItem openNoLog = open.addItem("Open without logging..."); + MenuItem openLog = open.addItem("Open with logging...", item -> log("Open triggered")); + + BrowserWindowOpener bwo = new BrowserWindowOpener(openResource); + bwo.extend(openNoLog); + BrowserWindowOpener bwo2 = new BrowserWindowOpener(openResource); + bwo2.extend(openLog); + + addComponent(menuBar); + + addComponent(new Button("Remove downloaders and openers", event -> { + fd.remove(); + fd2.remove(); + bwo.remove(); + bwo2.remove(); + })); + + setupTestExtension(menuBar); + + } + + private void setupTestExtension(MenuBar menuBar) { + EventTriggerExtension triggerable1 = new EventTriggerExtension(); + EventTriggerExtension triggerable2 = new EventTriggerExtension(); + + MenuItem testExtension = menuBar.addItem("TestExtension"); + MenuItem runMe = testExtension.addItem("RunMe"); + triggerable1.extend(runMe); + + testExtension.addItem("AddTrigger", c -> triggerable2.extend(runMe)); + testExtension.addItem("RemoveTrigger", c -> triggerable2.remove()); + + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/extensions/EventTriggerExtension.java b/uitest/src/main/java/com/vaadin/tests/extensions/EventTriggerExtension.java new file mode 100644 index 0000000000..c6bac2b54a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/extensions/EventTriggerExtension.java @@ -0,0 +1,23 @@ +package com.vaadin.tests.extensions; + +import com.vaadin.server.AbstractExtension; +import com.vaadin.server.EventTrigger; +import com.vaadin.shared.extension.PartInformationState; + +public class EventTriggerExtension extends AbstractExtension { + + @Override + protected PartInformationState getState() { + return (PartInformationState) super.getState(); + } + + @Override + protected PartInformationState getState(boolean markAsDirty) { + return (PartInformationState) super.getState(markAsDirty); + } + + public void extend(EventTrigger eventTrigger) { + super.extend(eventTrigger.getConnector()); + getState().partInformation = eventTrigger.getPartInformation(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/extension/EventTriggerExtensionConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/extension/EventTriggerExtensionConnector.java new file mode 100644 index 0000000000..10994f7430 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/extension/EventTriggerExtensionConnector.java @@ -0,0 +1,13 @@ +package com.vaadin.tests.widgetset.client.extension; + +import com.vaadin.client.extensions.AbstractEventTriggerExtensionConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.extensions.EventTriggerExtension; + +@Connect(EventTriggerExtension.class) +public class EventTriggerExtensionConnector extends AbstractEventTriggerExtensionConnector{ + @Override + protected native void trigger() /*-{ + alert("Trigger"); + }-*/; +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/MenuBarDownloadBrowserOpenerUITest.java b/uitest/src/test/java/com/vaadin/tests/components/MenuBarDownloadBrowserOpenerUITest.java new file mode 100644 index 0000000000..00e12bd1f3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/MenuBarDownloadBrowserOpenerUITest.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Alert; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.MenuBarElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class MenuBarDownloadBrowserOpenerUITest extends MultiBrowserTest { + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + //alerts do not work properly on PhantomJS + return getBrowserCapabilities(Browser.CHROME); + } + + @Test + public void testTriggerExtension() { + openTestURL(); + MenuBarElement first = $(MenuBarElement.class).first(); + first.clickItem("TestExtension", "RunMe"); + checkAndCloseAlert(); + + first.clickItem("TestExtension", "AddTrigger"); + first.clickItem("TestExtension", "RunMe"); + checkAndCloseAlert(); + checkAndCloseAlert(); + + first.clickItem("TestExtension", "RemoveTrigger"); + first.clickItem("TestExtension", "RunMe"); + checkAndCloseAlert(); + } + + private void checkAndCloseAlert() { + Alert alert = getDriver().switchTo().alert(); + Assert.assertEquals("Trigger",alert.getText()); + alert.dismiss(); + } + +} |