|
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"> |
|
8 |
|
9 SimpleTest.waitForExplicitFinish(); |
|
10 addLoadEvent(runNextTest); |
|
11 |
|
12 var TEST_URL = "http://mochi.test:8888/tests/docshell/test/chrome/allowContentRetargeting.sjs"; |
|
13 |
|
14 var Ci = Components.interfaces; |
|
15 |
|
16 function runNextTest() { |
|
17 var test = tests.shift(); |
|
18 if (!test) { |
|
19 SimpleTest.finish(); |
|
20 return; |
|
21 } |
|
22 test(); |
|
23 } |
|
24 |
|
25 var tests = [ |
|
26 |
|
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 }, |
|
34 |
|
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 ]; |
|
43 |
|
44 function docshellForWindow(win) { |
|
45 return win. |
|
46 QueryInterface(Ci.nsIInterfaceRequestor). |
|
47 getInterface(Ci.nsIWebNavigation). |
|
48 QueryInterface(Ci.nsIDocShell); |
|
49 } |
|
50 |
|
51 function insertIframe() { |
|
52 var iframe = document.createElement("iframe"); |
|
53 document.body.appendChild(iframe); |
|
54 return iframe; |
|
55 } |
|
56 |
|
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 } |
|
65 |
|
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 }, |
|
75 |
|
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 }; |
|
87 |
|
88 </script> |
|
89 </head> |
|
90 <body> |
|
91 <p id="display"> |
|
92 </p> |
|
93 </body> |
|
94 </html> |