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

Unified Diff: test/filterText.js

Issue 29909576: [experiment] Issue 7045 - Optimize V8 memory layout of filter text Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Remove check in lib/filterClasses.js Created Oct. 15, 2018, 9:25 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 | « lib/filterText.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/filterText.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/filterText.js
@@ -0,0 +1,106 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present 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";
+
+const {createSandbox} = require("./_common");
+
+let LONG_DOMAINS_THRESHOLD = null;
+let optimizeContentFilterText = null;
+let optimizeRegExpFilterText = null;
+
+function randomName()
+{
+ let str = Math.random().toString(36).substring(2);
+ return str.substring(0, Math.ceil(Math.random() * str.length));
+}
+
+function randomDomain()
+{
+ // Create a domain with between one and four parts to cover all the usual
+ // cases.
+ let domain = randomName();
+ for (let i = 0; i < Math.floor(Math.random() * 4); i++)
+ domain += "." + randomName();
+ return domain;
+}
+
+exports.setUp = function(callback)
+{
+ let sandboxedRequire = createSandbox({
+ extraExports: {
+ filterText: ["LONG_DOMAINS_THRESHOLD"]
+ }
+ });
+ (
+ {LONG_DOMAINS_THRESHOLD,
+ optimizeContentFilterText,
+ optimizeRegExpFilterText} = sandboxedRequire("../lib/filterText")
+ );
+
+ callback();
+};
+
+exports.testOptimizeContentFilterText = function(test)
+{
+ let domains = randomDomain();
+ while (domains.length < LONG_DOMAINS_THRESHOLD)
+ domains += "," + randomDomain();
+
+ let filterParts = [
+ [domains, null, "." + randomName()],
+ [domains, "@", "." + randomName()],
+ [domains, "?", `.${randomName()}:-abp-contains(${randomName()})`],
+ [domains, "$",
+ `${randomName()} '${randomName()} ${randomName()}' ${randomName()}`]
+ ];
+
+ let filters = filterParts.map(
+ ([domains_, type, selector]) =>
+ [domains_ + "#" + (type || "") + "#" + selector,
+ domains_, type, selector]
+ );
+
+ // We just have to make sure that the parts returned are the same as the
+ // parts passed in to the function.
+ for (let filter of filters)
+ test.deepEqual(optimizeContentFilterText(...filter), filter);
+
+ test.done();
+};
+
+exports.testOptimizeRegExpFilterText = function(test)
+{
+ let domains = randomDomain();
+ while (domains.length < LONG_DOMAINS_THRESHOLD)
+ domains += "|" + randomDomain();
+
+ let filterParts = [
+ ["", randomName(), domains],
+ ["@@", randomName(), domains]
+ ];
+
+ let filters = filterParts.map(
+ ([marker, pattern, domains_]) => [marker + pattern + "$domain=" + domains,
+ pattern, domains, null, null, null]
+ );
+
+ for (let filter of filters)
+ test.deepEqual(optimizeRegExpFilterText(...filter), filter);
+
+ test.done();
+};
« no previous file with comments | « lib/filterText.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld