2121import org .htmlunit .WebDriverTestCase ;
2222import org .htmlunit .WebRequest ;
2323import org .htmlunit .junit .annotation .Alerts ;
24+ import org .htmlunit .junit .annotation .HtmlUnitNYI ;
2425import org .htmlunit .util .MimeType ;
2526import org .htmlunit .util .NameValuePair ;
26- import org .junit .jupiter .api .Disabled ;
2727import org .junit .jupiter .api .Test ;
2828import org .openqa .selenium .WebDriver ;
29+ import org .openqa .selenium .htmlunit .HtmlUnitDriver ;
2930
3031/**
3132 * Tests for Fetch API.
@@ -38,9 +39,11 @@ public class FetchTest extends WebDriverTestCase {
3839 * @throws Exception if the test fails
3940 */
4041 @ Test
41- @ Disabled
4242 @ Alerts ({"200" , "OK" , "true" , "text/xml;charset=iso-8859-1" ,
4343 "<xml><content>blah</content></xml>" })
44+ @ HtmlUnitNYI (
45+ FF = {"200" , "OK" , "true" , "text/xml" , "<xml><content>blah</content></xml>" },
46+ FF_ESR = {"200" , "OK" , "true" , "text/xml" , "<xml><content>blah</content></xml>" })
4447 public void fetchGet () throws Exception {
4548 final String html = DOCTYPE_HTML
4649 + "<html>\n "
@@ -64,7 +67,8 @@ public void fetchGet() throws Exception {
6467 final String xml = "<xml><content>blah</content></xml>" ;
6568 getMockWebConnection ().setResponse (URL_SECOND , xml , MimeType .TEXT_XML );
6669
67- final WebDriver driver = loadPage2 (html );
70+ final WebDriver driver = enableFetchPolyfill ();
71+ loadPage2 (html );
6872 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
6973
7074 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -74,7 +78,6 @@ public void fetchGet() throws Exception {
7478 * @throws Exception if the test fails
7579 */
7680 @ Test
77- @ Disabled
7881 @ Alerts ("TypeError" )
7982 public void fetchGetWithBody () throws Exception {
8083 final String html = DOCTYPE_HTML
@@ -101,7 +104,8 @@ public void fetchGetWithBody() throws Exception {
101104
102105 getMockWebConnection ().setResponse (URL_SECOND , "<response/>" , MimeType .TEXT_XML );
103106
104- final WebDriver driver = loadPage2 (html );
107+ final WebDriver driver = enableFetchPolyfill ();
108+ loadPage2 (html );
105109 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
106110
107111 assertEquals (URL_FIRST , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -111,7 +115,6 @@ public void fetchGetWithBody() throws Exception {
111115 * @throws Exception if the test fails
112116 */
113117 @ Test
114- @ Disabled
115118 @ Alerts ("TypeError" )
116119 public void fetchGetWrongUrl () throws Exception {
117120 final String html = DOCTYPE_HTML
@@ -135,7 +138,8 @@ public void fetchGetWrongUrl() throws Exception {
135138
136139 getMockWebConnection ().setResponse (URL_SECOND , "<response/>" , MimeType .TEXT_XML );
137140
138- final WebDriver driver = loadPage2 (html );
141+ final WebDriver driver = enableFetchPolyfill ();
142+ loadPage2 (html );
139143 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
140144
141145 assertEquals (1 , getMockWebConnection ().getRequestCount ());
@@ -146,8 +150,10 @@ public void fetchGetWrongUrl() throws Exception {
146150 * @throws Exception if the test fails
147151 */
148152 @ Test
149- @ Disabled
150153 @ Alerts ({"200" , "OK" , "true" , "text/xml;charset=iso-8859-1" , "<response/>" })
154+ @ HtmlUnitNYI (
155+ FF = {"200" , "OK" , "true" , "text/xml" , "<response/>" },
156+ FF_ESR = {"200" , "OK" , "true" , "text/xml" , "<response/>" })
151157 public void fetchPost () throws Exception {
152158 final String html = DOCTYPE_HTML
153159 + "<html>\n "
@@ -173,7 +179,8 @@ public void fetchPost() throws Exception {
173179
174180 getMockWebConnection ().setResponse (URL_SECOND , "<response/>" , MimeType .TEXT_XML );
175181
176- final WebDriver driver = loadPage2 (html );
182+ final WebDriver driver = enableFetchPolyfill ();
183+ loadPage2 (html );
177184 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
178185
179186 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -184,9 +191,11 @@ public void fetchPost() throws Exception {
184191 * @throws Exception if the test fails
185192 */
186193 @ Test
187- @ Disabled
188194 @ Alerts ({"200" , "OK" , "true" ,
189195 "text/plain;charset=iso-8859-1" , "bla\\ sbla" })
196+ @ HtmlUnitNYI (
197+ FF = {"200" , "OK" , "true" , "text/plain" , "bla\\ sbla" },
198+ FF_ESR = {"200" , "OK" , "true" , "text/plain" , "bla\\ sbla" })
190199 public void fetchGetText () throws Exception {
191200 final String html = DOCTYPE_HTML
192201 + "<html>\n "
@@ -209,7 +218,8 @@ public void fetchGetText() throws Exception {
209218
210219 getMockWebConnection ().setResponse (URL_SECOND , "bla bla" , MimeType .TEXT_PLAIN );
211220
212- final WebDriver driver = loadPage2 (html );
221+ final WebDriver driver = enableFetchPolyfill ();
222+ loadPage2 (html );
213223 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
214224
215225 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -219,9 +229,11 @@ public void fetchGetText() throws Exception {
219229 * @throws Exception if the test fails
220230 */
221231 @ Test
222- @ Disabled
223232 @ Alerts ({"200" , "OK" , "true" ,
224233 "application/json;charset=iso-8859-1" , "{\\ s'Html':\\ s'Unit'\\ s}" })
234+ @ HtmlUnitNYI (
235+ FF = {"200" , "OK" , "true" , "application/json" , "{\\ s'Html':\\ s'Unit'\\ s}" },
236+ FF_ESR = {"200" , "OK" , "true" , "application/json" , "{\\ s'Html':\\ s'Unit'\\ s}" })
225237 public void fetchGetJsonText () throws Exception {
226238 final String html = DOCTYPE_HTML
227239 + "<html>\n "
@@ -245,7 +257,8 @@ public void fetchGetJsonText() throws Exception {
245257 final String json = "{ 'Html': 'Unit' }" ;
246258 getMockWebConnection ().setResponse (URL_SECOND , json , MimeType .APPLICATION_JSON );
247259
248- final WebDriver driver = loadPage2 (html );
260+ final WebDriver driver = enableFetchPolyfill ();
261+ loadPage2 (html );
249262 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
250263
251264 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -255,10 +268,14 @@ public void fetchGetJsonText() throws Exception {
255268 * @throws Exception if the test fails
256269 */
257270 @ Test
258- @ Disabled
259271 @ Alerts ({"200" , "OK" , "true" ,
260272 "application/json;charset=iso-8859-1" ,
261273 "[object\\ sObject]" , "Unit" , "{\" Html\" :\" Unit\" }" })
274+ @ HtmlUnitNYI (
275+ FF = {"200" , "OK" , "true" , "application/json" ,
276+ "[object\\ sObject]" , "Unit" , "{\" Html\" :\" Unit\" }" },
277+ FF_ESR = {"200" , "OK" , "true" , "application/json" ,
278+ "[object\\ sObject]" , "Unit" , "{\" Html\" :\" Unit\" }" })
262279 public void fetchGetJson () throws Exception {
263280 final String html = DOCTYPE_HTML
264281 + "<html>\n "
@@ -286,7 +303,8 @@ public void fetchGetJson() throws Exception {
286303 final String json = "{ \" Html\" : \" Unit\" }" ;
287304 getMockWebConnection ().setResponse (URL_SECOND , json , MimeType .APPLICATION_JSON );
288305
289- final WebDriver driver = loadPage2 (html );
306+ final WebDriver driver = enableFetchPolyfill ();
307+ loadPage2 (html );
290308 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
291309
292310 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -296,13 +314,15 @@ public void fetchGetJson() throws Exception {
296314 * @throws Exception if the test fails
297315 */
298316 @ Test
299- @ Disabled
300317 @ Alerts (DEFAULT = {"200" , "OK" , "true" , "text/plain;charset=iso-8859-1" ,
301318 "[object\\ sBlob]" , "4" , "text/plain" },
302319 FF = {"200" , "OK" , "true" , "text/plain;charset=iso-8859-1" ,
303320 "[object\\ sBlob]" , "4" , "text/plain;charset=iso-8859-1" },
304321 FF_ESR = {"200" , "OK" , "true" , "text/plain;charset=iso-8859-1" ,
305322 "[object\\ sBlob]" , "4" , "text/plain;charset=iso-8859-1" })
323+ @ HtmlUnitNYI (
324+ FF = {"200" , "OK" , "true" , "text/plain" , "[object\\ sBlob]" , "4" , "text/plain" },
325+ FF_ESR = {"200" , "OK" , "true" , "text/plain" , "[object\\ sBlob]" , "4" , "text/plain" })
306326 public void fetchGetBlob () throws Exception {
307327 final String html = DOCTYPE_HTML
308328 + "<html>\n "
@@ -329,7 +349,8 @@ public void fetchGetBlob() throws Exception {
329349
330350 getMockWebConnection ().setResponse (URL_SECOND , "ABCD" , MimeType .TEXT_PLAIN );
331351
332- final WebDriver driver = loadPage2 (html );
352+ final WebDriver driver = enableFetchPolyfill ();
353+ loadPage2 (html );
333354 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
334355
335356 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -339,9 +360,11 @@ public void fetchGetBlob() throws Exception {
339360 * @throws Exception if the test fails
340361 */
341362 @ Test
342- @ Disabled
343363 @ Alerts ({"200" , "OK" , "true" , "text/plain;charset=iso-8859-1" ,
344364 "[object\\ sArrayBuffer]" , "4" })
365+ @ HtmlUnitNYI (
366+ FF = {"200" , "OK" , "true" , "text/plain" , "[object\\ sArrayBuffer]" , "4" },
367+ FF_ESR = {"200" , "OK" , "true" , "text/plain" , "[object\\ sArrayBuffer]" , "4" })
345368 public void fetchGetArrayBuffer () throws Exception {
346369 final String html = DOCTYPE_HTML
347370 + "<html>\n "
@@ -367,7 +390,8 @@ public void fetchGetArrayBuffer() throws Exception {
367390
368391 getMockWebConnection ().setResponse (URL_SECOND , "ABCD" , MimeType .TEXT_PLAIN );
369392
370- final WebDriver driver = loadPage2 (html );
393+ final WebDriver driver = enableFetchPolyfill ();
394+ loadPage2 (html );
371395 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
372396
373397 assertEquals (URL_SECOND , getMockWebConnection ().getLastWebRequest ().getUrl ());
@@ -377,7 +401,6 @@ public void fetchGetArrayBuffer() throws Exception {
377401 * @throws Exception if the test fails
378402 */
379403 @ Test
380- @ Disabled
381404 @ Alerts ({"200" , "OK" , "true" })
382405 public void fetchGetCustomHeader () throws Exception {
383406 final String html = DOCTYPE_HTML
@@ -405,7 +428,8 @@ public void fetchGetCustomHeader() throws Exception {
405428 final String json = "{ \" Html\" : \" Unit\" }" ;
406429 getMockWebConnection ().setResponse (URL_SECOND , json , MimeType .APPLICATION_JSON );
407430
408- final WebDriver driver = loadPage2 (html );
431+ final WebDriver driver = enableFetchPolyfill ();
432+ loadPage2 (html );
409433 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
410434
411435 final WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
@@ -418,8 +442,10 @@ public void fetchGetCustomHeader() throws Exception {
418442 * @throws Exception if the test fails
419443 */
420444 @ Test
421- @ Disabled
422445 @ Alerts ({"200" , "OK" , "true" , "text/plain;charset=iso-8859-1" , "x-tEsT" })
446+ @ HtmlUnitNYI (
447+ FF = {"200" , "OK" , "true" , "text/plain" , "null" },
448+ FF_ESR = {"200" , "OK" , "true" , "text/plain" , "null" })
423449 public void fetchGetCustomResponseHeader () throws Exception {
424450 final String html = DOCTYPE_HTML
425451 + "<html>\n "
@@ -449,7 +475,8 @@ public void fetchGetCustomResponseHeader() throws Exception {
449475 headers .add (new NameValuePair ("X-Custom-Header" , "x-tEsT" ));
450476 getMockWebConnection ().setResponse (URL_SECOND , "HtmlUnit" , 200 , "ok" , MimeType .TEXT_PLAIN , headers );
451477
452- final WebDriver driver = loadPage2 (html );
478+ final WebDriver driver = enableFetchPolyfill ();
479+ loadPage2 (html );
453480 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
454481
455482 final WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
@@ -462,7 +489,6 @@ public void fetchGetCustomResponseHeader() throws Exception {
462489 * @throws Exception if the test fails
463490 */
464491 @ Test
465- @ Disabled
466492 @ Alerts ({"200" , "OK" , "true" })
467493 public void fetchPostFormData () throws Exception {
468494 final String html = DOCTYPE_HTML
@@ -493,7 +519,8 @@ public void fetchPostFormData() throws Exception {
493519
494520 getMockWebConnection ().setResponse (URL_SECOND , "HtmlUnit" , MimeType .TEXT_PLAIN );
495521
496- final WebDriver driver = loadPage2 (html );
522+ final WebDriver driver = enableFetchPolyfill ();
523+ loadPage2 (html );
497524 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
498525
499526 final WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
@@ -509,7 +536,6 @@ public void fetchPostFormData() throws Exception {
509536 * @throws Exception if the test fails
510537 */
511538 @ Test
512- @ Disabled
513539 @ Alerts ({"200" , "OK" , "true" })
514540 public void fetchPostURLSearchParams () throws Exception {
515541 final String html = DOCTYPE_HTML
@@ -536,7 +562,8 @@ public void fetchPostURLSearchParams() throws Exception {
536562
537563 getMockWebConnection ().setResponse (URL_SECOND , "HtmlUnit" , MimeType .TEXT_PLAIN );
538564
539- final WebDriver driver = loadPage2 (html );
565+ final WebDriver driver = enableFetchPolyfill ();
566+ loadPage2 (html );
540567 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
541568
542569 final WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
@@ -558,7 +585,6 @@ public void fetchPostURLSearchParams() throws Exception {
558585 * @throws Exception if the test fails
559586 */
560587 @ Test
561- @ Disabled
562588 @ Alerts ({"200" , "OK" , "true" })
563589 public void fetchPostJSON () throws Exception {
564590 final String html = DOCTYPE_HTML
@@ -586,7 +612,8 @@ public void fetchPostJSON() throws Exception {
586612
587613 getMockWebConnection ().setResponse (URL_SECOND , "HtmlUnit" , MimeType .TEXT_PLAIN );
588614
589- final WebDriver driver = loadPage2 (html );
615+ final WebDriver driver = enableFetchPolyfill ();
616+ loadPage2 (html );
590617 verifyTitle2 (DEFAULT_WAIT_TIME , driver , getExpectedAlerts ());
591618
592619 final WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
@@ -751,4 +778,12 @@ public void fetchPostJSON() throws Exception {
751778// final WebDriver driver = loadPage2(html);
752779// verifyTitle2(DEFAULT_WAIT_TIME, driver, getExpectedAlerts());
753780// }
781+
782+ private WebDriver enableFetchPolyfill () {
783+ final WebDriver driver = getWebDriver ();
784+ if (driver instanceof HtmlUnitDriver ) {
785+ ((HtmlUnitDriver ) driver ).getWebClient ().getOptions ().setFetchPolyfillEnabled (true );
786+ }
787+ return driver ;
788+ }
754789}
0 commit comments