2222import static org .junit .Assert .assertNotNull ;
2323import static org .junit .Assert .assertNull ;
2424import static org .junit .Assert .assertSame ;
25+ import static org .junit .Assert .assertThrows ;
2526import static org .junit .Assert .assertTrue ;
2627import static org .junit .Assert .fail ;
2728import static org .junit .Assume .assumeFalse ;
4041import java .nio .file .Paths ;
4142import java .time .Instant ;
4243import java .util .ArrayList ;
44+ import java .util .Collection ;
4345import java .util .Collections ;
4446import java .util .List ;
4547import java .util .Locale ;
8183import org .junit .Rule ;
8284import org .junit .Test ;
8385import org .junit .rules .TestName ;
86+ import org .junit .runner .RunWith ;
8487import org .junit .runners .MethodSorters ;
88+ import org .junit .runners .Parameterized ;
89+ import org .junit .runners .Parameterized .Parameters ;
8590
8691/**
8792 * Automated Test Suite for class org.eclipse.swt.browser.Browser
8893 *
8994 * @see org.eclipse.swt.browser.Browser
9095 */
96+ @ RunWith (Parameterized .class )
9197@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
9298public class Test_org_eclipse_swt_browser_Browser extends Test_org_eclipse_swt_widgets_Composite {
9399
@@ -132,6 +138,23 @@ private void testLogAppend(String msg) {
132138 boolean ignoreNonDisposedShells ;
133139 static List <String > descriptors = new ArrayList <>();
134140
141+ private final int swtBrowserSettings ;
142+
143+ @ Parameters (name = "browser flags: {0}" )
144+ public static Collection <Object []> browserFlagsToTest () {
145+ List <Object []> browserFlags = new ArrayList <>();
146+ browserFlags .add (new Object [] {SWT .NONE });
147+ if (SwtTestUtil .isWindows ) {
148+ // Execute Edge tests first, because IE starts some OS timer that conflicts with Edge event handling
149+ browserFlags .add (0 , new Object [] {SWT .EDGE });
150+ }
151+ return browserFlags ;
152+ }
153+
154+ public Test_org_eclipse_swt_browser_Browser (int swtBrowserSettings ) {
155+ this .swtBrowserSettings = swtBrowserSettings ;
156+ }
157+
135158@ Override
136159@ Before
137160public void setUp () {
@@ -147,7 +170,7 @@ public void setUp() {
147170 System .out .println ("Running Test_org_eclipse_swt_browser_Browser#" + name .getMethodName ());
148171
149172 shell .setLayout (new FillLayout ());
150- browser = createBrowser (shell , SWT . NONE );
173+ browser = createBrowser (shell , swtBrowserSettings );
151174
152175 isEdge = browser .getBrowserType ().equals ("edge" );
153176
@@ -206,6 +229,16 @@ public void tearDown() {
206229 printThreadsInfo ();
207230 }
208231 }
232+ // if (isEdge) {
233+ // // wait for and process pending events to properly cleanup Edge browser resources
234+ // do {
235+ // processUiEvents();
236+ // try {
237+ // Thread.sleep(100);
238+ // } catch (InterruptedException e) {
239+ // }
240+ // } while (Display.getCurrent().readAndDispatch());
241+ // }
209242 if (SwtTestUtil .isGTK ) {
210243 int descriptorDiff = reportOpenedDescriptors ();
211244 if (descriptorDiff > 0 ) {
@@ -249,23 +282,26 @@ private int reportOpenedDescriptors() {
249282}
250283
251284private Browser createBrowser (Shell s , int flags ) {
285+ long maximumBrowserCreationMilliseconds = 20_000 ;
286+ long createStartTime = System .currentTimeMillis ();
252287 Browser b = new Browser (s , flags );
253288 createdBroswers .add (b );
289+ long createDuration = System .currentTimeMillis () - createStartTime ;
290+ assertTrue ("creating browser took too long: " + createDuration + "ms" , createDuration < maximumBrowserCreationMilliseconds );
254291 return b ;
255292}
256293
257294/**
258295 * Test that if Browser is constructed with the parent being "null", Browser throws an exception.
259296 */
260297@ Override
261- @ Test (expected = IllegalArgumentException .class )
262298public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI () {
263- Browser browser = createBrowser (shell , SWT . NONE );
299+ Browser browser = createBrowser (shell , swtBrowserSettings );
264300 browser .dispose ();
265- browser = createBrowser (shell , SWT .BORDER );
301+ browser = createBrowser (shell , SWT .BORDER | swtBrowserSettings );
266302 // System.out.println("Test_org_eclipse_swt_browser_Browser#test_Constructor*#getBrowserType(): " + browser.getBrowserType());
267303 browser .dispose ();
268- browser = createBrowser (null , SWT . NONE ); // Should throw.
304+ assertThrows ( IllegalArgumentException . class , () -> createBrowser (null , swtBrowserSettings ));
269305}
270306
271307/**
@@ -276,7 +312,7 @@ public void test_Constructor_asyncParentDisposal() {
276312 Display .getCurrent ().asyncExec (() -> {
277313 shell .dispose ();
278314 });
279- Browser browser = createBrowser (shell , SWT . EDGE );
315+ Browser browser = createBrowser (shell , swtBrowserSettings );
280316 assertFalse (browser .isDisposed ());
281317}
282318
@@ -374,7 +410,7 @@ public void test_getChildren() {
374410public void test_CloseWindowListener_closeShell () {
375411 Display display = Display .getCurrent ();
376412 Shell shell = new Shell (display );
377- Browser browser = createBrowser (shell , SWT . NONE );
413+ Browser browser = createBrowser (shell , swtBrowserSettings );
378414 browser .addCloseWindowListener (event -> {}); // shouldn't throw
379415 shell .close ();
380416}
@@ -413,7 +449,7 @@ public void test_CloseWindowListener_close () {
413449public void test_LocationListener_adapter_closeShell () {
414450 Display display = Display .getCurrent ();
415451 Shell shell = new Shell (display );
416- Browser browser = createBrowser (shell , SWT . NONE );
452+ Browser browser = createBrowser (shell , swtBrowserSettings );
417453 LocationAdapter adapter = new LocationAdapter () {};
418454 browser .addLocationListener (adapter ); // shouldn't throw
419455 shell .close ();
@@ -454,6 +490,8 @@ public void test_LocationListener_changing() {
454490}
455491@ Test
456492public void test_LocationListener_changed () {
493+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
494+
457495 AtomicBoolean changedFired = new AtomicBoolean (false );
458496 browser .addLocationListener (changedAdapter (e -> changedFired .set (true )));
459497 shell .open ();
@@ -463,6 +501,8 @@ public void test_LocationListener_changed() {
463501}
464502@ Test
465503public void test_LocationListener_changingAndOnlyThenChanged () {
504+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
505+
466506 // Test proper order of events.
467507 // Check that 'changed' is only fired after 'changing' has fired at least once.
468508 AtomicBoolean changingFired = new AtomicBoolean (false );
@@ -506,6 +546,8 @@ else if (!changingFired.get())
506546
507547@ Test
508548public void test_LocationListener_then_ProgressListener () {
549+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
550+
509551 AtomicBoolean locationChanged = new AtomicBoolean (false );
510552 AtomicBoolean progressChanged = new AtomicBoolean (false );
511553 AtomicBoolean progressChangedAfterLocationChanged = new AtomicBoolean (false );
@@ -599,6 +641,8 @@ public void changed(LocationEvent event) {
599641@ Test
600642/** Ensue that only one changed and one completed event are fired for url changes */
601643public void test_LocationListener_ProgressListener_noExtraEvents () {
644+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
645+
602646 AtomicInteger changedCount = new AtomicInteger (0 );
603647 AtomicInteger completedCount = new AtomicInteger (0 );
604648
@@ -626,7 +670,7 @@ public void test_LocationListener_ProgressListener_noExtraEvents() {
626670public void test_OpenWindowListener_closeShell () {
627671 Display display = Display .getCurrent ();
628672 Shell shell = new Shell (display );
629- Browser browser = createBrowser (shell , SWT . NONE );
673+ Browser browser = createBrowser (shell , swtBrowserSettings );
630674 browser .addOpenWindowListener (event -> {});
631675 shell .close ();
632676}
@@ -651,7 +695,7 @@ public void test_OpenWindowListener_addAndRemove() {
651695@ Test
652696public void test_OpenWindowListener_openHasValidEventDetails () {
653697 AtomicBoolean openFiredCorrectly = new AtomicBoolean (false );
654- final Browser browserChild = createBrowser (shell , SWT . None );
698+ final Browser browserChild = createBrowser (shell , swtBrowserSettings );
655699 browser .addOpenWindowListener (event -> {
656700 assertSame ("Expected Browser1 instance, but have another instance" , browser , event .widget );
657701 assertNull ("Expected event.browser to be null" , event .browser );
@@ -670,12 +714,14 @@ public void test_OpenWindowListener_openHasValidEventDetails() {
670714/** Test that a script 'window.open()' opens a child popup shell. */
671715@ Test
672716public void test_OpenWindowListener_open_ChildPopup () {
717+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
718+
673719 AtomicBoolean childCompleted = new AtomicBoolean (false );
674720
675721 Shell childShell = new Shell (shell , SWT .None );
676722 childShell .setText ("Child shell" );
677723 childShell .setLayout (new FillLayout ());
678- final Browser browserChild = createBrowser (childShell , SWT . NONE );
724+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
679725
680726 browser .addOpenWindowListener (event -> {
681727 event .browser = browserChild ;
@@ -705,14 +751,16 @@ public void test_OpenWindowListener_open_ChildPopup() {
705751/** Validate event order : Child's visibility should come before progress completed event */
706752@ Test
707753public void test_OpenWindow_Progress_Listener_ValidateEventOrder () {
754+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
755+
708756 AtomicBoolean windowOpenFired = new AtomicBoolean (false );
709757 AtomicBoolean childCompleted = new AtomicBoolean (false );
710758 AtomicBoolean visibilityShowed = new AtomicBoolean (false );
711759
712760 Shell childShell = new Shell (shell , SWT .None );
713761 childShell .setText ("Child shell" );
714762 childShell .setLayout (new FillLayout ());
715- final Browser browserChild = createBrowser (childShell , SWT . NONE );
763+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
716764
717765 browser .addOpenWindowListener (event -> {
718766 event .browser = browserChild ;
@@ -762,7 +810,7 @@ public void test_ProgressListener_newProgressAdapter() {
762810public void test_ProgressListener_newProgressAdapter_closeShell () {
763811 Display display = Display .getCurrent ();
764812 Shell shell = new Shell (display );
765- Browser browser = createBrowser (shell , SWT . NONE );
813+ Browser browser = createBrowser (shell , swtBrowserSettings );
766814 browser .addProgressListener (new ProgressAdapter () {});
767815 shell .close ();
768816}
@@ -771,7 +819,7 @@ public void test_ProgressListener_newProgressAdapter_closeShell() {
771819public void test_ProgressListener_newListener_closeShell () {
772820 Display display = Display .getCurrent ();
773821 Shell shell = new Shell (display );
774- Browser browser = createBrowser (shell , SWT . NONE );
822+ Browser browser = createBrowser (shell , swtBrowserSettings );
775823 browser .addProgressListener (new ProgressListener () {
776824 @ Override
777825 public void changed (ProgressEvent event ) {
@@ -868,13 +916,13 @@ public void test_StatusTextListener_addAndRemove() {
868916 */
869917@ Test
870918public void test_StatusTextListener_hoverMouseOverLink () {
871- assumeFalse (isEdge ); // no API in Edge for this
919+ assumeFalse (" no API in Edge for this" , isEdge );
872920
873921 AtomicBoolean statusChanged = new AtomicBoolean (false );
874922 int size = 500 ;
875923
876924 // 1) Create a page that has a hyper link (covering the whole page)
877- Browser browser = createBrowser (shell , SWT . NONE );
925+ Browser browser = createBrowser (shell , swtBrowserSettings );
878926 StringBuilder longhtml = new StringBuilder ();
879927 for (int i = 0 ; i < 200 ; i ++) {
880928 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>" );
@@ -914,7 +962,7 @@ public void test_StatusTextListener_hoverMouseOverLink() {
914962public void test_TitleListener_addListener_closeShell () {
915963 Display display = Display .getCurrent ();
916964 Shell shell = new Shell (display );
917- Browser browser = createBrowser (shell , SWT . NONE );
965+ Browser browser = createBrowser (shell , swtBrowserSettings );
918966 browser .addTitleListener (event -> {
919967 });
920968 shell .close ();
@@ -1078,7 +1126,7 @@ public void test_VisibilityWindowListener_newAdapter() {
10781126public void test_VisibilityWindowListener_newAdapter_closeShell () {
10791127 Display display = Display .getCurrent ();
10801128 Shell shell = new Shell (display );
1081- Browser browser = createBrowser (shell , SWT . NONE );
1129+ Browser browser = createBrowser (shell , swtBrowserSettings );
10821130 browser .addVisibilityWindowListener (new VisibilityWindowAdapter (){});
10831131 shell .close ();
10841132}
@@ -1087,7 +1135,7 @@ public void test_VisibilityWindowListener_newAdapter_closeShell() {
10871135public void test_VisibilityWindowListener_newListener_closeShell () {
10881136 Display display = Display .getCurrent ();
10891137 Shell shell = new Shell (display );
1090- Browser browser = createBrowser (shell , SWT . NONE );
1138+ Browser browser = createBrowser (shell , swtBrowserSettings );
10911139 browser .addVisibilityWindowListener (new VisibilityWindowListener () {
10921140 @ Override
10931141 public void hide (WindowEvent event ) {
@@ -1133,7 +1181,7 @@ public void test_VisibilityWindowListener_multiple_shells() {
11331181 Shell childShell = new Shell (shell );
11341182 childShell .setText ("Child shell " + childCount .get ());
11351183 childShell .setLayout (new FillLayout ());
1136- Browser browserChild = createBrowser (childShell , SWT . NONE );
1184+ Browser browserChild = createBrowser (childShell , swtBrowserSettings );
11371185 event .browser = browserChild ;
11381186 browserChild .setText ("Child window" );
11391187 browserChild .addVisibilityWindowListener (new VisibilityWindowAdapter () {
@@ -1184,6 +1232,8 @@ public void completed(ProgressEvent event) {
11841232 */
11851233@ Test
11861234public void test_VisibilityWindowListener_eventSize () {
1235+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1236+
11871237 shell .setSize (200 ,300 );
11881238 AtomicBoolean childCompleted = new AtomicBoolean (false );
11891239 AtomicReference <Point > result = new AtomicReference <>(new Point (0 ,0 ));
@@ -1192,7 +1242,7 @@ public void test_VisibilityWindowListener_eventSize() {
11921242 childShell .setSize (250 , 350 );
11931243 childShell .setText ("Child shell" );
11941244 childShell .setLayout (new FillLayout ());
1195- final Browser browserChild = createBrowser (childShell , SWT . NONE );
1245+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
11961246
11971247 browser .addOpenWindowListener (event -> {
11981248 event .browser = browserChild ;
@@ -1311,8 +1361,7 @@ public void test_setJavascriptEnabled_multipleInstances() {
13111361 AtomicBoolean instanceOneFinishedCorrectly = new AtomicBoolean (false );
13121362 AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean (false );
13131363
1314-
1315- Browser browserSecondInsance = createBrowser (shell , SWT .None );
1364+ Browser browserSecondInsance = createBrowser (shell , swtBrowserSettings );
13161365
13171366 browser .addProgressListener (completedAdapter (event -> {
13181367 if (pageLoadCount .get () == 1 ) {
@@ -1373,6 +1422,8 @@ public void completed(ProgressEvent event) {
13731422*/
13741423@ Test
13751424public void test_LocationListener_evaluateInCallback () {
1425+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1426+
13761427 AtomicBoolean changingFinished = new AtomicBoolean (false );
13771428 AtomicBoolean changedFinished = new AtomicBoolean (false );
13781429 browser .addLocationListener (new LocationListener () {
@@ -1421,6 +1472,8 @@ public void changed(LocationEvent event) {
14211472/** Verify that evaluation works inside an OpenWindowListener */
14221473@ Test
14231474public void test_OpenWindowListener_evaluateInCallback () {
1475+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1476+
14241477 AtomicBoolean eventFired = new AtomicBoolean (false );
14251478 browser .addOpenWindowListener (event -> {
14261479 browser .evaluate ("SWTopenListener = true" );
@@ -2368,7 +2421,7 @@ public Object function(Object[] arguments) {
23682421 browser .setText ("1st (initial) page load" );
23692422 new JavascriptCallback (browser , "jsCallbackToJava" );
23702423 browser .execute ("jsCallbackToJava()" );
2371- // see if function still works after a page change:
2424+ // see if function still works after a page change:
23722425 browser .addProgressListener (completedAdapter (e -> browser .execute ("jsCallbackToJava()" )));
23732426
23742427 shell .open ();
@@ -2380,8 +2433,8 @@ public Object function(Object[] arguments) {
23802433@ Test
23812434public void test_BrowserFunction_multiprocess () {
23822435 // Test that BrowserFunctions work in multiple Browser instances simultaneously.
2383- Browser browser1 = createBrowser (shell , SWT . NONE );
2384- Browser browser2 = createBrowser (shell , SWT . NONE );
2436+ Browser browser1 = createBrowser (shell , swtBrowserSettings );
2437+ Browser browser2 = createBrowser (shell , swtBrowserSettings );
23852438
23862439 class JavaFunc extends BrowserFunction {
23872440 JavaFunc (Browser browser ) {
0 commit comments