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

Unified Diff: test/browser/elemHideEmulation.js

Issue 29373596: Issue 4838 - Use nodeunit framework for integration tests running in browser (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Simplified phantomjs script Created Jan. 24, 2017, 8:08 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 | « test/browser/elemHideEmulation.html ('k') | test_runner.js » ('j') | 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
@@ -13,53 +13,58 @@
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
// We are currently limited to ECMAScript 5 in this file, because it is being
// used in the browser tests. See https://issues.adblockplus.org/ticket/4796
-QUnit.module("Element hiding emulation",
+// TODO: This should be using document.currentScript once supported by
+// PhantomJS.
+var myUrl = document.head.lastChild.src;
+
+exports.setUp = function(callback)
{
- before: function()
+ // The URL object in PhantomJS 2.1.7 does not implement any properties, so
+ // we need a polyfill.
+ if (!URL || !("origin" in URL))
{
- // The URL object in PhantomJS 2.1.7 does not implement any properties, so
- // we need a polyfill.
- if (!URL || !("origin" in URL))
+ var doc = document.implementation.createHTMLDocument();
+ var anchor = doc.createElement("a");
+ doc.body.appendChild(anchor);
+ URL = function(url)
{
- var doc = document.implementation.createHTMLDocument();
- var anchor = doc.createElement("a");
- doc.body.appendChild(anchor);
- URL = function(url)
- {
- if (!url)
- throw "Invalid URL";
- anchor.href = url;
- this.origin = anchor.origin;
- };
- }
- },
- afterEach: function()
- {
- var styleElements = document.head.getElementsByTagName("style");
- for (var i = 0; i < styleElements.length; i++)
- document.head.removeChild(styleElements[0]);
+ if (!url)
+ throw "Invalid URL";
+ anchor.href = url;
+ this.origin = anchor.origin;
+ };
}
-});
-QUnit.assert.hidden = function(element)
+ callback();
+};
+
+exports.tearDown = function(callback)
{
- this.equal(getComputedStyle(element).display, "none",
+ var styleElements = document.head.getElementsByTagName("style");
+ while (styleElements.length)
+ styleElements[0].parentNode.removeChild(styleElements[0]);
+ callback();
+}
+
+function expectHidden(test, element)
+{
+ test.equal(window.getComputedStyle(element).display, "none",
"The element's display property should be set to 'none'");
};
-QUnit.assert.visible = function(element)
+function expectVisible(test, element)
{
- this.notEqual(getComputedStyle(element).display, "none",
+ test.notEqual(window.getComputedStyle(element).display, "none",
"The element's display property should not be set to 'none'");
};
function findUniqueId()
{
var id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000);
if (!document.getElementById(id))
return id;
@@ -88,16 +93,28 @@ function createElementWithStyle(styleBlo
element.id = findUniqueId();
document.body.appendChild(element);
insertStyleRule("#" + element.id + " " + styleBlock);
return element;
}
function applyElemHideEmulation(selectors, callback)
{
+ if (typeof ElemHideEmulation == "undefined")
+ {
+ loadScript(myUrl + "/../../../lib/common.js", function()
+ {
+ loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js", function()
+ {
+ applyElemHideEmulation(selectors, callback);
+ });
+ });
+ return;
+ }
+
var elemHideEmulation = new ElemHideEmulation(
window,
function(callback)
{
var patterns = [];
selectors.forEach(function(selector)
{
patterns.push({selector: selector});
@@ -115,115 +132,90 @@ function applyElemHideEmulation(selector
elemHideEmulation.load(function()
{
elemHideEmulation.apply();
callback();
});
}
-QUnit.test(
- "Verbatim property selector",
- function(assert)
- {
- var done = assert.async();
- var toHide = createElementWithStyle("{background-color: #000}");
- applyElemHideEmulation(
- ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
- function()
- {
- assert.hidden(toHide);
- done();
- }
- );
- }
-);
-
-QUnit.test(
- "Property selector with wildcard",
- function(assert)
- {
- var done = assert.async();
- var toHide = createElementWithStyle("{background-color: #000}");
- applyElemHideEmulation(
- ["[-abp-properties='*color: rgb(0, 0, 0)']"],
- function()
- {
- assert.hidden(toHide);
- done();
- }
- );
- }
-);
-
-QUnit.test(
- "Property selector with regular expression",
- function(assert)
- {
- var done = assert.async();
- var toHide = createElementWithStyle("{background-color: #000}");
- applyElemHideEmulation(
- ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"],
- function()
- {
- assert.hidden(toHide);
- done();
- }
- );
- }
-);
+exports.testVerbatimPropertySelector = function(test)
+{
+ var toHide = createElementWithStyle("{background-color: #000}");
+ applyElemHideEmulation(
+ ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
+ function()
+ {
+ expectHidden(test, toHide);
+ test.done();
+ }
+ );
+};
-QUnit.test(
- "Property selector with regular expression containing escaped brace",
- function(assert)
- {
- var done = assert.async();
- var toHide = createElementWithStyle("{background-color: #000}");
- applyElemHideEmulation(
- ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"],
- function()
- {
- assert.hidden(toHide);
- done();
- }
- );
- }
-);
+exports.testPropertySelectorWithWildcard = function(test)
+{
+ var toHide = createElementWithStyle("{background-color: #000}");
+ applyElemHideEmulation(
+ ["[-abp-properties='*color: rgb(0, 0, 0)']"],
+ function()
+ {
+ expectHidden(test, toHide);
+ test.done();
+ }
+ );
+};
-QUnit.test(
- "Property selector with regular expression containing improperly escaped \
-brace",
- function(assert)
- {
- var done = assert.async();
- var toHide = createElementWithStyle("{background-color: #000}");
- applyElemHideEmulation(
- ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"],
- function()
+exports.testPropertySelectorWithRegularExpression = function(test)
+{
+ var toHide = createElementWithStyle("{background-color: #000}");
+ applyElemHideEmulation(
+ ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"],
+ function()
+ {
+ expectHidden(test, toHide);
+ test.done();
+ }
+ );
+};
+
+exports.testPropertySelectorWithEscapedBrace = function(test)
+{
+ var toHide = createElementWithStyle("{background-color: #000}");
+ applyElemHideEmulation(
+ ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"],
+ function()
+ {
+ expectHidden(test, toHide);
+ test.done();
+ }
+ );
+};
+
+exports.testPropertySelectorWithImproperlyEscapedBrace = function(test)
+{
+ var toHide = createElementWithStyle("{background-color: #000}");
+ applyElemHideEmulation(
+ ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"],
+ function()
+ {
+ expectVisible(test, toHide);
+ test.done();
+ }
+ );
+};
+
+exports.testPropertySelectorWithDynamicallyChangedProperty = function(test)
+{
+ var toHide = createElementWithStyle("{}");
+ applyElemHideEmulation(
+ ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
+ function()
+ {
+ expectVisible(test, toHide);
+ insertStyleRule("#" + toHide.id + " {background-color: #000}");
+ window.setTimeout(function()
{
- assert.visible(toHide);
- done();
- }
- );
- }
-);
-
-QUnit.test(
- "Property selector works for dynamically changed property",
- function(assert)
- {
- var done = assert.async();
- var toHide = createElementWithStyle("{}");
- applyElemHideEmulation(
- ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
- function()
- {
- assert.visible(toHide);
- insertStyleRule("#" + toHide.id + " {background-color: #000}");
- setTimeout(function()
- {
- assert.hidden(toHide);
- done();
- });
- }
- );
- }
-);
+ expectHidden(test, toHide);
+ test.done();
+ }, 0);
+ }
+ );
+};
« no previous file with comments | « test/browser/elemHideEmulation.html ('k') | test_runner.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld