aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java
blob: a09c4c845a71b19044e6d25bc27c1333bce8099d (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.vaadin.tests.application;

import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

public class ErrorInUnloadEvent extends AbstractTestCase {

    private LegacyWindow mainWindow;
    private Object user = null;

    @Override
    public void init() {
        if (user == null) {
            showLoginWindow();
        } else {
            showMainWindow();
        }
    }

    private void showLoginWindow() {
        if (mainWindow == null) {
            mainWindow = new LegacyWindow();
            setMainWindow(mainWindow);
        } else {
            mainWindow.removeAllComponents();
        }
        mainWindow.setCaption("Please login");

        FormLayout formLayout = new FormLayout();
        final TextField userField = new TextField("Username");
        userField.setId("user");
        final PasswordField passwordField = new PasswordField("Password");
        passwordField.setId("pwd");
        Button login = new Button("login");
        login.setId("loginButton");
        login.setClickShortcut(KeyCode.ENTER);
        formLayout.addComponent(userField);
        formLayout.addComponent(passwordField);
        formLayout.addComponent(login);
        mainWindow.setContent(formLayout);

        login.addListener(new ClickListener() {
            @Override
            public void buttonClick(final ClickEvent event) {
                String username = userField.getValue();
                String password = passwordField.getValue();

                user = username;
                showMainWindow();
            }
        });
    }

    private void showMainWindow() {
        if (mainWindow == null) {
            mainWindow = new LegacyWindow();
            setMainWindow(mainWindow);
        } else {
            mainWindow.removeAllComponents();
        }
        VerticalLayout root = new VerticalLayout();
        root.addComponent(createHeader());

        mainWindow.addComponent(root);
    }

    private Component createHeader() {
        HorizontalLayout header = new HorizontalLayout();
        header.addStyleName("header-background");
        Label title = new Label("...Title...");
        title.addStyleName("header-title");
        header.addComponent(title);
        Button logout = new Button("Logout");
        logout.addListener(new ClickListener() {
            @Override
            public void buttonClick(final ClickEvent event) {
                user = null;
                showLoginWindow();
            }

        });
        header.addComponent(logout);
        return header;
    }

    @Override
    protected String getDescription() {
        return "Enter a text in the password field and press enter. Then reload the page. No error message should be printed about ignoring a variable change.";
    }

    @Override
    protected Integer getTicketNumber() {
        return 6316;
    }
}