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

Unified Diff: test/browser/snippets.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created March 7, 2019, 1:14 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.js ('k') | test/caching.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/browser/snippets.js
===================================================================
--- a/test/browser/snippets.js
+++ b/test/browser/snippets.js
@@ -12,117 +12,118 @@
* 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";
+/* global assert */
+
const library = require("../../lib/content/snippets.js");
-// We need this stub for the injector.
-window.browser =
-{
- runtime:
- {
- getURL: () => ""
- }
-};
-
-let testDocument = null;
-
-exports.setUp = function(callback)
-{
- let iframe = document.createElement("iframe");
- document.body.appendChild(iframe);
- testDocument = iframe.contentDocument;
-
- callback();
-};
-
-exports.tearDown = function(callback)
+describe("Snippets", () =>
{
- let iframe = testDocument.defaultView.frameElement;
- iframe.parentNode.removeChild(iframe);
- testDocument = null;
+ before(() =>
+ {
+ // We need this stub for the injector.
+ window.browser =
+ {
+ runtime:
+ {
+ getURL: () => ""
+ }
+ };
+ });
- callback();
-};
+ let testDocument = null;
-function timeout(delay)
-{
- return new Promise((resolve, reject) =>
+ beforeEach(() =>
{
- window.setTimeout(resolve, delay);
+ let iframe = document.createElement("iframe");
+ document.body.appendChild(iframe);
+ testDocument = iframe.contentDocument;
});
-}
-async function runSnippet(test, snippetName, ...args)
-{
- let snippet = library[snippetName];
-
- test.ok(snippet);
+ afterEach(() =>
+ {
+ let iframe = testDocument.defaultView.frameElement;
+ iframe.parentNode.removeChild(iframe);
+ testDocument = null;
+ });
- snippet(...args);
- await timeout(100);
-}
+ function timeout(delay)
+ {
+ return new Promise((resolve, reject) =>
+ {
+ window.setTimeout(resolve, delay);
+ });
+ }
-exports.testAbortPropertyReadSnippet = async function(test)
-{
- window.abpTest = "foo";
+ async function runSnippet(snippetName, ...args)
+ {
+ let snippet = library[snippetName];
+
+ assert.ok(snippet);
+
+ snippet(...args);
+ await timeout(100);
+ }
async function testProperty(property, result = true)
{
let properties = property.split(".");
- test.ok(properties.length >= 1);
+ assert.ok(properties.length >= 1);
let exceptionCaught = false;
let value = 1;
try
{
let obj = window;
while (properties.length > 1)
obj = obj[properties.shift()];
value = obj[properties.shift()];
}
catch (e)
{
if (properties.length == 0)
exceptionCaught = true;
}
- test.equal(exceptionCaught, result, `The property "${property}" didn't trigger and exception.`);
- test.equal(value, result ? 1 : undefined, `The value for "${property}" shouldn't have been read.`);
+ assert.equal(exceptionCaught, result, `The property "${property}" didn't trigger and exception.`);
+ assert.equal(value, result ? 1 : undefined, `The value for "${property}" shouldn't have been read.`);
}
- await runSnippet(test, "abort-on-property-read", "abpTest");
- await testProperty("abpTest");
+ it("Test abort property read", async() =>
+ {
+ window.abpTest = "foo";
- window.abpTest2 = {prop1: "foo"};
-
- await runSnippet(test, "abort-on-property-read", "abpTest2.prop1");
- await testProperty("abpTest2.prop1");
+ await runSnippet("abort-on-property-read", "abpTest");
+ await testProperty("abpTest");
- // Test that we try to catch a property that don't exist yet.
- await runSnippet(test, "abort-on-property-read", "abpTest3.prop1");
- window.abpTest3 = {prop1: "foo"};
- await testProperty("abpTest3.prop1");
+ window.abpTest2 = {prop1: "foo"};
+
+ await runSnippet("abort-on-property-read", "abpTest2.prop1");
+ await testProperty("abpTest2.prop1");
- // Test that other properties don't trigger.
- await testProperty("abpTest3.prop2", false);
+ // Test that we try to catch a property that don't exist yet.
+ await runSnippet("abort-on-property-read", "abpTest3.prop1");
+ window.abpTest3 = {prop1: "foo"};
+ await testProperty("abpTest3.prop1");
- // Test overwriting the object with another object
- window.foo = {bar: {}};
- await runSnippet(test, "abort-on-property-read", "foo.bar.lambda");
- await testProperty("foo.bar.lambda");
- window.foo.bar = {};
- await testProperty("foo.bar.lambda");
+ // Test that other properties don't trigger.
+ await testProperty("abpTest3.prop2", false);
- // Test if we start with a non-object
- window.foo2 = 5;
- await runSnippet(test, "abort-on-property-read", "foo2.bar2.lambda");
- await testProperty("foo2.bar2.lambda");
- window.foo2 = {};
- await testProperty("foo2.bar2.lambda");
+ // Test overwriting the object with another object
+ window.foo = {bar: {}};
+ await runSnippet("abort-on-property-read", "foo.bar.lambda");
+ await testProperty("foo.bar.lambda");
+ window.foo.bar = {};
+ await testProperty("foo.bar.lambda");
- test.done();
-};
-
+ // Test if we start with a non-object
+ window.foo2 = 5;
+ await runSnippet("abort-on-property-read", "foo2.bar2.lambda");
+ await testProperty("foo2.bar2.lambda");
+ window.foo2 = {};
+ await testProperty("foo2.bar2.lambda");
+ });
+});
« no previous file with comments | « test/browser/elemHideEmulation.js ('k') | test/caching.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld