Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
141 lines
3.3 KiB
JavaScript
Executable file
141 lines
3.3 KiB
JavaScript
Executable file
/* global IACHandler */
|
|
'use strict';
|
|
|
|
require('/shared/js/iac_handler.js');
|
|
|
|
var MockMozSetMessageHandler_listeners = {};
|
|
function MockMozSetMessageHandler(event, listener) {
|
|
MockMozSetMessageHandler_listeners[event] = listener;
|
|
}
|
|
|
|
suite('IACHandler > ', function() {
|
|
|
|
var realMozSetMessageHandler;
|
|
var spyDispatchEvent;
|
|
|
|
var FakePort = function() {};
|
|
FakePort.prototype.postMessage = function(e) {
|
|
this.onmessage.call(this, e);
|
|
};
|
|
|
|
suiteSetup(function() {
|
|
realMozSetMessageHandler = navigator.mozSetMessageHandler;
|
|
navigator.mozSetMessageHandler = MockMozSetMessageHandler;
|
|
|
|
spyDispatchEvent = sinon.spy(window, 'dispatchEvent');
|
|
IACHandler.init();
|
|
});
|
|
|
|
suiteTeardown(function() {
|
|
navigator.mozSetMessageHandler = realMozSetMessageHandler;
|
|
spyDispatchEvent.restore();
|
|
});
|
|
|
|
suite('connect to mediacomms', function() {
|
|
var request;
|
|
var fakePort = new FakePort();
|
|
|
|
setup(function() {
|
|
|
|
request = {
|
|
keyword: 'mediacomms',
|
|
port: fakePort
|
|
};
|
|
|
|
// pretend Gecko call this event somewhere
|
|
MockMozSetMessageHandler_listeners.connection(request);
|
|
});
|
|
|
|
test('IACHandler can send to mediacomms successfully', function() {
|
|
var message = {
|
|
type: 'appinfo',
|
|
data: true
|
|
};
|
|
|
|
fakePort.postMessage({
|
|
data: message
|
|
});
|
|
assert.deepEqual(spyDispatchEvent.lastCall.args[0].detail, message);
|
|
});
|
|
});
|
|
|
|
suite('connect to ftucomms', function() {
|
|
var request;
|
|
var fakePort = new FakePort();
|
|
|
|
setup(function() {
|
|
|
|
request = {
|
|
keyword: 'ftucomms',
|
|
port: fakePort
|
|
};
|
|
|
|
// pretend Gecko call this event somewhere
|
|
MockMozSetMessageHandler_listeners.connection(request);
|
|
});
|
|
|
|
test('IACHandler can send to mediacomms successfully', function() {
|
|
var message = {
|
|
type: 'ftudone',
|
|
data: true
|
|
};
|
|
|
|
fakePort.postMessage({
|
|
data: message
|
|
});
|
|
|
|
assert.deepEqual(spyDispatchEvent.lastCall.args[0].detail, message);
|
|
});
|
|
});
|
|
|
|
suite('connect to fxa-mgmt', function() {
|
|
var request;
|
|
var fakePort = new FakePort();
|
|
|
|
setup(function() {
|
|
|
|
request = {
|
|
keyword: 'fxa-mgmt',
|
|
port: fakePort
|
|
};
|
|
|
|
// pretend Gecko call this event somewhere
|
|
MockMozSetMessageHandler_listeners.connection(request);
|
|
});
|
|
|
|
test('IACHandler can send to fxa-mgmt successfully', function() {
|
|
var message = {
|
|
method: 'getAccount'
|
|
};
|
|
|
|
fakePort.postMessage({
|
|
data: message
|
|
});
|
|
|
|
assert.deepEqual(spyDispatchEvent.lastCall.args[0].detail, message);
|
|
});
|
|
});
|
|
|
|
suite('IACHandler can store ports', function() {
|
|
|
|
test('IACHandler has three ports', function() {
|
|
assert.equal(Object.keys(IACHandler._ports).length, 3);
|
|
});
|
|
|
|
test('IACHandler.getPort() return undefined', function() {
|
|
assert.isUndefined(IACHandler.getPort());
|
|
});
|
|
|
|
test('IACHandler.getPort(\'ftucomms\') return port', function() {
|
|
assert.isObject(IACHandler.getPort('ftucomms'));
|
|
});
|
|
|
|
test('IACHandler.getPort(\'mediacomms\') return port', function() {
|
|
assert.isObject(IACHandler.getPort('mediacomms'));
|
|
});
|
|
|
|
test('IACHandler.getPort(\'fxa-mgmt\') return port', function() {
|
|
assert.isObject(IACHandler.getPort('fxa-mgmt'));
|
|
});
|
|
});
|
|
});
|