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

Unified Diff: test/snippets.js

Issue 29869555: Issue 6862 - Add tests for Snippets module events (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 30, 2018, 10:24 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: test/snippets.js
===================================================================
--- a/test/snippets.js
+++ b/test/snippets.js
@@ -83,22 +83,36 @@
["foo-2"]
);
test.done();
};
exports.testSnippetFiltersContainer = function(test)
{
+ let events = [];
+
+ function eventHandler(...args)
+ {
+ events.push([...args]);
+ }
+
function compareRules(description, domain, expectedMatches)
{
let result = Snippets.getFiltersForDomain(domain);
test.deepEqual(result.sort(), expectedMatches.sort(), description);
}
+ Snippets.on("snippets.filterAdded",
+ eventHandler.bind(null, "snippets.filterAdded"));
+ Snippets.on("snippets.filterRemoved",
+ eventHandler.bind(null, "snippets.filterRemoved"));
+ Snippets.on("snippets.filtersCleared",
+ eventHandler.bind(null, "snippets.filtersCleared"));
+
let domainFilter = Filter.fromText("example.com#$#filter1");
let subdomainFilter = Filter.fromText("www.example.com#$#filter2");
let otherDomainFilter = Filter.fromText("other.example.com#$#filter3");
Snippets.add(domainFilter);
Snippets.add(subdomainFilter);
Snippets.add(otherDomainFilter);
compareRules(
@@ -116,16 +130,25 @@
Snippets.clear();
compareRules(
"Return no filters after clearing",
"www.example.com",
[]
);
+ test.deepEqual(events, [
+ ["snippets.filterAdded", domainFilter],
+ ["snippets.filterAdded", subdomainFilter],
+ ["snippets.filterAdded", otherDomainFilter],
+ ["snippets.filterRemoved", domainFilter],
+ ["snippets.filtersCleared"]
+ ],
+ "Event log");
+
test.done();
};
exports.testScriptParsing = function(test)
{
function checkParsedScript(description, script, expectedTree)
{
let tree = parseScript(script);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld