diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/browser/browser_xhr_sandbox.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-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 'dom/tests/browser/browser_xhr_sandbox.js')
-rw-r--r-- | dom/tests/browser/browser_xhr_sandbox.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/dom/tests/browser/browser_xhr_sandbox.js b/dom/tests/browser/browser_xhr_sandbox.js new file mode 100644 index 000000000..d80fee9f8 --- /dev/null +++ b/dom/tests/browser/browser_xhr_sandbox.js @@ -0,0 +1,50 @@ +// This code is evaluated in a sandbox courtesy of toSource(); +var sandboxCode = (function() { + let req = new XMLHttpRequest(); + req.open("GET", "http://mochi.test:8888/browser/dom/tests/browser/", true); + req.onreadystatechange = function() { + if (req.readyState === 4) { + // If we get past the problem above, we end up with a req.status of zero + // (ie, blocked due to CORS) even though we are fetching from the same + // origin as the window itself. + let result; + if (req.status != 200) { + result = "ERROR: got request status of " + req.status; + } else if (req.responseText.length == 0) { + result = "ERROR: got zero byte response text"; + } else { + result = "ok"; + } + postMessage({result: result}, "*"); + } + }; + req.send(null); +}).toSource() + "();"; + +function test() { + waitForExplicitFinish(); + let appShell = Cc["@mozilla.org/appshell/appShellService;1"] + .getService(Ci.nsIAppShellService); + let doc = appShell.hiddenDOMWindow.document; + let frame = doc.createElement("iframe"); + frame.setAttribute("type", "content"); + frame.setAttribute("src", "http://mochi.test:8888/browser/dom/tests/browser/browser_xhr_sandbox.js"); + + frame.addEventListener("load", function () { + let workerWindow = frame.contentWindow; + workerWindow.addEventListener("message", function(evt) { + is(evt.data.result, "ok", "check the sandbox code was happy"); + frame.remove(); + finish(); + }, true); + let sandbox = new Cu.Sandbox(workerWindow); + // inject some functions from the window into the sandbox. + // postMessage so the async code in the sandbox can report a result. + sandbox.importFunction(workerWindow.postMessage.bind(workerWindow), "postMessage"); + sandbox.importFunction(workerWindow.XMLHttpRequest, "XMLHttpRequest"); + Cu.evalInSandbox(sandboxCode, sandbox, "1.8"); + }, true); + + let container = doc.body ? doc.body : doc.documentElement; + container.appendChild(frame); +} |