Index: test/browser/elemHideEmulation.js |
=================================================================== |
--- a/test/browser/elemHideEmulation.js |
+++ b/test/browser/elemHideEmulation.js |
@@ -15,17 +15,17 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
"use strict"; |
/* globals ElemHideEmulation, splitSelector, |
parseSelectorContent, |
parseSelector, positionInParent, makeSelector, |
- PlainSelector, HasSelector, PropsSelector */ |
+ PlainSelector, HasSelector, PropsSelector, ContainsSelector */ |
let myUrl = document.currentScript.src; |
exports.tearDown = function(callback) |
{ |
let styleElements = document.head.getElementsByTagName("style"); |
while (styleElements.length) |
styleElements[0].parentNode.removeChild(styleElements[0]); |
@@ -168,19 +168,21 @@ |
test.equal(parsed, null); |
}).catch(unexpectedError.bind(test)).then(() => test.done()); |
}; |
exports.testParseSelector = function(test) |
{ |
loadElemHideEmulation().then(() => |
{ |
- let {selectors, hide} = parseSelector(""); |
- test.equal(selectors.length, 0); |
- test.ok(!hide); |
+ { |
+ let {selectors, hide} = parseSelector(""); |
+ test.equal(selectors.length, 0); |
+ test.ok(!hide); |
+ } |
let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')"; |
let parsed = parseSelector(selector); |
test.equal(parsed.selectors.length, 2); |
test.ok(!parsed.hide); |
test.ok(parsed.selectors[0] instanceof PlainSelector); |
test.ok(parsed.selectors[1] instanceof PropsSelector); |
@@ -210,16 +212,28 @@ |
test.ok(parsed.selectors[1] instanceof HasSelector); |
test.ok(parsed.selectors[2] instanceof PlainSelector); |
test.ok(parsed.selectors[3] instanceof PropsSelector); |
selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color: rgb(0, 0, 0))"; |
parsed = parseSelector(selector); |
test.equal(parsed.selectors, null); |
+ selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp-contains("Suggested Post"))'; |
+ parsed = parseSelector(selector); |
+ let {selectors} = parsed; |
+ test.equal(selectors.length, 2); |
+ test.ok(selectors[0] instanceof PlainSelector); |
+ test.ok(selectors[1] instanceof HasSelector); |
+ |
+ selectors = selectors[1]._innerSelectors; |
+ test.equals(selectors.length, 2); |
+ test.ok(selectors[0] instanceof PlainSelector); |
+ test.ok(selectors[1] instanceof ContainsSelector); |
+ |
// -abp-has-unsupported() is unknown. Ensure we fail parsing. |
selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp-unsupported("Suggested Post"))'; |
parsed = parseSelector(selector); |
test.equal(parsed.selectors, null); |
}).catch(unexpectedError.bind(test)).then(() => test.done()); |
}; |
function buildDom(doc) |
@@ -310,16 +324,39 @@ |
test.ok(value.done); |
selector = new HasSelector(":-abp-has(> div.inside)"); |
test.ok(selector._innerSelectors); |
}).catch(unexpectedError.bind(test)).then(() => test.done()); |
}; |
+exports.testContainsSelector = function(test) |
+{ |
+ let {toHide} = buildDom(document); |
+ |
+ loadElemHideEmulation().then(() => |
+ { |
+ let selector = new ContainsSelector("to hide"); |
+ |
+ let iter = selector.getSelectors("", document, document.sheet); |
+ let value = iter.next(); |
+ test.ok(!value.done); |
+ test.equal(value.value[0], |
+ ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)"); |
+ |
+ iter = selector.getElements("", document, document.sheet); |
+ value = iter.next(); |
+ test.ok(!value.done); |
+ test.equal(value.value, toHide); |
+ value = iter.next(); |
+ test.ok(value.done); |
+ }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+}; |
+ |
exports.testSplitStyleRule = function(test) |
{ |
loadElemHideEmulation().then(() => |
{ |
let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='background-color: rgb(0, 0, 0)'] > span"); |
test.ok(selectors); |
test.equal(selectors.length, 1, "There is only one selector"); |