diff --git a/flow-tests/test-themes/frontend/theme/app-theme/global.css b/flow-tests/test-themes/frontend/theme/app-theme/global.css index b9c74aeb816..5b396b01db1 100644 --- a/flow-tests/test-themes/frontend/theme/app-theme/global.css +++ b/flow-tests/test-themes/frontend/theme/app-theme/global.css @@ -9,3 +9,18 @@ body { background-image: url("./img/bg.jpg"); font-family: "Ostrich"; } + +#butterfly { + /* This shouldn't be translated */ + background-image: url("./test/path/monarch-butterfly.jpg"); + width: 300px; + height: 274px; + display: block; +} + +#octopuss { + background-image: url('/octopuss.jpg'); + width: 224px; + height: 224px; + display: block; +} diff --git a/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/servlets/WorkaroundServlet.java b/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/servlets/WorkaroundServlet.java index f7d11ba7a05..61845ba3e28 100644 --- a/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/servlets/WorkaroundServlet.java +++ b/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/servlets/WorkaroundServlet.java @@ -17,6 +17,9 @@ import javax.servlet.annotation.WebServlet; +import java.io.PrintWriter; +import java.util.function.Consumer; + import com.vaadin.flow.server.VaadinServlet; /** @@ -24,7 +27,7 @@ * * @since 2.0 */ -@WebServlet("/*") +@WebServlet("/path/*") public class WorkaroundServlet extends VaadinServlet { } diff --git a/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/theme/ThemeView.java b/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/theme/ThemeView.java index 26cc45a84ef..685caf72d14 100644 --- a/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/theme/ThemeView.java +++ b/flow-tests/test-themes/src/main/java/com/vaadin/flow/uitest/ui/theme/ThemeView.java @@ -30,15 +30,28 @@ public class ThemeView extends Div { public static final String MY_POLYMER_ID = "field"; public static final String MY_LIT_ID = "button"; public static final String TEST_TEXT_ID = "test-text"; + public static final String BUTTERFLY_ID = "butterfly"; + public static final String OCTOPUSS_ID = "octopuss"; + public static final String SUB_COMPONENT_ID = "sub-component"; public ThemeView() { final Span textSpan = new Span("This is the theme test view"); textSpan.setId(TEST_TEXT_ID); + Span subCss = new Span(); - subCss.setId("sub-component"); - add(textSpan, subCss); + subCss.setId(SUB_COMPONENT_ID); + + Span butterfly = new Span(); + butterfly.setId(BUTTERFLY_ID); + + Span octopuss = new Span(); + octopuss.setId(OCTOPUSS_ID); + + add(textSpan, subCss, butterfly, octopuss); + add(new Div()); add(new MyPolymerField().withId(MY_POLYMER_ID)); + add(new Div()); add(new MyLitField().withId(MY_LIT_ID)); } diff --git a/flow-tests/test-themes/src/main/webapp/octopuss.jpg b/flow-tests/test-themes/src/main/webapp/octopuss.jpg new file mode 100644 index 00000000000..892036a54bc Binary files /dev/null and b/flow-tests/test-themes/src/main/webapp/octopuss.jpg differ diff --git a/flow-tests/test-themes/src/main/webapp/path/test/path/monarch-butterfly.jpg b/flow-tests/test-themes/src/main/webapp/path/test/path/monarch-butterfly.jpg new file mode 100644 index 00000000000..89a0a69a6ce Binary files /dev/null and b/flow-tests/test-themes/src/main/webapp/path/test/path/monarch-butterfly.jpg differ diff --git a/flow-tests/test-themes/src/test/java/com/vaadin/flow/uitest/ui/theme/ThemeIT.java b/flow-tests/test-themes/src/test/java/com/vaadin/flow/uitest/ui/theme/ThemeIT.java index 3c1e4fcab66..77ede64fa1b 100644 --- a/flow-tests/test-themes/src/test/java/com/vaadin/flow/uitest/ui/theme/ThemeIT.java +++ b/flow-tests/test-themes/src/test/java/com/vaadin/flow/uitest/ui/theme/ThemeIT.java @@ -24,19 +24,21 @@ import com.vaadin.flow.testutil.ChromeBrowserTest; import com.vaadin.testbench.TestBenchElement; +import static com.vaadin.flow.uitest.ui.theme.ThemeView.BUTTERFLY_ID; import static com.vaadin.flow.uitest.ui.theme.ThemeView.MY_LIT_ID; import static com.vaadin.flow.uitest.ui.theme.ThemeView.MY_POLYMER_ID; +import static com.vaadin.flow.uitest.ui.theme.ThemeView.OCTOPUSS_ID; +import static com.vaadin.flow.uitest.ui.theme.ThemeView.SUB_COMPONENT_ID; public class ThemeIT extends ChromeBrowserTest { @Test public void secondTheme_staticFilesNotCopied() { - getDriver().get(getRootURL() + "/VAADIN/static/img/bg.jpg"); + getDriver().get(getRootURL() + "/path/VAADIN/static/img/bg.jpg"); Assert.assertFalse("app-theme static files should be copied", driver.getPageSource().contains("HTTP ERROR 404")); - getDriver().get(getRootURL() + "/VAADIN/static/no-copy.txt"); - System.out.println(driver.getPageSource()); + getDriver().get(getRootURL() + "/path/VAADIN/static/no-copy.txt"); Assert.assertTrue("no-copy theme should not be handled", driver.getPageSource().contains("HTTP ERROR 404")); } @@ -49,12 +51,12 @@ public void applicationTheme_GlobalCss_isUsed() { final WebElement body = findElement(By.tagName("body")); Assert.assertEquals( - "url(\"" + getRootURL() + "/VAADIN/static/img/bg.jpg\")", + "url(\"" + getRootURL() + "/path/VAADIN/static/img/bg.jpg\")", body.getCssValue("background-image")); Assert.assertEquals("Ostrich", body.getCssValue("font-family")); - getDriver().get(getRootURL() + "/VAADIN/static/img/bg.jpg"); + getDriver().get(getRootURL() + "/path/VAADIN/static/img/bg.jpg"); Assert.assertFalse("app-theme background file should be served", driver.getPageSource().contains("Could not navigate")); } @@ -85,16 +87,42 @@ public void subCssWithRelativePath_urlPathIsNotRelative() { checkLogsForErrors(); Assert.assertEquals("Imported css file URLs should have been handled.", - "url(\"" + getRootURL() + "/VAADIN/static/icons/archive.png\")", - $(SpanElement.class).id("sub-component") + "url(\"" + getRootURL() + "/path/VAADIN/static/icons/archive.png\")", + $(SpanElement.class).id(SUB_COMPONENT_ID) .getCssValue("background-image")); } + @Test + public void nonThemeDependency_urlIsNotRewritten() { + open(); + checkLogsForErrors(); + + Assert.assertEquals("Relative non theme url should not be touched", + "url(\"" + getRootURL() + "/path/test/path/monarch-butterfly.jpg\")", + $(SpanElement.class).id(BUTTERFLY_ID) + .getCssValue("background-image")); + + Assert.assertEquals("Absolute non theme url should not be touched", + "url(\"" + getRootURL() + "/octopuss.jpg\")", + $(SpanElement.class).id(OCTOPUSS_ID) + .getCssValue("background-image")); + + + getDriver().get(getRootURL() + "/path/test/path/monarch-butterfly.jpg"); + Assert.assertFalse("webapp resource should be served", + driver.getPageSource().contains("HTTP ERROR 404 Not Found")); + + + getDriver().get(getRootURL() + "/octopuss.jpg"); + Assert.assertFalse("root resource should be served", + driver.getPageSource().contains("HTTP ERROR 404 Not Found")); + } + @Override protected String getTestPath() { String path = super.getTestPath(); String view = "view/"; - return path.substring(view.length()); + return path.replace(view, "path/"); } }