summaryrefslogtreecommitdiffstats
path: root/toolkit/components/webextensions/test/mochitest/file_permission_xhr.html
blob: 22a55f90d2cfc1ec4ea838cf0d264029030a0fa4 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE HTML>

<html>
<head>
<meta charset="utf-8">
</head>
<body>

<script>
"use strict";

/* globals privilegedFetch, privilegedXHR */
/* eslint-disable mozilla/balanced-listeners */

addEventListener("message", function rcv(event) {
  removeEventListener("message", rcv, false);

  function assertTrue(condition, description) {
    postMessage({msg: "assertTrue", condition, description}, "*");
  }

  function passListener() {
    assertTrue(true, "Content XHR has no elevated privileges");
    postMessage({"msg": "finish"}, "*");
  }

  function failListener() {
    assertTrue(false, "Content XHR has no elevated privileges");
    postMessage({"msg": "finish"}, "*");
  }

  try {
    new privilegedXHR();
    assertTrue(false, "Content should not have access to privileged XHR constructor");
  } catch (e) {
    assertTrue(/Permission denied to access object/.test(e), "Content should not have access to privileged XHR constructor");
  }

  try {
    new privilegedFetch();
    assertTrue(false, "Content should not have access to privileged fetch() constructor");
  } catch (e) {
    assertTrue(/Permission denied to access object/.test(e), "Content should not have access to privileged fetch() constructor");
  }

  let req = new XMLHttpRequest();
  req.addEventListener("load", failListener);
  req.addEventListener("error", passListener);
  req.open("GET", "http://example.org/example.txt");
  req.send();
}, false);
</script>

</body>
</html>