package com.vaadin.tests.components.window;

import com.vaadin.server.ExternalResource;
import com.vaadin.tests.TestForWindowOpen;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.LegacyWindow;

public class LegacyWindowOpenTest extends TestBase {

    final ExternalResource r = new ExternalResource("http://www.google.com");

    @Override
    protected void setup() {
        final LegacyWindow win = getMainWindow();

        addComponent(new TestForWindowOpen());

        addComponent(new Button("Window.open _blank always as popup",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        win.open(r, "_blank", true);
                    }
                }));

        addComponent(new Button("Window.open _blank NOT always as popup",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        win.open(r, "_blank", false);
                    }
                }));

        addComponent(new Button("Window.open _new always as popup",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        win.open(r, "_new", true);
                    }
                }));

        addComponent(new Button("Window.open _new NOT always as popup",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        win.open(r, "_new", false);
                    }
                }));
        addComponent(new Button(
                "Window execute Javascript window.open(www.google.com, _blank)",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        win.executeJavaScript("window.open(\"http://www.google.com\", \"_blank\");");
                    }
                }));
        addComponent(new Button(
                "Window execute Javascript window.open(www.google.com, _blank, resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes)",
                new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        win.executeJavaScript("window.open(\"http://www.google.com\", \"_blank\", \"resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes\");");
                    }
                }));

    }

    @Override
    protected String getDescription() {
        return "Windows never opened to a new tab";
    }

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

}
