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

Unified Diff: test/browser/elemHideEmulation.js

Issue 29613805: Issue 6034 - :-abp-contains() accept a regular expression (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Do all matches with RegExp. Created Jan. 9, 2018, 10: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/content/elemHideEmulation.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/browser/elemHideEmulation.js
===================================================================
--- a/test/browser/elemHideEmulation.js
+++ b/test/browser/elemHideEmulation.js
@@ -348,16 +348,30 @@
{
expectVisible(test, parent);
expectVisible(test, middle);
expectVisible(test, sibling);
expectHidden(test, toHide);
}).catch(unexpectedError.bind(test)).then(() => test.done());
};
+function compareExpectations(test, elems, expectations)
+{
+ for (let elem in expectations)
+ {
+ if (elems[elem])
+ {
+ if (expectations[elem])
+ expectVisible(test, elems[elem]);
+ else
+ expectHidden(test, elems[elem]);
+ }
+ }
+}
+
function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector, expectations)
{
testDocument.body.innerHTML = `<div id="parent">
<div id="middle">
<div id="middle1"><div id="inside" class="inside"></div></div>
</div>
<div id="sibling">
<div id="tohide">to hide</div>
@@ -376,24 +390,17 @@
};
insertStyleRule(".inside {}");
applyElemHideEmulation(
[selector]
).then(() =>
{
- for (let elem in expectations)
- if (elems[elem])
- {
- if (expectations[elem])
- expectVisible(test, elems[elem]);
- else
- expectHidden(test, elems[elem]);
- }
+ compareExpectations(test, elems, expectations);
}).catch(unexpectedError.bind(test)).then(() => test.done());
}
exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
{
let expectations = {
parent: true,
middile: true,
@@ -429,47 +436,71 @@
sibling: true,
sibling2: true,
toHide: true
};
runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(
test, "div:-abp-has(> body div.inside) + div > div", expectations);
};
-exports.testPseudoClassContains = function(test)
+function runTestPseudoClassContains(test, selector, expectations)
{
testDocument.body.innerHTML = `<div id="parent">
<div id="middle">
<div id="middle1"><div id="inside" class="inside"></div></div>
</div>
<div id="sibling">
<div id="tohide">to hide</div>
</div>
<div id="sibling2">
<div id="sibling21"><div id="sibling211" class="inside"></div></div>
</div>
</div>`;
- let parent = testDocument.getElementById("parent");
- let middle = testDocument.getElementById("middle");
- let inside = testDocument.getElementById("inside");
- let sibling = testDocument.getElementById("sibling");
- let sibling2 = testDocument.getElementById("sibling2");
- let toHide = testDocument.getElementById("tohide");
+ let elems = {
+ parent: testDocument.getElementById("parent"),
+ middle: testDocument.getElementById("middle"),
+ inside: testDocument.getElementById("inside"),
+ sibling: testDocument.getElementById("sibling"),
+ sibling2: testDocument.getElementById("sibling2"),
+ toHide: testDocument.getElementById("tohide")
+ };
applyElemHideEmulation(
- ["#parent div:-abp-contains(to hide)"]
- ).then(() =>
- {
- expectVisible(test, parent);
- expectVisible(test, middle);
- expectVisible(test, inside);
- expectHidden(test, sibling);
- expectVisible(test, sibling2);
- expectHidden(test, toHide);
- }).catch(unexpectedError.bind(test)).then(() => test.done());
+ [selector]
+ ).then(
+ () => compareExpectations(test, elems, expectations)
+ ).catch(unexpectedError.bind(test)).then(() => test.done());
+}
+
+exports.testPseudoClassContainsText = function(test)
+{
+ let expectations = {
+ parent: true,
+ middle: true,
+ inside: true,
+ sibling: false,
+ sibling2: true,
+ toHide: false
+ };
+ runTestPseudoClassContains(
+ test, "#parent div:-abp-contains(to hide)", expectations);
+};
+
+exports.testPseudoClassContainsRegexp = function(test)
+{
+ let expectations = {
+ parent: true,
+ middle: true,
+ inside: true,
+ sibling: false,
+ sibling2: true,
+ toHide: false
+ };
+ runTestPseudoClassContains(
+ test, "#parent div:-abp-contains(/to\\shide/)", expectations);
};
exports.testPseudoClassHasSelectorWithPropSelector = function(test)
{
let parent = createElementWithStyle("{}");
let child = createElementWithStyle("{background-color: #000}", parent);
applyElemHideEmulation(
["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
« no previous file with comments | « lib/content/elemHideEmulation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld