summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/test-rules.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /addon-sdk/source/test/test-rules.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'addon-sdk/source/test/test-rules.js')
-rw-r--r--addon-sdk/source/test/test-rules.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/addon-sdk/source/test/test-rules.js b/addon-sdk/source/test/test-rules.js
new file mode 100644
index 000000000..705e909cb
--- /dev/null
+++ b/addon-sdk/source/test/test-rules.js
@@ -0,0 +1,79 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+'use strict';
+
+const { Rules } = require('sdk/util/rules');
+const { on, off, emit } = require('sdk/event/core');
+
+exports.testAdd = function (test, done) {
+ let rules = Rules();
+ let urls = [
+ 'http://www.firefox.com',
+ '*.mozilla.org',
+ '*.html5audio.org'
+ ];
+ let count = 0;
+ on(rules, 'add', function (rule) {
+ if (count < urls.length) {
+ test.ok(rules.get(rule), 'rule added to internal registry');
+ test.equal(rule, urls[count], 'add event fired with proper params');
+ if (++count < urls.length) rules.add(urls[count]);
+ else done();
+ }
+ });
+ rules.add(urls[0]);
+};
+
+exports.testRemove = function (test, done) {
+ let rules = Rules();
+ let urls = [
+ 'http://www.firefox.com',
+ '*.mozilla.org',
+ '*.html5audio.org'
+ ];
+ let count = 0;
+ on(rules, 'remove', function (rule) {
+ if (count < urls.length) {
+ test.ok(!rules.get(rule), 'rule removed to internal registry');
+ test.equal(rule, urls[count], 'remove event fired with proper params');
+ if (++count < urls.length) rules.remove(urls[count]);
+ else done();
+ }
+ });
+ urls.forEach(url => rules.add(url));
+ rules.remove(urls[0]);
+};
+
+exports.testMatchesAny = function(test) {
+ let rules = Rules();
+ rules.add('*.mozilla.org');
+ rules.add('data:*');
+ matchTest('http://mozilla.org', true);
+ matchTest('http://www.mozilla.org', true);
+ matchTest('http://www.google.com', false);
+ matchTest('data:text/html;charset=utf-8,', true);
+
+ function matchTest(string, expected) {
+ test.equal(rules.matchesAny(string), expected,
+ 'Expected to find ' + string + ' in rules');
+ }
+};
+
+exports.testIterable = function(test) {
+ let rules = Rules();
+ rules.add('*.mozilla.org');
+ rules.add('data:*');
+ rules.add('http://google.com');
+ rules.add('http://addons.mozilla.org');
+ rules.remove('http://google.com');
+
+ test.equal(rules.length, 3, 'has correct length of keys');
+ Array.forEach(rules, function (rule, i) {
+ test.equal(rule, ['*.mozilla.org', 'data:*', 'http://addons.mozilla.org'][i]);
+ });
+ for (let i in rules)
+ test.equal(rules[i], ['*.mozilla.org', 'data:*', 'http://addons.mozilla.org'][i]);
+};
+
+require('sdk/test').run(exports);