diff --git a/gpii/node_modules/lifecycleActions/src/LifecycleActions.js b/gpii/node_modules/lifecycleActions/src/LifecycleActions.js index 19493fc7b..a4e7154e2 100644 --- a/gpii/node_modules/lifecycleActions/src/LifecycleActions.js +++ b/gpii/node_modules/lifecycleActions/src/LifecycleActions.js @@ -22,6 +22,7 @@ gpii = fluid.registerNamespace("gpii"); fluid.registerNamespace("gpii.launch"); + fluid.registerNamespace("gpii.lifecycleActions.utils"); fluid.defaults("gpii.launch.exec", { gradeNames: "fluid.function", @@ -44,4 +45,27 @@ gpii.launch.spawn = child_process.spawn; + fluid.defaults("gpii.launch.browser", { + gradeNames: [ "fluid.function", "fluid.littleComponent" ], + argumentMap: { + bogus: 0, + URL: 1, + parameters: 2 + } + }); + + gpii.lifecycleActions.utils.composeURL = function (URL, parameters) { + var paramString = ""; + fluid.each(parameters, function (val, name) { + if (val !== undefined) { + paramString += (paramString === "" ? "" : "&") + encodeURIComponent(name) + "=" + encodeURIComponent(val); + } + }); + return encodeURIComponent(URL) + ((paramString === "") ? "" : "?" + paramString); + }; + + gpii.launch.browser = function (bogus, URL, parameters) { + child_process.spawn("open", [gpii.launch.browser.composeURL(URL, parameters)]); + }; + })(); diff --git a/gpii/node_modules/lifecycleActions/test/LifecycleActionsTests.js b/gpii/node_modules/lifecycleActions/test/LifecycleActionsTests.js new file mode 100644 index 000000000..3774508a2 --- /dev/null +++ b/gpii/node_modules/lifecycleActions/test/LifecycleActionsTests.js @@ -0,0 +1,94 @@ +/* + * Lifecycle Actions Tests + * + * Copyright 2015 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 + */ + +/*global require, __dirname */ + +(function () { + + "use strict"; + + var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"), + jqUnit = fluid.require("jqUnit"), + kettle = require("kettle"); + + fluid.registerNamespace("gpii.tests.lifecycleActions"); + + kettle.loadTestingSupport(); + + require("lifecycleActions"); + + var composeURLTestSpec = [ + { + desc: "Simple URL, no parameters", + URL: "myURL.html", + parameters: {}, + expected: "myURL.html" + }, { + desc: "Simple URL, undefined parameters", + URL: "myURL.html", + parameters: undefined, + expected: "myURL.html" + }, { + desc: "Simple URL, multiple parameters", + URL: "myURL.html", + parameters: { + foo: "bar", + boo: "har" + }, + expected: "myURL.html?foo=bar&boo=har" + }, { + desc: "URL and parameters require URL encoding", + URL: "myURL,number2.html", + parameters: { + "crazy param": "I am a string, that needs URL encoding%$" + }, + expected: "myURL%2Cnumber2.html?crazy%20param=I%20am%20a%20string%2C%20that%20needs%20URL%20encoding%25%24" + } + ]; + + + gpii.tests.lifecycleActions.composeURL = function () { + fluid.each(composeURLTestSpec, function (spec) { + var response = gpii.lifecycleActions.utils.composeURL(spec.URL, spec.parameters); + jqUnit.assertEquals("gpii.launch.browser.composeURL - " + spec.desc, spec.expected, response); + }); + }; + + fluid.defaults("gpii.tests.lifecycleActions.environment", { + gradeNames: ["fluid.test.testEnvironment", "autoInit"], + components: { + tester: { + type: "gpii.tests.lifecycleActions.holder" + } + } + }); + + fluid.defaults("gpii.tests.lifecycleActions.holder", { + gradeNames: ["fluid.test.testCaseHolder", "autoInit"], + modules: [{ + name: "gpii.launch.browser.composeURL", + tests: [{ + expect: composeURLTestSpec.length, + name: "gpii.launch.browser.composeURL tests", + func: "gpii.tests.lifecycleActions.composeURL" + }] + }] + }); + + module.exports = kettle.test.bootstrap("gpii.tests.lifecycleActions.environment"); + +}()); \ No newline at end of file diff --git a/gpii/node_modules/lifecycleManager/src/LifecycleManager.js b/gpii/node_modules/lifecycleManager/src/LifecycleManager.js index 665e21369..27a51c5e9 100644 --- a/gpii/node_modules/lifecycleManager/src/LifecycleManager.js +++ b/gpii/node_modules/lifecycleManager/src/LifecycleManager.js @@ -77,6 +77,10 @@ var gpii = fluid.registerNamespace("gpii"); funcName: "gpii.lifecycleManager.invokeSettingsHandlers", args: ["{that}", "{arguments}.0", "{arguments}.1"] // solutionId, settingsHandlers + }, + settingsResolver: { + funcName: "gpii.lifecycleManager.settingsResolver", + args: [ "{that}", "{arguments}.0" ] } } }); @@ -151,11 +155,26 @@ var gpii = fluid.registerNamespace("gpii"); }; }; - gpii.combineFetchers = function (main, fallback) { - return fallback ? function (parsed) { - var fetched = main(parsed); - return fetched === undefined ? fallback(parsed) : fetched; - } : main; + gpii.combineFetchers = function () { + // this slightly akward start of the function due to: + // http://stackoverflow.com/questions/6396046/unlimited-arguments-in-a-javascript-function + var args = []; + for (var i = 0; i < arguments.length; ++i) { + args[i] = arguments[i]; + } + // use first matched fetcher + return function (parsed) { + for (var i = 0; i < args.length; ++i) { + if (typeof args[i] !== "function") { + fluid.log("WARNING: fetcher is not a function so ignoring: " + args[i]); + continue; + } + var fetched = args[i](parsed); + if (fetched !== undefined) { + return fetched; + } + } + }; }; fluid.defaults("gpii.lifecycleManager.standardResolverConfig", { @@ -390,6 +409,21 @@ var gpii = fluid.registerNamespace("gpii"); return sequence; }; + gpii.lifecycleManager.buildSettingsResolver = function (lifecycleInstructions) { + // build settings resolvers: + var settingsResolver = {}; + fluid.each(lifecycleInstructions, function (content, id) { + if (!content.settingsHandlers || !content.settingsHandlers[0]) { + //ignore entries without settings handlers + return; + } + fluid.each(content.settingsHandlers[0].settings, function (val, name) { + settingsResolver["settings." + id + "." + name] = val; + }); + }); + return settingsResolver; + }; + gpii.lifecycleManager.start = function (that, requestProxy, finalPayload, callback) { var userToken = finalPayload.userToken, lifecycleInstructions = finalPayload.lifecycleInstructions; @@ -404,10 +438,12 @@ var gpii = fluid.registerNamespace("gpii"); actionResults: {} }, fluid.filterKeys(finalPayload, ["userToken", "activeConfiguration", "solutionsRegistryEntries", "matchMakerOutput"])); + var settingsResolver = gpii.lifecycleManager.buildSettingsResolver(lifecycleInstructions); // let the user's token as well as any named action results accumulated // to date be resolvable for any future action sessionState.localFetcher = gpii.combineFetchers( gpii.resolversToFetcher({userToken: userToken}), + gpii.resolversToFetcher(settingsResolver), gpii.resolversToFetcher(sessionState.actionResults)); sessionState.localResolver = function (material) { diff --git a/gpii/node_modules/lifecycleManager/test/js/LifecycleManagerTests.js b/gpii/node_modules/lifecycleManager/test/js/LifecycleManagerTests.js index fcd17639a..4adf31795 100644 --- a/gpii/node_modules/lifecycleManager/test/js/LifecycleManagerTests.js +++ b/gpii/node_modules/lifecycleManager/test/js/LifecycleManagerTests.js @@ -25,6 +25,38 @@ var fluid = fluid || require("infusion"); fluid.registerNamespace("gpii.tests.lifecycleManager"); + // fetcher related tests: + gpii.tests.lifecycleManager.combineFetchersSpec = { + functions: [ + function (val) { return val == "fun1" ? "foo1" : undefined }, + "I am not a function", + function (val) { return val == "fun2" ? "foo2" : undefined } + ], + tests: { + "First match": { + input: "fun1", + expected: "foo1" + }, + "Last match": { + input: "fun2", + expected: "foo2" + }, + "No match": { + input: "foo", + expected: undefined + } + } + }; + + gpii.tests.lifecycleManager.combineFetchers = function () { + var fetchers = gpii.combineFetchers.apply(undefined, gpii.tests.lifecycleManager.combineFetchersSpec.functions); + fluid.each(gpii.tests.lifecycleManager.combineFetchersSpec.tests, function (spec, desc) { + var response = fetchers(spec.input); + jqUnit.assertEquals(desc, spec.expected, response); + }); + } + + gpii.tests.lifecycleManager.fakeEnvironment = { JAWS_DIR: "e:\\Programs and Things\\Jaws\\", WINDIR: "c:\\Windows\\" @@ -444,6 +476,7 @@ var fluid = fluid || require("infusion"); } }); + jqUnit.test("Testing gpii.combineFetchers", gpii.tests.lifecycleManager.combineFetchers); gpii.tests.lifecycleManager.buildUpdateTests(); }; }(jQuery)); diff --git a/testData/deviceReporter/installedSolutions.json b/testData/deviceReporter/installedSolutions.json index 74fce21b4..e2e3d3d88 100644 --- a/testData/deviceReporter/installedSolutions.json +++ b/testData/deviceReporter/installedSolutions.json @@ -68,11 +68,7 @@ }, { - "id": "webinsight.webAnywhere.windows" - }, - - { - "id": "webinsight.webAnywhere.linux" + "id": "webinsight.webAnywhere" }, { diff --git a/testData/deviceReporter/linux_installedSolutions.json b/testData/deviceReporter/linux_installedSolutions.json index a4cf463f3..5eb5d10f1 100644 --- a/testData/deviceReporter/linux_installedSolutions.json +++ b/testData/deviceReporter/linux_installedSolutions.json @@ -73,11 +73,7 @@ }, { - "id": "webinsight.webAnywhere.windows" - }, - - { - "id": "webinsight.webAnywhere.linux" + "id": "webinsight.webAnywhere" } ] } diff --git a/testData/deviceReporter/win32_installedSolutions.json b/testData/deviceReporter/win32_installedSolutions.json index 2efbd4d9d..2c748c14c 100644 --- a/testData/deviceReporter/win32_installedSolutions.json +++ b/testData/deviceReporter/win32_installedSolutions.json @@ -61,11 +61,7 @@ }, { - "id": "webinsight.webAnywhere.windows" - }, - - { - "id": "webinsight.webAnywhere.linux" + "id": "webinsight.webAnywhere" }, { diff --git a/testData/preferences/webanywhere.json b/testData/preferences/webanywhere.json new file mode 100644 index 000000000..942f5fe31 --- /dev/null +++ b/testData/preferences/webanywhere.json @@ -0,0 +1,16 @@ +{ + "flat": { + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/applications/webinsight.webAnywhere": { + "locale": "en", + "voicepitch": 12, + "voicespeed": 400 + } + } + } + } + } +} \ No newline at end of file diff --git a/testData/preferences/webanywhere_common.json b/testData/preferences/webanywhere_common.json new file mode 100644 index 000000000..7746984a9 --- /dev/null +++ b/testData/preferences/webanywhere_common.json @@ -0,0 +1,14 @@ +{ + "flat": { + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/language": "es", + "http://registry.gpii.net/common/pitch": 0.4, + "http://registry.gpii.net/common/speechRate": 160 + } + } + } + } +} \ No newline at end of file diff --git a/testData/solutions/linux.json b/testData/solutions/linux.json index f456ff5ea..32864b289 100644 --- a/testData/solutions/linux.json +++ b/testData/solutions/linux.json @@ -1270,7 +1270,7 @@ } }, - "webinsight.webAnywhere.linux": { + "webinsight.webAnywhere": { "name": "Web Anywhere", "contexts": { "OS": [ @@ -1285,26 +1285,34 @@ "type": "gpii.settingsHandlers.noSettings", "capabilities": [ "display.screenReader", - "applications.webinsight\\.webAnywhere\\.linux.id", - "display.screenReader.applications.webinsight\\.webAnywhere\\.linux.name" - ] + "applications.webinsight\\.webAnywhere.id" + ], + "capabilitiesTransformations": { + "locale": "http://registry\\.gpii\\.net/common/language", + "voicepitch": "http://registry\\.gpii\\.net/common/pitch", + "voicespeed": "http://registry\\.gpii\\.net/common/speechRate" + } } ], "lifecycleManager" : { - "start": [ + "start": [ { - "type": "gpii.launch.exec", - "command": "google-chrome http://webanywhere.cs.washington.edu/beta/?starting_url=http%3A%2F%2Fcloud4all.info" + "type": "gpii.launch.browser", + "URL": "http://webanywhere.cs.washington.edu/beta/", + "parameters": { + "locale": "${{settings.webinsight.webAnywhere.locale}}", + "voicepitch": "${{settings.webinsight.webAnywhere.voicepitch}}", + "voicespeed": "${{settings.webinsight.webAnywhere.voicespeed}}" + + + } } ], "stop": [ - { - "type": "gpii.launch.exec", - "command": "pkill -2 chrome" - } ] } }, + "org.freedesktop.xrandr": { "name": "Xrandr", "contexts": { diff --git a/testData/solutions/win32.json b/testData/solutions/win32.json index 708ff9910..746a2f36d 100644 --- a/testData/solutions/win32.json +++ b/testData/solutions/win32.json @@ -700,7 +700,7 @@ } }, - "webinsight.webAnywhere.windows": { + "webinsight.webAnywhere": { "name": "Web Anywhere", "contexts": { "OS": [ @@ -715,23 +715,30 @@ "type": "gpii.settingsHandlers.noSettings", "capabilities": [ "display.screenReader", - "applications.webinsight\\.webAnywhere\\.windows.id", - "display.screenReader.applications.webinsight\\.webAnywhere\\.windows.name" - ] + "applications.webinsight\\.webAnywhere.id" + ], + "capabilitiesTransformations": { + "locale": "http://registry\\.gpii\\.net/common/language", + "voicepitch": "http://registry\\.gpii\\.net/common/pitch", + "voicespeed": "http://registry\\.gpii\\.net/common/speechRate" + } } ], "lifecycleManager" : { "start": [ { - "type": "gpii.launch.exec", - "command": "\"${{registry}.HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe\\}\" \"http://webanywhere.cs.washington.edu/beta/?starting_url=http%3A%2F%2Fcloud4all.info\"" + "type": "gpii.launch.browser", + "URL": "http://webanywhere.cs.washington.edu/beta/", + "parameters": { + "locale": "${{settings.webinsight.webAnywhere.locale}}", + "voicepitch": "${{settings.webinsight.webAnywhere.voicepitch}}", + "voicespeed": "${{settings.webinsight.webAnywhere.voicespeed}}" + + + } } ], "stop": [ - { - "type": "gpii.launch.exec", - "command": "${{environment}.SystemRoot}\\System32\\taskkill.exe /im firefox.exe" - } ] } }, diff --git a/tests/all-tests.js b/tests/all-tests.js index 19da955e6..786647a44 100644 --- a/tests/all-tests.js +++ b/tests/all-tests.js @@ -47,6 +47,7 @@ var testIncludes = [ "../gpii/node_modules/settingsHandlers/test/JSONSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/XMLSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/INISettingsHandlerTests.js", + "../gpii/node_modules/lifecycleActions/test/lifecycleActionsTests.js", "../gpii/node_modules/preferencesServer/test/preferencesServerTests.js", "../gpii/node_modules/rawPreferencesServer/test/RawPreferencesTest.js", "../gpii/node_modules/ontologyHandler/test/node/OntologyHandlerTests.js",