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
17
gaia/apps/operatorvariant/test/unit/.jshintrc
Executable file
17
gaia/apps/operatorvariant/test/unit/.jshintrc
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"extends": "../../../../.jshintrc",
|
||||
"predef": [
|
||||
"assert",
|
||||
"suite",
|
||||
"test",
|
||||
"setup",
|
||||
"teardown",
|
||||
"suiteSetup",
|
||||
"suiteTeardown",
|
||||
"require",
|
||||
"requireApp",
|
||||
"sinon",
|
||||
"mocha",
|
||||
"loadBodyHTML"
|
||||
]
|
||||
}
|
||||
53
gaia/apps/operatorvariant/test/unit/browser_customizer_test.js
Executable file
53
gaia/apps/operatorvariant/test/unit/browser_customizer_test.js
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
/* global MockNavigatorDatastore, MockDatastore,
|
||||
browserCustomizer, BookmarksDatabase */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/browser_customizer.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_datastore.js');
|
||||
require('/shared/js/bookmarks_database.js');
|
||||
|
||||
suite('BrowserCustomizer >', function() {
|
||||
var realDatastore = null,
|
||||
bookmarkDBSpy = null,
|
||||
url = 'http://mozilla.org',
|
||||
name = 'mozilla',
|
||||
data = {
|
||||
bookmarks: [ {
|
||||
id: '0',
|
||||
uri: url,
|
||||
title: name
|
||||
}]
|
||||
};
|
||||
|
||||
suiteSetup(function() {
|
||||
bookmarkDBSpy = sinon.spy(BookmarksDatabase, 'add');
|
||||
navigator.getDataStores = MockNavigatorDatastore.getDataStores;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.getDataStores = realDatastore;
|
||||
bookmarkDBSpy.restore();
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
bookmarkDBSpy.reset();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
MockDatastore._inError = false;
|
||||
MockDatastore._records = Object.create(null);
|
||||
});
|
||||
|
||||
test('First run with valid SIM. Set bookmarks.', function() {
|
||||
browserCustomizer.simPresentOnFirstBoot = true;
|
||||
browserCustomizer.set(data);
|
||||
assert.deepEqual(bookmarkDBSpy.args[0][0], {
|
||||
type: 'url',
|
||||
name: name,
|
||||
url: url,
|
||||
icon: undefined
|
||||
}, 'Arguments not equal');
|
||||
});
|
||||
});
|
||||
130
gaia/apps/operatorvariant/test/unit/customizer_test.js
Executable file
130
gaia/apps/operatorvariant/test/unit/customizer_test.js
Executable file
|
|
@ -0,0 +1,130 @@
|
|||
/* global requireApp, suite, suiteSetup, sinon, Resources, setup, Customizer,
|
||||
test, assert, suite, teardown, suiteTeardown */
|
||||
|
||||
'use strict';
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/resources.js');
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
|
||||
suite(' Customizer > ', function() {
|
||||
var realSettings;
|
||||
|
||||
var eventName = 'test-event';
|
||||
var resourceType = 'blob';
|
||||
var resourcePath = 'resources/wallpaper.jpg';
|
||||
|
||||
suite(' init > ', function() {
|
||||
var resourceLoaderSpy;
|
||||
var customizer;
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
|
||||
resourceLoaderSpy = sinon.spy(Resources, 'load');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
customizer = new Customizer(eventName, resourceType);
|
||||
customizer.set = function () {};
|
||||
resourceLoaderSpy.reset();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
customizer = null;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
resourceLoaderSpy.restore();
|
||||
});
|
||||
|
||||
test(' resource loaded ', function() {
|
||||
// Init for adding the listener
|
||||
customizer.init();
|
||||
// Check that listener is working as expected
|
||||
var eventContent = {
|
||||
detail: {
|
||||
setting: eventName,
|
||||
value: resourcePath,
|
||||
simPresentOnFirstBoot: 'A Random Value'
|
||||
}
|
||||
};
|
||||
var customizationEvent = new CustomEvent('customization', eventContent);
|
||||
// Once we dispatch the event, handler should
|
||||
// manage this properly
|
||||
window.dispatchEvent(customizationEvent);
|
||||
assert.isTrue(resourceLoaderSpy.calledOnce);
|
||||
assert.equal(customizer.simPresentOnFirstBoot,
|
||||
eventContent.detail.simPresentOnFirstBoot);
|
||||
// A new event should not be handled, because
|
||||
// we are removing the listener when the event
|
||||
// is handled.
|
||||
window.dispatchEvent(customizationEvent);
|
||||
assert.isTrue(resourceLoaderSpy.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' set > ', function() {
|
||||
test(' resource available ', function(done) {
|
||||
var eventContent = {
|
||||
detail: {
|
||||
setting: eventName,
|
||||
value: resourcePath,
|
||||
simPresentOnFirstBoot: 'a value'
|
||||
}
|
||||
};
|
||||
|
||||
var onerror = function() {
|
||||
assert.ok(false, 'Resource not loaded properly');
|
||||
done();
|
||||
};
|
||||
var customizerSuccessful =
|
||||
new Customizer(eventName, resourceType, onerror);
|
||||
customizerSuccessful.set = function() {
|
||||
assert.equal(customizerSuccessful.simPresentOnFirstBoot,
|
||||
eventContent.detail.simPresentOnFirstBoot);
|
||||
done();
|
||||
};
|
||||
// Init for adding the listener
|
||||
customizerSuccessful.init();
|
||||
// Check that listener is working as expected
|
||||
var customizationEvent = new CustomEvent('customization', eventContent);
|
||||
// Once we dispatch the event, handler should
|
||||
// manage this properly
|
||||
window.dispatchEvent(customizationEvent);
|
||||
});
|
||||
|
||||
test(' resource unavailable ', function(done) {
|
||||
var eventContent = {
|
||||
detail: {
|
||||
setting: eventName,
|
||||
value: 'wrong/path/file.jpg',
|
||||
simPresentOnFirstBoot: 'Another value'
|
||||
}
|
||||
};
|
||||
|
||||
var customizerError = new Customizer(eventName, resourceType, function() {
|
||||
assert.equal(customizerError.simPresentOnFirstBoot,
|
||||
eventContent.detail.simPresentOnFirstBoot);
|
||||
done();
|
||||
});
|
||||
customizerError.set = function() {
|
||||
assert.ok(false, 'Resource available when it should not');
|
||||
done();
|
||||
};
|
||||
// Init for adding the listener
|
||||
customizerError.init();
|
||||
// Check that listener is working as expected
|
||||
var customizationEvent = new CustomEvent('customization', eventContent);
|
||||
// Once we dispatch the event, handler should
|
||||
// manage this properly
|
||||
window.dispatchEvent(customizationEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
38
gaia/apps/operatorvariant/test/unit/data_ftu_customizer_test.js
Executable file
38
gaia/apps/operatorvariant/test/unit/data_ftu_customizer_test.js
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
/* global requireApp, suite, suiteSetup, suiteTeardown, setup, teardown, test,
|
||||
assert, sinon, dataFTUCustomizer */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/data_ftu_customizer.js');
|
||||
|
||||
suite('Data FTU customizer >', function() {
|
||||
var createLockSpy;
|
||||
var realSettings;
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
createLockSpy = sinon.spy(navigator.mozSettings, 'createLock');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
createLockSpy.restore();
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
createLockSpy.reset();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
});
|
||||
|
||||
test(' set > ', function() {
|
||||
dataFTUCustomizer.set(true);
|
||||
assert.isTrue(createLockSpy.calledOnce);
|
||||
});
|
||||
});
|
||||
113
gaia/apps/operatorvariant/test/unit/data_roaming_customizer_test.js
Executable file
113
gaia/apps/operatorvariant/test/unit/data_roaming_customizer_test.js
Executable file
|
|
@ -0,0 +1,113 @@
|
|||
/* global dataRoamingCustomizer */
|
||||
'use strict';
|
||||
|
||||
require('/test/unit/mock_navigator_moz_settings.js');
|
||||
require('/js/customizers/customizer.js');
|
||||
require('/js/customizers/data_roaming_customizer.js');
|
||||
|
||||
|
||||
suite('DataRoaming customizer >', function() {
|
||||
var TINY_TIMEOUT = 20;
|
||||
var DATA_ROAMING_SETTING = 'ril.data.roaming_enabled';
|
||||
|
||||
var realSettings;
|
||||
|
||||
var testCases = [
|
||||
{
|
||||
title: 'Set true value. SIM present on first boot > ',
|
||||
inputValue: true,
|
||||
currentValue: false,
|
||||
expectedValue: true,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'Set false value. SIM present on first boot > ',
|
||||
inputValue: false,
|
||||
currentValue: false,
|
||||
expectedValue: false,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title:
|
||||
'Set false value, setting no defined when SIM present on first boot > ',
|
||||
inputValue: false,
|
||||
expectedValue: false,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title:
|
||||
'Set true value, setting no defined when SIM present on first boot > ',
|
||||
inputValue: true,
|
||||
expectedValue: true,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'Set to wrong value,(default false) SIM present on first boot > ',
|
||||
inputValue: 12,
|
||||
currentValue: false,
|
||||
expectedValue: false,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set true value. Previous RUN with no SIM (or unconfigured one)> ',
|
||||
inputValue: true,
|
||||
expectedValue: undefined,
|
||||
simPresentOnFirstBoot: false
|
||||
},
|
||||
{
|
||||
title: 'set false value. Previous RUN with no SIM (or unconfigured one)>',
|
||||
inputValue: false,
|
||||
expectedValue: undefined,
|
||||
simPresentOnFirstBoot: false
|
||||
},
|
||||
{
|
||||
title: 'Set false value. Expected value do not change >',
|
||||
inputValue: false,
|
||||
simPresentOnFirstBoot: false,
|
||||
currentValue: true,
|
||||
expectedValue: true
|
||||
},
|
||||
{
|
||||
title: 'Set true value. Expected value do not change >',
|
||||
inputValue: true,
|
||||
simPresentOnFirstBoot: false,
|
||||
currentValue: false,
|
||||
expectedValue: false
|
||||
}
|
||||
];
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
this.sinon.clock.restore();
|
||||
});
|
||||
|
||||
testCases.forEach(function(testCase) {
|
||||
test(testCase.title, function() {
|
||||
if (testCase.currentValue !== undefined) {
|
||||
window.MockNavigatorSettings.mSettings[DATA_ROAMING_SETTING] =
|
||||
testCase.currentValue;
|
||||
}
|
||||
dataRoamingCustomizer.simPresentOnFirstBoot =
|
||||
testCase.simPresentOnFirstBoot;
|
||||
dataRoamingCustomizer.set(testCase.inputValue);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
var mSettings = window.MockNavigatorSettings.mSettings;
|
||||
assert.strictEqual(mSettings[DATA_ROAMING_SETTING],
|
||||
testCase.expectedValue,
|
||||
DATA_ROAMING_SETTING + ' has a incorrect value');
|
||||
});
|
||||
});
|
||||
});
|
||||
45
gaia/apps/operatorvariant/test/unit/default_contacts_customizer_test.js
Executable file
45
gaia/apps/operatorvariant/test/unit/default_contacts_customizer_test.js
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
/* global requireApp, suite, suiteSetup, MockNavigatorContacts,
|
||||
MockMozContact, sinon, suiteTeardown, setup, test, defaultContactsCustomizer,
|
||||
assert*/
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_mozContact.js');
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_contacts.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/default_contacts_customizer.js');
|
||||
|
||||
var mozContact;
|
||||
|
||||
suite('Default contacts customizer >', function() {
|
||||
var realMozContacts, saveContactSpy;
|
||||
var contactsMockup = [
|
||||
{'givenName': ['Foo']},
|
||||
{'givenName': ['Bar']}
|
||||
];
|
||||
|
||||
suiteSetup(function() {
|
||||
realMozContacts = navigator.mozContacts;
|
||||
navigator.mozContacts = window.MockNavigatorContacts;
|
||||
mozContact = MockMozContact;
|
||||
saveContactSpy = sinon.spy(MockNavigatorContacts, 'save');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozContacts = realMozContacts;
|
||||
mozContact = null;
|
||||
saveContactSpy.restore();
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
saveContactSpy.reset();
|
||||
});
|
||||
|
||||
test(' set ', function() {
|
||||
defaultContactsCustomizer.set(contactsMockup);
|
||||
// As contactsMockup has 2 contacts, this method
|
||||
// should be called twice
|
||||
assert.equal(saveContactSpy.callCount, contactsMockup.length);
|
||||
});
|
||||
});
|
||||
124
gaia/apps/operatorvariant/test/unit/keyboard_settings_customizer_test.js
Executable file
124
gaia/apps/operatorvariant/test/unit/keyboard_settings_customizer_test.js
Executable file
|
|
@ -0,0 +1,124 @@
|
|||
/* global keyboardSettingsCustomizer, requireApp, suite, suiteSetup,
|
||||
suiteTeardown, setup, teardown, test, assert */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/keyboard_settings_customizer.js');
|
||||
|
||||
suite('Keyboard settings customizer >', function() {
|
||||
const TINY_TIMEOUT = 20;
|
||||
var realSettings;
|
||||
|
||||
var testCases = [
|
||||
{
|
||||
title: 'First run with valid SIM - options with valid values > ',
|
||||
inputValues: {
|
||||
'values': {
|
||||
'keyboard.vibration': false,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': false,
|
||||
'keyboard.wordsuggestion': true
|
||||
}
|
||||
},
|
||||
actualValues: {
|
||||
'keyboard.vibration': true,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': false,
|
||||
'keyboard.wordsuggestion': true
|
||||
},
|
||||
expectedValues: {
|
||||
'keyboard.vibration': false,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': false,
|
||||
'keyboard.wordsuggestion': true
|
||||
},
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'First Run with valid SIM - set invalid values > ',
|
||||
inputValues: {
|
||||
'values': {
|
||||
'keyboard.vibration': [],
|
||||
'keyboard.wordsuggestion': 'aFakeValue',
|
||||
'keyboard.clicksound': {}
|
||||
}
|
||||
},
|
||||
'actualValues': {
|
||||
'keyboard.vibration': true,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': false,
|
||||
'keyboard.wordsuggestion': true
|
||||
},
|
||||
expectedValues: {
|
||||
'keyboard.vibration': true,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': false,
|
||||
'keyboard.wordsuggestion': true
|
||||
},
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'first run without valid SIM > ',
|
||||
inputValues: {
|
||||
'values': {
|
||||
'keyboard.vibration': false,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': false,
|
||||
'keyboard.wordsuggestion': true
|
||||
}
|
||||
},
|
||||
'actualValues': {
|
||||
'keyboard.vibration': true,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': undefined,
|
||||
'keyboard.wordsuggestion': true
|
||||
},
|
||||
expectedValues: {
|
||||
'keyboard.vibration': true,
|
||||
'keyboard.autocorrect': true,
|
||||
'keyboard.clicksound': undefined,
|
||||
'keyboard.wordsuggestion': true
|
||||
},
|
||||
simPresentOnFirstBoot: false
|
||||
}
|
||||
];
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
this.sinon.clock.restore();
|
||||
});
|
||||
|
||||
testCases.forEach(function(testCase) {
|
||||
test(testCase.title, function() {
|
||||
var actualValues = testCase.actualValues;
|
||||
for (var avKey in actualValues) {
|
||||
window.MockNavigatorSettings.mSettings[avKey] = actualValues[avKey];
|
||||
}
|
||||
keyboardSettingsCustomizer.simPresentOnFirstBoot =
|
||||
testCase.simPresentOnFirstBoot;
|
||||
keyboardSettingsCustomizer.set(testCase.inputValues);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
var mSettings = window.MockNavigatorSettings.mSettings;
|
||||
for (var evKey in testCase.expectedValues) {
|
||||
assert.strictEqual(mSettings[evKey], testCase.expectedValues[evKey],
|
||||
evKey + ' has a incorrect value');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
341
gaia/apps/operatorvariant/test/unit/known_networks_customizer_test.js
Executable file
341
gaia/apps/operatorvariant/test/unit/known_networks_customizer_test.js
Executable file
|
|
@ -0,0 +1,341 @@
|
|||
/* global knownNetworksCustomizer, MockWindowMozWifiNetwork */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_wifi_manager.js');
|
||||
requireApp('operatorvariant/test/unit/mock_window_moz_wifi_network.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/known_networks_customizer.js');
|
||||
|
||||
suite('Known networks customizer >', function() {
|
||||
var realWifiManager;
|
||||
var realWifiNetwork;
|
||||
|
||||
suiteSetup(function() {
|
||||
realWifiManager = navigator.mozWifiManager;
|
||||
navigator.mozWifiManager = window.MockNavigatorMozWifiManager;
|
||||
realWifiNetwork = window.MozWifiNetwork;
|
||||
window.MozWifiNetwork = MockWindowMozWifiNetwork;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozWifiManager = realWifiManager;
|
||||
window.MozWifiNetwork = realWifiNetwork;
|
||||
window.MockNavigatorMozWifiManager = null;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
navigator.mozWifiManager.mSetup();
|
||||
});
|
||||
|
||||
var testCases = [
|
||||
{
|
||||
'title': 'Wrong Wifi datas ',
|
||||
'inputKeysValues': {
|
||||
'bad': {
|
||||
'bsid': '00:3a:9a:d1:e3:c0'
|
||||
}
|
||||
},
|
||||
'expectedResult': []
|
||||
},
|
||||
{
|
||||
'title': 'Wifi without key type ',
|
||||
'inputKeysValues': {
|
||||
'onlyId': {
|
||||
'ssid': 'onlyId'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'onlyId'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Existing wifi ',
|
||||
'inputKeysValues': {
|
||||
'firstWifiAdd': {
|
||||
'ssid': 'existing-Wifi',
|
||||
'keyType': 'WEP',
|
||||
'password': '1234567891234'
|
||||
},
|
||||
'existing-Wifi': {
|
||||
'ssid': 'existing-Wifi',
|
||||
'keyType': 'WPA-PSK',
|
||||
'password': '123456789'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'existing-Wifi',
|
||||
'keyManagement': 'WEP',
|
||||
'security': ['WEP'],
|
||||
'capabilities': [],
|
||||
'wep': '1234567891234'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WEP without key ',
|
||||
'inputKeysValues': {
|
||||
'wep-without-key': {
|
||||
'ssid': 'wep-without-key',
|
||||
'keyType': 'WEP'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wep-without-key',
|
||||
'keyManagement': 'WEP',
|
||||
'security': ['WEP'],
|
||||
'capabilities': []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WEP with wrong key ',
|
||||
'inputKeysValues': {
|
||||
'wep-wrong-key': {
|
||||
'ssid': 'wep-wrong-key',
|
||||
'keyType': 'WEP',
|
||||
'password': 'wrong1'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wep-wrong-key',
|
||||
'keyManagement': 'WEP',
|
||||
'security': ['WEP'],
|
||||
'capabilities': []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WEP OK ',
|
||||
'inputKeysValues': {
|
||||
'wep-ok': {
|
||||
'ssid': 'wep-ok',
|
||||
'keyType': 'WEP',
|
||||
'password': '1234567891234'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wep-ok',
|
||||
'keyManagement': 'WEP',
|
||||
'security': ['WEP'],
|
||||
'capabilities': [],
|
||||
'wep': '1234567891234'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WEP OK with WPS ',
|
||||
'inputKeysValues': {
|
||||
'wep-ok-wps': {
|
||||
'ssid': 'wep-ok-wps',
|
||||
'keyType': 'WEP',
|
||||
'password': '1234567891234',
|
||||
'capabilities': 'WPS'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wep-ok-wps',
|
||||
'keyManagement': 'WEP',
|
||||
'security': ['WEP'],
|
||||
'capabilities': ['WPS'],
|
||||
'wep': '1234567891234'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-PSK without key ',
|
||||
'inputKeysValues': {
|
||||
'wpa-psk-nokey': {
|
||||
'ssid': 'wpa-psk-nokey',
|
||||
'keyType': 'WPA-PSK'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-psk-nokey',
|
||||
'keyManagement': 'WPA-PSK',
|
||||
'security': ['WPA-PSK'],
|
||||
'capabilities': []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-PSK key OK ',
|
||||
'inputKeysValues': {
|
||||
'wpa-psk-ok': {
|
||||
'ssid': 'wpa-psk-ok',
|
||||
'keyType': 'WPA-PSK',
|
||||
'password': '123456789'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-psk-ok',
|
||||
'keyManagement': 'WPA-PSK',
|
||||
'security': ['WPA-PSK'],
|
||||
'capabilities': [],
|
||||
'psk': '123456789'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-PSK wrong key ',
|
||||
'inputKeysValues': {
|
||||
'wpa-psk-ko-key': {
|
||||
'ssid': 'wpa-psk-ko-key',
|
||||
'keyType': 'WPA-PSK',
|
||||
'password': '1234',
|
||||
'capabilities': 'WPS'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-psk-ko-key',
|
||||
'keyManagement': 'WPA-PSK',
|
||||
'security': ['WPA-PSK'],
|
||||
'capabilities': ['WPS']
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-PSK wrong key ',
|
||||
'inputKeysValues': {
|
||||
'wpa-psk-ko-key': {
|
||||
'ssid': 'wpa-psk-ko-key',
|
||||
'keyType': 'WPA-PSK',
|
||||
'password': '1234'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-psk-ko-key',
|
||||
'keyManagement': 'WPA-PSK',
|
||||
'security': ['WPA-PSK'],
|
||||
'capabilities': []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-EAP without eap ',
|
||||
'inputKeysValues': {
|
||||
'wpa-eap-no-eap': {
|
||||
'ssid': 'wpa-eap-no-eap',
|
||||
'keyType': 'WPA-EAP'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-eap-no-eap',
|
||||
'keyManagement': 'WPA-EAP',
|
||||
'security': ['WPA-EAP'],
|
||||
'capabilities': []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-EAP wrong eap ',
|
||||
'inputKeysValues': {
|
||||
'wpa-eap-ko-eap': {
|
||||
'ssid': 'wpa-eap-ko-eap',
|
||||
'keyType': 'WPA-EAP',
|
||||
'eap': 'wrong'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-eap-ko-eap',
|
||||
'keyManagement': 'WPA-EAP',
|
||||
'security': ['WPA-EAP'],
|
||||
'capabilities': [],
|
||||
'eap': 'wrong'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-EAP eap=SIM ',
|
||||
'inputKeysValues': {
|
||||
'wpa-eap-sim': {
|
||||
'ssid': 'wpa-eap-sim',
|
||||
'keyType': 'WPA-EAP',
|
||||
'eap': 'SIM'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-eap-sim',
|
||||
'keyManagement': 'WPA-EAP',
|
||||
'security': ['WPA-EAP'],
|
||||
'capabilities': [],
|
||||
'eap': 'SIM'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-EAP eap ok and not SIM with key ok ',
|
||||
'inputKeysValues': {
|
||||
'wpa-eap-peap': {
|
||||
'ssid': 'wpa-eap-peap',
|
||||
'keyType': 'WPA-EAP',
|
||||
'capabilities': 'WPS',
|
||||
'eap': 'PEAP',
|
||||
'password': '123456789',
|
||||
'identity': 'HI\\cjc'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-eap-peap',
|
||||
'keyManagement': 'WPA-EAP',
|
||||
'security': ['WPA-EAP'],
|
||||
'capabilities': ['WPS'],
|
||||
'eap': 'PEAP',
|
||||
'password': '123456789',
|
||||
'identity': 'HI\\cjc'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'Wifi WPA-EAP eap ok and not SIM with phase2 ok ',
|
||||
'inputKeysValues': {
|
||||
'wpa-eap-peap-phase2': {
|
||||
'ssid': 'wpa-eap-peap-phase2',
|
||||
'keyType': 'WPA-EAP',
|
||||
'capabilities': 'WPS',
|
||||
'eap': 'PEAP',
|
||||
'password': '123456789',
|
||||
'identity': 'HI\\cjc',
|
||||
'phase2': 'PAP'
|
||||
}
|
||||
},
|
||||
'expectedResult': [
|
||||
{
|
||||
'ssid': 'wpa-eap-peap-phase2',
|
||||
'keyManagement': 'WPA-EAP',
|
||||
'security': ['WPA-EAP'],
|
||||
'capabilities': ['WPS'],
|
||||
'eap': 'PEAP',
|
||||
'password': '123456789',
|
||||
'identity': 'HI\\cjc',
|
||||
'phase2': 'PAP'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
testCases.forEach(function(testCase) {
|
||||
test(testCase.title, function() {
|
||||
knownNetworksCustomizer.set(testCase.inputKeysValues);
|
||||
var knownNet = navigator.mozWifiManager.getKnownNetworks().result;
|
||||
assert.deepEqual(knownNet, testCase.expectedResult,
|
||||
'Known networks not equals');
|
||||
});
|
||||
});
|
||||
});
|
||||
13
gaia/apps/operatorvariant/test/unit/mock_file_reader.js
Executable file
13
gaia/apps/operatorvariant/test/unit/mock_file_reader.js
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
function MockFileReader() {}
|
||||
|
||||
MockFileReader.prototype.readAsDataURL = function readAsText(file) {
|
||||
if (this.onloadend) {
|
||||
this.result = file;
|
||||
this.onloadend();
|
||||
}
|
||||
};
|
||||
|
||||
window.MockFileReader = MockFileReader;
|
||||
|
||||
13
gaia/apps/operatorvariant/test/unit/mock_mozContact.js
Executable file
13
gaia/apps/operatorvariant/test/unit/mock_mozContact.js
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
var MockMozContact = (function() {});
|
||||
|
||||
MockMozContact.prototype.init = function(obj) {
|
||||
var self = this;
|
||||
Object.keys(obj).forEach(function(k) {
|
||||
self[k] = obj[k];
|
||||
});
|
||||
};
|
||||
|
||||
MockMozContact.prototype.save = function() {};
|
||||
19
gaia/apps/operatorvariant/test/unit/mock_navigator_contacts.js
Executable file
19
gaia/apps/operatorvariant/test/unit/mock_navigator_contacts.js
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
var MockNavigatorContacts = (function() {
|
||||
var contacts = [];
|
||||
return {
|
||||
save: function(contact) {
|
||||
contacts.push(contact);
|
||||
return {};
|
||||
},
|
||||
get contacts() {
|
||||
return contacts;
|
||||
},
|
||||
resetContacts: function() {
|
||||
contacts = [];
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
window.MockNavigatorContacts = MockNavigatorContacts;
|
||||
91
gaia/apps/operatorvariant/test/unit/mock_navigator_moz_settings.js
Executable file
91
gaia/apps/operatorvariant/test/unit/mock_navigator_moz_settings.js
Executable file
|
|
@ -0,0 +1,91 @@
|
|||
'use strict';
|
||||
|
||||
var MockNavigatorSettings = (function() {
|
||||
var observers = {};
|
||||
// Set default message size with 300KB
|
||||
var settings = {
|
||||
'dom.mms.operatorSizeLimitation' : 300
|
||||
};
|
||||
var removedObservers = {};
|
||||
|
||||
function mns_mLockSet(obj) {
|
||||
for (var key in obj) {
|
||||
settings[key] = obj[key];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
function mns_mLockGet(key) {
|
||||
var resultObj = {};
|
||||
resultObj[key] = settings[key];
|
||||
var settingsRequest = {
|
||||
result: resultObj,
|
||||
addEventListener: function(name, cb) {
|
||||
settingsRequest['on' + name] = cb;
|
||||
}
|
||||
};
|
||||
|
||||
setTimeout(function() {
|
||||
if (settingsRequest.onsuccess) {
|
||||
settingsRequest.onsuccess();
|
||||
}
|
||||
});
|
||||
|
||||
return settingsRequest;
|
||||
}
|
||||
|
||||
function mns_addObserver(name, cb) {
|
||||
observers[name] = observers[name] || [];
|
||||
observers[name].push(cb);
|
||||
}
|
||||
|
||||
function mns_removeObserver(name, cb) {
|
||||
removedObservers[name] = removedObservers[name] || [];
|
||||
removedObservers[name].push(cb);
|
||||
}
|
||||
|
||||
function mns_createLock() {
|
||||
return {
|
||||
set: mns_mLockSet,
|
||||
get: mns_mLockGet
|
||||
};
|
||||
}
|
||||
|
||||
function mns_mTriggerObservers(name, args) {
|
||||
var theseObservers = observers[name];
|
||||
|
||||
if (! theseObservers) {
|
||||
return;
|
||||
}
|
||||
|
||||
theseObservers.forEach(function(func) {
|
||||
func(args);
|
||||
});
|
||||
}
|
||||
|
||||
function mns_teardown() {
|
||||
observers = {};
|
||||
settings = {};
|
||||
removedObservers = {};
|
||||
}
|
||||
|
||||
return {
|
||||
addObserver: mns_addObserver,
|
||||
removeObserver: mns_removeObserver,
|
||||
createLock: mns_createLock,
|
||||
|
||||
mTriggerObservers: mns_mTriggerObservers,
|
||||
mTeardown: mns_teardown,
|
||||
get mObservers() {
|
||||
return observers;
|
||||
},
|
||||
get mSettings() {
|
||||
return settings;
|
||||
},
|
||||
get mRemovedObservers() {
|
||||
return removedObservers;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
window.MockNavigatorSettings = MockNavigatorSettings;
|
||||
56
gaia/apps/operatorvariant/test/unit/mock_navigator_moz_wifi_manager.js
Executable file
56
gaia/apps/operatorvariant/test/unit/mock_navigator_moz_wifi_manager.js
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
/* exported MockNavigatorMozWifiManager */
|
||||
|
||||
'use strict';
|
||||
|
||||
var MockNavigatorMozWifiManager = (function() {
|
||||
var networks;
|
||||
var knownNetworks = [];
|
||||
|
||||
function mwm_setNetworks(aNetworks) {
|
||||
networks = aNetworks;
|
||||
}
|
||||
|
||||
function mwm_associate(network) {
|
||||
if (network.dontConnect) {
|
||||
delete network.dontConnect;
|
||||
}
|
||||
knownNetworks.push(network);
|
||||
}
|
||||
|
||||
function mwm_getKnownNetworks() {
|
||||
/*jshint validthis: true */
|
||||
var self = this;
|
||||
return {
|
||||
result: self.knownNetworks,
|
||||
set onsuccess(callback) {
|
||||
this.result = self.knownNetworks;
|
||||
callback && callback(this);
|
||||
},
|
||||
get onsuccess() {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function mwm_mSetup() {
|
||||
networks = undefined;
|
||||
knownNetworks = [];
|
||||
}
|
||||
|
||||
return {
|
||||
get networks() {
|
||||
return networks;
|
||||
},
|
||||
get knownNetworks() {
|
||||
return knownNetworks;
|
||||
},
|
||||
setNetworks: mwm_setNetworks,
|
||||
connection: {
|
||||
network: null
|
||||
},
|
||||
associate: mwm_associate,
|
||||
getKnownNetworks: mwm_getKnownNetworks,
|
||||
mSetup: mwm_mSetup
|
||||
};
|
||||
})();
|
||||
|
||||
window.MockNavigatorMozWifiManager = MockNavigatorMozWifiManager;
|
||||
9
gaia/apps/operatorvariant/test/unit/mock_window_moz_wifi_network.js
Executable file
9
gaia/apps/operatorvariant/test/unit/mock_window_moz_wifi_network.js
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
/* exported MockWindowMozWifiNetwork */
|
||||
|
||||
'use strict';
|
||||
|
||||
function MockWindowMozWifiNetwork(network) {
|
||||
for (var elem in network) {
|
||||
this[elem] = network[elem];
|
||||
}
|
||||
}
|
||||
89
gaia/apps/operatorvariant/test/unit/mock_xmlhttprequest.js
Executable file
89
gaia/apps/operatorvariant/test/unit/mock_xmlhttprequest.js
Executable file
|
|
@ -0,0 +1,89 @@
|
|||
'use strict';
|
||||
|
||||
(function() {
|
||||
var lastInstance;
|
||||
// To avoid race conditions between defining the XHR and sending the data
|
||||
var storedResponse;
|
||||
|
||||
function MockXMLHttpRequest() {
|
||||
lastInstance = this;
|
||||
}
|
||||
|
||||
var throwAtNextSend = false,
|
||||
objectToThrow = null;
|
||||
|
||||
function mxhr_mThrowAtNextSend(e) {
|
||||
throwAtNextSend = true;
|
||||
objectToThrow = e || new Error('throwing an exception');
|
||||
}
|
||||
|
||||
function mxhr_mTeardown() {
|
||||
throwAtNextSend = false;
|
||||
objectToThrow = null;
|
||||
delete MockXMLHttpRequest.mLastOpenedUrl;
|
||||
lastInstance = null;
|
||||
storedResponse = undefined;
|
||||
}
|
||||
|
||||
function mxhr_send() {
|
||||
if (throwAtNextSend) {
|
||||
throwAtNextSend = false;
|
||||
throw objectToThrow;
|
||||
}
|
||||
if (storedResponse) {
|
||||
mxhr_mOnLoad(storedResponse);
|
||||
}
|
||||
}
|
||||
|
||||
function mxhr_open(method, url, opts) {
|
||||
MockXMLHttpRequest.mLastOpenedUrl = url;
|
||||
}
|
||||
|
||||
function mxhr_mSendError() {
|
||||
lastInstance && lastInstance.onerror && lastInstance.onerror();
|
||||
}
|
||||
|
||||
function mxhr_mOnLoad(states) {
|
||||
storedResponse = {};
|
||||
storedResponse.status = 200;
|
||||
for (var keyS in states) {
|
||||
storedResponse[keyS] = states[keyS];
|
||||
}
|
||||
if (lastInstance) {
|
||||
lastInstance.status = 200;
|
||||
for (var keySR in storedResponse) {
|
||||
lastInstance[keySR] = storedResponse[keySR];
|
||||
}
|
||||
lastInstance.onload && lastInstance.onload();
|
||||
storedResponse = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function mxhr_mSendReadyState(states) {
|
||||
if (lastInstance) {
|
||||
lastInstance.readyState = XMLHttpRequest.DONE;
|
||||
lastInstance.status = 200;
|
||||
for (var key in states) {
|
||||
lastInstance[key] = states[key];
|
||||
}
|
||||
lastInstance.onreadystatechange && lastInstance.onreadystatechange();
|
||||
}
|
||||
}
|
||||
|
||||
MockXMLHttpRequest.prototype = {
|
||||
open: mxhr_open,
|
||||
send: mxhr_send,
|
||||
DONE: XMLHttpRequest.prototype.DONE,
|
||||
overrideMimeType: function() {}
|
||||
};
|
||||
|
||||
MockXMLHttpRequest.mThrowAtNextSend = mxhr_mThrowAtNextSend;
|
||||
MockXMLHttpRequest.mTeardown = mxhr_mTeardown;
|
||||
MockXMLHttpRequest.mSendError = mxhr_mSendError;
|
||||
MockXMLHttpRequest.mSendOnLoad = mxhr_mOnLoad;
|
||||
MockXMLHttpRequest.mSendReadyState = mxhr_mSendReadyState;
|
||||
MockXMLHttpRequest.DONE = XMLHttpRequest.DONE;
|
||||
|
||||
|
||||
window.MockXMLHttpRequest = MockXMLHttpRequest;
|
||||
})();
|
||||
55
gaia/apps/operatorvariant/test/unit/network_type_customizer_test.js
Executable file
55
gaia/apps/operatorvariant/test/unit/network_type_customizer_test.js
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
/* global networkTypeCustomizer, requireApp, suite, suiteSetup,
|
||||
suiteTeardown, setup, teardown, test, assert */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp(
|
||||
'operatorvariant/shared/test/unit/mocks/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/network_type_customizer.js');
|
||||
|
||||
suite('Network type customizer >', function() {
|
||||
var realSettings;
|
||||
var TINY_TIMEOUT = 10;
|
||||
var SETTING_DATA_ICON = 'operatorResources.data.icon';
|
||||
var testCases = [
|
||||
{
|
||||
title: 'set > ',
|
||||
values: {
|
||||
'lte': '4GChng',
|
||||
'ehrpd': '4GChng',
|
||||
'hspa+': 'H+Chng',
|
||||
'hsdpa': 'HChng', 'hsupa': 'HChng', 'hspa': 'HChng'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
window.MockNavigatorSettings.mSettings[SETTING_DATA_ICON] = '{}';
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
this.sinon.clock.restore();
|
||||
});
|
||||
|
||||
testCases.forEach(function(testCase) {
|
||||
test(testCase.title, function() {
|
||||
networkTypeCustomizer.set(testCase.values);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
var mSettings = window.MockNavigatorSettings.mSettings;
|
||||
assert.deepEqual(mSettings[SETTING_DATA_ICON], testCase.values);
|
||||
});
|
||||
});
|
||||
});
|
||||
129
gaia/apps/operatorvariant/test/unit/nfc_customizer_test.js
Executable file
129
gaia/apps/operatorvariant/test/unit/nfc_customizer_test.js
Executable file
|
|
@ -0,0 +1,129 @@
|
|||
/* global requireApp, suite, teardown, suiteSetup, suiteTeardown, setup, test,
|
||||
assert, nfcCustomizer */
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/nfc_customizer.js');
|
||||
|
||||
|
||||
suite('NFC customizer >', function() {
|
||||
const TINY_TIMEOUT = 20;
|
||||
const NFC_SETTING = 'nfc.enabled';
|
||||
|
||||
var realSettings;
|
||||
|
||||
var testCases = [
|
||||
{
|
||||
title: 'set true value. It has not changed previously > ',
|
||||
inputValue: {
|
||||
'isEnabled': true,
|
||||
'default': false
|
||||
},
|
||||
currentValue: false,
|
||||
expectedValue: true,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set false value. It has not changed previously > ',
|
||||
inputValue: {
|
||||
'isEnabled': false,
|
||||
'default': false
|
||||
},
|
||||
currentValue: false,
|
||||
expectedValue: false,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set true value. It has changed previously > ',
|
||||
inputValue: {
|
||||
'isEnabled': true,
|
||||
'default': false
|
||||
},
|
||||
currentValue: true,
|
||||
expectedValue: true,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set false value. It has changed previously > ',
|
||||
inputValue: {
|
||||
'isEnabled': false,
|
||||
'default': false
|
||||
},
|
||||
currentValue: true,
|
||||
expectedValue: true,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set true value. Previously value undefined > ',
|
||||
inputValue: {
|
||||
'isEnabled': true,
|
||||
'default': false
|
||||
},
|
||||
currentValue: undefined,
|
||||
expectedValue: true,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set false value. Previous value undefined > ',
|
||||
inputValue: {
|
||||
'isEnabled': false,
|
||||
'default': false
|
||||
},
|
||||
currentValue: undefined,
|
||||
expectedValue: false,
|
||||
simPresentOnFirstBoot: true
|
||||
},
|
||||
{
|
||||
title: 'set true value. Previous RUN with no SIM (or unconfigured one)> ',
|
||||
inputValue: {
|
||||
'isEnabled': true,
|
||||
'default': false
|
||||
},
|
||||
expectedValue: undefined,
|
||||
simPresentOnFirstBoot: false
|
||||
},
|
||||
{
|
||||
title: 'set false value. Previous RUN with no SIM (or unconfigured one)>',
|
||||
inputValue: {
|
||||
'isEnabled': false,
|
||||
'default': false
|
||||
},
|
||||
expectedValue: undefined,
|
||||
simPresentOnFirstBoot: false
|
||||
}
|
||||
];
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
this.sinon.clock.restore();
|
||||
});
|
||||
|
||||
testCases.forEach(function(testCase) {
|
||||
test(testCase.title, function() {
|
||||
if (testCase.currentValue !== undefined) {
|
||||
window.MockNavigatorSettings.mSettings[NFC_SETTING] =
|
||||
testCase.currentValue;
|
||||
}
|
||||
nfcCustomizer.simPresentOnFirstBoot = testCase.simPresentOnFirstBoot;
|
||||
nfcCustomizer.set(testCase.inputValue);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
var mSettings = window.MockNavigatorSettings.mSettings;
|
||||
assert.strictEqual(mSettings[NFC_SETTING], testCase.expectedValue,
|
||||
NFC_SETTING + ' has a incorrect value');
|
||||
});
|
||||
});
|
||||
});
|
||||
123
gaia/apps/operatorvariant/test/unit/operator_variant_test.js
Executable file
123
gaia/apps/operatorvariant/test/unit/operator_variant_test.js
Executable file
|
|
@ -0,0 +1,123 @@
|
|||
/* global require, requireApp, suite, suiteSetup, suiteTeardown, setup,
|
||||
teardown, test, assert, OperatorVariantManager
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_xmlhttprequest.js');
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
requireApp('operatorvariant/shared/test/unit/mocks/' +
|
||||
'mock_navigator_moz_set_message_handler.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
requireApp('operatorvariant/js/resources.js');
|
||||
requireApp('operatorvariant/js/operator_variant.js');
|
||||
|
||||
suite(' OperatorVariantManager > ', function() {
|
||||
const TEST_NETWORK_MCC = '214';
|
||||
const TEST_NETWORK_MNC = '7';
|
||||
const TEST_MCC_MNC = '214-007';
|
||||
var realSettings;
|
||||
var realSetMessageHandler;
|
||||
var realLazyLoader;
|
||||
var realXHR;
|
||||
|
||||
var customizationList = {
|
||||
'214-007': {
|
||||
'support_contacts': '/resources/support_contacts.json',
|
||||
'wallpaper': '/resources/wallpaper.jpg',
|
||||
'default_contacts': '/resources/contacts.json',
|
||||
'ringtone': '/resources/ringtone.ogg'
|
||||
}
|
||||
};
|
||||
const MSG_NAME = 'first-run-with-sim';
|
||||
const FIRST_RUN_SETTING = 'ftu.simPresentOnFirstBoot';
|
||||
var message = {
|
||||
mcc: '214',
|
||||
mnc: '007'
|
||||
};
|
||||
|
||||
suiteSetup(function() {
|
||||
realXHR = window.XMLHttpRequest;
|
||||
window.XMLHttpRequest = window.MockXMLHttpRequest;
|
||||
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
|
||||
realSetMessageHandler = navigator.mozSetMessageHandler;
|
||||
navigator.mozSetMessageHandler = window.MockNavigatormozSetMessageHandler;
|
||||
|
||||
realLazyLoader = window.LazyLoader;
|
||||
window.LazyLoader = window.MockLazyLoader;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
navigator.mozSetMessageHandler = realSetMessageHandler;
|
||||
window.LazyLoader = realLazyLoader;
|
||||
window.XMLHttpRequest = realXHR;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
navigator.mozSetMessageHandler.mSetup();
|
||||
OperatorVariantManager.init();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
navigator.mozSetMessageHandler.mTeardown();
|
||||
window.XMLHttpRequest.mTeardown();
|
||||
});
|
||||
|
||||
test(' normalize ', function() {
|
||||
assert.equal(OperatorVariantManager.normalizeCode('7'), '007');
|
||||
assert.equal(OperatorVariantManager.normalizeCode('07'), '007');
|
||||
assert.equal(OperatorVariantManager.normalizeCode('007'), '007');
|
||||
});
|
||||
|
||||
test(' getMccMnc ', function() {
|
||||
assert.equal(
|
||||
OperatorVariantManager.getMccMnc(TEST_NETWORK_MCC, TEST_NETWORK_MNC),
|
||||
TEST_MCC_MNC
|
||||
);
|
||||
});
|
||||
|
||||
test(' dispatchCustomizationEvents ', function(done) {
|
||||
var eventsDispatched = {};
|
||||
var eventsToDispatch = customizationList[TEST_MCC_MNC];
|
||||
|
||||
// Run the initialization with the setting set to true, the expected value
|
||||
// is true
|
||||
window.MockNavigatorSettings.mSettings[FIRST_RUN_SETTING] = TEST_MCC_MNC;
|
||||
navigator.mozSetMessageHandler.mTrigger(MSG_NAME, message);
|
||||
assert.isTrue(OperatorVariantManager.simPresentOnFirstBoot,
|
||||
'The simPresentOnFirstBoot value should be true');
|
||||
|
||||
window.addEventListener('customization', function customizer(event) {
|
||||
var setting = event.detail.setting;
|
||||
var value = event.detail.value;
|
||||
// Check that the value is the expected
|
||||
assert.equal(value, eventsToDispatch[setting]);
|
||||
|
||||
// Check that we got true as ftu.simPresentOnFirstBoot on the event.
|
||||
assert.isTrue(event.detail.simPresentOnFirstBoot,
|
||||
'event simPresentOnFirstBoot should be true');
|
||||
|
||||
// Check that we have only one event dispatched per setting
|
||||
if (eventsDispatched[setting]) {
|
||||
assert.ok(false, 'The setting ' + setting +
|
||||
' was dispatched several times.');
|
||||
done();
|
||||
return;
|
||||
}
|
||||
eventsDispatched[setting] = true;
|
||||
// Check that the number of events dispatched is the expected
|
||||
if (Object.keys(eventsToDispatch).length ==
|
||||
Object.keys(eventsDispatched).length) {
|
||||
window.removeEventListener('customization', customizer);
|
||||
done();
|
||||
}
|
||||
});
|
||||
OperatorVariantManager.dispatchCustomizationEvents(customizationList);
|
||||
});
|
||||
});
|
||||
44
gaia/apps/operatorvariant/test/unit/power_customizer_test.js
Executable file
44
gaia/apps/operatorvariant/test/unit/power_customizer_test.js
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
/* global sinon, requireApp, suite, suiteSetup, suiteTeardown, setup, teardown,
|
||||
test, assert, powerCustomizer */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/power_customizer.js');
|
||||
|
||||
suite('power on/off customizer >', function() {
|
||||
var createLockSpy;
|
||||
var realSettings;
|
||||
const POWER_KEYS_VALUES = {
|
||||
'poweron': {
|
||||
'video': 'app://operatorresources/resources/power/power_on.mp4',
|
||||
'image': 'app://operatorresources/resources/power/power_on.png'
|
||||
}
|
||||
};
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
createLockSpy = sinon.spy(navigator.mozSettings, 'createLock');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
createLockSpy.restore();
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
createLockSpy.reset();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
});
|
||||
|
||||
test(' set > ', function() {
|
||||
powerCustomizer.set(POWER_KEYS_VALUES);
|
||||
assert.isTrue(createLockSpy.calledOnce);
|
||||
});
|
||||
});
|
||||
BIN
gaia/apps/operatorvariant/test/unit/resources/5secs.ogg
Executable file
BIN
gaia/apps/operatorvariant/test/unit/resources/5secs.ogg
Executable file
Binary file not shown.
23
gaia/apps/operatorvariant/test/unit/resources/customization.json
Executable file
23
gaia/apps/operatorvariant/test/unit/resources/customization.json
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"214-01": {
|
||||
"support_contacts": "/ftu/test/unit/resources/support_contacts.json",
|
||||
"wallpaper": "/resources/wallpaper.jpg",
|
||||
"default_contacts": "/resources/contacts.json",
|
||||
"ringtone": "/resources/ringtone.ogg",
|
||||
"power": "/ftu/test/unit/resources/power.json"
|
||||
},
|
||||
"214-02": {
|
||||
"support_contacts": "/ftu/test/unit/resources/support_contacts.json",
|
||||
"wallpaper": "/resources/wallpaper.jpg",
|
||||
"default_contacts": "/resources/contacts.json",
|
||||
"ringtone": "/resources/ringtone.ogg",
|
||||
"power": "/ftu/test/unit/resources/power.json"
|
||||
},
|
||||
"214-007": {
|
||||
"support_contacts": "/test/unit/resources/support_contacts.json",
|
||||
"wallpaper": "/resources/wallpaper.jpg",
|
||||
"default_contacts": "/resources/contacts.json",
|
||||
"ringtone": "/resources/ringtone.ogg",
|
||||
"power": "/test/unit/resources/power.json"
|
||||
}
|
||||
}
|
||||
BIN
gaia/apps/operatorvariant/test/unit/resources/wallpaper.jpg
Executable file
BIN
gaia/apps/operatorvariant/test/unit/resources/wallpaper.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 157 KiB |
29
gaia/apps/operatorvariant/test/unit/resources_test.js
Executable file
29
gaia/apps/operatorvariant/test/unit/resources_test.js
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
/* global requireApp, suite, test, assert, Resources */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/js/resources.js');
|
||||
|
||||
var resourcePath = '/test/unit/resources/wallpaper.jpg';
|
||||
|
||||
suite(' Resources > ', function() {
|
||||
test(' load properly ', function(done) {
|
||||
var onerror = function errorHandler() {
|
||||
assert.ok(false, 'Resource not loaded properly');
|
||||
done();
|
||||
};
|
||||
Resources.load(resourcePath, 'blob', function() {
|
||||
done();
|
||||
}, onerror);
|
||||
});
|
||||
|
||||
test(' error while loading ', function(done) {
|
||||
var onerror = function errorHandler() {
|
||||
done();
|
||||
};
|
||||
Resources.load('/wrong/path/file.jpg', 'blob', function() {
|
||||
assert.ok(false, 'Resource loaded when it should not.');
|
||||
done();
|
||||
}, onerror);
|
||||
});
|
||||
});
|
||||
72
gaia/apps/operatorvariant/test/unit/ringtone_customizer_test.js
Executable file
72
gaia/apps/operatorvariant/test/unit/ringtone_customizer_test.js
Executable file
|
|
@ -0,0 +1,72 @@
|
|||
/* global requireApp, suite, suiteSetup, suiteTeardown, setup, teardown,
|
||||
test, sinon, Resources, ringtoneCustomizer */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/resources.js');
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/ringtone_customizer.js');
|
||||
|
||||
suite('RingtoneCustomizer >', function() {
|
||||
var ringtoneParams = {
|
||||
uri: '/test/unit/resources/5secs.ogg',
|
||||
name: 'ringtone'
|
||||
};
|
||||
|
||||
var TINY_TIMEOUT = 20;
|
||||
|
||||
var realSettings;
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
this.sinon.clock.restore();
|
||||
});
|
||||
|
||||
test(' First run with valid SIM. Set > ', function() {
|
||||
var resourcesSpy = sinon.spy(Resources, 'load');
|
||||
ringtoneCustomizer.simPresentOnFirstBoot = true;
|
||||
ringtoneCustomizer.set(ringtoneParams);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
sinon.assert.calledOnce(resourcesSpy);
|
||||
sinon.assert.calledWith(resourcesSpy, ringtoneParams.uri, 'blob');
|
||||
resourcesSpy.restore();
|
||||
});
|
||||
|
||||
test(' set the ringtone > ', function() {
|
||||
var createLockSpy = sinon.spy(navigator.mozSettings, 'createLock');
|
||||
this.sinon.stub(Resources, 'load', function(uri, type, onsuccess) {
|
||||
onsuccess('ABC');
|
||||
});
|
||||
ringtoneCustomizer.simPresentOnFirstBoot = true;
|
||||
ringtoneCustomizer.set(ringtoneParams);
|
||||
sinon.assert.calledOnce(createLockSpy);
|
||||
createLockSpy.restore();
|
||||
});
|
||||
|
||||
test(' First run outwith valid SIM. Not set > ', function() {
|
||||
var createLockSpy = sinon.spy(navigator.mozSettings, 'createLock');
|
||||
this.sinon.stub(Resources, 'load', function(uri, type, onsuccess) {
|
||||
onsuccess('ABC');
|
||||
});
|
||||
ringtoneCustomizer.simPresentOnFirstBoot = false;
|
||||
ringtoneCustomizer.set(ringtoneParams);
|
||||
sinon.assert.notCalled(createLockSpy);
|
||||
createLockSpy.restore();
|
||||
});
|
||||
|
||||
});
|
||||
80
gaia/apps/operatorvariant/test/unit/sms_customizer_test.js
Executable file
80
gaia/apps/operatorvariant/test/unit/sms_customizer_test.js
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
/* global requireApp, suite, suiteSetup, suiteTeardown, setup, teardown, test,
|
||||
assert, sinon, smsCustomizer */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/sms_customizer.js');
|
||||
|
||||
suite('SMS customizer >', function() {
|
||||
const SMS_MAX_CONCAT = 'operatorResource.sms.maxConcat';
|
||||
|
||||
var createLockSpy;
|
||||
var realSettings;
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
createLockSpy = sinon.spy(navigator.mozSettings, 'createLock');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
createLockSpy.restore();
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
createLockSpy.reset();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
});
|
||||
|
||||
test(' set valid value (integer) > ', function() {
|
||||
var sttngs = navigator.mozSettings.mSettings;
|
||||
|
||||
smsCustomizer.set({
|
||||
smsMaxConcat: 10
|
||||
});
|
||||
|
||||
assert.isTrue(createLockSpy.calledOnce);
|
||||
|
||||
assert.strictEqual(sttngs[SMS_MAX_CONCAT], 10);
|
||||
});
|
||||
|
||||
test(' set valid value (decimal) > ', function() {
|
||||
var sttngs = navigator.mozSettings.mSettings;
|
||||
|
||||
smsCustomizer.set({
|
||||
smsMaxConcat: 10.5
|
||||
});
|
||||
assert.isTrue(createLockSpy.calledOnce);
|
||||
|
||||
assert.strictEqual(sttngs[SMS_MAX_CONCAT], 10);
|
||||
});
|
||||
|
||||
test(' set invalid value (NaN) > ', function() {
|
||||
var sttngs = navigator.mozSettings.mSettings;
|
||||
|
||||
smsCustomizer.set({
|
||||
smsMaxConcat: 'a'
|
||||
});
|
||||
assert.isTrue(createLockSpy.notCalled);
|
||||
|
||||
assert.isUndefined(sttngs.SMS_MAX_CONCAT);
|
||||
});
|
||||
|
||||
test(' set invalid value (negative value) > ', function() {
|
||||
var sttngs = navigator.mozSettings.mSettings;
|
||||
|
||||
smsCustomizer.set({
|
||||
smsMaxConcat: -1
|
||||
});
|
||||
assert.isTrue(createLockSpy.notCalled);
|
||||
|
||||
assert.isUndefined(sttngs.SMS_MAX_CONCAT);
|
||||
});
|
||||
});
|
||||
52
gaia/apps/operatorvariant/test/unit/support_contacts_customizer_test.js
Executable file
52
gaia/apps/operatorvariant/test/unit/support_contacts_customizer_test.js
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
/* global requireApp, suite, suiteSetup, suiteTeardown, setup, teardown, test,
|
||||
assert, sinon, supportContactsCustomizer */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/support_contacts_customizer.js');
|
||||
|
||||
suite('Support contacts customizer >', function() {
|
||||
var createLockSpy;
|
||||
var realSettings;
|
||||
const SUPPORT_CONTACTS_KEYS_VALUES = {
|
||||
'onlinesupport': {
|
||||
'title': 'Mozilla Support',
|
||||
'href': 'http://test.mozilla.org/support'
|
||||
},
|
||||
'callsupport1': {
|
||||
'title': 'Call Support (Primary)',
|
||||
'href': 'tel:14155550001'
|
||||
},
|
||||
'callsupport2': {
|
||||
'title': 'Call Support (Secondary)',
|
||||
'href': 'tel:14155550002'
|
||||
}
|
||||
};
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
createLockSpy = sinon.spy(navigator.mozSettings, 'createLock');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
createLockSpy.restore();
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
createLockSpy.reset();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozSettings.mTeardown();
|
||||
});
|
||||
|
||||
test(' set > ', function() {
|
||||
supportContactsCustomizer.set(SUPPORT_CONTACTS_KEYS_VALUES);
|
||||
assert.isTrue(createLockSpy.calledOnce);
|
||||
});
|
||||
});
|
||||
52
gaia/apps/operatorvariant/test/unit/topsite_customizer_test.js
Executable file
52
gaia/apps/operatorvariant/test/unit/topsite_customizer_test.js
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
/* global MockNavigatorDatastore */
|
||||
/* global MockDatastore */
|
||||
/* global topSitesCustomizer */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/topsites_customizer.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_datastore.js');
|
||||
|
||||
suite('TopSitesCustomizer >', function() {
|
||||
var realDatastore = null;
|
||||
|
||||
suiteSetup(function() {
|
||||
navigator.getDataStores = MockNavigatorDatastore.getDataStores;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.getDataStores = realDatastore;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
MockDatastore._inError = false;
|
||||
MockDatastore._records = Object.create(null);
|
||||
});
|
||||
|
||||
test('First run with valid SIM. Set places', function(done) {
|
||||
|
||||
var url = 'http://example.org';
|
||||
var title = 'Example';
|
||||
var tile = 'atile';
|
||||
var data = {
|
||||
topSites: [{
|
||||
url: url,
|
||||
title: title,
|
||||
tile: tile,
|
||||
}]
|
||||
};
|
||||
|
||||
MockDatastore.addEventListener('change', function() {
|
||||
assert.deepEqual(MockDatastore._records[url], {
|
||||
url: url,
|
||||
title: title,
|
||||
tile: tile,
|
||||
frecency: -1
|
||||
}, 'Arguments not equal');
|
||||
done();
|
||||
});
|
||||
topSitesCustomizer.simPresentOnFirstBoot = true;
|
||||
topSitesCustomizer.set(data);
|
||||
});
|
||||
});
|
||||
105
gaia/apps/operatorvariant/test/unit/wallpaper_customizer_test.js
Executable file
105
gaia/apps/operatorvariant/test/unit/wallpaper_customizer_test.js
Executable file
|
|
@ -0,0 +1,105 @@
|
|||
/* global requireApp, suite, suiteSetup, suiteTeardown, setup, teardown, test,
|
||||
assert, sinon, MockXMLHttpRequest, wallpaperCustomizer, Resources */
|
||||
|
||||
'use strict';
|
||||
|
||||
requireApp('operatorvariant/test/unit/mock_navigator_moz_settings.js');
|
||||
requireApp('operatorvariant/test/unit/mock_xmlhttprequest.js');
|
||||
requireApp('operatorvariant/test/unit/mock_file_reader.js');
|
||||
|
||||
requireApp('operatorvariant/js/resources.js');
|
||||
requireApp('operatorvariant/js/customizers/customizer.js');
|
||||
requireApp('operatorvariant/js/customizers/wallpaper_customizer.js');
|
||||
|
||||
suite('WallpaperCustomizer >', function() {
|
||||
const WALLPAPER_SETTING = 'wallpaper.image';
|
||||
const TINY_TIMEOUT = 20;
|
||||
|
||||
var realFileReader;
|
||||
var realSettings;
|
||||
var realXHR;
|
||||
var resourcesSpy;
|
||||
|
||||
suiteSetup(function() {
|
||||
realSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = window.MockNavigatorSettings;
|
||||
realXHR = window.XMLHttpRequest;
|
||||
window.XMLHttpRequest = window.MockXMLHttpRequest;
|
||||
realFileReader = window.FileReader;
|
||||
window.FileReader = window.MockFileReader;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozSettings = realSettings;
|
||||
window.XMLHttpRequest = realXHR;
|
||||
window.FileReader = realFileReader;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.sinon.useFakeTimers();
|
||||
resourcesSpy = sinon.spy(Resources, 'load');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
window.XMLHttpRequest.mTeardown();
|
||||
navigator.mozSettings.mTeardown();
|
||||
this.sinon.clock.restore();
|
||||
resourcesSpy.restore();
|
||||
});
|
||||
|
||||
function sendResponseText(text) {
|
||||
MockXMLHttpRequest.mSendOnLoad({
|
||||
responseText: text,
|
||||
response: text
|
||||
});
|
||||
}
|
||||
|
||||
var configuredValue = 'data:application/object;base64,configuredValue';
|
||||
var userValue = 'data:application/object;base64,userValue';
|
||||
var defaultValue = 'data:application/object;base64,defaultValue';
|
||||
|
||||
test('First run with valid SIM. Set ', function() {
|
||||
var settings = navigator.mozSettings.mSettings;
|
||||
|
||||
var inputParam = {
|
||||
uri: '/test/unit/resources/wallpaper.png',
|
||||
default: defaultValue
|
||||
};
|
||||
|
||||
wallpaperCustomizer.simPresentOnFirstBoot = true;
|
||||
wallpaperCustomizer.set(inputParam);
|
||||
|
||||
sendResponseText(configuredValue);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
|
||||
sinon.assert.calledOnce(resourcesSpy);
|
||||
sinon.assert.calledWith(resourcesSpy,
|
||||
inputParam.uri, 'blob');
|
||||
|
||||
//Verify if value has been correctly changed
|
||||
assert.strictEqual(settings[WALLPAPER_SETTING], configuredValue,
|
||||
WALLPAPER_SETTING + ' has a incorrect value');
|
||||
});
|
||||
|
||||
test('Previous run withot SIM. Not set ', function() {
|
||||
var settings = navigator.mozSettings.mSettings;
|
||||
settings[WALLPAPER_SETTING] = userValue;
|
||||
|
||||
var inputParam = {
|
||||
uri: '/test/unit/resources/wallpaper.png',
|
||||
default: defaultValue
|
||||
};
|
||||
|
||||
wallpaperCustomizer.simPresentOnFirstBoot = false;
|
||||
wallpaperCustomizer.set(inputParam);
|
||||
|
||||
sendResponseText(configuredValue);
|
||||
this.sinon.clock.tick(TINY_TIMEOUT);
|
||||
|
||||
sinon.assert.notCalled(resourcesSpy);
|
||||
|
||||
//Verify if value has been correctly changed
|
||||
assert.strictEqual(settings[WALLPAPER_SETTING], userValue,
|
||||
WALLPAPER_SETTING + ' has a incorrect value');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue