diff options
Diffstat (limited to 'toolkit/components/pdfjs/test/browser_pdfjs_js.js')
-rw-r--r-- | toolkit/components/pdfjs/test/browser_pdfjs_js.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/toolkit/components/pdfjs/test/browser_pdfjs_js.js b/toolkit/components/pdfjs/test/browser_pdfjs_js.js new file mode 100644 index 0000000000..19500a5b1f --- /dev/null +++ b/toolkit/components/pdfjs/test/browser_pdfjs_js.js @@ -0,0 +1,49 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const RELATIVE_DIR = "toolkit/components/pdfjs/test/"; +const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR; + +// Test js in pdf file. +add_task(async function test_js_sandbox() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:blank" }, + async function(browser) { + await SpecialPowers.pushPrefEnv({ + set: [["pdfjs.enableScripting", true]], + }); + + await Promise.all([ + waitForPdfJSAnnotationLayer(browser, TESTROOT + "file_pdfjs_js.pdf"), + waitForPdfJSSandbox(browser), + ]); + + await SpecialPowers.spawn(browser, [], async () => { + const { PdfSandbox } = ChromeUtils.import( + "resource://pdf.js/PdfSandbox.jsm" + ); + + let sandboxDestroyCount = 0; + const originalDestroy = PdfSandbox.prototype.destroy; + PdfSandbox.prototype.destroy = function() { + const obj = this.sandbox.eval("({})"); + originalDestroy.apply(this, arguments); + sandboxDestroyCount++; + ok(Cu.isDeadWrapper(obj), "Sandbox must have been nuked"); + }; + + const document = content.document; + const button = document.querySelector("[data-annotation-id='16R'] a"); + button.dispatchEvent(new content.Event("click")); + + const text = document.querySelector(`[data-element-id="15R"]`); + + is(text.value, "test", "Text field must containt 'test' string"); + + content.addEventListener("unload", () => { + is(sandboxDestroyCount, 1, "Sandbox must have been destroyed"); + }); + }); + } + ); +}); |