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); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 [["##div#test1", "@@localhost$generichide"], ["visible", "visible"]], | 111 [["##div#test1", "@@localhost$generichide"], ["visible", "visible"]], |
112 [["##div#test1", "@@localhost$genericblock"], ["hidden", "visible"]], | 112 [["##div#test1", "@@localhost$genericblock"], ["hidden", "visible"]], |
113 [["localhost##div#test1", "@@localhost$generichide"], ["hidden", "visible"]]
, | 113 [["localhost##div#test1", "@@localhost$generichide"], ["hidden", "visible"]]
, |
114 [["~example.com##div#test1", "@@localhost$generichide"], ["visible", "visibl
e"]], | 114 [["~example.com##div#test1", "@@localhost$generichide"], ["visible", "visibl
e"]], |
115 [["~example.com##div#test1", "@@localhost$genericblock"], ["hidden", "visibl
e"]], | 115 [["~example.com##div#test1", "@@localhost$genericblock"], ["hidden", "visibl
e"]], |
116 [["~example.com,localhost##div#test1", "@@localhost$generichide"], ["hidden"
, "visible"]], | 116 [["~example.com,localhost##div#test1", "@@localhost$generichide"], ["hidden"
, "visible"]], |
117 ]; | 117 ]; |
118 | 118 |
119 function runTest([filters, expected], stage) | 119 function runTest([filters, expected], stage) |
120 { | 120 { |
121 let listener = function(action) | 121 for (let filterText of filters) |
| 122 FilterStorage.addFilter(Filter.fromText(filterText)); |
| 123 |
| 124 if (stage == 2) |
| 125 FilterStorage.addFilter(Filter.fromText("@@||localhost^$document")); |
| 126 else if (stage == 3) |
| 127 FilterStorage.addFilter(Filter.fromText("@@||localhost^$~document")); |
| 128 else if (stage == 4) |
| 129 FilterStorage.addFilter(Filter.fromText("@@||localhost^$elemhide")); |
| 130 |
| 131 // Second and forth runs are whitelisted, nothing should be hidden |
| 132 if (stage == 2 || stage == 4) |
| 133 expected = ["visible", "visible"]; |
| 134 |
| 135 frame.addEventListener("abp:frameready", function() |
122 { | 136 { |
123 if (action != "elemhideupdate") | 137 let frameScript = ` |
124 return; | 138 // The "load" event doesn't mean that our styles are applied - these |
125 FilterNotifier.removeListener(listener); | 139 // are only applied after a message roundtrip to parent determining |
| 140 // whether element hiding is enabled. Do the same roundtrip here before |
| 141 // checking visibility to make sure timing is right. |
| 142 addMessageListener("pong", function() |
| 143 { |
| 144 let visibility = [ |
| 145 content.document.getElementById("test1").offsetHeight > 0 ? "visible
" : "hidden", |
| 146 content.document.getElementById("test2").offsetHeight > 0 ? "visible
" : "hidden" |
| 147 ]; |
| 148 sendAsyncMessage("visibility", visibility); |
| 149 }); |
| 150 sendAsyncMessage("ping"); |
| 151 `; |
| 152 frame.messageManager.addMessageListener("ping", () => frame.messageManager
.sendAsyncMessage("pong")); |
| 153 frame.messageManager.addMessageListener("visibility", (message) => |
| 154 { |
| 155 let visibility = message.data; |
| 156 equal(visibility[0], expected[0], "First element visible"); |
| 157 equal(visibility[1], expected[1], "Second element visible"); |
126 | 158 |
127 if (stage == 2) | 159 start(); |
128 defaultMatcher.add(Filter.fromText("@@||localhost^$document")); | 160 }); |
129 else if (stage == 3) | 161 frame.messageManager.loadFrameScript("data:text/javascript," + encodeURICo
mponent(frameScript), false); |
130 defaultMatcher.add(Filter.fromText("@@||localhost^$~document")); | 162 }, false, true); |
131 else if (stage == 4) | 163 frame.setAttribute("src", "http://localhost:1234/test"); |
132 defaultMatcher.add(Filter.fromText("@@||localhost^$elemhide")); | |
133 | |
134 if (stage == 2 || stage == 4) | |
135 expected = ["visible", "visible"]; // Second and forth runs are whitel
isted, nothing should be hidden | |
136 | |
137 frame.addEventListener("abp:frameready", function() | |
138 { | |
139 let frameScript = ` | |
140 // The "load" event doesn't mean XBL bindings are done, these will | |
141 // take longer to load (async messaging). Only check visibility after | |
142 // sending a message to parent and receiving response. | |
143 addMessageListener("pong", function() | |
144 { | |
145 let visibility = [ | |
146 content.document.getElementById("test1").offsetHeight > 0 ? "visib
le" : "hidden", | |
147 content.document.getElementById("test2").offsetHeight > 0 ? "visib
le" : "hidden" | |
148 ]; | |
149 sendAsyncMessage("visibility", visibility); | |
150 }); | |
151 sendAsyncMessage("ping"); | |
152 `; | |
153 frame.messageManager.addMessageListener("ping", () => frame.messageManag
er.sendAsyncMessage("pong")); | |
154 frame.messageManager.addMessageListener("visibility", (message) => | |
155 { | |
156 let visibility = message.data; | |
157 equal(visibility[0], expected[0], "First element visible"); | |
158 equal(visibility[1], expected[1], "Second element visible"); | |
159 | |
160 start(); | |
161 }); | |
162 frame.messageManager.loadFrameScript("data:text/javascript," + encodeURI
Component(frameScript), false); | |
163 }, false, true); | |
164 frame.setAttribute("src", "http://localhost:1234/test"); | |
165 }; | |
166 FilterNotifier.addListener(listener); | |
167 | |
168 for (let filter_text of filters) | |
169 { | |
170 let filter = Filter.fromText(filter_text); | |
171 if (filter instanceof WhitelistFilter) | |
172 defaultMatcher.add(filter); | |
173 else | |
174 ElemHide.add(filter); | |
175 } | |
176 | |
177 ElemHide.isDirty = true; | |
178 ElemHide.apply(); | |
179 } | 164 } |
180 | 165 |
181 let stageDescriptions = { | 166 let stageDescriptions = { |
182 1: "running without exceptions", | 167 1: "running without exceptions", |
183 2: "running with whitelisted document", | 168 2: "running with whitelisted document", |
184 3: "running with exception not applying to documents", | 169 3: "running with exception not applying to documents", |
185 4: "running with element hiding exception", | 170 4: "running with element hiding exception", |
186 }; | 171 }; |
187 | 172 |
188 for (let test = 0; test < tests.length; test++) | 173 for (let test = 0; test < tests.length; test++) |
189 { | 174 { |
190 let [filters, expected] = tests[test]; | 175 let [filters, expected] = tests[test]; |
191 for (let stage = 1; stage in stageDescriptions; stage++) | 176 for (let stage = 1; stage in stageDescriptions; stage++) |
192 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT
est.bind(null, tests[test], stage)); | 177 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT
est.bind(null, tests[test], stage)); |
193 } | 178 } |
194 })(); | 179 })(); |
OLD | NEW |