Publish Vulpes Preview 15 sources for desktop, Android and Tundra

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

View file

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

View file

@ -0,0 +1,146 @@
/* global marionette, require, setup, suite, test */
'use strict';
var assert = require('assert');
var Fm = require('./lib/fm.js');
marionette('FM Radio test', function() {
var client = marionette.client({
profile: {},
desiredCapabilities: { raisesAccessibilityExceptions: false }
});
var fm;
setup(function() {
fm = new Fm(client);
fm.launch();
fm.waitForLoaded();
});
suite('FM Radio UI', function() {
test('Test basic UI', function() {
try {
var freq = fm.getCurrentFrequency();
assert.equal(freq, '87.5');
var dialFreq = fm.getDialFreq();
assert.equal(dialFreq, '87.5');
assert.equal(freq, dialFreq);
// test seek up and down
var startFreq = freq;
fm.seekUp();
freq = fm.getCurrentFrequency();
assert.notEqual(freq, startFreq);
dialFreq = fm.getDialFreq();
assert.equal(parseFloat(dialFreq), parseFloat(freq));
fm.seekDown();
freq = fm.getCurrentFrequency();
assert.equal(freq, startFreq);
dialFreq = fm.getDialFreq();
assert.equal(parseFloat(dialFreq), parseFloat(freq));
// see about the frequency being saved.
fm.seekUp();
startFreq = fm.getCurrentFrequency();
fm.close();
fm.launch();
fm.waitForLoaded();
freq = fm.getCurrentFrequency();
assert.equal(parseFloat(freq), parseFloat(startFreq));
} catch(e) {
assert.ok(false, e.stack);
}
});
});
suite('FM Radio favourites', function() {
test('Test favouriting', function() {
try {
fm.seekUp();
var isFav = fm.isFav();
assert.ok(!isFav, 'Frequency shouldn\'t have been favourited');
fm.fav();
isFav = fm.isFav();
assert.ok(isFav, 'Frequency should be favourited');
fm.close();
fm.launch();
fm.waitForLoaded();
isFav = fm.isFav();
assert.ok(isFav, 'Frequency should be favourited after reboot.');
// checking we have a selected favourite.
var elem = fm.selectedFavItem();
assert.ok(elem, 'Can\'t find selected favourite');
var freq = fm.getCurrentFrequency();
// checking the text content of the favourite.
var favFreq = fm.selectedFavItemText();
assert.equal(favFreq, freq,
'Current frequency and selected favourite do not match');
// checking the id of the favourite.
var id = elem.getAttribute('id');
favFreq = id.substring(id.indexOf('-') + 1);
assert.equal(
parseFloat(favFreq), parseFloat(freq),
'Current frequency and selected favourite ID do not match');
fm.seekUp();
var newFreq = fm.getCurrentFrequency();
assert.notEqual(freq, newFreq);
fm.fav();
assert.ok(fm.isFav());
// count number of favs. Should be 2.
var elems = client.findElement(Fm.Selector.favList).
findElements(Fm.Selector.favItem);
assert.equal(elems.length, 2);
favFreq = fm.selectedFavItemText();
assert.equal(favFreq, newFreq);
elem.tap();
assert.ok(fm.isFav());
favFreq = fm.selectedFavItemText();
assert.notEqual(favFreq, newFreq);
// remove the favourite.
fm.fav();
assert.ok(!fm.isFav());
// count number of favs. Should be 1.
elems = client.findElement(Fm.Selector.favList).
findElements(Fm.Selector.favItem);
assert.equal(elems.length, 1);
} catch(e) {
assert.ok(false, e.stack);
}
});
});
});

View file

