docshell/test/chrome/test_allowContentRetargeting.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <script type="application/javascript" 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">
     9 SimpleTest.waitForExplicitFinish();
    10 addLoadEvent(runNextTest);
    12 var TEST_URL = "http://mochi.test:8888/tests/docshell/test/chrome/allowContentRetargeting.sjs";
    14 var Ci = Components.interfaces;
    16 function runNextTest() {
    17   var test = tests.shift();
    18   if (!test) {
    19     SimpleTest.finish();
    20     return;
    21   }
    22   test();
    23 }
    25 var tests = [
    27   // Set allowContentRetargeting = false, load a downloadable URL, verify the
    28   // downloadable stops loading.
    29   function basic() {
    30     var iframe = insertIframe();
    31     docshellForWindow(iframe.contentWindow).allowContentRetargeting = false;
    32     loadIframe(iframe);
    33   },
    35   // Set allowContentRetargeting = false on parent docshell, load a downloadable
    36   // URL, verify the downloadable stops loading.
    37   function inherit() {
    38     var docshell = docshellForWindow(window);
    39     docshell.allowContentRetargeting = false;
    40     loadIframe(insertIframe());
    41   },
    42 ];
    44 function docshellForWindow(win) {
    45   return win.
    46          QueryInterface(Ci.nsIInterfaceRequestor).
    47          getInterface(Ci.nsIWebNavigation).
    48          QueryInterface(Ci.nsIDocShell);
    49 }
    51 function insertIframe() {
    52   var iframe = document.createElement("iframe");
    53   document.body.appendChild(iframe);
    54   return iframe;
    55 }
    57 function loadIframe(iframe) {
    58   iframe.setAttribute("src", TEST_URL);
    59   docshellForWindow(iframe.contentWindow).
    60     QueryInterface(Ci.nsIInterfaceRequestor).
    61     getInterface(Ci.nsIWebProgress).
    62     addProgressListener(progressListener,
    63                         Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
    64 }
    66 var progressListener = {
    67   onStateChange: function (webProgress, req, flags, status) {
    68     if (!(flags & Ci.nsIWebProgressListener.STATE_STOP))
    69       return;
    70     is(Components.isSuccessCode(status), false,
    71        "Downloadable should have failed to load");
    72     document.querySelector("iframe").remove();
    73     runNextTest();
    74   },
    76   QueryInterface: function (iid) {
    77     var iids = [
    78       Ci.nsIWebProgressListener,
    79       Ci.nsISupportsWeakReference,
    80       Ci.nsISupports,
    81     ];
    82     if (iids.some(function (i) { return iid.equals(i); }))
    83       return this;
    84     throw Components.results.NS_ERROR_NO_INTERFACE;
    85   },
    86 };
    88   </script>
    89 </head>
    90 <body>
    91 <p id="display">
    92 </p>
    93 </body>
    94 </html>

mercurial