gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
1,106 lines (1,039 loc) • 68.5 kB
JavaScript
/*!
GPII Lifecycle Manager Tests
Copyright 2012 OCAD University
Copyright 2012, 2017 Raising The Floor - International
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
The research leading to these results has received funding from the European Union's
Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016.
You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
/* eslint-env browser */
/* eslint strict: ["error", "function"] */
/* global jqUnit, fluid */
(function () {
"use strict";
fluid.setLogging(true);
var gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.tests.lifecycleManager");
gpii.tests.lifecycleManager.fakeEnvironment = {
JAWS_DIR: "e:\\Programs and Things\\Jaws\\",
WINDIR: "c:\\Windows\\"
};
fluid.defaults("gpii.tests.lifecycleManager.resolverConfig", {
gradeNames: ["fluid.component"],
resolvers: {
environment: "gpii.tests.lifecycleManager.environmentResolver"
}
});
gpii.tests.lifecycleManager.environmentResolver = function (name) {
return gpii.tests.lifecycleManager.fakeEnvironment[name];
};
/*
* ensure everything is clean and ready for the tests
*/
gpii.tests.lifecycleManager.setup = function () {
gpii.tests.lifecycleManager.staticRepository.execHandler = undefined;
// To keep track of the number of times that the mock settingsHandler's set() is called
gpii.tests.lifecycleManager.NumOfSettingsHandlerSetCalls = 0;
};
/*
* Create a solution entry keyed by solution ID.
* All subsequent arguments will be part of the solution entry
*/
gpii.tests.lifecycleManager.buildLifecycleInstructions = function (solId) {
var togo = {};
for (var i = 1; i < arguments.length; ++i) {
togo[solId] = fluid.extend(true, {}, togo[solId], arguments[i]);
}
return togo;
};
/**
* Used by a bunch of the tests to avoid having to write out the almost-identical full set of lifecycle
* instructions for each test. Instead one can have a "base set" of lifecycle instructions
* that can be shared across multiple tests/multiple phases of a single test, and then use
* this function to extend base set to match the specific test/test phase.
*
* The function takes an unlimited number of arguments. The first argument is mandatory and must
* be a set of lifecycle instructions entries keyed by solution ids. While the system wont explode
* if entries for multiple solutions are provided, only the "first" solution entry will be
* extended. The remaining arguments will be fluid.extended onto the first argument.
*
* @param {Object} currentInstructions - A set of lifecycle instructions keyed by a solution id. For example,
* this could be the output of the buildLifecycleInstructions function.
* @param {Object} arguments - The remaining arguments should be valid lifecycleInstructions that will
* be extended onto the original.
* @return {Object} The original lifecycle instructions, but with the remaining arguments fluid.extend'ed
* onto the first solution entry in the currentInstructions.
*/
gpii.tests.lifecycleManager.extendLifecycleInstructions = function (currentInstructions) {
if (Object.keys(currentInstructions).length < 1) {
jqUnit.assertTrue("Instructions passed to extendLifecycleInstructions didn't contain an entry as expected", false);
}
var togo = fluid.copy(currentInstructions);
var solId = Object.keys(currentInstructions)[0];
for (var i = 1; i < arguments.length; ++i) {
togo[solId] = fluid.extend(true, {}, togo[solId], arguments[i]);
}
return togo;
};
gpii.tests.lifecycleManager.buildSettingsHandlersEntry = function (settings, setRunning, removeLifecycleHandlerBlock) {
var togo = {
"settingsHandlers": {
"myconf": {
"type": "gpii.tests.lifecycleManager.mockSettingsHandler",
"options": {}
}
},
"launchHandlers": {
"launcher": {
"type": "gpii.tests.lifecycleManager.mockLaunchHandler",
"options": {}
}
}
};
if (settings !== undefined) {
fluid.set(togo, [ "settingsHandlers", "myconf", "settings" ], settings);
} else {
delete togo.settingsHandlers;
}
if (setRunning !== undefined) {
fluid.set(togo, [ "launchHandlers", "launcher", "settings" ], { running: setRunning });
}
if (removeLifecycleHandlerBlock) {
delete togo.launchHandlers;
}
return togo;
};
gpii.tests.lifecycleManager.noUpdateLifecycle = {
"active": true,
"configure": [
"settings.myconf"
],
"restore": [
"settings.myconf"
],
"start": [
{
"type": "gpii.tests.lifecycleManager.mockExecHandler",
"name": "exec",
"command": "${{environment}.JAWS_DIR}jaws.exe",
args: ["-settingsDirectory", "${{environment}.WINDIR}"]
}
],
"stop": [
{
"type": "gpii.tests.lifecycleManager.mockKillHandler",
pid: "${{exec}.pid}"
}
]
};
gpii.tests.lifecycleManager.standardLifecycle = {
"active": true,
"configure": [
"settings.myconf"
],
"restore": [
"settings.myconf"
],
"start": [
"launchers.launcher"
],
"stop": [
"launchers.launcher"
],
"isRunning": [
"launchers.launcher"
]
};
gpii.tests.lifecycleManager.configurationSpec = gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true, "cross-hairs-color": "red" }),
gpii.tests.lifecycleManager.noUpdateLifecycle,
{ "update": [ "settings.myconf" ] });
gpii.tests.lifecycleManager.specToSettingsHandlerTests = {
"Basic test for response and conversion": {
request: {
"type": "gpii.gsettings.set",
"settings": {
"cross-hairs-clip": true,
"cross-hairs-color": "red"
},
"options": {}
},
response: [{
"settings": {
"cross-hairs-clip": true,
"cross-hairs-color": "red"
},
"options": {}
}]
}
};
gpii.tests.lifecycleManager.responseToSnapshotRequestNoSettings = {
"org.gnome.desktop.interface": [{
"settings": {}
}]
};
gpii.tests.lifecycleManager.responseToSnapshotRequest = {
"org.gnome.desktop.a11y.magnifier": [{
"settings": {
"cross-hairs-clip": {
"oldValue": false,
"newValue": true
},
"cross-hairs-color": {
"oldValue": "red",
"newValue": "red",
statusCode: 500,
statusMessage: "Internal Error"
}
}
}]
};
gpii.tests.lifecycleManager.responseToSnapshotExpectedResponse = {
"settings": {
"cross-hairs-clip": false,
"cross-hairs-color": "red"
}
};
gpii.tests.lifecycleManager.invokeSettingsHandlersRequest = {
"type": "gpii.tests.lifecycleManager.mockSettingsHandler",
"settings": {
"cross-hairs-clip": true,
"cross-hairs-color": "red"
},
"options": {}
};
gpii.tests.lifecycleManager.invokeSettingsHandlersExpectedSnapshot = {
"type": "gpii.tests.lifecycleManager.mockSettingsHandler",
"settings": {
"cross-hairs-clip": false,
"cross-hairs-color": "red"
},
"options": {}
};
gpii.tests.lifecycleManager.testOptions = {
distributeOptions: {
"resolverConfig": {
record: "gpii.tests.lifecycleManager.resolverConfig",
target: "{that resolverConfig}.type"
}
}
};
gpii.tests.lifecycleManager.userOptions = {
gpiiKey: 123
};
gpii.tests.lifecycleManager.buildStartPayload = function (lifecycleInstructions) {
return fluid.extend(true, {}, gpii.tests.lifecycleManager.userOptions, {
activeConfiguration: {
lifecycleInstructions: lifecycleInstructions
}
});
};
gpii.tests.lifecycleManager.startPayload = gpii.tests.lifecycleManager.buildStartPayload(gpii.tests.lifecycleManager.configurationSpec);
gpii.tests.lifecycleManager.sampleActiveSession = {
123: {
gpiiKey: 123
}
};
// Repository for "static" information reported by various kinds of handlers during the lifecycle
// cleared to be empty on each test start
gpii.tests.lifecycleManager.staticRepository = {};
gpii.tests.lifecycleManager.mockExecHandler = function (command, args) {
gpii.tests.lifecycleManager.staticRepository.execHandler = {
command: command,
args: args
};
return {
pid: 8839
};
};
fluid.defaults("gpii.tests.lifecycleManager.mockExecHandler", {
gradeNames: "fluid.function",
argumentMap: {
command: 0,
args: 1
// Forfar: 4, Fife: 5
}
});
gpii.tests.lifecycleManager.mockKillHandler = function (pid) {
gpii.tests.lifecycleManager.staticRepository.killHandler = {
pid: pid
};
};
fluid.defaults("gpii.tests.lifecycleManager.mockKillHandler", {
gradeNames: "fluid.function",
argumentMap: {
pid: 0
}
});
gpii.tests.lifecycleManager.backingMockSettingsHandler = null; // initialised in every test that requires it
gpii.tests.lifecycleManager.initBackingMock = function (origSettings, setRunning) {
gpii.tests.lifecycleManager.backingMockSettingsHandler = gpii.test.integration.mockSettingsHandler({
optionsPathKey: function (options, solutionId) {
return "settings|" + solutionId;
}
});
gpii.tests.lifecycleManager.backingMockLaunchHandler = gpii.test.integration.mockSettingsHandler({
optionsPathKey: function (options, solutionId) {
return "launch|" + solutionId;
}
});
var settings = origSettings === undefined ? // use default if no parameter is given
gpii.tests.lifecycleManager.settingsHandlerOriginalSystemSettings :
origSettings;
setRunning = (setRunning === undefined) ? false : setRunning; // default to false
var launchSettings = gpii.tests.lifecycleManager.launchHandlerOriginalSystemSettingsRunning(setRunning);
// initialise the mock with the initial settings expected at the end of the test
gpii.tests.lifecycleManager.backingMockSettingsHandler.set(settings);
gpii.tests.lifecycleManager.backingMockLaunchHandler.set(launchSettings);
// and ensure our 'local' storage is reset
gpii.tests.lifecycleManager.staticRepository.settingsHandler = undefined;
gpii.tests.lifecycleManager.staticRepository.launchHandler = undefined;
gpii.tests.lifecycleManager.staticRepository.launchHandlerCalls = 0;
};
gpii.tests.lifecycleManager.mockSettingsHandler = {
set: function (data) {
gpii.tests.lifecycleManager.NumOfSettingsHandlerSetCalls++;
var togo = fluid.promise();
gpii.invokeLater(function () {
gpii.tests.lifecycleManager.staticRepository.settingsHandler = data;
var response = gpii.resolveSync(gpii.tests.lifecycleManager.backingMockSettingsHandler.set(data));
togo.resolve(response);
}, 100);
return togo;
},
get: function (data) {
return gpii.resolveSync(gpii.tests.lifecycleManager.backingMockSettingsHandler.get(data));
}
};
gpii.tests.lifecycleManager.mockLaunchHandler = {
set: function (data) {
var togo = fluid.promise();
gpii.invokeLater(function () {
gpii.tests.lifecycleManager.staticRepository.launchHandlerCalls++;
gpii.tests.lifecycleManager.staticRepository.launchHandler = data;
var response = gpii.resolveSync(gpii.tests.lifecycleManager.backingMockLaunchHandler.set(data));
togo.resolve(response);
}, 100);
return togo;
},
get: function (data) {
return gpii.resolveSync(gpii.tests.lifecycleManager.backingMockLaunchHandler.get(data));
}
};
gpii.tests.lifecycleManager.createSettingsHandlerPayload = function (solutionId, settings) {
if (settings === undefined) {
return undefined;
} else {
var togo = {};
togo[solutionId] = [
{
options: {},
settings: settings
}
];
return togo;
}
};
gpii.tests.lifecycleManager.settingsHandlerOriginalSystemSettings = {
"org.gnome.desktop.a11y.magnifier": [{
"settings": {
"cross-hairs-clip": false,
"cross-hairs-color": "red",
"iamasetting": 200,
"undefSetting": undefined
},
"options": {
// "storePath": "settingsBlock1"
}
}],
"other.application": [{
"settings": {
"mysetting": "Hello World"
},
"options": {
// "storePath": "settingsBlock1"
}
}]
};
gpii.tests.lifecycleManager.launchHandlerOriginalSystemSettingsRunning = function (setRunning) {
return {
"org.gnome.desktop.a11y.magnifier": [{
"settings": {
"running": setRunning
}
}]
};
};
gpii.tests.lifecycleManager.settingsHandlerExpectedInputNewSettings = {
"org.gnome.desktop.a11y.magnifier": [{
"settings": {
"cross-hairs-clip": true,
"cross-hairs-color": "red"
},
"options": {}
}]
};
gpii.tests.lifecycleManager.settingsHandlerExpectedInputRestoreSettings = {
"org.gnome.desktop.a11y.magnifier": [{
"settings": {
"cross-hairs-clip": false,
"cross-hairs-color": "red"
},
"options": {}
}]
};
gpii.tests.lifecycleManager.startTestDefs = [{
name: "Solution with all lifecycle blocks",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: true,
expectedLaunchHandlerCalls: 2
}, {
name: "Solution with no explicit configure and restore (GPII-2106)",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": true,
"start": [
"launchers.launcher"
],
"stop": [
"launchers.launcher"
],
"isRunning": [
"launchers.launcher"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: true,
expectedLaunchHandlerCalls: 2
}, {
name: "Solution with no configure and restore and no settingsHandler block",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": true,
"start": [
"launchers.launcher"
],
"stop": [
"launchers.launcher"
],
"isRunning": [
"launchers.launcher"
]
}
),
originalSettings: undefined,
runningOnLogin: false,
appliedSettings: undefined,
runningAfterLogin: true,
expectedLaunchHandlerCalls: 2
}, {
name: "no explicit start, stop, isRunning directives",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": true,
"configure": [
"settings.myconf"
],
"restore": [
"settings.myconf"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: true,
expectedLaunchHandlerCalls: 2
}, {
name: "no explicit start, stop, isRunning directives and no launchHandlers block", // expect no launch handler calls
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": true,
"configure": [
"settings.myconf"
],
"restore": [
"settings.myconf"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: undefined,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: undefined,
expectedLaunchHandlerCalls: 0,
removeLifecycleHandlerBlock: true
}, {
name: "no explicit lifecycle directives (i.e. start,stop,configure,restore,isRunning)",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": true
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: true,
expectedLaunchHandlerCalls: 2
}, {
name: "solution with active: false", // no launch handler calls
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "active": false }
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: undefined,
expectedLaunchHandlerCalls: 0
}, {
name: "solution with active: undefined", // expect no launch handler calls
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": undefined,
"configure": [
"settings.myconf"
],
"restore": [
"settings.myconf"
],
"start": [
"launchers.launcher"
],
"stop": [
"launchers.launcher"
],
"isRunning": [
"launchers.launcher"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: undefined,
expectedLaunchHandlerCalls: 0
}, {
name: "running on login - 'update' with reference to settings handler block",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{
"update": [
"settings.myconf"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: true,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: undefined,
expectedLaunchHandlerCalls: 0
}, {
name: "running on login - 'update' with reference to 'configure' block",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{
"update": [
"configure"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: true,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: undefined,
expectedLaunchHandlerCalls: 0
}, {
name: "running on login - 'update' with reference to 'stop', 'configure' and 'start' blocks",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{
"update": [
"stop",
"configure",
"start"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: true,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: true,
expectedLaunchHandlerCalls: 4 // we run start/stop cycle both on login and logout
}, {
name: "running on login - with active: false",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{
"active": false
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: true,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: false,
expectedLaunchHandlerCalls: 2
}, {
name: "running on login - with active: undefined",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
{
"active": undefined,
"configure": [
"settings.myconf"
],
"restore": [
"settings.myconf"
],
"start": [
"launchers.launcher"
],
"stop": [
"launchers.launcher"
],
"isRunning": [
"launchers.launcher"
],
"update": [
"stop",
"configure",
"start"
]
}
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: true,
appliedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterLogin: true,
expectedLaunchHandlerCalls: 4 // we run start/stop cycle both on login and logout
}];
gpii.tests.lifecycleManager.updateTestDefs = [{
name: "Updating with the same prefs and values as already applied with the application not running at the login - the prefs should NOT be re-applied",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "settings.myconf" ] }
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
expectedSettingsHandlerSetCalls: 1,
expectedLaunchHandlerCalls: 2
}, {
name: "single pref changed without 'update' directive in solution registry entry",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" }, // don't expect these to apply
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
expectedSettingsHandlerSetCalls: 1,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with normal reference to settingsHandler block, single settings",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "settings.myconf" ] }
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with normal reference to settingsHandler block, multiple settings",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "settings.myconf" ] }
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": false, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with reference to 'configure' directive, single settings",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with normal reference to settingsHandler block, and a setting not in the original settings applied to the system",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "settings.myconf" ] }
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-color": "green", "iamasetting": 100 },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green", "iamasetting": 100 },
originalSettingsAfterUpdate: { "cross-hairs-clip": false, "cross-hairs-color": "red", "iamasetting": undefined },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with no 'update' block in solutions registry entry and 'live' liveness",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
payloadExtras: {
settingsHandlers: {
myconf: {
liveness: "live"
}
}
},
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with no 'update' block in solutions registry entry and no liveness",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
expectedSettingsHandlerSetCalls: 1,
expectedLaunchHandlerCalls: 2
}, {
name: "Updating with no 'update' block in solutions registry entry and 'liveRestart' liveness",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
payloadExtras: {
settingsHandlers: {
myconf: {
liveness: "liveRestart"
}
}
},
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 4
}, {
name: "Updating with no 'update' block in solutions registry entry and 'manualRestart' liveness",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
payloadExtras: {
settingsHandlers: {
myconf: {
liveness: "manualRestart"
}
}
},
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 4
}, {
name: "Updating with no 'update' block in solutions registry entry and 'OSRestart' liveness",
basePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle
),
payloadExtras: {
settingsHandlers: {
myconf: {
liveness: "OSRestart"
}
}
},
originalSettings: { "cross-hairs-clip": false, "cross-hairs-color": "red" },
runningOnLogin: false,
loginSettings: { "cross-hairs-clip": true, "cross-hairs-color": "red" },
runningAfterLogin: true,
updateSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
runningAfterUpdate: true,
expectedSettings: { "cross-hairs-clip": true, "cross-hairs-color": "green" },
expectedSettingsHandlerSetCalls: 2,
expectedLaunchHandlerCalls: 4
}];
gpii.tests.lifecycleManager.completeLifecycleTests = [{
name: "Updating with normal reference to settingsHandler block, and an application not in the original settings applied to the system",
expect: 10,
expectedLaunchHandlerCalls: 2,
expectedSettingsHandlerSetCalls: 2,
runningOnLogin: false,
originalSettings: {
"org.gnome.desktop.a11y.magnifier": [{ options: {}, settings: { "cross-hairs-clip": false, "cross-hairs-color": "red" }}]
},
loginPayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] },
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true, "cross-hairs-color": "red" })),
expectedOriginal: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] },
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": false, "cross-hairs-color": "red" }, false)),
expectedAfterLogin: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] },
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true, "cross-hairs-color": "red" }, true)),
runningAfterLogin: true,
updatePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions("other.application",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "mysetting": "Hallow World" }),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }),
expectedAfterUpdate: fluid.extend(true, {},
gpii.tests.lifecycleManager.buildLifecycleInstructions("org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true, "cross-hairs-color": "red" }, true),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }),
gpii.tests.lifecycleManager.buildLifecycleInstructions("other.application",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "mysetting": "Hallow World" }),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] })),
expectedOriginalSettingsAfterUpdate: gpii.tests.lifecycleManager.buildLifecycleInstructions("org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": false, "cross-hairs-color": "red" }, false),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }),
originalSettingsAfterUpdate: {
"other.application": [{
"options": {},
"settings": {
"mysetting": undefined
}
}]
},
runningAfterUpdate: true
}, {
name: "Updating with normal reference to settingsHandler block, and 'undefined' value stored in snapshot",
expect: 10,
expectedLaunchHandlerCalls: 2,
expectedSettingsHandlerSetCalls: 2,
runningOnLogin: false,
originalSettings: {
"org.gnome.desktop.a11y.magnifier": [{ options: {}, settings: { "cross-hairs-clip": false, "cross-hairs-color": "red" }}]
},
loginPayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] },
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true })),
expectedOriginal: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] },
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": false }, false)),
expectedAfterLogin: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] },
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true }, true)),
runningAfterLogin: true,
updatePayload: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "undefSetting": "some other value" }),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }),
expectedAfterUpdate: gpii.tests.lifecycleManager.buildLifecycleInstructions(
"org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": true, "undefSetting": "some other value" }, true),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }),
expectedOriginalSettingsAfterUpdate: gpii.tests.lifecycleManager.buildLifecycleInstructions("org.gnome.desktop.a11y.magnifier",
gpii.tests.lifecycleManager.buildSettingsHandlersEntry({ "cross-hairs-clip": false, "undefSetting": undefined }, false),
gpii.tests.lifecycleManager.standardLifecycle,
{ "update": [ "configure" ] }),
originalSettingsAfterUpdate: gpii.tests.lifecycleManager.createSettingsHandlerPayload("org.gnome.desktop.a11y.magnifier", { "cross-hairs-clip": false, "undefSetting": undefined }),
runningAfterUpdate: true
}];
gpii.tests.lifecycleManager.checkFinalSettingsPayload = function (msg, expSettings, store) {
var expectedLastSettings;
if (expSettings === undefined) {
expectedLastSettings = expSettings;
} else {
// change to the format that is stoed by the mock settingshandler:
expectedLastSettings = {
"org.gnome.desktop.a11y.magnifier": [
{
"options": {},
"settings": expSettings
}
]
};
}
jqUnit.assertDeepEq(msg, expectedLastSettings, store);
};
/*
* expects an input with the following:
* name: name of the test
* expect: number of tests to expect
* expectedLaunchHandlerCalls: number of luanch handler calls to expect (incl. logout)
* expectedSettingsHandlerSetCalls: number of setting handler calls on set() to expect (incl. logout)
* originalSettings: the original settings to apply to the system (ie. before login)
* runningOnLogin: boolean - if the magnifier should be running before login
* loginPayload: payload to send to the start() function
* expectedOriginal: the expected "originalSettings" of the session after login
* expectedAfterLogin: the expected "currentSettings" of the session after login
* runningAfterLogin: boolean - if the magnifier should be running after login
* --- The below keys are optional and will trigger an update cycle if present. ---
* updatePayload: payload to send to the update() function
* expectedAfterUpdate: the expected "currentSettings" of the session after update call
* expectedOriginalSettingsAfterUpdate: the original after a call to update() has been done,
* originalSettingsAfterUpdate: the settings that the system should reset to (ie. last call to settingsHandler)
* runningAfterUpdate: boolean - if the magnifier should be running after update
*/
gpii.tests.lifecycleManager.runSequentialLifecycleTest = function (testDef) {
var originalRunSetting = testDef.expectedLaunchHandlerCalls === 0 ? undefined : testDef.runningOnLogin;
jqUnit.asyncTest("Sequential " + testDef.name, function () {
gpii.tests.lifecycleManager.setup();
jqUnit.expect(testDef.expect);
var lifecycleManager = gpii.lifecycleManager(gpii.tests.lifecycleManager.testOptions);
gpii.tests.lifecycleManager.initBackingMock(testDef.originalSettings, testDef.runningOnLogin);
lifecycleManager.start(gpii.tests.lifecycleManager.buildStartPayload(testDef.loginPayload)).then(function (success) {
jqUnit.assertTrue("gpii.lifecycleManager.start() succeeds", success);
var session = lifecycleManager.getSession(123); // always just use the default GPII key
jqUnit.assertDeepEq("Checking currentSettings after start", testDef.expectedAfterLogin, session.model.currentSettings);
var originalSettings = session.model.originalSettings;
jqUnit.assertDeepEq("Checking originalSettings after start", gpii.lifecycleManager.transformAllSolutionSettings(testDef.expectedOriginal, gpii.settingsHandlers.settingsToChanges), originalSettings);
var stopCycle = function () {
lifecycleManager.stop(gpii.tests.lifecycleManager.userOptions).then(function () {
jqUnit.assertDeepEq("Session not running after stop", lifecycleManager.getSession(123));
jqUnit.assertEquals("Number of calls to launch handler", testDef.expectedLaunchHandlerCalls, gpii.tests.lifecycleManager.staticRepository.launchHandlerCalls);
// Check that last calls to launch and settings handlers were actually the ones resetting to expected state
jqUnit.assertDeepEq("checking last payload sent to settingshandler:", testDef.originalSettingsAfterUpdate || testDef.originalSettings, gpii.tests.lifecycleManager.staticRepository.settingsHandler);
// Check that last calls to launch and settings handlers were actually the ones resetting to expected state
gpii.tests.lifecycleManager.checkFinalSettingsPayload("checking last set launch settings", (originalRunSetting === undefined) ? undefined : { running: originalRunSetting }, gpii.tests.lifecycleManager.staticRepository.launchHandler);
jqUnit.start();
});
};
if (testDef.updatePayload) {
lifecycleManager.update(gpii.tests.lifecycleManager.buildStartPayload(testDef.updatePayload)).then(function () {
jqUnit.assertDeepEq("Checking currentSettings after update", testDef.expectedAfterUpdate, session.model.currentSettings);
jqUnit.assertEquals("Checking the number of times that set() is called", testDef.expectedSettingsHandlerSetCalls, gpii.tests.lifecycleManager.NumOfSettingsHandlerSetCalls);
var expected = gpii.lifecycleManager.transformAllSolutionSettings(testDef.expectedOriginalSettingsAfterUpdate, gpii.settingsHandlers.settingsToChanges);
jqUnit.assertDeepEq("Checking originalSettings after update", expected, originalSettings);
});
stopCycle();
} else {
stopCycle();
}
});
});
};
/*
* expects an input with the following:
* name: name of the test
* expect: number of tests to expect
* expectedLaunchHandlerCalls: number of luanch handler calls to expect (incl. logout)
* originalSettings: the original settings to apply to the system (ie. before login)
* runningOnLogin: boolean - if the magnifier should be running before login
* loginPayload: payload to send to the start() function
* expectedOriginal: the expected "originalSettings" of the session after login
* expectedAfterLogin: the expected "currentSettings" of the session after login
* runningAfterLogin: boolean - if the magnifier should be running after login
* --- The below keys are optional and will trigger an update cycle if present. ---
* updatePayload: payload to send to the update() function
* expectedAfterUpdate: the expected "currentSettings" of the session after update call
* expectedOriginalSettingsAfterUpdate: the original after a call to update() has been done,
* originalSettingsAfterUpdate: the settings that the system should reset to (ie. last call to settingsHandler)
* runningAfterUpdate: boolean - if the magnifier should be running after update
*/
gpii.tests.lifecycleManager.runAsyncLifecycleTest = function (testDef) {
var originalRunSetting = testDef.expectedLaunchHandlerCalls === 0 ? undefined : testDef.runningOnLogin;
jqUnit.asyncTest("Async " + testDef.name, function () {
gpii.tests.lifecycleManager.setup();
jqUnit.expect(testDef.expect);
var lifecycleManager = gpii.lifecycleManager(gpii.tests.lifecycleManager.testOptions);
gpii.tests.lifecycleManager.initBackingMock(testDef.originalSettings, testDef.runningOnLogin);
var session,
originalSettings;
lifecycleManager.start(gpii.tests.lifecycleManager.buildStartPayload(testDef.loginPayload)).then(function (success) {
session = lifecycleManager.getSession(123); // always just use the default GPII key
jqUnit.assertTrue("gpii.lifecycleManager.start() succeeds", success);
jqUnit.assertDeepEq("Checking currentSettings after start", testDef.expectedAfterLogin, session.model.currentSettings);
originalSettings = session.model.originalSettings;
jqUnit.assertDeepEq("Checking originalSettings after start", gpii.lifecycleManager.transformAllSolutionSettings(testDef.expectedOriginal, gpii.settingsHandlers.settingsToChanges), originalSettings);
});
if (testDef.updatePayload) {
lifecycleManager.update(gpii.tests.lifecycleManager.buildStartPayload(testDef.updatePayload)).then(function () {
jqUnit.assertDeepEq("Checking currentSettings after update", testDef.expectedAfterUpdate, session.model.currentSettings);
var expected = gpii.lifecycleManager.transformAllSolutionSettings(testDef.expectedOriginalSettingsAfterUpdate, gpii.settingsHandlers.settingsToChanges);
j