Publish Vulpes Preview 15 sources for desktop, Android and Tundra

Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
OverSu 2026-09-30 23:13:03 +02:00
commit b38dea0597
25901 changed files with 9982925 additions and 369 deletions

View file

@ -0,0 +1,27 @@
'use strict';
/* jshint node: true, mocha: true */
/* global suiteSetup */
var helper = require('helper');
suite('Wappush tests', function() {
suiteSetup(helper.cleanupWorkspace);
teardown(helper.cleanupWorkspace);
test('APP=wappush make', function(done) {
helper.exec('APP=wappush make', function(error, stdout, stderr) {
helper.checkError(error, stdout, stderr);
var zipPath = process.cwd() +
'/profile/webapps/wappush.gaiamobile.org/application.zip';
var checkList = ['manifest.webapp'];
checkList.forEach(function(filePath) {
helper.checkFilePathInZip(zipPath, filePath);
});
done();
});
});
});

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../.jshintrc",
"predef": [
"assert",
"suite",
"test",
"setup",
"teardown",
"suiteSetup",
"suiteTeardown",
"require",
"requireApp",
"sinon",
"mocha",
"loadBodyHTML"
]
}

View file

@ -0,0 +1,91 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global ActivityPicker, MockL10n, MocksHelper, MozActivity */
'use strict';
require('/shared/test/unit/mocks/mock_l10n.js');
requireApp('wappush/js/activity_picker.js');
requireApp('wappush/test/unit/mock_moz_activity.js');
var mocksHelperAP = new MocksHelper([
'MozActivity'
]).init();
suite('ActivityPicker', function() {
var realMozL10n, onsuccess, onerror;
mocksHelperAP.attachTestHelpers();
suiteSetup(function() {
realMozL10n = navigator.mozL10n;
navigator.mozL10n = MockL10n;
onsuccess = function() {};
onerror = function() {};
});
suiteTeardown(function() {
navigator.mozL10n = realMozL10n;
});
setup(function() {
mocksHelperAP.setup();
});
teardown(function() {
mocksHelperAP.teardown();
});
suite('url', function() {
test('url(url) ', function() {
ActivityPicker.url('http://mozilla.com');
assert.deepEqual(MozActivity.calls[0], {
name: 'view',
data: {
type: 'url',
url: 'http://mozilla.com'
}
});
});
test('url(url, success) ', function() {
ActivityPicker.url('http://mozilla.com', onsuccess);
assert.equal(
MozActivity.instances[0].onsuccess, onsuccess
);
assert.deepEqual(MozActivity.calls[0], {
name: 'view',
data: {
type: 'url',
url: 'http://mozilla.com'
}
});
});
test('url(url, success, error) ', function() {
ActivityPicker.url('http://mozilla.com', onsuccess, onerror);
assert.equal(
MozActivity.instances[0].onsuccess, onsuccess
);
assert.equal(
MozActivity.instances[0].onerror, onerror
);
assert.deepEqual(MozActivity.calls[0], {
name: 'view',
data: {
type: 'url',
url: 'http://mozilla.com'
}
});
});
});
});

View file

@ -0,0 +1,148 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global ProvisioningAuthentication */
'use strict';
requireApp('wappush/js/ext/CryptoJSv3.1.2/rollups/hmac-sha1.js');
requireApp('wappush/js/auth.js');
suite('ProvisioningAuthentication >', function() {
suite('ProvisioningAuthentication.isDocumentValid()', function() {
var USER_PIN = '1234567890';
var USER_PIN_AUTH_INFO;
test('Unknow security mechanism', function() {
USER_PIN_AUTH_INFO = {
sec: 'FAKEMECHANISM'
};
assert.throw(
function() {
ProvisioningAuthentication.isDocumentValid(USER_PIN,
USER_PIN_AUTH_INFO);
},
'cp-finish-confirm-dialog-message-auth-unsupported-mechanism'
);
});
test('NETWPIN security mechanism should not be called', function() {
USER_PIN_AUTH_INFO = {
sec: 'NETWPIN'
};
assert.throw(
function() {
ProvisioningAuthentication.isDocumentValid(USER_PIN,
USER_PIN_AUTH_INFO);
},
'cp-finish-confirm-dialog-message-auth-error'
);
});
test('USERNETWPIN security mechanism is not supported yet', function() {
USER_PIN_AUTH_INFO = {
sec: 'USERNETWPIN'
};
assert.throw(
function() {
ProvisioningAuthentication.isDocumentValid(USER_PIN,
USER_PIN_AUTH_INFO);
},
'cp-finish-confirm-dialog-message-auth-unsupported-mechanism'
);
});
test('USERPINMAC security mechanism is not supported yet', function() {
USER_PIN_AUTH_INFO = {
sec: 'USERPINMAC'
};
assert.throw(
function() {
ProvisioningAuthentication.isDocumentValid(USER_PIN,
USER_PIN_AUTH_INFO);
},
'cp-finish-confirm-dialog-message-auth-unsupported-mechanism'
);
});
test('A message with USERPIN security mechanism was authenticated',
function() {
var wbxml = new Uint8Array([
0x03, 0x0B, 0x6A, 0x00, 0x45, 0xC6, 0x56, 0x01,
0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x01,
0xC6, 0x00, 0x01, 0x55, 0x01, 0x87, 0x36, 0x00,
0x00, 0x06, 0x03, 0x77, 0x32, 0x00, 0x01, 0x87,
0x00, 0x01, 0x39, 0x00, 0x00, 0x06, 0x03, 0x57,
0x50, 0x52, 0x4F, 0x58, 0x59, 0x00, 0x01, 0x87,
0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F, 0x65,
0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0xC6, 0x00,
0x01, 0x59, 0x01, 0x87, 0x3A, 0x00, 0x00, 0x06,
0x03, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F,
0x77, 0x61, 0x70, 0x2E, 0x65, 0x6D, 0x6F, 0x6D,
0x65, 0x2E, 0x6E, 0x65, 0x74, 0x2F, 0x00, 0x01,
0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x87,
0x1C, 0x01, 0x01, 0x01, 0xC6, 0x00, 0x01, 0x55,
0x01, 0x87, 0x36, 0x00, 0x00, 0x06, 0x03, 0x77,
0x34, 0x00, 0x01, 0x87, 0x00, 0x01, 0x39, 0x00,
0x00, 0x06, 0x03, 0x4D, 0x50, 0x52, 0x4F, 0x58,
0x59, 0x00, 0x01, 0x87, 0x00, 0x01, 0x34, 0x00,
0x00, 0x06, 0x03, 0x68, 0x74, 0x74, 0x70, 0x3A,
0x2F, 0x2F, 0x6D, 0x6D, 0x73, 0x3A, 0x38, 0x30,
0x30, 0x32, 0x00, 0x01, 0x01, 0xC6, 0x51, 0x01,
0x87, 0x15, 0x06, 0x03, 0x57, 0x50, 0x52, 0x4F,
0x58, 0x59, 0x00, 0x01, 0x87, 0x07, 0x06, 0x03,
0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F, 0x6D,
0x65, 0x00, 0x01, 0x87, 0x1C, 0x06, 0x03, 0x68,
0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x61,
0x70, 0x2E, 0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x2E,
0x6E, 0x65, 0x74, 0x2F, 0x00, 0x01, 0xC6, 0x52,
0x01, 0x87, 0x2F, 0x06, 0x03, 0x50, 0x52, 0x4F,
0x58, 0x59, 0x31, 0x00, 0x01, 0x87, 0x20, 0x06,
0x03, 0x31, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x2E,
0x31, 0x00, 0x01, 0x87, 0x21, 0x06, 0x85, 0x01,
0x87, 0x22, 0x06, 0x03, 0x43, 0x48, 0x54, 0x5F,
0x65, 0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0xC6,
0x53, 0x01, 0x87, 0x23, 0x06, 0x03, 0x38, 0x30,
0x38, 0x30, 0x00, 0x01, 0x01, 0x01, 0x01, 0xC6,
0x51, 0x01, 0x87, 0x15, 0x06, 0x03, 0x4D, 0x50,
0x52, 0x4F, 0x58, 0x59, 0x00, 0x01, 0x87, 0x07,
0x06, 0x03, 0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D,
0x53, 0x00, 0x01, 0xC6, 0x52, 0x01, 0x87, 0x2F,
0x06, 0x03, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x32,
0x00, 0x01, 0x87, 0x20, 0x06, 0x03, 0x31, 0x30,
0x2E, 0x31, 0x2E, 0x31, 0x2E, 0x31, 0x00, 0x01,
0x87, 0x21, 0x06, 0x85, 0x01, 0x87, 0x22, 0x06,
0x03, 0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D, 0x53,
0x00, 0x01, 0xC6, 0x53, 0x01, 0x87, 0x23, 0x06,
0x03, 0x38, 0x30, 0x38, 0x30, 0x00, 0x01, 0x01,
0x01, 0x01, 0xC6, 0x55, 0x01, 0x87, 0x11, 0x06,
0x03, 0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F,
0x6D, 0x65, 0x00, 0x01, 0x87, 0x07, 0x06, 0x03,
0x43, 0x48, 0x54, 0x5F, 0x65, 0x6D, 0x6F, 0x6D,
0x65, 0x00, 0x01, 0x87, 0x10, 0x06, 0xAB, 0x01,
0x87, 0x08, 0x06, 0x03, 0x65, 0x6D, 0x6F, 0x6D,
0x65, 0x00, 0x01, 0x87, 0x09, 0x06, 0x89, 0x01,
0x01, 0xC6, 0x55, 0x01, 0x87, 0x11, 0x06, 0x03,
0x43, 0x48, 0x54, 0x5F, 0x4D, 0x4D, 0x53, 0x00,
0x01, 0x87, 0x07, 0x06, 0x03, 0x43, 0x48, 0x54,
0x5F, 0x4D, 0x4D, 0x53, 0x00, 0x01, 0x87, 0x10,
0x06, 0xAB, 0x01, 0x87, 0x08, 0x06, 0x03, 0x65,
0x6D, 0x6F, 0x6D, 0x65, 0x00, 0x01, 0x87, 0x09,
0x06, 0x89, 0x01, 0x01, 0x01
]);
USER_PIN = '0000';
USER_PIN_AUTH_INFO = {
sec: 'USERPIN',
mac: 'AA2DC41FC48AEEF3FED7351B1EE704461A8894D4',
data: wbxml
};
assert.isTrue(
ProvisioningAuthentication.isDocumentValid(USER_PIN,
USER_PIN_AUTH_INFO)
);
});
});
});

