diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java index beeff7d7d9..1a2507b7b2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java @@ -425,7 +425,7 @@ private void waitForFutureToFinish(CompletableFuture future) { * is required for processing the OS events during browser initialization, since * Edge browser initialization happens asynchronously. *

- * {@link Display#readAndDisplay()} also processes events scheduled for + * {@link Display#readAndDispatch()} also processes events scheduled for * asynchronous execution via {@link Display#asyncExec(Runnable)}. This may * include events such as the disposal of the browser's parent composite, which * leads to a failure in browser initialization if processed in between the OS diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java index 46c142c532..9097284461 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java @@ -41,6 +41,7 @@ import java.nio.file.Paths; import java.time.Instant; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -81,13 +82,17 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; +import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; /** * Automated Test Suite for class org.eclipse.swt.browser.Browser * * @see org.eclipse.swt.browser.Browser */ +@RunWith(Parameterized.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class Test_org_eclipse_swt_browser_Browser extends Test_org_eclipse_swt_widgets_Composite { @@ -132,6 +137,24 @@ private void testLogAppend(String msg) { boolean ignoreNonDisposedShells; static List descriptors = new ArrayList<>(); + private final int swtBrowserSettings; + +@Parameters(name = "browser flags: {0}") +public static Collection browserFlagsToTest() { + List browserFlags = new ArrayList<>(); + if (SwtTestUtil.isWindows) { + // NOTE: This is currently disabled due to test issues in the CI + // Execute Edge tests first, because IE starts some OS timer that conflicts with Edge event handling + // browserFlags.add(0, new Object[] {SWT.EDGE}); + } + browserFlags.add(new Object[] {SWT.NONE}); + return browserFlags; +} + +public Test_org_eclipse_swt_browser_Browser(int swtBrowserSettings) { + this.swtBrowserSettings = swtBrowserSettings; +} + @Override @Before public void setUp() { @@ -147,7 +170,7 @@ public void setUp() { System.out.println("Running Test_org_eclipse_swt_browser_Browser#" + name.getMethodName()); shell.setLayout(new FillLayout()); - browser = createBrowser(shell, SWT.NONE); + browser = createBrowser(shell, swtBrowserSettings); isEdge = browser.getBrowserType().equals("edge"); @@ -249,8 +272,12 @@ private int reportOpenedDescriptors() { } private Browser createBrowser(Shell s, int flags) { + long maximumBrowserCreationMilliseconds = 10_000; + long createStartTime = System.currentTimeMillis(); Browser b = new Browser(s, flags); createdBroswers.add(b); + long createDuration = System.currentTimeMillis() - createStartTime; + assertTrue("creating browser took too long: " + createDuration + "ms", createDuration < maximumBrowserCreationMilliseconds); return b; } @@ -259,12 +286,12 @@ private Browser createBrowser(Shell s, int flags) { */ @Override public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() { - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.dispose(); - browser = createBrowser(shell, SWT.BORDER); + browser = createBrowser(shell, SWT.BORDER | swtBrowserSettings); // System.out.println("Test_org_eclipse_swt_browser_Browser#test_Constructor*#getBrowserType(): " + browser.getBrowserType()); browser.dispose(); - assertThrows(IllegalArgumentException.class, () -> createBrowser(null, SWT.NONE)); + assertThrows(IllegalArgumentException.class, () -> createBrowser(null, swtBrowserSettings)); } /** @@ -275,7 +302,7 @@ public void test_Constructor_asyncParentDisposal() { Display.getCurrent().asyncExec(() -> { shell.dispose(); }); - Browser browser = createBrowser(shell, SWT.EDGE); + Browser browser = createBrowser(shell, swtBrowserSettings); assertFalse(browser.isDisposed()); } @@ -448,7 +475,7 @@ public void test_getChildren() { public void test_CloseWindowListener_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addCloseWindowListener(event -> {}); // shouldn't throw shell.close(); } @@ -487,7 +514,7 @@ public void test_CloseWindowListener_close () { public void test_LocationListener_adapter_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); LocationAdapter adapter = new LocationAdapter() {}; browser.addLocationListener(adapter); // shouldn't throw shell.close(); @@ -526,9 +553,9 @@ public void test_LocationListener_changing() { boolean passed = waitForPassCondition(changingFired::get); assertTrue("LocationListener.changing() event was never fired", passed); } + @Test public void test_LocationListener_changed() { - AtomicBoolean changedFired = new AtomicBoolean(false); browser.addLocationListener(changedAdapter(e -> changedFired.set(true))); shell.open(); @@ -737,7 +764,7 @@ public void test_LocationListener_ProgressListener_noExtraEvents() { public void test_OpenWindowListener_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addOpenWindowListener(event -> {}); shell.close(); } @@ -762,7 +789,7 @@ public void test_OpenWindowListener_addAndRemove() { @Test public void test_OpenWindowListener_openHasValidEventDetails() { AtomicBoolean openFiredCorrectly = new AtomicBoolean(false); - final Browser browserChild = createBrowser(shell, SWT.None); + final Browser browserChild = createBrowser(shell, swtBrowserSettings); browser.addOpenWindowListener(event -> { assertSame("Expected Browser1 instance, but have another instance", browser, event.widget); assertNull("Expected event.browser to be null", event.browser); @@ -786,7 +813,7 @@ public void test_OpenWindowListener_open_ChildPopup() { Shell childShell = new Shell(shell, SWT.None); childShell.setText("Child shell"); childShell.setLayout(new FillLayout()); - final Browser browserChild = createBrowser(childShell, SWT.NONE); + final Browser browserChild = createBrowser(childShell, swtBrowserSettings); browser.addOpenWindowListener(event -> { event.browser = browserChild; @@ -816,7 +843,6 @@ public void test_OpenWindowListener_open_ChildPopup() { /** Validate event order : Child's visibility should come before progress completed event */ @Test public void test_OpenWindow_Progress_Listener_ValidateEventOrder() { - AtomicBoolean windowOpenFired = new AtomicBoolean(false); AtomicBoolean childCompleted = new AtomicBoolean(false); AtomicBoolean visibilityShowed = new AtomicBoolean(false); @@ -824,7 +850,7 @@ public void test_OpenWindow_Progress_Listener_ValidateEventOrder() { Shell childShell = new Shell(shell, SWT.None); childShell.setText("Child shell"); childShell.setLayout(new FillLayout()); - final Browser browserChild = createBrowser(childShell, SWT.NONE); + final Browser browserChild = createBrowser(childShell, swtBrowserSettings); browser.addOpenWindowListener(event -> { event.browser = browserChild; @@ -874,7 +900,7 @@ public void test_ProgressListener_newProgressAdapter() { public void test_ProgressListener_newProgressAdapter_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addProgressListener(new ProgressAdapter() {}); shell.close(); } @@ -883,7 +909,7 @@ public void test_ProgressListener_newProgressAdapter_closeShell() { public void test_ProgressListener_newListener_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addProgressListener(new ProgressListener() { @Override public void changed(ProgressEvent event) { @@ -980,13 +1006,13 @@ public void test_StatusTextListener_addAndRemove() { */ @Test public void test_StatusTextListener_hoverMouseOverLink() { - assumeFalse(isEdge); // no API in Edge for this + assumeFalse("no API in Edge for this", isEdge); AtomicBoolean statusChanged = new AtomicBoolean(false); int size = 500; // 1) Create a page that has a hyper link (covering the whole page) - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); 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
"); @@ -1026,7 +1052,7 @@ public void test_StatusTextListener_hoverMouseOverLink() { public void test_TitleListener_addListener_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addTitleListener(event -> { }); shell.close(); @@ -1205,7 +1231,7 @@ public void test_VisibilityWindowListener_newAdapter() { public void test_VisibilityWindowListener_newAdapter_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addVisibilityWindowListener(new VisibilityWindowAdapter(){}); shell.close(); } @@ -1214,7 +1240,7 @@ public void test_VisibilityWindowListener_newAdapter_closeShell() { public void test_VisibilityWindowListener_newListener_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); - Browser browser = createBrowser(shell, SWT.NONE); + Browser browser = createBrowser(shell, swtBrowserSettings); browser.addVisibilityWindowListener(new VisibilityWindowListener() { @Override public void hide(WindowEvent event) { @@ -1260,7 +1286,7 @@ public void test_VisibilityWindowListener_multiple_shells() { Shell childShell = new Shell(shell); childShell.setText("Child shell " + childCount.get()); childShell.setLayout(new FillLayout()); - Browser browserChild = createBrowser(childShell, SWT.NONE); + Browser browserChild = createBrowser(childShell, swtBrowserSettings); event.browser = browserChild; browserChild.setText("Child window"); browserChild.addVisibilityWindowListener(new VisibilityWindowAdapter() { @@ -1319,7 +1345,7 @@ public void test_VisibilityWindowListener_eventSize() { childShell.setSize(250, 350); childShell.setText("Child shell"); childShell.setLayout(new FillLayout()); - final Browser browserChild = createBrowser(childShell, SWT.NONE); + final Browser browserChild = createBrowser(childShell, swtBrowserSettings); browser.addOpenWindowListener(event -> { event.browser = browserChild; @@ -1439,7 +1465,7 @@ public void test_setJavascriptEnabled_multipleInstances() { AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean(false); - Browser browserSecondInsance = createBrowser(shell, SWT.None); + Browser browserSecondInsance = createBrowser(shell, swtBrowserSettings); browser.addProgressListener(completedAdapter(event -> { if (pageLoadCount.get() == 1) { @@ -2511,8 +2537,8 @@ public Object function(Object[] arguments) { @Test public void test_BrowserFunction_multiprocess() { // Test that BrowserFunctions work in multiple Browser instances simultaneously. - Browser browser1 = createBrowser(shell, SWT.NONE); - Browser browser2 = createBrowser(shell, SWT.NONE); + Browser browser1 = createBrowser(shell, swtBrowserSettings); + Browser browser2 = createBrowser(shell, swtBrowserSettings); class JavaFunc extends BrowserFunction { JavaFunc(Browser browser) {