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();
}
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);
}
Aggregations