use of org.eclipse.swt.browser.StatusTextListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_StatusTextListener_hoverMouseOverLink.
/**
* Test if hovering over a hyperlink triggers status Text change listener.
* Logic:
* 1) Create a page that has a hyper link (covering the whole page)
* 2) Move shell to top left corner
* 3) Upon compleation of page load, move cursor across whole shell.
* (Note, in current jUnit, browser sometimes only takes up half the shell).
* 4) StatusTextListener should get triggered. Test passes.
* 5) Else timeout & fail.
*
* Set variable "debug_show_browser" to true to see this being performed at human-observable speed.
*
* Note: Historically one could execute some javascript to change status bar (window.status=txt).
* But most browsers don't support this anymore. Only hovering over a hyperlink changes status.
*
* StatusTextListener may be triggerd upon page load also. So this test can pass if
* a page load sets the status text (on older browsers) or passes when the mouse hovers
* over the hyperlink (newer Webkit2+) browser.
*/
@Test
public void test_StatusTextListener_hoverMouseOverLink() {
AtomicBoolean statusChanged = new AtomicBoolean(false);
int size = 500;
// 1) Create a page that has a hyper link (covering the whole page)
Browser browser = new Browser(shell, SWT.NONE);
StringBuilder longhtml = new StringBuilder();
for (int i = 0; i < 200; i++) {
longhtml.append("text text text text text text text text text text text text text text text text text text text text text text text text<br>");
}
browser.setText("<a href='http://localhost'>" + longhtml + "</a>");
// 2) Move shell to top left corner
shell.setLocation(0, 0);
shell.setSize(size, size);
browser.addProgressListener(completedAdapter(event -> {
// * 3) Upon compleation of page load, move cursor across whole shell.
// * (Note, in current jUnit, browser sometimes only takes up half the shell).
Display display = event.display;
Point cachedLocation = display.getCursorLocation();
display.setCursorLocation(20, 10);
browser.getBounds();
for (int i = 0; i < size; i = i + 5) {
display.setCursorLocation(i, i);
// Move mouse slower during debug.
waitForMilliseconds(debug_show_browser ? 3 : 1);
}
// for convenience of developer. Not needed for test.
display.setCursorLocation(cachedLocation);
}));
browser.addStatusTextListener(event -> {
statusChanged.set(true);
});
shell.open();
boolean passed = waitForPassCondition(() -> statusChanged.get());
String msg = "Mouse movent over text was suppose to trigger StatusTextListener. But it didn't";
assertTrue(msg, passed);
}
Aggregations