View file

@ -0,0 +1,75 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global ActivityPicker, LinkActionHandler, MockL10n, MocksHelper */
'use strict';
require('/shared/test/unit/mocks/mock_l10n.js');
requireApp('wappush/js/link_action_handler.js');
requireApp('wappush/test/unit/mock_activity_picker.js');
requireApp('wappush/test/unit/mock_moz_activity.js');
var mocksHelperLAH = new MocksHelper([
'ActivityPicker',
'MozActivity'
]).init();
suite('LinkActionHandler', function() {
var realMozL10n, events;
mocksHelperLAH.attachTestHelpers();
suiteSetup(function() {
realMozL10n = navigator.mozL10n;
navigator.mozL10n = MockL10n;
events = {
url: {
target: {
dataset: {
action: 'url-link',
url: 'http://mozilla.com'
}
}
}
};
});
suiteTeardown(function() {
navigator.mozL10n = realMozL10n;
});
setup(function() {
Object.keys(events).forEach(function(type) {
events[type].preventDefault = this.sinon.spy();
events[type].stopPropagation = this.sinon.spy();
}, this);
mocksHelperLAH.setup();
});
teardown(function() {
mocksHelperLAH.teardown();
});
suite('onClick', function() {
setup(function() {
mocksHelperLAH.setup();
});
teardown(function() {
LinkActionHandler.reset();
mocksHelperLAH.teardown();
});
test('url-link ', function() {
LinkActionHandler.onClick(events.url);
assert.ok(ActivityPicker.url.called);
assert.equal(ActivityPicker.url.calledWith[0], 'http://mozilla.com');
});
});
});

View file

@ -0,0 +1,327 @@
/* global MessageDB */
'use strict';
require('/shared/js/event_dispatcher.js');
require('/js/messagedb.js');
suite('MessageDB', function() {
var messages = {
current: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '1',
href: 'http://www.mozilla.org',
id: 'gaia-test@mozilla.org',
created: (new Date('2013-09-03T10:35:33Z')).getTime(),
action: 'signal-medium',
text: 'check this out'
},
older: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '2',
href: 'http://www.mozilla.org',
id: 'gaia-test@mozilla.org',
created: (new Date('2013-09-03T10:35:32Z')).getTime(),
action: 'signal-medium',
text: 'older message'
},
newer: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '3',
href: 'http://www.mozilla.org',
id: 'gaia-test@mozilla.org',
created: (new Date('2013-09-03T10:35:34Z')).getTime(),
action: 'signal-medium',
text: 'newer message'
},
delete: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '3',
href: 'http://www.mozilla.org',
id: 'gaia-test@mozilla.org',
action: 'delete',
text: ''
},
old_delete: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '4',
href: 'http://www.mozilla.org',
id: 'gaia-test@mozilla.org',
created: (new Date('2013-09-03T10:35:32Z')).getTime(),
action: 'delete',
text: ''
},
low: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '5',
href: 'http://www.mozilla.org',
id: 'http://www.mozilla.org',
action: 'signal-low',
text: 'check this out'
},
medium: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '6',
href: 'http://www.mozilla.org',
id: 'http://www.mozilla.org',
action: 'signal-medium',
text: 'check this out'
},
high: {
type: 'text/vnd.wap.si',
sender: '+31641600986',
serviceId: 0,
timestamp: '7',
href: 'http://www.mozilla.org',
id: 'http://www.mozilla.org',
action: 'signal-high',
text: 'check this out'
},
sl: {
type: 'text/vnd.wap.sl',
sender: '+31641600986',
serviceId: 0,
timestamp: '8',
href: 'http://www.mozilla.org'
}
};
setup(function(done) {
MessageDB.clear().then(done, done);
});
teardown(function() {
MessageDB.offAll();
});
suite('storing and retrieving messages', function() {
var onNewStub;
setup(function() {
MessageDB.on('new', onNewStub = this.sinon.stub());
});
test('message is stored', function(done) {
MessageDB.put(messages.current).then(function() {
return MessageDB.retrieve(messages.current.timestamp);
}).then(function(message) {
sinon.assert.calledOnce(onNewStub);
sinon.assert.calledWith(onNewStub, message);
assert.equal(message.type, messages.current.type);
assert.equal(message.sender, messages.current.sender);
assert.equal(message.serviceId, messages.current.serviceId);
assert.equal(message.href, messages.current.href);
assert.equal(message.text, messages.current.text);
}).then(done, done);
});
test('non-SI message is stored', function(done) {
MessageDB.put(messages.sl).then(function() {
return MessageDB.retrieve(messages.sl.timestamp);
}).then(function(message) {
sinon.assert.calledOnce(onNewStub);
sinon.assert.calledWith(onNewStub, message);
assert.equal(message.type, messages.sl.type);
assert.equal(message.sender, messages.sl.sender);
assert.equal(message.serviceId, messages.sl.serviceId);
assert.equal(message.href, messages.sl.href);
}).then(done, done);
});
});
suite('handling multiple messages', function() {
var onNewStub;
setup(function() {
MessageDB.on('new', onNewStub = this.sinon.stub());
});
test('storing multiple messages with the same si-id', function(done) {
var results = {};
MessageDB.put(messages.low).then(function(message) {
return MessageDB.put(messages.medium);
}).then(function(message) {
return MessageDB.put(messages.high);
}).then(function(message) {
return MessageDB.retrieve(messages.low.timestamp);
}).then(function(message) {
results.low = message;
return MessageDB.retrieve(messages.medium.timestamp);
}).then(function(message) {
results.medium = message;
return MessageDB.retrieve(messages.high.timestamp);
}).then(function(message) {
results.high = message;
sinon.assert.calledThrice(onNewStub);
assert.equal(onNewStub.args[0][0], messages.low);
assert.equal(results.low.id, messages.low.id);
assert.equal(results.low.action, messages.low.action);
assert.equal(onNewStub.args[1][0], messages.medium);
assert.equal(results.medium.id, messages.medium.id);
assert.equal(results.medium.action, messages.medium.action);
assert.equal(onNewStub.args[2][0], messages.high);
assert.equal(results.high.id, messages.high.id);
assert.equal(results.high.action, messages.high.action);
}).then(done, done);
});
});
suite('out-of-order message handling', function() {
var onNewStub;
var onDiscardedStub;
var onUpdatedStub;
setup(function() {
MessageDB.on('new', onNewStub = this.sinon.stub());
MessageDB.on('update', onUpdatedStub = this.sinon.stub());
MessageDB.on('discard', onDiscardedStub = this.sinon.stub());
});
test('message is updated by newer message', function(done) {
var results = {};
MessageDB.put(messages.current).then(function() {
sinon.assert.calledOnce(onNewStub);
sinon.assert.calledWith(onNewStub, messages.current);
return MessageDB.put(messages.newer);
}).then(function() {
sinon.assert.calledOnce(onUpdatedStub);
sinon.assert.calledWith(onUpdatedStub, messages.newer);
return MessageDB.retrieve(messages.newer.timestamp);
}).then(function(message) {
results.timestamp = message.timestamp;
results.text = message.text;
assert.equal(results.timestamp, messages.current.timestamp);
assert.equal(results.text, messages.newer.text);
}).then(done, done);
});
test('old message is discarded', function(done) {
MessageDB.put(messages.current).then(function() {
sinon.assert.calledOnce(onNewStub);
sinon.assert.calledWith(onNewStub, messages.current);
return MessageDB.put(messages.older);
}).then(function() {
sinon.assert.calledOnce(onDiscardedStub);
sinon.assert.calledWith(onDiscardedStub, messages.older);
return MessageDB.retrieve(messages.older.timestamp);
}).then(function() {
assert(false, 'The promise should be rejected');
}, function() {}).then(done, done);
});
});
suite('message actions', function() {
var onDeletedStub;
var onDiscardedStub;
setup(function() {
MessageDB.on('delete', onDeletedStub = this.sinon.stub());
MessageDB.on('discard', onDiscardedStub = this.sinon.stub());
});
test('delete action removes all message with same id', function(done) {
MessageDB.put(messages.current).then(function() {
return MessageDB.put(messages.delete);
}).then(function() {
return MessageDB.retrieve(messages.current.timestamp);
}).then(function() {
assert(false, 'The promise should be rejected');
}, function() {}).then(done, done);
});
test('delete action messages are never stored', function(done) {
MessageDB.put(messages.delete).then(function() {
return MessageDB.retrieve(messages.delete.timestamp);
}).then(function() {
assert(false, 'The promise should be rejected');
}, function() {
sinon.assert.calledOnce(onDiscardedStub);
sinon.assert.calledWith(onDiscardedStub, messages.delete);
}).then(done, done);
});
test('delete action messages dispatch a \'deleted\' event',
function(done) {
MessageDB.put(messages.current).then(function() {
return MessageDB.put(messages.delete);
}).then(function() {
sinon.assert.calledOnce(onDeletedStub);
sinon.assert.calledWith(onDeletedStub, messages.current);
}).then(done, done);
});
test('old delete action is ignored', function(done) {
MessageDB.put(messages.current).then(function() {
return MessageDB.put(messages.old_delete);
}).then(function() {
sinon.assert.notCalled(onDeletedStub);
return MessageDB.retrieve(messages.current.timestamp);
}).then(function(message) {
sinon.assert.calledOnce(onDiscardedStub);
sinon.assert.calledWith(onDiscardedStub, messages.old_delete);
assert.ok(message);
}).then(done, done);
});
});
suite('deleting messages', function() {
var onDeletedStub;
setup(function() {
MessageDB.on('delete', onDeletedStub = this.sinon.stub());
});
test('delete messages by timestamp', function(done) {
MessageDB.put(messages.low).then(function(status) {
return MessageDB.put(messages.medium);
}).then(function(status) {
return MessageDB.put(messages.high);
}).then(function(status) {
return MessageDB.deleteByTimestamp(messages.low.timestamp);
}).then(function() {
return MessageDB.deleteByTimestamp(messages.medium.timestamp);
}).then(function() {
return MessageDB.deleteByTimestamp(messages.high.timestamp);
}).then(function() {
return MessageDB.retrieve(messages.low.timestamp);
}).then(function() {
assert(false, 'The promise should be rejected');
}, function() {
return MessageDB.retrieve(messages.medium.timestamp);
}).then(function() {
assert(false, 'The promise should be rejected');
}, function() {
return MessageDB.retrieve(messages.high.timestamp);
}).then(function() {
assert(false, 'The promise should be rejected');
}, function() {}).then(done, done);
});
test('a \'deleted\' event is dispatched', function(done) {
MessageDB.put(messages.current).then(function() {
return MessageDB.deleteByTimestamp(messages.current.timestamp);
}).then(function() {
sinon.assert.calledOnce(onDeletedStub);
sinon.assert.calledWith(onDeletedStub, messages.current);
}).then(done, done);
});
});
});

