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:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
82
gaia/apps/settings/test/unit/panels/root/airplane_mode_item_test.js
Executable file
82
gaia/apps/settings/test/unit/panels/root/airplane_mode_item_test.js
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
'use strict';
|
||||
|
||||
suite('AirplaneModeItem', function() {
|
||||
var map = {
|
||||
'*': {
|
||||
'shared/airplane_mode_helper': 'unit/mock_airplane_mode_helper'
|
||||
}
|
||||
};
|
||||
|
||||
var modules = [
|
||||
'panels/root/airplane_mode_item',
|
||||
'unit/mock_airplane_mode_helper'
|
||||
];
|
||||
|
||||
setup(function(done) {
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
|
||||
requireCtx(modules, function(AirplaneModeItem, MockAirplaneModeHelper) {
|
||||
var element = document.createElement('input');
|
||||
element.type = 'checkbox';
|
||||
|
||||
this.element = element;
|
||||
this.AirplaneModeItem = AirplaneModeItem;
|
||||
this.MockAirplaneModeHelper = MockAirplaneModeHelper;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
test('when init is called, we would wait until APMhelper is ready',
|
||||
function() {
|
||||
this.sinon.stub(this.MockAirplaneModeHelper, 'ready');
|
||||
var airplaneModeItem = this.AirplaneModeItem(this.element);
|
||||
airplaneModeItem.init();
|
||||
assert.isTrue(this.MockAirplaneModeHelper.ready.called);
|
||||
});
|
||||
|
||||
test('when wificontext-ready event is received', function() {
|
||||
var airplaneModeItem = this.AirplaneModeItem(this.element);
|
||||
airplaneModeItem.handleEvent({
|
||||
type: 'wificontext-ready'
|
||||
});
|
||||
assert.isFalse(airplaneModeItem._element.disabled);
|
||||
});
|
||||
|
||||
test('when item is enabled, we would start observing change', function() {
|
||||
this.sinon.stub(this.MockAirplaneModeHelper, 'addEventListener');
|
||||
var airplaneModeItem = this.AirplaneModeItem(this.element);
|
||||
airplaneModeItem._itemEnabled = false;
|
||||
airplaneModeItem.enabled = true;
|
||||
assert.isTrue(this.MockAirplaneModeHelper.addEventListener.called);
|
||||
});
|
||||
|
||||
test('when item is enabled, we would stop observing change', function() {
|
||||
this.sinon.stub(this.MockAirplaneModeHelper, 'removeEventListener');
|
||||
var airplaneModeItem = this.AirplaneModeItem(this.element);
|
||||
airplaneModeItem._itemEnabled = true;
|
||||
airplaneModeItem.enabled = false;
|
||||
assert.isTrue(this.MockAirplaneModeHelper.removeEventListener.called);
|
||||
});
|
||||
|
||||
suite('when onAPMstateChange is triggered', function() {
|
||||
var airplaneModeItem;
|
||||
setup(function() {
|
||||
airplaneModeItem = this.AirplaneModeItem(this.element);
|
||||
});
|
||||
|
||||
['enabled', 'disabled'].forEach(function(status) {
|
||||
test('status is ' + status + ', let UI clickable', function() {
|
||||
airplaneModeItem._onAPMStateChange(status);
|
||||
assert.equal(this.element.checked, (status === 'enabled'));
|
||||
assert.isFalse(this.element.disabled);
|
||||
});
|
||||
});
|
||||
|
||||
['enabling', 'disabling'].forEach(function(status) {
|
||||
test('status is ' + status + ', let UI unclickable', function() {
|
||||
airplaneModeItem._onAPMStateChange(status);
|
||||
assert.isTrue(this.element.disabled);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
87
gaia/apps/settings/test/unit/panels/root/battery_item_test.js
Executable file
87
gaia/apps/settings/test/unit/panels/root/battery_item_test.js
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
'use strict';
|
||||
|
||||
suite('BatteryItem', function() {
|
||||
var realL10n;
|
||||
var modules = [
|
||||
'shared_mocks/mock_l20n',
|
||||
'panels/root/battery_item',
|
||||
];
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/battery': 'MockBattery'
|
||||
}
|
||||
};
|
||||
|
||||
suiteSetup(function(done) {
|
||||
this.MockBattery = {
|
||||
state: 'charging',
|
||||
level: 10,
|
||||
observe: function() {},
|
||||
unobserve: function() {}
|
||||
};
|
||||
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
define('MockBattery', function() {
|
||||
return this.MockBattery;
|
||||
}.bind(this));
|
||||
|
||||
requireCtx(modules, function(MockL10n, BatteryItem) {
|
||||
realL10n = document.l10n;
|
||||
this.MockL10n = MockL10n;
|
||||
document.l10n = MockL10n;
|
||||
|
||||
this.BatteryItem = BatteryItem;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
document.l10n = realL10n;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.element = document.createElement('div');
|
||||
this.subject = this.BatteryItem(this.element);
|
||||
});
|
||||
|
||||
test('when enabled = true', function() {
|
||||
this.sinon.stub(this.MockBattery, 'observe');
|
||||
this.sinon.stub(this.subject, '_boundRefreshText');
|
||||
this.subject.enabled = true;
|
||||
|
||||
sinon.assert.called(this.subject._boundRefreshText);
|
||||
sinon.assert.calledTwice(this.MockBattery.observe);
|
||||
assert.equal(this.MockBattery.observe.args[0][0], 'level');
|
||||
assert.equal(this.MockBattery.observe.args[0][1],
|
||||
this.subject._boundRefreshText);
|
||||
assert.equal(this.MockBattery.observe.args[1][0], 'state');
|
||||
assert.equal(this.MockBattery.observe.args[1][1],
|
||||
this.subject._boundRefreshText);
|
||||
});
|
||||
|
||||
test('when enabled = false', function() {
|
||||
this.sinon.stub(this.MockBattery, 'unobserve');
|
||||
this.sinon.stub(this.subject, '_boundRefreshText');
|
||||
// The default enabled value is false. Set to true first.
|
||||
this.subject.enabled = true;
|
||||
this.subject.enabled = false;
|
||||
|
||||
sinon.assert.calledTwice(this.MockBattery.unobserve);
|
||||
assert.equal(this.MockBattery.unobserve.args[0][0], 'level');
|
||||
assert.equal(this.MockBattery.unobserve.args[0][1],
|
||||
this.subject._boundRefreshText);
|
||||
assert.equal(this.MockBattery.unobserve.args[1][0], 'state');
|
||||
assert.equal(this.MockBattery.unobserve.args[1][1],
|
||||
this.subject._boundRefreshText);
|
||||
});
|
||||
|
||||
suite('_boundRefreshText', function() {
|
||||
test('should call to localize correctly', function() {
|
||||
this.sinon.stub(this.MockL10n, 'setAttributes');
|
||||
this.subject._boundRefreshText();
|
||||
sinon.assert.calledWith(this.MockL10n.setAttributes, this.element,
|
||||
'battery-level-percent',
|
||||
sinon.match({level: this.MockBattery.level}));
|
||||
});
|
||||
});
|
||||
});
|
||||
138
gaia/apps/settings/test/unit/panels/root/bluetooth_item_test.js
Executable file
138
gaia/apps/settings/test/unit/panels/root/bluetooth_item_test.js
Executable file
|
|
@ -0,0 +1,138 @@
|
|||
'use strict';
|
||||
|
||||
suite('BluetoothItem', function() {
|
||||
var realL10n;
|
||||
var modules = [
|
||||
'shared_mocks/mock_l20n',
|
||||
'panels/root/bluetooth_item'
|
||||
];
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/settings_service': 'MockSettingsService',
|
||||
'modules/bluetooth/bluetooth_context': 'MockBluetooth'
|
||||
}
|
||||
};
|
||||
|
||||
suiteSetup(function(done) {
|
||||
this.MockSettingsService = {
|
||||
navigate: function() {}
|
||||
};
|
||||
|
||||
this.MockBluetooth = {
|
||||
enabled: false,
|
||||
numberOfPairedDevices: 0,
|
||||
firstPairedDeviceName: null,
|
||||
observe: function() {},
|
||||
unobserve: function() {}
|
||||
};
|
||||
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
define('MockSettingsService', function() {
|
||||
return this.MockSettingsService;
|
||||
}.bind(this));
|
||||
|
||||
define('MockBluetooth', function() {
|
||||
return this.MockBluetooth;
|
||||
}.bind(this));
|
||||
|
||||
requireCtx(modules, function(MockL10n, BluetoothItem) {
|
||||
realL10n = document.l10n;
|
||||
this.MockL10n = MockL10n;
|
||||
document.l10n = MockL10n;
|
||||
|
||||
this.BluetoothItem = BluetoothItem;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
document.l10n = realL10n;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.liElement = document.createElement('li');
|
||||
this.element = document.createElement('div');
|
||||
this.liElement.appendChild(this.element);
|
||||
this.subject = this.BluetoothItem(this.element);
|
||||
});
|
||||
|
||||
test('when enabled = true', function() {
|
||||
this.sinon.stub(this.MockBluetooth, 'observe');
|
||||
this.sinon.stub(this.subject, '_boundRefreshMenuDescription');
|
||||
|
||||
this.subject.enabled = true;
|
||||
sinon.assert.called(this.subject._boundRefreshMenuDescription);
|
||||
sinon.assert.calledTwice(this.MockBluetooth.observe);
|
||||
assert.equal(this.MockBluetooth.observe.args[0][0], 'enabled');
|
||||
assert.equal(this.MockBluetooth.observe.args[0][1],
|
||||
this.subject._boundRefreshMenuDescription);
|
||||
assert.equal(this.MockBluetooth.observe.args[1][0],
|
||||
'numberOfPairedDevices');
|
||||
assert.equal(this.MockBluetooth.observe.args[1][1],
|
||||
this.subject._boundRefreshMenuDescription);
|
||||
});
|
||||
|
||||
test('when enabled = false', function() {
|
||||
this.sinon.stub(this.MockBluetooth, 'unobserve');
|
||||
this.sinon.stub(this.subject, '_boundRefreshMenuDescription');
|
||||
// The default enabled value is false. Set to true first.
|
||||
this.subject.enabled = true;
|
||||
this.subject.enabled = false;
|
||||
sinon.assert.calledTwice(this.MockBluetooth.unobserve);
|
||||
assert.equal(this.MockBluetooth.unobserve.args[0][0], 'enabled');
|
||||
assert.equal(this.MockBluetooth.unobserve.args[0][1],
|
||||
this.subject._boundRefreshMenuDescription);
|
||||
assert.equal(this.MockBluetooth.unobserve.args[1][0],
|
||||
'numberOfPairedDevices');
|
||||
assert.equal(this.MockBluetooth.unobserve.args[1][1],
|
||||
this.subject._boundRefreshMenuDescription);
|
||||
});
|
||||
|
||||
suite('_boundRefreshMenuDescription > ', function() {
|
||||
suite('when Bluetooth module enabled = true, ' +
|
||||
'numberOfPairedDevices = 0', function() {
|
||||
setup(function() {
|
||||
this.MockBluetooth.enabled = true;
|
||||
this.MockBluetooth.numberOfPairedDevices = 0;
|
||||
});
|
||||
|
||||
test('should call to localize correctly', function() {
|
||||
this.subject._boundRefreshMenuDescription();
|
||||
assert.equal(this.element.getAttribute('data-l10n-id'),
|
||||
'bt-status-nopaired');
|
||||
});
|
||||
});
|
||||
|
||||
suite('when Bluetooth module enabled = true, ' +
|
||||
'numberOfPairedDevices = 3', function() {
|
||||
var resultObj;
|
||||
setup(function() {
|
||||
this.MockBluetooth.enabled = true;
|
||||
this.MockBluetooth.numberOfPairedDevices = 3;
|
||||
this.MockBluetooth.firstPairedDeviceName = 'device-A1';
|
||||
resultObj = {
|
||||
name: this.MockBluetooth.firstPairedDeviceName,
|
||||
n: this.MockBluetooth.numberOfPairedDevices - 1
|
||||
};
|
||||
});
|
||||
|
||||
test('should call to localize correctly', function() {
|
||||
this.sinon.stub(this.MockL10n, 'setAttributes');
|
||||
this.subject._boundRefreshMenuDescription();
|
||||
sinon.assert.calledWith(this.MockL10n.setAttributes, this.element,
|
||||
'bt-status-paired', sinon.match(resultObj));
|
||||
});
|
||||
});
|
||||
|
||||
suite('when Bluetooth module enabled = false', function() {
|
||||
test('should call to localize correctly', function() {
|
||||
// The default enabled value is false. Set to true first.
|
||||
this.MockBluetooth.enabled = true;
|
||||
this.MockBluetooth.enabled = false;
|
||||
this.subject._boundRefreshMenuDescription();
|
||||
assert.equal(this.element.getAttribute('data-l10n-id'),
|
||||
'bt-status-turnoff');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
63
gaia/apps/settings/test/unit/panels/root/language_item_test.js
Executable file
63
gaia/apps/settings/test/unit/panels/root/language_item_test.js
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
'use strict';
|
||||
|
||||
suite('LanguageItem', function() {
|
||||
var realL10n;
|
||||
var realLanguageList;
|
||||
var modules = [
|
||||
'shared_mocks/mock_l20n',
|
||||
'shared_mocks/mock_language_list',
|
||||
'panels/root/language_item',
|
||||
];
|
||||
var map = {
|
||||
'panels/root/language_item': {
|
||||
'shared/language_list': 'shared_mocks/mock_language_list'
|
||||
}
|
||||
};
|
||||
|
||||
suiteSetup(function(done) {
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
|
||||
requireCtx(modules, function(MockL10n, MockLanguageList, LanguageItem) {
|
||||
realL10n = document.l10n;
|
||||
document.l10n = MockL10n;
|
||||
|
||||
realLanguageList = window.LanguageList;
|
||||
window.LanguageList = MockLanguageList;
|
||||
|
||||
this.LanguageItem = LanguageItem;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
window.LanguageList = realLanguageList;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.element = document.createElement('div');
|
||||
this.subject = this.LanguageItem(this.element);
|
||||
});
|
||||
|
||||
test('when enabled = true', function() {
|
||||
this.sinon.stub(this.subject, '_boundRefreshText');
|
||||
this.sinon.stub(document, 'addEventListener');
|
||||
this.subject.enabled = true;
|
||||
sinon.assert.calledWith(this.subject._boundRefreshText);
|
||||
sinon.assert.calledWith(document.addEventListener,
|
||||
'DOMRetranslated', this.subject._boundRefreshText);
|
||||
});
|
||||
|
||||
test('when enabled = false', function() {
|
||||
this.sinon.stub(document, 'removeEventListener');
|
||||
// The default enabled value is false. Set to true first.
|
||||
this.subject._enabled = true;
|
||||
this.subject.enabled = false;
|
||||
sinon.assert.calledWith(document.removeEventListener,
|
||||
'DOMRetranslated', this.subject._boundRefreshText);
|
||||
});
|
||||
|
||||
test('_boundRefreshText', function() {
|
||||
this.subject._boundRefreshText();
|
||||
assert.equal(this.element.textContent, 'English (US)');
|
||||
});
|
||||
});
|
||||
113
gaia/apps/settings/test/unit/panels/root/nfc_item_test.js
Executable file
113
gaia/apps/settings/test/unit/panels/root/nfc_item_test.js
Executable file
|
|
@ -0,0 +1,113 @@
|
|||
'use strict';
|
||||
|
||||
suite('NFCItem', function() {
|
||||
var realMozNfc;
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'shared/settings_listener':'shared_mocks/mock_settings_listener'
|
||||
}
|
||||
};
|
||||
|
||||
var modules = [
|
||||
'panels/root/nfc_item',
|
||||
'shared_mocks/mock_settings_listener',
|
||||
];
|
||||
|
||||
setup(function(done) {
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
|
||||
requireCtx(modules, (NFCItem, MockSettingsListener) => {
|
||||
var div = document.createElement('div');
|
||||
var checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
div.appendChild(checkbox);
|
||||
|
||||
this.div = div;
|
||||
this.checkbox = checkbox;
|
||||
this.NFCItem = NFCItem;
|
||||
this.MockSettingsListener = MockSettingsListener;
|
||||
|
||||
realMozNfc = window.navigator.mozNfc;
|
||||
window.navigator.mozNfc = {};
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
window.navigator.mozNfc = realMozNfc;
|
||||
});
|
||||
|
||||
test('is visible and initialized if mozNfc defined', function() {
|
||||
var stubObserver = this.sinon.stub(this.MockSettingsListener, 'observe');
|
||||
var stubAddListener = this.sinon.stub(this.checkbox, 'addEventListener');
|
||||
|
||||
var nfcItem = this.NFCItem({
|
||||
nfcMenuItem: this.div,
|
||||
nfcCheckBox: this.checkbox
|
||||
});
|
||||
|
||||
assert.isFalse(this.div.hidden, 'hidden');
|
||||
assert.deepEqual(nfcItem._checkbox, this.checkbox);
|
||||
|
||||
assert.isTrue(stubAddListener.calledOnce, 'addEventListener');
|
||||
assert.equal(stubAddListener.firstCall.args[0], 'change');
|
||||
|
||||
assert.isTrue(stubObserver.calledOnce, 'observe');
|
||||
assert.equal(stubObserver.firstCall.args[0], 'nfc.status');
|
||||
});
|
||||
|
||||
test('setts checkbox to disabled on toggle change', function() {
|
||||
var nfcItem = this.NFCItem({
|
||||
nfcMenuItem: this.div,
|
||||
nfcCheckBox: this.checkbox
|
||||
});
|
||||
|
||||
var spyCheckboxChanged = this.sinon.spy(nfcItem, '_onCheckboxChanged');
|
||||
this.checkbox.disabled = false;
|
||||
|
||||
this.checkbox.dispatchEvent(new CustomEvent('change'));
|
||||
assert.isTrue(spyCheckboxChanged.calledOnce);
|
||||
assert.isTrue(this.checkbox.disabled);
|
||||
});
|
||||
|
||||
suite('NFC status changes', function() {
|
||||
var nfcItem;
|
||||
var stubNfcChanged;
|
||||
var idleStatus = ['enabled', 'disabled'];
|
||||
var transitionStatus = ['enabling', 'disabling'];
|
||||
|
||||
setup(function() {
|
||||
nfcItem = this.NFCItem({
|
||||
nfcMenuItem: this.div,
|
||||
nfcCheckBox: this.checkbox
|
||||
});
|
||||
stubNfcChanged = this.sinon.spy(nfcItem, '_onNfcStatusChanged');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
stubNfcChanged.restore();
|
||||
});
|
||||
|
||||
idleStatus.forEach((status) => {
|
||||
test('checkbox should be enabled when nfc.status ' + status, function() {
|
||||
nfcItem._checkbox.disabled = true;
|
||||
|
||||
this.MockSettingsListener.mTriggerCallback('nfc.status', status);
|
||||
assert.isTrue(stubNfcChanged.withArgs(status).calledOnce);
|
||||
assert.isFalse(nfcItem._checkbox.disabled);
|
||||
});
|
||||
});
|
||||
|
||||
transitionStatus.forEach((status) => {
|
||||
test('checkbox should be disabled when nfc.status ' + status, function() {
|
||||
nfcItem._checkbox.disabled = false;
|
||||
|
||||
this.MockSettingsListener.mTriggerCallback('nfc.status', status);
|
||||
assert.isTrue(stubNfcChanged.withArgs(status).calledOnce);
|
||||
assert.isTrue(nfcItem._checkbox.disabled);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
123
gaia/apps/settings/test/unit/panels/root/panel_test.js
Executable file
123
gaia/apps/settings/test/unit/panels/root/panel_test.js
Executable file
|
|
@ -0,0 +1,123 @@
|
|||
/* global loadBodyHTML, MockNavigatorSettings */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
suite('RootPanel', function() {
|
||||
var realSettings;
|
||||
var realMobileConnections;
|
||||
var panel;
|
||||
var MockAirplaneModeItem;
|
||||
|
||||
var modules = [
|
||||
'panels/root/panel',
|
||||
'shared_mocks/mock_navigator_moz_settings'
|
||||
];
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/settings_service': 'unit/mock_settings_service',
|
||||
'modules/settings_panel': 'MockSettingsPanel',
|
||||
'panels/root/root': 'MockRoot',
|
||||
'panels/root/airplane_mode_item': 'MockAirplaneModeItem',
|
||||
'panels/root/themes_item': 'MockThemesItem',
|
||||
'panels/root/addons_item': 'MockAddonsItem',
|
||||
'panels/root/stk_item': 'MockStkItem',
|
||||
'modules/bluetooth/version_detector': 'MockBluetoothVersionDetector'
|
||||
}
|
||||
};
|
||||
|
||||
setup(function(done) {
|
||||
// Create a new requirejs context
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
var that = this;
|
||||
|
||||
loadBodyHTML('_root.html');
|
||||
|
||||
// Define MockSettingsPanel
|
||||
define('MockSettingsPanel', function() {
|
||||
return function(options) {
|
||||
return {
|
||||
init: options.onInit,
|
||||
show: options.onShow,
|
||||
beforeShow: options.onBeforeShow,
|
||||
beforeHide: options.onBeforeHide,
|
||||
hide: options.onHide,
|
||||
uninit: options.onUninit,
|
||||
_showSimItems: function() {},
|
||||
_showDeveloperMenuItem: function() {}
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
// Define MockRoot
|
||||
this.mockRoot = {
|
||||
init: function() {}
|
||||
};
|
||||
define('MockRoot', function() {
|
||||
return function() {
|
||||
return that.mockRoot;
|
||||
};
|
||||
});
|
||||
|
||||
MockAirplaneModeItem = {
|
||||
enabled: false
|
||||
};
|
||||
define('MockAirplaneModeItem', function() {
|
||||
return function(element) {
|
||||
return MockAirplaneModeItem;
|
||||
};
|
||||
});
|
||||
|
||||
define('MockThemesItem', function() {
|
||||
return function(element) {
|
||||
return {};
|
||||
};
|
||||
});
|
||||
|
||||
define('MockAddonsItem', function() {
|
||||
return function(element) {
|
||||
return {};
|
||||
};
|
||||
});
|
||||
|
||||
define('MockStkItem', function() {
|
||||
return function(element) {
|
||||
return {};
|
||||
};
|
||||
});
|
||||
|
||||
define('MockBluetoothVersionDetector', function() {
|
||||
return {
|
||||
getVersion: function() {}
|
||||
};
|
||||
});
|
||||
|
||||
requireCtx(modules, function(RootPanel) {
|
||||
navigator.addIdleObserver = sinon.spy();
|
||||
realMobileConnections = navigator.mozMobileConnections;
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
|
||||
panel = RootPanel();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
navigator.mozMobileConnections = realMobileConnections;
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
test('AirplaneModeItem is enabled on show', function() {
|
||||
panel.init(document);
|
||||
panel.show();
|
||||
assert.isTrue(MockAirplaneModeItem.enabled);
|
||||
});
|
||||
|
||||
test('AirplaneModeItem is disabled on uninit', function() {
|
||||
panel.init(document);
|
||||
panel.uninit();
|
||||
assert.isFalse(MockAirplaneModeItem.enabled);
|
||||
});
|
||||
});
|
||||
192
gaia/apps/settings/test/unit/panels/root/root_test.js
Executable file
192
gaia/apps/settings/test/unit/panels/root/root_test.js
Executable file
|
|
@ -0,0 +1,192 @@
|
|||
/* global MockNavigatorSettings */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
suite('Root', function() {
|
||||
var realMobileConnections;
|
||||
var realSettings;
|
||||
var panel;
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'shared/lazyLoader': 'MockLazyLoader'
|
||||
}
|
||||
};
|
||||
var modules = [
|
||||
'panels/root/root',
|
||||
'MockLazyLoader',
|
||||
'shared_mocks/mock_navigator_moz_settings'
|
||||
];
|
||||
|
||||
setup(function(done) {
|
||||
this.MockLazyLoader = {
|
||||
load: function(scripts, callback) { setTimeout(callback); }
|
||||
};
|
||||
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
loadBodyHTML('_root.html');
|
||||
|
||||
define('MockLazyLoader', function() {
|
||||
return this.MockLazyLoader;
|
||||
}.bind(this));
|
||||
|
||||
requireCtx(modules, function(Root, MockLazyLoader, MockNavigatorSettings) {
|
||||
realMobileConnections = navigator.mozMobileConnections;
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
|
||||
panel = Root();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
navigator.mozMobileConnections = realMobileConnections;
|
||||
});
|
||||
|
||||
suite('init', function() {
|
||||
var fakeTimer;
|
||||
|
||||
setup(function() {
|
||||
fakeTimer = sinon.useFakeTimers();
|
||||
this.sinon.stub(panel, '_loadScripts');
|
||||
panel.init(document.body);
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fakeTimer.restore();
|
||||
});
|
||||
|
||||
test('_loadScripts should be called', function() {
|
||||
fakeTimer.tick();
|
||||
assert.ok(panel._loadScripts.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('should show/hide nfc item correctly', function() {
|
||||
var realNfc;
|
||||
var nfcItem;
|
||||
|
||||
setup(function() {
|
||||
realNfc = navigator.mozNfc;
|
||||
nfcItem = document.querySelector('.nfc-settings');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozNfc = realNfc;
|
||||
});
|
||||
|
||||
test('nfc is available', function() {
|
||||
navigator.mozNfc = {'aa': 'bb'};
|
||||
panel.init(document.body);
|
||||
assert.isFalse(nfcItem.hidden);
|
||||
});
|
||||
|
||||
test('nfc is not available', function() {
|
||||
navigator.mozNfc = null;
|
||||
panel.init(document.body);
|
||||
assert.isTrue(nfcItem.hidden);
|
||||
});
|
||||
});
|
||||
|
||||
suite('should show/hide sim items correctly', function() {
|
||||
var callSettingsItem;
|
||||
var dataConnectivityItem;
|
||||
var messagingItem;
|
||||
var simSecurityItem;
|
||||
var simCardManagerItem;
|
||||
|
||||
test('no mobile connections', function() {
|
||||
navigator.mozMobileConnections = null;
|
||||
panel.init(document.body);
|
||||
callSettingsItem = document.getElementById('call-settings');
|
||||
dataConnectivityItem = document.getElementById('data-connectivity');
|
||||
messagingItem = document.getElementById('messaging-settings');
|
||||
simSecurityItem = document.getElementById('simSecurity-settings');
|
||||
simCardManagerItem = document.getElementById('simCardManager-settings');
|
||||
assert.isTrue(callSettingsItem.hidden);
|
||||
assert.isTrue(dataConnectivityItem.hidden);
|
||||
assert.isTrue(messagingItem.hidden);
|
||||
assert.isTrue(simSecurityItem.hidden);
|
||||
assert.isTrue(simCardManagerItem.hidden);
|
||||
});
|
||||
|
||||
test('single sim', function() {
|
||||
navigator.mozMobileConnections = {
|
||||
length: 1
|
||||
};
|
||||
panel.init(document.body);
|
||||
callSettingsItem = document.getElementById('call-settings');
|
||||
dataConnectivityItem = document.getElementById('data-connectivity');
|
||||
messagingItem = document.getElementById('messaging-settings');
|
||||
simSecurityItem = document.getElementById('simSecurity-settings');
|
||||
simCardManagerItem = document.getElementById('simCardManager-settings');
|
||||
assert.isFalse(callSettingsItem.hidden);
|
||||
assert.isFalse(dataConnectivityItem.hidden);
|
||||
assert.isFalse(messagingItem.hidden);
|
||||
assert.isFalse(simSecurityItem.hidden);
|
||||
assert.isTrue(simCardManagerItem.hidden);
|
||||
});
|
||||
|
||||
test('multiple sims', function() {
|
||||
navigator.mozMobileConnections = {
|
||||
length: 2
|
||||
};
|
||||
panel.init(document.body);
|
||||
callSettingsItem = document.getElementById('call-settings');
|
||||
dataConnectivityItem = document.getElementById('data-connectivity');
|
||||
messagingItem = document.getElementById('messaging-settings');
|
||||
simSecurityItem = document.getElementById('simSecurity-settings');
|
||||
simCardManagerItem = document.getElementById('simCardManager-settings');
|
||||
assert.isFalse(callSettingsItem.hidden);
|
||||
assert.isFalse(dataConnectivityItem.hidden);
|
||||
assert.isFalse(messagingItem.hidden);
|
||||
assert.isTrue(simSecurityItem.hidden);
|
||||
assert.isFalse(simCardManagerItem.hidden);
|
||||
});
|
||||
});
|
||||
|
||||
suite('should show/hide developer menu item correctly', function() {
|
||||
var developerMenuItem;
|
||||
|
||||
setup(function() {
|
||||
MockNavigatorSettings.mSetup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
MockNavigatorSettings.mTeardown();
|
||||
});
|
||||
|
||||
test('developer menu is enabled', function(done) {
|
||||
MockNavigatorSettings.mSet({
|
||||
'developer.menu.enabled': true
|
||||
});
|
||||
panel.init(document.body);
|
||||
developerMenuItem =
|
||||
document.querySelector('[data-show-name="developer.menu.enabled"]');
|
||||
panel._showDeveloperMenuItem().then(function() {
|
||||
assert.isFalse(developerMenuItem.hidden);
|
||||
}, function() {
|
||||
// This function does not reject.
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('developer menu is disabled', function(done) {
|
||||
MockNavigatorSettings.mSet({
|
||||
'developer.menu.enabled': false
|
||||
});
|
||||
panel.init(document.body);
|
||||
developerMenuItem =
|
||||
document.querySelector('[data-show-name="developer.menu.enabled"]');
|
||||
panel._showDeveloperMenuItem().then(function() {
|
||||
assert.isTrue(developerMenuItem.hidden);
|
||||
}, function() {
|
||||
// This function does not reject.
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
217
gaia/apps/settings/test/unit/panels/root/sim_securiy_item_test.js
Executable file
217
gaia/apps/settings/test/unit/panels/root/sim_securiy_item_test.js
Executable file
|
|
@ -0,0 +1,217 @@
|
|||
'use strict';
|
||||
|
||||
suite('simSecurityItem', function() {
|
||||
var modules = [
|
||||
'shared_mocks/mock_simslot_manager',
|
||||
'unit/mock_airplane_mode_helper',
|
||||
'modules/sim_security',
|
||||
'panels/root/sim_security_item',
|
||||
];
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'shared/simslot_manager': 'shared_mocks/mock_simslot_manager',
|
||||
'shared/airplane_mode_helper': 'unit/mock_airplane_mode_helper',
|
||||
'modules/sim_security': 'MockSimSecurity'
|
||||
}
|
||||
};
|
||||
|
||||
var simSecurityItem;
|
||||
var mockSIMSlotManager;
|
||||
var mockAirplaneModeHelper;
|
||||
var mockSimSecurity;
|
||||
|
||||
setup(function(done) {
|
||||
var self = this;
|
||||
|
||||
define('MockSimSecurity', function() {
|
||||
return {
|
||||
addEventListener: function() {},
|
||||
getCardLock: function() {}
|
||||
};
|
||||
});
|
||||
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
requireCtx(modules, function(MockSIMSlotManager,
|
||||
MockAirplaneModeHelper, MockSimSecurity ,SimSecurityItem) {
|
||||
mockSIMSlotManager = MockSIMSlotManager;
|
||||
mockAirplaneModeHelper = MockAirplaneModeHelper;
|
||||
mockSimSecurity = MockSimSecurity;
|
||||
|
||||
self.sinon.stub(mockSIMSlotManager, 'get', function() {
|
||||
return {
|
||||
isAbsent: function() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var element = document.createElement('div');
|
||||
simSecurityItem = SimSecurityItem(element);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('_updateUI', function() {
|
||||
suite('if APM is on', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(mockAirplaneModeHelper, 'getStatus', function() {
|
||||
return 'enabled';
|
||||
});
|
||||
});
|
||||
|
||||
test('properties would be set correctly', function(done) {
|
||||
simSecurityItem._updateUI().then(function() {
|
||||
assert.equal(simSecurityItem._element.style.fontStyle, 'italic');
|
||||
assert.equal(simSecurityItem._element.getAttribute('data-l10n-id'),
|
||||
'simCardNotReady');
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('if APM is off, and no simcard', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(mockAirplaneModeHelper, 'getStatus', function() {
|
||||
return 'disabled';
|
||||
});
|
||||
|
||||
simSecurityItem._activeSlot = {
|
||||
simCard: {
|
||||
cardState: null
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
test('properties would be set correctly', function(done) {
|
||||
simSecurityItem._updateUI().then(function() {
|
||||
assert.equal(simSecurityItem._element.style.fontStyle, 'italic');
|
||||
assert.equal(simSecurityItem._element.getAttribute('data-l10n-id'),
|
||||
'noSimCard');
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('if APM is off, and simcard is unknown', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(mockAirplaneModeHelper, 'getStatus', function() {
|
||||
return 'disabled';
|
||||
});
|
||||
|
||||
simSecurityItem._activeSlot = {
|
||||
simCard: {
|
||||
cardState: 'unknown'
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
test('properties would be set correctly', function(done) {
|
||||
simSecurityItem._updateUI().then(function() {
|
||||
assert.equal(simSecurityItem._element.style.fontStyle, 'italic');
|
||||
assert.equal(simSecurityItem._element.getAttribute('data-l10n-id'),
|
||||
'unknownSimCardState');
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('if APM is off, simcard is ready', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(mockAirplaneModeHelper, 'getStatus', function() {
|
||||
return 'disabled';
|
||||
});
|
||||
|
||||
simSecurityItem._activeSlot = {
|
||||
simCard: {
|
||||
cardState: 'normal'
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
test('and if pin is enabled', function(done) {
|
||||
this.sinon.stub(mockSimSecurity, 'getCardLock', function() {
|
||||
return Promise.resolve({
|
||||
enabled: true
|
||||
});
|
||||
});
|
||||
|
||||
simSecurityItem._updateUI().then(function() {
|
||||
assert.equal(simSecurityItem._element.style.fontStyle, 'normal');
|
||||
assert.equal(simSecurityItem._element.getAttribute('data-l10n-id'),
|
||||
'enabled');
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('and if pin is disabled', function(done) {
|
||||
this.sinon.stub(mockSimSecurity, 'getCardLock', function() {
|
||||
return Promise.resolve({
|
||||
enabled: false
|
||||
});
|
||||
});
|
||||
|
||||
simSecurityItem._updateUI().then(function() {
|
||||
assert.equal(simSecurityItem._element.style.fontStyle, 'normal');
|
||||
assert.equal(simSecurityItem._element.getAttribute('data-l10n-id'),
|
||||
'disabled');
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('enabled item', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(mockAirplaneModeHelper, 'addEventListener');
|
||||
this.sinon.stub(mockAirplaneModeHelper, 'removeEventListener');
|
||||
this.sinon.stub(simSecurityItem, '_boundUpdateUI');
|
||||
});
|
||||
|
||||
suite('wont do anything', function() {
|
||||
test('if this is a DSDS device', function() {
|
||||
this.sinon.stub(mockSIMSlotManager, 'isMultiSIM', function() {
|
||||
return true;
|
||||
});
|
||||
simSecurityItem.enabled = true;
|
||||
assert.isFalse(simSecurityItem._boundUpdateUI.called);
|
||||
});
|
||||
|
||||
test('if there is no active slot', function() {
|
||||
this.sinon.stub(mockSIMSlotManager, 'isMultiSIM', function() {
|
||||
return true;
|
||||
});
|
||||
simSecurityItem._activeSlot = null;
|
||||
simSecurityItem.enabled = true;
|
||||
assert.isFalse(simSecurityItem._boundUpdateUI.called);
|
||||
});
|
||||
|
||||
test('if internal state is the same with outter', function() {
|
||||
this.sinon.stub(mockSIMSlotManager, 'isMultiSIM', function() {
|
||||
return true;
|
||||
});
|
||||
simSecurityItem._activeSlot = {};
|
||||
simSecurityItem._itemEnabled = true;
|
||||
simSecurityItem.enabled = true;
|
||||
assert.isFalse(simSecurityItem._boundUpdateUI.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('would do related works', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(mockSIMSlotManager, 'isMultiSIM', function() {
|
||||
return false;
|
||||
});
|
||||
simSecurityItem._activeSlot = {};
|
||||
simSecurityItem._itemEnabled = null;
|
||||
});
|
||||
|
||||
test('if we are going to enable simSecurityItem', function() {
|
||||
simSecurityItem.enabled = true;
|
||||
assert.isTrue(simSecurityItem._boundUpdateUI.called);
|
||||
assert.isTrue(mockAirplaneModeHelper.addEventListener.called);
|
||||
});
|
||||
|
||||
test('if we are going to disable simSecurityItem', function() {
|
||||
simSecurityItem.enabled = false;
|
||||
assert.isTrue(mockAirplaneModeHelper.removeEventListener.called);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
226
gaia/apps/settings/test/unit/panels/root/stk_item_test.js
Executable file
226
gaia/apps/settings/test/unit/panels/root/stk_item_test.js
Executable file
|
|
@ -0,0 +1,226 @@
|
|||
'use strict';
|
||||
/* global MockNavigatorSettings */
|
||||
requireApp('settings/shared/test/unit/load_body_html_helper.js');
|
||||
requireApp('settings/test/unit/mock_navigator_settings.js');
|
||||
|
||||
suite('STK Item >', function() {
|
||||
var modules = [
|
||||
'panels/root/stk_item',
|
||||
'shared_mocks/mock_l20n',
|
||||
'shared_mocks/mock_stk_helper',
|
||||
'shared_mocks/mock_dump',
|
||||
'shared_mocks/mock_navigator_moz_icc_manager'
|
||||
];
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'shared/intl/l20n' : 'shared_mocks/mock_l20n',
|
||||
'shared/stk_helper': 'shared_mocks/mock_stk_helper'
|
||||
}
|
||||
};
|
||||
|
||||
var realL10n;
|
||||
var realMozIccManager;
|
||||
var realMozSettings;
|
||||
var subject;
|
||||
var fakeTimer;
|
||||
var mockSTKHelper;
|
||||
|
||||
var dummySTKMenuEntries = {
|
||||
'title': 'DummyOperator',
|
||||
'items': [{
|
||||
'identifier': 1,
|
||||
'text': 'Dummy 1'
|
||||
},
|
||||
{
|
||||
'identifier': 2,
|
||||
'text': 'Dummy 2'
|
||||
},
|
||||
{
|
||||
'identifier': 3,
|
||||
'text': 'Dummy 3'
|
||||
}],
|
||||
'presentationType': 0
|
||||
};
|
||||
|
||||
setup(function(done) {
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
requireCtx(modules, function(STKItem, MockL10n, MockSTKHelper,
|
||||
MockDump, MockNavigatorMozIccManager) {
|
||||
realMozSettings = navigator.mozSettings;
|
||||
loadBodyHTML('./_root.html');
|
||||
realL10n = document.l10n;
|
||||
document.l10n = MockL10n;
|
||||
realMozIccManager = navigator.mozIccManager;
|
||||
navigator.mozIccManager = MockNavigatorMozIccManager;
|
||||
mockSTKHelper = MockSTKHelper;
|
||||
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
|
||||
window.Settings = {
|
||||
mozSettings: navigator.mozSettings
|
||||
};
|
||||
|
||||
MockDump.mSuiteSetup();
|
||||
fakeTimer = sinon.useFakeTimers();
|
||||
|
||||
subject = STKItem({
|
||||
iccMainHeader: document.querySelector('#icc-mainheader'),
|
||||
iccEntries: document.querySelector('#icc-entries')
|
||||
});
|
||||
fakeTimer.tick();
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
document.l10n = realL10n;
|
||||
navigator.mozIccManager = realMozIccManager;
|
||||
navigator.mozSettings = realMozSettings;
|
||||
MockNavigatorSettings.mTeardown();
|
||||
fakeTimer.restore();
|
||||
});
|
||||
|
||||
suite('Single SIM >', function() {
|
||||
setup(function() {
|
||||
MockNavigatorSettings.mTriggerObservers('icc.applications', {
|
||||
settingValue: JSON.stringify({
|
||||
'1': {
|
||||
'iccId': '1111111111111',
|
||||
'entries': dummySTKMenuEntries
|
||||
}})});
|
||||
});
|
||||
|
||||
test('One entry into the STK applications list', function() {
|
||||
assert.equal(subject._elements.iccEntries.childElementCount, 1);
|
||||
});
|
||||
|
||||
test('Operator name showed in the list', function() {
|
||||
assert.equal(document.querySelector(
|
||||
'#icc-entries li a').textContent, 'DummyOperator');
|
||||
});
|
||||
|
||||
test('SIM number not showed in the list', function() {
|
||||
assert.isNull(document.querySelector(
|
||||
'#icc-entries li small'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('Dual SIM >', function() {
|
||||
setup(function() {
|
||||
MockNavigatorSettings.mTriggerObservers('icc.applications', {
|
||||
settingValue: JSON.stringify({
|
||||
'1': {
|
||||
'iccId': '1111111111111',
|
||||
'entries': dummySTKMenuEntries
|
||||
},
|
||||
'2': {
|
||||
'iccId': '2222222222222',
|
||||
'entries': dummySTKMenuEntries
|
||||
}})});
|
||||
});
|
||||
|
||||
test('Two entries into the STK applications list', function() {
|
||||
assert.equal(subject._elements.iccEntries.childElementCount, 2);
|
||||
});
|
||||
|
||||
test('Operator name (SIM 1) showed in the list', function() {
|
||||
assert.equal(document.querySelector(
|
||||
'#icc-entries li span').textContent, 'DummyOperator');
|
||||
});
|
||||
|
||||
test('SIM number (SIM 1) showed in the list', function() {
|
||||
assert.equal(document.querySelector(
|
||||
'#icc-entries li small').getAttribute('data-l10n-id'), 'sim1');
|
||||
});
|
||||
|
||||
test('Operator name (SIM 2) showed in the list', function() {
|
||||
assert.equal(document.querySelector(
|
||||
'#icc-entries li:nth-child(2) span').textContent, 'DummyOperator');
|
||||
});
|
||||
|
||||
test('SIM number (SIM 2) showed in the list', function() {
|
||||
assert.equal(document.querySelector('#icc-entries li:nth-child(2) small').
|
||||
getAttribute('data-l10n-id'), 'sim2');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Icons >', function() {
|
||||
var icons = [{
|
||||
'pixels':[0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0x000000FF,0x000000FF,0x000000FF,0x000000FF,
|
||||
0xFFFFFFFF,0x000000FF,0xFFFFFFFF,0x000000FF,
|
||||
0xFFFFFFFF,0x000000FF,0x000000FF,0xFFFFFFFF],
|
||||
'codingScheme': 'basic',
|
||||
'width': 4,
|
||||
'height': 4
|
||||
}];
|
||||
|
||||
function updateMenu(withIcons) {
|
||||
if (withIcons) {
|
||||
dummySTKMenuEntries.icons = icons;
|
||||
} else {
|
||||
delete dummySTKMenuEntries.icons;
|
||||
}
|
||||
|
||||
MockNavigatorSettings.mTriggerObservers('icc.applications', {
|
||||
settingValue: JSON.stringify({
|
||||
'1': {
|
||||
'iccId': '1111111111111',
|
||||
'entries': dummySTKMenuEntries
|
||||
},
|
||||
'2': {
|
||||
'iccId': '2222222222222',
|
||||
'entries': dummySTKMenuEntries
|
||||
}})});
|
||||
}
|
||||
|
||||
setup(function() {
|
||||
this.sinon.stub(mockSTKHelper, 'getFirstIconRawData', function(stkItem) {
|
||||
return stkItem.icons && stkItem.icons.length > 0 ?
|
||||
stkItem.icons[0] : null;
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function () {
|
||||
delete dummySTKMenuEntries.icons;
|
||||
});
|
||||
|
||||
test('Icons should be rendered correctly', function() {
|
||||
updateMenu(true);
|
||||
assert.isDefined(subject._elements.iccEntries.dataset.customIcon);
|
||||
assert.equal(document.querySelector('#icc-entries li:nth-child(1) span').
|
||||
childElementCount, 1);
|
||||
assert.equal(document.querySelector('#icc-entries li:nth-child(2) span').
|
||||
childElementCount, 1);
|
||||
});
|
||||
|
||||
test('Default icon should be rendered if no icons are defined', function() {
|
||||
updateMenu();
|
||||
assert.isUndefined(subject._elements.iccEntries.dataset.customIcon);
|
||||
assert.equal(document.querySelector('#icc-entries li:nth-child(1) a').
|
||||
dataset.icon, 'sim-toolkit');
|
||||
assert.equal(document.querySelector('#icc-entries li:nth-child(2) a').
|
||||
dataset.icon, 'sim-toolkit');
|
||||
assert.isNull(
|
||||
document.querySelector('#icc-entries li:nth-child(1) > span'),
|
||||
'span with icon should not be added to the DOM');
|
||||
assert.isNull(
|
||||
document.querySelector('#icc-entries li:nth-child(2) > span'),
|
||||
'span with icon should not be added to the DOM');
|
||||
});
|
||||
|
||||
test('Update menu in ICC panel.', function() {
|
||||
window.Settings.currentPanel = '#icc';
|
||||
updateMenu(false);
|
||||
assert.equal(window.Settings.currentPanel, '#root');
|
||||
});
|
||||
|
||||
test('Update menu in other panel.', function() {
|
||||
window.Settings.currentPanel = '#developer';
|
||||
updateMenu(false);
|
||||
assert.equal(window.Settings.currentPanel, '#developer');
|
||||
});
|
||||
});
|
||||
});
|
||||
84
gaia/apps/settings/test/unit/panels/root/storage_app_item_test.js
Executable file
84
gaia/apps/settings/test/unit/panels/root/storage_app_item_test.js
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
'use strict';
|
||||
|
||||
suite('AppStorageItem', function() {
|
||||
var modules = ['panels/root/storage_app_item'];
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/app_storage': 'MockAppStorage',
|
||||
'modules/storage_helper': 'MockStorageHelper'
|
||||
}
|
||||
};
|
||||
|
||||
suiteSetup(function(done) {
|
||||
// Define MockAppStorage
|
||||
this.MockAppStorage = {
|
||||
isMock: true,
|
||||
usedPercentage: 1,
|
||||
totalSize: 1,
|
||||
usedSize: 1,
|
||||
freeSize: 1,
|
||||
observe: function() {},
|
||||
unobserve: function() {}
|
||||
};
|
||||
|
||||
this.MockStorageHelper = {
|
||||
showFormatedSize: function(element, l10nId, size) {return size;}
|
||||
};
|
||||
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
define('MockAppStorage', () => {
|
||||
return this.MockAppStorage;
|
||||
});
|
||||
|
||||
define('MockStorageHelper', () => {
|
||||
return this.MockStorageHelper;
|
||||
});
|
||||
|
||||
requireCtx(modules, StorageAppItem => {
|
||||
this.StorageAppItem = StorageAppItem;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.subject = this.StorageAppItem(document.createElement('div'));
|
||||
});
|
||||
|
||||
test('when enabled = true', function() {
|
||||
this.sinon.stub(this.MockAppStorage, 'observe');
|
||||
this.sinon.stub(this.subject, '_updateAppFreeSpace');
|
||||
this.sinon.stub(this.subject, '_boundUpdateAppFreeSpace');
|
||||
this.subject.enabled = true;
|
||||
|
||||
sinon.assert.called(this.subject._updateAppFreeSpace);
|
||||
sinon.assert.calledOnce(this.MockAppStorage.observe);
|
||||
assert.isTrue(this.MockAppStorage.observe.calledWith('freeSize',
|
||||
this.subject._boundUpdateAppFreeSpace));
|
||||
});
|
||||
|
||||
test('when enabled = false', function() {
|
||||
this.sinon.stub(this.MockAppStorage, 'unobserve');
|
||||
this.sinon.stub(this.subject, '_updateAppFreeSpace');
|
||||
this.sinon.stub(this.subject, '_boundUpdateAppFreeSpace');
|
||||
// The default enabled value is false. Set to true first.
|
||||
this.subject._enabled = true;
|
||||
this.subject.enabled = false;
|
||||
|
||||
sinon.assert.calledOnce(this.MockAppStorage.unobserve);
|
||||
assert.isTrue(this.MockAppStorage.unobserve.calledWith('freeSize',
|
||||
this.subject._boundUpdateAppFreeSpace));
|
||||
});
|
||||
|
||||
test('when current = false and enabled = false', function() {
|
||||
this.sinon.stub(this.MockAppStorage, 'unobserve');
|
||||
this.sinon.stub(this.subject, '_updateAppFreeSpace');
|
||||
this.sinon.stub(this.subject, '_boundUpdateAppFreeSpace');
|
||||
// set enabled value to false to let the further false set not action.
|
||||
this.subject._enabled = false;
|
||||
this.subject.enabled = false;
|
||||
|
||||
assert.isFalse(this.MockAppStorage.unobserve.called);
|
||||
assert.isFalse(this.MockAppStorage.unobserve.called);
|
||||
});
|
||||
});
|
||||
148
gaia/apps/settings/test/unit/panels/root/themes_item_test.js
Executable file
148
gaia/apps/settings/test/unit/panels/root/themes_item_test.js
Executable file
|
|
@ -0,0 +1,148 @@
|
|||
'use strict';
|
||||
|
||||
suite('ThemesItem', function() {
|
||||
|
||||
var modules = [
|
||||
'panels/root/themes_item',
|
||||
'unit/mock_apps_cache'
|
||||
];
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/apps_cache': 'unit/mock_apps_cache'
|
||||
}
|
||||
};
|
||||
|
||||
var themesItem;
|
||||
var mockAppsCache;
|
||||
|
||||
setup(function(done) {
|
||||
var self = this;
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
|
||||
requireCtx(modules, function(ThemesItem, MockAppsCache) {
|
||||
mockAppsCache = MockAppsCache;
|
||||
self.sinon.stub(mockAppsCache, 'addEventListener');
|
||||
self.sinon.stub(mockAppsCache, 'removeEventListener');
|
||||
|
||||
var element = document.createElement('div');
|
||||
themesItem = ThemesItem(element);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('enabled', function() {
|
||||
setup(function() {
|
||||
themesItem._enabled = false;
|
||||
this.sinon.stub(themesItem, '_updateThemeSectionVisibility');
|
||||
themesItem.enabled = true;
|
||||
});
|
||||
test('will call _updateThemeSectionVisibility', function() {
|
||||
assert.isTrue(themesItem._updateThemeSectionVisibility.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('init', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(themesItem, '_updateThemeSectionVisibility');
|
||||
// We assumed we did install two theme apps by default
|
||||
mockAppsCache._apps = [
|
||||
{ manifest: { role: 'theme' } },
|
||||
{ manifest: { role: 'theme' } },
|
||||
{ manifest: { role: 'homescreen' } },
|
||||
];
|
||||
});
|
||||
|
||||
test('we will do related works', function(done) {
|
||||
themesItem.init().then(function() {
|
||||
assert.equal(
|
||||
mockAppsCache.addEventListener.getCall(0).args[1],
|
||||
themesItem._boundUpdateThemes);
|
||||
|
||||
assert.equal(
|
||||
mockAppsCache.addEventListener.getCall(1).args[1],
|
||||
themesItem._boundUpdateThemes);
|
||||
|
||||
assert.isTrue(themesItem._updateThemeSectionVisibility.called);
|
||||
assert.equal(themesItem._themeCount, 2);
|
||||
}, function() {
|
||||
// This callback should not be executed
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('_isThemeApp', function() {
|
||||
var themeApp = {
|
||||
manifest: {
|
||||
role: 'theme'
|
||||
}
|
||||
};
|
||||
|
||||
var homescreenApp = {
|
||||
manifest: {
|
||||
role: 'homescreen'
|
||||
}
|
||||
};
|
||||
|
||||
test('we can check whether this is theme app or not', function() {
|
||||
assert.isTrue(themesItem._isThemeApp(themeApp));
|
||||
assert.isFalse(themesItem._isThemeApp(homescreenApp));
|
||||
});
|
||||
});
|
||||
|
||||
suite('_updateThemes', function() {
|
||||
setup(function() {
|
||||
// We assumed we already installed one theme by default
|
||||
themesItem._themeCount = 1;
|
||||
this.sinon.stub(themesItem, '_updateThemeSectionVisibility');
|
||||
this.sinon.stub(themesItem, '_isThemeApp').returns(true);
|
||||
});
|
||||
|
||||
suite('received install event', function() {
|
||||
setup(function() {
|
||||
themesItem._updateThemes({ type : 'install' });
|
||||
});
|
||||
|
||||
test('add themeCount and update visibility', function() {
|
||||
assert.isTrue(themesItem._updateThemeSectionVisibility.called);
|
||||
assert.equal(themesItem._themeCount, 2);
|
||||
});
|
||||
});
|
||||
|
||||
suite('received uninstall event', function() {
|
||||
setup(function() {
|
||||
themesItem._updateThemes({ type : 'uninstall' });
|
||||
});
|
||||
|
||||
test('add themeCount and update visibility', function() {
|
||||
assert.isTrue(themesItem._updateThemeSectionVisibility.called);
|
||||
assert.equal(themesItem._themeCount, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('_updateThemeSectionVisibility', function() {
|
||||
suite('1 theme installed', function() {
|
||||
setup(function() {
|
||||
themesItem._themeCount = 1;
|
||||
themesItem._updateThemeSectionVisibility();
|
||||
});
|
||||
|
||||
test('we would hide section', function() {
|
||||
assert.isTrue(themesItem._element.hidden);
|
||||
});
|
||||
});
|
||||
|
||||
suite('2 themes installed', function() {
|
||||
setup(function() {
|
||||
themesItem._themeCount = 2;
|
||||
themesItem._updateThemeSectionVisibility();
|
||||
});
|
||||
|
||||
test('we would show section', function() {
|
||||
assert.isFalse(themesItem._element.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
81
gaia/apps/settings/test/unit/panels/root/wifi_item_test.js
Executable file
81
gaia/apps/settings/test/unit/panels/root/wifi_item_test.js
Executable file
|
|
@ -0,0 +1,81 @@
|
|||
/* global MockNavigatorMozWifiManager */
|
||||
'use strict';
|
||||
|
||||
requireApp(
|
||||
'settings/shared/test/unit/mocks/mock_navigator_moz_wifi_manager.js');
|
||||
|
||||
suite('WifiItem', function() {
|
||||
var subject;
|
||||
var element;
|
||||
var realWifiManager;
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/wifi_context': 'MockWifiContext'
|
||||
}
|
||||
};
|
||||
|
||||
var modules = [
|
||||
'panels/root/wifi_item'
|
||||
];
|
||||
|
||||
setup(function(done) {
|
||||
// Define MockAppStorage
|
||||
this.MockWifiContext = {
|
||||
isMock: true,
|
||||
wifiStatusText: {id: 'disabled'},
|
||||
addEventListener: function() {},
|
||||
removeEventListener: function() {}
|
||||
};
|
||||
|
||||
define('MockWifiContext', function() {
|
||||
return this.MockWifiContext;
|
||||
}.bind(this));
|
||||
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
requireCtx(modules, function(WifiItem) {
|
||||
realWifiManager = navigator.mozWifiManager;
|
||||
navigator.mozWifiManager = MockNavigatorMozWifiManager;
|
||||
MockNavigatorMozWifiManager.mSetup();
|
||||
element = document.createElement('small');
|
||||
subject = WifiItem(element);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozWifiManager = realWifiManager;
|
||||
});
|
||||
|
||||
test('when enabled = true', function() {
|
||||
this.sinon.stub(this.MockWifiContext, 'addEventListener');
|
||||
this.sinon.stub(subject, '_boundUpdateWifiDesc');
|
||||
subject.enabled = true;
|
||||
|
||||
sinon.assert.called(subject._boundUpdateWifiDesc);
|
||||
this.MockWifiContext.addEventListener.calledWith(
|
||||
'wifiStatusTextChange', subject._boundUpdateWifiDesc
|
||||
);
|
||||
// assert.isTrue(this.MockAppStorage.observe.calledWith('freeSize',
|
||||
// this.subject._boundUpdateAppFreeSpace));
|
||||
});
|
||||
|
||||
test('when enabled = false', function() {
|
||||
this.sinon.stub(this.MockWifiContext, 'removeEventListener');
|
||||
this.sinon.stub(subject, '_boundUpdateWifiDesc');
|
||||
// The default enabled value is false. Set to true first.
|
||||
subject._enabled = true;
|
||||
subject.enabled = false;
|
||||
|
||||
this.MockWifiContext.removeEventListener.calledWith(
|
||||
'wifiStatusTextChange', subject._boundUpdateWifiDesc
|
||||
);
|
||||
});
|
||||
|
||||
test('when _updateWifiDesc', function() {
|
||||
this.sinon.spy(window, 'dispatchEvent');
|
||||
subject._updateWifiDesc(element);
|
||||
|
||||
assert.ok(window.dispatchEvent.called);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue