diff options
author | Bogdan Udrescu <bogdan@vaadin.com> | 2014-07-04 16:23:26 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-07-07 09:55:39 +0000 |
commit | 0eb8b337a936d8b39fb9a8793bafb83a302c86f5 (patch) | |
tree | d570786827bf806a2b52cc48f6fbbb3d7cc7659c | |
parent | 7b008eb818d2d27bd7034321bcbe07d24a6e60d8 (diff) | |
download | vaadin-framework-0eb8b337a936d8b39fb9a8793bafb83a302c86f5.tar.gz vaadin-framework-0eb8b337a936d8b39fb9a8793bafb83a302c86f5.zip |
Return a value on __gwtStatsEvent in Profiler (#11709)
Calling GWT RPC throw an exception when __gwtStatsEvent doesn't return
a boolean. This was in the Profiler.ensureNoLogger where the function
assigned was empty.
Change-Id: If97e15eb3c2c6512e80f3bde81ba180b8c95c947
9 files changed, 377 insertions, 15 deletions
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index 268fe1ea66..fb2ddbd998 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -44,6 +44,11 @@ <async-supported>true</async-supported> </servlet> <servlet> + <servlet-name>GwtRpcTest</servlet-name> + <servlet-class>com.vaadin.tests.widgetset.server.gwtrpc.GwtRpcServletTest</servlet-class> + </servlet> + + <servlet> <servlet-name>UI provider app</servlet-name> <servlet-class>com.vaadin.server.VaadinServlet</servlet-class> <init-param> @@ -134,15 +139,19 @@ <param-value>false</param-value> </init-param> </servlet> + <servlet-mapping> <servlet-name>Embed App 1</servlet-name> <url-pattern>/embed1/*</url-pattern> </servlet-mapping> - <servlet-mapping> <servlet-name>Embed App 2</servlet-name> <url-pattern>/embed2/*</url-pattern> </servlet-mapping> + <servlet-mapping> + <servlet-name>GwtRpcTest</servlet-name> + <url-pattern>/VAADIN/widgetsets/com.vaadin.tests.widgetset.TestingWidgetSet/GwtRpcTest/*</url-pattern> + </servlet-mapping> <servlet-mapping> <servlet-name>UI provider app</servlet-name> diff --git a/client/src/com/vaadin/client/Profiler.java b/client/src/com/vaadin/client/Profiler.java index 2174e00de1..6c0967099f 100644 --- a/client/src/com/vaadin/client/Profiler.java +++ b/client/src/com/vaadin/client/Profiler.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -37,14 +37,14 @@ import com.vaadin.client.debug.internal.ProfilerSection.ProfilerResultConsumer; * zero overhead unless enabled. To enable profiling, add * <code><set-property name="vaadin.profiler" value="true" /></code> to * your .gwt.xml file. - * + * * @author Vaadin Ltd * @since 7.0.0 */ public class Profiler { /** * Class to include using deferred binding to enable the profiling. - * + * * @author Vaadin Ltd * @since 7.0.0 */ @@ -101,7 +101,7 @@ public class Profiler { /** * Checks whether the profiling gathering is enabled. - * + * * @return <code>true</code> if the profiling is enabled, else * <code>false</code> */ @@ -115,7 +115,7 @@ public class Profiler { * Enters a named block. There should always be a matching invocation of * {@link #leave(String)} when leaving the block. Calls to this method will * be removed by the compiler unless profiling is enabled. - * + * * @param name * the name of the entered block */ @@ -129,7 +129,7 @@ public class Profiler { * Leaves a named block. There should always be a matching invocation of * {@link #enter(String)} when entering the block. Calls to this method will * be removed by the compiler unless profiling is enabled. - * + * * @param name * the name of the left block */ @@ -178,7 +178,7 @@ public class Profiler { * enabled because it will then remove a logger function that might have * been included in the HTML page and that would leak memory unless removed. * </p> - * + * * @since 7.0.2 */ public static void initialize() { @@ -281,7 +281,7 @@ public class Profiler { /** * Overridden in {@link EnabledProfiler} to make {@link #isEnabled()} return * true if GWT.create returns that class. - * + * * @return <code>true</code> if the profiling is enabled, else * <code>false</code> */ @@ -352,7 +352,7 @@ public class Profiler { if (typeof $wnd.__gwtStatsEvent != 'function') { if (typeof $wnd.vaadin.gwtStatsEvents != 'object') { $wnd.vaadin.gwtStatsEvents = []; - } + } $wnd.__gwtStatsEvent = function(event) { $wnd.vaadin.gwtStatsEvents.push(event); return true; @@ -369,9 +369,9 @@ public class Profiler { if (typeof $wnd.vaadin.gwtStatsEvents == 'object') { delete $wnd.vaadin.gwtStatsEvents; if (typeof $wnd.__gwtStatsEvent == 'function') { - $wnd.__gwtStatsEvent = function(){}; + $wnd.__gwtStatsEvent = function() { return true; }; } - } + } }-*/; private static native JsArray<GwtStatsEvent> clearEventsList() @@ -385,7 +385,7 @@ public class Profiler { * <p> * <b>Warning!</b> This is internal API and should not be used by * applications or add-ons. - * + * * @since 7.1.4 * @param profilerResultConsumer * the consumer that gets profiler data diff --git a/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcButtonConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcButtonConnector.java new file mode 100644 index 0000000000..43d96afd2b --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcButtonConnector.java @@ -0,0 +1,123 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.client.gwtrpc; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.google.gwt.core.shared.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.Label; +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.gwtrpc.GwtRpcButton; + +/** + * Dummy connector to test our Vaadin/GWT RPC bug. In a Vaadin environment with + * DevMode enabled, a pure GWT RPC call would throw an exception. See #11709. + * + * @author Vaadin Ltd + */ +@SuppressWarnings("serial") +@Connect(GwtRpcButton.class) +public class GwtRpcButtonConnector extends AbstractComponentConnector { + + static Logger logger = Logger.getLogger(GwtRpcButtonConnector.class + .getName()); + static { + logger.setLevel(Level.ALL); + } + + @Override + public Button getWidget() { + return (Button) super.getWidget(); + } + + @Override + protected Button createWidget() { + return GWT.create(Button.class); + } + + private void log(String message) { + logger.log(Level.INFO, message); + } + + @Override + public void init() { + super.init(); + + log("GwtRpcButtonTestConnector init"); + + getWidget().setText("Click me"); + getWidget().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + doRPC(); + } + + }); + } + + /** + * The ID of the label in case the test is successful. + */ + public static final String SUCCESS_LABEL_ID = "yes"; + + /** + * The ID of the label in case the test failed. + */ + public static final String FAIL_LABEL_ID = "no"; + + /* + * Make an RPC to test our bug. + */ + private void doRPC() { + log("GwtRpcButtonTestConnector onClick"); + + GwtRpcServiceTestAsync service = GWT.create(GwtRpcServiceTest.class); + + service.giveMeThat("honey", "sugar", new AsyncCallback<String>() { + + @Override + public void onSuccess(String result) { + showResult(result, SUCCESS_LABEL_ID); + } + + @Override + public void onFailure(Throwable caught) { + showResult(caught.getMessage(), FAIL_LABEL_ID); + } + + /* + * Show the result box. + */ + private void showResult(String result, String labelID) { + DialogBox box = new DialogBox(true); + Label label = new Label(result); + label.getElement().setId(labelID); + box.add(label); + box.center(); + box.show(); + } + + }); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcServiceTest.java b/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcServiceTest.java new file mode 100644 index 0000000000..16df928d77 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcServiceTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.client.gwtrpc; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +/** + * Test GWT RPC in Vaadin DevMode. + * + * @author Vaadin Ltd + */ +@RemoteServiceRelativePath("GwtRpcTest") +public interface GwtRpcServiceTest extends RemoteService { + + /* + * Dummy method to verify if RPC works. + */ + String giveMeThat(String that, String haveThis); + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcServiceTestAsync.java b/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcServiceTestAsync.java new file mode 100644 index 0000000000..93eda8ca34 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/gwtrpc/GwtRpcServiceTestAsync.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.client.gwtrpc; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * Test GWT RPC in Vaadin DevMode. + * + * @author Vaadin Ltd + */ +public interface GwtRpcServiceTestAsync { + + /* + * Dummy async method to verify if RPC works. + */ + void giveMeThat(String that, String haveThis, AsyncCallback<String> callback); + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpc.java b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpc.java new file mode 100644 index 0000000000..c9f949c465 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpc.java @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.server.gwtrpc; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; + +/** + * Test the GWT RPC with Vaadin DevMode. See #11709. + * + * @author Vaadin Ltd + */ +@SuppressWarnings("serial") +@Widgetset(TestingWidgetSet.NAME) +public class GwtRpc extends AbstractTestUI { + + /** + * Id of the button triggering the test case. + */ + public final static String BUTTON_ID = "gwtRpcButton"; + + @Override + protected void setup(VaadinRequest request) { + GwtRpcButton button = new GwtRpcButton(); + button.setId(BUTTON_ID); + button.setCaption("Press me"); + + addComponent(button); + } + + @Override + protected String getTestDescription() { + return "Cannot call RPC in development mode"; + } + + @Override + protected Integer getTicketNumber() { + return 11709; + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcButton.java b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcButton.java new file mode 100644 index 0000000000..c04800713d --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcButton.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.server.gwtrpc; + +import com.vaadin.ui.AbstractComponent; + +/** + * Dummy client connector to link with the client functionality where the GWT + * RPC is triggered. + * + * @since + * @author Vaadin Ltd + */ +@SuppressWarnings("serial") +public class GwtRpcButton extends AbstractComponent { + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcServletTest.java b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcServletTest.java new file mode 100644 index 0000000000..df01b4dc81 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcServletTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.server.gwtrpc; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.vaadin.tests.widgetset.client.gwtrpc.GwtRpcServiceTest; + +/** + * Test GWT RPC in Vaadin DevMode. + * + * @author Vaadin Ltd + */ +@SuppressWarnings("serial") +public class GwtRpcServletTest extends RemoteServiceServlet implements + GwtRpcServiceTest { + + @Override + public String giveMeThat(String that, String haveThis) { + return "Take " + that + " for " + haveThis; + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcTest.java b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcTest.java new file mode 100644 index 0000000000..d27884a13a --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/gwtrpc/GwtRpcTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.widgetset.server.gwtrpc; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.widgetset.client.gwtrpc.GwtRpcButtonConnector; + +/** + * Test the GWT RPC with Vaadin DevMode. See #11709. + * + * @author Vaadin Ltd + */ +public class GwtRpcTest extends MultiBrowserTest { + + @Test + public void testGwtRpc() { + openTestURL(); + + getDriver().findElement(By.id(GwtRpc.BUTTON_ID)).click(); + + By label = By.id(GwtRpcButtonConnector.SUCCESS_LABEL_ID); + + waitForElementToBePresent(label); + getDriver().findElement(label); + } + +} |