-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1694952 [wpt PR 27778] - XMLHttpRequest: response stream errors, …
…a=testonly Automatic update from web-platform-tests XMLHttpRequest: response stream errors For whatwg/xhr#314. -- wpt-commits: 57ceb7e5521452bbc67afb75d130c40980e48a11 wpt-pr: 27778 UltraBlame original commit: 5ff73d61dcf3523bf8e1d1b9b8e0695b2b123c93
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...latform/tests/service-workers/service-worker/fetch-request-xhr-sync-error.https.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,19 @@ | ||
|
||
|
||
"use strict"; | ||
|
||
promise_test(async t => { | ||
const url = "resources/fetch-request-xhr-sync-error-worker.js"; | ||
const scope = "resources/fetch-request-xhr-sync-iframe.html"; | ||
|
||
const registration = await service_worker_unregister_and_register(t, url, scope); | ||
t.add_cleanup(() => registration.unregister()); | ||
|
||
await wait_for_state(t, registration.installing, 'activated'); | ||
const frame = await with_iframe(scope); | ||
t.add_cleanup(() => frame.remove()); | ||
|
||
assert_throws_dom("NetworkError", frame.contentWindow.DOMException, () => frame.contentWindow.performSyncXHR("non-existent-stream-1.txt")); | ||
assert_throws_dom("NetworkError", frame.contentWindow.DOMException, () => frame.contentWindow.performSyncXHR("non-existent-stream-2.txt")); | ||
assert_throws_dom("NetworkError", frame.contentWindow.DOMException, () => frame.contentWindow.performSyncXHR("non-existent-stream-3.txt")); | ||
}, "Verify synchronous XMLHttpRequest always throws a NetworkError for ReadableStream errors"); |
19 changes: 19 additions & 0 deletions
19
...orm/tests/service-workers/service-worker/resources/fetch-request-xhr-sync-error-worker.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,19 @@ | ||
"use strict"; | ||
|
||
self.onfetch = event => { | ||
if (event.request.url.endsWith("non-existent-stream-1.txt")) { | ||
const rs1 = new ReadableStream(); | ||
event.respondWith(new Response(rs1)); | ||
rs1.cancel(1); | ||
} else if (event.request.url.endsWith("non-existent-stream-2.txt")) { | ||
const rs2 = new ReadableStream({ | ||
start(controller) { controller.error(1) } | ||
}); | ||
event.respondWith(new Response(rs2)); | ||
} else if (event.request.url.endsWith("non-existent-stream-3.txt")) { | ||
const rs3 = new ReadableStream({ | ||
pull(controller) { controller.error(1) } | ||
}); | ||
event.respondWith(new Response(rs3)); | ||
} | ||
}; |
23 changes: 23 additions & 0 deletions
23
testing/web-platform/tests/xhr/response-body-errors.any.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,23 @@ | ||
|
||
const url = "/fetch/api/resources/bad-chunk-encoding.py?ms=1&count=2"; | ||
|
||
test(() => { | ||
client = new XMLHttpRequest(); | ||
client.open("GET", url, false); | ||
assert_throws_dom("NetworkError", () => client.send()); | ||
}, "Synchronous XMLHttpRequest should throw on bad chunk"); | ||
|
||
async_test(t => { | ||
client = new XMLHttpRequest(); | ||
client.open("GET", url, true); | ||
client.onreadystatechange = t.step_func(() => { | ||
if (client.readyState === 3) { | ||
assert_true(client.responseText.indexOf("TEST_CHUNK") !== -1); | ||
} | ||
}); | ||
client.onerror = t.step_func_done(() => { | ||
assert_equals(client.responseText, ""); | ||
}); | ||
client.onload = t.unreached_func(); | ||
client.send(); | ||
}, "Asynchronous XMLHttpRequest should clear response on bad chunk"); |