View file

@ -0,0 +1,25 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
var MockActivityPicker = {};
[
'url'
].forEach(function(fn) {
MockActivityPicker[fn] = function() {
MockActivityPicker[fn].called = true;
MockActivityPicker[fn].calledWith = [].slice.call(arguments);
};
MockActivityPicker[fn].mSetup = function() {
MockActivityPicker[fn].called = false;
MockActivityPicker[fn].calledWith = null;
};
MockActivityPicker[fn].mTeardown = function() {
delete MockActivityPicker[fn].called;
delete MockActivityPicker[fn].calledWith;
};
});

View file

@ -0,0 +1,12 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* exported MockLinkActionHandler */
'use strict';
var MockLinkActionHandler = {
reset: function() {},
onContextMenu: function() {},
onClick: function() {}
};

View file

@ -0,0 +1,15 @@
/* exported MockMessageDB */
'use strict';
var MockMessageDB = {
put: function() {},
retrieve: function() {},
deleteByTimestamp: function() {},
clear: function() {},
on: function() {},
once: function() {},
off: function() {},
offAll: function() {},
emit: function() {}
};

View file

@ -0,0 +1,24 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
function MockMozActivity(activity) {
MockMozActivity.calls.push(activity);
MockMozActivity.instances.push(this);
this.onsuccess = function() {};
this.onerror = function() {};
}
// create an array to hold any calls to this function to test them
MockMozActivity.mSetup = function() {
MockMozActivity.calls = [];
MockMozActivity.instances = [];
};
// destroy the array so it resets every time
MockMozActivity.mTeardown = function() {
delete MockMozActivity.calls;
delete MockMozActivity.instances;
};

View file

@ -0,0 +1,30 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* exported MockParsedProvisioningDoc */
'use strict';
var MockParsedProvisioningDoc = {
_apns: [],
mSetup: function mwl_setup(apns) {
if (apns) {
this._apns = apns;
}
},
from: function mppd_from(provisioningDoc) {
var apns = this._apns;
return {
getApns: function mppd_getApns() {
return apns;
}
};
},
mTeardown: function mwl_teardown() {
this._apns = [];
}
};

View file

@ -0,0 +1,34 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* exported MockWhiteList */
'use strict';
var MockWhiteList = {
_whiteList: [],
init: function mwl_init() {
return new Promise(function mwl_init_promise(resolve) {
resolve();
});
},
has: function mwl_has(value) {
if (this._whiteList.length === 0) {
return true;
}
return (this._whiteList.indexOf(value) !== -1);
},
mSetup: function mwl_setup(list) {
if (list) {
this._whiteList = list;
}
},
mTeardown: function mwl_teardown() {
this._whiteList = [];
}
};

View file

