use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method page_configurator_link_shorthands_are_added_correctly.
// 3203
@Test
public void page_configurator_link_shorthands_are_added_correctly() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorLinkShorthands.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_inlines_javascript_from_content.
// 3036
@Test
public void page_configurator_inlines_javascript_from_content() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorPrependContents.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
// Note element 0 is the full head element.
assertStringEquals("Content javascript should have been prepended to head element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"content script\");</script>", allElements.get(1).toString());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method uiInitialization_allRegisteredListenersAreNotified.
// UIInitListeners
@Test
public void uiInitialization_allRegisteredListenersAreNotified() {
BootstrapHandler bootstrapHandler = new BootstrapHandler();
VaadinResponse response = Mockito.mock(VaadinResponse.class);
AtomicReference<UI> uiReference = new AtomicReference<>();
Registration registration = service.addUIInitListener(event -> Assert.assertTrue("Atomic reference was not empty.", uiReference.compareAndSet(null, event.getUI())));
final BootstrapContext context = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", context.getUI(), uiReference.get());
// unregister listener
registration.remove();
AtomicReference<UI> secondListenerReference = new AtomicReference<>();
service.addUIInitListener(event -> Assert.assertTrue("Atomic reference did not contain previous UI.", uiReference.compareAndSet(context.getUI(), event.getUI())));
service.addUIInitListener(event -> Assert.assertTrue("Atomic reference was not empty.", secondListenerReference.compareAndSet(null, event.getUI())));
final BootstrapContext secondInit = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", secondInit.getUI(), uiReference.get());
Assert.assertEquals("Second event UI didn't match initialized UI instance.", secondInit.getUI(), secondListenerReference.get());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method uiInitialization_changingListenersOnEventWorks.
// UIInitListeners
@Test
public void uiInitialization_changingListenersOnEventWorks() {
BootstrapHandler bootstrapHandler = new BootstrapHandler();
VaadinResponse response = Mockito.mock(VaadinResponse.class);
AtomicReference<UI> uiReference = new AtomicReference<>();
Registration registration = service.addUIInitListener(event -> service.addUIInitListener(laterEvent -> uiReference.compareAndSet(null, laterEvent.getUI())));
bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", null, uiReference.get());
// unregister listener
registration.remove();
service.addUIInitListener(event -> registration.remove());
final BootstrapContext secondInit = bootstrapHandler.createAndInitUI(TestUI.class, createVaadinRequest(), response, session);
Assert.assertEquals("Event UI didn't match initialized UI instance.", secondInit.getUI(), uiReference.get());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method headHasMetaTags.
@Test
public void headHasMetaTags() throws Exception {
initUI(testUI, createVaadinRequest());
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Element head = page.head();
Elements metas = head.getElementsByTag("meta");
Assert.assertEquals(2, metas.size());
Element meta = metas.get(0);
assertEquals("Content-Type", meta.attr("http-equiv"));
assertEquals("text/html; charset=utf-8", meta.attr("content"));
meta = metas.get(1);
assertEquals("X-UA-Compatible", meta.attr("http-equiv"));
assertEquals("IE=edge", meta.attr("content"));
}
Aggregations