Index: test/browser/elemHideEmulation.js |
=================================================================== |
--- a/test/browser/elemHideEmulation.js |
+++ b/test/browser/elemHideEmulation.js |
@@ -12,20 +12,17 @@ |
* 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"; |
-/* globals ElemHideEmulation, splitSelector, |
- parseSelectorContent, |
- parseSelector, positionInParent, makeSelector, |
- PlainSelector, HasSelector, PropsSelector */ |
+/* globals ElemHideEmulation */ |
let myUrl = document.currentScript.src; |
exports.tearDown = function(callback) |
{ |
let styleElements = document.head.getElementsByTagName("style"); |
while (styleElements.length) |
styleElements[0].parentNode.removeChild(styleElements[0]); |
@@ -139,193 +136,16 @@ |
} |
); |
elemHideEmulation.apply(); |
return Promise.resolve(elemHideEmulation); |
}); |
} |
-// internals testing |
- |
-exports.testParseSelectorContent = function(test) |
-{ |
- loadElemHideEmulation().then(() => |
- { |
- let parsed = parseSelectorContent(":-abp-has(> div) > div", 10); |
- test.equal(parsed.text, "> div"); |
- test.equal(parsed.end, 15); |
- |
- parsed = parseSelectorContent("> div) > div", 0); |
- test.equal(parsed.text, "> div"); |
- test.equal(parsed.end, 5); |
- |
- // parens not closed. |
- parsed = parseSelectorContent("> div > div", 0); |
- test.equal(parsed, null); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
-}; |
- |
-exports.testParseSelector = function(test) |
-{ |
- loadElemHideEmulation().then(() => |
- { |
- let selectors = parseSelector(""); |
- test.equal(selectors.length, 0); |
- |
- let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')"; |
- selectors = parseSelector(selector); |
- test.equal(selectors.length, 2); |
- test.ok(selectors[0] instanceof PlainSelector); |
- test.ok(selectors[1] instanceof PropsSelector); |
- |
- selector = "div > :-abp-has(> div.inside) > div"; |
- selectors = parseSelector(selector); |
- test.equal(selectors.length, 3); |
- test.ok(selectors[0] instanceof PlainSelector); |
- test.ok(selectors[1] instanceof HasSelector); |
- test.ok(selectors[2] instanceof PlainSelector); |
- |
- selector = "div > div:-abp-has(> div.inside) > div"; |
- selectors = parseSelector(selector); |
- |
- test.equal(selectors.length, 3); |
- test.ok(selectors[0] instanceof PlainSelector); |
- test.ok(selectors[1] instanceof HasSelector); |
- test.ok(selectors[2] instanceof PlainSelector); |
- |
- selector = "div > :-abp-has(> div.inside) > :-abp-properties(background-color: rgb(0, 0, 0))"; |
- selectors = parseSelector(selector); |
- |
- test.equal(selectors.length, 4); |
- test.ok(selectors[0] instanceof PlainSelector); |
- 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); |
- |
- // -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) |
-{ |
- doc.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 = document.getElementById("parent"); |
- let middle = document.getElementById("middle"); |
- let middle1 = document.getElementById("middle1"); |
- let inside = document.getElementById("inside"); |
- let sibling = document.getElementById("sibling"); |
- let sibling2 = document.getElementById("sibling2"); |
- let toHide = document.getElementById("tohide"); |
- return {parent, middle, middle1, inside, sibling, sibling2, toHide}; |
-} |
- |
-exports.testPositionInParent = function(test) |
-{ |
- let nodes = buildDom(document); |
- |
- loadElemHideEmulation().then(() => |
- { |
- test.equal(positionInParent(nodes.middle1), 1); |
- test.equal(positionInParent(nodes.inside), 1); |
- test.equal(positionInParent(nodes.sibling2), 3); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
-}; |
- |
-exports.testMakeSelector = function(test) |
-{ |
- let nodes = buildDom(document); |
- |
- loadElemHideEmulation().then(() => |
- { |
- test.equal(makeSelector(nodes.middle, ""), |
- ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)"); |
- test.equal(makeSelector(nodes.toHide, ""), |
- ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)"); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
-}; |
- |
-exports.testPlainSelector = function(test) |
-{ |
- buildDom(document); |
- |
- loadElemHideEmulation().then(() => |
- { |
- let selector = new PlainSelector("div > div"); |
- |
- let iter = selector.getSelectors("foo > "); |
- let value = iter.next(); |
- test.equal(value.value[0], "foo > div > div"); |
- test.ok(iter.next().done); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
-}; |
- |
-exports.testHasSelector = function(test) |
-{ |
- buildDom(document); |
- |
- loadElemHideEmulation().then(() => |
- { |
- let selector = new HasSelector("> div.inside"); |
- |
- 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(1) > DIV:nth-child(1)"); |
- |
- iter = selector.getElements("", document, document.sheet); |
- value = iter.next(); |
- test.ok(!value.done); |
- test.equal(value.value.id, "middle1"); |
- value = iter.next(); |
- test.ok(!value.done); |
- test.equal(value.value.id, "sibling21"); |
- value = iter.next(); |
- test.ok(value.done); |
- |
- selector = new HasSelector(":-abp-has(> div.inside)"); |
- |
- test.ok(selector._innerSelectors); |
- }).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"); |
- |
- selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-color: rgb(0, 0, 0)']"); |
- test.ok(selectors); |
- test.equal(selectors.length, 2, "There are two selectors"); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
-}; |
- |
-// API testing |
- |
exports.testVerbatimPropertySelector = function(test) |
{ |
let toHide = createElementWithStyle("{background-color: #000}"); |
applyElemHideEmulation( |
[":-abp-properties(background-color: rgb(0, 0, 0))"] |
).then(() => |
{ |
expectHidden(test, toHide); |