@ -0,0 +1,325 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global ParsedProvisioningDoc */
'use strict';
requireApp('wappush/js/parsed_doc.js');
suite('ParsedProvisioningDoc >', function() {
suite('ParsedProvisioningDoc.from()', function() {
test('Empty document. List of APN is empty', function() {
var parsedProvisioningDoc;
var provisioningDoc = '';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 0);
});
test('TEF document with default APN', function() {
var parsedProvisioningDoc;
var provisioningDoc =
'<wap-provisioningdoc>' +
'<characteristic type="PXLOGICAL">' +
'<parm name="PROXY-ID" value="10.138.255.133"/>' +
'<parm name="NAME" value="Telefonica"/>' +
'<parm name="STARTPAGE" value="http://www.movistar.es"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="8080"/>' +
'<parm name="SERVICE" value="CO-WSP"/>' +
'</characteristic>' +
'<characteristic type="PXPHYSICAL">' +
'<parm name="PHYSICAL-PROXY-ID" value="PRX1"/>' +
'<parm name="PXADDR" value="10.138.255.133"/>' +
'<parm name="PXADDRTYPE" value="IPV4"/>' +
'<parm name="TO-NAPID" value="NAP1"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="8080"/>' +
'<parm name="SERVICE" value="CO-WSP"/>' +
'</characteristic>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="NAP1"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAME" value="Telefonica"/>' +
'<parm name="NAP-ADDRESS" value="telefonica.es"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'<characteristic type="NAPAUTHINFO">' +
'<parm name="AUTHTYPE" value="PAP"/>' +
'<parm name="AUTHNAME" value="telefonica"/>' +
'<parm name="AUTHSECRET" value="telefonica"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="w2"/>' +
'<parm name="TO-PROXY" value="10.138.255.133"/>' +
'<parm name="NAME" value="Telefonica"/>' +
'</characteristic>' +
'</wap-provisioningdoc>';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 1);
});
test('CHT document with default and mms APN', function() {
var parsedProvisioningDoc;
var provisioningDoc =
'<wap-provisioningdoc>' +
'<characteristic type="BOOTSTRAP">' +
'<parm name="NAME" value="CHT_emome"/>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="w2"/>' +
'<parm name="TO-PROXY" value="WPROXY"/>' +
'<parm name="NAME" value="CHT_emome"/>' +
'<characteristic type="RESOURCE">' +
'<parm name="URI" value="http://wap.emome.net/"/>' +
'<parm name="NAME" value="CHT_emome"/>' +
'<parm name="STARTPAGE"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="w4"/>' +
'<parm name="TO-PROXY" value="MPROXY"/>' +
'<parm name="ADDR" value="http://mms:8002"/>' +
'</characteristic>' +
'<characteristic type="PXLOGICAL">' +
'<parm name="PROXY-ID" value="WPROXY"/>' +
'<parm name="NAME" value="CHT_emome"/>' +
'<parm name="STARTPAGE" value="http://wap.emome.net/"/>' +
'<characteristic type="PXPHYSICAL">' +
'<parm name="PHYSICAL-PROXY-ID" value="PROXY1"/>' +
'<parm name="PXADDR" value="10.1.1.1"/>' +
'<parm name="PXADDRTYPE" value="IPV4"/>' +
'<parm name="TO-NAPID" value="CHT_emome"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="8080"/>' +
'</characteristic>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="PXLOGICAL">' +
'<parm name="PROXY-ID" value="MPROXY"/>' +
'<parm name="NAME" value="CHT_MMS"/>' +
'<characteristic type="PXPHYSICAL">' +
'<parm name="PHYSICAL-PROXY-ID" value="PROXY2"/>' +
'<parm name="PXADDR" value="10.1.1.1"/>' +
'<parm name="PXADDRTYPE" value="IPV4"/>' +
'<parm name="TO-NAPID" value="CHT_MMS"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="8080"/>' +
'</characteristic>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="CHT_emome"/>' +
'<parm name="NAME" value="CHT_emome"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAP-ADDRESS" value="emome"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="CHT_MMS"/>' +
'<parm name="NAME" value="CHT_MMS"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<Parm name="NAP-ADDRESS" value="emome"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'</characteristic>' +
'</wap-provisioningdoc>';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 2);
});
test('TEF document without APPLICATION nodes', function() {
var parsedProvisioningDoc;
var provisioningDoc =
'<wap-provisioningdoc>' +
'<characteristic type="PXLOGICAL">' +
'<parm name="PROXY-ID" value="10.138.255.133"/>' +
'<parm name="NAME" value="Telefonica"/>' +
'<parm name="STARTPAGE" value="http://www.movistar.es"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="8080"/>' +
'<parm name="SERVICE" value="CO-WSP"/>' +
'</characteristic>' +
'<characteristic type="PXPHYSICAL">' +
'<parm name="PHYSICAL-PROXY-ID" value="PRX1"/>' +
'<parm name="PXADDR" value="10.138.255.133"/>' +
'<parm name="PXADDRTYPE" value="IPV4"/>' +
'<parm name="TO-NAPID" value="NAP1"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="8080"/>' +
'<parm name="SERVICE" value="CO-WSP"/>' +
'</characteristic>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="NAP1"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAME" value="Telefonica"/>' +
'<parm name="NAP-ADDRESS" value="telefonica.es"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'<characteristic type="NAPAUTHINFO">' +
'<parm name="AUTHTYPE" value="PAP"/>' +
'<parm name="AUTHNAME" value="telefonica"/>' +
'<parm name="AUTHSECRET" value="telefonica"/>' +
'</characteristic>' +
'</characteristic>' +
'</wap-provisioningdoc>';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 0);
});
test('TEF document without valid APPLICATION nodes', function() {
var parsedProvisioningDoc;
var provisioningDoc =
'<wap-provisioningdoc>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="Yahoo"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAME" value="Yahoo"/>' +
'<parm name="NAP-ADDRESS" value="movistar.es"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'<characteristic type="NAPAUTHINFO">' +
'<parm name="AUTHTYPE" value="PAP"/>' +
'<parm name="AUTHNAME" value=""/>' +
'<parm name="AUTHSECRET" value=""/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="25"/>' +
'<parm name="PROVIDER-ID" value="Yahoo"/>' +
'<parm name="NAME" value="Yahoo"/>' +
'<parm name="FROM" value="owdqa_test1@yahoo.es"/>' +
'<parm name="TO-NAPID" value="Yahoo"/>' +
'<characteristic type="APPADDR">' +
'<parm name="ADDR" value="smtp.yahoo.es"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="25"/>' +
'</characteristic>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="110"/>' +
'<parm name="PROVIDER-ID" value="Yahoo"/>' +
'<parm name="NAME" value="Yahoo"/>' +
'<parm name="TO-NAPID" value="Yahoo"/>' +
'<characteristic type="APPADDR">' +
'<parm name="ADDR" value="pop.yahoo.es"/>' +
'<characteristic type="PORT">' +
'<parm name="PORTNBR" value="110"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPAUTH">' +
'<parm name="AAUTHNAME" value="owdqa_test1@yahoo.es"/>' +
'<parm name="AAUTHSECRET"/>' +
'</characteristic>' +
'</characteristic>' +
'</wap-provisioningdoc>';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 0);
});
test('DT document without TO-PROXY nodes in the APPLICATION nodes',
function() {
var parsedProvisioningDoc;
var provisioningDoc =
'<wap-provisioningdoc version="1.0">' +
'<characteristic type="BOOTSTRAP">' +
'<parm name="NAME" value="T-Mobile Internet"/>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="internet-apn"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAME" value="T-Mobile Internet"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'<parm name="NAP-ADDRESS" value="internet.t-mobile"/>' +
'<parm name="LINGER" value="150"/>' +
'<parm name="DNS-ADDR" value="193.254.160.001"/>' +
'<parm name="DNS-ADDR" value="193.254.160.130"/>' +
'<characteristic type="NAPAUTHINFO">' +
'<parm name="AUTHTYPE" value="PAP"/>' +
'<parm name="AUTHNAME" value="t-mobile"/>' +
'<parm name="AUTHSECRET" value="tm"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="w2"/>' +
'<parm name="TO-NAPID" value="internet-apn"/>' +
'<parm name="NAME" value="T-Mobile Internet"/>' +
'<characteristic type="RESOURCE">' +
'<parm name="NAME" value="Start page"/>' +
'<parm name="URI" value="http://www.t-mobile-favoriten.de"/>' +
'<parm name="STARTPAGE"/>' +
'</characteristic>' +
'</characteristic>' +
'</wap-provisioningdoc>';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 1);
});
test('Document without matched PROXY-ID node for a TO-PROXY node',
function() {
var parsedProvisioningDoc;
var provisioningDoc =
'<wap-provisioningdoc version="1.0">' +
'<characteristic type="PXLOGICAL">' +
'<parm name="PROXY-ID" value="www.operator.com"/>' +
'<parm name="NAME" value="GW WAP"/>' +
'<characteristic type="PXPHYSICAL">' +
'<parm name="PHYSICAL-PROXY-ID" value="PROXY_WAP_3"/>' +
'<parm name="PXADDR" value="172.150.70.5"/>' +
'<parm name="PXADDRTYPE" value="IPV4"/>' +
'<parm name="TO-NAPID" value="WAP_GPRS"/>' +
'<parm name="TO-NAPID" value="WAP_CSD"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="WAP_GPRS"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAME" value="operator GPRS"/>' +
'<parm name="NAP-ADDRESS" value="wap.operator.com"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'<characteristic type="NAPAUTHINFO">' +
'<parm name="AUTHTYPE" value="PAP"/>' +
'<parm name="AUTHNAME" value="WAPOP"/>' +
'<parm name="AUTHSECRET" value="WAPOP"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="NAPDEF">' +
'<parm name="NAPID" value="WAP_GPRS"/>' +
'<parm name="BEARER" value="GSM-GPRS"/>' +
'<parm name="NAME" value="operator GPRS"/>' +
'<parm name="NAP-ADDRESS" value="wapOP.operator.com"/>' +
'<parm name="NAP-ADDRTYPE" value="APN"/>' +
'<characteristic type="NAPAUTHINFO">' +
'<parm name="AUTHTYPE" value="PAP"/>' +
'<parm name="AUTHNAME" value="WAPOP"/>' +
'<parm name="AUTHSECRET" value="WAPOP"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="w2"/>' +
'<parm name="NAME" value="Operator-portal"/>' +
'<parm name="TO-PROXY" value="www.operator.com"/>' +
'<characteristic type="RESOURCE">' +
'<parm name="URI" value="http://wap.operator_portal.com"/>' +
'<parm name="NAME" value="Operator portal"/>' +
'<parm name="STARTPAGE"/>' +
'</characteristic>' +
'</characteristic>' +
'<characteristic type="APPLICATION">' +
'<parm name="APPID" value="w2"/>' +
'<parm name="NAME" value="Operator-portal"/>' +
'<parm name="TO-PROXY" value="www.wap.operator.com"/>' +
'</characteristic>' +
'</wap-provisioningdoc>';
parsedProvisioningDoc = ParsedProvisioningDoc.from(provisioningDoc);
assert.lengthOf(parsedProvisioningDoc.getApns(), 1);
});
});
});

View file

