summaryrefslogtreecommitdiffstats
path: root/dom/presentation/tests/mochitest/test_presentation_mixed_security_contexts.html
blob: 31918a2c4082d855993f1d507478a5a198f10dc0 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE HTML>
<html>
<!-- Any copyright is dedicated to the Public Domain.
   - http://creativecommons.org/publicdomain/zero/1.0/ -->
<head>
  <meta charset="utf-8">
  <title>Test default request for B2G Presentation API at sender side</title>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1268758">Test allow-presentation sandboxing flag</a>
<iframe id="iframe" src="https://example.com/tests/dom/presentation/tests/mochitest/file_presentation_mixed_security_contexts.html"></iframe>
<script type="application/javascript;version=1.8">

"use strict";

var iframe = document.getElementById("iframe");
var readyToStart = false;
var testSetuped = false;

function setup() {
  SpecialPowers.addPermission("presentation",
                              true, { url: "https://example.com/tests/dom/presentation/tests/mochitest/file_presentation_mixed_security_contexts.html",
                                      originAttributes: {
                                        appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
                                        inIsolatedMozBrowser: false }});

  return new Promise(function(aResolve, aReject) {
    addEventListener("message", function listener(event) {
      var message = event.data;
      if (/^OK /.exec(message)) {
        ok(true, message.replace(/^OK /, ""));
      } else if (/^KO /.exec(message)) {
        ok(false, message.replace(/^KO /, ""));
      } else if (/^INFO /.exec(message)) {
        info(message.replace(/^INFO /, ""));
      } else if (/^COMMAND /.exec(message)) {
        var command = JSON.parse(message.replace(/^COMMAND /, ""));
        if (command === "ready-to-start") {
          readyToStart = true;
          startTest();
        }
      } else if (/^DONE$/.exec(message)) {
        window.removeEventListener('message', listener);
        SimpleTest.finish();
      }
    }, false);

    testSetuped = true;
    aResolve();
  });
}

iframe.onload = startTest();

function startTest() {
  if (!(testSetuped && readyToStart)) {
    return;
  }
  iframe.contentWindow.postMessage("start", "*");
}

function runTests() {
  ok(navigator.presentation, "navigator.presentation should be available.");
  setup().then(startTest);
}

SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
  {type: "presentation-device-manage", allow: false, context: document},
], function() {
  SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
                                      ["dom.presentation.controller.enabled", true],
                                      ["dom.presentation.session_transport.data_channel.enable", false]]},
                            runTests);
});

</script>
</body>
</html>