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
@@ -388,7 +424,7 @@ public void test_getChildren() {
388
424
public void test_CloseWindowListener_closeShell () {
389
425
Display display = Display .getCurrent ();
390
426
Shell shell = new Shell (display );
391
- Browser browser = createBrowser (shell , SWT . NONE );
427
+ Browser browser = createBrowser (shell , swtBrowserSettings );
392
428
browser .addCloseWindowListener (event -> {}); // shouldn't throw
393
429
shell .close ();
394
430
}
@@ -427,7 +463,7 @@ public void test_CloseWindowListener_close () {
427
463
public void test_LocationListener_adapter_closeShell () {
428
464
Display display = Display .getCurrent ();
429
465
Shell shell = new Shell (display );
430
- Browser browser = createBrowser (shell , SWT . NONE );
466
+ Browser browser = createBrowser (shell , swtBrowserSettings );
431
467
LocationAdapter adapter = new LocationAdapter () {};
432
468
browser .addLocationListener (adapter ); // shouldn't throw
433
469
shell .close ();
@@ -468,6 +504,8 @@ public void test_LocationListener_changing() {
468
504
}
469
505
@ Test
470
506
public void test_LocationListener_changed () {
507
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
508
+
471
509
AtomicBoolean changedFired = new AtomicBoolean (false );
472
510
browser .addLocationListener (changedAdapter (e -> changedFired .set (true )));
473
511
shell .open ();
@@ -477,6 +515,8 @@ public void test_LocationListener_changed() {
477
515
}
478
516
@ Test
479
517
public void test_LocationListener_changingAndOnlyThenChanged () {
518
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
519
+
480
520
// Test proper order of events.
481
521
// Check that 'changed' is only fired after 'changing' has fired at least once.
482
522
AtomicBoolean changingFired = new AtomicBoolean (false );
@@ -520,6 +560,8 @@ else if (!changingFired.get())
520
560
521
561
@ Test
522
562
public void test_LocationListener_then_ProgressListener () {
563
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
564
+
523
565
AtomicBoolean locationChanged = new AtomicBoolean (false );
524
566
AtomicBoolean progressChanged = new AtomicBoolean (false );
525
567
AtomicBoolean progressChangedAfterLocationChanged = new AtomicBoolean (false );
@@ -613,6 +655,8 @@ public void changed(LocationEvent event) {
613
655
@ Test
614
656
/** Ensue that only one changed and one completed event are fired for url changes */
615
657
public void test_LocationListener_ProgressListener_noExtraEvents () {
658
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
659
+
616
660
AtomicInteger changedCount = new AtomicInteger (0 );
617
661
AtomicInteger completedCount = new AtomicInteger (0 );
618
662
@@ -640,7 +684,7 @@ public void test_LocationListener_ProgressListener_noExtraEvents() {
640
684
public void test_OpenWindowListener_closeShell () {
641
685
Display display = Display .getCurrent ();
642
686
Shell shell = new Shell (display );
643
- Browser browser = createBrowser (shell , SWT . NONE );
687
+ Browser browser = createBrowser (shell , swtBrowserSettings );
644
688
browser .addOpenWindowListener (event -> {});
645
689
shell .close ();
646
690
}
@@ -665,7 +709,7 @@ public void test_OpenWindowListener_addAndRemove() {
665
709
@ Test
666
710
public void test_OpenWindowListener_openHasValidEventDetails () {
667
711
AtomicBoolean openFiredCorrectly = new AtomicBoolean (false );
668
- final Browser browserChild = createBrowser (shell , SWT . None );
712
+ final Browser browserChild = createBrowser (shell , swtBrowserSettings );
669
713
browser .addOpenWindowListener (event -> {
670
714
assertSame ("Expected Browser1 instance, but have another instance" , browser , event .widget );
671
715
assertNull ("Expected event.browser to be null" , event .browser );
@@ -684,12 +728,14 @@ public void test_OpenWindowListener_openHasValidEventDetails() {
684
728
/** Test that a script 'window.open()' opens a child popup shell. */
685
729
@ Test
686
730
public void test_OpenWindowListener_open_ChildPopup () {
731
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
732
+
687
733
AtomicBoolean childCompleted = new AtomicBoolean (false );
688
734
689
735
Shell childShell = new Shell (shell , SWT .None );
690
736
childShell .setText ("Child shell" );
691
737
childShell .setLayout (new FillLayout ());
692
- final Browser browserChild = createBrowser (childShell , SWT . NONE );
738
+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
693
739
694
740
browser .addOpenWindowListener (event -> {
695
741
event .browser = browserChild ;
@@ -719,14 +765,16 @@ public void test_OpenWindowListener_open_ChildPopup() {
719
765
/** Validate event order : Child's visibility should come before progress completed event */
720
766
@ Test
721
767
public void test_OpenWindow_Progress_Listener_ValidateEventOrder () {
768
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
769
+
722
770
AtomicBoolean windowOpenFired = new AtomicBoolean (false );
723
771
AtomicBoolean childCompleted = new AtomicBoolean (false );
724
772
AtomicBoolean visibilityShowed = new AtomicBoolean (false );
725
773
726
774
Shell childShell = new Shell (shell , SWT .None );
727
775
childShell .setText ("Child shell" );
728
776
childShell .setLayout (new FillLayout ());
729
- final Browser browserChild = createBrowser (childShell , SWT . NONE );
777
+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
730
778
731
779
browser .addOpenWindowListener (event -> {
732
780
event .browser = browserChild ;
@@ -776,7 +824,7 @@ public void test_ProgressListener_newProgressAdapter() {
776
824
public void test_ProgressListener_newProgressAdapter_closeShell () {
777
825
Display display = Display .getCurrent ();
778
826
Shell shell = new Shell (display );
779
- Browser browser = createBrowser (shell , SWT . NONE );
827
+ Browser browser = createBrowser (shell , swtBrowserSettings );
780
828
browser .addProgressListener (new ProgressAdapter () {});
781
829
shell .close ();
782
830
}
@@ -785,7 +833,7 @@ public void test_ProgressListener_newProgressAdapter_closeShell() {
785
833
public void test_ProgressListener_newListener_closeShell () {
786
834
Display display = Display .getCurrent ();
787
835
Shell shell = new Shell (display );
788
- Browser browser = createBrowser (shell , SWT . NONE );
836
+ Browser browser = createBrowser (shell , swtBrowserSettings );
789
837
browser .addProgressListener (new ProgressListener () {
790
838
@ Override
791
839
public void changed (ProgressEvent event ) {
@@ -882,13 +930,13 @@ public void test_StatusTextListener_addAndRemove() {
882
930
*/
883
931
@ Test
884
932
public void test_StatusTextListener_hoverMouseOverLink () {
885
- assumeFalse (isEdge ); // no API in Edge for this
933
+ assumeFalse (" no API in Edge for this" , isEdge );
886
934
887
935
AtomicBoolean statusChanged = new AtomicBoolean (false );
888
936
int size = 500 ;
889
937
890
938
// 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 );
892
940
StringBuilder longhtml = new StringBuilder ();
893
941
for (int i = 0 ; i < 200 ; i ++) {
894
942
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() {
928
976
public void test_TitleListener_addListener_closeShell () {
929
977
Display display = Display .getCurrent ();
930
978
Shell shell = new Shell (display );
931
- Browser browser = createBrowser (shell , SWT . NONE );
979
+ Browser browser = createBrowser (shell , swtBrowserSettings );
932
980
browser .addTitleListener (event -> {
933
981
});
934
982
shell .close ();
@@ -1092,7 +1140,7 @@ public void test_VisibilityWindowListener_newAdapter() {
1092
1140
public void test_VisibilityWindowListener_newAdapter_closeShell () {
1093
1141
Display display = Display .getCurrent ();
1094
1142
Shell shell = new Shell (display );
1095
- Browser browser = createBrowser (shell , SWT . NONE );
1143
+ Browser browser = createBrowser (shell , swtBrowserSettings );
1096
1144
browser .addVisibilityWindowListener (new VisibilityWindowAdapter (){});
1097
1145
shell .close ();
1098
1146
}
@@ -1101,7 +1149,7 @@ public void test_VisibilityWindowListener_newAdapter_closeShell() {
1101
1149
public void test_VisibilityWindowListener_newListener_closeShell () {
1102
1150
Display display = Display .getCurrent ();
1103
1151
Shell shell = new Shell (display );
1104
- Browser browser = createBrowser (shell , SWT . NONE );
1152
+ Browser browser = createBrowser (shell , swtBrowserSettings );
1105
1153
browser .addVisibilityWindowListener (new VisibilityWindowListener () {
1106
1154
@ Override
1107
1155
public void hide (WindowEvent event ) {
@@ -1147,7 +1195,7 @@ public void test_VisibilityWindowListener_multiple_shells() {
1147
1195
Shell childShell = new Shell (shell );
1148
1196
childShell .setText ("Child shell " + childCount .get ());
1149
1197
childShell .setLayout (new FillLayout ());
1150
- Browser browserChild = createBrowser (childShell , SWT . NONE );
1198
+ Browser browserChild = createBrowser (childShell , swtBrowserSettings );
1151
1199
event .browser = browserChild ;
1152
1200
browserChild .setText ("Child window" );
1153
1201
browserChild .addVisibilityWindowListener (new VisibilityWindowAdapter () {
@@ -1198,6 +1246,8 @@ public void completed(ProgressEvent event) {
1198
1246
*/
1199
1247
@ Test
1200
1248
public void test_VisibilityWindowListener_eventSize () {
1249
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1250
+
1201
1251
shell .setSize (200 ,300 );
1202
1252
AtomicBoolean childCompleted = new AtomicBoolean (false );
1203
1253
AtomicReference <Point > result = new AtomicReference <>(new Point (0 ,0 ));
@@ -1206,7 +1256,7 @@ public void test_VisibilityWindowListener_eventSize() {
1206
1256
childShell .setSize (250 , 350 );
1207
1257
childShell .setText ("Child shell" );
1208
1258
childShell .setLayout (new FillLayout ());
1209
- final Browser browserChild = createBrowser (childShell , SWT . NONE );
1259
+ final Browser browserChild = createBrowser (childShell , swtBrowserSettings );
1210
1260
1211
1261
browser .addOpenWindowListener (event -> {
1212
1262
event .browser = browserChild ;
@@ -1325,8 +1375,7 @@ public void test_setJavascriptEnabled_multipleInstances() {
1325
1375
AtomicBoolean instanceOneFinishedCorrectly = new AtomicBoolean (false );
1326
1376
AtomicBoolean instanceTwoFinishedCorrectly = new AtomicBoolean (false );
1327
1377
1328
-
1329
- Browser browserSecondInsance = createBrowser (shell , SWT .None );
1378
+ Browser browserSecondInsance = createBrowser (shell , swtBrowserSettings );
1330
1379
1331
1380
browser .addProgressListener (completedAdapter (event -> {
1332
1381
if (pageLoadCount .get () == 1 ) {
@@ -1387,6 +1436,8 @@ public void completed(ProgressEvent event) {
1387
1436
*/
1388
1437
@ Test
1389
1438
public void test_LocationListener_evaluateInCallback () {
1439
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1440
+
1390
1441
AtomicBoolean changingFinished = new AtomicBoolean (false );
1391
1442
AtomicBoolean changedFinished = new AtomicBoolean (false );
1392
1443
browser .addLocationListener (new LocationListener () {
@@ -1435,6 +1486,8 @@ public void changed(LocationEvent event) {
1435
1486
/** Verify that evaluation works inside an OpenWindowListener */
1436
1487
@ Test
1437
1488
public void test_OpenWindowListener_evaluateInCallback () {
1489
+ assumeFalse ("behavior is not (yet) supported by Edge browser" , isEdge );
1490
+
1438
1491
AtomicBoolean eventFired = new AtomicBoolean (false );
1439
1492
browser .addOpenWindowListener (event -> {
1440
1493
browser .evaluate ("SWTopenListener = true" );
@@ -2382,7 +2435,7 @@ public Object function(Object[] arguments) {
2382
2435
browser .setText ("1st (initial) page load" );
2383
2436
new JavascriptCallback (browser , "jsCallbackToJava" );
2384
2437
browser .execute ("jsCallbackToJava()" );
2385
- // see if function still works after a page change:
2438
+ // see if function still works after a page change:
2386
2439
browser .addProgressListener (completedAdapter (e -> browser .execute ("jsCallbackToJava()" )));
2387
2440
2388
2441
shell .open ();
@@ -2394,8 +2447,8 @@ public Object function(Object[] arguments) {
2394
2447
@ Test
2395
2448
public void test_BrowserFunction_multiprocess () {
2396
2449
// 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 );
2399
2452
2400
2453
class JavaFunc extends BrowserFunction {
2401
2454
JavaFunc (Browser browser ) {
0 commit comments