|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 let tab = gBrowser.selectedTab = gBrowser.addTab(); |
|
8 registerCleanupFunction(function () { |
|
9 gBrowser.removeTab(tab); |
|
10 }); |
|
11 |
|
12 let browser = tab.linkedBrowser; |
|
13 browser.stop(); // stop the about:blank load |
|
14 |
|
15 let writeDomainURL = encodeURI("data:text/html,<script>document.write(document.domain);</script>"); |
|
16 let tests = [ |
|
17 { |
|
18 name: "view background image", |
|
19 url: "http://mochi.test:8888/", |
|
20 go: function (cb) { |
|
21 let contentBody = browser.contentDocument.body; |
|
22 contentBody.style.backgroundImage = "url('" + writeDomainURL + "')"; |
|
23 doOnLoad(function () { |
|
24 let domain = browser.contentDocument.body.textContent; |
|
25 is(domain, "", "no domain was inherited for view background image"); |
|
26 cb(); |
|
27 }); |
|
28 |
|
29 let contextMenu = initContextMenu(contentBody); |
|
30 contextMenu.viewBGImage(); |
|
31 } |
|
32 }, |
|
33 { |
|
34 name: "view image", |
|
35 url: "http://mochi.test:8888/", |
|
36 go: function (cb) { |
|
37 doOnLoad(function () { |
|
38 let domain = browser.contentDocument.body.textContent; |
|
39 is(domain, "", "no domain was inherited for view image"); |
|
40 cb(); |
|
41 }); |
|
42 |
|
43 let doc = browser.contentDocument; |
|
44 let img = doc.createElement("img"); |
|
45 img.setAttribute("src", writeDomainURL); |
|
46 doc.body.appendChild(img); |
|
47 |
|
48 let contextMenu = initContextMenu(img); |
|
49 contextMenu.viewMedia(); |
|
50 } |
|
51 }, |
|
52 { |
|
53 name: "show only this frame", |
|
54 url: "http://mochi.test:8888/", |
|
55 go: function (cb) { |
|
56 doOnLoad(function () { |
|
57 let domain = browser.contentDocument.body.textContent; |
|
58 is(domain, "", "no domain was inherited for 'show only this frame'"); |
|
59 cb(); |
|
60 }); |
|
61 |
|
62 let doc = browser.contentDocument; |
|
63 let iframe = doc.createElement("iframe"); |
|
64 iframe.setAttribute("src", writeDomainURL); |
|
65 doc.body.appendChild(iframe); |
|
66 |
|
67 iframe.addEventListener("load", function onload() { |
|
68 let contextMenu = initContextMenu(iframe.contentDocument.body); |
|
69 contextMenu.showOnlyThisFrame(); |
|
70 }, false); |
|
71 } |
|
72 } |
|
73 ]; |
|
74 |
|
75 function doOnLoad(cb) { |
|
76 browser.addEventListener("load", function onLoad(e) { |
|
77 if (e.target != browser.contentDocument) |
|
78 return; |
|
79 browser.removeEventListener("load", onLoad, true); |
|
80 cb(); |
|
81 }, true); |
|
82 } |
|
83 |
|
84 function doNext() { |
|
85 let test = tests.shift(); |
|
86 if (test) { |
|
87 info("Running test: " + test.name); |
|
88 doOnLoad(function () { |
|
89 test.go(function () { |
|
90 executeSoon(doNext); |
|
91 }); |
|
92 }); |
|
93 browser.contentDocument.location = test.url; |
|
94 } else { |
|
95 executeSoon(finish); |
|
96 } |
|
97 } |
|
98 |
|
99 doNext(); |
|
100 } |
|
101 |
|
102 function initContextMenu(aNode) { |
|
103 document.popupNode = aNode; |
|
104 let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); |
|
105 let contextMenu = new nsContextMenu(contentAreaContextMenu); |
|
106 return contextMenu; |
|
107 } |