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

Unified Diff: test/elemHide.js

Issue 29342884: Issue 4055 - Test ElemHide.getSelectorsFordomain (Closed)
Patch Set: Ignore selector order Created May 23, 2016, 11:45 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 | « package.json ('k') | test/stub-modules/io.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/elemHide.js
diff --git a/test/elemHide.js b/test/elemHide.js
new file mode 100644
index 0000000000000000000000000000000000000000..f45ebb896f3bedfd79cd6d0bb3ed84c51492ccde
--- /dev/null
+++ b/test/elemHide.js
@@ -0,0 +1,133 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+GLOBAL.Ci = { };
Wladimir Palant 2016/05/23 13:23:02 Nit: We usually write that as {}, without any spac
kzar 2016/05/23 13:47:52 Done.
+GLOBAL.Cu = {
+ import: function() { }
Wladimir Palant 2016/05/23 13:23:02 Nit: eslint doesn't like that, should have proper
kzar 2016/05/23 13:47:52 Done.
+};
+
+let {ElemHide} = require("elemHide");
+let {Filter} = require("filterClasses");
+
+exports.testGetSelectorsForDomain = function(test)
+{
+ function fromText(f)
+ {
+ return (filterText) => ElemHide[f](Filter.fromText(filterText));
+ }
+ let addFilter = fromText("add");
+ let removeFilter = fromText("remove");
Wladimir Palant 2016/05/23 13:23:02 Nit: I'd rather pass in the actual function: ElemH
kzar 2016/05/23 13:47:52 Done.
+
+ function selectorsEqual(domain, selectors, specificOnly)
+ {
+ test.deepEqual(ElemHide.getSelectorsForDomain(domain, specificOnly).sort(),
kzar 2016/05/23 11:46:50 Different implementations produce the selectors in
Wladimir Palant 2016/05/23 13:23:02 Yes, I was about to comment on this but you alread
+ selectors.sort());
+ }
+
+ selectorsEqual("", []);
+
+ addFilter("~foo.example.com,example.com##foo");
+ selectorsEqual("foo.example.com", []);
+ selectorsEqual("example.com", ["foo"]);
Wladimir Palant 2016/05/23 13:23:01 How about testing bar.example.com as well, to see
kzar 2016/05/23 13:47:52 Done.
+ selectorsEqual("com", []);
+ selectorsEqual("", []);
+
+ addFilter("foo.example.com##turnip");
+ selectorsEqual("foo.example.com", ["turnip"]);
+ selectorsEqual("example.com", ["foo"]);
+ selectorsEqual("com", []);
+ selectorsEqual("", []);
+
+ addFilter("example.com#@#foo");
+ selectorsEqual("foo.example.com", ["turnip"]);
+ selectorsEqual("example.com", []);
+ selectorsEqual("com", []);
+ selectorsEqual("", []);
+
+ addFilter("com##bar");
+ selectorsEqual("foo.example.com", ["turnip", "bar"]);
+ selectorsEqual("example.com", ["bar"]);
+ selectorsEqual("com", ["bar"]);
+ selectorsEqual("", []);
+
+ addFilter("example.com#@#bar");
+ selectorsEqual("foo.example.com", ["turnip"]);
+ selectorsEqual("example.com", []);
+ selectorsEqual("com", ["bar"]);
+ selectorsEqual("", []);
+
+ removeFilter("example.com#@#foo");
+ selectorsEqual("foo.example.com", ["turnip"]);
+ selectorsEqual("example.com", ["foo"]);
+ selectorsEqual("com", ["bar"]);
+ selectorsEqual("", []);
+
+ removeFilter("example.com#@#bar");
+ selectorsEqual("foo.example.com", ["turnip", "bar"]);
+ selectorsEqual("example.com", ["foo", "bar"]);
+ selectorsEqual("com", ["bar"]);
+ selectorsEqual("", []);
+
+ addFilter("##generic");
+ selectorsEqual("foo.example.com", ["turnip", "bar", "generic"]);
+ selectorsEqual("example.com", ["foo", "bar", "generic"]);
+ selectorsEqual("com", ["bar", "generic"]);
+ selectorsEqual("", ["generic"]);
+ selectorsEqual("foo.example.com", ["turnip", "bar"], true);
+ selectorsEqual("example.com", ["foo", "bar"], true);
+ selectorsEqual("com", ["bar"], true);
+ selectorsEqual("", [], true);
+ removeFilter("##generic");
+
+ addFilter("~adblockplus.org##example");
+ selectorsEqual("adblockplus.org", []);
+ selectorsEqual("", ["example"]);
+ selectorsEqual("foo.example.com", ["turnip", "bar", "example"]);
+ selectorsEqual("foo.example.com", ["turnip", "bar"], true);
+ removeFilter("~adblockplus.org##example");
+
+ removeFilter("~foo.example.com,example.com##foo");
+ selectorsEqual("foo.example.com", ["turnip", "bar"]);
+ selectorsEqual("example.com", ["bar"]);
+ selectorsEqual("com", ["bar"]);
+ selectorsEqual("", []);
+
+ removeFilter("com##bar");
+ selectorsEqual("foo.example.com", ["turnip"]);
+ selectorsEqual("example.com", []);
+ selectorsEqual("com", []);
+ selectorsEqual("", []);
+
+ removeFilter("foo.example.com##turnip");
+ selectorsEqual("foo.example.com", []);
+ selectorsEqual("example.com", []);
+ selectorsEqual("com", []);
+ selectorsEqual("", []);
Wladimir Palant 2016/05/23 13:23:01 This does a very thorough job testing interaction
kzar 2016/05/23 13:47:52 Done.
+
+ // As a consession for performance we don't handle the case of more than one
+ // identical rule being added, then one of them removed. Ideally the final
+ // result here would be ["dupe"] instead of [].
Wladimir Palant 2016/05/23 13:23:02 This has nothing to do with performance - ElemHide
kzar 2016/05/23 13:47:52 Acknowledged.
+ addFilter("example.com##dupe");
+ addFilter("example.com##dupe");
+ selectorsEqual("example.com", ["dupe"]);
+ removeFilter("example.com##dupe");
+ selectorsEqual("example.com", []);
+
+ test.done();
+};
« no previous file with comments | « package.json ('k') | test/stub-modules/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld