Skip to content

Commit 99e5332

Browse files
committed
Improve assertions in BrowserFunction registration test #3254
The test case test_BrowserFunction_availableOnLoad_concurrentInstances_issue20 currently only asserts that the two involved progress listeners were successfully executed. In case of a failure, there is not information about which of the listeners was not executed. In addition, the listeners may even fail to execute with an exception, but that exception is currently swallowed. With this change, exceptions are properly propagated to test failures and in case a listener is not executed at all, the error message will report for which of them that is the case. Contributes to #3254
1 parent 4f38a5e commit 99e5332

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,11 +3002,14 @@ public void test_BrowserFunction_availableOnLoad_concurrentInstances_issue20() {
30023002
@Override
30033003
public Object function(Object[] arguments) { return null; }
30043004
};
3005+
AtomicReference<SWTException> exceptionInBrowser1 = new AtomicReference<>();
30053006
b1.addProgressListener(completedAdapter(e -> {
30063007
try {
30073008
b1.evaluate("options();");
30083009
browser1FuncAvailable.set(true);
3009-
} catch (SWTException ignored) {}
3010+
} catch (SWTException ex) {
3011+
exceptionInBrowser1.set(ex);
3012+
}
30103013
}));
30113014
createdBroswers.add(b1);
30123015

@@ -3017,19 +3020,29 @@ public void test_BrowserFunction_availableOnLoad_concurrentInstances_issue20() {
30173020
@Override
30183021
public Object function(Object[] arguments) { return null; }
30193022
};
3023+
AtomicReference<SWTException> exceptionInBrowser2 = new AtomicReference<>();
30203024
b2.addProgressListener(completedAdapter(e -> {
30213025
try {
30223026
b2.evaluate("options();");
30233027
browser2FuncAvailable.set(true);
3024-
} catch (SWTException ignored) {}
3028+
} catch (SWTException ex) {
3029+
exceptionInBrowser2.set(ex);
3030+
}
30253031
}));
30263032
createdBroswers.add(b2);
30273033

30283034
shell.open();
3029-
assertTrue(
3030-
waitForPassCondition(() -> browser1FuncAvailable.get() && browser2FuncAvailable.get()),
3031-
"BrowserFunction must be available when page load completes on both browsers "
3032-
+ "(regression of https://github.com/eclipse-platform/eclipse.platform.swt/issues/20)");
3035+
waitForPassCondition(() -> (exceptionInBrowser1.get() != null || browser1FuncAvailable.get())
3036+
&& (exceptionInBrowser2.get() != null || browser2FuncAvailable.get()));
3037+
3038+
if (exceptionInBrowser1.get() != null) {
3039+
throw exceptionInBrowser1.get();
3040+
}
3041+
if (exceptionInBrowser2.get() != null) {
3042+
throw exceptionInBrowser2.get();
3043+
}
3044+
assertTrue(browser1FuncAvailable.get(), "BrowserFunction for first browser missing when page load completed");
3045+
assertTrue(browser2FuncAvailable.get(), "BrowserFunction for second browser missing when page load completed");
30333046
}
30343047

30353048
@Test

0 commit comments

Comments
 (0)