use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method bootstrap_page_has_viewport_for_route_alias_parent.
// #3008
@Test
public void bootstrap_page_has_viewport_for_route_alias_parent() throws InvalidRouteConfigurationException {
HttpServletRequest httpRequest = Mockito.mock(HttpServletRequest.class);
Mockito.doAnswer(invocation -> "").when(httpRequest).getServletPath();
VaadinServletRequest vaadinRequest = new VaadinServletRequest(httpRequest, service);
initUI(testUI, vaadinRequest, Collections.singleton(AliasLayout.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(vaadinRequest, null, session, testUI));
Assert.assertFalse("Viewport found even though not part of Route", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
Mockito.doAnswer(invocation -> "/alias").when(httpRequest).getPathInfo();
page = BootstrapHandler.getBootstrapPage(new BootstrapContext(vaadinRequest, null, session, testUI));
Assert.assertTrue("Viewport meta tag was missing even tough alias route parent has annotation", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method bootstrap_page_has_viewport_for_route_top_parent.
// #3008
@Test
public void bootstrap_page_has_viewport_for_route_top_parent() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(RootWithParents.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Assert.assertTrue("Viewport meta tag was missing", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerDependenciesTest method initUIAndGetPage.
private Document initUIAndGetPage(UI ui) {
ui.getInternals().setSession(session);
VaadinRequest request = new VaadinServletRequest(createRequest(), service);
service.init();
ui.doInit(request, 0);
return BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, ui));
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method testBody.
// #1134
@Test
public void testBody() throws Exception {
initUI(testUI, createVaadinRequest());
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Element body = page.head().nextElementSibling();
assertEquals("body", body.tagName());
assertEquals("html", body.parent().tagName());
assertEquals(2, body.parent().childNodeSize());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method use_inline_to_append_files_to_head.
// 3010
@Test
public void use_inline_to_append_files_to_head() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InlineAnnotations.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
assertStringEquals("File javascript should have been appended to head element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"inline.js\");</script>", allElements.get(allElements.size() - 3).toString());
assertStringEquals("File html should have been appended to head element", "<script type=\"text/javascript\">\n" + " // document.body might not yet be accessible, so just leave a message\n" + " window.messages = window.messages || [];\n" + " window.messages.push(\"inline.html\");\n" + "</script>", allElements.get(allElements.size() - 2).toString());
assertStringEquals("File css should have been appended to head element", "<style type=\"text/css\">/* inline.css */\n" + "\n" + "#preloadedDiv {\n" + " color: rgba(255, 255, 0, 1);\n" + "}\n" + "\n" + "#inlineCssTestDiv {\n" + " color: rgba(255, 255, 0, 1);\n" + "}</style>", allElements.get(allElements.size() - 1).toString());
}
Aggregations