summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/test-host-events.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
commit37d5300335d81cecbecc99812747a657588c63eb (patch)
tree765efa3b6a56bb715d9813a8697473e120436278 /addon-sdk/source/test/test-host-events.js
parentb2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff)
parent4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff)
downloadUXP-37d5300335d81cecbecc99812747a657588c63eb.tar
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz
UXP-37d5300335d81cecbecc99812747a657588c63eb.zip
Merge branch 'ext-work'
Diffstat (limited to 'addon-sdk/source/test/test-host-events.js')
-rw-r--r--addon-sdk/source/test/test-host-events.js99
1 files changed, 0 insertions, 99 deletions
diff --git a/addon-sdk/source/test/test-host-events.js b/addon-sdk/source/test/test-host-events.js
deleted file mode 100644
index 1c6664534..000000000
--- a/addon-sdk/source/test/test-host-events.js
+++ /dev/null
@@ -1,99 +0,0 @@
-/* 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 { Cc, Ci } = require('chrome');
-const { defer, all } = require('sdk/core/promise');
-const { setTimeout } = require('sdk/timers');
-const { request, response } = require('sdk/addon/host');
-const { send } = require('sdk/addon/events');
-const { filter } = require('sdk/event/utils');
-const { on, emit, off } = require('sdk/event/core');
-
-var stream = filter(request, (data) => /sdk-x-test/.test(data.event));
-
-exports.testSend = function (assert, done) {
- on(stream, 'data', handle);
- send('sdk-x-test-simple', { title: 'my test data' }).then((data) => {
- assert.equal(data.title, 'my response', 'response is handled');
- off(stream, 'data', handle);
- done();
- }, (reason) => {
- assert.fail('should not call reject');
- });
- function handle (e) {
- assert.equal(e.event, 'sdk-x-test-simple', 'correct event name');
- assert.ok(e.id != null, 'message has an ID');
- assert.equal(e.data.title, 'my test data', 'serialized data passes');
- e.data.title = 'my response';
- emit(response, 'data', e);
- }
-};
-
-exports.testSendError = function (assert, done) {
- on(stream, 'data', handle);
- send('sdk-x-test-error', { title: 'my test data' }).then((data) => {
- assert.fail('should not call success');
- }, (reason) => {
- assert.equal(reason, 'ErrorInfo', 'should reject with error/reason');
- off(stream, 'data', handle);
- done();
- });
- function handle (e) {
- e.error = 'ErrorInfo';
- emit(response, 'data', e);
- }
-};
-
-exports.testMultipleSends = function (assert, done) {
- let count = 0;
- let ids = [];
- on(stream, 'data', handle);
- ['firefox', 'thunderbird', 'rust'].map(data =>
- send('sdk-x-test-multi', { data: data }).then(val => {
- assert.ok(val === 'firefox' || val === 'rust', 'successful calls resolve correctly');
- if (++count === 3) {
- off(stream, 'data', handle);
- done();
- }
- }, reason => {
- assert.equal(reason.error, 'too blue', 'rejected calls are rejected');
- if (++count === 3) {
- off(stream, 'data', handle);
- done();
- }
- }));
-
- function handle (e) {
- if (e.data !== 'firefox' || e.data !== 'rust')
- e.error = { data: e.data, error: 'too blue' };
- assert.ok(!~ids.indexOf(e.id), 'ID should be unique');
- assert.equal(e.event, 'sdk-x-test-multi', 'has event name');
- ids.push(e.id);
- emit(response, 'data', e);
- }
-};
-
-exports.testSerialization = function (assert, done) {
- on(stream, 'data', handle);
- let object = { title: 'my test data' };
- let resObject;
- send('sdk-x-test-serialize', object).then(data => {
- data.title = 'another title';
- assert.equal(object.title, 'my test data', 'original object not modified');
- assert.equal(resObject.title, 'new title', 'object passed by value from host');
- off(stream, 'data', handle);
- done();
- }, (reason) => {
- assert.fail('should not call reject');
- });
- function handle (e) {
- e.data.title = 'new title';
- assert.equal(object.title, 'my test data', 'object passed by value to host');
- resObject = e.data;
- emit(response, 'data', e);
- }
-};
-
-require('sdk/test').run(exports);