summaryrefslogtreecommitdiffstats
path: root/dom/downloads/tests/test_downloads_navigator_object.html
blob: 1c38388b71357e87d8cd267c026df62797a8e7d7 (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
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=938023
-->
<head>
  <title>Test for Bug 938023 Downloads API</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=938023">Mozilla Bug 938023</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript;version=1.7">

SimpleTest.waitForExplicitFinish();

var index = -1;

function next() {
  index += 1;
  if (index >= steps.length) {
    ok(false, "Shouldn't get here!");
    return;
  }
  try {
    steps[index]();
  } catch(ex) {
    ok(false, "Caught exception", ex);
  }
}

var steps = [
  // Start by setting the pref to true.
  function() {
    SpecialPowers.pushPrefEnv({
      set: [["dom.mozDownloads.enabled", true]]
    }, next);
  },

  function() {
    SpecialPowers.pushPermissions([
      {type: "downloads", allow: 0, context: document}
    ], function() {
      is(frames[0].navigator.mozDownloadManager, null, "navigator.mozDownloadManager is null when the page doesn't have permissions");
      next();
    });
  },

  function() {
    SpecialPowers.pushPrefEnv({
      set: [["dom.mozDownloads.enabled", false]]
    }, function() {
      is(navigator.mozDownloadManager, undefined, "navigator.mozDownloadManager is undefined");
      next();
    });
  },

  function() {
    SimpleTest.finish();
  }
];

next();

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