docshell/test/chrome/test_allowContentRetargeting.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/test_allowContentRetargeting.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
    1.10 +  <script type="application/javascript">
    1.11 +
    1.12 +SimpleTest.waitForExplicitFinish();
    1.13 +addLoadEvent(runNextTest);
    1.14 +
    1.15 +var TEST_URL = "http://mochi.test:8888/tests/docshell/test/chrome/allowContentRetargeting.sjs";
    1.16 +
    1.17 +var Ci = Components.interfaces;
    1.18 +
    1.19 +function runNextTest() {
    1.20 +  var test = tests.shift();
    1.21 +  if (!test) {
    1.22 +    SimpleTest.finish();
    1.23 +    return;
    1.24 +  }
    1.25 +  test();
    1.26 +}
    1.27 +
    1.28 +var tests = [
    1.29 +
    1.30 +  // Set allowContentRetargeting = false, load a downloadable URL, verify the
    1.31 +  // downloadable stops loading.
    1.32 +  function basic() {
    1.33 +    var iframe = insertIframe();
    1.34 +    docshellForWindow(iframe.contentWindow).allowContentRetargeting = false;
    1.35 +    loadIframe(iframe);
    1.36 +  },
    1.37 +
    1.38 +  // Set allowContentRetargeting = false on parent docshell, load a downloadable
    1.39 +  // URL, verify the downloadable stops loading.
    1.40 +  function inherit() {
    1.41 +    var docshell = docshellForWindow(window);
    1.42 +    docshell.allowContentRetargeting = false;
    1.43 +    loadIframe(insertIframe());
    1.44 +  },
    1.45 +];
    1.46 +
    1.47 +function docshellForWindow(win) {
    1.48 +  return win.
    1.49 +         QueryInterface(Ci.nsIInterfaceRequestor).
    1.50 +         getInterface(Ci.nsIWebNavigation).
    1.51 +         QueryInterface(Ci.nsIDocShell);
    1.52 +}
    1.53 +
    1.54 +function insertIframe() {
    1.55 +  var iframe = document.createElement("iframe");
    1.56 +  document.body.appendChild(iframe);
    1.57 +  return iframe;
    1.58 +}
    1.59 +
    1.60 +function loadIframe(iframe) {
    1.61 +  iframe.setAttribute("src", TEST_URL);
    1.62 +  docshellForWindow(iframe.contentWindow).
    1.63 +    QueryInterface(Ci.nsIInterfaceRequestor).
    1.64 +    getInterface(Ci.nsIWebProgress).
    1.65 +    addProgressListener(progressListener,
    1.66 +                        Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
    1.67 +}
    1.68 +
    1.69 +var progressListener = {
    1.70 +  onStateChange: function (webProgress, req, flags, status) {
    1.71 +    if (!(flags & Ci.nsIWebProgressListener.STATE_STOP))
    1.72 +      return;
    1.73 +    is(Components.isSuccessCode(status), false,
    1.74 +       "Downloadable should have failed to load");
    1.75 +    document.querySelector("iframe").remove();
    1.76 +    runNextTest();
    1.77 +  },
    1.78 +
    1.79 +  QueryInterface: function (iid) {
    1.80 +    var iids = [
    1.81 +      Ci.nsIWebProgressListener,
    1.82 +      Ci.nsISupportsWeakReference,
    1.83 +      Ci.nsISupports,
    1.84 +    ];
    1.85 +    if (iids.some(function (i) { return iid.equals(i); }))
    1.86 +      return this;
    1.87 +    throw Components.results.NS_ERROR_NO_INTERFACE;
    1.88 +  },
    1.89 +};
    1.90 +
    1.91 +  </script>
    1.92 +</head>
    1.93 +<body>
    1.94 +<p id="display">
    1.95 +</p>
    1.96 +</body>
    1.97 +</html>

mercurial