|
| 1 | +// The following tests deal with the <meta http-equiv=refresh> pragma and the |
| 2 | +// `Refresh` header. The spec is still hazy on the precise behavior in those |
| 3 | +// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline. |
| 4 | + |
| 5 | +async_test(t => { |
| 6 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 7 | + t.add_cleanup(() => frame.remove()); |
| 8 | + frame.onload = t.step_func(() => { |
| 9 | + frame.onload = null; |
| 10 | + |
| 11 | + const client = new frame.contentWindow.XMLHttpRequest(); |
| 12 | + client.open("GET", "/common/blank.html"); |
| 13 | + client.onabort = t.step_func_done(); |
| 14 | + client.send(); |
| 15 | + |
| 16 | + frame.contentDocument.open(); |
| 17 | + }); |
| 18 | + frame.src = "resources/meta-refresh.py?0"; |
| 19 | +}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (XMLHttpRequest)"); |
| 20 | + |
| 21 | +async_test(t => { |
| 22 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 23 | + t.add_cleanup(() => frame.remove()); |
| 24 | + frame.onload = t.step_func(() => { |
| 25 | + frame.onload = null; |
| 26 | + |
| 27 | + frame.contentWindow.fetch("/common/blank.html").then( |
| 28 | + t.unreached_func("Fetch should have been aborted"), |
| 29 | + t.step_func_done()); |
| 30 | + |
| 31 | + frame.contentDocument.open(); |
| 32 | + }); |
| 33 | + frame.src = "resources/meta-refresh.py?0"; |
| 34 | +}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (fetch())"); |
| 35 | + |
| 36 | +// We cannot test for img element's error event for this test, as Firefox does |
| 37 | +// not fire the event if the fetch is aborted while Chrome does. |
| 38 | +async_test(t => { |
| 39 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 40 | + t.add_cleanup(() => frame.remove()); |
| 41 | + frame.onload = t.step_func(() => { |
| 42 | + frame.onload = null; |
| 43 | + |
| 44 | + let happened = false; |
| 45 | + const img = frame.contentDocument.createElement("img"); |
| 46 | + img.src = new URL("resources/slow-png.py", document.URL); |
| 47 | + img.onload = t.unreached_func("Image loading should not have succeeded"); |
| 48 | + // The image fetch starts in a microtask, so let's be sure to test after |
| 49 | + // the fetch has started. |
| 50 | + t.step_timeout(() => { |
| 51 | + frame.contentDocument.open(); |
| 52 | + happened = true; |
| 53 | + }); |
| 54 | + // If 3 seconds have passed and the image has still not loaded, we consider |
| 55 | + // it aborted. slow-png.py only sleeps for 2 wallclock seconds. |
| 56 | + t.step_timeout(t.step_func_done(() => { |
| 57 | + assert_true(happened); |
| 58 | + }), 3000); |
| 59 | + }); |
| 60 | + frame.src = "resources/meta-refresh.py?0"; |
| 61 | +}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (image loading)"); |
| 62 | + |
| 63 | +async_test(t => { |
| 64 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 65 | + t.add_cleanup(() => frame.remove()); |
| 66 | + frame.onload = t.step_func(() => { |
| 67 | + frame.onload = null; |
| 68 | + |
| 69 | + const client = new frame.contentWindow.XMLHttpRequest(); |
| 70 | + client.open("GET", "/common/blank.html"); |
| 71 | + client.onabort = t.step_func_done(); |
| 72 | + client.send(); |
| 73 | + |
| 74 | + frame.contentDocument.open(); |
| 75 | + }); |
| 76 | + frame.src = "resources/http-refresh.py?0"; |
| 77 | +}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (XMLHttpRequest)"); |
| 78 | + |
| 79 | +async_test(t => { |
| 80 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 81 | + t.add_cleanup(() => frame.remove()); |
| 82 | + frame.onload = t.step_func(() => { |
| 83 | + frame.onload = null; |
| 84 | + |
| 85 | + frame.contentWindow.fetch("/common/blank.html").then( |
| 86 | + t.unreached_func("Fetch should have been aborted"), |
| 87 | + t.step_func_done()); |
| 88 | + |
| 89 | + frame.contentDocument.open(); |
| 90 | + }); |
| 91 | + frame.src = "resources/http-refresh.py?0"; |
| 92 | +}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (fetch())"); |
| 93 | + |
| 94 | +// We cannot test for img element's error event for this test, as Firefox does |
| 95 | +// not fire the event if the fetch is aborted while Chrome does. |
| 96 | +async_test(t => { |
| 97 | + const frame = document.body.appendChild(document.createElement("iframe")); |
| 98 | + t.add_cleanup(() => frame.remove()); |
| 99 | + frame.onload = t.step_func(() => { |
| 100 | + frame.onload = null; |
| 101 | + |
| 102 | + let happened = false; |
| 103 | + const img = frame.contentDocument.createElement("img"); |
| 104 | + img.src = new URL("resources/slow-png.py", document.URL); |
| 105 | + img.onload = t.unreached_func("Image loading should not have succeeded"); |
| 106 | + // The image fetch starts in a microtask, so let's be sure to test after |
| 107 | + // the fetch has started. |
| 108 | + t.step_timeout(() => { |
| 109 | + frame.contentDocument.open(); |
| 110 | + happened = true; |
| 111 | + }); |
| 112 | + // If 3 seconds have passed and the image has still not loaded, we consider |
| 113 | + // it aborted. slow-png.py only sleeps for 2 wallclock seconds. |
| 114 | + t.step_timeout(t.step_func_done(() => { |
| 115 | + assert_true(happened); |
| 116 | + }), 3000); |
| 117 | + }); |
| 118 | + frame.src = "resources/http-refresh.py?0"; |
| 119 | +}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (image loading)"); |
0 commit comments