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

Unified Diff: test/filterClasses.js

Issue 29354827: Issue 4394 - Create a filter class for element hiding emulation filters [WIP] (Closed)
Patch Set: Created Sept. 23, 2016, 4:21 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
« lib/filterClasses.js ('K') | « lib/filterListener.js ('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
@@ -15,17 +15,17 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
let {
Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
- ElemHideException, CSSPropertyFilter
+ ElemHideException, ElemHideEmulationFilter
} = require("../lib/filterClasses");
function serializeFilter(filter)
{
// Filter serialization only writes out essential properties, need to do a full serialization here
let result = [];
result.push("text=" + filter.text);
if (filter instanceof InvalidFilter)
@@ -73,19 +73,19 @@
}
}
else if (filter instanceof ElemHideBase)
{
if (filter instanceof ElemHideFilter)
result.push("type=elemhide");
else if (filter instanceof ElemHideException)
result.push("type=elemhideexception");
- else if (filter instanceof CSSPropertyFilter)
+ else if (filter instanceof ElemHideEmulationFilter)
{
- result.push("type=cssrule");
+ result.push("type=elemhideemulation");
result.push("prefix=" + (filter.selectorPrefix || ""));
result.push("regexp=" + filter.regexpString);
result.push("suffix=" + (filter.selectorSuffix || ""));
}
result.push("selectorDomain=" + (filter.selectorDomain || ""));
result.push("selector=" + filter.selector);
}
@@ -106,17 +106,17 @@
}
function addProperty(prop, value)
{
if (!(prop in hasProperty))
expected.push(prop + "=" + value);
}
- if (type == "whitelist" || type == "filterlist" || type == "elemhide" || type == "elemhideexception" || type == "cssrule")
+ if (type == "whitelist" || type == "filterlist" || type == "elemhide" || type == "elemhideexception" || type == "elemhideemulation")
{
addProperty("disabled", "false");
addProperty("lastHit", "0");
addProperty("hitCount", "0");
}
if (type == "whitelist" || type == "filterlist")
{
addProperty("contentType", 0x7FFFFFFF & ~(
@@ -128,22 +128,22 @@
addProperty("thirdParty", "null");
addProperty("domains", "");
addProperty("sitekeys", "");
}
if (type == "filterlist")
{
addProperty("collapse", "null");
}
- if (type == "elemhide" || type == "elemhideexception" || type == "cssrule")
+ if (type == "elemhide" || type == "elemhideexception" || type == "elemhideemulation")
{
addProperty("selectorDomain", "");
addProperty("domains", "");
}
- if (type == "cssrule")
+ if (type == "elemhideemulation")
{
addProperty("regexp", "");
addProperty("prefix", "");
addProperty("suffix", "");
}
}
function compareFilter(test, text, expected, postInit)
@@ -185,17 +185,17 @@
test.equal(typeof CommentFilter, "function", "typeof CommentFilter");
test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter");
test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter");
test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter");
test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase");
test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter");
test.equal(typeof ElemHideException, "function", "typeof ElemHideException");
- test.equal(typeof CSSPropertyFilter, "function", "typeof CSSPropertyFilter");
+ test.equal(typeof ElemHideEmulationFilter, "function", "typeof ElemHideEmulationFilter");
test.done();
};
exports.testComments = function(test)
{
compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]);
compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]);
@@ -209,17 +209,17 @@
compareFilter(test, "/??/", ["type=invalid", "text=/??/", "reason=filter_invalid_regexp"]);
compareFilter(test, "asd$foobar", ["type=invalid", "text=asd$foobar", "reason=filter_unknown_option"]);
compareFilter(test, "#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "reason=filter_elemhide_duplicate_id"]);
compareFilter(test, "#*", ["type=invalid", "text=#*", "reason=filter_elemhide_nocriteria"]);
function compareCSSRule(domains)
{
let filterText = domains + "##[-abp-properties='abc']";
- compareFilter(test, filterText, ["type=invalid", "text=" + filterText, "reason=filter_cssproperty_nodomain"]);
+ compareFilter(test, filterText, ["type=invalid", "text=" + filterText, "reason=filter_elemhideemulation_nodomain"]);
}
compareCSSRule("");
compareCSSRule("~foo.com");
compareCSSRule("~foo.com,~bar.com");
compareCSSRule("foo");
compareCSSRule("~foo.com,bar");
test.done();
@@ -323,23 +323,23 @@
compareFilter(test, "foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO"]);
compareFilter(test, "foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
compareFilter(test, "foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
compareFilter(test, "foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
test.done();
};
-exports.testCSSPropertyFilters = function(test)
+exports.testElemHideEmulationFilters = function(test)
Felix Dahlke 2016/09/23 16:41:59 I'll add to these tests to make sure the parsing c
{
// Check valid domain combinations
- compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=cssrule", "text=foo.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM", "regexp=abc"]);
- compareFilter(test, "foo.com,~bar.com##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "regexp=abc"]);
- compareFilter(test, "foo.com,~bar##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR", "regexp=abc"]);
- compareFilter(test, "~foo.com,bar.com##[-abp-properties='abc']", ["type=cssrule", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "selector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "regexp=abc"]);
+ compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM", "regexp=abc"]);
+ compareFilter(test, "foo.com,~bar.com##[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "regexp=abc"]);
+ compareFilter(test, "foo.com,~bar##[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR", "regexp=abc"]);
+ compareFilter(test, "~foo.com,bar.com##[-abp-properties='abc']", ["type=elemhideemulation", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "selector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "regexp=abc"]);
compareFilter(test, "##[-abp-properties='']", ["type=elemhide", "text=##[-abp-properties='']", "selector=[-abp-properties='']"]);
compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexception", "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM"]);
- compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=cssrule", "text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "selector=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "regexp=abc", "suffix= bbb"]);
- compareFilter(test, "foo.com##[-abp-properties='|background-image: url(data:*)']", ["type=cssrule", "text=foo.com##[-abp-properties='|background-image: url(data:*)']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-image: url(data:*)']", "domains=FOO.COM", "regexp=^background\\-image\\:\\ url\\(data\\:.*\\)"]);
+ compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhideemulation", "text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "selector=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "regexp=abc", "suffix= bbb"]);
+ compareFilter(test, "foo.com##[-abp-properties='|background-image: url(data:*)']", ["type=elemhideemulation", "text=foo.com##[-abp-properties='|background-image: url(data:*)']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-image: url(data:*)']", "domains=FOO.COM", "regexp=^background\\-image\\:\\ url\\(data\\:.*\\)"]);
test.done();
};
« lib/filterClasses.js ('K') | « lib/filterListener.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld