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
@@ -388,7 +424,7 @@ public void test_getChildren() {
388424public void test_CloseWindowListener_closeShell () {
389425 Display display = Display .getCurrent ();
390426 Shell shell = new Shell (display );
391- Browser browser = createBrowser (shell , SWT . NONE );
427+ Browser browser = createBrowser (shell , swtBrowserSettings );
392428 browser .addCloseWindowListener (event -> {}); // shouldn't throw
393429 shell .close ();
394430}
@@ -427,7 +463,7 @@ public void test_CloseWindowListener_close () {
427463public void test_LocationListener_adapter_closeShell () {
428464 Display display = Display .getCurrent ();
429465 Shell shell = new Shell (display );
430- Browser browser = createBrowser (shell , SWT . NONE );
466+ Browser browser = createBrowser (shell , swtBrowserSettings );
431467 LocationAdapter adapter = new LocationAdapter () {};
432468 browser .addLocationListener (adapter ); // shouldn't throw
433469 shell .close ();
@@ -468,6 +504,8 @@ public void test_LocationListener_changing() {
468504}
469505@ Test
470506public void test_LocationListener_changed () {
507+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
508+
471509 AtomicBoolean changedFired = new AtomicBoolean (false );
472510 browser .addLocationListener (changedAdapter (e -> changedFired .set (true )));
473511 shell .open ();
@@ -477,6 +515,8 @@ public void test_LocationListener_changed() {
477515}
478516@ Test
479517public void test_LocationListener_changingAndOnlyThenChanged () {
518+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
519+
480520 // Test proper order of events.
481521 // Check that 'changed' is only fired after 'changing' has fired at least once.
482522 AtomicBoolean changingFired = new AtomicBoolean (false );
@@ -520,6 +560,8 @@ else if (!changingFired.get())
520560
521561@ Test
522562public void test_LocationListener_then_ProgressListener () {
563+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
564+
523565 AtomicBoolean locationChanged = new AtomicBoolean (false );
524566 AtomicBoolean progressChanged = new AtomicBoolean (false );
525567 AtomicBoolean progressChangedAfterLocationChanged = new AtomicBoolean (false );
@@ -613,6 +655,8 @@ public void changed(LocationEvent event) {
613655@ Test
614656/** Ensue that only one changed and one completed event are fired for url changes */
615657public void test_LocationListener_ProgressListener_noExtraEvents () {
658+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
659+
616660 AtomicInteger changedCount = new AtomicInteger (0 );
617661 AtomicInteger completedCount = new AtomicInteger (0 );
618662
@@ -640,7 +684,7 @@ public void test_LocationListener_ProgressListener_noExtraEvents() {
640684public void test_OpenWindowListener_closeShell () {
641685 Display display = Display .getCurrent ();
642686 Shell shell = new Shell (display );
643- Browser browser = createBrowser (shell , SWT . NONE );
687+ Browser browser = createBrowser (shell , swtBrowserSettings );
644688 browser .addOpenWindowListener (event -> {});
645689 shell .close ();
646690}
@@ -665,7 +709,7 @@ public void test_OpenWindowListener_addAndRemove() {
665709@ Test
666710public void test_OpenWindowListener_openHasValidEventDetails () {
667711 AtomicBoolean openFiredCorrectly = new AtomicBoolean (false );
668- final Browser browserChild = createBrowser (shell , SWT . None );
712+ final Browser browserChild = createBrowser (shell , swtBrowserSettings );
669713 browser .addOpenWindowListener (event -> {
670714 assertSame ("Expected Browser1 instance, but have another instance" , browser , event .widget );
671715 assertNull ("Expected event.browser to be null" , event .browser );
@@ -684,12 +728,14 @@ public void test_OpenWindowListener_openHasValidEventDetails() {
684728/** Test that a script 'window.open()' opens a child popup shell. */
685729@ Test
686730public void test_OpenWindowListener_open_ChildPopup () {
731+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
732+
687733 AtomicBoolean childCompleted = new AtomicBoolean (false );
688734
689735 Shell childShell = new Shell (shell , SWT .None );
690736 childShell .setText ("Child shell" );
691737 childShell .setLayout (new FillLayout ());
692- final Browser browserChild = createBrowser (childShell , SWT . NONE );
738+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
693739
694740 browser .addOpenWindowListener (event -> {
695741 event .browser = browserChild ;
@@ -719,14 +765,16 @@ public void test_OpenWindowListener_open_ChildPopup() {
719765/** Validate event order : Child's visibility should come before progress completed event */
720766@ Test
721767public void test_OpenWindow_Progress_Listener_ValidateEventOrder () {
768+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
769+
722770 AtomicBoolean windowOpenFired = new AtomicBoolean (false );
723771 AtomicBoolean childCompleted = new AtomicBoolean (false );
724772 AtomicBoolean visibilityShowed = new AtomicBoolean (false );
725773
726774 Shell childShell = new Shell (shell , SWT .None );
727775 childShell .setText ("Child shell" );
728776 childShell .setLayout (new FillLayout ());
729- final Browser browserChild = createBrowser (childShell , SWT . NONE );
777+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
730778
731779 browser .addOpenWindowListener (event -> {
732780 event .browser = browserChild ;
@@ -776,7 +824,7 @@ public void test_ProgressListener_newProgressAdapter() {
776824public void test_ProgressListener_newProgressAdapter_closeShell () {
777825 Display display = Display .getCurrent ();
778826 Shell shell = new Shell (display );
779- Browser browser = createBrowser (shell , SWT . NONE );
827+ Browser browser = createBrowser (shell , swtBrowserSettings );
780828 browser .addProgressListener (new ProgressAdapter () {});
781829 shell .close ();
782830}
@@ -785,7 +833,7 @@ public void test_ProgressListener_newProgressAdapter_closeShell() {
785833public void test_ProgressListener_newListener_closeShell () {
786834 Display display = Display .getCurrent ();
787835 Shell shell = new Shell (display );
788- Browser browser = createBrowser (shell , SWT . NONE );
836+ Browser browser = createBrowser (shell , swtBrowserSettings );
789837 browser .addProgressListener (new ProgressListener () {
790838 @ Override
791839 public void changed (ProgressEvent event ) {
@@ -882,13 +930,13 @@ public void test_StatusTextListener_addAndRemove() {
882930 */
883931@ Test
884932public void test_StatusTextListener_hoverMouseOverLink () {
885- assumeFalse (isEdge ); // no API in Edge for this
933+ assumeFalse (" no API in Edge for this" , isEdge );
886934
887935 AtomicBoolean statusChanged = new AtomicBoolean (false );
888936 int size = 500 ;
889937
890938 // 1) Create a page that has a hyper link (covering the whole page)
891- Browser browser = createBrowser (shell , SWT . NONE );
939+ Browser browser = createBrowser (shell , swtBrowserSettings );
892940 StringBuilder longhtml = new StringBuilder ();
893941 for (int i = 0 ; i < 200 ; i ++) {
894942 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>" );
@@ -928,7 +976,7 @@ public void test_StatusTextListener_hoverMouseOverLink() {
928976public void test_TitleListener_addListener_closeShell () {
929977 Display display = Display .getCurrent ();
930978 Shell shell = new Shell (display );
931- Browser browser = createBrowser (shell , SWT . NONE );
979+ Browser browser = createBrowser (shell , swtBrowserSettings );
932980 browser .addTitleListener (event -> {
933981 });
934982 shell .close ();
@@ -1092,7 +1140,7 @@ public void test_VisibilityWindowListener_newAdapter() {
10921140public void test_VisibilityWindowListener_newAdapter_closeShell () {
10931141 Display display = Display .getCurrent ();
10941142 Shell shell = new Shell (display );
1095- Browser browser = createBrowser (shell , SWT . NONE );
1143+ Browser browser = createBrowser (shell , swtBrowserSettings );
10961144 browser .addVisibilityWindowListener (new VisibilityWindowAdapter (){});
10971145 shell .close ();
10981146}
@@ -1101,7 +1149,7 @@ public void test_VisibilityWindowListener_newAdapter_closeShell() {
11011149public void test_VisibilityWindowListener_newListener_closeShell () {
11021150 Display display = Display .getCurrent ();
11031151 Shell shell = new Shell (display );
1104- Browser browser = createBrowser (shell , SWT . NONE );
1152+ Browser browser = createBrowser (shell , swtBrowserSettings );
11051153 browser .addVisibilityWindowListener (new VisibilityWindowListener () {
11061154 @ Override
11071155 public void hide (WindowEvent event ) {
@@ -1147,7 +1195,7 @@ public void test_VisibilityWindowListener_multiple_shells() {
11471195 Shell childShell = new Shell (shell );
11481196 childShell .setText ("Child shell " + childCount .get ());
11491197 childShell .setLayout (new FillLayout ());
1150- Browser browserChild = createBrowser (childShell , SWT . NONE );
1198+ Browser browserChild = createBrowser (childShell , swtBrowserSettings );
11511199 event .browser = browserChild ;
11521200 browserChild .setText ("Child window" );
11531201 browserChild .addVisibilityWindowListener (new VisibilityWindowAdapter () {
@@ -1198,6 +1246,8 @@ public void completed(ProgressEvent event) {
11981246 */
11991247@ Test
12001248public void test_VisibilityWindowListener_eventSize () {
1249+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1250+
12011251 shell .setSize (200 ,300 );
12021252 AtomicBoolean childCompleted = new AtomicBoolean (false );
12031253 AtomicReference <Point > result = new AtomicReference <>(new Point (0 ,0 ));
@@ -1206,7 +1256,7 @@ public void test_VisibilityWindowListener_eventSize() {
12061256 childShell .setSize (250 , 350 );
12071257 childShell .setText ("Child shell" );
12081258 childShell .setLayout (new FillLayout ());
1209- final Browser browserChild = createBrowser (childShell , SWT . NONE );
1259+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
12101260
12111261 browser .addOpenWindowListener (event -> {
12121262 event .browser = browserChild ;
@@ -1325,8 +1375,7 @@ public void test_setJavascriptEnabled_multipleInstances() {
13251375 AtomicBoolean instanceOneFinishedCorrectly = new AtomicBoolean (false );
13261376 AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean (false );
13271377
1328-
1329- Browser browserSecondInsance = createBrowser (shell , SWT .None );
1378+ Browser browserSecondInsance = createBrowser (shell , swtBrowserSettings );
13301379
13311380 browser .addProgressListener (completedAdapter (event -> {
13321381 if (pageLoadCount .get () == 1 ) {
@@ -1387,6 +1436,8 @@ public void completed(ProgressEvent event) {
13871436*/
13881437@ Test
13891438public void test_LocationListener_evaluateInCallback () {
1439+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1440+
13901441 AtomicBoolean changingFinished = new AtomicBoolean (false );
13911442 AtomicBoolean changedFinished = new AtomicBoolean (false );
13921443 browser .addLocationListener (new LocationListener () {
@@ -1435,6 +1486,8 @@ public void changed(LocationEvent event) {
14351486/** Verify that evaluation works inside an OpenWindowListener */
14361487@ Test
14371488public void test_OpenWindowListener_evaluateInCallback () {
1489+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1490+
14381491 AtomicBoolean eventFired = new AtomicBoolean (false );
14391492 browser .addOpenWindowListener (event -> {
14401493 browser .evaluate ("SWTopenListener = true" );
@@ -2382,7 +2435,7 @@ public Object function(Object[] arguments) {
23822435 browser .setText ("1st (initial) page load" );
23832436 new JavascriptCallback (browser , "jsCallbackToJava" );
23842437 browser .execute ("jsCallbackToJava()" );
2385- // see if function still works after a page change:
2438+ // see if function still works after a page change:
23862439 browser .addProgressListener (completedAdapter (e -> browser .execute ("jsCallbackToJava()" )));
23872440
23882441 shell .open ();
@@ -2394,8 +2447,8 @@ public Object function(Object[] arguments) {
23942447@ Test
23952448public void test_BrowserFunction_multiprocess () {
23962449 // Test that BrowserFunctions work in multiple Browser instances simultaneously.
2397- Browser browser1 = createBrowser (shell , SWT . NONE );
2398- Browser browser2 = createBrowser (shell , SWT . NONE );
2450+ Browser browser1 = createBrowser (shell , swtBrowserSettings );
2451+ Browser browser2 = createBrowser (shell , swtBrowserSettings );
23992452
24002453 class JavaFunc extends BrowserFunction {
24012454 JavaFunc (Browser browser ) {
0 commit comments