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_openHasValidEventDetails.
@Test
public void test_OpenWindowListener_openHasValidEventDetails() {
AtomicBoolean openFiredCorrectly = new AtomicBoolean(false);
final Browser browserChild = new Browser(shell, SWT.None);
browser.addOpenWindowListener(event -> {
assertTrue("Expected Browser1 instance, but have another instance", (Browser) event.widget == browser);
assertTrue("Expected event.browser to be null", event.browser == null);
openFiredCorrectly.set(true);
event.browser = browserChild;
});
shell.open();
browser.setText("<html><script type='text/javascript'>window.open()</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
boolean passed = waitForPassCondition(() -> openFiredCorrectly.get());
assertTrue("Test timed out. OpenWindow event not fired.", 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_TitleListener_addListener_closeShell.
@Test
public void test_TitleListener_addListener_closeShell() {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
Browser browser = new Browser(shell, SWT.NONE);
browser.addTitleListener(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_ProgressListener_newProgressAdapter_closeShell.
@Test
public void test_ProgressListener_newProgressAdapter_closeShell() {
Display display = Display.getCurrent();
Shell shell = new Shell(display);
Browser browser = new Browser(shell, SWT.NONE);
browser.addProgressListener(new ProgressAdapter() {
});
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_setJavascriptEnabled_multipleInstances.
/**
* Check that if there are two browser instances, turning off JS in one instance doesn't turn off JS in the other instance.
*/
@Test
public void test_setJavascriptEnabled_multipleInstances() {
AtomicInteger pageLoadCount = new AtomicInteger(1);
AtomicInteger pageLoadCountSecondInstance = new AtomicInteger(1);
AtomicBoolean instanceOneFinishedCorrectly = new AtomicBoolean(false);
AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean(false);
Browser browserSecondInsance = new Browser(shell, SWT.None);
browser.addProgressListener(completedAdapter(event -> {
if (pageLoadCount.get() == 1) {
browser.setJavascriptEnabled(false);
pageLoadCount.set(2);
browser.setText("First instance, second page (with javascript turned off)");
pageLoadCountSecondInstance.set(2);
browserSecondInsance.setText("Second instance, second page (javascript execution not changed)");
} else if (pageLoadCount.get() == 2) {
pageLoadCount.set(3);
Boolean shouldBeNull = (Boolean) browser.evaluate("return true");
assertNull("1) Evaluate execution should be null, but 'true was returned'", shouldBeNull);
instanceOneFinishedCorrectly.set(true);
}
}));
browserSecondInsance.addProgressListener(new ProgressAdapter() {
@Override
public void completed(ProgressEvent event) {
if (pageLoadCountSecondInstance.get() == 2) {
pageLoadCountSecondInstance.set(3);
Boolean shouldBeTrue = (Boolean) browserSecondInsance.evaluate("return true");
assertTrue("2) Javascript should be executable in second instance (as javascript was not turned off), but it was not. " + "Expected:'someStr', Actual:" + shouldBeTrue, shouldBeTrue);
instanceTwoFinishedCorrectly.set(true);
}
}
});
browser.setText("First Instance, first page");
browserSecondInsance.setText("Second instance, first page");
shell.open();
boolean passed = waitForPassCondition(() -> {
return instanceOneFinishedCorrectly.get() && instanceTwoFinishedCorrectly.get();
});
String message = "3) Test timed out. Debug Info:\n" + "InstanceOneFinishedCorrectly: " + instanceOneFinishedCorrectly.get() + "\n" + "InstanceTwoFinishedCorrectly: " + instanceTwoFinishedCorrectly.get() + "\n" + "Instance 1 & 2 page counts: " + pageLoadCount.get() + " & " + pageLoadCountSecondInstance.get();
assertTrue(message, 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_OpenWindowListener_open_ChildPopup.
/**
* Test that a script 'window.open()' opens a child popup shell.
*/
@Test
public void test_OpenWindowListener_open_ChildPopup() {
AtomicBoolean childCompleted = new AtomicBoolean(false);
Shell childShell = new Shell(shell, SWT.None);
childShell.setText("Child shell");
childShell.setLayout(new FillLayout());
final Browser browserChild = new Browser(childShell, SWT.NONE);
browser.addOpenWindowListener(event -> {
event.browser = browserChild;
});
browserChild.addVisibilityWindowListener(showAdapter(event -> {
childShell.open();
browserChild.setText("Child Browser");
}));
// Triggers test to finish.
browserChild.addProgressListener(completedAdapter(event -> childCompleted.set(true)));
shell.open();
browser.setText("<html>" + "<script type='text/javascript'>" + // opens child window.
"var newWin = window.open();" + "</script>\n" + "<body>This test uses javascript to open a new window.</body></html>");
boolean passed = waitForPassCondition(() -> childCompleted.get());
String errMsg = "\nTest timed out.";
assertTrue(errMsg, passed);
}
Aggregations