From c4d3ca692e8086ce93540b26bbfd41faa9510d07 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 13 Aug 2012 13:58:22 +0300 Subject: Refactor to have separate BootstrapListener methods (#9274) --- .../vaadin/tests/vaadincontext/BoostrapModify.html | 9 +++++-- .../vaadincontext/TestVaadinContextListener.java | 29 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) (limited to 'tests/testbench/com/vaadin') diff --git a/tests/testbench/com/vaadin/tests/vaadincontext/BoostrapModify.html b/tests/testbench/com/vaadin/tests/vaadincontext/BoostrapModify.html index d5ab5af108..84c02254b4 100644 --- a/tests/testbench/com/vaadin/tests/vaadincontext/BoostrapModify.html +++ b/tests/testbench/com/vaadin/tests/vaadincontext/BoostrapModify.html @@ -23,8 +23,13 @@ assertText - //h1 - This is a heading + //div[1] + Added by modifyBootstrapPage + + + assertText + //div[2] + Added by modifyBootstrapFragment diff --git a/tests/testbench/com/vaadin/tests/vaadincontext/TestVaadinContextListener.java b/tests/testbench/com/vaadin/tests/vaadincontext/TestVaadinContextListener.java index fa2767a023..9d1fc6b6c3 100644 --- a/tests/testbench/com/vaadin/tests/vaadincontext/TestVaadinContextListener.java +++ b/tests/testbench/com/vaadin/tests/vaadincontext/TestVaadinContextListener.java @@ -4,7 +4,12 @@ package com.vaadin.tests.vaadincontext; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; + +import com.vaadin.terminal.gwt.server.BootstrapFragmentResponse; import com.vaadin.terminal.gwt.server.BootstrapListener; +import com.vaadin.terminal.gwt.server.BootstrapPageResponse; import com.vaadin.terminal.gwt.server.BootstrapResponse; import com.vaadin.terminal.gwt.server.VaadinContextEvent; import com.vaadin.terminal.gwt.server.VaadinContextListener; @@ -15,11 +20,27 @@ public class TestVaadinContextListener implements VaadinContextListener { public void contextCreated(VaadinContextEvent event) { event.getVaadinContext().addBootstrapListener(new BootstrapListener() { @Override - public void modifyBootstrap(BootstrapResponse response) { + public void modifyBootstrapFragment( + BootstrapFragmentResponse response) { + if (shouldModify(response)) { + Element heading = new Element(Tag.valueOf("div"), "") + .text("Added by modifyBootstrapFragment"); + response.getFragmentNodes().add(0, heading); + } + } + + private boolean shouldModify(BootstrapResponse response) { Root root = response.getRoot(); - if (root != null && root.getClass() == BoostrapModifyRoot.class) { - response.getApplicationTag().before( - "

This is a heading

"); + boolean shouldModify = root != null + && root.getClass() == BoostrapModifyRoot.class; + return shouldModify; + } + + @Override + public void modifyBootstrapPage(BootstrapPageResponse response) { + if (shouldModify(response)) { + response.getDocument().body().child(0) + .before("
Added by modifyBootstrapPage
"); } } }); -- cgit v1.2.3