| Left: | ||
| Right: |
| 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 filter_text of filters) |
|
kzar
2016/10/07 09:42:08
Nit: We usually use camelCase for variable names i
Wladimir Palant
2016/10/07 10:41:21
Done.
| |
| 122 FilterStorage.addFilter(Filter.fromText(filter_text)); | |
|
Wladimir Palant
2016/10/07 08:35:50
Rietveld doesn't show it because of whitespace cha
kzar
2016/10/07 09:42:08
Sounds good to me, in fact I wonder why didn't do
Wladimir Palant
2016/10/07 10:16:05
Because element hiding was applying in an async fa
kzar
2016/10/07 10:19:54
Acknowledged.
| |
| 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 if (stage == 2 || stage == 4) | |
| 132 expected = ["visible", "visible"]; // Second and forth runs are whitelis ted, nothing should be hidden | |
|
kzar
2016/10/07 09:42:08
Nit: Mind moving the comment above the if statemen
Wladimir Palant
2016/10/07 10:16:05
Done.
| |
| 133 | |
| 134 frame.addEventListener("abp:frameready", function() | |
| 122 { | 135 { |
| 123 if (action != "elemhideupdate") | 136 let frameScript = ` |
| 124 return; | 137 // The "load" event doesn't mean that our styles are applied - these |
| 125 FilterNotifier.removeListener(listener); | 138 // are only applied after a message roundtrip to parent determining |
| 139 // whether element hiding is enabled. Do the same roundtrip here before | |
| 140 // checking visibility to make sure timing is right. | |
|
Wladimir Palant
2016/10/07 08:35:50
This comment changed - the reason why we need to p
kzar
2016/10/07 09:42:08
Acknowledged.
| |
| 141 addMessageListener("pong", function() | |
| 142 { | |
| 143 let visibility = [ | |
| 144 content.document.getElementById("test1").offsetHeight > 0 ? "visible " : "hidden", | |
| 145 content.document.getElementById("test2").offsetHeight > 0 ? "visible " : "hidden" | |
| 146 ]; | |
| 147 sendAsyncMessage("visibility", visibility); | |
| 148 }); | |
| 149 sendAsyncMessage("ping"); | |
| 150 `; | |
| 151 frame.messageManager.addMessageListener("ping", () => frame.messageManager .sendAsyncMessage("pong")); | |
| 152 frame.messageManager.addMessageListener("visibility", (message) => | |
| 153 { | |
| 154 let visibility = message.data; | |
| 155 equal(visibility[0], expected[0], "First element visible"); | |
| 156 equal(visibility[1], expected[1], "Second element visible"); | |
| 126 | 157 |
| 127 if (stage == 2) | 158 start(); |
| 128 defaultMatcher.add(Filter.fromText("@@||localhost^$document")); | 159 }); |
| 129 else if (stage == 3) | 160 frame.messageManager.loadFrameScript("data:text/javascript," + encodeURICo mponent(frameScript), false); |
| 130 defaultMatcher.add(Filter.fromText("@@||localhost^$~document")); | 161 }, false, true); |
| 131 else if (stage == 4) | 162 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 } | 163 } |
| 180 | 164 |
| 181 let stageDescriptions = { | 165 let stageDescriptions = { |
| 182 1: "running without exceptions", | 166 1: "running without exceptions", |
| 183 2: "running with whitelisted document", | 167 2: "running with whitelisted document", |
| 184 3: "running with exception not applying to documents", | 168 3: "running with exception not applying to documents", |
| 185 4: "running with element hiding exception", | 169 4: "running with element hiding exception", |
| 186 }; | 170 }; |
| 187 | 171 |
| 188 for (let test = 0; test < tests.length; test++) | 172 for (let test = 0; test < tests.length; test++) |
| 189 { | 173 { |
| 190 let [filters, expected] = tests[test]; | 174 let [filters, expected] = tests[test]; |
| 191 for (let stage = 1; stage in stageDescriptions; stage++) | 175 for (let stage = 1; stage in stageDescriptions; stage++) |
| 192 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT est.bind(null, tests[test], stage)); | 176 asyncTest(filters.join(", ") + " (" + stageDescriptions[stage] + ")", runT est.bind(null, tests[test], stage)); |
| 193 } | 177 } |
| 194 })(); | 178 })(); |
| OLD | NEW |