@ -0,0 +1,277 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global MockMessageDB, MocksHelper, ParsedMessage */
'use strict';
require('/js/provisioning.js');
require('/js/parsed_message.js');
require('/test/unit/mock_messagedb.js');
var mocksHelperParsedMessage = new MocksHelper([
'MessageDB'
]).init();
suite('ParsedMessage', function() {
var messages;
var timestamp;
mocksHelperParsedMessage.attachTestHelpers();
suiteSetup(function() {
timestamp = Date.now();
messages = {
si_text_only: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si><indication>check this out</indication></si>',
serviceId: 0
},
si_href_only: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si><indication href="http://www.mozilla.org"></indication>' +
'</si>',
serviceId: 0
},
si_text_and_href: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si><indication href="http://www.mozilla.org">' +
'check this out</indication></si>',
serviceId: 0
},
si_id: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org"' +
' href="http://www.mozilla.org">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
created: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org"' +
' href="http://www.mozilla.org"' +
' created="2013-09-03T10:35:33Z">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
expires: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org"' +
' href="http://www.mozilla.org"' +
' si-expires="2013-09-03T10:35:33Z">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
action: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication action="signal-none">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
invalid_delete: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication action="delete"' +
' href="http://www.mozilla.org">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
sl: {
sender: '+31641600986',
contentType: 'text/vnd.wap.sl',
content: '<sl href="http://www.mozilla.org"/>',
serviceId: 0
},
sl_action: {
sender: '+31641600986',
contentType: 'text/vnd.wap.sl',
content: '<sl href="http://www.mozilla.org" action="execute-high"/>',
serviceId: 0
},
cp_noauth: {
sender: '22997',
contentType: 'text/vnd.wap.connectivity-xml',
content: '<wap-provisioningdoc></wap-provisioningdoc>',
serviceId: 0
},
cp_netwpin_checked_notpass: {
sender: '22997',
contentType: 'text/vnd.wap.connectivity-xml',
content: '<wap-provisioningdoc></wap-provisioningdoc>',
authInfo: {
sec: 'NETWPIN',
checked: true,
pass: false
},
serviceId: 0
},
unsupported: {
sender: '+31641600986',
contentType: 'text/foobar',
content: '',
serviceId: 0
}
};
});
suite('ParsedMessage.from()', function() {
test('Text only', function() {
var message = ParsedMessage.from(messages.si_text_only, timestamp);
assert.equal(message.type, 'text/vnd.wap.si');
assert.equal(message.sender, '+31641600986');
assert.equal(message.timestamp, timestamp);
assert.equal(message.text, 'check this out');
assert.equal(message.href, undefined);
assert.equal(message.action, 'signal-medium');
assert.equal(message.serviceId, 0);
});
test('HREF only', function() {
var message = ParsedMessage.from(messages.si_href_only, timestamp);
assert.equal(message.text, '');
assert.equal(message.href, 'http://www.mozilla.org');
assert.equal(message.id, 'http://www.mozilla.org');
});
test('Text and HREF only', function() {
var message = ParsedMessage.from(messages.si_text_and_href, timestamp);
assert.equal(message.text, 'check this out');
assert.equal(message.href, 'http://www.mozilla.org');
assert.equal(message.id, 'http://www.mozilla.org');
});
test('SI message with explicit si-id field', function() {
var message = ParsedMessage.from(messages.si_id, timestamp);
assert.equal(message.href, 'http://www.mozilla.org');
assert.equal(message.id, 'gaia-test@mozilla.org');
});
test('SI message with explicit creation time', function() {
var message = ParsedMessage.from(messages.created, timestamp);
assert.equal(message.created, Date.parse('2013-09-03T10:35:33Z'));
});
test('SI message with explicit expiration date', function() {
var message = ParsedMessage.from(messages.expires, timestamp);
assert.equal(message.expires, Date.parse('2013-09-03T10:35:33Z'));
assert.isTrue(message.isExpired());
});
test('SI message with explicit action', function() {
var message = ParsedMessage.from(messages.action, timestamp);
assert.equal(message.action, 'signal-none');
});
test('SI message with delete action but no si-id field', function() {
assert.isNull(ParsedMessage.from(messages.invalid_delete, timestamp));
});
test('SL message', function() {
var message = ParsedMessage.from(messages.sl, timestamp);
assert.equal(message.type, 'text/vnd.wap.sl');
assert.equal(message.text, undefined);
assert.equal(message.href, 'http://www.mozilla.org');
assert.equal(message.action, 'execute-low');
});
test('SL message with explicit action', function() {
var message = ParsedMessage.from(messages.sl_action, timestamp);
assert.equal(message.action, 'execute-high');
});
test('OMA CP message without auth info', function() {
var message = ParsedMessage.from(messages.cp_noauth, timestamp);
assert.equal(message, null);
});
test('OMA CP message with NETWPIN auth info not authenticated', function() {
var message = ParsedMessage.from(messages.cp_netwpin_checked_notpass,
timestamp);
assert.equal(message, null);
});
test('unsupported content', function() {
var message = ParsedMessage.from(messages.unsupported, timestamp);
assert.equal(message, null);
});
});
suite('ParsedMessage.load()', function() {
var jsonMessage;
suiteSetup(function() {
jsonMessage = ParsedMessage.from({
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si><indication>check this out</indication></si>',
serviceId: 0
}, 0).toJSON();
});
test('Successful retrieve a message', function(done) {
this.sinon.stub(MockMessageDB, 'retrieve').returns(
Promise.resolve(jsonMessage)
);
ParsedMessage.load(0).then(message => {
assert.instanceOf(message, ParsedMessage);
}).then(done, done);
});
test('Rejects if no message is found', function(done) {
this.sinon.stub(MockMessageDB, 'retrieve').returns(Promise.reject());
ParsedMessage.load(0).then(
() => assert.isTrue(false, 'Should not resolve the promise'),
() => {}
).then(done, done);
});
});
});

View file

@ -0,0 +1,7 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
require('/shared/test/unit/load_body_html_helper.js');
require('/shared/test/unit/mocks/mocks_helper.js');

View file

@ -0,0 +1,172 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global MockNavigatorSettings, StoreProvisioning, MocksHelper */
'use strict';
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
require('/js/store.js');
require('/shared/js/uuid.js');
require('/shared/test/unit/mocks/mocks_helper.js');
var mocksHelperStoreProvisioning = new MocksHelper([
'NavigatorSettings'
]).init();
suite('StoreProvisioning >', function() {
var realSettings;
mocksHelperStoreProvisioning.attachTestHelpers();
suiteSetup(function() {
realSettings = navigator.mozSettings;
navigator.mozSettings = MockNavigatorSettings;
});
suiteTeardown(function() {
navigator.mozSettings = realSettings;
realSettings = null;
});
setup(function() {
MockNavigatorSettings.mSettings['operatorvariant.mcc'] = ['214', '216'];
MockNavigatorSettings.mSettings['operatorvariant.mnc'] = ['07', '01'];
MockNavigatorSettings.mSyncRepliesOnly = true;
});
suite('StoreProvisioning.getMccMncCodes()', function() {
test('Get SIM1 MCC code', function() {
StoreProvisioning.getMccMncCodes(0, function(mcc, mnc) {
assert.equal(mcc, '214');
});
// getMccMncCodes does 2 mozSettings requests in sequence
MockNavigatorSettings.mReplyToRequests();
MockNavigatorSettings.mReplyToRequests();
});
test('Get SIM1 MNC code', function() {
StoreProvisioning.getMccMncCodes(0, function(mcc, mnc) {
assert.equal(mnc, '07');
});
MockNavigatorSettings.mReplyToRequests();
MockNavigatorSettings.mReplyToRequests();
});
test('Get SIM2 MCC code', function() {
StoreProvisioning.getMccMncCodes(1, function(mcc, mnc) {
assert.equal(mcc, '216');
});
MockNavigatorSettings.mReplyToRequests();
MockNavigatorSettings.mReplyToRequests();
});
test('Get SIM2 MNC code', function() {
StoreProvisioning.getMccMncCodes(1, function(mcc, mnc) {
assert.equal(mnc, '01');
});
MockNavigatorSettings.mReplyToRequests();
MockNavigatorSettings.mReplyToRequests();
});
});
suite('StoreProvisioning.provision()', function() {
setup(function() {
MockNavigatorSettings.mSettings['ril.data.cp.apns'] = '';
MockNavigatorSettings.mSettings['ril.data.apnSettings'] = '';
});
test('Add APN to SIM1: Telefonica DEFAULT type', function() {
var apns = [{
carrier: 'Movistar',
apn: 'telefonica.es',
user: 'telefonica',
password: 'telefonica',
type: ['default']
}];
StoreProvisioning.provision(apns, 0, function(){
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.cp.apns']['214']['07'], 1
);
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.apnSettings'][0], 1
);
});
MockNavigatorSettings.mReplyToRequests();
});
test('Add APN to SIM2: Pannon DEFAULT type', function() {
var apns = [{
carrier: 'Pannon GSM',
apn: 'Pannon.hu',
user: 'Pannon',
password: 'Pannon',
type: ['default']
}];
StoreProvisioning.provision(apns, 1, function() {
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.cp.apns']['216']['01'], 1
);
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.apnSettings'][1], 1
);
});
MockNavigatorSettings.mReplyToRequests();
});
});
suite('StoreProvisioning.provision()', function() {
setup(function() {
MockNavigatorSettings.mSettings['ril.data.apnSettings'] = '';
MockNavigatorSettings.mSettings['ril.data.cp.apns'] = {};
MockNavigatorSettings.mSettings['ril.data.cp.apns']['214'] = {};
MockNavigatorSettings.mSettings['ril.data.cp.apns']['216'] = {};
MockNavigatorSettings.mSettings['ril.data.cp.apns']['214']['07'] = [{
carrier: 'Movistar',
apn: 'telefonica.es',
user: 'telefonica',
password: 'telefonica',
type: ['default']
}];
MockNavigatorSettings.mSettings['ril.data.cp.apns']['216']['01'] = [{
carrier: 'Pannon GSM',
apn: 'Pannon.hu',
user: 'Pannon',
password: 'Pannon',
type: ['default']
}];
});
test('Add APN to SIM1: Telefonica MMS type', function() {
var apns = [{
carrier: 'Movistar MMS',
apn: 'telefonica.es',
user: 'telefonica',
password: 'telefonica',
type: ['mms']
}];
StoreProvisioning.provision(apns, 0, function() {
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.cp.apns']['214']['07'], 2
);
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.apnSettings'][0], 1
);
});
MockNavigatorSettings.mReplyToRequests();
});
test('Add APN to SIM2: Pannon MMS type', function() {
var apns = [{
carrier: 'Pannon GSM MMS',
apn: 'Pannon.hu',
user: 'Pannon',
password: 'Pannon',
type: ['mms']
}];
StoreProvisioning.provision(apns, 1, function(){
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.cp.apns']['216']['01'], 2
);
assert.lengthOf(
MockNavigatorSettings.mSettings['ril.data.apnSettings'][1], 1
);
});
MockNavigatorSettings.mReplyToRequests();
});
});
});

