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]); |
@@ -205,16 +205,28 @@ |
test.ok(selectors[1] instanceof HasSelector); |
test.ok(selectors[2] instanceof PlainSelector); |
test.ok(selectors[3] instanceof PropsSelector); |
selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color: rgb(0, 0, 0))"; |
selectors = parseSelector(selector); |
test.equal(selectors, null); |
+ selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp-contains(Suggested Post))'; |
+ selectors = parseSelector(selector); |
+ 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); |
+ test.equals(selectors[1]._text, "Suggested Post"); |
+ |
// -abp-has-unsupported() is unknown. Ensure we fail parsing. |
selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp-unsupported("Suggested Post"))'; |
selectors = parseSelector(selector); |
test.equal(selectors, null); |
}).catch(unexpectedError.bind(test)).then(() => test.done()); |
}; |
function buildDom(doc) |
@@ -305,16 +317,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"); |