This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21988 from gitmai/bug-1038810-roaming-customizer
Bug 1038810 - [User Story] Single variant: Data roaming on/off by defaul...
- Loading branch information
1 parent
49ff85e
commit 4c58c3a
Showing
5 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
apps/operatorvariant/js/customizers/data_roaming_customizer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
apps/operatorvariant/test/unit/data_roaming_customizer_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
}); |