Skip to content

Commit 603eecd

Browse files
Execute browser tests for Edge #671
Browser tests were only executed for the default configuration of a system's browser using the SWT.NONE flag. Other configurations, such as using the Edge browser in Windows, were not tested. A parameterization has been added to allow other configurations to be tested. This change adds Edge to the test configurations executed for the browser. This allows to detect regressions when performing future changes to the Edge browser. Fixes #671 Co-authored-by: Federico Jeanne <[email protected]>
1 parent 9339c92 commit 603eecd

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ void setupBrowser(int hr, long pv) {
596596
error(SWT.ERROR_THREAD_INVALID_ACCESS, hr);
597597
break;
598598
default:
599+
System.err.println("WebView instantiation failed with result: " + hr);
599600
containingEnvironment.instances().remove(this);
600601
error(SWT.ERROR_NO_HANDLES, hr);
601602
}

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import org.eclipse.swt.widgets.Shell;
8282
import org.eclipse.swt.widgets.Text;
8383
import org.junit.Before;
84+
import org.junit.BeforeClass;
8485
import org.junit.FixMethodOrder;
8586
import org.junit.Rule;
8687
import org.junit.Test;
@@ -144,13 +145,10 @@ private void testLogAppend(String msg) {
144145
@Parameters(name = "browser flags: {0}")
145146
public static Collection<Object[]> browserFlagsToTest() {
146147
List<Object[]> browserFlags = new ArrayList<>();
148+
browserFlags.add(new Object[] {SWT.NONE});
147149
if (SwtTestUtil.isWindows) {
148-
// NOTE: This is currently disabled due to test issues in the CI
149-
// Execute Edge tests first, because IE starts some OS timer that conflicts with Edge event handling
150-
// browserFlags.add(0, new Object[] {SWT.EDGE});
150+
// Execute IE tests after Edge, because IE starts some OS timer that conflicts with Edge event handling
151151
browserFlags.add(new Object[] {SWT.IE});
152-
} else {
153-
browserFlags.add(new Object[] {SWT.NONE});
154152
}
155153
return browserFlags;
156154
}
@@ -159,6 +157,16 @@ public Test_org_eclipse_swt_browser_Browser(int swtBrowserSettings) {
159157
this.swtBrowserSettings = swtBrowserSettings;
160158
}
161159

160+
@BeforeClass
161+
public static void setupEdgeEnvironment() {
162+
// initialize Edge environment before any test runs to isolate environment setup
163+
if (SwtTestUtil.isWindows) {
164+
Shell shell = new Shell();
165+
new Browser(shell, SWT.EDGE);
166+
shell.dispose();
167+
}
168+
}
169+
162170
@Override
163171
@Before
164172
public void setUp() {
@@ -215,6 +223,7 @@ protected void afterDispose(Display display) {
215223

216224
if(!shell.isDisposed()) {
217225
System.out.println("Not disposed shell: " + shell);
226+
shell.dispose();
218227
disposedShells ++;
219228
}
220229
}
@@ -239,6 +248,16 @@ protected void afterDispose(Display display) {
239248
printThreadsInfo();
240249
}
241250
}
251+
if (isEdge) {
252+
// wait for and process pending events to properly cleanup Edge browser resources
253+
do {
254+
processUiEvents();
255+
try {
256+
Thread.sleep(100);
257+
} catch (InterruptedException e) {
258+
}
259+
} while (Display.getCurrent().readAndDispatch());
260+
}
242261
if (SwtTestUtil.isGTK) {
243262
int descriptorDiff = reportOpenedDescriptors();
244263
if(descriptorDiff > 0) {
@@ -285,6 +304,8 @@ private Browser createBrowser(Shell s, int flags) {
285304
long maximumBrowserCreationMilliseconds = 10_000;
286305
long createStartTime = System.currentTimeMillis();
287306
Browser b = new Browser(s, flags);
307+
// Wait for asynchronous initialization via getting URL
308+
b.getUrl();
288309
createdBroswers.add(b);
289310
long createDuration = System.currentTimeMillis() - createStartTime;
290311
assertTrue("creating browser took too long: " + createDuration + "ms", createDuration < maximumBrowserCreationMilliseconds);
@@ -722,14 +743,17 @@ public void changed(LocationEvent event) {
722743

723744
@Test
724745
public void test_LocationListener_LocationListener_ordered_changing () {
725-
List<String> locations = new ArrayList<>();
726-
browser.addLocationListener(changingAdapter(event -> locations.add(event.location)));
746+
assumeFalse("Currently broken for Edge", isEdge);
747+
List<String> locations = Collections.synchronizedList(new ArrayList<>());
748+
browser.addLocationListener(changingAdapter(event -> {
749+
locations.add(event.location);
750+
}));
727751
shell.open();
728752
browser.setText("You should not see this message.");
729753
String url = getValidUrl();
730754
browser.setUrl(url);
731-
waitForPassCondition(() -> locations.size() == 2);
732-
assertTrue("Change of locations do not fire in order.", locations.get(0).equals("about:blank") && locations.get(1).contains("testWebsiteWithTitle.html"));
755+
assertTrue("Change of locations do not fire in order: " + locations.toString(), waitForPassCondition(() -> locations.size() == 2));
756+
assertTrue("Change of locations do not fire in order", locations.get(0).equals("about:blank") && locations.get(1).contains("testWebsiteWithTitle.html"));
733757
}
734758

735759
private String getValidUrl() {
@@ -1942,6 +1966,7 @@ public void test_evaluate_null() {
19421966
// Boolen only used as dummy placeholder so the object is not null.
19431967
final AtomicReference<Object> returnValue = new AtomicReference<>(true);
19441968
browser.addProgressListener(completedAdapter(event -> {
1969+
returnValue.set(false);
19451970
Object evalResult = browser.evaluate("return null");
19461971
returnValue.set(evalResult);
19471972
if (debug_verbose_output)
@@ -1951,7 +1976,7 @@ public void test_evaluate_null() {
19511976
browser.setText("<html><body>HelloWorld</body></html>");
19521977
shell.open();
19531978
boolean passed = waitForPassCondition(() -> returnValue.get() == null);
1954-
assertTrue("Evaluate did not return a null. Timed out.", passed);
1979+
assertTrue("Evaluate did not return a null (current value: " + returnValue.get() + "). Timed out.", passed);
19551980
}
19561981

19571982
/**
@@ -2156,6 +2181,7 @@ public void test_evaluate_array_mixedTypes () {
21562181
*/
21572182
@Test
21582183
public void test_BrowserFunction_callback () {
2184+
assumeFalse("Currently broken for Edge", isEdge);
21592185
AtomicBoolean javaCallbackExecuted = new AtomicBoolean(false);
21602186

21612187
class JavascriptCallback extends BrowserFunction { // Note: Local class defined inside method.

0 commit comments

Comments
 (0)