@ -0,0 +1,141 @@
/* global require, module */
'use strict';
var assert = require('assert');
function Fm(client, origin) {
this.client = client;
this.origin = origin || ('app://' + Fm.DEFAULT_ORIGIN);
this.actions = client.loader.getActions();
}
module.exports = Fm;
Fm.DEFAULT_ORIGIN = 'fm.gaiamobile.org';
Fm.Selector = Object.freeze({
currentFrequency: '#frequency',
dialerContainer: '#dialer-container',
seekDown: '#frequency-op-seekdown',
seekUp: '#frequency-op-seekup',
powerSwitch: '#power-switch',
favButton: '#bookmark-button',
favList: '#fav-list',
favListContainer: '#fav-list-container',
favItemSelected: '.fav-list-item.selected',
favItemSelectedFreq:'.fav-list-item.selected .fav-list-frequency',
favItem: '.fav-list-item',
});
Fm.prototype = {
client: null,
get powerSwitch() {
return this.client.findElement(Fm.Selector.powerSwitch);
},
get favButton() {
return this.client.findElement(Fm.Selector.favButton);
},
get favListContainer() {
return this.client.findElement(Fm.Selector.favListContainer);
},
// debug function.
debugDocument: function() {
var debug = this.client.executeScript(function() {
return document.documentElement.innerHTML;
});
console.log('debug', debug);
},
launch: function() {
this.client.switchToFrame();
this.client.apps.launch(this.origin);
this.client.apps.switchToApp(this.origin);
this.client.helper.waitForElement('body');
},
close: function() {
this.client.apps.close(this.origin);
},
// since we can't get the child text isolated with marionette.
// You might want to call _trimFreqTextContent() on the result.
_getTextNodeContent: function(sel) {
return this.client.executeScript(function(sel) {
return document.querySelector(sel).firstChild.textContent;
}, [sel]);
},
// make sure we have just the frequency
_trimFreqTextContent: function(freq) {
// for some reason these unicode delimiters are inserted
// in the text node
return freq.trim().replace(/[\u2068\u2069]/g, '');
},
getCurrentFrequency: function() {
var elem = this.client.findElement(Fm.Selector.currentFrequency);
assert.ok(elem, 'Couldn\'t find frequency');
var freq = this._getTextNodeContent(Fm.Selector.currentFrequency);
return this._trimFreqTextContent(freq);
},
getDialFreq: function() {
var elem = this.client.findElement(Fm.Selector.dialerContainer);
assert.ok(elem, 'Couldn\'t find dialer container');
var dialFreq = elem.getAttribute('aria-valuenow');
return dialFreq;
},
seekDown: function() {
var elem = this.client.findElement(Fm.Selector.seekDown);
assert.ok(elem, 'Seek Down button not found');
elem.click();
this.client.waitFor(function() {
return !this.powerSwitch.getAttribute('data-seeking');
}.bind(this));
},
seekUp: function() {
var elem = this.client.findElement(Fm.Selector.seekUp);
assert.ok(elem, 'Seek Down button not found');
elem.click();
this.client.waitFor(function() {
return !this.powerSwitch.getAttribute('data-seeking');
}.bind(this));
},
fav: function() {
var elem = this.favButton;
elem.tap();
},
selectedFavItem: function() {
return this.favListContainer.findElement(Fm.Selector.favItemSelected);
},
selectedFavItemText: function() {
var freq = this._getTextNodeContent(Fm.Selector.favItemSelectedFreq);
return this._trimFreqTextContent(freq);
},
isFav: function() {
return this.favButton.getAttribute('data-bookmarked') == 'true';
},
waitForLoaded: function() {
this.client.waitFor(function() {
return this.powerSwitch.getAttribute('data-enabled');
}.bind(this));
}
};

View file

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

386
gaia/apps/fm/test/unit/fm_test.js Executable file
View file

