Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/tests/elemhide.js

Issue 29356283: Issue 4500 - Fix element hiding integration tests (Closed) Base URL: https://hg.adblockplus.org/adblockplustests
Patch Set: Addressed one more nit Created Oct. 7, 2016, 10:40 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/elemhide.js
===================================================================
--- a/chrome/content/tests/elemhide.js
+++ b/chrome/content/tests/elemhide.js
@@ -113,74 +113,59 @@
[["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 filterText of filters)
+ FilterStorage.addFilter(Filter.fromText(filterText));
- 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
+ // Second and forth runs are whitelisted, nothing should be hidden
+ if (stage == 2 || stage == 4)
+ expected = ["visible", "visible"];
- 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.
+ 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",
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld