aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-08-31 12:35:42 +0300
committerVaadin Code Review <review@vaadin.com>2015-09-02 07:58:57 +0000
commit4a2380605d171eec96fe7adb83f1de2dcc9edbae (patch)
tree9290b0ac48c64dcf4bf52aa7546b9065a8fa403c /uitest/src/com/vaadin/tests
parent0922cc0ee60fd1cddc1c189eac500a305aa9db92 (diff)
downloadvaadin-framework-4a2380605d171eec96fe7adb83f1de2dcc9edbae.tar.gz
vaadin-framework-4a2380605d171eec96fe7adb83f1de2dcc9edbae.zip
Detect broken Profiler.isEnabled() inlining
The mechanism that makes calls to e.g. Profiler.start() completely disappear if vaadin.profiler is set to false is quite fragile. Furhtermore, the implementation pattern has some parts that look like potential optimizations even though the end result would be the opposite. This patch adds a test that will fail if that kind of change has accidentally been introduced. Change-Id: Ic948feb4d3b73120dc3f245bcc130af16bfd32a9
Diffstat (limited to 'uitest/src/com/vaadin/tests')
-rw-r--r--uitest/src/com/vaadin/tests/debug/ProfilerZeroOverhead.java37
-rw-r--r--uitest/src/com/vaadin/tests/debug/ProfilerZeroOverheadTest.java51
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/ProfilerCompilationCanary.java48
3 files changed, 136 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/debug/ProfilerZeroOverhead.java b/uitest/src/com/vaadin/tests/debug/ProfilerZeroOverhead.java
new file mode 100644
index 0000000000..7daf38a0e5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/debug/ProfilerZeroOverhead.java
@@ -0,0 +1,37 @@
+/*
+ * 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.debug;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.tests.widgetset.client.ProfilerCompilationCanary;
+import com.vaadin.tests.widgetset.server.TestWidgetComponent;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class ProfilerZeroOverhead extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(new TestWidgetComponent(ProfilerCompilationCanary.class));
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test UI for verifying that Profiler.isEnabled() causes no side effects in generated javascript";
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/debug/ProfilerZeroOverheadTest.java b/uitest/src/com/vaadin/tests/debug/ProfilerZeroOverheadTest.java
new file mode 100644
index 0000000000..659823e49a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/debug/ProfilerZeroOverheadTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.debug;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ProfilerZeroOverheadTest extends SingleBrowserTest {
+ @Test
+ public void testZeroOverhead() {
+ openTestURL();
+
+ /*
+ * This will get the compiled JS for the
+ * ProfilerCompilationCanary.canaryWithProfiler method. Expected to be
+ * something like "function canaryWithProfiler(){\n}" with a PRETTY
+ * non-draft widgetset.
+ */
+ String canaryMethodString = findElement(By.className("gwt-Label"))
+ .getText();
+
+ // Only look at the method body to avoid false negatives if e.g.
+ // obfuscation changes
+ int bodyStart = canaryMethodString.indexOf('{');
+ int bodyEnd = canaryMethodString.lastIndexOf('}');
+
+ String methodBody = canaryMethodString
+ .substring(bodyStart + 1, bodyEnd);
+
+ // Method body shouldn't contain anything else than whitespace
+ if (!methodBody.replaceAll("\\s", "").isEmpty()) {
+ Assert.fail("Canary method is not empty: " + canaryMethodString);
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/ProfilerCompilationCanary.java b/uitest/src/com/vaadin/tests/widgetset/client/ProfilerCompilationCanary.java
new file mode 100644
index 0000000000..d5ab1da2f9
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/ProfilerCompilationCanary.java
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import com.google.gwt.user.client.ui.Label;
+import com.vaadin.client.Profiler;
+
+public class ProfilerCompilationCanary extends Label {
+ public ProfilerCompilationCanary() {
+ if (Profiler.isEnabled()) {
+ setText("Test does not work when profiler is enabled {dummyCode;}");
+ } else {
+ setText(getCanaryCode());
+ }
+ }
+
+ /*
+ * Finds the native js function for the canaryWithProfiler method and gets a
+ * string representation of it, which in most browsers produces the actual
+ * method implementation that we want to verify has an empty body.
+ */
+ private static native String getCanaryCode()
+ /*-{
+ return @ProfilerCompilationCanary::canaryWithProfiler(*).toString();
+ }-*/;
+
+ /*
+ * We don't care about running this method, we just want to make sure that
+ * the generated implementation is empty.
+ */
+ public static void canaryWithProfiler() {
+ Profiler.enter("canaryWithProfiler");
+ Profiler.leave("canaryWithProfiler");
+ }
+}