Skip to content

Commit

Permalink
XMLHttpRequest: response stream errors
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk committed Feb 25, 2021
1 parent c2f0970 commit ee00915
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// META: script=resources/test-helpers.sub.js

"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");
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));
}
};

0 comments on commit ee00915

Please sign in to comment.