-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML: document.open() and aborting documents
For #10773. Co-authored-by: Anne van Kesteren <[email protected]>
- Loading branch information
Showing
12 changed files
with
559 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...papis/dynamic-markup-insertion/opening-the-input-stream/abort-refresh-immediate.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// The following tests deal with the <meta http-equiv=refresh> pragma and the | ||
// `Refresh` header. The spec is still hazy on the precise behavior in those | ||
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline. | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
|
||
const client = new frame.contentWindow.XMLHttpRequest(); | ||
client.open("GET", "/common/blank.html"); | ||
client.onabort = t.step_func_done(); | ||
client.send(); | ||
|
||
frame.contentDocument.open(); | ||
}); | ||
frame.src = "resources/meta-refresh.py?0"; | ||
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (XMLHttpRequest)"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
|
||
frame.contentWindow.fetch("/common/blank.html").then( | ||
t.unreached_func("Fetch should have been aborted"), | ||
t.step_func_done()); | ||
|
||
frame.contentDocument.open(); | ||
}); | ||
frame.src = "resources/meta-refresh.py?0"; | ||
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (fetch())"); | ||
|
||
// We cannot test for img element's error event for this test, as Firefox does | ||
// not fire the event if the fetch is aborted while Chrome does. | ||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
|
||
let happened = false; | ||
const img = frame.contentDocument.createElement("img"); | ||
img.src = new URL("resources/slow-png.py", document.URL); | ||
img.onload = t.unreached_func("Image loading should not have succeeded"); | ||
// The image fetch starts in a microtask, so let's be sure to test after | ||
// the fetch has started. | ||
t.step_timeout(() => { | ||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
// If 3 seconds have passed and the image has still not loaded, we consider | ||
// it aborted. slow-png.py only sleeps for 2 wallclock seconds. | ||
t.step_timeout(t.step_func_done(() => { | ||
assert_true(happened); | ||
}), 3000); | ||
}); | ||
frame.src = "resources/meta-refresh.py?0"; | ||
}, "document.open() aborts documents that are queued for navigation through <meta> refresh with timeout 0 (image loading)"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
|
||
const client = new frame.contentWindow.XMLHttpRequest(); | ||
client.open("GET", "/common/blank.html"); | ||
client.onabort = t.step_func_done(); | ||
client.send(); | ||
|
||
frame.contentDocument.open(); | ||
}); | ||
frame.src = "resources/http-refresh.py?0"; | ||
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (XMLHttpRequest)"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
|
||
frame.contentWindow.fetch("/common/blank.html").then( | ||
t.unreached_func("Fetch should have been aborted"), | ||
t.step_func_done()); | ||
|
||
frame.contentDocument.open(); | ||
}); | ||
frame.src = "resources/http-refresh.py?0"; | ||
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (fetch())"); | ||
|
||
// We cannot test for img element's error event for this test, as Firefox does | ||
// not fire the event if the fetch is aborted while Chrome does. | ||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
|
||
let happened = false; | ||
const img = frame.contentDocument.createElement("img"); | ||
img.src = new URL("resources/slow-png.py", document.URL); | ||
img.onload = t.unreached_func("Image loading should not have succeeded"); | ||
// The image fetch starts in a microtask, so let's be sure to test after | ||
// the fetch has started. | ||
t.step_timeout(() => { | ||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
// If 3 seconds have passed and the image has still not loaded, we consider | ||
// it aborted. slow-png.py only sleeps for 2 wallclock seconds. | ||
t.step_timeout(t.step_func_done(() => { | ||
assert_true(happened); | ||
}), 3000); | ||
}); | ||
frame.src = "resources/http-refresh.py?0"; | ||
}, "document.open() aborts documents that are queued for navigation through Refresh header with timeout 0 (image loading)"); |
69 changes: 69 additions & 0 deletions
69
...amic-markup-insertion/opening-the-input-stream/abort-refresh-multisecond-header.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// The following tests deal with the <meta http-equiv=refresh> pragma and the | ||
// `Refresh` header. The spec is still hazy on the precise behavior in those | ||
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline. | ||
// | ||
// This is separate from abort-refresh-multisecond-meta.window.js to avoid | ||
// browser interventions that limit the number of connections in a tab. | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
let happened = false; | ||
|
||
const client = new frame.contentWindow.XMLHttpRequest(); | ||
client.open("GET", "/common/blank.html"); | ||
client.onload = t.step_func_done(() => { | ||
assert_true(happened); | ||
}); | ||
client.onerror = t.unreached_func("XMLHttpRequest should have succeeded"); | ||
client.onabort = t.unreached_func("XMLHttpRequest should have succeeded"); | ||
client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded"); | ||
client.send(); | ||
|
||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
frame.src = "resources/http-refresh.py?1"; | ||
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (XMLHttpRequest)"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
let happened = false; | ||
frame.contentWindow.fetch("/common/blank.html").then( | ||
t.step_func_done(() => { | ||
assert_true(happened); | ||
}), | ||
t.unreached_func("Fetch should have succeeded") | ||
); | ||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
frame.src = "resources/http-refresh.py?1"; | ||
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 1-sec timeout (fetch())"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
let happened = false; | ||
const img = frame.contentDocument.createElement("img"); | ||
img.src = new URL("resources/slow-png.py", document.URL); | ||
img.onload = t.step_func_done(() => { | ||
assert_true(happened); | ||
}); | ||
img.onerror = t.unreached_func("Image loading should not have errored"); | ||
// The image fetch starts in a microtask, so let's be sure to test after | ||
// the fetch has started. | ||
t.step_timeout(() => { | ||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
}); | ||
frame.src = "resources/http-refresh.py?4"; | ||
}, "document.open() does NOT abort documents that are queued for navigation through Refresh header with 4-sec timeout (image loading)"); |
69 changes: 69 additions & 0 deletions
69
...ynamic-markup-insertion/opening-the-input-stream/abort-refresh-multisecond-meta.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// The following tests deal with the <meta http-equiv=refresh> pragma and the | ||
// `Refresh` header. The spec is still hazy on the precise behavior in those | ||
// cases but we use https://github.com/whatwg/html/issues/4003 as a guideline. | ||
// | ||
// This is separate from abort-refresh-multisecond-header.window.js to avoid | ||
// browser interventions that limit the number of connections in a tab. | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
let happened = false; | ||
|
||
const client = new frame.contentWindow.XMLHttpRequest(); | ||
client.open("GET", "/common/blank.html"); | ||
client.onload = t.step_func_done(() => { | ||
assert_true(happened); | ||
}); | ||
client.onerror = t.unreached_func("XMLHttpRequest should have succeeded"); | ||
client.onabort = t.unreached_func("XMLHttpRequest should have succeeded"); | ||
client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded"); | ||
client.send(); | ||
|
||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
frame.src = "resources/meta-refresh.py?1"; | ||
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 1-sec timeout (XMLHttpRequest)"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
let happened = false; | ||
frame.contentWindow.fetch("/common/blank.html").then( | ||
t.step_func_done(() => { | ||
assert_true(happened); | ||
}), | ||
t.unreached_func("Fetch should have succeeded") | ||
); | ||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
frame.src = "resources/meta-refresh.py?1"; | ||
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 1-sec timeout (fetch())"); | ||
|
||
async_test(t => { | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.onload = t.step_func(() => { | ||
frame.onload = null; | ||
let happened = false; | ||
const img = frame.contentDocument.createElement("img"); | ||
img.src = new URL("resources/slow-png.py", document.URL); | ||
img.onload = t.step_func_done(() => { | ||
assert_true(happened); | ||
}); | ||
img.onerror = t.unreached_func("Image loading should not have errored"); | ||
// The image fetch starts in a microtask, so let's be sure to test after | ||
// the fetch has started. | ||
t.step_timeout(() => { | ||
frame.contentDocument.open(); | ||
happened = true; | ||
}); | ||
}); | ||
frame.src = "resources/meta-refresh.py?4"; | ||
}, "document.open() does NOT abort documents that are queued for navigation through <meta> refresh with 4-sec timeout (image loading)"); |
Oops, something went wrong.