22
22
import static org .junit .Assert .assertNotNull ;
23
23
import static org .junit .Assert .assertNull ;
24
24
import static org .junit .Assert .assertSame ;
25
+ import static org .junit .Assert .assertThrows ;
25
26
import static org .junit .Assert .assertTrue ;
26
27
import static org .junit .Assert .fail ;
27
28
import static org .junit .Assume .assumeFalse ;
40
41
import java .nio .file .Paths ;
41
42
import java .time .Instant ;
42
43
import java .util .ArrayList ;
44
+ import java .util .Collection ;
43
45
import java .util .Collections ;
44
46
import java .util .List ;
45
47
import java .util .Locale ;
81
83
import org .junit .Rule ;
82
84
import org .junit .Test ;
83
85
import org .junit .rules .TestName ;
86
+ import org .junit .runner .RunWith ;
84
87
import org .junit .runners .MethodSorters ;
88
+ import org .junit .runners .Parameterized ;
89
+ import org .junit .runners .Parameterized .Parameters ;
85
90
86
91
/**
87
92
* Automated Test Suite for class org.eclipse.swt.browser.Browser
88
93
*
89
94
* @see org.eclipse.swt.browser.Browser
90
95
*/
96
+ @ RunWith (Parameterized .class )
91
97
@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
92
98
public class Test_org_eclipse_swt_browser_Browser extends Test_org_eclipse_swt_widgets_Composite {
93
99
@@ -132,6 +138,23 @@ private void testLogAppend(String msg) {
132
138
boolean ignoreNonDisposedShells ;
133
139
static List <String > descriptors = new ArrayList <>();
134
140
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
+
135
158
@ Override
136
159
@ Before
137
160
public void setUp () {
@@ -147,7 +170,7 @@ public void setUp() {
147
170
System .out .println ("Running Test_org_eclipse_swt_browser_Browser#" + name .getMethodName ());
148
171
149
172
shell .setLayout (new FillLayout ());
150
- browser = createBrowser (shell , SWT . NONE );
173
+ browser = createBrowser (shell , swtBrowserSettings );
151
174
152
175
isEdge = browser .getBrowserType ().equals ("edge" );
153
176
@@ -206,6 +229,16 @@ public void tearDown() {
206
229
printThreadsInfo ();
207
230
}
208
231
}
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
+ // }
209
242
if (SwtTestUtil .isGTK ) {
210
243
int descriptorDiff = reportOpenedDescriptors ();
211
244
if (descriptorDiff > 0 ) {
@@ -249,23 +282,26 @@ private int reportOpenedDescriptors() {
249
282
}
250
283
251
284
private Browser createBrowser (Shell s , int flags ) {
285
+ long maximumBrowserCreationMilliseconds = 20_000 ;
286
+ long createStartTime = System .currentTimeMillis ();
252
287
Browser b = new Browser (s , flags );
253
288
createdBroswers .add (b );
289
+ long createDuration = System .currentTimeMillis () - createStartTime ;
290
+ assertTrue ("creating browser took too long: " + createDuration + "ms" , createDuration < maximumBrowserCreationMilliseconds );
254
291
return b ;
255
292
}
256
293
257
294
/**
258
295
* Test that if Browser is constructed with the parent being "null", Browser throws an exception.
259
296
*/
260
297
@ Override
261
- @ Test (expected = IllegalArgumentException .class )
262
298
public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI () {
263
- Browser browser = createBrowser (shell , SWT . NONE );
299
+ Browser browser = createBrowser (shell , swtBrowserSettings );
264
300
browser .dispose ();
265
- browser = createBrowser (shell , SWT .BORDER );
301
+ browser = createBrowser (shell , SWT .BORDER | swtBrowserSettings );
266
302
// System.out.println("Test_org_eclipse_swt_browser_Browser#test_Constructor*#getBrowserType(): " + browser.getBrowserType());
267
303
browser .dispose ();
268
- browser = createBrowser (null , SWT . NONE ); // Should throw.
304
+ assertThrows ( IllegalArgumentException . class , () -> createBrowser (null , swtBrowserSettings ));
269
305
}
270
306
271
307
/**
@@ -276,7 +312,7 @@ public void test_Constructor_asyncParentDisposal() {
276
312
Display .getCurrent ().asyncExec (() -> {
277
313
shell .dispose ();
278
314
});
279
- Browser browser = createBrowser (shell , SWT . EDGE );
315
+ Browser browser = createBrowser (shell , swtBrowserSettings );
280
316
assertFalse (browser .isDisposed ());
281
317
}
282
318
@@ -374,7 +410,7 @@ public void test_getChildren() {
374
410
public void test_CloseWindowListener_closeShell () {
375
411
Display display = Display .getCurrent ();
376
412
Shell shell = new Shell (display );
377
- Browser browser = createBrowser (shell , SWT . NONE );
413
+ Browser browser = createBrowser (shell , swtBrowserSettings );
378
414
browser .addCloseWindowListener (event -> {}); // shouldn't throw
379
415
shell .close ();
380
416
}
@@ -413,7 +449,7 @@ public void test_CloseWindowListener_close () {
413
449
public void test_LocationListener_adapter_closeShell () {
414
450
Display display = Display .getCurrent ();
415
451
Shell shell = new Shell (display );
416
- Browser browser = createBrowser (shell , SWT . NONE );
452
+ Browser browser = createBrowser (shell , swtBrowserSettings );
417
453
LocationAdapter adapter = new LocationAdapter () {};
418
454
browser .addLocationListener (adapter ); // shouldn't throw
419
455
shell .close ();
@@ -454,6 +490,8 @@ public void test_LocationListener_changing() {
454
490
}
455
491
@ Test
456
492
public void test_LocationListener_changed () {
493
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
494
+
457
495
AtomicBoolean changedFired = new AtomicBoolean (false );
458
496
browser .addLocationListener (changedAdapter (e -> changedFired .set (true )));
459
497
shell .open ();
@@ -463,6 +501,8 @@ public void test_LocationListener_changed() {
463
501
}
464
502
@ Test
465
503
public void test_LocationListener_changingAndOnlyThenChanged () {
504
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
505
+
466
506
// Test proper order of events.
467
507
// Check that 'changed' is only fired after 'changing' has fired at least once.
468
508
AtomicBoolean changingFired = new AtomicBoolean (false );
@@ -506,6 +546,8 @@ else if (!changingFired.get())
506
546
507
547
@ Test
508
548
public void test_LocationListener_then_ProgressListener () {
549
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
550
+
509
551
AtomicBoolean locationChanged = new AtomicBoolean (false );
510
552
AtomicBoolean progressChanged = new AtomicBoolean (false );
511
553
AtomicBoolean progressChangedAfterLocationChanged = new AtomicBoolean (false );
@@ -599,6 +641,8 @@ public void changed(LocationEvent event) {
599
641
@ Test
600
642
/** Ensue that only one changed and one completed event are fired for url changes */
601
643
public void test_LocationListener_ProgressListener_noExtraEvents () {
644
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
645
+
602
646
AtomicInteger changedCount = new AtomicInteger (0 );
603
647
AtomicInteger completedCount = new AtomicInteger (0 );
604
648
@@ -626,7 +670,7 @@ public void test_LocationListener_ProgressListener_noExtraEvents() {
626
670
public void test_OpenWindowListener_closeShell () {
627
671
Display display = Display .getCurrent ();
628
672
Shell shell = new Shell (display );
629
- Browser browser = createBrowser (shell , SWT . NONE );
673
+ Browser browser = createBrowser (shell , swtBrowserSettings );
630
674
browser .addOpenWindowListener (event -> {});
631
675
shell .close ();
632
676
}
@@ -651,7 +695,7 @@ public void test_OpenWindowListener_addAndRemove() {
651
695
@ Test
652
696
public void test_OpenWindowListener_openHasValidEventDetails () {
653
697
AtomicBoolean openFiredCorrectly = new AtomicBoolean (false );
654
- final Browser browserChild = createBrowser (shell , SWT . None );
698
+ final Browser browserChild = createBrowser (shell , swtBrowserSettings );
655
699
browser .addOpenWindowListener (event -> {
656
700
assertSame ("Expected Browser1 instance, but have another instance" , browser , event .widget );
657
701
assertNull ("Expected event.browser to be null" , event .browser );
@@ -670,12 +714,14 @@ public void test_OpenWindowListener_openHasValidEventDetails() {
670
714
/** Test that a script 'window.open()' opens a child popup shell. */
671
715
@ Test
672
716
public void test_OpenWindowListener_open_ChildPopup () {
717
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
718
+
673
719
AtomicBoolean childCompleted = new AtomicBoolean (false );
674
720
675
721
Shell childShell = new Shell (shell , SWT .None );
676
722
childShell .setText ("Child shell" );
677
723
childShell .setLayout (new FillLayout ());
678
- final Browser browserChild = createBrowser (childShell , SWT . NONE );
724
+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
679
725
680
726
browser .addOpenWindowListener (event -> {
681
727
event .browser = browserChild ;
@@ -705,14 +751,16 @@ public void test_OpenWindowListener_open_ChildPopup() {
705
751
/** Validate event order : Child's visibility should come before progress completed event */
706
752
@ Test
707
753
public void test_OpenWindow_Progress_Listener_ValidateEventOrder () {
754
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
755
+
708
756
AtomicBoolean windowOpenFired = new AtomicBoolean (false );
709
757
AtomicBoolean childCompleted = new AtomicBoolean (false );
710
758
AtomicBoolean visibilityShowed = new AtomicBoolean (false );
711
759
712
760
Shell childShell = new Shell (shell , SWT .None );
713
761
childShell .setText ("Child shell" );
714
762
childShell .setLayout (new FillLayout ());
715
- final Browser browserChild = createBrowser (childShell , SWT . NONE );
763
+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
716
764
717
765
browser .addOpenWindowListener (event -> {
718
766
event .browser = browserChild ;
@@ -762,7 +810,7 @@ public void test_ProgressListener_newProgressAdapter() {
762
810
public void test_ProgressListener_newProgressAdapter_closeShell () {
763
811
Display display = Display .getCurrent ();
764
812
Shell shell = new Shell (display );
765
- Browser browser = createBrowser (shell , SWT . NONE );
813
+ Browser browser = createBrowser (shell , swtBrowserSettings );
766
814
browser .addProgressListener (new ProgressAdapter () {});
767
815
shell .close ();
768
816
}
@@ -771,7 +819,7 @@ public void test_ProgressListener_newProgressAdapter_closeShell() {
771
819
public void test_ProgressListener_newListener_closeShell () {
772
820
Display display = Display .getCurrent ();
773
821
Shell shell = new Shell (display );
774
- Browser browser = createBrowser (shell , SWT . NONE );
822
+ Browser browser = createBrowser (shell , swtBrowserSettings );
775
823
browser .addProgressListener (new ProgressListener () {
776
824
@ Override
777
825
public void changed (ProgressEvent event ) {
@@ -868,13 +916,13 @@ public void test_StatusTextListener_addAndRemove() {
868
916
*/
869
917
@ Test
870
918
public void test_StatusTextListener_hoverMouseOverLink () {
871
- assumeFalse (isEdge ); // no API in Edge for this
919
+ assumeFalse (" no API in Edge for this" , isEdge );
872
920
873
921
AtomicBoolean statusChanged = new AtomicBoolean (false );
874
922
int size = 500 ;
875
923
876
924
// 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 );
878
926
StringBuilder longhtml = new StringBuilder ();
879
927
for (int i = 0 ; i < 200 ; i ++) {
880
928
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() {
914
962
public void test_TitleListener_addListener_closeShell () {
915
963
Display display = Display .getCurrent ();
916
964
Shell shell = new Shell (display );
917
- Browser browser = createBrowser (shell , SWT . NONE );
965
+ Browser browser = createBrowser (shell , swtBrowserSettings );
918
966
browser .addTitleListener (event -> {
919
967
});
920
968
shell .close ();
@@ -1078,7 +1126,7 @@ public void test_VisibilityWindowListener_newAdapter() {
1078
1126
public void test_VisibilityWindowListener_newAdapter_closeShell () {
1079
1127
Display display = Display .getCurrent ();
1080
1128
Shell shell = new Shell (display );
1081
- Browser browser = createBrowser (shell , SWT . NONE );
1129
+ Browser browser = createBrowser (shell , swtBrowserSettings );
1082
1130
browser .addVisibilityWindowListener (new VisibilityWindowAdapter (){});
1083
1131
shell .close ();
1084
1132
}
@@ -1087,7 +1135,7 @@ public void test_VisibilityWindowListener_newAdapter_closeShell() {
1087
1135
public void test_VisibilityWindowListener_newListener_closeShell () {
1088
1136
Display display = Display .getCurrent ();
1089
1137
Shell shell = new Shell (display );
1090
- Browser browser = createBrowser (shell , SWT . NONE );
1138
+ Browser browser = createBrowser (shell , swtBrowserSettings );
1091
1139
browser .addVisibilityWindowListener (new VisibilityWindowListener () {
1092
1140
@ Override
1093
1141
public void hide (WindowEvent event ) {
@@ -1133,7 +1181,7 @@ public void test_VisibilityWindowListener_multiple_shells() {
1133
1181
Shell childShell = new Shell (shell );
1134
1182
childShell .setText ("Child shell " + childCount .get ());
1135
1183
childShell .setLayout (new FillLayout ());
1136
- Browser browserChild = createBrowser (childShell , SWT . NONE );
1184
+ Browser browserChild = createBrowser (childShell , swtBrowserSettings );
1137
1185
event .browser = browserChild ;
1138
1186
browserChild .setText ("Child window" );
1139
1187
browserChild .addVisibilityWindowListener (new VisibilityWindowAdapter () {
@@ -1184,6 +1232,8 @@ public void completed(ProgressEvent event) {
1184
1232
*/
1185
1233
@ Test
1186
1234
public void test_VisibilityWindowListener_eventSize () {
1235
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1236
+
1187
1237
shell .setSize (200 ,300 );
1188
1238
AtomicBoolean childCompleted = new AtomicBoolean (false );
1189
1239
AtomicReference <Point > result = new AtomicReference <>(new Point (0 ,0 ));
@@ -1192,7 +1242,7 @@ public void test_VisibilityWindowListener_eventSize() {
1192
1242
childShell .setSize (250 , 350 );
1193
1243
childShell .setText ("Child shell" );
1194
1244
childShell .setLayout (new FillLayout ());
1195
- final Browser browserChild = createBrowser (childShell , SWT . NONE );
1245
+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
1196
1246
1197
1247
browser .addOpenWindowListener (event -> {
1198
1248
event .browser = browserChild ;
@@ -1311,8 +1361,7 @@ public void test_setJavascriptEnabled_multipleInstances() {
1311
1361
AtomicBoolean instanceOneFinishedCorrectly = new AtomicBoolean (false );
1312
1362
AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean (false );
1313
1363
1314
-
1315
- Browser browserSecondInsance = createBrowser (shell , SWT .None );
1364
+ Browser browserSecondInsance = createBrowser (shell , swtBrowserSettings );
1316
1365
1317
1366
browser .addProgressListener (completedAdapter (event -> {
1318
1367
if (pageLoadCount .get () == 1 ) {
@@ -1373,6 +1422,8 @@ public void completed(ProgressEvent event) {
1373
1422
*/
1374
1423
@ Test
1375
1424
public void test_LocationListener_evaluateInCallback () {
1425
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1426
+
1376
1427
AtomicBoolean changingFinished = new AtomicBoolean (false );
1377
1428
AtomicBoolean changedFinished = new AtomicBoolean (false );
1378
1429
browser .addLocationListener (new LocationListener () {
@@ -1421,6 +1472,8 @@ public void changed(LocationEvent event) {
1421
1472
/** Verify that evaluation works inside an OpenWindowListener */
1422
1473
@ Test
1423
1474
public void test_OpenWindowListener_evaluateInCallback () {
1475
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1476
+
1424
1477
AtomicBoolean eventFired = new AtomicBoolean (false );
1425
1478
browser .addOpenWindowListener (event -> {
1426
1479
browser .evaluate ("SWTopenListener = true" );
@@ -2368,7 +2421,7 @@ public Object function(Object[] arguments) {
2368
2421
browser .setText ("1st (initial) page load" );
2369
2422
new JavascriptCallback (browser , "jsCallbackToJava" );
2370
2423
browser .execute ("jsCallbackToJava()" );
2371
- // see if function still works after a page change:
2424
+ // see if function still works after a page change:
2372
2425
browser .addProgressListener (completedAdapter (e -> browser .execute ("jsCallbackToJava()" )));
2373
2426
2374
2427
shell .open ();
@@ -2380,8 +2433,8 @@ public Object function(Object[] arguments) {
2380
2433
@ Test
2381
2434
public void test_BrowserFunction_multiprocess () {
2382
2435
// 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 );
2385
2438
2386
2439
class JavaFunc extends BrowserFunction {
2387
2440
JavaFunc (Browser browser ) {
0 commit comments