use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method bootstrap_page_has_viewport_for_route_parent.
// #3008
@Test
public void bootstrap_page_has_viewport_for_route_parent() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(RootWithParent.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 BootstrapHandlerTest method page_configurator_adds_link.
// 3036
@Test
public void page_configurator_adds_link() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorLinks.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
Assert.assertEquals("<link href=\"icons/favicon.ico\" rel=\"shortcut icon\">", allElements.get(allElements.size() - 2).toString());
Assert.assertEquals("<link href=\"icons/icon-192.png\" rel=\"icon\" sizes=\"192x192\">", allElements.get(allElements.size() - 1).toString());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method page_configurator_overrides_viewport.
// 3036
@Test
public void page_configurator_overrides_viewport() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorViewportOverride.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Assert.assertFalse("Viewport annotation value found even if it should be overridden.", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
Assert.assertTrue("Viewport annotation value not the expected one.", page.toString().contains("<meta name=\"viewport\" content=\"width=100\">"));
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method initTestUI.
private Element initTestUI() {
TestUI anotherUI = new TestUI();
initUI(testUI);
anotherUI.getInternals().setSession(session);
VaadinRequest vaadinRequest = createVaadinRequest();
anotherUI.doInit(vaadinRequest, 0);
BootstrapContext bootstrapContext = new BootstrapContext(vaadinRequest, null, session, anotherUI);
return BootstrapHandler.getBootstrapPage(bootstrapContext).head();
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method testBootstrapListener.
@Test
public void testBootstrapListener() throws ServiceException {
List<BootstrapListener> listeners = new ArrayList<>(3);
AtomicReference<VaadinUriResolver> resolver = new AtomicReference<>();
listeners.add(evt -> evt.getDocument().head().getElementsByTag("script").remove());
listeners.add(evt -> {
resolver.set(evt.getUriResolver());
evt.getDocument().head().appendElement("script").attr("src", "testing.1");
});
listeners.add(evt -> evt.getDocument().head().appendElement("script").attr("src", "testing.2"));
Mockito.when(service.createInstantiator()).thenReturn(new MockInstantiator(event -> listeners.forEach(event::addBootstrapListener)));
initUI(testUI);
BootstrapContext bootstrapContext = new BootstrapContext(request, null, session, testUI);
Document page = BootstrapHandler.getBootstrapPage(bootstrapContext);
Elements scripts = page.head().getElementsByTag("script");
assertEquals(2, scripts.size());
assertEquals("testing.1", scripts.get(0).attr("src"));
assertEquals("testing.2", scripts.get(1).attr("src"));
Assert.assertNotNull(resolver.get());
Assert.assertEquals(bootstrapContext.getUriResolver(), resolver.get());
}
Aggregations