Skip to content

Commit

Permalink
Export extra test in FileAPI/url/url-with-fetch.any.js from WebKit
Browse files Browse the repository at this point in the history
Export extra test in FileAPI/url/url-with-fetch.any.js from WebKit:
WebKit/WebKit#3306

The test makes sure that the blob URL is kept alive even after
cloning the fetch Request.
  • Loading branch information
cdumez authored and gsnedders committed Aug 24, 2022
1 parent ac84ada commit f2870c0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions FileAPI/url/url-with-fetch.any.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
// META: script=resources/fetch-tests.js

async function garbageCollect() {
if (typeof TestUtils !== 'undefined' && TestUtils.gc) {
await TestUtils.gc();
} else if (self.gc) {
await self.gc();
} else if (self.GCController) {
// Present in some WebKit development environments
await GCController.collect();
} else {
var gcRec = function (n) {
if (n < 1)
return {};
var temp = {i: "ab" + i + (i / 100000)};
temp += "foo";
gcRec(n-1);
};
for (var i = 0; i < 1000; i++)
gcRec(10);
}
}

function fetch_should_succeed(test, request) {
return fetch(request).then(response => response.text());
}
Expand Down Expand Up @@ -37,6 +58,24 @@ promise_test(t => {
});
}, 'Revoke blob URL after creating Request, will fetch');

promise_test(async t => {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
const url = URL.createObjectURL(blob);
let request = new Request(url);

// Revoke the object URL. Request should take a reference to the blob as
// soon as it receives it in open(), so the request succeeds even though we
// revoke the URL before calling fetch().
URL.revokeObjectURL(url);

request = request.clone();
await garbageCollect();

const text = await fetch_should_succeed(t, request);
assert_equals(text, blob_contents);
}, 'Revoke blob URL after creating Request, then clone Request, will fetch');

promise_test(function(t) {
const blob_contents = 'test blob contents';
const blob = new Blob([blob_contents]);
Expand Down

0 comments on commit f2870c0

Please sign in to comment.