diff --git a/dom/file/tests/test_agentcluster_bloburl.js b/dom/file/tests/test_agentcluster_bloburl.js new file mode 100644 index 000000000000..102786f181ca --- /dev/null +++ b/dom/file/tests/test_agentcluster_bloburl.js @@ -0,0 +1,159 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +const { CookieXPCShellUtils } = ChromeUtils.import( + "resource://testing-common/CookieXPCShellUtils.jsm" +); + +CookieXPCShellUtils.init(this); + +// Same agent cluster, all works fine: blobURLs can be opened. +add_task(async () => { + do_get_profile(); + + const server = CookieXPCShellUtils.createServer({ hosts: ["example.org"] }); + + let result = new Promise(resolve => { + server.registerPathHandler("/result", (metadata, response) => { + resolve(metadata.queryString == "ok"); + + const body = "Done"; + response.bodyOutputStream.write(body, body.length); + }); + }); + + server.registerPathHandler("/test", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/html", false); + const body = ``; + response.bodyOutputStream.write(body, body.length); + }); + + let contentPage = await CookieXPCShellUtils.loadContentPage( + "http://example.org/test" + ); + + Assert.ok(await result, "BlobURL works"); + await contentPage.close(); +}); + +// Same agent cluster: frames +add_task(async () => { + do_get_profile(); + + const server = CookieXPCShellUtils.createServer({ hosts: ["example.org"] }); + + let result = new Promise(resolve => { + server.registerPathHandler("/result", (metadata, response) => { + resolve(metadata.queryString == "ok"); + + const body = "Done"; + response.bodyOutputStream.write(body, body.length); + }); + }); + + server.registerPathHandler("/iframe", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/html", false); + const body = ``; + response.bodyOutputStream.write(body, body.length); + }); + + server.registerPathHandler("/test", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/html", false); + const body = ``; + response.bodyOutputStream.write(body, body.length); + }); + + let contentPage = await CookieXPCShellUtils.loadContentPage( + "http://example.org/test" + ); + + Assert.ok(await result, "BlobURL works"); + await contentPage.close(); +}); + +// Cross agent cluster: different tabs +add_task(async () => { + do_get_profile(); + + const server = CookieXPCShellUtils.createServer({ hosts: ["example.org"] }); + + let result = new Promise(resolve => { + server.registerPathHandler("/result", (metadata, response) => { + resolve(metadata.queryString == "ok"); + + const body = "Done"; + response.bodyOutputStream.write(body, body.length); + }); + }); + + const step = new Promise(resolve => { + server.registerPathHandler("/step", (metadata, response) => { + resolve(metadata.queryString); + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/html", false); + const body = "Thanks!"; + response.bodyOutputStream.write(body, body.length); + }); + }); + + server.registerPathHandler("/test", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/html", false); + const body = ``; + response.bodyOutputStream.write(body, body.length); + }); + + let contentPage = await CookieXPCShellUtils.loadContentPage( + "http://example.org/test" + ); + + const blobURL = await step; + Assert.ok(blobURL.length, "We have a blobURL"); + + server.registerPathHandler("/cross-test", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/html", false); + const body = ``; + response.bodyOutputStream.write(body, body.length); + }); + + let contentPage2 = await CookieXPCShellUtils.loadContentPage( + "http://example.org/cross-test?" + blobURL + ); + + Assert.ok(!(await result), "BlobURL should not work"); + await contentPage.close(); + await contentPage2.close(); +}); diff --git a/dom/file/tests/xpcshell.ini b/dom/file/tests/xpcshell.ini index dc9faecf8c45..2f817948d328 100644 --- a/dom/file/tests/xpcshell.ini +++ b/dom/file/tests/xpcshell.ini @@ -4,3 +4,5 @@ [test_createFile.js] [test_ipc_messagemanager_blob.js] skip-if = os == "android" +[test_agentcluster_bloburl.js] +skip-if = os == "android"