aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/window/MaximizedWindowOrderTest.java
blob: abf3443da81ba79a6a0f544fd0653c6dddeb3386 (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
package com.vaadin.tests.components.window;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.testbench.elements.WindowElement;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class MaximizedWindowOrderTest extends MultiBrowserTest {

    private WindowElement openAnotherWindow() {
        WindowElement maximizedWindow = getMaximizedWindow();
        maximizedWindow.$(ButtonElement.class).first().click();

        return getAnotherWindow();
    }

    private WindowElement getMaximizedWindow() {
        return $(WindowElement.class).first();
    }

    private WindowElement getAnotherWindow() {
        return $(WindowElement.class).get(1);
    }

    private WindowElement openMaximizedWindow() {
        $(ButtonElement.class).first().click();

        return getMaximizedWindow();
    }

    @Override
    public void setup() throws Exception {
        super.setup();
        openTestURL();
    }

    @Test
    public void newWindowOpensOnTopOfMaximizedWindow() {
        WindowElement maximizedWindow = openMaximizedWindow();
        WindowElement anotherWindow = openAnotherWindow();

        assertThat(anotherWindow.getCssValue("z-index"),
                is(greaterThan(maximizedWindow.getCssValue("z-index"))));

        assertThat(getMaximizedWindow().getCssValue("z-index"), is("10000"));
        assertThat(getAnotherWindow().getCssValue("z-index"), is("10001"));
    }

    @Test
    public void backgroundWindowIsBroughtOnTopWhenMaximized() {
        WindowElement maximizedWindow = openMaximizedWindow();

        maximizedWindow.restore();

        // the new window is opened on top of the original.
        WindowElement anotherWindow = openAnotherWindow();

        // move the window to make the maximize button visible.
        moveWindow(anotherWindow, 10, 20);
        maximizedWindow.maximize();

        assertThat(maximizedWindow.getCssValue("z-index"),
                is(greaterThan(anotherWindow.getCssValue("z-index"))));
    }

    private void moveWindow(WindowElement window, int xOffset, int yOffset) {
        WebElement wrap = window
                .findElement(org.openqa.selenium.By.className("v-window-wrap"));
        new Actions(getDriver())
                .moveToElement(wrap, getXOffset(wrap, 5), getYOffset(wrap, 5))
                .clickAndHold().moveByOffset(xOffset, yOffset).release().build()
                .perform();
    }
}