summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/application/WebBrowserTimeZone.java
blob: 5253b0b0e7045985dd9d353092edb0962d3e8d16 (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
package com.vaadin.tests.application;

import java.util.Arrays;
import java.util.Date;
import java.util.TimeZone;

import com.vaadin.server.VaadinRequest;
import com.vaadin.testbench.annotations.RunLocally;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;

@RunLocally
public class WebBrowserTimeZone extends AbstractTestUI {

    @Override
    protected void setup(VaadinRequest request) {

        final Label offsetLabel = addLabel("Browser offset");
        final Label rawOffsetLabel = addLabel("Browser raw offset");
        final Label dstDiffLabel = addLabel("Difference between raw offset and DST");
        final Label dstInEffectLabel = addLabel("Is DST currently active?");
        final Label curDateLabel = addLabel("Current date in the browser");
        final Label diffLabel = addLabel("Browser to Europe/Helsinki offset difference");
        final Label containsLabel = addLabel("Browser could be in Helsinki");

        addButton("Get TimeZone from browser", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                TimeZone hkiTZ = TimeZone.getTimeZone("Europe/Helsinki");
                int hkiOffset = hkiTZ.getOffset(new Date().getTime());

                int browserOffset = getBrowser().getTimezoneOffset();
                int browserRawOffset = getBrowser().getRawTimezoneOffset();
                String[] tzs = TimeZone.getAvailableIDs(browserRawOffset);

                boolean contains = Arrays.asList(tzs).contains(hkiTZ.getID());

                offsetLabel.setValue(String.valueOf(browserOffset));
                rawOffsetLabel.setValue(String.valueOf(browserRawOffset));
                diffLabel.setValue(String.valueOf(browserOffset - hkiOffset));
                containsLabel.setValue(contains ? "Yes" : "No");
                dstDiffLabel.setValue(String.valueOf(getBrowser()
                        .getDSTSavings()));
                dstInEffectLabel.setValue(getBrowser().isDSTInEffect() ? "Yes"
                        : "No");
                curDateLabel.setValue(getBrowser().getCurrentDate().toString());
            }
        });
    }

    private Label addLabel(String caption) {
        final Label label = new Label("n/a");
        label.setCaption(caption);
        addComponent(label);
        return label;
    }

    @Override
    protected String getTestDescription() {
        return "Verifies that browser TimeZone offset works - should be same as server in our case (NOTE assumes server+browser in same TZ)";
    }

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

}