summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/browser_file_nonscript.js
blob: 95243c32a7431efab106298e24c45d4034331b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_fileurl_nonscript_load() {
  await SpecialPowers.pushPrefEnv({
    set: [["security.block_fileuri_script_with_wrong_mime", true]],
  });

  let file = getChromeDir(getResolvedURI(gTestPath));
  file.append("file_loads_nonscript.html");
  let uriString = Services.io.newFileURI(file).spec;

  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, uriString);
  registerCleanupFunction(async function () {
    BrowserTestUtils.removeTab(tab);
  });

  let counter = await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
    Cu.exportFunction(Assert.equal.bind(Assert), content.window, {
      defineAs: "equal",
    });
    content.window.postMessage("run", "*");

    await new Promise(resolve => {
      content.window.addEventListener("message", event => {
        if (event.data === "done") {
          resolve();
        }
      });
    });

    return content.window.wrappedJSObject.counter;
  });

  is(counter, 1, "Only one script should have run");
});