diff options
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"); + } +} |