summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/fetch/plugin/plugins.html
blob: b268f6d99e3230105b3557da402c96b70992e4b9 (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
<!DOCTYPE html>
<script>
  var obj, embed;

  function ok(v, msg) {
    window.opener.postMessage({status: "ok", result: !!v, message: msg}, "*");
  }

  function finish() {
    document.documentElement.removeChild(obj);
    document.documentElement.removeChild(embed);
    window.opener.postMessage({status: "done"}, "*");
  }

  function test_object() {
    obj = document.createElement("object");
    obj.setAttribute('data', "object");
    document.documentElement.appendChild(obj);
  }

  function test_embed() {
    embed = document.createElement("embed");
    embed.setAttribute('src', "embed");
    document.documentElement.appendChild(embed);
  }

  navigator.serviceWorker.addEventListener("message", function onMessage(e) {
    if (e.data.destination === "object") {
      ok(false, "<object> should not be intercepted");
    } else if (e.data.destination === "embed") {
      ok(false, "<embed> should not be intercepted");
    } else if (e.data.destination === "" && e.data.resource === "foo.txt") {
      navigator.serviceWorker.removeEventListener("message", onMessage);
      finish();
    }
  });

  test_object();
  test_embed();
  // SW will definitely intercept fetch API, use this to see if plugins are
  // intercepted before fetch().
  fetch("foo.txt");
</script>