aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/debug/ProfilerZeroOverheadTest.java
blob: 57727e2a81a83f49dccccfd952c0ae27ce1ed4e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.vaadin.tests.debug;

import static org.junit.Assert.fail;

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()) {
            fail("Canary method is not empty: " + canaryMethodString);
        }
    }
}