use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.
the class UidlRequestHandler method writeUidl.
void writeUidl(UI ui, Writer writer, boolean resync) throws IOException {
JsonObject uidl = createUidl(ui, resync);
if (ui instanceof JavaScriptBootstrapUI) {
removeOffendingMprHashFragment(uidl);
}
// some dirt to prevent cross site scripting
String responseString = "for(;;);[" + uidl.toJson() + "]";
writer.write(responseString);
}
use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.
the class JavaScriptBootstrapHandlerTest method should_attachViewTo_Body_when_serverRouting.
@Test
public void should_attachViewTo_Body_when_serverRouting() throws Exception {
VaadinRequest request = mocks.createRequest(mocks, "/", "v-r=init&location=bar%3Fpar1%26par2&serverSideRouting");
jsInitHandler.handleRequest(session, request, response);
JavaScriptBootstrapUI ui = (JavaScriptBootstrapUI) UI.getCurrent();
TestNodeVisitor visitor = new TestNodeVisitor(true);
BasicElementStateProvider.get().visit(ui.getElement().getNode(), visitor);
Assert.assertTrue(hasNodeTag(visitor, "^<body>.*", ElementType.REGULAR));
Assert.assertTrue(hasNodeTag(visitor, "^<div>.*", ElementType.REGULAR));
Assert.assertTrue(hasNodeTag(visitor, "^<div>.*Could not navigate to 'bar'.*", ElementType.REGULAR));
Mockito.verify(session, Mockito.times(1)).setAttribute(SERVER_ROUTING, Boolean.TRUE);
}
use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.
the class UidlRequestHandlerTest method should_updateHash_when_v7LocationNotProvided.
@Test
public void should_updateHash_when_v7LocationNotProvided() throws Exception {
JavaScriptBootstrapUI ui = mock(JavaScriptBootstrapUI.class);
UidlRequestHandler handler = spy(new UidlRequestHandler());
StringWriter writer = new StringWriter();
JsonObject uidl = generateUidl(false, true);
doReturn(uidl).when(handler).createUidl(ui, false);
handler.writeUidl(ui, writer, false);
String out = writer.toString();
uidl = JsonUtil.parse(out.substring(9, out.length() - 1));
assertEquals("setTimeout(() => history.pushState(null, null, location.pathname + location.search + '#!away'));", uidl.getArray("execute").getArray(1).getString(1));
}
use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.
the class UidlRequestHandlerTest method should_modifyUidl_when_MPR_JavaScriptBootstrapUI.
@Test
public void should_modifyUidl_when_MPR_JavaScriptBootstrapUI() throws Exception {
JavaScriptBootstrapUI ui = mock(JavaScriptBootstrapUI.class);
UidlRequestHandler handler = spy(new UidlRequestHandler());
StringWriter writer = new StringWriter();
JsonObject uidl = generateUidl(true, true);
doReturn(uidl).when(handler).createUidl(ui, false);
handler.writeUidl(ui, writer, false);
String out = writer.toString();
uidl = JsonUtil.parse(out.substring(9, out.length() - 1));
String v7Uidl = uidl.getArray("execute").getArray(2).getString(1);
assertFalse(v7Uidl.contains("http://localhost:9998/#!away"));
assertTrue(v7Uidl.contains("http://localhost:9998/"));
assertFalse(v7Uidl.contains("window.location.hash = '!away';"));
}
use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.
the class UidlRequestHandlerTest method should_not_modifyUidl_when_MPR_nonJavaScriptBootstrapUI.
@Test
public void should_not_modifyUidl_when_MPR_nonJavaScriptBootstrapUI() throws Exception {
JavaScriptBootstrapUI ui = null;
UidlRequestHandler handler = spy(new UidlRequestHandler());
StringWriter writer = new StringWriter();
JsonObject uidl = generateUidl(true, true);
doReturn(uidl).when(handler).createUidl(ui, false);
handler.writeUidl(ui, writer, false);
String out = writer.toString();
assertTrue(out.startsWith("for(;;);[{"));
assertTrue(out.endsWith("}]"));
uidl = JsonUtil.parse(out.substring(9, out.length() - 1));
String v7Uidl = uidl.getArray("execute").getArray(2).getString(1);
assertTrue(v7Uidl.contains("http://localhost:9998/#!away"));
assertTrue(v7Uidl.contains("window.location.hash = '!away';"));
assertEquals("setTimeout(() => window.history.pushState(null, '', $0))", uidl.getArray("execute").getArray(1).getString(1));
}
Aggregations