docshell/test/chrome/test_allowContentRetargeting.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial