1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 const RELATIVE_DIR = "toolkit/components/pdfjs/test/";
5 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
7 // Test js in pdf file.
8 add_task(async function test_js_sandbox() {
9 await BrowserTestUtils.withNewTab(
10 { gBrowser, url: "about:blank" },
11 async function (browser) {
12 await SpecialPowers.pushPrefEnv({
13 set: [["pdfjs.enableScripting", true]],
17 waitForPdfJSAnnotationLayer(browser, TESTROOT + "file_pdfjs_js.pdf"),
18 waitForPdfJSSandbox(browser),
21 await SpecialPowers.spawn(browser, [], async () => {
22 const { PdfSandbox } = ChromeUtils.importESModule(
23 "resource://pdf.js/PdfSandbox.sys.mjs"
26 let sandboxDestroyCount = 0;
27 const originalDestroy = PdfSandbox.prototype.destroy;
28 PdfSandbox.prototype.destroy = function () {
29 const obj = this.sandbox.eval("({})");
30 originalDestroy.apply(this, arguments);
31 sandboxDestroyCount++;
32 ok(Cu.isDeadWrapper(obj), "Sandbox must have been nuked");
35 const document = content.document;
36 const button = document.querySelector("[data-annotation-id='16R'] a");
37 button.dispatchEvent(new content.Event("click"));
39 const text = document.querySelector(`[data-element-id="15R"]`);
41 is(text.value, "test", "Text field must containt 'test' string");
43 content.addEventListener("unload", () => {
44 is(sandboxDestroyCount, 1, "Sandbox must have been destroyed");
48 await waitForPdfJSClose(browser);
49 await SpecialPowers.popPrefEnv();