@ -0,0 +1,386 @@
'use strict';
/* global
$,
$$,
airplaneModeEnabled:true,
enabling,
favoritesList,
frequencyDialer,
historyList,
MockL10n,
mozFMRadio,
updateEnablingState,
updateFreqUI,
updateWarningModeUI */
requireApp('shared/js/airplane_mode_helper.js');
requireApp('fm/js/fm.js');
require('/shared/test/unit/load_body_html_helper.js');
require('/shared/test/unit/mocks/mock_l20n.js');
suite('FM', function() {
function setFrequency(frequency) {
var setFreq = frequencyDialer.setFrequency(frequency);
if (frequency < mozFMRadio.frequencyLowerBound) {
assert.equal(setFreq, mozFMRadio.frequencyLowerBound);
} else if (frequency > mozFMRadio.frequencyUpperBound) {
assert.equal(setFreq, mozFMRadio.frequencyUpperBound);
} else {
assert.equal(setFreq, frequency);
}
}
function testScreenReaderSwipe(swipeDirection, startFreq, expectedFreq) {
var modifier, key;
if (swipeDirection === 'up') {
modifier = 0.1;
key = 38; // DOM_VK_UP = 38
} else if (swipeDirection === 'down') {
modifier = -0.1;
key = 40; // DOM_VK_DOWN = 40
}
var keyEvent = document.createEvent('KeyboardEvent');
keyEvent.initKeyEvent('keypress',
true, true, window,
false, false, false, false,
key, 0);
frequencyDialer.setFrequency(startFreq);
$('dialer-container').dispatchEvent(keyEvent);
assert.equal(frequencyDialer._currentFreqency, expectedFreq);
}
function testPowerSwitchLabel() {
assert.equal(mozFMRadio.enabled ? 'power-switch-off' : 'power-switch-on',
$('power-switch').getAttribute('data-l10n-id'));
}
suite('frequency dialer', function() {
var nativeL10n = document.l10n;
suiteSetup(function() {
sinon.stub(favoritesList, '_save').returns(true);
favoritesList._favList = {};
sinon.stub(historyList, '_save').returns(true);
loadBodyHTML('/index.html');
document.l10n = MockL10n;
frequencyDialer.init();
});
suiteTeardown(function() {
document.l10n = nativeL10n;
document.body.innerHTML = '';
});
test('resolved frequency within bounds', function() {
setFrequency(92);
});
test('resolved frequency exceeding upperbound', function() {
setFrequency(mozFMRadio.frequencyUpperBound + 10);
});
test('resolved frequency exceeding lowerbound', function() {
setFrequency(mozFMRadio.frequencyLowerBound - 10);
});
test('retrieved frequency', function() {
assert.equal(frequencyDialer.getFrequency(), 87.5);
});
test('updated #frequency dom display digits', function() {
assert.deepEqual(
document.l10n.getAttributes($('frequency')),
{ id: 'frequency-MHz', args: { value: '87.5' } });
});
test('compare new set frequency with aria-valuenow', function() {
var frequency = 95.7;
frequencyDialer.setFrequency(frequency);
assert.equal($('dialer-container').getAttribute('aria-valuenow'),
frequency.toString());
});
test('screen reader swipe up on dialer', function() {
testScreenReaderSwipe('up', 95.7, 95.8);
testScreenReaderSwipe('down', 95.7, 95.6);
});
test('maintain aria-pressed on bookmark button', function() {
var bookmarkButton = $('bookmark-button');
// Start at arbitrary station
mozFMRadio.setFrequency(88.6);
updateFreqUI();
assert.equal('false', bookmarkButton.getAttribute('aria-pressed'));
// Add station to favorites
favoritesList.add(88.6);
updateFreqUI();
assert.equal('true', bookmarkButton.getAttribute('aria-pressed'));
// Browse to different station
mozFMRadio.setFrequency(99.5);
updateFreqUI();
assert.equal('false', bookmarkButton.getAttribute('aria-pressed'));
// Come back to first station
mozFMRadio.setFrequency(88.6);
updateFreqUI();
assert.equal('true', bookmarkButton.getAttribute('aria-pressed'));
// Remove station from favorites
favoritesList.remove(88.6);
updateFreqUI();
assert.equal('false', bookmarkButton.getAttribute('aria-pressed'));
});
// temporarily removing due to test not passing on TBPL Bug 876265
// test('changed horizontal position of dialer', function() {
// var prevX = frequencyDialer._translateX;
// frequencyDialer.setFrequency(100);
// assert.notEqual(frequencyDialer._translateX, prevX);
// });
test('#frequency display precision to one decimal point', function() {
var freq = document.l10n.getAttributes($('frequency')).args.value;
assert.ok(freq.indexOf('.') > -1);
});
});
suite('history list', function() {
setup(function() {
historyList._save = function() {
return true;
};
});
test('item added to history list', function() {
historyList.add(100);
assert.equal(historyList._historyList.length, 1);
});
test('gets the last frequency tuned', function() {
assert.equal(historyList.last().frequency, 100);
});
});
suite('favorite list', function() {
var nativeL10n = document.l10n;
suiteSetup(function() {
loadBodyHTML('/index.html');
document.l10n = MockL10n;
});
suiteTeardown(function() {
document.l10n = nativeL10n;
document.body.innerHTML = '';
});
test('item added to favorite list', function() {
favoritesList.add(100);
assert.equal(Object.keys(favoritesList._favList).length, 1);
});
test('added item is updated in DOM #fav-list', function() {
assert.equal($('fav-list-container').childNodes.length, 1);
});
test('contains a frequency', function() {
assert.ok(favoritesList.contains(100));
});
test('selected frequency in DOM #fav-list', function() {
favoritesList.select(100);
assert.ok($$('#fav-list-container div.fav-list-item')[0]
.classList.contains('selected'));
});
test('removed frequency from list', function() {
assert.ok(favoritesList.remove(100));
});
test('removed item is updated in DOM #fav-list', function() {
assert.equal($('fav-list-container').childNodes.length, 0);
});
test('items are in desceding order', function() {
favoritesList.add(100);
favoritesList.add(101);
favoritesList.add(102);
var items = $$('#fav-list-container div.fav-list-item');
var isAscending = true;
for (var i = 0, len = items.length; i < len - 1; i++) {
var itemA = items[i].childNodes[0].textContent;
var itemB = items[i + 1].childNodes[0].textContent;
if (itemA > itemB) {
isAscending = false;
break;
}
}
assert.ok(isAscending);
});
test('set aria-selected = true on active favorite stations, else false',
function() {
var testFreqs = [88.6, 103.7, 104.8, 55.6];
var favorites = $$('#fav-list-container div.fav-list-item');
favoritesList.add(88.6);
favoritesList.add(103.7);
favoritesList.add(104.8);
testFreqs.forEach(function(testFreq, index, array) {
favoritesList.select(testFreq);
for (var i = 0; i < favorites.length; i++) {
assert.equal(favoritesList._getElemFreq(favorites[i]) === testFreq ?
'true' : 'false', favorites[i].getAttribute('aria-selected'));
}
});
});
});
suite('update display states', function() {
var nativeL10n = document.l10n;
suiteSetup(function() {
mozFMRadio.enabled = true;
mozFMRadio.antennaAvailable = true;
loadBodyHTML('/index.html');
document.l10n = MockL10n;
updateEnablingState(true);
});
suiteTeardown(function() {
document.l10n = nativeL10n;
document.body.innerHTML = '';
});
suite('enabling UI', function() {
test('#power-switch enabled attribute is correctly set', function() {
assert.equal(!!$('power-switch').dataset.enabled, mozFMRadio.enabled);
});
test('#power-switchh enabling attribute is correctly set', function() {
assert.equal(!!$('power-switch').dataset.enabling, enabling);
});
test('#frequency-bar display is dimmed', function() {
assert.ok($('frequency-bar').classList.contains('dim'));
});
test('#antenna-warning is hidden', function() {
assert.ok(!!$('antenna-warning').hidden, mozFMRadio.antennaAvailable);
});
test('#power-switch has appropriate aria-label based on enabled status',
function() {
testPowerSwitchLabel();
$('power-switch').click();
testPowerSwitchLabel();
}
);
});
});
suite('update UI based on the airplane mode status', function() {
var nativeL10n = document.l10n;
suiteSetup(function() {
loadBodyHTML('/index.html');
document.l10n = MockL10n;
});
suiteTeardown(function() {
document.l10n = nativeL10n;
document.body.innerHTML = '';
});
suite('airplane mode on', function() {
setup(function() {
airplaneModeEnabled = true;
updateWarningModeUI();
});
test('#airplane-mode-warning is shown', function() {
assert.equal(!!$('airplane-mode-warning').hidden, false);
});
test('#container is hidden', function() {
assert.equal($('container').classList.contains('hidden-block'), true);
});
test('#antenna-warning is hidden', function() {
assert.equal(!!$('antenna-warning').hidden, true);
});
});
suite('airplane mode off', function() {
setup(function() {
airplaneModeEnabled = false;
updateWarningModeUI();
});
test('#airplane-mode-warning is hidden', function() {
assert.equal(!!$('airplane-mode-warning').hidden, true);
});
test('#antenna-warning is on and container is hidden', function() {
mozFMRadio.antennaAvailable = false;
updateWarningModeUI();
assert.equal(!!$('antenna-warning').hidden, false);
assert.equal($('container').classList.contains('hidden-block'), true);
});
test('#antenna-warning is off and container is visible', function() {
mozFMRadio.antennaAvailable = true;
updateWarningModeUI();
assert.equal(!!$('antenna-warning').hidden, true);
assert.equal($('container').classList.contains('hidden-block'), false);
});
});
});
suite('update UI based on the antenna status', function() {
var nativeL10n = document.l10n;
suiteSetup(function() {
loadBodyHTML('/index.html');
document.l10n = MockL10n;
});
suiteTeardown(function() {
document.l10n = nativeL10n;
document.body.innerHTML = '';
});
suite('antenna is plugged in', function() {
setup(function() {
mozFMRadio.antennaAvailable = true;
updateWarningModeUI();
});
test('#antenna-warning is hidden', function() {
assert.equal(!!$('antenna-warning').hidden, true);
});
});
suite('antenna is not plugged in', function() {
setup(function() {
mozFMRadio.antennaAvailable = false;
updateWarningModeUI();
});
test('#antenna-warning is shown', function() {
assert.equal(!!$('antenna-warning').hidden, false);
});
});
});
});