Search in sources :

Example 11 with BootstrapContext

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\">"));
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 12 with BootstrapContext

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());
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 13 with BootstrapContext

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\">"));
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 14 with BootstrapContext

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();
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext)

Example 15 with BootstrapContext

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());
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) Component(com.vaadin.flow.component.Component) JavaScript(com.vaadin.flow.component.dependency.JavaScript) Inline(com.vaadin.flow.component.page.Inline) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) TargetElement(com.vaadin.flow.component.page.TargetElement) Registration(com.vaadin.flow.shared.Registration) PageTitle(com.vaadin.flow.router.PageTitle) Router(com.vaadin.flow.router.Router) Route(com.vaadin.flow.router.Route) RouteAlias(com.vaadin.flow.router.RouteAlias) Theme(com.vaadin.flow.theme.Theme) Assert.assertThat(org.junit.Assert.assertThat) Locale(java.util.Locale) Element(org.jsoup.nodes.Element) After(org.junit.After) UI(com.vaadin.flow.component.UI) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Document(org.jsoup.nodes.Document) LoadMode(com.vaadin.flow.shared.ui.LoadMode) BodySize(com.vaadin.flow.component.page.BodySize) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Elements(org.jsoup.select.Elements) ApplicationConstants(com.vaadin.flow.shared.ApplicationConstants) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Matchers(org.mockito.Matchers) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) Dependency(com.vaadin.flow.shared.ui.Dependency) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) Tag(com.vaadin.flow.component.Tag) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Before(org.junit.Before) Text(com.vaadin.flow.component.Text) RouterLayout(com.vaadin.flow.router.RouterLayout) Html(com.vaadin.flow.component.Html) StyleSheet(com.vaadin.flow.component.dependency.StyleSheet) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) Mockito(org.mockito.Mockito) Assert(org.junit.Assert) Collections(java.util.Collections) Viewport(com.vaadin.flow.component.page.Viewport) ParentLayout(com.vaadin.flow.router.ParentLayout) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) AtomicReference(java.util.concurrent.atomic.AtomicReference) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)36 Test (org.junit.Test)32 Document (org.jsoup.nodes.Document)31 Elements (org.jsoup.select.Elements)21 TargetElement (com.vaadin.flow.component.page.TargetElement)13 Element (org.jsoup.nodes.Element)13 UI (com.vaadin.flow.component.UI)9 Registration (com.vaadin.flow.shared.Registration)9 Component (com.vaadin.flow.component.Component)8 Html (com.vaadin.flow.component.Html)8 Tag (com.vaadin.flow.component.Tag)8 Text (com.vaadin.flow.component.Text)8 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)8 JavaScript (com.vaadin.flow.component.dependency.JavaScript)8 StyleSheet (com.vaadin.flow.component.dependency.StyleSheet)8 BodySize (com.vaadin.flow.component.page.BodySize)8 Inline (com.vaadin.flow.component.page.Inline)8 Viewport (com.vaadin.flow.component.page.Viewport)8 PageTitle (com.vaadin.flow.router.PageTitle)8 ParentLayout (com.vaadin.flow.router.ParentLayout)8