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

Side by Side Diff: test/filterClasses.js

Issue 29791555: Issue 6727 - Use string rather than map for single-domain filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Fix ESLint error Created June 6, 2018, 11:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filterClasses.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 result.push("type=comment"); 64 result.push("type=comment");
65 else if (filter instanceof ActiveFilter) 65 else if (filter instanceof ActiveFilter)
66 { 66 {
67 result.push("disabled=" + filter.disabled); 67 result.push("disabled=" + filter.disabled);
68 result.push("lastHit=" + filter.lastHit); 68 result.push("lastHit=" + filter.lastHit);
69 result.push("hitCount=" + filter.hitCount); 69 result.push("hitCount=" + filter.hitCount);
70 70
71 let domains = []; 71 let domains = [];
72 if (filter.domains) 72 if (filter.domains)
73 { 73 {
74 for (let [domain, isIncluded] of filter.domains) 74 if (typeof filter.domains == "string")
75 { 75 {
76 if (domain != "") 76 domains.push(filter.domains);
77 domains.push(isIncluded ? domain : "~" + domain); 77 }
78 else
79 {
80 for (let [domain, isIncluded] of filter.domains)
81 {
82 if (domain != "")
83 domains.push(isIncluded ? domain : "~" + domain);
84 }
78 } 85 }
79 } 86 }
80 result.push("domains=" + domains.sort().join("|")); 87 result.push("domains=" + domains.sort().join("|"));
81 88
82 if (filter instanceof RegExpFilter) 89 if (filter instanceof RegExpFilter)
83 { 90 {
84 result.push("regexp=" + filter.regexp.source); 91 result.push("regexp=" + filter.regexp.source);
85 result.push("contentType=" + filter.contentType); 92 result.push("contentType=" + filter.contentType);
86 result.push("matchCase=" + filter.matchCase); 93 result.push("matchCase=" + filter.matchCase);
87 94
(...skipping 13 matching lines...) Expand all
101 } 108 }
102 else if (filter instanceof ElemHideBase) 109 else if (filter instanceof ElemHideBase)
103 { 110 {
104 if (filter instanceof ElemHideFilter) 111 if (filter instanceof ElemHideFilter)
105 result.push("type=elemhide"); 112 result.push("type=elemhide");
106 else if (filter instanceof ElemHideException) 113 else if (filter instanceof ElemHideException)
107 result.push("type=elemhideexception"); 114 result.push("type=elemhideexception");
108 else if (filter instanceof ElemHideEmulationFilter) 115 else if (filter instanceof ElemHideEmulationFilter)
109 result.push("type=elemhideemulation"); 116 result.push("type=elemhideemulation");
110 117
118 let filterDomains = typeof filter.domains == "string" ?
119 [[filter.domains, true]] : filter.domains;
111 result.push("selectorDomains=" + 120 result.push("selectorDomains=" +
112 [...filter.domains || []] 121 [...filterDomains || []]
113 .filter(([domain, isIncluded]) => isIncluded) 122 .filter(([domain, isIncluded]) => isIncluded)
114 .map(([domain]) => domain.toLowerCase())); 123 .map(([domain]) => domain.toLowerCase()));
115 result.push("selector=" + filter.selector); 124 result.push("selector=" + filter.selector);
116 } 125 }
117 } 126 }
118 return result; 127 return result;
119 } 128 }
120 129
121 function addDefaults(expected) 130 function addDefaults(expected)
122 { 131 {
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), 550 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"),
542 "http://content.server/file/foo.txt/disable" 551 "http://content.server/file/foo.txt/disable"
543 ); 552 );
544 test.equal( 553 test.equal(
545 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), 554 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"),
546 "http://example.com/file/foo.txt/disable" 555 "http://example.com/file/foo.txt/disable"
547 ); 556 );
548 557
549 test.done(); 558 test.done();
550 }; 559 };
OLDNEW
« no previous file with comments | « lib/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld