Skip to content

Commit 56b690f

Browse files
HeikoKlarefedejeanne
authored andcommitted
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
1 parent 9339c92 commit 56b690f

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() {
@@ -239,6 +247,16 @@ protected void afterDispose(Display display) {
239247
printThreadsInfo();
240248
}
241249
}
250+
if (isEdge) {
251+
// wait for and process pending events to properly cleanup Edge browser resources
252+
do {
253+
processUiEvents();
254+
try {
255+
Thread.sleep(100);
256+
} catch (InterruptedException e) {
257+
}
258+
} while (Display.getCurrent().readAndDispatch());
259+
}
242260
if (SwtTestUtil.isGTK) {
243261
int descriptorDiff = reportOpenedDescriptors();
244262
if(descriptorDiff > 0) {
@@ -285,6 +303,8 @@ private Browser createBrowser(Shell s, int flags) {
285303
long maximumBrowserCreationMilliseconds = 10_000;
286304
long createStartTime = System.currentTimeMillis();
287305
Browser b = new Browser(s, flags);
306+
// Wait for asynchronous initialization via getting URL
307+
b.getUrl();
288308
createdBroswers.add(b);
289309
long createDuration = System.currentTimeMillis() - createStartTime;
290310
assertTrue("creating browser took too long: " + createDuration + "ms", createDuration < maximumBrowserCreationMilliseconds);
@@ -722,14 +742,17 @@ public void changed(LocationEvent event) {
722742

723743
@Test
724744
public void test_LocationListener_LocationListener_ordered_changing () {
725-
List<String> locations = new ArrayList<>();
726-
browser.addLocationListener(changingAdapter(event -> locations.add(event.location)));
745+
// assumeFalse("Currently broken for Edge", !isEdge);
746+
List<String> locations = Collections.synchronizedList(new ArrayList<>());
747+
browser.addLocationListener(changingAdapter(event -> {
748+
locations.add(event.location);
749+
}));
727750
shell.open();
728751
browser.setText("You should not see this message.");
729752
String url = getValidUrl();
730753
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"));
754+
assertTrue("Change of locations do not fire in order: " + locations.toString(), waitForPassCondition(() -> locations.size() == 2));
755+
assertTrue("Change of locations do not fire in order", locations.get(0).equals("about:blank") && locations.get(1).contains("testWebsiteWithTitle.html"));
733756
}
734757

735758
private String getValidUrl() {
@@ -1119,6 +1142,7 @@ public void test_setText() {
11191142
*/
11201143
@Test
11211144
public void test_setTextContainingScript_applicationLayerProgressListenerMustSeeUpToDateDom() {
1145+
// assumeFalse("Currently broken for Edge", !isEdge);
11221146
AtomicBoolean completed = new AtomicBoolean();
11231147
browser.addProgressListener(ProgressListener.completedAdapter(event -> {
11241148
String script = """
@@ -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)