aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin/tests/application/ConfirmBrowserTabClose.java
blob: e7ae9647f934685d523c7f9d1141530810bbdb5c (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
package com.vaadin.tests.application;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button;
import com.vaadin.ui.JavaScript;

public class ConfirmBrowserTabClose extends AbstractTestUIWithLog {

    @Override
    protected void setup(VaadinRequest request) {
        // To test the behavior, do
        // 1. Open the test in the browser
        // 2. Close the browser tab/window
        // 3. Choose to stay on the page after all
        // 4. Click the button
        // There should be no error
        Button b = new Button("Say hello", event -> log("Hello"));
        addComponent(b);
        JavaScript.eval("window.addEventListener('beforeunload', function (e) {"
                + "var confirmationMessage = 'Please stay!';"
                + "e.returnValue = confirmationMessage;"
                + "return confirmationMessage;" + "});");
    }
}