View file

@ -0,0 +1,993 @@
/* global CpScreenHelper, loadBodyHTML, MockL10n, MessageDB,
MockNavigatormozApps, MockNavigatorMozIccManager,
MockNavigatormozSetMessageHandler, MockNavigatorSettings,
MockNotification, MockNotificationHelper, MocksHelper,
WapPushManager, MockParsedProvisioningDoc, SiSlScreenHelper */
'use strict';
require('/shared/js/event_dispatcher.js');
require('/shared/test/unit/mocks/mock_dump.js');
require('/shared/test/unit/mocks/mock_navigator_moz_apps.js');
require('/shared/test/unit/mocks/mock_navigator_moz_set_message_handler.js');
require('/shared/test/unit/mocks/mock_notification.js');
require('/shared/test/unit/mocks/mock_notification_helper.js');
require('/shared/test/unit/mocks/mock_navigator_moz_icc_manager.js');
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
require('/js/cp_screen_helper.js');
require('/js/messagedb.js');
require('/js/parsed_message.js');
require('/js/provisioning.js');
require('/js/si_sl_screen_helper.js');
require('/js/utils.js');
require('/js/wappush.js');
require('/shared/test/unit/mocks/mock_l10n.js');
require('/test/unit/mock_link_action_handler.js');
require('/test/unit/mock_whitelist.js');
require('/test/unit/mock_parsed_doc.js');
var mocksHelperWapPush = new MocksHelper([
'Dump',
'LinkActionHandler',
'NotificationHelper',
'Notification',
'WhiteList',
'ParsedProvisioningDoc'
]).init();
suite('WAP Push', function() {
var realMozApps;
var realMozIccManager;
var realMozSettings;
var realSetMessageHandler;
var realMozL10n;
var isDocumentHidden = false;
mocksHelperWapPush.attachTestHelpers();
suiteSetup(function() {
realMozApps = navigator.mozApps;
navigator.mozApps = MockNavigatormozApps;
realMozIccManager = navigator.mozIccManager;
navigator.mozIccManager = MockNavigatorMozIccManager;
realMozL10n = navigator.mozL10n;
navigator.mozL10n = MockL10n;
realMozSettings = navigator.mozSettings;
navigator.mozSettings = MockNavigatorSettings;
realSetMessageHandler = navigator.mozSetMessageHandler;
navigator.mozSetMessageHandler = MockNavigatormozSetMessageHandler;
});
suiteTeardown(function() {
navigator.mozApps = realMozApps;
navigator.mozL10n = realMozL10n;
navigator.mozSettings = realMozSettings;
navigator.mozSetMessageHandler = realSetMessageHandler;
});
setup(function(done) {
var notificationGetStub = function notificationGet() {
var options = {};
options.icon = 'icon';
options.tag = '0';
return {
then: function(onSuccess, onError, onProgress) {
onSuccess([
new MockNotification('1', options)
]);
}
};
};
this.sinon.stub(MockNotification, 'get', notificationGetStub);
mocksHelperWapPush.setup();
MockNavigatorSettings.createLock().set({ 'wap.push.enabled': 'true' });
loadBodyHTML('/index.html');
Object.defineProperty(document, 'hidden', {
configurable: true,
get: function() {
return isDocumentHidden;
}
});
MockNavigatorMozIccManager.addIcc(0, {});
MockNavigatormozSetMessageHandler.mSetup();
WapPushManager.init()
.then(MessageDB.clear.bind(MessageDB))
.then(done, done);
MockNavigatormozApps.mTriggerLastRequestSuccess();
});
teardown(function() {
delete document.hidden;
MockNavigatormozSetMessageHandler.mTeardown();
MockNavigatorMozIccManager.mTeardown();
MockNavigatormozApps.mTeardown();
MockNavigatorSettings.mTeardown();
mocksHelperWapPush.teardown();
});
suite('init', function() {
test('the message handlers are bound', function() {
var handlers = MockNavigatormozSetMessageHandler.mMessageHandlers;
assert.ok(handlers.notification);
assert.equal(handlers['wappush-received'],
WapPushManager.onWapPushReceived);
});
test('the headers are empty', function() {
assert.equal(document.getElementById('title-si-sl').textContent, '');
assert.equal(document.getElementById('title-apn').textContent, '');
assert.equal(document.getElementById('title-details').textContent, '');
assert.equal(document.getElementById('title-pin').textContent, '');
});
});
suite('unsupported message', function() {
var message = {
sender: '+31641600986',
contentType: 'text/foobar',
content: '',
serviceId: 0
};
test('unsupported messages are discarded', function(done) {
this.sinon.spy(MessageDB, 'put');
WapPushManager.onWapPushReceived(message).then(function() {
done(function checks() {
sinon.assert.notCalled(MessageDB.put);
});
}, done);
});
});
suite('receiving and displaying a SI message', function() {
var message = {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si><indication href="http://www.mozilla.org">' +
'check this out</indication></si>',
serviceId: 0
};
test('the notification is sent and populated correctly', function(done) {
this.sinon.spy(MockNotificationHelper, 'send');
WapPushManager.onWapPushReceived(message).then(function() {
done(function checks() {
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
id: 'message-title',
args: { title: message.sender }
}, {
bodyL10n: {
args: {
text: 'check this out',
url: 'http://www.mozilla.org'
},
id: 'si-message-body'
}
});
});
}, done);
});
test('the display is populated with the message contents', function(done) {
var title = document.getElementById('title-si-sl');
var screen = document.getElementById('si-sl-screen');
var container = screen.querySelector('.container');
var text = container.querySelector('p');
var link = container.querySelector('a');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(MockL10n, 'setAttributes');
this.sinon.spy(CpScreenHelper, 'hide');
WapPushManager.onWapPushReceived(message).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
sinon.assert.calledWith(MockNotification.get, { tag: 0 });
sinon.assert.calledOnce(MockNotification.prototype.close);
sinon.assert.calledOnce(CpScreenHelper.hide);
sinon.assert.calledWith(MockL10n.setAttributes, title,
'message-title', { title: message.sender });
assert.equal(text.textContent, 'check this out');
assert.equal(link.textContent, 'http://www.mozilla.org');
assert.equal(link.dataset.url, 'http://www.mozilla.org');
assert.equal(link.href, 'http://www.mozilla.org/');
}).then(done, done);
});
suite('DSDS scenarios', function() {
setup(function() {
this.sinon.spy(MockNotificationHelper, 'send');
MockNavigatorMozIccManager.addIcc(1, {});
});
test('the notification is populated correctly for SIM1', function(done) {
WapPushManager.onWapPushReceived(message).then(function() {
done(function checks() {
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
args: {
id: 1,
title: message.sender
},
id: 'message-title-with-sim'
});
});
}, done);
});
test('the notification is populated correctly for SIM2', function(done) {
message.serviceId = 1;
WapPushManager.onWapPushReceived(message).then(function() {
done(function checks() {
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
args: {
id: 2,
title: message.sender
},
id: 'message-title-with-sim'
});
});
}, done);
});
});
});
suite('receiving and displaying a SL message', function() {
var message = {
sender: '+31641600986',
contentType: 'text/vnd.wap.sl',
content: '<sl href="http://www.mozilla.org" />',
serviceId: 0
};
test('the notification is sent and populated correctly', function(done) {
this.sinon.spy(MockNotificationHelper, 'send');
WapPushManager.onWapPushReceived(message).then(function() {
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
id: 'message-title',
args: { title: message.sender }
}, {
bodyL10n: {
args: {
url: 'http://www.mozilla.org'
},
id: 'sl-message-body'
}
});
}).then(done, done);
});
test('the display is populated with the message contents', function(done) {
var title = document.getElementById('title-si-sl');
var screen = document.getElementById('si-sl-screen');
var container = screen.querySelector('.container');
var text = container.querySelector('p');
var link = container.querySelector('a');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(MockL10n, 'setAttributes');
this.sinon.spy(CpScreenHelper, 'hide');
WapPushManager.onWapPushReceived(message).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.calledWith(MockNotification.get, { tag: 0 });
sinon.assert.calledOnce(MockNotification.prototype.close);
sinon.assert.calledOnce(CpScreenHelper.hide);
sinon.assert.calledWith(MockL10n.setAttributes, title,
'message-title', { title: message.sender });
assert.equal(text.textContent, '');
assert.equal(link.textContent, 'http://www.mozilla.org');
assert.equal(link.dataset.url, 'http://www.mozilla.org');
assert.equal(link.href, 'http://www.mozilla.org/');
});
}, done);
});
});
suite('receiving and displaying a CP message', function() {
var messages = {
netwpin: {
sender: '22997',
contentType: 'text/vnd.wap.connectivity-xml',
content: '<wap-provisioningdoc></wap-provisioningdoc>',
authInfo: {
pass: true,
checked: true,
sec: 'NETWPIN',
mac: 'FAKEMAC',
data: 'FAKEDATA'
},
serviceId: 0
},
userpin: {
sender: '22997',
contentType: 'text/vnd.wap.connectivity-xml',
content: '<wap-provisioningdoc></wap-provisioningdoc>',
authInfo: {
pass: true,
checked: true,
sec: 'USERPIN',
mac: 'FAKEMAC',
data: 'FAKEDATA'
},
serviceId: 0
}
};
var apns = {
none: [],
single: [
{ carrier: 'Test APN'}
],
multiple: [
{ carrier: 'Test APN 1'},
{ carrier: 'Test APN 2'},
{ carrier: 'Test APN 3'}
],
};
test('the notification is sent and populated correctly', function(done) {
this.sinon.spy(MockNotificationHelper, 'send');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
done(function checks() {
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
args: { title: messages.netwpin.sender },
id: 'message-title'
}, {
bodyL10n: 'cp-message-received'
});
});
}, done);
});
test('the display shows warning message asking for install configuration',
function(done) {
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var acceptButton = installCfgConfirmDialog.querySelector('.accept');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(SiSlScreenHelper, 'hide');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
sinon.assert.calledOnce(SiSlScreenHelper.hide);
assert.isFalse(acceptButton.classList.contains('hidden'),
'the accept button should be visible');
assert.isFalse(acceptButton.hidden);
});
}, done);
}
);
test('the app is closed when if the user does not accept the instalation',
function(done) {
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var cancelButton = installCfgConfirmDialog.querySelector('.cancel');
this.sinon.spy(WapPushManager, 'close');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
assert.isFalse(cancelButton.classList.contains('hidden'),
'the accept button should be visible');
assert.isFalse(cancelButton.hidden);
cancelButton.click();
sinon.assert.calledOnce(WapPushManager.close);
});
}, done);
}
);
test('show finish dialog when no apns are present in a CP message',
function(done) {
MockParsedProvisioningDoc.mSetup(apns.none);
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var acceptCfgButton = installCfgConfirmDialog.querySelector('.accept');
var dialog = document.getElementById('cp-finish-confirm');
var finishButton = dialog.querySelector('button');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
acceptCfgButton.click();
assert.isFalse(finishButton.classList.contains('hidden'),
'the accept button should be visible');
assert.isFalse(finishButton.hidden);
});
}, done);
}
);
test('details of apn are shown after warning message when a single apn ' +
'is defined in CP message',
function(done) {
MockParsedProvisioningDoc.mSetup(apns.single);
var title = document.getElementById('title-details');
var screen = document.getElementById('cp-details-screen');
var details = screen.querySelector('.message');
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var acceptCfgButton = installCfgConfirmDialog.querySelector('.accept');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(MockL10n, 'setAttributes');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
acceptCfgButton.click();
sinon.assert.calledWith(MockL10n.setAttributes, title,
'message-title', { title: messages.netwpin.sender });
assert.isFalse(screen.classList.contains('left') ||
screen.classList.contains('right'),
'the details screen should be visible');
var apnList = details.getElementsByTagName('li');
assert.equal(apns.single.length, apnList.length);
for (var i = 0; i < apnList.length; i++) {
assert.equal(apns.single[i].carrier,
apnList[i].childNodes[1].textContent);
}
});
}, done);
}
);
test('apn list screen is shown after warning message when multiple apns ' +
'are defined in CP message',
function(done) {
MockParsedProvisioningDoc.mSetup(apns.multiple);
var titleApn = document.getElementById('title-apn');
var titleDetails = document.getElementById('title-details');
var apnScreen = document.getElementById('cp-apn-screen');
var detailsScreen = document.getElementById('cp-details-screen');
var apnsElement = apnScreen.querySelector('.message');
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var acceptCfgButton = installCfgConfirmDialog.querySelector('.accept');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(MockL10n, 'setAttributes');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
acceptCfgButton.click();
sinon.assert.calledWith(MockL10n.setAttributes, titleApn,
'message-title', { title: messages.netwpin.sender });
assert.isFalse(apnScreen.classList.contains('left') ||
apnScreen.classList.contains('right'),
'the apn screen should be visible');
sinon.assert.calledWith(MockL10n.setAttributes, titleDetails,
'message-title', { title: messages.netwpin.sender });
assert.isTrue(detailsScreen.classList.contains('right'),
'the details screen should not be visible');
var apnList = apnsElement.getElementsByTagName('li');
assert.equal(apns.multiple.length, apnList.length);
for (var i = 0; i < apnList.length; i++) {
assert.equal(apns.multiple[i].carrier,
apnList[i].childNodes[0].childNodes[1].textContent);
}
// Test that click on apn element shows its details.
apnList[0].childNodes[0].click();
assert.isFalse(detailsScreen.classList.contains('left') ||
detailsScreen.classList.contains('right'),
'the details screen should be visible');
assert.isTrue(apnScreen.classList.contains('left'),
'the apn screen should not be visible');
});
}, done);
}
);
test('the display is populated with the NETWPIN message contents after ' +
'accepting installation ',
function(done) {
MockParsedProvisioningDoc.mSetup(apns.single);
var title = document.getElementById('title-pin');
var screen = document.getElementById('cp-pin-screen');
var acceptButton = document.getElementById('details-accept');
var pin = screen.querySelector('input');
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var acceptInstallButton =
installCfgConfirmDialog.querySelector('.accept');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(MockL10n, 'setAttributes');
WapPushManager.onWapPushReceived(messages.netwpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
acceptInstallButton.click();
acceptButton.click();
sinon.assert.calledWith(MockL10n.setAttributes, title,
'message-title', { title: messages.netwpin.sender });
assert.isFalse(screen.classList.contains('left') ||
screen.classList.contains('right'),
'the details screen should be visible');
assert.equal(pin.type, 'hidden');
});
}, done);
}
);
test('the display is populated with the USERPIN message contents after ' +
'accepting installation ',
function(done) {
MockParsedProvisioningDoc.mSetup(apns.single);
var title = document.getElementById('title-pin');
var screen = document.getElementById('cp-pin-screen');
var acceptButton = document.getElementById('details-accept');
var pin = screen.querySelector('input');
var installCfgConfirmDialog =
document.getElementById('cp-install-configuration-confirm');
var acceptInstallButton =
installCfgConfirmDialog.querySelector('.accept');
this.sinon.stub(Date, 'now').returns(0);
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.spy(MockL10n, 'setAttributes');
WapPushManager.onWapPushReceived(messages.userpin).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(MockNotification.prototype.close);
acceptInstallButton.click();
acceptButton.click();
sinon.assert.calledWith(MockL10n.setAttributes, title,
'message-title', { title: messages.netwpin.sender });
assert.isFalse(screen.classList.contains('left') ||
screen.classList.contains('right'),
'the details screen should be visible');
assert.equal(pin.type, 'number');
});
}, done);
}
);
});
suite('handling out-of-order reception of messages', function() {
var messages = {
old: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org" ' +
' created="2013-09-03T12:35:33Z">' +
'old message' +
'</indication>' +
'</si>',
serviceId: 0
},
current: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org" ' +
' created="2013-09-03T14:35:33Z">' +
'current message' +
'</indication>' +
'</si>',
serviceId: 0
}
};
test('a new message updates an older one', function(done) {
var screen = document.getElementById('si-sl-screen');
var container = screen.querySelector('.container');
var text = container.querySelector('p');
this.sinon.spy(MockNotificationHelper, 'send');
this.sinon.stub(Date, 'now')
.onFirstCall().returns(0)
.onSecondCall().returns(1);
WapPushManager.onWapPushReceived(messages.old).then(function() {
return WapPushManager.onWapPushReceived(messages.current);
}).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.alwaysCalledWithMatch(MockNotificationHelper.send, {
id: 'message-title',
args: { title: messages.current.sender }
}, {
tag: '0'
});
assert.equal(text.textContent, 'current message');
});
}, done);
});
test('a new message updates an older one which is being viewed',
function(done) {
this.sinon.spy(SiSlScreenHelper, 'populateScreen');
this.sinon.stub(Date, 'now')
.onFirstCall().returns(0)
.onSecondCall().returns(1);
WapPushManager.onWapPushReceived(messages.old).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
sinon.assert.calledOnce(SiSlScreenHelper.populateScreen);
sinon.assert.calledWithMatch(SiSlScreenHelper.populateScreen, {
text: 'old message'
});
SiSlScreenHelper.populateScreen.reset();
return WapPushManager.onWapPushReceived(messages.current);
}).then(function() {
sinon.assert.calledOnce(SiSlScreenHelper.populateScreen);
sinon.assert.calledWithMatch(SiSlScreenHelper.populateScreen, {
text: 'current message'
});
}).then(done, done);
});
test('an outdated message does not replace a newer one', function(done) {
var screen = document.getElementById('si-sl-screen');
var container = screen.querySelector('.container');
var text = container.querySelector('p');
this.sinon.spy(MockNotificationHelper, 'send');
this.sinon.stub(Date, 'now')
.onFirstCall().returns(0)
.onSecondCall().returns(1);
WapPushManager.onWapPushReceived(messages.current).then(function() {
return WapPushManager.onWapPushReceived(messages.old);
}).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
done(function checks() {
sinon.assert.calledOnce(MockNotificationHelper.send);
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
id: 'message-title',
args: { title: messages.current.sender }
}, {
tag: '0'
});
assert.equal(text.textContent, 'current message');
});
}, done);
});
});
suite('handling expired messages', function() {
var message = {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-expires="2013-09-03T10:35:33Z">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
};
// UI elements
var screen;
var container;
var text;
setup(function() {
screen = document.getElementById('si-sl-screen');
container = screen.querySelector('.container');
text = container.querySelector('p');
});
test('the message is expired upon arrival', function(done) {
this.sinon.stub(Date, 'now')
.onFirstCall().returns(0)
.onSecondCall().returns(1378204533001);
this.sinon.spy(MockNotificationHelper, 'send');
WapPushManager.onWapPushReceived(message).then(function() {
sinon.assert.notCalled(MockNotificationHelper.send);
}).then(done, done);
});
test('the message is expired after arrival', function(done) {
this.sinon.stub(Date, 'now')
.onFirstCall().returns(0)
.onSecondCall().returns(0)
.onThirdCall().returns(1378204533001);
this.sinon.spy(MockL10n, 'setAttributes');
WapPushManager.onWapPushReceived(message).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
sinon.assert.calledWith(MockL10n.setAttributes, text,
'this-message-has-expired');
}).then(done, done);
});
});
suite('handling actions', function() {
var clock;
var messages = {
none: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org"' +
' action="signal-none">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
signal_high: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org"' +
' action="signal-high">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
execute_high: {
sender: '+31641600986',
contentType: 'text/vnd.wap.sl',
content: '<sl href="http://www.mozilla.org" action="execute-high"/>',
serviceId: 0
},
no_action: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
},
delete: {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si>' +
'<indication si-id="gaia-test@mozilla.org"' +
' action="delete">' +
'check this out' +
'</indication>' +
'</si>',
serviceId: 0
}
};
setup(function() {
clock = this.sinon.useFakeTimers();
isDocumentHidden = true;
this.sinon.spy(MockNotificationHelper, 'send');
this.sinon.spy(window, 'close');
});
/* XXX: Workaround for bug 981521. We shouldn't send notifications for
* signal-none messages but we do until we'll have another way for the user
* to find & display them. */
test('action=signal-none sends a notification', function(done) {
WapPushManager.onWapPushReceived(messages.none).then(function() {
clock.tick(100);
sinon.assert.calledWithMatch(MockNotificationHelper.send, {
id: 'message-title',
args: { title: messages.none.sender }
}, {
bodyL10n: {
id: 'si-message-body',
args: { text: 'check this out' }
}
});
sinon.assert.calledOnce(window.close);
assert.isFalse(MockNavigatormozApps.mAppWasLaunched);
}).then(done, done);
});
test('action=signal-high displays the SI message immediately',
function(done) {
this.sinon.stub(SiSlScreenHelper, 'populateScreen', function() {
clock.tick(100);
sinon.assert.notCalled(MockNotificationHelper.send);
sinon.assert.notCalled(window.close);
sinon.assert.calledOnce(SiSlScreenHelper.populateScreen);
assert.isTrue(MockNavigatormozApps.mAppWasLaunched);
done();
});
WapPushManager.onWapPushReceived(messages.signal_high);
});
test('action=execute-high displays the SL message immediately',
function(done) {
this.sinon.stub(SiSlScreenHelper, 'populateScreen', function() {
clock.tick(100);
sinon.assert.notCalled(MockNotificationHelper.send);
sinon.assert.notCalled(window.close);
sinon.assert.calledOnce(SiSlScreenHelper.populateScreen);
assert.isTrue(MockNavigatormozApps.mAppWasLaunched);
done();
});
WapPushManager.onWapPushReceived(messages.execute_high);
});
test('action=delete causes notifications of the deleted messages to ' +
'be removed', function(done) {
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.stub(Date, 'now').returns(0);
WapPushManager.onWapPushReceived(messages.no_action).then(function() {
return WapPushManager.onWapPushReceived(messages.delete);
}).then(function() {
sinon.assert.calledOnce(MockNotificationHelper.send);
sinon.assert.calledWith(MockNotification.get, { tag: 0 });
sinon.assert.calledOnce(MockNotification.prototype.close);
}).then(done, done);
});
test('action=delete causes the app to be closed if the message is being ' +
'displayed', function(done) {
this.sinon.spy(MockNotification.prototype, 'close');
this.sinon.stub(Date, 'now').returns(0);
WapPushManager.onWapPushReceived(messages.no_action).then(function() {
return WapPushManager.displayWapPushMessage(0);
}).then(function() {
MockNotification.prototype.close.reset();
MockNotification.get.reset();
return WapPushManager.onWapPushReceived(messages.delete);
}).then(function() {
sinon.assert.calledWith(MockNotification.get, { tag: 0 });
sinon.assert.calledOnce(MockNotification.prototype.close);
clock.tick(100);
sinon.assert.calledOnce(window.close);
}).then(done, done);
});
});
suite('automatic closing of the application', function() {
var message = {
sender: '+31641600986',
contentType: 'text/vnd.wap.si',
content: '<si><indication href="http://www.mozilla.org">' +
'check this out</indication></si>',
serviceId: 0
};
var clock;
setup(function() {
clock = this.sinon.useFakeTimers();
this.sinon.spy(window, 'close');
});
test('the app is closed after displaying a notification', function(done) {
isDocumentHidden = true;
WapPushManager.onWapPushReceived(message).then(function() {
done(function checks() {
clock.tick(100);
sinon.assert.calledOnce(window.close);
});
}, done);
});
test('the app is not closed if it is visible', function(done) {
isDocumentHidden = false;
WapPushManager.onWapPushReceived(message).then(function() {
done(function checks() {
clock.tick(100);
sinon.assert.notCalled(window.close);
});
}, done);
});
test('the app is closed only after all messages have been processed',
function(done) {
isDocumentHidden = true;
WapPushManager.onWapPushReceived(message).then(function() {
sinon.assert.notCalled(window.close);
return WapPushManager.onWapPushReceived(message);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(window.close);
clock.tick(100);
sinon.assert.calledOnce(window.close);
});
}, done);
}
);
test('prevent the app from closing if it becomes visible', function(done) {
isDocumentHidden = true;
WapPushManager.onWapPushReceived(message).then(function() {
sinon.assert.notCalled(window.close);
return WapPushManager.onWapPushReceived(message);
}).then(function() {
done(function checks() {
sinon.assert.notCalled(window.close);
clock.tick(50);
isDocumentHidden = false;
WapPushManager.onVisibilityChange();
clock.tick(50);
sinon.assert.notCalled(window.close);
});
}, done);
});
test('the app is closed when hidden', function() {
isDocumentHidden = false;
WapPushManager.onVisibilityChange();
clock.tick(100);
isDocumentHidden = true;
WapPushManager.onVisibilityChange();
clock.tick(100);
sinon.assert.calledOnce(window.close);
});
});
});