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

Delta Between Two Patch Sets: test/regexpFilters_matching.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created March 7, 2019, 1:14 p.m.
Right Patch Set: Rebased Created April 10, 2019, 6:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/notification.js ('k') | test/signatures.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const assert = require("assert"); 20 const assert = require("assert");
21 const {createSandbox} = require("./_common"); 21 const {createSandbox} = require("./_common");
22 22
23 let Filter = null; 23 let Filter = null;
24 let RegExpFilter = null; 24 let RegExpFilter = null;
25 let URLRequest = null;
25 26
26 describe("Regexp filters matching", () => 27 describe("Regexp filters matching", () =>
27 { 28 {
28 beforeEach(() => 29 beforeEach(() =>
29 { 30 {
30 let sandboxedRequire = createSandbox(); 31 let sandboxedRequire = createSandbox();
31 ( 32 (
32 {Filter, RegExpFilter} = sandboxedRequire("../lib/filterClasses") 33 {Filter, RegExpFilter} = sandboxedRequire("../lib/filterClasses"),
34 {URLRequest} = sandboxedRequire("../lib/url")
33 ); 35 );
34 }); 36 });
35 37
36 function testMatch(text, location, contentType, docDomain, thirdParty, sitekey , expected) 38 function testMatch(text, location, contentType, docDomain, thirdParty, sitekey , expected)
37 { 39 {
40 if (thirdParty && docDomain == null)
41 docDomain = "some-other-domain";
42
38 function testMatchInternal(filterText) 43 function testMatchInternal(filterText)
39 { 44 {
40 let filter = Filter.fromText(filterText); 45 let filter = Filter.fromText(filterText);
41 let result = filter.matches(location, RegExpFilter.typeMap[contentType], d ocDomain, thirdParty, sitekey); 46 let request = URLRequest.from(location, docDomain);
47 let result = filter.matches(request, RegExpFilter.typeMap[contentType], si tekey);
42 assert.equal(!!result, expected, '"' + filterText + '".matches(' + locatio n + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ")"); 48 assert.equal(!!result, expected, '"' + filterText + '".matches(' + locatio n + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ")");
43 } 49 }
44 50
45 testMatchInternal(text); 51 testMatchInternal(text);
46 if (!/^@@/.test(text)) 52 if (!/^@@/.test(text))
47 testMatchInternal("@@" + text); 53 testMatchInternal("@@" + text);
48 } 54 }
49 55
50 it("Basic Filters", () => 56 it("Basic Filters", () =>
51 { 57 {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 testMatch("@@test$~image,document", "http://test/", "DOCUMENT", null, false, null, true); 349 testMatch("@@test$~image,document", "http://test/", "DOCUMENT", null, false, null, true);
344 testMatch("@@test$document,~image", "http://test/", "DOCUMENT", null, false, null, true); 350 testMatch("@@test$document,~image", "http://test/", "DOCUMENT", null, false, null, true);
345 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "foo .com", false, null, true); 351 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "foo .com", false, null, true);
346 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "bar .com", false, null, false); 352 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "bar .com", false, null, false);
347 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "fo o.com", false, null, false); 353 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "fo o.com", false, null, false);
348 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "ba r.com", false, null, true); 354 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "ba r.com", false, null, true);
349 testMatch("@@test$document,sitekey=foo-publickey", "http://test/", "DOCUMENT ", "foo.com", false, "foo-publickey", true); 355 testMatch("@@test$document,sitekey=foo-publickey", "http://test/", "DOCUMENT ", "foo.com", false, "foo-publickey", true);
350 testMatch("@@test$document,sitekey=foo-publickey", "http://test/", "DOCUMENT ", "foo.com", false, null, false); 356 testMatch("@@test$document,sitekey=foo-publickey", "http://test/", "DOCUMENT ", "foo.com", false, null, false);
351 }); 357 });
352 }); 358 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld