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

Unified Diff: test/filterClasses.js

Issue 29574665: Issue 5159 - Expose collapse property for BlockingFilter (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Fix test Created Nov. 21, 2017, 5:42 p.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 | « compiled/filter/RegExpFilter.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/filterClasses.js
===================================================================
--- a/test/filterClasses.js
+++ b/test/filterClasses.js
@@ -43,42 +43,44 @@
} = sandboxedRequire("../lib/filterClasses")
);
({FilterNotifier} = sandboxedRequire("../lib/filterNotifier"));
callback();
};
exports.testFromText = function(test)
{
+ // fields are:
+ // text, type, typeName, collapse (optional, BlockingFilter only)
let tests = [
["!asdf", CommentFilter, "comment"],
- ["asdf", BlockingFilter, "blocking"],
- ["asdf$image,~collapse", BlockingFilter, "blocking"],
- ["/asdf/", BlockingFilter, "blocking"],
+ ["asdf", BlockingFilter, "blocking", 1],
+ ["asdf$image,~collapse", BlockingFilter, "blocking", 0],
+ ["/asdf/", BlockingFilter, "blocking", 1],
["/asdf??+/", InvalidFilter, "invalid"],
["@@asdf", WhitelistFilter, "whitelist"],
["@@asdf$image,~collapse", WhitelistFilter, "whitelist"],
["@@/asdf/", WhitelistFilter, "whitelist"],
["@@/asdf??+/", InvalidFilter, "invalid"],
["##asdf", ElemHideFilter, "elemhide"],
["#@#asdf", ElemHideException, "elemhideexception"],
["foobar##asdf", ElemHideFilter, "elemhide"],
["foobar#@#asdf", ElemHideException, "elemhideexception"],
["foobar##a", ElemHideFilter, "elemhide"],
["foobar#@#a", ElemHideException, "elemhideexception"],
- ["foobar#asdf", BlockingFilter, "blocking"],
- ["foobar|foobas##asdf", BlockingFilter, "blocking"],
+ ["foobar#asdf", BlockingFilter, "blocking", 1],
+ ["foobar|foobas##asdf", BlockingFilter, "blocking", 1],
["foobar##asdf{asdf}", ElemHideFilter, "elemhide"],
- ["foobar##", BlockingFilter, "blocking"],
- ["foobar#@#", BlockingFilter, "blocking"],
+ ["foobar##", BlockingFilter, "blocking", 1],
+ ["foobar#@#", BlockingFilter, "blocking", 1],
["asdf$foobar", InvalidFilter, "invalid"],
["asdf$image,foobar", InvalidFilter, "invalid"],
- ["asdf$image=foobar", BlockingFilter, "blocking"],
- ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking"],
+ ["asdf$image=foobar", BlockingFilter, "blocking", 1],
+ ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0],
["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"],
["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexception"],
["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter, "elemhideemulation"],
["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexception"],
["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invalid"],
["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexception"],
["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidFilter, "invalid"],
@@ -89,23 +91,27 @@
["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexception"],
["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "elemhideemulation"],
["example.com#@#[-abp-properties='something']", ElemHideException, "elemhideexception"],
["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "elemhideemulation"],
["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhideexception"],
["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "elemhideemulation"],
["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhideexception"]
];
- for (let [text, type, typeName] of tests)
+ for (let [text, type, typeName, collapse] of tests)
{
let filter = Filter.fromText(text);
test.ok(filter instanceof Filter, "Got filter for " + text);
test.equal(filter.text, text, "Correct filter text for " + text);
test.ok(filter instanceof type, "Correct filter type for " + text);
test.equal(filter.type, typeName, "Type name for " + text + " is " + typeName);
+ if (filter instanceof BlockingFilter)
+ test.equal(filter.collapse, collapse);
+ else
+ test.equal(filter.collapse, undefined);
if (type == InvalidFilter)
test.ok(filter.reason, "Invalid filter " + text + " has a reason set");
filter.delete();
}
test.done();
};
exports.testClassHierarchy = function(test)
@@ -230,27 +236,29 @@
test.done();
};
exports.testSerialize = function(test)
{
// Comment
let filter = Filter.fromText("! serialize");
test.equal(filter.serialize(), "[Filter]\ntext=! serialize\n");
+ test.equal(filter.collapse, undefined);
filter.delete();
// Blocking filter
filter = Filter.fromText("serialize");
test.equal(filter.serialize(), "[Filter]\ntext=serialize\n");
filter.disabled = true;
test.equal(filter.serialize(), "[Filter]\ntext=serialize\ndisabled=true\n");
filter.disabled = false;
filter.hitCount = 10;
filter.lastHit = 12;
test.equal(filter.serialize(), "[Filter]\ntext=serialize\nhitCount=10\nlastHit=12\n");
+ test.ok(filter.collapse);
filter.delete();
// Invalid filter
filter = Filter.fromText("serialize$foobar");
test.equal(filter.serialize(), "[Filter]\ntext=serialize$foobar\n");
filter.delete();
// Element hiding filter
« no previous file with comments | « compiled/filter/RegExpFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld