tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_allowContentRetargeting.html (2032B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
      7  <script type="application/javascript">
      8 
      9 SimpleTest.waitForExplicitFinish();
     10 addLoadEvent(runNextTest);
     11 
     12 var TEST_URL = "http://mochi.test:8888/tests/docshell/test/chrome/allowContentRetargeting.sjs";
     13 
     14 function runNextTest() {
     15  var test = tests.shift();
     16  if (!test) {
     17    SimpleTest.finish();
     18    return;
     19  }
     20  test();
     21 }
     22 
     23 var tests = [
     24 
     25  // Set allowContentRetargeting = false, load a downloadable URL, verify the
     26  // downloadable stops loading.
     27  function basic() {
     28    var iframe = insertIframe();
     29    iframe.contentWindow.docShell.allowContentRetargeting = false;
     30    loadIframe(iframe);
     31  },
     32 
     33  // Set allowContentRetargeting = false on parent docshell, load a downloadable
     34  // URL, verify the downloadable stops loading.
     35  function inherit() {
     36    var docshell = window.docShell;
     37    docshell.allowContentRetargeting = false;
     38    loadIframe(insertIframe());
     39  },
     40 ];
     41 
     42 function insertIframe() {
     43  var iframe = document.createElement("iframe");
     44  document.body.appendChild(iframe);
     45  return iframe;
     46 }
     47 
     48 function loadIframe(iframe) {
     49  iframe.setAttribute("src", TEST_URL);
     50  iframe.contentWindow.docShell.
     51    QueryInterface(Ci.nsIInterfaceRequestor).
     52    getInterface(Ci.nsIWebProgress).
     53    addProgressListener(progressListener,
     54                        Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
     55 }
     56 
     57 var progressListener = {
     58  onStateChange(webProgress, req, flags, status) {
     59    if (!(flags & Ci.nsIWebProgressListener.STATE_STOP))
     60      return;
     61    is(Components.isSuccessCode(status), false,
     62       "Downloadable should have failed to load");
     63    document.querySelector("iframe").remove();
     64    runNextTest();
     65  },
     66 
     67  QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener", "nsISupportsWeakReference"]),
     68 };
     69 
     70  </script>
     71 </head>
     72 <body>
     73 <p id="display">
     74 </p>
     75 </body>
     76 </html>