summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/mochitest/test_sandbox_fetch.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/xpconnect/tests/mochitest/test_sandbox_fetch.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/xpconnect/tests/mochitest/test_sandbox_fetch.html')
-rw-r--r--js/xpconnect/tests/mochitest/test_sandbox_fetch.html54
1 files changed, 54 insertions, 0 deletions
diff --git a/js/xpconnect/tests/mochitest/test_sandbox_fetch.html b/js/xpconnect/tests/mochitest/test_sandbox_fetch.html
new file mode 100644
index 000000000..b206efdb8
--- /dev/null
+++ b/js/xpconnect/tests/mochitest/test_sandbox_fetch.html
@@ -0,0 +1,54 @@
+<!doctype html>
+<html>
+<head>
+ <title>Fetch in JS Sandbox</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"></link>
+ <script src="test_fetch_basic.js"></script>
+</head>
+<body>
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function testHttpFetch(url) {
+ info('fetch: ' + url);
+ return fetch(new Request(url, { method: 'GET' }))
+ .then(response => {
+ is(response.status, 200, 'Response is 200');
+ is(response.url, url, 'Response URL matches');
+ });
+}
+
+function runSandboxTest(testFunc, argString) {
+ is(typeof testFunc, 'function');
+ var resolvePromise;
+ var testPromise = new Promise(r => resolvePromise = r);
+ var finishFuncName = 'finish_' + testFunc.name;
+ SpecialPowers.Cu.exportFunction(_ => resolvePromise(), sb,
+ { defineAs: finishFuncName });
+ SpecialPowers.Cu.evalInSandbox('(' + testFunc.toSource() + ')' +
+ '(' + argString + ')' +
+ '.then(' + finishFuncName + ');', sb);
+ return testPromise;
+}
+
+var origin = 'https://example.com';
+var properties = ['fetch', 'Blob', 'URL'];
+var sb = new SpecialPowers.Cu.Sandbox(origin,
+ { wantGlobalProperties: properties });
+
+sb.ok = SpecialPowers.Cu.exportFunction(ok, sb);
+sb.is = SpecialPowers.Cu.exportFunction(is, sb);
+sb.info = SpecialPowers.Cu.exportFunction(info, sb);
+
+Promise.resolve()
+ .then(_ => runSandboxTest(testHttpFetch, '"' + origin + window.location.pathname + '"'))
+ .then(_ => runSandboxTest(testAboutURL))
+ .then(_ => runSandboxTest(testDataURL))
+ .then(_ => runSandboxTest(testSameOriginBlobURL))
+ .then(_ => SimpleTest.finish());
+
+</script>
+</body>
+</html>