Index: chrome/content/tests/elemhide.js |
=================================================================== |
--- a/chrome/content/tests/elemhide.js |
+++ b/chrome/content/tests/elemhide.js |
@@ -113,74 +113,58 @@ |
[["localhost##div#test1", "@@localhost$generichide"], ["hidden", "visible"]], |
[["~example.com##div#test1", "@@localhost$generichide"], ["visible", "visible"]], |
[["~example.com##div#test1", "@@localhost$genericblock"], ["hidden", "visible"]], |
[["~example.com,localhost##div#test1", "@@localhost$generichide"], ["hidden", "visible"]], |
]; |
function runTest([filters, expected], stage) |
{ |
- let listener = function(action) |
- { |
- if (action != "elemhideupdate") |
- return; |
- FilterNotifier.removeListener(listener); |
+ 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.
|
+ 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.
|
- if (stage == 2) |
- defaultMatcher.add(Filter.fromText("@@||localhost^$document")); |
- else if (stage == 3) |
- defaultMatcher.add(Filter.fromText("@@||localhost^$~document")); |
- else if (stage == 4) |
- defaultMatcher.add(Filter.fromText("@@||localhost^$elemhide")); |
+ if (stage == 2) |
+ FilterStorage.addFilter(Filter.fromText("@@||localhost^$document")); |
+ else if (stage == 3) |
+ FilterStorage.addFilter(Filter.fromText("@@||localhost^$~document")); |
+ else if (stage == 4) |
+ FilterStorage.addFilter(Filter.fromText("@@||localhost^$elemhide")); |
- if (stage == 2 || stage == 4) |
- expected = ["visible", "visible"]; // Second and forth runs are whitelisted, nothing should be hidden |
+ if (stage == 2 || stage == 4) |
+ expected = ["visible", "visible"]; // Second and forth runs are whitelisted, 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.
|
- frame.addEventListener("abp:frameready", function() |
+ frame.addEventListener("abp:frameready", function() |
+ { |
+ let frameScript = ` |
+ // The "load" event doesn't mean that our styles are applied - these |
+ // are only applied after a message roundtrip to parent determining |
+ // whether element hiding is enabled. Do the same roundtrip here before |
+ // 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.
|
+ addMessageListener("pong", function() |
+ { |
+ let visibility = [ |
+ content.document.getElementById("test1").offsetHeight > 0 ? "visible" : "hidden", |
+ content.document.getElementById("test2").offsetHeight > 0 ? "visible" : "hidden" |
+ ]; |
+ sendAsyncMessage("visibility", visibility); |
+ }); |
+ sendAsyncMessage("ping"); |
+ `; |
+ frame.messageManager.addMessageListener("ping", () => frame.messageManager.sendAsyncMessage("pong")); |
+ frame.messageManager.addMessageListener("visibility", (message) => |
{ |
- let frameScript = ` |
- // The "load" event doesn't mean XBL bindings are done, these will |
- // take longer to load (async messaging). Only check visibility after |
- // sending a message to parent and receiving response. |
- addMessageListener("pong", function() |
- { |
- let visibility = [ |
- content.document.getElementById("test1").offsetHeight > 0 ? "visible" : "hidden", |
- content.document.getElementById("test2").offsetHeight > 0 ? "visible" : "hidden" |
- ]; |
- sendAsyncMessage("visibility", visibility); |
- }); |
- sendAsyncMessage("ping"); |
- `; |
- frame.messageManager.addMessageListener("ping", () => frame.messageManager.sendAsyncMessage("pong")); |
- frame.messageManager.addMessageListener("visibility", (message) => |
- { |
- let visibility = message.data; |
- equal(visibility[0], expected[0], "First element visible"); |
- equal(visibility[1], expected[1], "Second element visible"); |
+ let visibility = message.data; |
+ equal(visibility[0], expected[0], "First element visible"); |
+ equal(visibility[1], expected[1], "Second element visible"); |
- start(); |
- }); |
- frame.messageManager.loadFrameScript("data:text/javascript," + encodeURIComponent(frameScript), false); |
- }, false, true); |
- frame.setAttribute("src", "http://localhost:1234/test"); |
- }; |
- FilterNotifier.addListener(listener); |
- |
- for (let filter_text of filters) |
- { |
- let filter = Filter.fromText(filter_text); |
- if (filter instanceof WhitelistFilter) |
- defaultMatcher.add(filter); |
- else |
- ElemHide.add(filter); |
- } |
- |
- ElemHide.isDirty = true; |
- ElemHide.apply(); |
+ start(); |
+ }); |
+ frame.messageManager.loadFrameScript("data:text/javascript," + encodeURIComponent(frameScript), false); |
+ }, false, true); |
+ frame.setAttribute("src", "http://localhost:1234/test"); |
} |
let stageDescriptions = { |
1: "running without exceptions", |
2: "running with whitelisted document", |
3: "running with exception not applying to documents", |
4: "running with element hiding exception", |
}; |