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
27
gaia/apps/findmydevice/test/build/integration/findmydevice_test.js
Executable file
27
gaia/apps/findmydevice/test/build/integration/findmydevice_test.js
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
/* jshint node: true, mocha: true */
|
||||
/* global suiteSetup */
|
||||
|
||||
var helper = require('helper');
|
||||
|
||||
suite('Findmydevice tests', function() {
|
||||
suiteSetup(helper.cleanupWorkspace);
|
||||
teardown(helper.cleanupWorkspace);
|
||||
|
||||
test('APP=findmydevice make', function(done) {
|
||||
helper.exec('APP=findmydevice make', function(error, stdout, stderr) {
|
||||
helper.checkError(error, stdout, stderr);
|
||||
|
||||
var zipPath = process.cwd() +
|
||||
'/profile/webapps/findmydevice.gaiamobile.org/application.zip';
|
||||
var checkList = ['manifest.webapp'];
|
||||
|
||||
checkList.forEach(function(filePath) {
|
||||
helper.checkFilePathInZip(zipPath, filePath);
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
17
gaia/apps/findmydevice/test/marionette/.jshintrc
Executable file
17
gaia/apps/findmydevice/test/marionette/.jshintrc
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"extends": "../../../../.jshintrc",
|
||||
"predef": [
|
||||
"suite",
|
||||
"test",
|
||||
"setup",
|
||||
"teardown",
|
||||
"suiteSetup",
|
||||
"suiteTeardown",
|
||||
"marionette",
|
||||
"marionetteScriptFinished",
|
||||
"require",
|
||||
"define",
|
||||
"requireApp",
|
||||
"sinon"
|
||||
]
|
||||
}
|
||||
106
gaia/apps/findmydevice/test/marionette/findmydevice_test.js
Executable file
106
gaia/apps/findmydevice/test/marionette/findmydevice_test.js
Executable file
|
|
@ -0,0 +1,106 @@
|
|||
'use strict';
|
||||
/* global __dirname */
|
||||
|
||||
marionette('Find My Device lock >', function() {
|
||||
var assert = require('assert');
|
||||
|
||||
var FINDMYDEVICE_TEST_APP = 'app://test-findmydevice.gaiamobile.org';
|
||||
var SETTINGS_DIGEST_VALUE = 'lockscreen.passcode-lock.digest.value';
|
||||
|
||||
var client = marionette.client({
|
||||
profile: {
|
||||
apps: {
|
||||
'test-findmydevice.gaiamobile.org':
|
||||
__dirname + '/fixtures/test-findmydevice',
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
// launch the test app
|
||||
client.apps.launch(FINDMYDEVICE_TEST_APP);
|
||||
client.apps.switchToApp(FINDMYDEVICE_TEST_APP);
|
||||
client.helper.waitForElement('body');
|
||||
});
|
||||
|
||||
test('Lock the screen through the test app', function() {
|
||||
var messageText = 'This phone is lost.';
|
||||
var messageInput = client.findElement('input[name="message"]');
|
||||
messageInput.sendKeys(messageText);
|
||||
|
||||
client.switchToFrame();
|
||||
var oldDigest = client.settings.get(SETTINGS_DIGEST_VALUE);
|
||||
client.apps.switchToApp(FINDMYDEVICE_TEST_APP);
|
||||
var passcode = '4567';
|
||||
var passcodeInput = client.findElement('input[name="code"]');
|
||||
passcodeInput.sendKeys(passcode);
|
||||
|
||||
var lockButton = client.findElement('#lock');
|
||||
lockButton.click();
|
||||
|
||||
// XXX: After we make LockScreen as an iframe or app, this should be the
|
||||
// line to switch to LockScreen frame.
|
||||
client.switchToFrame();
|
||||
var lockscreen = client.findElement('#lockscreen');
|
||||
client.waitFor(function() {
|
||||
return lockscreen.displayed();
|
||||
});
|
||||
|
||||
var lockscreenMessage = client.findElement('#lockscreen-message');
|
||||
client.waitFor(function() {
|
||||
var text = lockscreenMessage.text();
|
||||
if (text !== '') {
|
||||
assert.equal(lockscreenMessage.text(), messageText);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// sanity-check the settings we should have set
|
||||
var settings = {
|
||||
'lockscreen.enabled': true,
|
||||
'lockscreen.passcode-lock.enabled': true,
|
||||
'lockscreen.notifications-preview.enabled': false,
|
||||
'lockscreen.lock-message': messageText,
|
||||
};
|
||||
for (var s in settings) {
|
||||
assert.equal(client.settings.get(s), settings[s]);
|
||||
}
|
||||
// checking if passcode was changed:
|
||||
var newDigest = client.settings.get(SETTINGS_DIGEST_VALUE);
|
||||
assert.notEqual(newDigest, oldDigest);
|
||||
|
||||
client.switchToFrame();
|
||||
|
||||
// now unlock the screen and re-lock it, the message should disappear
|
||||
client.executeScript(function() {
|
||||
window.wrappedJSObject.Service.request('unlock');
|
||||
});
|
||||
|
||||
client.waitFor(function() {
|
||||
return client.executeScript(function() {
|
||||
return !window.wrappedJSObject.Service.locked;
|
||||
});
|
||||
});
|
||||
|
||||
client.executeScript(function() {
|
||||
window.wrappedJSObject.Service.request('lock');
|
||||
});
|
||||
|
||||
// XXX: After we make LockScreen as an iframe or app, this should be the
|
||||
// line to switch to LockScreen frame.
|
||||
client.switchToFrame();
|
||||
lockscreen = client.findElement('#lockscreen');
|
||||
client.waitFor(function() {
|
||||
return lockscreen.displayed();
|
||||
});
|
||||
|
||||
lockscreenMessage = client.findElement('#lockscreen-message');
|
||||
client.waitFor(function() {
|
||||
return !lockscreenMessage.displayed();
|
||||
});
|
||||
|
||||
assert.equal(client.settings.get('lockscreen.lock-message'), '');
|
||||
});
|
||||
});
|
||||
38
gaia/apps/findmydevice/test/marionette/fixtures/test-findmydevice/index.html
Executable file
38
gaia/apps/findmydevice/test/marionette/fixtures/test-findmydevice/index.html
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<title>Find My Device Test App</title>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="js/findmydevice.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="buttons">
|
||||
<button id="track">Track</button>
|
||||
<button id="erase">Erase</button>
|
||||
<button id="lock">Lock</button>
|
||||
<button id="ring">Ring</button>
|
||||
</div>
|
||||
|
||||
<div id="options">
|
||||
<label>Duration <input name="duration" type="number" placeholder="60"/></label>
|
||||
<label>Message <input name="message" type="text" placeholder="Help! I'm lost!"/></label>
|
||||
<label>Passcode <input name="code" type="text" placeholder="0000"/></label>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
window.onload = function() {
|
||||
var systemPort = null;
|
||||
navigator.mozApps.getSelf().onsuccess = function() {
|
||||
var app = this.result;
|
||||
app.connect('findmydevice-test').then(function(ports) {
|
||||
if (ports.length !== 1) {
|
||||
console.error('got more than one connection?');
|
||||
return;
|
||||
}
|
||||
|
||||
systemPort = ports[0];
|
||||
}, function(err) {
|
||||
console.error('failed to connect: ' + err);
|
||||
});
|
||||
};
|
||||
|
||||
var buttons = document.getElementById('buttons');
|
||||
buttons.addEventListener('click', function(event) {
|
||||
var cmdobj = {};
|
||||
var command = event.target.id[0];
|
||||
cmdobj[command] = {};
|
||||
|
||||
var options = document.getElementsByTagName('input');
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
cmdobj[command][options[i].name[0]] = options[i].value;
|
||||
}
|
||||
|
||||
systemPort.postMessage(cmdobj);
|
||||
});
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "Test Find My Device",
|
||||
"description": "Manually issue commands for Find My Device",
|
||||
"type": "certified",
|
||||
"launch_path": "/index.html",
|
||||
"developer": {
|
||||
"name": "The Gaia Team",
|
||||
"url": "https://github.com/mozilla-b2g/gaia"
|
||||
},
|
||||
"default_locale": "en-US",
|
||||
"icons": {
|
||||
"128": "/style/icons/Blank.png"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
17
gaia/apps/findmydevice/test/unit/.jshintrc
Executable file
17
gaia/apps/findmydevice/test/unit/.jshintrc
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"extends": "../../../../.jshintrc",
|
||||
"predef": [
|
||||
"assert",
|
||||
"suite",
|
||||
"test",
|
||||
"setup",
|
||||
"teardown",
|
||||
"suiteSetup",
|
||||
"suiteTeardown",
|
||||
"require",
|
||||
"requireApp",
|
||||
"sinon",
|
||||
"mocha",
|
||||
"loadBodyHTML"
|
||||
]
|
||||
}
|
||||
506
gaia/apps/findmydevice/test/unit/findmydevice_commands_test.js
Executable file
506
gaia/apps/findmydevice/test/unit/findmydevice_commands_test.js
Executable file
|
|
@ -0,0 +1,506 @@
|
|||
/* global MocksHelper */
|
||||
/* global MockSettingsListener */
|
||||
/* global MockGeolocation */
|
||||
/* global Commands */
|
||||
/* global FindMyDevice */
|
||||
/* global MockNavigatorSettings */
|
||||
/* global PasscodeHelper */
|
||||
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_settings_url.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
|
||||
require('/shared/test/unit/mocks/mock_settings_listener.js');
|
||||
require('/shared/test/unit/mocks/mock_settings_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_audio.js');
|
||||
require('/shared/test/unit/mocks/mock_device_storage.js');
|
||||
require('/shared/test/unit/mocks/mock_geolocation.js');
|
||||
require('/shared/js/passcode_helper.js');
|
||||
|
||||
var mocksForFindMyDevice = new MocksHelper([
|
||||
'SettingsListener', 'SettingsURL', 'SettingsHelper', 'Audio',
|
||||
'DeviceStorage', 'Geolocation'
|
||||
]).init();
|
||||
|
||||
suite('FindMyDevice >', function() {
|
||||
var realMozPower;
|
||||
var realKillSwitch;
|
||||
var realMozApps;
|
||||
var fakeClock;
|
||||
var realMozSettings;
|
||||
|
||||
mocksForFindMyDevice.attachTestHelpers();
|
||||
|
||||
var subject;
|
||||
setup(function(done) {
|
||||
realMozPower = navigator.mozPower;
|
||||
navigator.mozPower = {
|
||||
factoryReset: function(reason) {},
|
||||
};
|
||||
|
||||
this.sinon.spy(navigator.mozPower, 'factoryReset');
|
||||
|
||||
realKillSwitch = navigator.mozKillSwitch;
|
||||
navigator.mozKillSwitch = {
|
||||
enable: function() {}
|
||||
};
|
||||
|
||||
realMozApps = navigator.mozApps;
|
||||
navigator.mozApps = {
|
||||
getSelf: function() {
|
||||
var app = {
|
||||
manifestURL: 'app://findmydevice.gaiamobile.org/manifest.webapp',
|
||||
origin: 'app://findmydevice.gaiamobile.org/'
|
||||
};
|
||||
|
||||
var request = {result: app};
|
||||
setTimeout(function() {
|
||||
request.onsuccess.call(request);
|
||||
});
|
||||
|
||||
return request;
|
||||
}
|
||||
};
|
||||
|
||||
// replace shared/js/dump.js
|
||||
window.DUMP = function() {};
|
||||
|
||||
fakeClock = this.sinon.useFakeTimers();
|
||||
|
||||
realMozSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
|
||||
window.FindMyDevice = {
|
||||
beginHighPriority: this.sinon.stub(),
|
||||
endHighPriority: this.sinon.stub()
|
||||
};
|
||||
|
||||
require('/js/commands.js', function() {
|
||||
subject = Commands;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('Ring command', function() {
|
||||
var duration = 2;
|
||||
|
||||
setup(function() {
|
||||
this.sinon.spy(window, 'setTimeout');
|
||||
this.sinon.spy(window, 'clearTimeout');
|
||||
});
|
||||
|
||||
test('Basic invocation', function() {
|
||||
var ringtone = 'user selected ringtone';
|
||||
|
||||
MockSettingsListener.mCallbacks['dialer.ringtone'](ringtone);
|
||||
|
||||
Commands.invokeCommand('ring', [duration, function(retval) {
|
||||
var lock = MockSettingsListener.getSettingsLock().locks.pop();
|
||||
|
||||
var channel = Commands._ringer.mozAudioChannelType;
|
||||
assert.equal(channel, 'ringer', 'use notification channel');
|
||||
assert.equal(lock['audio.volume.notification'], 15,
|
||||
'volume set to maximum');
|
||||
assert.equal(Commands._ringer.paused, false, 'must be playing');
|
||||
assert.equal(Commands._ringer.src, ringtone, 'must use ringtone');
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
}]);
|
||||
|
||||
fakeClock.tick(duration * 1000);
|
||||
assert.equal(Commands._ringer.paused, true, 'must have stopped');
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'command');
|
||||
});
|
||||
|
||||
test('Stop ringing if duration is zero', function() {
|
||||
Commands.invokeCommand('ring', [duration, function(retval) {
|
||||
assert.equal(Commands._ringer.paused, false, 'must be playing');
|
||||
sinon.assert.called(window.setTimeout);
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.notCalled(FindMyDevice.endHighPriority);
|
||||
}]);
|
||||
|
||||
fakeClock.tick(duration/2 * 1000);
|
||||
|
||||
var timeoutId = Commands._ringTimeoutId;
|
||||
assert.isFalse(Commands._ringer.paused, 'must not be done ringing');
|
||||
Commands.invokeCommand('ring', [0, function(retval) {}]);
|
||||
|
||||
assert.equal(Commands._ringer.paused, true, 'must have stopped');
|
||||
assert.isNull(Commands._ringTimeoutId, 'timeout must have been canceled');
|
||||
sinon.assert.calledWith(window.clearTimeout, timeoutId);
|
||||
sinon.assert.calledTwice(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
sinon.assert.calledTwice(FindMyDevice.endHighPriority);
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.endHighPriority, 'command');
|
||||
});
|
||||
|
||||
test('Should do nothing if already ringing', function() {
|
||||
Commands.invokeCommand('ring', [duration, function(retval) {
|
||||
assert.isFalse(Commands._ringer.paused, 'must be playing');
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.notCalled(FindMyDevice.endHighPriority);
|
||||
}]);
|
||||
|
||||
fakeClock.tick(duration/2 * 1000);
|
||||
|
||||
assert.isFalse(Commands._ringer.paused, 'must not be done ringing');
|
||||
Commands.invokeCommand('ring', [duration, function(retval) {}]);
|
||||
|
||||
fakeClock.tick(duration/2 * 1000);
|
||||
|
||||
assert.isTrue(Commands._ringer.paused, 'must have stopped');
|
||||
assert.isNull(Commands._ringTimeoutId, 'no timeouts should be set');
|
||||
sinon.assert.calledTwice(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
sinon.assert.calledTwice(FindMyDevice.endHighPriority);
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.endHighPriority, 'command');
|
||||
});
|
||||
|
||||
test('Should do nothing if not ringing and duration is zero', function() {
|
||||
Commands.invokeCommand('ring', [0, function(retval) {}]);
|
||||
assert.isTrue(Commands._ringer.paused, 'must not have started');
|
||||
assert.isNull(Commands._ringTimeoutId);
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.endHighPriority, 'command');
|
||||
});
|
||||
});
|
||||
|
||||
test('Erase: ensure factoryReset is called with "wipe"', function(done) {
|
||||
subject.invokeCommand('erase', [function(retval, error) {
|
||||
assert.equal(navigator.mozPower.factoryReset.calledWith('wipe'), true);
|
||||
done();
|
||||
}]);
|
||||
});
|
||||
|
||||
suite('Track command', function() {
|
||||
test('Track receives positions correctly', function() {
|
||||
// track for a period of time
|
||||
var duration = (subject.TRACK_UPDATE_INTERVAL_MS) / 1000;
|
||||
subject.invokeCommand('track', [duration, function(retval, position) {
|
||||
assert.equal(retval, true);
|
||||
// ensure, while tracking, the locations match what the mock makes
|
||||
assert.deepEqual(position, MockGeolocation.fakePosition ,
|
||||
'check the position is what the mock provided');
|
||||
}]);
|
||||
fakeClock.tick(2* subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
});
|
||||
|
||||
test('Track command', function() {
|
||||
// track for 3 intervals
|
||||
var duration = (3 * subject.TRACK_UPDATE_INTERVAL_MS) / 1000;
|
||||
subject.invokeCommand('track', [duration, function(retval, position) {}]);
|
||||
|
||||
// after 2 intervals...
|
||||
fakeClock.tick(2 * subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
// we're mid-track, check we have a watch and timeout IDs
|
||||
assert.notEqual(subject._watchPositionId, null);
|
||||
assert.notEqual(subject._trackTimeoutId, null);
|
||||
|
||||
// after another interval...
|
||||
fakeClock.tick(1 * subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
// .. tracking should have stopped.
|
||||
// ensure we no longer have track and watch IDs.
|
||||
assert.equal(subject._trackTimeoutId, null);
|
||||
assert.equal(subject._watchPositionId, null);
|
||||
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
sinon.assert.alwaysCalledWith(FindMyDevice.endHighPriority, 'command');
|
||||
|
||||
// check wakelock count
|
||||
var begin = FindMyDevice.beginHighPriority.callCount;
|
||||
var end = FindMyDevice.beginHighPriority.callCount;
|
||||
assert.equal(begin, end, 'begin and end count should match');
|
||||
});
|
||||
|
||||
// We assume for this test that the interval used by the geolocation mock
|
||||
// is significantly smaller than TRACK_UPDATE_INTERVAL.
|
||||
test('Track command should throttle observed positions', function() {
|
||||
// track for a long duration (e.g. 10 intervals)
|
||||
var duration = 10 * subject.TRACK_UPDATE_INTERVAL_MS / 1000;
|
||||
var positions = 0;
|
||||
subject.invokeCommand('track', [duration, function(retval, position) {
|
||||
positions++;
|
||||
}]);
|
||||
|
||||
// set the clock to just before the interval, ensure no locations are seen
|
||||
var amountBefore = 2;
|
||||
fakeClock.tick(subject.TRACK_UPDATE_INTERVAL_MS - amountBefore);
|
||||
assert.equal(positions, 0, 'no update intervals should have passed');
|
||||
// set the clock to almost two intervals, ensure only one location is seen
|
||||
fakeClock.tick(subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
assert.equal(positions, 1, '1 update interval should have passed');
|
||||
});
|
||||
|
||||
test('Track command should update its duration if invoked while running',
|
||||
function() {
|
||||
// track for a long duration (e.g. 10 intervals)
|
||||
var duration = 10 * subject.TRACK_UPDATE_INTERVAL_MS / 1000;
|
||||
var positions = 0;
|
||||
subject.invokeCommand('track', [duration, function(retval, position) {
|
||||
positions++;
|
||||
}]);
|
||||
|
||||
// ensure the position count updates as expected (one position per
|
||||
// interval)
|
||||
fakeClock.tick(subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
assert.equal(positions, 1, '1 update interval should have passed');
|
||||
|
||||
// reset the duration to a shorter value:
|
||||
duration = 2 * subject.TRACK_UPDATE_INTERVAL_MS / 1000;
|
||||
subject.invokeCommand('track', [duration, function(retval, position) {
|
||||
positions++;
|
||||
}]);
|
||||
|
||||
// allow the timer to progress to after the duration completes
|
||||
fakeClock.tick(5 * subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
|
||||
// ensure tracking stopped at the end of the new duration:
|
||||
// position count should be at 3
|
||||
assert.equal(positions, 3, '2 more (3) intervals should have passed');
|
||||
|
||||
// and the track and watch IDs should be null
|
||||
assert.equal(subject._trackTimeoutId, null);
|
||||
assert.equal(subject._watchPositionId, null);
|
||||
|
||||
// check wakelock count
|
||||
var begin = FindMyDevice.beginHighPriority.callCount;
|
||||
var end = FindMyDevice.beginHighPriority.callCount;
|
||||
assert.equal(begin, end, 'begin and end count should match');
|
||||
});
|
||||
|
||||
test('Track command should stop if duration is zero',
|
||||
function() {
|
||||
// track for a long duration (e.g. 10 intervals)
|
||||
var duration = 10 * subject.TRACK_UPDATE_INTERVAL_MS / 1000;
|
||||
var positions = 0;
|
||||
subject.invokeCommand('track', [duration, function(retval, position) {
|
||||
positions++;
|
||||
}]);
|
||||
|
||||
fakeClock.tick(subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
|
||||
// after a single interval, stop the tracking
|
||||
subject.invokeCommand('track', [0, function(retval) {
|
||||
assert.equal(retval, true);
|
||||
}]);
|
||||
|
||||
// allow more intervals to pass
|
||||
fakeClock.tick(2 * subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
|
||||
// and ensure the position count remains at 1
|
||||
assert.equal(positions, 1);
|
||||
|
||||
// check the track and watch IDs should be null
|
||||
assert.equal(subject._trackTimeoutId, null);
|
||||
assert.equal(subject._watchPositionId, null);
|
||||
});
|
||||
|
||||
test('track should not leak wakelocks with nonzero duration', function() {
|
||||
// start tracking
|
||||
var duration = 9 * subject.TRACK_UPDATE_INTERVAL_MS / 1000;
|
||||
subject.invokeCommand('track', [duration, function() {}]);
|
||||
|
||||
// once tracking is complete, check the wakelock call counts match
|
||||
fakeClock.tick(10 * subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
var begin = FindMyDevice.beginHighPriority.callCount;
|
||||
var end = FindMyDevice.beginHighPriority.callCount;
|
||||
assert.equal(begin, end, 'begin and end count should match');
|
||||
});
|
||||
|
||||
test('track should not leak wakelocks with zero duration', function() {
|
||||
subject.invokeCommand('track', [0, function() {}]);
|
||||
var begin = FindMyDevice.beginHighPriority.callCount;
|
||||
var end = FindMyDevice.beginHighPriority.callCount;
|
||||
assert.equal(begin, end, 'begin and end count should match');
|
||||
});
|
||||
|
||||
test('track should not leak wakelocks if stopped mid-track', function() {
|
||||
// track for a long duration (e.g. 10 intervals)
|
||||
var duration = 10 * subject.TRACK_UPDATE_INTERVAL_MS / 1000;
|
||||
subject.invokeCommand('track', [duration, function() {}]);
|
||||
|
||||
// after a single interval, stop the tracking
|
||||
fakeClock.tick(subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
subject.invokeCommand('track', [0, function(retval) {}]);
|
||||
|
||||
// go past the original duration
|
||||
fakeClock.tick(10 * subject.TRACK_UPDATE_INTERVAL_MS);
|
||||
|
||||
// check the wakelock call counts
|
||||
var begin = FindMyDevice.beginHighPriority.callCount;
|
||||
var end = FindMyDevice.beginHighPriority.callCount;
|
||||
assert.equal(begin, end, 'begin and end count should match');
|
||||
});
|
||||
});
|
||||
|
||||
test('Bug 1027325 - correctly check that passcode lock is set', function() {
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.enabled', true);
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.passcode-lock.enabled',
|
||||
'1234');
|
||||
assert.equal(true, subject.deviceHasPasscode());
|
||||
});
|
||||
|
||||
test('Bug 1027325 - correctly check that passcode lock is unset', function() {
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.enabled', false);
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.passcode-lock.enabled',
|
||||
false);
|
||||
assert.equal(false, subject.deviceHasPasscode());
|
||||
});
|
||||
|
||||
test('Bug 1027325 - correctly check that lockscreen is set, but passcode ' +
|
||||
'lock is unset', function() {
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.enabled', true);
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.passcode-lock.enabled',
|
||||
false);
|
||||
assert.equal(false, subject.deviceHasPasscode());
|
||||
});
|
||||
|
||||
suite('KillSwitch command', function() {
|
||||
suite('With API existing', function() {
|
||||
setup(function() {
|
||||
this.sinon.spy(navigator.mozKillSwitch, 'enable');
|
||||
});
|
||||
|
||||
test('Basic invocation', function(done) {
|
||||
subject.invokeCommand('killswitch', [ function(retval, error) {
|
||||
sinon.assert.calledOnce(navigator.mozKillSwitch.enable);
|
||||
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
} ]);
|
||||
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'command');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('Without API existing', function() {
|
||||
setup(function() {
|
||||
navigator.mozKillSwitch = undefined;
|
||||
});
|
||||
|
||||
test('No invocation', function(done) {
|
||||
subject.invokeCommand('killswitch', [ function(retval, error) {
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
} ]);
|
||||
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'command');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('List of accepted commands', function() {
|
||||
MockSettingsListener.mTriggerCallback('geolocation.enabled', true);
|
||||
|
||||
var allCommands = ['track', 'erase', 'ring', 'lock', 'killswitch'];
|
||||
var enabledCommands = subject.getEnabledCommands();
|
||||
assert.deepEqual(enabledCommands.sort(), allCommands.sort());
|
||||
|
||||
// track should be disabled when geolocation is disabled
|
||||
MockSettingsListener.mTriggerCallback('geolocation.enabled', false);
|
||||
allCommands = ['erase', 'ring', 'lock', 'killswitch'];
|
||||
enabledCommands = subject.getEnabledCommands();
|
||||
assert.deepEqual(enabledCommands.sort(), allCommands.sort());
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
navigator.mozPower = realMozPower;
|
||||
navigator.mozKillSwitch = realKillSwitch;
|
||||
navigator.mozApps = realMozApps;
|
||||
navigator.mozSettings = realMozSettings;
|
||||
|
||||
delete window.DUMP;
|
||||
|
||||
fakeClock.restore();
|
||||
|
||||
delete window.FindMyDevice;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
suite('FindMyDevice (with real clock) >', function() {
|
||||
var realMozSettings;
|
||||
|
||||
mocksForFindMyDevice.attachTestHelpers();
|
||||
|
||||
var subject;
|
||||
setup(function(done) {
|
||||
|
||||
// replace shared/js/dump.js
|
||||
window.DUMP = function() {};
|
||||
|
||||
realMozSettings = navigator.mozSettings;
|
||||
MockNavigatorSettings.mSetup();
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
|
||||
window.FindMyDevice = {
|
||||
beginHighPriority: this.sinon.stub(),
|
||||
endHighPriority: this.sinon.stub()
|
||||
};
|
||||
|
||||
require('/js/commands.js', function() {
|
||||
subject = Commands;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Lock command', function(done) {
|
||||
var code = '1234', message = 'locked!';
|
||||
var DIGEST_VALUE = 'lockscreen.passcode-lock.digest.value';
|
||||
var settingsLock = MockSettingsListener.getSettingsLock();
|
||||
var oldDigest = settingsLock.get(DIGEST_VALUE);
|
||||
|
||||
subject.invokeCommand('lock', [message, code, function(retval) {
|
||||
assert.equal(retval, true);
|
||||
sinon.assert.calledWith(FindMyDevice.beginHighPriority, 'command');
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'command');
|
||||
var lock = MockSettingsListener.getSettingsLock().locks.pop();
|
||||
assert.deepEqual({
|
||||
'lockscreen.enabled': true,
|
||||
'lockscreen.notifications-preview.enabled': false,
|
||||
'lockscreen.passcode-lock.enabled': true,
|
||||
'lockscreen.lock-message': message,
|
||||
'lockscreen.lock-immediately': true
|
||||
}, lock, 'check that the correct settings were set');
|
||||
assert.notEqual(oldDigest, lock[DIGEST_VALUE],
|
||||
'check that Passcode digest changed');
|
||||
|
||||
done();
|
||||
}]);
|
||||
});
|
||||
|
||||
test('Bug 1201530 - check existing passcode override', function() {
|
||||
var code = '2342', message = 'already locked!';
|
||||
var stubPasscodeSet = sinon.stub(PasscodeHelper, 'set', function() {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
// Simulate already-locked device.
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.enabled', true);
|
||||
MockSettingsListener.mTriggerCallback('lockscreen.passcode-lock.enabled',
|
||||
true);
|
||||
subject.invokeCommand('lock', [message, code, function() {}]);
|
||||
assert.isTrue(stubPasscodeSet.calledWith(code),
|
||||
'existing passcode is not overridden');
|
||||
stubPasscodeSet.restore();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
// clean up sinon.js stubs
|
||||
navigator.mozSettings = realMozSettings;
|
||||
MockNavigatorSettings.mTeardown();
|
||||
delete window.DUMP;
|
||||
delete window.FindMyDevice;
|
||||
});
|
||||
});
|
||||
135
gaia/apps/findmydevice/test/unit/findmydevice_requester_test.js
Executable file
135
gaia/apps/findmydevice/test/unit/findmydevice_requester_test.js
Executable file
|
|
@ -0,0 +1,135 @@
|
|||
/* global MocksHelper, hawk, Requester */
|
||||
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mock_dump.js');
|
||||
|
||||
var mocksForFindMyDevice = new MocksHelper([
|
||||
'Dump'
|
||||
]).init();
|
||||
|
||||
suite('FindMyDevice >', function() {
|
||||
var fakeXHR;
|
||||
|
||||
mocksForFindMyDevice.attachTestHelpers();
|
||||
|
||||
suiteSetup(function(done) {
|
||||
window.Config = {
|
||||
api_url: 'https://find.firefox.com',
|
||||
api_version: 'v0'
|
||||
};
|
||||
|
||||
// We require requester.js here and not above because
|
||||
// we want to make sure all of our dependencies have already
|
||||
// been loaded.
|
||||
require('/js/requester.js', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
delete window.Config;
|
||||
});
|
||||
|
||||
var xhr;
|
||||
setup(function() {
|
||||
xhr = null;
|
||||
fakeXHR = sinon.useFakeXMLHttpRequest();
|
||||
fakeXHR.onCreate = function(request) {
|
||||
xhr = request;
|
||||
};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fakeXHR.restore();
|
||||
});
|
||||
|
||||
test('url is properly loaded from configuration', function() {
|
||||
assert.equal(Requester._url, 'https://find.firefox.com/v0');
|
||||
});
|
||||
|
||||
test('XHR is created with the correct properties', function() {
|
||||
Requester.post('/register');
|
||||
assert.equal(xhr.url, 'https://find.firefox.com/v0/register');
|
||||
assert.equal(xhr.requestHeaders['Content-Type'],
|
||||
'application/json;charset=utf-8');
|
||||
assert.equal(xhr.method, 'POST');
|
||||
assert.equal(xhr.timeout, Requester.XHR_TIMEOUT_MS);
|
||||
});
|
||||
|
||||
test('onsuccess is called on successful server response', function() {
|
||||
var response = '{"ok": true}';
|
||||
var onsuccess = this.sinon.stub();
|
||||
Requester.post('/register', {}, onsuccess);
|
||||
|
||||
xhr.respond(200, {'Content-type': 'application/json'}, response);
|
||||
sinon.assert.called(onsuccess);
|
||||
});
|
||||
|
||||
test('onerror is called on failed server response', function() {
|
||||
var onerror = this.sinon.stub();
|
||||
Requester.post('/register', {}, null, onerror);
|
||||
|
||||
xhr.respond(401, {}, '');
|
||||
sinon.assert.called(onerror);
|
||||
});
|
||||
|
||||
test('onerror is called on timeout', function() {
|
||||
var onerror = this.sinon.stub();
|
||||
Requester.post('/register', {}, null, onerror);
|
||||
|
||||
xhr.ontimeout();
|
||||
sinon.assert.called(onerror);
|
||||
});
|
||||
|
||||
suite('HAWK credentials', function() {
|
||||
var hawkOptions = {
|
||||
credentials: {id: 'id', key: 'key', algorithm: 'sha256'},
|
||||
contentType: 'application/json',
|
||||
payload: '{}'
|
||||
};
|
||||
|
||||
suiteSetup(function() {
|
||||
window.hawk = {
|
||||
client: {
|
||||
header: function() {
|
||||
return {field: 'header'};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Requester.setHawkCredentials('id', 'key');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
delete window.hawk;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
this.sinon.spy(hawk.client, 'header');
|
||||
});
|
||||
|
||||
test('HAWK credentials are included in the request', function() {
|
||||
Requester.post('/register', {});
|
||||
|
||||
sinon.assert.calledWith(hawk.client.header,
|
||||
xhr.url, 'POST', hawkOptions);
|
||||
assert.equal(xhr.requestHeaders.Authorization,
|
||||
hawk.client.header().field);
|
||||
});
|
||||
|
||||
test('ignore response if HAWK doesn\'t verify', function() {
|
||||
hawk.client.authenticate = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
var onsuccess = this.sinon.stub();
|
||||
var onerror = this.sinon.stub();
|
||||
Requester.post('/register', {}, onsuccess, onerror);
|
||||
xhr.respond(200, {'Content-type': 'application/json'}, '{}');
|
||||
|
||||
sinon.assert.notCalled(onsuccess);
|
||||
sinon.assert.notCalled(onerror);
|
||||
});
|
||||
});
|
||||
});
|
||||
826
gaia/apps/findmydevice/test/unit/findmydevice_test.js
Executable file
826
gaia/apps/findmydevice/test/unit/findmydevice_test.js
Executable file
|
|
@ -0,0 +1,826 @@
|
|||
/* global MocksHelper, MockGeolocation, MockNavigatormozSetMessageHandler,
|
||||
MockSettingsHelper, MockNavigatorSettings, FindMyDevice, MockMozAlarms,
|
||||
IAC_API_WAKEUP_REASON_LOGIN, IAC_API_WAKEUP_REASON_LOGOUT,
|
||||
IAC_API_WAKEUP_REASON_TRY_DISABLE, IAC_API_WAKEUP_REASON_ENABLED_CHANGED,
|
||||
IAC_API_WAKEUP_REASON_LOCKSCREEN_CLOSED, Commands
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_dump.js');
|
||||
require('/shared/test/unit/mocks/mock_async_storage.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
|
||||
require('/shared/test/unit/mocks/mock_settings_listener.js');
|
||||
require('/shared/test/unit/mocks/mock_settings_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_geolocation.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_moz_set_message_handler.js');
|
||||
require('/shared/js/findmydevice_iac_api.js');
|
||||
require('/shared/test/unit/mocks/mock_moz_alarms.js');
|
||||
|
||||
var mocksForFindMyDevice = new MocksHelper([
|
||||
'asyncStorage',
|
||||
'Dump',
|
||||
'Geolocation',
|
||||
'SettingsHelper'
|
||||
]).init();
|
||||
|
||||
suite('FindMyDevice >', function() {
|
||||
var realMozId;
|
||||
var realMozSettings;
|
||||
var realMozSetMessageHandler;
|
||||
var realMozAlarms;
|
||||
var realNavigatorOnLine;
|
||||
var realCommands;
|
||||
var observerSpy;
|
||||
|
||||
mocksForFindMyDevice.attachTestHelpers();
|
||||
|
||||
suiteSetup(function(done) {
|
||||
realMozId = navigator.mozId;
|
||||
// attempting to stub only the request method of mozId,
|
||||
// as in |sinon.stub(navigator.mozId, 'request', ...)|,
|
||||
// causes an exception to be raised, so we replace the
|
||||
// entire mozId object.
|
||||
navigator.mozId = {
|
||||
request: sinon.stub(),
|
||||
watch: sinon.stub()
|
||||
};
|
||||
|
||||
realMozSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
MockNavigatorSettings.mSetup();
|
||||
|
||||
realMozSetMessageHandler = navigator.mozSetMessageHandler;
|
||||
navigator.mozSetMessageHandler = MockNavigatormozSetMessageHandler;
|
||||
MockNavigatormozSetMessageHandler.mSetup();
|
||||
|
||||
realMozAlarms = navigator.mozAlarms;
|
||||
navigator.mozAlarms = MockMozAlarms;
|
||||
|
||||
realNavigatorOnLine = Object.getOwnPropertyDescriptor(navigator, 'onLine');
|
||||
Object.defineProperty(navigator, 'onLine', {
|
||||
fakeOnLine: true,
|
||||
configurable: true,
|
||||
get: function() { return this.fakeOnLine; },
|
||||
set: function(status) { this.fakeOnLine = !!status; }
|
||||
});
|
||||
|
||||
window.Config = {
|
||||
api_url: 'https://find.firefox.com',
|
||||
api_version: 'v0'
|
||||
};
|
||||
|
||||
observerSpy = sinon.spy(MockNavigatorSettings, 'addObserver');
|
||||
|
||||
// We require findmydevice.js here and not above because
|
||||
// we want to make sure all of our dependencies have already
|
||||
// been loaded.
|
||||
require('/js/findmydevice.js', function() {
|
||||
// We stub navigator.mozId.watch above, so FindMyDevice.init()
|
||||
// is effectively a no-op. We don't need to fully initialize FMD for
|
||||
// these tests, so just register for the events we care about below.
|
||||
FindMyDevice._observeSettings();
|
||||
FindMyDevice._initMessageHandlers();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
observerSpy.restore();
|
||||
|
||||
delete window.Config;
|
||||
|
||||
navigator.mozId = realMozId;
|
||||
|
||||
navigator.mozSettings = realMozSettings;
|
||||
MockNavigatorSettings.mTeardown();
|
||||
|
||||
navigator.mozSetMessageHandler = realMozSetMessageHandler;
|
||||
MockNavigatormozSetMessageHandler.mTeardown();
|
||||
|
||||
navigator.mozAlarms = realMozAlarms;
|
||||
|
||||
if (realNavigatorOnLine) {
|
||||
Object.defineProperty(navigator, 'onLine', realNavigatorOnLine);
|
||||
}
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
this.sinon.stub(FindMyDevice, '_reportDisabled');
|
||||
this.sinon.stub(FindMyDevice, '_replyAndFetchCommands');
|
||||
|
||||
realCommands = window.Commands;
|
||||
window.Commands = {
|
||||
invokeCommand: this.sinon.stub(),
|
||||
deviceHasPasscode: null
|
||||
};
|
||||
|
||||
// XXX(ggp) force re-creation of the SettingsHelper objects
|
||||
// used by FMD, since MockSettingsHelper invalidates all objects
|
||||
// in its mTeardown.
|
||||
FindMyDevice._initSettings(done);
|
||||
|
||||
navigator.onLine = true;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FindMyDevice._enabled = false;
|
||||
FindMyDevice._registered = false;
|
||||
FindMyDevice._loggedIn = false;
|
||||
FindMyDevice._state = null;
|
||||
window.Commands = realCommands;
|
||||
});
|
||||
|
||||
function sendWakeUpMessage(reason) {
|
||||
var port = {};
|
||||
MockNavigatormozSetMessageHandler.mTrigger('connection',
|
||||
{port: port, keyword: 'findmydevice-wakeup'});
|
||||
port.onmessage({data: reason});
|
||||
}
|
||||
|
||||
test('ensure retry counter is reset on enable', function() {
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_ENABLED_CHANGED);
|
||||
|
||||
MockSettingsHelper('findmydevice.retry-count').get(
|
||||
function(val) {
|
||||
assert.equal(val, 0, 'retry count should be 0');
|
||||
});
|
||||
});
|
||||
|
||||
test('retryCount is not incremented on error if registered', function() {
|
||||
FindMyDevice._registered = true;
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_ENABLED_CHANGED);
|
||||
|
||||
this.sinon.stub(FindMyDevice, 'beginHighPriority');
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
|
||||
// simulate 3 failed requests
|
||||
FindMyDevice._handleServerError({status:401});
|
||||
FindMyDevice._handleServerError({status:401});
|
||||
FindMyDevice._handleServerError({status:401});
|
||||
|
||||
MockSettingsHelper('findmydevice.retry-count').get(
|
||||
function(val) {
|
||||
assert.equal(val, 0, 'retry count should be 0');
|
||||
});
|
||||
});
|
||||
|
||||
test('retryCount is incremented on error when not registered', function() {
|
||||
FindMyDevice._registered = false;
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_ENABLED_CHANGED);
|
||||
|
||||
this.sinon.stub(FindMyDevice, 'beginHighPriority');
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
|
||||
// simulate 3 failed requests
|
||||
FindMyDevice._handleServerError({status:401});
|
||||
FindMyDevice._handleServerError({status:401});
|
||||
FindMyDevice._handleServerError({status:401});
|
||||
|
||||
MockSettingsHelper('findmydevice.retry-count').get(
|
||||
function(val) {
|
||||
assert.equal(val, 3, 'retry count should be 3');
|
||||
});
|
||||
});
|
||||
|
||||
test('retryCount is not incremented when offline', function() {
|
||||
FindMyDevice._registered = false;
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_ENABLED_CHANGED);
|
||||
|
||||
this.sinon.stub(FindMyDevice, 'beginHighPriority');
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
navigator.onLine = false;
|
||||
|
||||
// Simulate 3 failed requests
|
||||
FindMyDevice._handleServerError({status: 401});
|
||||
FindMyDevice._handleServerError({status: 401});
|
||||
FindMyDevice._handleServerError({status: 401});
|
||||
|
||||
MockSettingsHelper('findmydevice.retry-count').get(
|
||||
function(val) {
|
||||
assert.equal(val, 0, 'retry count should be 0');
|
||||
});
|
||||
});
|
||||
|
||||
test('fields from coordinates are included in server response', function() {
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._enabled = true;
|
||||
|
||||
FindMyDevice._replyCallback('t', true, MockGeolocation.fakePosition);
|
||||
sinon.assert.called(FindMyDevice._replyAndFetchCommands);
|
||||
assert.deepEqual(FindMyDevice._reply.t, {
|
||||
ok: true,
|
||||
la: MockGeolocation.fakePosition.coords.latitude,
|
||||
lo: MockGeolocation.fakePosition.coords.longitude,
|
||||
acc: MockGeolocation.fakePosition.coords.accuracy,
|
||||
ti: MockGeolocation.fakePosition.timestamp
|
||||
});
|
||||
});
|
||||
|
||||
test('error message is included in the server response', function() {
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._enabled = true;
|
||||
|
||||
var message = 'error message';
|
||||
FindMyDevice._replyCallback('t', false, message);
|
||||
sinon.assert.called(FindMyDevice._replyAndFetchCommands);
|
||||
assert.equal(FindMyDevice._reply.t.error, message);
|
||||
});
|
||||
|
||||
suite('settings observers', function() {
|
||||
test('Observes findmydevice.registered', function() {
|
||||
sinon.assert.calledWith(observerSpy, 'findmydevice.registered');
|
||||
assert.isTrue('_registered' in FindMyDevice);
|
||||
assert.equal('object', typeof FindMyDevice._registeredHelper);
|
||||
assert.notEqual(null, FindMyDevice._registeredHelper);
|
||||
});
|
||||
|
||||
test('Observes findmydevice.enabled', function() {
|
||||
sinon.assert.calledWith(observerSpy, 'findmydevice.enabled');
|
||||
assert.isTrue('_enabled' in FindMyDevice);
|
||||
assert.equal('object', typeof FindMyDevice._enabledHelper);
|
||||
assert.notEqual(null, FindMyDevice._enabledHelper);
|
||||
});
|
||||
|
||||
test('Observes findmydevice.current-clientid', function() {
|
||||
sinon.assert.calledWith(observerSpy, 'findmydevice.current-clientid');
|
||||
assert.isTrue('_currentClientID' in FindMyDevice);
|
||||
assert.equal('object', typeof FindMyDevice._currentClientIDHelper);
|
||||
assert.notEqual(null, FindMyDevice._currentClientIDHelper);
|
||||
});
|
||||
|
||||
test('Observes findmydevice.can-disable', function() {
|
||||
sinon.assert.calledWith(observerSpy, 'findmydevice.can-disable');
|
||||
assert.isTrue('_canDisable' in FindMyDevice);
|
||||
assert.equal('object', typeof FindMyDevice._canDisableHelper);
|
||||
assert.notEqual(null, FindMyDevice._canDisableHelper);
|
||||
});
|
||||
});
|
||||
|
||||
suite('settings handlers', function() {
|
||||
var endHighPriorityStub;
|
||||
|
||||
suite('Changes to findmydevice.registered', function() {
|
||||
var contactServerSpy, loadStateSpy, currentIdHelperSpy;
|
||||
var _registered = {};
|
||||
|
||||
setup(function() {
|
||||
contactServerSpy = this.sinon.spy(FindMyDevice, '_contactServer');
|
||||
loadStateSpy = this.sinon.spy(FindMyDevice, '_loadState');
|
||||
currentIdHelperSpy =
|
||||
this.sinon.spy(FindMyDevice._currentClientIDHelper, 'set');
|
||||
endHighPriorityStub = this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
});
|
||||
|
||||
suite('when not registered', function() {
|
||||
setup(function() {
|
||||
_registered = { settingValue: false};
|
||||
});
|
||||
|
||||
test('contact server', function() {
|
||||
FindMyDevice._onRegisteredChanged(_registered);
|
||||
sinon.assert.calledOnce(contactServerSpy);
|
||||
sinon.assert.notCalled(loadStateSpy);
|
||||
sinon.assert.notCalled(currentIdHelperSpy);
|
||||
});
|
||||
|
||||
test('end wakelock section', function() {
|
||||
FindMyDevice._onRegisteredChanged(_registered);
|
||||
sinon.assert.calledWith(endHighPriorityStub, 'clientLogic');
|
||||
sinon.assert.notCalled(loadStateSpy);
|
||||
sinon.assert.notCalled(currentIdHelperSpy);
|
||||
});
|
||||
});
|
||||
|
||||
suite('when registered', function() {
|
||||
setup(function() {
|
||||
_registered = { settingValue: true};
|
||||
});
|
||||
|
||||
test('does load state', function() {
|
||||
FindMyDevice._onRegisteredChanged(_registered);
|
||||
sinon.assert.calledOnce(loadStateSpy);
|
||||
});
|
||||
|
||||
test('does contact server', function() {
|
||||
FindMyDevice._onRegisteredChanged(_registered);
|
||||
sinon.assert.calledOnce(contactServerSpy);
|
||||
});
|
||||
|
||||
test('does set empty current id', function() {
|
||||
FindMyDevice._onRegisteredChanged(_registered);
|
||||
sinon.assert.calledOnce(currentIdHelperSpy);
|
||||
sinon.assert.calledWith(currentIdHelperSpy, '');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('Changes to findmydevice.enabled', function() {
|
||||
assert.isTrue(true, 'nothing to do');
|
||||
});
|
||||
|
||||
suite('Changes to findmydevice.current-clientid', function() {
|
||||
var _currentClientId = {};
|
||||
var refreshClientStub;
|
||||
|
||||
setup(function() {
|
||||
endHighPriorityStub = this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
refreshClientStub =
|
||||
this.sinon.stub(FindMyDevice, '_refreshClientIDIfRegistered');
|
||||
});
|
||||
|
||||
suite('logged and no clientid', function() {
|
||||
var oldLogged;
|
||||
|
||||
setup(function() {
|
||||
_currentClientId = { settingValue: ''};
|
||||
oldLogged = FindMyDevice._loggedIn;
|
||||
FindMyDevice._loggedIn = true;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FindMyDevice._loggedIn = oldLogged;
|
||||
});
|
||||
|
||||
test('client id refresh', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledOnce(refreshClientStub);
|
||||
sinon.assert.calledWith(refreshClientStub, false);
|
||||
});
|
||||
|
||||
test('end of wakelock section', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledWith(endHighPriorityStub, 'clientLogic');
|
||||
});
|
||||
});
|
||||
|
||||
suite('not logged/has clientid and registered', function() {
|
||||
var oldLogged, oldRegistered, oldState;
|
||||
|
||||
setup(function() {
|
||||
_currentClientId = { settingValue: 'cid'};
|
||||
oldLogged = FindMyDevice._loggedIn;
|
||||
oldRegistered = FindMyDevice._registered;
|
||||
oldState = FindMyDevice._state;
|
||||
FindMyDevice._loggedIn = false;
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._state = { };
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FindMyDevice._loggedIn = oldLogged;
|
||||
FindMyDevice._registered = oldRegistered;
|
||||
FindMyDevice._state = oldState;
|
||||
});
|
||||
|
||||
suite('calls to canDisableHelper', function() {
|
||||
var canDisableSpy;
|
||||
|
||||
setup(function() {
|
||||
canDisableSpy =
|
||||
this.sinon.spy(FindMyDevice._canDisableHelper, 'set');
|
||||
});
|
||||
|
||||
suite('with everything true', function() {
|
||||
setup(function() {
|
||||
FindMyDevice._loggedIn = true;
|
||||
FindMyDevice._state.clientid = 'cid';
|
||||
});
|
||||
|
||||
test('proper call to canDisableHelper', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledOnce(canDisableSpy);
|
||||
sinon.assert.calledWith(canDisableSpy, true);
|
||||
});
|
||||
});
|
||||
|
||||
suite('with loggedin false and matching clientid', function() {
|
||||
setup(function() {
|
||||
FindMyDevice._loggedIn = false;
|
||||
FindMyDevice._state.clientid = 'cid';
|
||||
});
|
||||
|
||||
test('proper call to canDisableHelper', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledOnce(canDisableSpy);
|
||||
sinon.assert.calledWith(canDisableSpy, false);
|
||||
});
|
||||
});
|
||||
|
||||
suite('with loggedin false and non matching clientid', function() {
|
||||
setup(function() {
|
||||
FindMyDevice._loggedIn = false;
|
||||
FindMyDevice._state.clientid = '';
|
||||
});
|
||||
|
||||
test('proper call to canDisableHelper', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledOnce(canDisableSpy);
|
||||
sinon.assert.calledWith(canDisableSpy, false);
|
||||
});
|
||||
});
|
||||
|
||||
suite('with loggedin true and non matching clientid', function() {
|
||||
setup(function() {
|
||||
FindMyDevice._loggedIn = true;
|
||||
FindMyDevice._state.clientid = '';
|
||||
});
|
||||
|
||||
test('proper call to canDisableHelper', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledOnce(canDisableSpy);
|
||||
sinon.assert.calledWith(canDisableSpy, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('keep wakelock section', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.notCalled(endHighPriorityStub);
|
||||
});
|
||||
});
|
||||
|
||||
suite('none of the above', function() {
|
||||
var oldLogged, oldRegistered;
|
||||
|
||||
setup(function() {
|
||||
_currentClientId = { settingValue: 'cid'};
|
||||
oldLogged = FindMyDevice._loggedIn;
|
||||
oldRegistered = FindMyDevice._registered;
|
||||
FindMyDevice._loggedIn = false;
|
||||
FindMyDevice._registered = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FindMyDevice._loggedIn = oldLogged;
|
||||
FindMyDevice._registered = oldRegistered;
|
||||
});
|
||||
|
||||
test('end of wakelock section', function() {
|
||||
FindMyDevice._onClientIDChanged(_currentClientId);
|
||||
sinon.assert.calledWith(endHighPriorityStub, 'clientLogic');
|
||||
sinon.assert.notCalled(refreshClientStub);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Changes to findmydevice.can-disable', function() {
|
||||
var _canDisable = {};
|
||||
var enabledSpy;
|
||||
var oldDisableAttempt;
|
||||
|
||||
setup(function() {
|
||||
endHighPriorityStub = this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
enabledSpy =
|
||||
this.sinon.spy(FindMyDevice._enabledHelper, 'set');
|
||||
oldDisableAttempt = FindMyDevice._disableAttempt;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FindMyDevice._disableAttempt = oldDisableAttempt;
|
||||
});
|
||||
|
||||
suite('can-disabled changed to true', function() {
|
||||
setup(function() {
|
||||
_canDisable = { settingValue: true};
|
||||
});
|
||||
|
||||
test('with disable attempt', function() {
|
||||
FindMyDevice._disableAttempt = true;
|
||||
FindMyDevice._onCanDisableChanged(_canDisable);
|
||||
sinon.assert.calledWith(enabledSpy, false);
|
||||
});
|
||||
|
||||
test('without disable attempt', function() {
|
||||
FindMyDevice._disableAttempt = false;
|
||||
FindMyDevice._onCanDisableChanged(_canDisable);
|
||||
sinon.assert.notCalled(enabledSpy);
|
||||
});
|
||||
|
||||
test('reset stuff', function() {
|
||||
FindMyDevice._onCanDisableChanged(_canDisable);
|
||||
assert.isFalse(FindMyDevice._disableAttempt,
|
||||
'set disableAttempt to false');
|
||||
sinon.assert.calledOnce(endHighPriorityStub, 'end wakelock section');
|
||||
});
|
||||
});
|
||||
|
||||
suite('can-disabled changed to false', function() {
|
||||
setup(function() {
|
||||
_canDisable = { settingValue: false};
|
||||
});
|
||||
|
||||
test('with disable attempt', function() {
|
||||
FindMyDevice._disableAttempt = true;
|
||||
FindMyDevice._onCanDisableChanged(_canDisable);
|
||||
sinon.assert.notCalled(enabledSpy);
|
||||
});
|
||||
|
||||
test('without disable attempt', function() {
|
||||
FindMyDevice._disableAttempt = false;
|
||||
FindMyDevice._onCanDisableChanged(_canDisable);
|
||||
sinon.assert.notCalled(enabledSpy);
|
||||
});
|
||||
|
||||
test('reset stuff', function() {
|
||||
FindMyDevice._onCanDisableChanged(_canDisable);
|
||||
assert.isFalse(FindMyDevice._disableAttempt,
|
||||
'set disableAttempt to false');
|
||||
sinon.assert.calledOnce(endHighPriorityStub, 'end wakelock section');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('findmydevice.current-clientid behavior', function() {
|
||||
setup(function() {
|
||||
this.sinon.spy(FindMyDevice._currentClientIDHelper, 'set');
|
||||
});
|
||||
|
||||
test('invalidate client id when logged in', function() {
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_LOGIN);
|
||||
assert.isTrue(FindMyDevice._loggedIn, 'not logged in after login event');
|
||||
sinon.assert.calledWith(FindMyDevice._currentClientIDHelper.set, '');
|
||||
});
|
||||
|
||||
test('invalidate client id when logged out', function() {
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_LOGOUT);
|
||||
assert.isFalse(FindMyDevice._loggedIn, 'logged in after logout event');
|
||||
sinon.assert.calledWith(FindMyDevice._currentClientIDHelper.set, '');
|
||||
});
|
||||
|
||||
test('refresh the current clientid after (re-)registering',
|
||||
function() {
|
||||
FindMyDevice._enabled = true;
|
||||
FindMyDevice._registered = true;
|
||||
this.sinon.stub(FindMyDevice, '_loadState', function(cb) { cb(); });
|
||||
FindMyDevice._onRegisteredChanged({settingValue: true});
|
||||
sinon.assert.calledWith(FindMyDevice._currentClientIDHelper.set, '');
|
||||
});
|
||||
});
|
||||
|
||||
suite('findmydevice.can-disable behavior', function() {
|
||||
setup(function() {
|
||||
this.sinon.spy(FindMyDevice._canDisableHelper, 'set');
|
||||
});
|
||||
|
||||
test('set findmydevice.can-disable to false when logged out', function() {
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._loggedIn = false;
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.current-clientid',
|
||||
{settingValue: ''});
|
||||
sinon.assert.calledWith(FindMyDevice._canDisableHelper.set, false);
|
||||
});
|
||||
|
||||
test('don\'t set findmydevice.can-disable on logout if not registered',
|
||||
function() {
|
||||
FindMyDevice._loggedIn = false;
|
||||
FindMyDevice._registered = false;
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.current-clientid',
|
||||
{settingValue: ''});
|
||||
sinon.assert.notCalled(FindMyDevice._canDisableHelper.set);
|
||||
});
|
||||
|
||||
test('allow disabling when clientid matches the state', function() {
|
||||
FindMyDevice._loggedIn = true;
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._state = {clientid: 'clientid'};
|
||||
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.current-clientid',
|
||||
{settingValue: 'clientid'});
|
||||
sinon.assert.calledWith(FindMyDevice._canDisableHelper.set, true);
|
||||
});
|
||||
|
||||
test('disallow disabling when clientid doesn\'t match the state',
|
||||
function() {
|
||||
FindMyDevice._loggedIn = true;
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._state = {clientid: 'wrong clientid'};
|
||||
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.current-clientid',
|
||||
{settingValue: 'clientid'});
|
||||
sinon.assert.calledWith(FindMyDevice._canDisableHelper.set, false);
|
||||
});
|
||||
});
|
||||
|
||||
test('request client id when invalidated', function() {
|
||||
FindMyDevice._loggedIn = true;
|
||||
FindMyDevice._registered = true;
|
||||
FindMyDevice._state = {clientid: 'clientid'};
|
||||
|
||||
this.sinon.stub(FindMyDevice, 'beginHighPriority');
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
this.sinon.spy(FindMyDevice, '_refreshClientIDIfRegistered');
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.current-clientid',
|
||||
{settingValue: ''});
|
||||
sinon.assert.calledWith(FindMyDevice._refreshClientIDIfRegistered, false);
|
||||
sinon.assert.calledWith(navigator.mozId.request, {});
|
||||
sinon.assert.calledOnce(FindMyDevice.beginHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.beginHighPriority, 'clientLogic');
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'clientLogic');
|
||||
});
|
||||
|
||||
test('refresh authentication when attempting to disable', function() {
|
||||
FindMyDevice._loggedIn = true;
|
||||
FindMyDevice._registered = true;
|
||||
|
||||
this.sinon.spy(FindMyDevice, '_refreshClientIDIfRegistered');
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_TRY_DISABLE);
|
||||
assert.isTrue(FindMyDevice._disableAttempt);
|
||||
sinon.assert.calledWith(FindMyDevice._refreshClientIDIfRegistered, true);
|
||||
assert.isTrue(
|
||||
navigator.mozId.request.calledWithMatch(
|
||||
{refreshAuthentication: 0}));
|
||||
});
|
||||
|
||||
test('setting an alarm releases a wakelock', function() {
|
||||
var clock = this.sinon.useFakeTimers();
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
FindMyDevice._scheduleAlarm('ping');
|
||||
clock.tick();
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'clientLogic');
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
test('contact the server on alarm', function() {
|
||||
this.sinon.stub(FindMyDevice, '_contactServer');
|
||||
this.sinon.stub(FindMyDevice, '_refreshClientIDIfRegistered');
|
||||
MockNavigatormozSetMessageHandler.mTrigger('alarm');
|
||||
sinon.assert.calledWith(FindMyDevice._refreshClientIDIfRegistered, false);
|
||||
sinon.assert.called(FindMyDevice._contactServer);
|
||||
});
|
||||
|
||||
test('report to the server when disabled', function() {
|
||||
FindMyDevice._registered = true;
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.enabled',
|
||||
{settingValue: false});
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_ENABLED_CHANGED);
|
||||
sinon.assert.called(FindMyDevice._reportDisabled);
|
||||
});
|
||||
|
||||
test('track and ring are cancelled on LOCKSCREEN_CLOSED, passcode set',
|
||||
function() {
|
||||
this.sinon.stub(Commands, 'deviceHasPasscode', function() {return true;});
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_LOCKSCREEN_CLOSED);
|
||||
sinon.assert.calledTwice(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'ring', [0]);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'track', [0]);
|
||||
});
|
||||
|
||||
test('track and ring continue on LOCKSCREEN_CLOSED, no passcode set',
|
||||
function() {
|
||||
this.sinon.stub(Commands, 'deviceHasPasscode', function() {return false;});
|
||||
sendWakeUpMessage(IAC_API_WAKEUP_REASON_LOCKSCREEN_CLOSED);
|
||||
sinon.assert.notCalled(Commands.invokeCommand);
|
||||
});
|
||||
|
||||
test('wakelocks are released on unregistered clientID change', function() {
|
||||
FindMyDevice._registered = false;
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
MockNavigatorSettings.mTriggerObservers('findmydevice.current-clientid',
|
||||
{settingValue: ''});
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'clientLogic');
|
||||
});
|
||||
|
||||
test('wakelocks are released when registering while already registering',
|
||||
function() {
|
||||
this.sinon.stub(FindMyDevice, 'endHighPriority');
|
||||
FindMyDevice._registering = true;
|
||||
FindMyDevice._register();
|
||||
sinon.assert.calledOnce(FindMyDevice.endHighPriority);
|
||||
sinon.assert.calledWith(FindMyDevice.endHighPriority, 'clientLogic');
|
||||
});
|
||||
|
||||
suite('testing command flow', function() {
|
||||
var serverResponse = {};
|
||||
var commandSpy;
|
||||
|
||||
setup(function() {
|
||||
FindMyDevice._enabled = true;
|
||||
commandSpy = this.sinon.spy(FindMyDevice, '_processCommands');
|
||||
});
|
||||
|
||||
suite('set alarm on server interaction', function() {
|
||||
var alarmSpy;
|
||||
|
||||
setup(function() {
|
||||
serverResponse = {t: {d: 60}};
|
||||
alarmSpy = this.sinon.spy(FindMyDevice, '_scheduleAlarm');
|
||||
});
|
||||
|
||||
suite('With FMD enabled', function() {
|
||||
setup(function() {
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
test('alarm is set on successful server response', function() {
|
||||
sinon.assert.calledOnce(commandSpy);
|
||||
sinon.assert.calledWith(commandSpy, serverResponse);
|
||||
sinon.assert.calledOnce(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'track');
|
||||
sinon.assert.calledWith(alarmSpy, 'ping');
|
||||
});
|
||||
});
|
||||
|
||||
suite('With FMD disabled', function() {
|
||||
setup(function() {
|
||||
FindMyDevice._enabled = false;
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FindMyDevice._enabled = true;
|
||||
});
|
||||
|
||||
test('alarm is set on server response even when disabled', function() {
|
||||
sinon.assert.notCalled(commandSpy);
|
||||
sinon.assert.notCalled(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(alarmSpy, 'ping');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Processing of erase command', function() {
|
||||
setup(function() {
|
||||
serverResponse = {e: {}};
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
test('erase command invoked', function() {
|
||||
sinon.assert.calledOnce(commandSpy);
|
||||
sinon.assert.calledWith(commandSpy, serverResponse);
|
||||
sinon.assert.calledOnce(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'erase');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Processing of killswitch command', function() {
|
||||
setup(function() {
|
||||
serverResponse = {k: {}};
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
test('killswitch command invoked', function() {
|
||||
sinon.assert.calledOnce(commandSpy);
|
||||
sinon.assert.calledWith(commandSpy, serverResponse);
|
||||
sinon.assert.calledOnce(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'killswitch');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Processing of lock command', function() {
|
||||
setup(function() {
|
||||
serverResponse = {l: {m: 'message', c: '1234'}};
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
test('lock command invoked', function() {
|
||||
sinon.assert.calledOnce(commandSpy);
|
||||
sinon.assert.calledWith(commandSpy, serverResponse);
|
||||
sinon.assert.calledOnce(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'lock');
|
||||
|
||||
var args = Commands.invokeCommand.firstCall.args[1];
|
||||
assert.equal(args[0], 'message');
|
||||
assert.equal(args[1], '1234');
|
||||
});
|
||||
});
|
||||
|
||||
suite('Processing of ring command', function() {
|
||||
setup(function() {
|
||||
serverResponse = {r: {d: 5}};
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
test('ring command invoked', function() {
|
||||
sinon.assert.calledOnce(commandSpy);
|
||||
sinon.assert.calledWith(commandSpy, serverResponse);
|
||||
sinon.assert.calledOnce(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'ring');
|
||||
|
||||
var args = Commands.invokeCommand.firstCall.args[1];
|
||||
assert.equal(args[0], 5);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Processing of track command', function() {
|
||||
setup(function() {
|
||||
serverResponse = {t: {d: 7}};
|
||||
FindMyDevice._handleServerResponse(serverResponse);
|
||||
});
|
||||
|
||||
test('track command invoked', function() {
|
||||
sinon.assert.calledOnce(commandSpy);
|
||||
sinon.assert.calledWith(commandSpy, serverResponse);
|
||||
sinon.assert.calledOnce(Commands.invokeCommand);
|
||||
sinon.assert.calledWith(Commands.invokeCommand, 'track');
|
||||
|
||||
var args = Commands.invokeCommand.firstCall.args[1];
|
||||
assert.equal(args[0], 7);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
3
gaia/apps/findmydevice/test/unit/setup.js
Executable file
3
gaia/apps/findmydevice/test/unit/setup.js
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
Loading…
Reference in a new issue