Search in sources :

Example 1 with VisibilityWindowAdapter

use of org.eclipse.swt.browser.VisibilityWindowAdapter in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_newAdapter_closeShell.

@Test
public void test_VisibilityWindowListener_newAdapter_closeShell() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    browser.addVisibilityWindowListener(new VisibilityWindowAdapter() {
    });
    shell.close();
}
Also used : VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) Shell(org.eclipse.swt.widgets.Shell) Display(org.eclipse.swt.widgets.Display) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Example 2 with VisibilityWindowAdapter

use of org.eclipse.swt.browser.VisibilityWindowAdapter in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_VisibilityWindowListener_multiple_shells.

/**
 * Verify that if multiple child shells are open, no duplicate visibility events are sent.
 */
@Test
public void test_VisibilityWindowListener_multiple_shells() {
    AtomicBoolean secondChildCompleted = new AtomicBoolean(false);
    AtomicInteger childCount = new AtomicInteger(0);
    browser.addOpenWindowListener(event -> {
        Shell childShell = new Shell(shell);
        childShell.setText("Child shell " + childCount.get());
        childShell.setLayout(new FillLayout());
        Browser browserChild = new Browser(childShell, SWT.NONE);
        event.browser = browserChild;
        browserChild.setText("Child window");
        browserChild.addVisibilityWindowListener(new VisibilityWindowAdapter() {

            AtomicInteger invocationCount = new AtomicInteger(1);

            AtomicInteger childID = new AtomicInteger(childCount.get());

            @Override
            public void show(WindowEvent event) {
                if (childID.get() == 0 && invocationCount.get() >= 2) {
                    // are considered 'legal' as long as they don't contain size and location information.
                    if (event.location != null || event.size != null) {
                        fail("Child browser's visibility show listener should only be fired once");
                    }
                }
                invocationCount.incrementAndGet();
            }
        });
        if (childCount.get() == 1) {
            browserChild.addProgressListener(new ProgressAdapter() {

                @Override
                public void completed(ProgressEvent event) {
                    secondChildCompleted.set(true);
                }
            });
        }
        childShell.open();
        childCount.incrementAndGet();
    });
    shell.open();
    browser.setText("<html>" + "<script type='text/javascript'>" + // opens child window.
    "window.open();" + "window.open();" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
    boolean passed = waitForPassCondition(() -> secondChildCompleted.get());
    String errMsg = "\nTest timed out.";
    assertTrue(errMsg, passed);
}
Also used : VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WindowEvent(org.eclipse.swt.browser.WindowEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Browser(org.eclipse.swt.browser.Browser) Test(org.junit.Test)

Aggregations

Browser (org.eclipse.swt.browser.Browser)2 VisibilityWindowAdapter (org.eclipse.swt.browser.VisibilityWindowAdapter)2 Shell (org.eclipse.swt.widgets.Shell)2 Test (org.junit.Test)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ProgressAdapter (org.eclipse.swt.browser.ProgressAdapter)1 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)1 WindowEvent (org.eclipse.swt.browser.WindowEvent)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Display (org.eclipse.swt.widgets.Display)1