OLD | NEW |
1 (function() | 1 (function() |
2 { | 2 { |
3 let server = null; | 3 let server = null; |
4 let frame = null; | 4 let frame = null; |
5 | 5 |
6 module("Element hiding", { | 6 module("Element hiding", { |
7 setup: function() | 7 setup: function() |
8 { | 8 { |
9 prepareFilterComponents.call(this); | 9 prepareFilterComponents.call(this); |
10 preparePrefs.call(this); | 10 preparePrefs.call(this); |
11 | 11 |
12 server = new nsHttpServer(); | 12 server = new nsHttpServer(); |
13 server.start(1234); | 13 server.start(1234); |
14 | 14 |
15 server.registerPathHandler("/test", function(metadata, response) | 15 server.registerPathHandler("/test", function(metadata, response) |
16 { | 16 { |
17 let body = '<div id="test1" class="testClass">foo</div><p id="test2" cla
ss="testClass">bar</p>'; | 17 let body = |
| 18 '<body onload="document.dispatchEvent(new CustomEvent(\'frameready\',
{bubbles: true}));">' + |
| 19 '<div id="test1" class="testClass">foo</div>' + |
| 20 '<p id="test2" class="testClass">bar</p>' + |
| 21 '</body>'; |
18 response.setStatusLine("1.1", "200", "OK"); | 22 response.setStatusLine("1.1", "200", "OK"); |
19 response.setHeader("Content-Type", "text/html; charset=utf-8"); | 23 response.setHeader("Content-Type", "text/html; charset=utf-8"); |
20 response.bodyOutputStream.write(body, body.length); | 24 response.bodyOutputStream.write(body, body.length); |
21 }); | 25 }); |
22 | 26 |
23 frame = document.createElement("iframe"); | 27 frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekee
per/there.is.only.xul", "iframe"); |
| 28 frame.setAttribute("type", "content"); |
24 frame.style.visibility = "collapse"; | 29 frame.style.visibility = "collapse"; |
25 document.body.appendChild(frame); | 30 document.body.appendChild(frame); |
26 }, | 31 }, |
27 teardown: function() | 32 teardown: function() |
28 { | 33 { |
29 restoreFilterComponents.call(this); | 34 restoreFilterComponents.call(this); |
30 restorePrefs.call(this); | 35 restorePrefs.call(this); |
31 | 36 |
32 stop(); | 37 stop(); |
33 server.stop(function() | 38 server.stop(function() |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (stage == 2) | 119 if (stage == 2) |
115 defaultMatcher.add(Filter.fromText("@@||localhost^$document")); | 120 defaultMatcher.add(Filter.fromText("@@||localhost^$document")); |
116 else if (stage == 3) | 121 else if (stage == 3) |
117 defaultMatcher.add(Filter.fromText("@@||localhost^$~document")); | 122 defaultMatcher.add(Filter.fromText("@@||localhost^$~document")); |
118 else if (stage == 4) | 123 else if (stage == 4) |
119 defaultMatcher.add(Filter.fromText("@@||localhost^$elemhide")); | 124 defaultMatcher.add(Filter.fromText("@@||localhost^$elemhide")); |
120 | 125 |
121 if (stage == 2 || stage == 4) | 126 if (stage == 2 || stage == 4) |
122 expected = ["visible", "visible"]; // Second and forth runs are whitel
isted, nothing should be hidden | 127 expected = ["visible", "visible"]; // Second and forth runs are whitel
isted, nothing should be hidden |
123 | 128 |
124 frame.onload = function() | 129 frame.addEventListener("frameready", function() |
125 { | 130 { |
126 Utils.runAsync(function() | 131 Utils.runAsync(function() |
127 { | 132 { |
128 let doc = frame.contentDocument; | 133 let doc = frame.contentDocument; |
129 equal(doc.getElementById("test1").offsetHeight > 0 ? "visible" : "hidd
en", expected[0], "First element visible"); | 134 equal(doc.getElementById("test1").offsetHeight > 0 ? "visible" : "hidd
en", expected[0], "First element visible"); |
130 equal(doc.getElementById("test2").offsetHeight > 0 ? "visible" : "hidd
en", expected[1], "Second element visible"); | 135 equal(doc.getElementById("test2").offsetHeight > 0 ? "visible" : "hidd
en", expected[1], "Second element visible"); |
131 | 136 |
132 start(); | 137 start(); |
133 }); | 138 }); |
134 }; | 139 }, false, true); |
135 frame.contentWindow.location.href = "http://localhost:1234/test"; | 140 frame.setAttribute("src", "http://localhost:1234/test"); |
136 } | 141 } |
137 FilterNotifier.addListener(listener); | 142 FilterNotifier.addListener(listener); |
138 | 143 |
139 for (let filter of filters) | 144 for (let filter of filters) |
140 ElemHide.add(Filter.fromText(filter)); | 145 ElemHide.add(Filter.fromText(filter)); |
141 ElemHide.isDirty = true; | 146 ElemHide.isDirty = true; |
142 ElemHide.apply(); | 147 ElemHide.apply(); |
143 } | 148 } |
144 | 149 |
145 let stageDescriptions = { | 150 let stageDescriptions = { |
146 1: "running without exceptions", | 151 1: "running without exceptions", |
147 2: "running with whitelisted document", | 152 2: "running with whitelisted document", |
148 3: "running with exception not applying to documents", | 153 3: "running with exception not applying to documents", |
149 4: "running with element hiding exception", | 154 4: "running with element hiding exception", |
150 }; | 155 }; |
151 | 156 |
152 for (let test = 0; test < tests.length; test++) | 157 for (let test = 0; test < tests.length; test++) |
153 { | 158 { |
154 let [filters, expected] = tests[test]; | 159 let [filters, expected] = tests[test]; |
155 for (let stage = 1; stage in stageDescriptions; stage++) | 160 for (let stage = 1; stage in stageDescriptions; stage++) |
156 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT
est.bind(null, tests[test], stage)); | 161 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT
est.bind(null, tests[test], stage)); |
157 } | 162 } |
158 })(); | 163 })(); |
OLD | NEW |