Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #21988 from gitmai/bug-1038810-roaming-customizer
Browse files Browse the repository at this point in the history
Bug 1038810 - [User Story] Single variant: Data roaming on/off by defaul...
  • Loading branch information
gitmai authored and rvandermeulen committed Jul 29, 2014
1 parent 49ff85e commit 4c58c3a
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
8 changes: 6 additions & 2 deletions apps/operatorvariant/build/build.js
Expand Up @@ -40,7 +40,7 @@ var Resources = function(gaia, settings, appDomain) {
};

// Parse and get resources for a given JSON configuration of one operator.
// Also create an output JSON configuration for the processed resources.
// Also create an output JSON configuration for the processed resources.
Resources.prototype.getResources = function(conf) {
var operatorJSON = {};

Expand All @@ -66,6 +66,10 @@ Resources.prototype.getResources = function(conf) {
operatorJSON.data_ftu = conf.data_ftu;
}

if ('data_roaming' in conf) {
operatorJSON.data_roaming = conf.data_roaming;
}

conf['mcc-mnc'].forEach(function(mcc) {
if (Object.keys(operatorJSON).length !== 0) {
this.json[mcc] = operatorJSON;
Expand Down Expand Up @@ -137,7 +141,7 @@ Resources.prototype.getWallpaperResource = function(wallpaper) {
}
};

// Create ringtone JSON and add file.
// Create ringtone JSON and add file.
Resources.prototype.getRingtoneResource = function(ringtone) {
if (ringtone) {
var jsonName = 'ringtone-' + getHash(JSON.stringify(ringtone)) + '.json';
Expand Down
2 changes: 1 addition & 1 deletion apps/operatorvariant/js/customizers/customizer.js
Expand Up @@ -14,14 +14,14 @@ var Customizer = (function(setting, resourceType, onerror) {
if (event.detail.setting === setting) {
window.removeEventListener('customization', eventHandler);
var value = event.detail.value;
self.simPresentOnFirstBoot = event.detail.simPresentOnFirstBoot;
// If resourceType === 'data' the value received contains directly the
// value that the customizer will proccess.
// In other case the value will have the resource to be loaded by the
// customizer.
if (resourceType === 'data') {
self.set(value);
} else {
self.simPresentOnFirstBoot = event.detail.simPresentOnFirstBoot;
Resources.load(value, resourceType, self.set.bind(self),
function onerrorRetrieving(status) {
console.error('Customizer.js: Error retrieving the resource.');
Expand Down
31 changes: 31 additions & 0 deletions apps/operatorvariant/js/customizers/data_roaming_customizer.js
@@ -0,0 +1,31 @@
/* global Customizer */

'use strict';

var DataRoamingCustomizer = (function() {
Customizer.call(this, 'data_roaming', 'data');
this.set = function(isEnabled) {
if (typeof isEnabled !== 'boolean') {
console.error('DataRoamingCustomizer. Invalid type for input value.');
return;
}

if (!this.simPresentOnFirstBoot) {
console.log('DataRoamingCustomizer. No first RUN with configured SIM.');
return;
}

var settings = navigator.mozSettings;
if (!settings) {
console.error('DataRoamingCustomizer. Settings is not available');
return;
}

settings.createLock().set({
'ril.data.roaming_enabled': isEnabled
});
};
});

var dataRoamingCustomizer = new DataRoamingCustomizer();
dataRoamingCustomizer.init();
3 changes: 2 additions & 1 deletion apps/operatorvariant/js/operator_variant.js
Expand Up @@ -33,7 +33,8 @@ var OperatorVariantManager = {
'/js/customizers/nfc_customizer.js',
'/js/customizers/search_customizer.js',
'/js/customizers/default_search_customizer.js',
'/js/customizers/topsites_customizer.js'
'/js/customizers/topsites_customizer.js',
'/js/customizers/data_roaming_customizer.js'
],

init: function ovm_init() {
Expand Down
113 changes: 113 additions & 0 deletions apps/operatorvariant/test/unit/data_roaming_customizer_test.js
@@ -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');
});
});
});

0 comments on commit 4c58c3a

Please sign in to comment.