summaryrefslogtreecommitdiffstats
path: root/docshell/test/chrome/test_allowContentRetargeting.html
blob: 58e838ca0114af24b6c8933d4c8cd89e5506a244 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

SimpleTest.waitForExplicitFinish();
addLoadEvent(runNextTest);

var TEST_URL = "http://mochi.test:8888/tests/docshell/test/chrome/allowContentRetargeting.sjs";

var Ci = Components.interfaces;

function runNextTest() {
  var test = tests.shift();
  if (!test) {
    SimpleTest.finish();
    return;
  }
  test();
}

var tests = [

  // Set allowContentRetargeting = false, load a downloadable URL, verify the
  // downloadable stops loading.
  function basic() {
    var iframe = insertIframe();
    docshellForWindow(iframe.contentWindow).allowContentRetargeting = false;
    loadIframe(iframe);
  },

  // Set allowContentRetargeting = false on parent docshell, load a downloadable
  // URL, verify the downloadable stops loading.
  function inherit() {
    var docshell = docshellForWindow(window);
    docshell.allowContentRetargeting = false;
    loadIframe(insertIframe());
  },
];

function docshellForWindow(win) {
  return win.
         QueryInterface(Ci.nsIInterfaceRequestor).
         getInterface(Ci.nsIWebNavigation).
         QueryInterface(Ci.nsIDocShell);
}

function insertIframe() {
  var iframe = document.createElement("iframe");
  document.body.appendChild(iframe);
  return iframe;
}

function loadIframe(iframe) {
  iframe.setAttribute("src", TEST_URL);
  docshellForWindow(iframe.contentWindow).
    QueryInterface(Ci.nsIInterfaceRequestor).
    getInterface(Ci.nsIWebProgress).
    addProgressListener(progressListener,
                        Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
}

var progressListener = {
  onStateChange: function (webProgress, req, flags, status) {
    if (!(flags & Ci.nsIWebProgressListener.STATE_STOP))
      return;
    is(Components.isSuccessCode(status), false,
       "Downloadable should have failed to load");
    document.querySelector("iframe").remove();
    runNextTest();
  },

  QueryInterface: function (iid) {
    var iids = [
      Ci.nsIWebProgressListener,
      Ci.nsISupportsWeakReference,
      Ci.nsISupports,
    ];
    if (iids.some(function (i) { return iid.equals(i); }))
      return this;
    throw Components.results.NS_ERROR_NO_INTERFACE;
  },
};

  </script>
</head>
<body>
<p id="display">
</p>
</body>
</html>