use of org.eclipse.swt.browser.Browser 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);
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_ConstructorLorg_eclipse_swt_widgets_CompositeI.
/**
* Test that if Browser is constructed with the parent being "null", Browser throws an exception.
*/
@Override
@Test(expected = IllegalArgumentException.class)
public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
Browser browser = new Browser(shell, SWT.NONE);
browser.dispose();
browser = new Browser(shell, SWT.BORDER);
// System.out.println("Test_org_eclipse_swt_browser_Browser#test_Constructor*#getBrowserType(): " + browser.getBrowserType());
browser.dispose();
// Should throw.
browser = new Browser(null, SWT.NONE);
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_CloseWindowListener_closeShell.
@Test
public void test_CloseWindowListener_closeShell() {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
Browser browser = new Browser(shell, SWT.NONE);
// shouldn't throw
browser.addCloseWindowListener(event -> {
});
shell.close();
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_OpenWindowListener_closeShell.
@Test
public void test_OpenWindowListener_closeShell() {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
Browser browser = new Browser(shell, SWT.NONE);
browser.addOpenWindowListener(event -> {
});
shell.close();
}
use of org.eclipse.swt.browser.Browser in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_BrowserFunction_callback_with_boolean.
/**
* Test that javascript can call java and pass a Boolean to java.
* loosely based on Snippet307.
*/
@Test
public void test_BrowserFunction_callback_with_boolean() {
// On webkit1, this test works if ran on it's own. But sometimes in test-suite with other tests it causes jvm crash.
// culprit seems to be the main_context_iteration() call in shell.setVisible().
// See Bug 509587. Solution: Webkit2.
assumeFalse(webkit1SkipMsg(), isWebkit1);
AtomicBoolean javaCallbackExecuted = new AtomicBoolean(false);
class JavascriptCallback extends // Note: Local class defined inside method.
BrowserFunction {
JavascriptCallback(Browser browser, String name) {
super(browser, name);
}
@Override
public Object function(Object[] arguments) {
Boolean returnBool = (Boolean) arguments[0];
javaCallbackExecuted.set(returnBool);
return null;
}
}
String htmlWithScript = "<html><head>\n" + "<script language=\"JavaScript\">\n" + // Define a javascript function.
"function callCustomFunction() {\n" + " document.body.style.backgroundColor = 'red'\n" + // This calls the javafunction that we registered.
" jsCallbackToJava(true)\n" + "}" + "</script>\n" + "</head>\n" + "<body> I'm going to make a callback to java </body>\n" + "</html>\n";
browser.setText(htmlWithScript);
new JavascriptCallback(browser, "jsCallbackToJava");
browser.addProgressListener(callCustomFunctionUponLoad);
shell.open();
boolean passed = waitForPassCondition(() -> javaCallbackExecuted.get());
String message = "Javascript did not pass a boolean back to java";
assertTrue(message, passed);
}
Aggregations