Index: test/browser/elemHideEmulation.js |
=================================================================== |
--- a/test/browser/elemHideEmulation.js |
+++ b/test/browser/elemHideEmulation.js |
@@ -143,301 +143,377 @@ |
function createElementWithStyle(styleBlock, parent) |
{ |
let element = createElement(parent); |
insertStyleRule("#" + element.id + " " + styleBlock); |
return element; |
} |
// Create a new ElemHideEmulation instance with @selectors. |
-function applyElemHideEmulation(selectors) |
+async function applyElemHideEmulation(selectors, test) |
{ |
- return Promise.resolve().then(() => |
+ await Promise.resolve(); |
+ |
+ let elemHideEmulation = null; |
+ |
+ try |
{ |
- let elemHideEmulation = new ElemHideEmulation( |
+ elemHideEmulation = new ElemHideEmulation( |
elems => |
{ |
for (let elem of elems) |
elem.style.display = "none"; |
} |
); |
elemHideEmulation.document = testDocument; |
elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2; |
elemHideEmulation.apply(selectors.map( |
selector => ({selector, text: selector}) |
)); |
- return elemHideEmulation; |
- }); |
+ } |
+ catch (error) |
+ { |
+ if (!test) |
+ throw error; |
+ |
+ unexpectedError.call(test, error); |
+ return null; |
+ } |
+ |
+ return elemHideEmulation; |
} |
-exports.testVerbatimPropertySelector = function(test) |
+exports.testVerbatimPropertySelector = async function(test) |
{ |
let toHide = createElementWithStyle("{background-color: #000}"); |
- applyElemHideEmulation( |
- [":-abp-properties(background-color: rgb(0, 0, 0))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(background-color: rgb(0, 0, 0))"], |
+ test |
+ )) |
{ |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testVerbatimPropertySelectorWithPrefix = function(test) |
+exports.testVerbatimPropertySelectorWithPrefix = async function(test) |
{ |
let parent = createElementWithStyle("{background-color: #000}"); |
let toHide = createElementWithStyle("{background-color: #000}", parent); |
- applyElemHideEmulation( |
- ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div > :-abp-properties(background-color: rgb(0, 0, 0))"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) |
+exports.testVerbatimPropertySelectorWithPrefixNoMatch = async function(test) |
{ |
let parent = createElementWithStyle("{background-color: #000}"); |
let toHide = createElementWithStyle("{background-color: #fff}", parent); |
- applyElemHideEmulation( |
- ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div > :-abp-properties(background-color: rgb(0, 0, 0))"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectVisible(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testVerbatimPropertySelectorWithSuffix = function(test) |
+exports.testVerbatimPropertySelectorWithSuffix = async function(test) |
{ |
let parent = createElementWithStyle("{background-color: #000}"); |
let toHide = createElementWithStyle("{background-color: #000}", parent); |
- applyElemHideEmulation( |
- [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(background-color: rgb(0, 0, 0)) > div"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) |
+exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = async function(test) |
{ |
let parent = createElementWithStyle("{background-color: #000}"); |
let middle = createElementWithStyle("{background-color: #000}", parent); |
let toHide = createElementWithStyle("{background-color: #000}", middle); |
- applyElemHideEmulation( |
- ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectVisible(test, middle); |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
// Add the style. Then add the element for that style. |
// This should retrigger the filtering and hide it. |
-exports.testPropertyPseudoSelectorAddStyleAndElement = function(test) |
+exports.testPropertyPseudoSelectorAddStyleAndElement = async function(test) |
{ |
let styleElement; |
let toHide; |
- applyElemHideEmulation( |
- [":-abp-properties(background-color: rgb(0, 0, 0))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(background-color: rgb(0, 0, 0))"], |
+ test |
+ )) |
{ |
styleElement = testDocument.createElement("style"); |
testDocument.head.appendChild(styleElement); |
styleElement.sheet.insertRule("#toHide {background-color: #000}"); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
toHide = createElement(); |
toHide.id = "toHide"; |
expectVisible(test, toHide); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPropertySelectorWithWildcard = function(test) |
+exports.testPropertySelectorWithWildcard = async function(test) |
{ |
let toHide = createElementWithStyle("{background-color: #000}"); |
- applyElemHideEmulation( |
- [":-abp-properties(*color: rgb(0, 0, 0))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(*color: rgb(0, 0, 0))"], |
+ test |
+ )) |
{ |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPropertySelectorWithRegularExpression = function(test) |
+exports.testPropertySelectorWithRegularExpression = async function(test) |
{ |
let toHide = createElementWithStyle("{background-color: #000}"); |
- applyElemHideEmulation( |
- [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"], |
+ test |
+ )) |
{ |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPropertySelectorWithEscapedBrace = function(test) |
+exports.testPropertySelectorWithEscapedBrace = async function(test) |
{ |
let toHide = createElementWithStyle("{background-color: #000}"); |
- applyElemHideEmulation( |
- [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)/)"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(/background.\\7B 0,6\\7D : rgb\\(0, 0, 0\\)/)"], |
+ test |
+ )) |
{ |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) |
+exports.testPropertySelectorWithImproperlyEscapedBrace = async function(test) |
{ |
let toHide = createElementWithStyle("{background-color: #000}"); |
- applyElemHideEmulation( |
- [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(/background.\\7B0,6\\7D: rgb\\(0, 0, 0\\)/)"], |
+ test |
+ )) |
{ |
expectVisible(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testDynamicallyChangedProperty = function(test) |
+exports.testDynamicallyChangedProperty = async function(test) |
{ |
let toHide = createElementWithStyle("{}"); |
- applyElemHideEmulation( |
- [":-abp-properties(background-color: rgb(0, 0, 0))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ [":-abp-properties(background-color: rgb(0, 0, 0))"], |
+ test |
+ )) |
{ |
expectVisible(test, toHide); |
insertStyleRule("#" + toHide.id + " {background-color: #000}"); |
- return timeout(0); |
- }).then(() => |
- { |
+ await timeout(0); |
+ |
// Re-evaluation will only happen after a delay |
expectVisible(test, toHide); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassWithPropBeforeSelector = function(test) |
+exports.testPseudoClassWithPropBeforeSelector = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{background-color: #000}", parent); |
insertStyleRule(`#${child.id}::before {content: "publicite"}`); |
- applyElemHideEmulation( |
- ["div:-abp-properties(content: \"publicite\")"] |
- ).then(() => |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-properties(content: \"publicite\")"], |
+ test |
+ )) |
{ |
expectHidden(test, child); |
expectVisible(test, parent); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasSelector = function(test) |
+exports.testPseudoClassHasSelector = async function(test) |
{ |
let toHide = createElementWithStyle("{}"); |
- applyElemHideEmulation( |
- ["div:-abp-has(div)"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(div)"], |
+ test |
+ )) |
{ |
expectVisible(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasSelectorWithPrefix = function(test) |
+exports.testPseudoClassHasSelectorWithPrefix = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{}", parent); |
- applyElemHideEmulation( |
- ["div:-abp-has(div)"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(div)"], |
+ test |
+ )) |
{ |
expectHidden(test, parent); |
expectVisible(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasSelectorWithSuffix = function(test) |
+exports.testPseudoClassHasSelectorWithSuffix = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let middle = createElementWithStyle("{}", parent); |
let child = createElementWithStyle("{}", middle); |
- applyElemHideEmulation( |
- ["div:-abp-has(div) > div"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(div) > div"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectHidden(test, middle); |
expectHidden(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) |
+exports.testPseudoClassHasSelectorWithSuffixSibling = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let middle = createElementWithStyle("{}", parent); |
let toHide = createElementWithStyle("{}"); |
- applyElemHideEmulation( |
- ["div:-abp-has(div) + div"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(div) + div"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectVisible(test, middle); |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) |
+exports.testPseudoClassHasSelectorWithSuffixSiblingChild = async function(test) |
{ |
// <div> |
// <div></div> |
// <div> |
// <div>to hide</div> |
// </div> |
// </div> |
let parent = createElementWithStyle("{}"); |
let middle = createElementWithStyle("{}", parent); |
let sibling = createElementWithStyle("{}"); |
let toHide = createElementWithStyle("{}", sibling); |
- applyElemHideEmulation( |
- ["div:-abp-has(div) + div > div"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(div) + div > div"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectVisible(test, middle); |
expectVisible(test, sibling); |
expectHidden(test, toHide); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
function compareExpectations(test, elems, expectations) |
{ |
for (let elem in expectations) |
{ |
if (elems[elem]) |
{ |
if (expectations[elem]) |
expectVisible(test, elems[elem], elem); |
else |
expectHidden(test, elems[elem], elem); |
} |
} |
} |
-function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector, expectations) |
+async 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"><span>to hide</span></div> |
</div> |
@@ -451,95 +527,98 @@ |
inside: testDocument.getElementById("inside"), |
sibling: testDocument.getElementById("sibling"), |
sibling2: testDocument.getElementById("sibling2"), |
toHide: testDocument.getElementById("tohide") |
}; |
insertStyleRule(".inside {}"); |
- applyElemHideEmulation( |
- [selector] |
- ).then(() => |
+ if (await applyElemHideEmulation( |
+ [selector], |
+ test |
+ )) |
{ |
compareExpectations(test, elems, expectations); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
} |
-exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) |
+exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = async function(test) |
{ |
let expectations = { |
parent: true, |
middile: true, |
inside: true, |
sibling: true, |
sibling2: true, |
toHide: false |
}; |
runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
test, "div:-abp-has(:-abp-has(div.inside)) + div > div", expectations); |
}; |
-exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) |
+exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = async function(test) |
{ |
let expectations = { |
parent: true, |
middile: true, |
inside: true, |
sibling: true, |
sibling2: true, |
toHide: false |
}; |
runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
test, "div:-abp-has(:-abp-has(> div.inside)) + div > div", expectations); |
}; |
-exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = function(test) |
+exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling3 = async function(test) |
{ |
let expectations = { |
parent: true, |
middile: true, |
inside: true, |
sibling: true, |
sibling2: true, |
toHide: false |
}; |
runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
test, "div:-abp-has(> div:-abp-has(div.inside)) + div > div", expectations); |
}; |
-exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = function(test) |
+exports.testPseudoClassHasSelectorWithSuffixSiblingNoop = async function(test) |
Manish Jethani
2019/01/17 08:03:33
Some functions don't really need to be async but i
Manish Jethani
2019/01/17 08:04:36
Removed now.
|
{ |
let expectations = { |
parent: true, |
middile: true, |
inside: true, |
sibling: true, |
sibling2: true, |
toHide: true |
}; |
runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
test, "div:-abp-has(> body div.inside) + div > div", expectations); |
}; |
-exports.testPseudoClassHasSelectorWithSuffixSiblingContains = function(test) |
+exports.testPseudoClassHasSelectorWithSuffixSiblingContains = async function(test) |
{ |
let expectations = { |
parent: true, |
middile: true, |
inside: true, |
sibling: true, |
sibling2: true, |
toHide: true |
}; |
runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling( |
test, "div:-abp-has(> span:-abp-contains(Advertisment))", expectations); |
}; |
-function runTestPseudoClassContains(test, selector, expectations) |
+async 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 \ud83d\ude42!</div> |
</div> |
@@ -551,407 +630,445 @@ |
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( |
- [selector] |
- ).then( |
- () => compareExpectations(test, elems, expectations) |
- ).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ if (await applyElemHideEmulation( |
+ [selector], |
+ test |
+ )) |
+ { |
+ compareExpectations(test, elems, expectations); |
+ } |
+ |
+ test.done(); |
} |
-exports.testPseudoClassContainsText = function(test) |
+exports.testPseudoClassContainsText = async function(test) |
{ |
let expectations = { |
parent: true, |
middle: true, |
inside: true, |
sibling: false, |
sibling2: true, |
toHide: true |
}; |
runTestPseudoClassContains( |
test, "#parent div:-abp-contains(to hide)", expectations); |
}; |
-exports.testPseudoClassContainsRegexp = function(test) |
+exports.testPseudoClassContainsRegexp = async function(test) |
{ |
let expectations = { |
parent: true, |
middle: true, |
inside: true, |
sibling: false, |
sibling2: true, |
toHide: true |
}; |
runTestPseudoClassContains( |
test, "#parent div:-abp-contains(/to\\shide/)", expectations); |
}; |
-exports.testPseudoClassContainsRegexpIFlag = function(test) |
+exports.testPseudoClassContainsRegexpIFlag = async function(test) |
{ |
let expectations = { |
parent: true, |
middle: true, |
inside: true, |
sibling: false, |
sibling2: true, |
toHide: true |
}; |
runTestPseudoClassContains( |
test, "#parent div:-abp-contains(/to\\sHide/i)", expectations); |
}; |
-exports.testPseudoClassContainsRegexpUFlag = function(test) |
+exports.testPseudoClassContainsRegexpUFlag = async function(test) |
{ |
let expectations = { |
parent: true, |
middle: true, |
inside: true, |
sibling: false, |
sibling2: true, |
toHide: true |
}; |
runTestPseudoClassContains( |
test, "#parent div:-abp-contains(/to\\shide\\s.!/u)", expectations); |
}; |
-exports.testPseudoClassContainsWildcardNoMatch = function(test) |
+exports.testPseudoClassContainsWildcardNoMatch = async function(test) |
{ |
let expectations = { |
parent: true, |
middle: true, |
inside: true, |
sibling: true, |
sibling2: true, |
toHide: true |
}; |
// this filter shouldn't match anything as "*" has no meaning. |
runTestPseudoClassContains( |
test, "#parent div:-abp-contains(to *hide)", expectations); |
}; |
-exports.testPseudoClassContainsWildcardMatch = function(test) |
+exports.testPseudoClassContainsWildcardMatch = async function(test) |
{ |
let expectations = { |
parent: true, |
middle: true, |
inside: true, |
sibling: true, |
sibling2: false, |
toHide: true |
}; |
runTestPseudoClassContains( |
test, "#parent div:-abp-contains(Ad*)", expectations); |
}; |
-exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
+exports.testPseudoClassHasSelectorWithPropSelector = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{background-color: #000}", parent); |
- applyElemHideEmulation( |
- ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], |
+ test |
+ )) |
{ |
expectVisible(test, child); |
expectHidden(test, parent); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) |
+exports.testPseudoClassHasSelectorWithPropSelector2 = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{}", parent); |
insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
- applyElemHideEmulation( |
- ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], |
+ test |
+ )) |
{ |
expectVisible(test, child); |
expectHidden(test, parent); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testDomUpdatesStyle = function(test) |
+exports.testDomUpdatesStyle = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{}", parent); |
- applyElemHideEmulation( |
- ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], |
+ test |
+ )) |
{ |
expectVisible(test, child); |
expectVisible(test, parent); |
insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
- return timeout(0); |
- }).then(() => |
- { |
+ await timeout(0); |
Manish Jethani
2019/01/17 08:03:34
Now we can just wait on the timeout.
|
+ |
expectVisible(test, child); |
expectVisible(test, parent); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, child); |
expectHidden(test, parent); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testDomUpdatesContent = function(test) |
+exports.testDomUpdatesContent = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{}", parent); |
- applyElemHideEmulation( |
- ["div > div:-abp-contains(hide me)"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div > div:-abp-contains(hide me)"], |
+ test |
+ )) |
{ |
expectVisible(test, parent); |
expectVisible(test, child); |
child.textContent = "hide me"; |
- return timeout(0); |
- }).then(() => |
- { |
+ await timeout(0); |
+ |
expectVisible(test, parent); |
expectVisible(test, child); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectHidden(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testDomUpdatesNewElement = function(test) |
+exports.testDomUpdatesNewElement = async function(test) |
{ |
let parent = createElementWithStyle("{}"); |
let child = createElementWithStyle("{ background-color: #000}", parent); |
let sibling; |
let child2; |
- applyElemHideEmulation( |
- ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
- ).then(() => |
+ |
+ if (await applyElemHideEmulation( |
+ ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"], |
+ test |
+ )) |
{ |
expectHidden(test, parent); |
expectVisible(test, child); |
sibling = createElementWithStyle("{}"); |
- return timeout(0); |
- }).then(() => |
- { |
+ await timeout(0); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
expectVisible(test, sibling); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
expectVisible(test, sibling); |
child2 = createElementWithStyle("{ background-color: #000}", |
sibling); |
- return timeout(0); |
- }).then(() => |
- { |
+ await timeout(0); |
+ |
expectVisible(test, child2); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
expectHidden(test, sibling); |
expectVisible(test, child2); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassPropertiesOnStyleSheetLoad = function(test) |
+exports.testPseudoClassPropertiesOnStyleSheetLoad = async function(test) |
{ |
let parent = createElement(); |
let child = createElement(parent); |
- applyElemHideEmulation( |
+ |
+ if (await applyElemHideEmulation( |
["div:-abp-properties(background-color: rgb(0, 0, 0))", |
"div:-abp-contains(hide me)", |
- "div:-abp-has(> div.hideMe)"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(> div.hideMe)"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectVisible(test, child); |
// Load a style sheet that targets the parent element. This should run only |
// the "div:-abp-properties(background-color: rgb(0, 0, 0))" pattern. |
insertStyleRule("#" + parent.id + " {background-color: #000}"); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPlainAttributeOnDomMutation = function(test) |
+exports.testPlainAttributeOnDomMutation = async function(test) |
{ |
let parent = createElement(); |
let child = createElement(parent); |
- applyElemHideEmulation( |
+ |
+ if (await applyElemHideEmulation( |
["div:-abp-properties(background-color: rgb(0, 0, 0))", |
"div[data-hide-me]", |
"div:-abp-contains(hide me)", |
- "div:-abp-has(> div.hideMe)"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(> div.hideMe)"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectVisible(test, child); |
// Set the "data-hide-me" attribute on the child element. |
// |
// Note: Since the "div[data-hide-me]" pattern has already been processed |
// and the selector added to the document's style sheet, this will in fact |
// not do anything at our end, but the browser will just match the selector |
// and hide the element. |
child.setAttribute("data-hide-me", ""); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectHidden(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassContainsOnDomMutation = function(test) |
+exports.testPseudoClassContainsOnDomMutation = async function(test) |
{ |
let parent = createElement(); |
let child = createElement(parent); |
child.innerText = "do nothing"; |
- applyElemHideEmulation( |
+ if (await applyElemHideEmulation( |
["div:-abp-properties(background-color: rgb(0, 0, 0))", |
"div[data-hide-me]", |
"div:-abp-contains(hide me)", |
- "div:-abp-has(> div.hideMe)"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(> div.hideMe)"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectVisible(test, child); |
// Set the child element's text to "hide me". This should run only the |
// "div:-abp-contains(hide me)" pattern. |
// |
// Note: We need to set Node.innerText here in order to trigger the |
// "characterData" DOM mutation on Chromium. If we set Node.textContent |
// instead, it triggers the "childList" DOM mutation instead. |
child.innerText = "hide me"; |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasOnDomMutation = function(test) |
+exports.testPseudoClassHasOnDomMutation = async function(test) |
{ |
let parent = createElement(); |
let child = null; |
- applyElemHideEmulation( |
+ |
+ if (await applyElemHideEmulation( |
["div:-abp-properties(background-color: rgb(0, 0, 0))", |
"div[data-hide-me]", |
"div:-abp-contains(hide me)", |
- "div:-abp-has(> div)"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(> div)"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
// Add the child element. This should run all the DOM-dependent patterns |
// ("div:-abp-contains(hide me)" and "div:-abp-has(> div)"). |
child = createElement(parent); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasWithClassOnDomMutation = function(test) |
+exports.testPseudoClassHasWithClassOnDomMutation = async function(test) |
{ |
let parent = createElement(); |
let child = createElement(parent); |
- applyElemHideEmulation( |
+ |
+ if (await applyElemHideEmulation( |
["div:-abp-properties(background-color: rgb(0, 0, 0))", |
"div[data-hide-me]", |
"div:-abp-contains(hide me)", |
- "div:-abp-has(> div.hideMe)"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(> div.hideMe)"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectVisible(test, child); |
// Set the child element's class to "hideMe". This should run only the |
// "div:-abp-has(> div.hideMe)" pattern. |
child.className = "hideMe"; |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectHidden(test, parent); |
expectVisible(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = function(test) |
+exports.testPseudoClassHasWithPseudoClassContainsOnDomMutation = async function(test) |
{ |
let parent = createElement(); |
let child = createElement(parent); |
child.innerText = "do nothing"; |
- applyElemHideEmulation( |
+ if (await applyElemHideEmulation( |
["div:-abp-properties(background-color: rgb(0, 0, 0))", |
"div[data-hide-me]", |
"div:-abp-contains(hide me)", |
- "div:-abp-has(> div:-abp-contains(hide me))"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(> div:-abp-contains(hide me))"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
expectVisible(test, parent); |
expectVisible(test, child); |
// Set the child element's text to "hide me". This should run only the |
// "div:-abp-contains(hide me)" and |
// "div:-abp-has(> div:-abp-contains(hide me))" patterns. |
child.innerText = "hide me"; |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
// Note: Even though it runs both the :-abp-contains() patterns, it only |
// hides the parent element because of revision d7d51d29aa34. |
expectHidden(test, parent); |
expectVisible(test, child); |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |
-exports.testOnlyRelevantElementsProcessed = function(test) |
+exports.testOnlyRelevantElementsProcessed = async function(test) |
{ |
// <body> |
// <div id="n1"> |
// <p id="n1_1"></p> |
// <p id="n1_2"></p> |
// <p id="n1_4">Hello</p> |
// </div> |
// <div id="n2"> |
@@ -972,23 +1089,25 @@ |
// </body> |
for (let i of [1, 2, 3, 4]) |
{ |
let n = createElement(null, "div", `n${i}`); |
for (let [j, text] of [[1], [2], [4, "Hello"]]) |
createElement(n, "p", `n${i}_${j}`, text); |
} |
- applyElemHideEmulation( |
+ if (await applyElemHideEmulation( |
["p:-abp-contains(Hello)", |
"div:-abp-contains(Try me!)", |
- "div:-abp-has(p:-abp-contains(This is good))"] |
- ).then(() => timeout(REFRESH_INTERVAL) |
- ).then(() => |
+ "div:-abp-has(p:-abp-contains(This is good))"], |
+ test |
+ )) |
{ |
+ await timeout(REFRESH_INTERVAL); |
+ |
// This is only a sanity check to make sure everything else is working |
// before we do the actual test. |
for (let i of [1, 2, 3, 4]) |
{ |
for (let j of [1, 2, 4]) |
{ |
let id = `n${i}_${j}`; |
if (j == 4) |
@@ -1003,41 +1122,41 @@ |
...testDocument.getElementsByTagName("p")]) |
{ |
expectProcessed(test, element, element.id); |
} |
// Modify the text in <p id="n4_1"> |
testDocument.getElementById("n4_1").innerText = "Try me!"; |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
// When an element's text is modified, only the element or one of its |
// ancestors matching any selector is processed for :-abp-has() and |
// :-abp-contains() |
for (let element of [...testDocument.getElementsByTagName("div"), |
...testDocument.getElementsByTagName("p")]) |
{ |
if (element.id == "n4" || element.id == "n4_1") |
expectProcessed(test, element, element.id); |
else |
expectNotProcessed(test, element, element.id); |
} |
// Create a new <p id="n2_3"> element with no text. |
createElement(testDocument.getElementById("n2"), "p", "n2_3"); |
- return timeout(REFRESH_INTERVAL); |
- }).then(() => |
- { |
+ await timeout(REFRESH_INTERVAL); |
+ |
// When a new element is added, only the element or one of its ancestors |
// matching any selector is processed for :-abp-has() and :-abp-contains() |
for (let element of [...testDocument.getElementsByTagName("div"), |
...testDocument.getElementsByTagName("p")]) |
{ |
if (element.id == "n2" || element.id == "n2_3") |
expectProcessed(test, element, element.id); |
else |
expectNotProcessed(test, element, element.id); |
} |
- }).catch(unexpectedError.bind(test)).then(() => test.done()); |
+ } |
+ |
+ test.done(); |
}; |