Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / mochitest / test_sandbox_fetch.html
blob3b6cffed4e87711ee4350d9f4b09b5211efbbd4a
1 <!doctype html>
2 <html>
3 <head>
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>
8 </head>
9 <body>
10 <script type="application/javascript">
12 SimpleTest.waitForExplicitFinish();
14 function testHttpFetch(url) {
15 info('fetch: ' + url);
16 return fetch(new Request(url, { method: 'GET' }))
17 .then(response => {
18 is(response.status, 200, 'Response is 200');
19 is(response.url, url, 'Response URL matches');
20 });
23 function runSandboxTest(testFunc, argString) {
24 is(typeof testFunc, 'function');
25 var resolvePromise;
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);
33 return testPromise;
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);
45 Promise.resolve()
46 .then(_ => runSandboxTest(testHttpFetch, '"' + origin + window.location.pathname + '"'))
47 .then(_ => runSandboxTest(testAboutURL))
48 .then(_ => runSandboxTest(testDataURL))
49 .then(_ => runSandboxTest(testSameOriginBlobURL))
50 .then(_ => SimpleTest.finish());
52 </script>
53 </body>
54 </html>