WebComponentBootstrapHandler extends BootstrapHandler { @Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { Class<? extends UI> uiClass = getUIClass(request); BootstrapContext context = createAndInitUI(uiClass, request, response, session); HandlerHelper.setResponseNoCacheHeaders(response::setHeader, response::setDateHeader); String serviceUrl = getServiceUrl(request, response); Document document = getPageBuilder().getBootstrapPage(context); writeBootstrapPage(response, document.head(), serviceUrl); return true; } WebComponentBootstrapHandler(); protected  WebComponentBootstrapHandler(PageBuilder pageBuilder); @Override boolean synchronizedHandleRequest(VaadinSession session,
            VaadinRequest request, VaadinResponse response);  }
@Test public void writeBootstrapPage_noPWA() throws IOException, ServiceException { TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler(); PwaRegistry registry = Mockito.mock(PwaRegistry.class); PwaConfiguration conf = Mockito.mock(PwaConfiguration.class); Mockito.when(registry.getPwaConfiguration()).thenReturn(conf); Mockito.when(conf.isEnabled()).thenReturn(true); Mockito.when(conf.getManifestPath()).thenReturn("bar"); PwaIcon icon = Mockito.mock(PwaIcon.class); Mockito.when(icon.asElement()).thenReturn(new Element("h1")); Mockito.when(registry.getHeaderIcons()) .thenReturn(Collections.singletonList(icon)); VaadinServletService service = new MockVaadinServletService() { @Override protected PwaRegistry getPwaRegistry() { return registry; }; }; service.init(); VaadinSession session = new MockVaadinSession(service); session.lock(); session.setConfiguration(service.getDeploymentConfiguration()); MockDeploymentConfiguration config = (MockDeploymentConfiguration) service .getDeploymentConfiguration(); config.setEnableDevServer(false); VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class); Mockito.when(request.getService()).thenReturn(service); Mockito.when(request.getServletPath()).thenReturn("/"); VaadinResponse response = getMockResponse(null); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Mockito.when(response.getOutputStream()).thenReturn(stream); handler.synchronizedHandleRequest(session, request, response); String result = stream.toString(StandardCharsets.UTF_8.name()); Assert.assertThat(result, CoreMatchers.not(CoreMatchers.containsString("bar"))); Assert.assertThat(result, CoreMatchers.not(CoreMatchers.containsString("h1"))); Assert.assertThat(result, CoreMatchers.not(CoreMatchers.containsString("baz"))); }
@Test public void writeBootstrapPage_devmodeGizmoIsDisabled() throws IOException, ServiceException { TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler(); VaadinServletService service = new MockVaadinServletService(); service.init(); VaadinSession session = new MockVaadinSession(service); session.lock(); session.setConfiguration(service.getDeploymentConfiguration()); MockDeploymentConfiguration config = (MockDeploymentConfiguration) service .getDeploymentConfiguration(); config.setEnableDevServer(false); VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class); Mockito.when(request.getService()).thenReturn(service); Mockito.when(request.getServletPath()).thenReturn("/"); VaadinResponse response = getMockResponse(null); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Mockito.when(response.getOutputStream()).thenReturn(stream); handler.synchronizedHandleRequest(session, request, response); String result = stream.toString(StandardCharsets.UTF_8.name()); Assert.assertTrue(result.contains("\\\"devmodeGizmoEnabled\\\": false")); }