4 <title>Fetch in JS Sandbox
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"></link>
7 <script src=
"test_fetch_basic.js"></script>
10 <script type=
"application/javascript">
12 SimpleTest.waitForExplicitFinish();
14 function testHttpFetch(url) {
15 info('fetch: ' + url);
16 return fetch(new Request(url, { method: 'GET' }))
18 is(response.status,
200, 'Response is
200');
19 is(response.url, url, 'Response URL matches');
23 function runSandboxTest(testFunc, argString) {
24 is(typeof testFunc, 'function');
26 var testPromise = new Promise(r =
> resolvePromise = r);
27 var finishFuncName = 'finish_' + testFunc.name;
28 SpecialPowers.Cu.exportFunction(_ =
> resolvePromise(), sb,
29 { defineAs: finishFuncName });
30 SpecialPowers.Cu.evalInSandbox('(' + testFunc.toString() + ')' +
31 '(' + argString + ')' +
32 '.then(' + finishFuncName + ');', sb);
36 var origin = document.location.origin;
37 var properties = ['fetch', 'Blob', 'URL'];
38 var sb = new SpecialPowers.Cu.Sandbox(origin,
39 { wantGlobalProperties: properties });
41 sb.ok = SpecialPowers.Cu.exportFunction(ok, sb);
42 sb.is = SpecialPowers.Cu.exportFunction(is, sb);
43 sb.info = SpecialPowers.Cu.exportFunction(info, sb);
46 .then(_ =
> runSandboxTest(testHttpFetch, '
"' + origin + window.location.pathname + '"'))
47 .then(_ =
> runSandboxTest(testAboutURL))
48 .then(_ =
> runSandboxTest(testDataURL))
49 .then(_ =
> runSandboxTest(testSameOriginBlobURL))
50 .then(_ =
> SimpleTest.finish());