Skip to content

Commit

Permalink
test: add test that external urls are not touched (#9482)
Browse files Browse the repository at this point in the history
Added test that we don't touch external
urls (relative or abosolute).
Moved flow to be under path so we can have
jetty serve "external" resources.

Fixes #9430
  • Loading branch information
caalador authored Nov 26, 2020
1 parent f7449d9 commit 64c38f6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
15 changes: 15 additions & 0 deletions flow-tests/test-themes/frontend/theme/app-theme/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

import javax.servlet.annotation.WebServlet;

import java.io.PrintWriter;
import java.util.function.Consumer;

import com.vaadin.flow.server.VaadinServlet;

/**
* This is a temporary workaround until #5740 is fixed.
*
* @since 2.0
*/
@WebServlet("/*")
@WebServlet("/path/*")
public class WorkaroundServlet extends VaadinServlet {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,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));
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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 Not Found"));

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 Not Found"));
}
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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/");
}

}

0 comments on commit 64c38f6

Please sign in to comment.