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

Unified Diff: test/domainRestrictions.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created March 7, 2019, 1:14 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 | « test/caching.js ('k') | test/elemHide.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/domainRestrictions.js
===================================================================
--- a/test/domainRestrictions.js
+++ b/test/domainRestrictions.js
@@ -12,202 +12,197 @@
* 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";
+const assert = require("assert");
const {createSandbox} = require("./_common");
let Filter = null;
-exports.setUp = function(callback)
-{
- let sandboxedRequire = createSandbox();
- (
- {Filter} = sandboxedRequire("../lib/filterClasses")
- );
-
- callback();
-};
-
-function testActive(test, text, domain, expectedActive, expectedOnlyDomain)
-{
- let filter = Filter.fromText(text);
- test.equal(filter.isActiveOnDomain(domain), expectedActive,
- text + " active on " + domain);
- test.equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain,
- text + " only active on " + domain);
-}
-
-exports.testUnrestrictedBlockingFilters = function(test)
-{
- testActive(test, "foo", null, true, false);
- testActive(test, "foo", "com", true, false);
- testActive(test, "foo", "example.com", true, false);
- testActive(test, "foo", "example.com.", true, false);
- testActive(test, "foo", "foo.example.com", true, false);
- testActive(test, "foo", "mple.com", true, false);
-
- test.done();
-};
-
-exports.testUnrestrictedHidingRules = function(test)
-{
- testActive(test, "##foo", null, true, false);
- testActive(test, "##foo", "com", true, false);
- testActive(test, "##foo", "example.com", true, false);
- testActive(test, "##foo", "example.com.", true, false);
- testActive(test, "##foo", "foo.example.com", true, false);
- testActive(test, "##foo", "mple.com", true, false);
-
- test.done();
-};
-
-exports.testDomainRestrictedBlockingFilters = function(test)
+describe("Domain Restrictions", () =>
{
- testActive(test, "foo$domain=example.com", null, false, false);
- testActive(test, "foo$domain=example.com", "com", false, true);
- testActive(test, "foo$domain=example.com", "example.com", true, true);
- testActive(test, "foo$domain=example.com", "example.com.", true, true);
- testActive(test, "foo$domain=example.com.", "example.com", false, false);
- testActive(test, "foo$domain=example.com.", "example.com.", false, false);
- testActive(test, "foo$domain=example.com", "foo.example.com", true, false);
- testActive(test, "foo$domain=example.com", "mple.com", false, false);
+ beforeEach(() =>
+ {
+ let sandboxedRequire = createSandbox();
+ (
+ {Filter} = sandboxedRequire("../lib/filterClasses")
+ );
+ });
+
+ function testActive(text, domain, expectedActive, expectedOnlyDomain)
+ {
+ let filter = Filter.fromText(text);
+ assert.equal(filter.isActiveOnDomain(domain), expectedActive,
+ text + " active on " + domain);
+ assert.equal(filter.isActiveOnlyOnDomain(domain), expectedOnlyDomain,
+ text + " only active on " + domain);
+ }
- test.done();
-};
+ describe("Unrestricted", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo", null, true, false);
+ testActive("foo", "com", true, false);
+ testActive("foo", "example.com", true, false);
+ testActive("foo", "example.com.", true, false);
+ testActive("foo", "foo.example.com", true, false);
+ testActive("foo", "mple.com", true, false);
+ });
-exports.testDomainRestrictedHidingRules = function(test)
-{
- testActive(test, "example.com##foo", null, false, false);
- testActive(test, "example.com##foo", "com", false, true);
- testActive(test, "example.com##foo", "example.com", true, true);
- testActive(test, "example.com##foo", "example.com.", true, true);
- testActive(test, "example.com.##foo", "example.com", false, false);
- testActive(test, "example.com.##foo", "example.com.", false, false);
- testActive(test, "example.com##foo", "foo.example.com", true, false);
- testActive(test, "example.com##foo", "mple.com", false, false);
+ it("Hiding Rules", () =>
+ {
+ testActive("##foo", null, true, false);
+ testActive("##foo", "com", true, false);
+ testActive("##foo", "example.com", true, false);
+ testActive("##foo", "example.com.", true, false);
+ testActive("##foo", "foo.example.com", true, false);
+ testActive("##foo", "mple.com", true, false);
+ });
+ });
- test.done();
-};
-
-exports.testBlockingFiltersRestrictedToDomainAndItsSubdomain = function(test)
-{
- testActive(test, "foo$domain=example.com|foo.example.com", null, false, false);
- testActive(test, "foo$domain=example.com|foo.example.com", "com", false, true);
- testActive(test, "foo$domain=example.com|foo.example.com", "example.com", true, true);
- testActive(test, "foo$domain=example.com|foo.example.com", "example.com.", true, true);
- testActive(test, "foo$domain=example.com|foo.example.com", "foo.example.com", true, false);
- testActive(test, "foo$domain=example.com|foo.example.com", "mple.com", false, false);
+ describe("Domain Restricted", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo$domain=example.com", null, false, false);
+ testActive("foo$domain=example.com", "com", false, true);
+ testActive("foo$domain=example.com", "example.com", true, true);
+ testActive("foo$domain=example.com", "example.com.", true, true);
+ testActive("foo$domain=example.com.", "example.com", false, false);
+ testActive("foo$domain=example.com.", "example.com.", false, false);
+ testActive("foo$domain=example.com", "foo.example.com", true, false);
+ testActive("foo$domain=example.com", "mple.com", false, false);
+ });
- test.done();
-};
+ it("Hiding Rules", () =>
+ {
+ testActive("example.com##foo", null, false, false);
+ testActive("example.com##foo", "com", false, true);
+ testActive("example.com##foo", "example.com", true, true);
+ testActive("example.com##foo", "example.com.", true, true);
+ testActive("example.com.##foo", "example.com", false, false);
+ testActive("example.com.##foo", "example.com.", false, false);
+ testActive("example.com##foo", "foo.example.com", true, false);
+ testActive("example.com##foo", "mple.com", false, false);
+ });
+ });
-exports.testHidingRulesRestrictedToDomainAndItsSubdomain = function(test)
-{
- testActive(test, "example.com,foo.example.com##foo", null, false, false);
- testActive(test, "example.com,foo.example.com##foo", "com", false, true);
- testActive(test, "example.com,foo.example.com##foo", "example.com", true, true);
- testActive(test, "example.com,foo.example.com##foo", "example.com.", true, true);
- testActive(test, "example.com,foo.example.com##foo", "foo.example.com", true, false);
- testActive(test, "example.com,foo.example.com##foo", "mple.com", false, false);
+ describe("Restricted to Domain and its Subdomain", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo$domain=example.com|foo.example.com", null, false, false);
+ testActive("foo$domain=example.com|foo.example.com", "com", false, true);
+ testActive("foo$domain=example.com|foo.example.com", "example.com", true, true);
+ testActive("foo$domain=example.com|foo.example.com", "example.com.", true, true);
+ testActive("foo$domain=example.com|foo.example.com", "foo.example.com", true, false);
+ testActive("foo$domain=example.com|foo.example.com", "mple.com", false, false);
+ });
- test.done();
-};
+ it("Hiding Rules", () =>
+ {
+ testActive("example.com,foo.example.com##foo", null, false, false);
+ testActive("example.com,foo.example.com##foo", "com", false, true);
+ testActive("example.com,foo.example.com##foo", "example.com", true, true);
+ testActive("example.com,foo.example.com##foo", "example.com.", true, true);
+ testActive("example.com,foo.example.com##foo", "foo.example.com", true, false);
+ testActive("example.com,foo.example.com##foo", "mple.com", false, false);
+ });
+ });
-exports.testBlockingFiltersWithExceptionForASubdomain = function(test)
-{
- testActive(test, "foo$domain=~foo.example.com", null, true, false);
- testActive(test, "foo$domain=~foo.example.com", "com", true, false);
- testActive(test, "foo$domain=~foo.example.com", "example.com", true, false);
- testActive(test, "foo$domain=~foo.example.com", "example.com.", true, false);
- testActive(test, "foo$domain=~foo.example.com", "foo.example.com", false, false);
- testActive(test, "foo$domain=~foo.example.com", "mple.com", true, false);
-
- test.done();
-};
+ describe("With Exception For a Subdomain", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo$domain=~foo.example.com", null, true, false);
+ testActive("foo$domain=~foo.example.com", "com", true, false);
+ testActive("foo$domain=~foo.example.com", "example.com", true, false);
+ testActive("foo$domain=~foo.example.com", "example.com.", true, false);
+ testActive("foo$domain=~foo.example.com", "foo.example.com", false, false);
+ testActive("foo$domain=~foo.example.com", "mple.com", true, false);
+ });
-exports.testHidingRulesWithExceptionForASubdomain = function(test)
-{
- testActive(test, "~foo.example.com##foo", null, true, false);
- testActive(test, "~foo.example.com##foo", "com", true, false);
- testActive(test, "~foo.example.com##foo", "example.com", true, false);
- testActive(test, "~foo.example.com##foo", "example.com.", true, false);
- testActive(test, "~foo.example.com##foo", "foo.example.com", false, false);
- testActive(test, "~foo.example.com##foo", "mple.com", true, false);
-
- test.done();
-};
+ it("Hiding Rules", () =>
+ {
+ testActive("~foo.example.com##foo", null, true, false);
+ testActive("~foo.example.com##foo", "com", true, false);
+ testActive("~foo.example.com##foo", "example.com", true, false);
+ testActive("~foo.example.com##foo", "example.com.", true, false);
+ testActive("~foo.example.com##foo", "foo.example.com", false, false);
+ testActive("~foo.example.com##foo", "mple.com", true, false);
+ });
+ });
-exports.testBlockingFiltersForDomainButNotItsSubdomain = function(test)
-{
- testActive(test, "foo$domain=example.com|~foo.example.com", null, false, false);
- testActive(test, "foo$domain=example.com|~foo.example.com", "com", false, true);
- testActive(test, "foo$domain=example.com|~foo.example.com", "example.com", true, true);
- testActive(test, "foo$domain=example.com|~foo.example.com", "example.com.", true, true);
- testActive(test, "foo$domain=example.com|~foo.example.com", "foo.example.com", false, false);
- testActive(test, "foo$domain=example.com|~foo.example.com", "mple.com", false, false);
-
- test.done();
-};
+ describe("For Domain but not its Subdomain", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo$domain=example.com|~foo.example.com", null, false, false);
+ testActive("foo$domain=example.com|~foo.example.com", "com", false, true);
+ testActive("foo$domain=example.com|~foo.example.com", "example.com", true, true);
+ testActive("foo$domain=example.com|~foo.example.com", "example.com.", true, true);
+ testActive("foo$domain=example.com|~foo.example.com", "foo.example.com", false, false);
+ testActive("foo$domain=example.com|~foo.example.com", "mple.com", false, false);
+ });
-exports.testHidingRulesForDomainButNotItsSubdomain = function(test)
-{
- testActive(test, "example.com,~foo.example.com##foo", null, false, false);
- testActive(test, "example.com,~foo.example.com##foo", "com", false, true);
- testActive(test, "example.com,~foo.example.com##foo", "example.com", true, true);
- testActive(test, "example.com,~foo.example.com##foo", "example.com.", true, true);
- testActive(test, "example.com,~foo.example.com##foo", "foo.example.com", false, false);
- testActive(test, "example.com,~foo.example.com##foo", "mple.com", false, false);
-
- test.done();
-};
+ it("Hiding Rules", () =>
+ {
+ testActive("example.com,~foo.example.com##foo", null, false, false);
+ testActive("example.com,~foo.example.com##foo", "com", false, true);
+ testActive("example.com,~foo.example.com##foo", "example.com", true, true);
+ testActive("example.com,~foo.example.com##foo", "example.com.", true, true);
+ testActive("example.com,~foo.example.com##foo", "foo.example.com", false, false);
+ testActive("example.com,~foo.example.com##foo", "mple.com", false, false);
+ });
+ });
-exports.testBlockingFiltersForDomainButNotItsTLD = function(test)
-{
- testActive(test, "foo$domain=example.com|~com", null, false, false);
- testActive(test, "foo$domain=example.com|~com", "com", false, true);
- testActive(test, "foo$domain=example.com|~com", "example.com", true, true);
- testActive(test, "foo$domain=example.com|~com", "example.com.", true, true);
- testActive(test, "foo$domain=example.com|~com", "foo.example.com", true, false);
- testActive(test, "foo$domain=example.com|~com", "mple.com", false, false);
-
- test.done();
-};
+ describe("For Domain but not is TLD", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo$domain=example.com|~com", null, false, false);
+ testActive("foo$domain=example.com|~com", "com", false, true);
+ testActive("foo$domain=example.com|~com", "example.com", true, true);
+ testActive("foo$domain=example.com|~com", "example.com.", true, true);
+ testActive("foo$domain=example.com|~com", "foo.example.com", true, false);
+ testActive("foo$domain=example.com|~com", "mple.com", false, false);
+ });
-exports.testHidingRulesForDomainButNotItsTLD = function(test)
-{
- testActive(test, "example.com,~com##foo", null, false, false);
- testActive(test, "example.com,~com##foo", "com", false, true);
- testActive(test, "example.com,~com##foo", "example.com", true, true);
- testActive(test, "example.com,~com##foo", "example.com.", true, true);
- testActive(test, "example.com,~com##foo", "foo.example.com", true, false);
- testActive(test, "example.com,~com##foo", "mple.com", false, false);
-
- test.done();
-};
+ it("Hiding Rules", () =>
+ {
+ testActive("example.com,~com##foo", null, false, false);
+ testActive("example.com,~com##foo", "com", false, true);
+ testActive("example.com,~com##foo", "example.com", true, true);
+ testActive("example.com,~com##foo", "example.com.", true, true);
+ testActive("example.com,~com##foo", "foo.example.com", true, false);
+ testActive("example.com,~com##foo", "mple.com", false, false);
+ });
+ });
-exports.testBlockingFiltersRestrictedToAnUnrelatedDomain = function(test)
-{
- testActive(test, "foo$domain=nnnnnnn.nnn", null, false, false);
- testActive(test, "foo$domain=nnnnnnn.nnn", "com", false, false);
- testActive(test, "foo$domain=nnnnnnn.nnn", "example.com", false, false);
- testActive(test, "foo$domain=nnnnnnn.nnn", "example.com.", false, false);
- testActive(test, "foo$domain=nnnnnnn.nnn", "foo.example.com", false, false);
- testActive(test, "foo$domain=nnnnnnn.nnn", "mple.com", false, false);
-
- test.done();
-};
+ describe("Restricted To An Unrelated Domain", () =>
+ {
+ it("Blocking Filters", () =>
+ {
+ testActive("foo$domain=nnnnnnn.nnn", null, false, false);
+ testActive("foo$domain=nnnnnnn.nnn", "com", false, false);
+ testActive("foo$domain=nnnnnnn.nnn", "example.com", false, false);
+ testActive("foo$domain=nnnnnnn.nnn", "example.com.", false, false);
+ testActive("foo$domain=nnnnnnn.nnn", "foo.example.com", false, false);
+ testActive("foo$domain=nnnnnnn.nnn", "mple.com", false, false);
+ });
-exports.testHidingRulesRestrictedToAnUnrelatedDomain = function(test)
-{
- testActive(test, "nnnnnnn.nnn##foo", null, false, false);
- testActive(test, "nnnnnnn.nnn##foo", "com", false, false);
- testActive(test, "nnnnnnn.nnn##foo", "example.com", false, false);
- testActive(test, "nnnnnnn.nnn##foo", "example.com.", false, false);
- testActive(test, "nnnnnnn.nnn##foo", "foo.example.com", false, false);
- testActive(test, "nnnnnnn.nnn##foo", "mple.com", false, false);
-
- test.done();
-};
+ it("Hiding Rules", () =>
+ {
+ testActive("nnnnnnn.nnn##foo", null, false, false);
+ testActive("nnnnnnn.nnn##foo", "com", false, false);
+ testActive("nnnnnnn.nnn##foo", "example.com", false, false);
+ testActive("nnnnnnn.nnn##foo", "example.com.", false, false);
+ testActive("nnnnnnn.nnn##foo", "foo.example.com", false, false);
+ testActive("nnnnnnn.nnn##foo", "mple.com", false, false);
+ });
+ });
+});
« no previous file with comments | « test/caching.js ('k') | test/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld