From 3988afe5fc73c8d9c8da864d870e8396f2c2be50 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 1 Aug 2017 16:34:18 -0400 Subject: [PATCH 1/6] GPII-3120: Modified PlatformReporter to use context awareness Cherry-picked from bbd5037c: GPII-1939: Device Reporter includes screen resolution information - modified the Platform Reporter to be context aware. - modified the Platform Reporter to allow OS contexts to report additional specific information, e.g., screen resolutions. --- .../deviceReporter/src/DeviceReporter.js | 48 +++++++-- .../test/PlatformReporterTests.js | 99 +++++++++++++++++++ .../deviceReporter/test/all-tests.js | 27 +++++ tests/all-tests.js | 3 +- 4 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 gpii/node_modules/deviceReporter/test/PlatformReporterTests.js create mode 100644 gpii/node_modules/deviceReporter/test/all-tests.js diff --git a/gpii/node_modules/deviceReporter/src/DeviceReporter.js b/gpii/node_modules/deviceReporter/src/DeviceReporter.js index a6213ecc9..ff8c8a6ad 100644 --- a/gpii/node_modules/deviceReporter/src/DeviceReporter.js +++ b/gpii/node_modules/deviceReporter/src/DeviceReporter.js @@ -40,7 +40,7 @@ fluid.defaults("gpii.deviceReporter.base", { }, components: { platformReporter: { - type: "gpii.platformReporter.native" + type: "gpii.platformReporter" }, nameResolver: { type: "gpii.deviceReporter.nameResolver" @@ -162,21 +162,55 @@ gpii.deviceReporter.filterByInstalledSolutions = function (entries, deviceReport return installedSolutions; }; -fluid.defaults("gpii.platformReporter.native", { - gradeNames: ["fluid.component"], +fluid.defaults("gpii.platformReporter", { + gradeNames: ["fluid.component", "fluid.contextAware"], + contextAwareness: { + platform: { + checks: { + linux: { + contextValue: "{gpii.contexts.linux}", + gradeNames: "gpii.platformReporter.linux" + }, + windows: { + contextValue: "{gpii.contexts.windows}", + gradeNames: "gpii.platformReporter.windows" + } + } + } + }, invokers: { + getBasicOS: "gpii.platformReporter.getBasicOS", reportPlatform: { - funcName: "gpii.platformReporter.native.reportPlatform" - } + funcName: "gpii.platformReporter.reportAll", + args: ["{that}", "{that}.reportOSinfo"] + }, + reportOSinfo: "fluid.identity" } }); -gpii.platformReporter["native"].reportPlatform = function () { // "native" is a reserved word +/** + * Returns the OS name and its version. + * + * @return (Object) An object consisting of "id" and "version" properties. + */ +gpii.platformReporter.getBasicOS = function () { return { - // TODO: need to report more details - windowmanager, etc. id: os.platform(), // TODO: Need a better strategy - Node semver fails horribly // in the face of the benign underscore (eg. x86_64). version: os.release().replace("_", "-") }; }; + +/** + * Returns platform information such as OS, OS version, screen resolution + * and so on. + * + * @param that (Component) A platform reporter instance. + * @param reportOSinfo {Function} The context specific function to call to + * cquire OS specific platform information. + */ +gpii.platformReporter.reportAll = function (that, reportOSinfo) { + var allInfo = that.getBasicOS(); + return Object.assign(allInfo, reportOSinfo()); +}; diff --git a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js new file mode 100644 index 000000000..48985095f --- /dev/null +++ b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js @@ -0,0 +1,99 @@ +/* + * GPII Web-based PlatformReporter unit tests/ + * + * Copyright 2017 Inclusive Design Research Centre, OCAD University + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. You may obtain a copy of the License at + * https://github.com/gpii/universal/LICENSE.txt + */ + +/* global require */ + +"use strict"; + +var fluid = require("infusion"), + jqUnit = fluid.require("node-jqunit"); + +require("../index.js"); + +var gpii = fluid.registerNamespace("gpii"); +fluid.registerNamespace("gpii.tests.platformReporter"); + +fluid.defaults("gpii.tests.platformReporter", { + gradeNames: ["gpii.platformReporter", "gpii.contexts.test"], + invokers: { + reportOSinfo: "gpii.tests.platformReporter.reportOSinfo" + } +}); + +// Mock OS info, e.g., screen resolutions. +gpii.tests.platformReporter.OSinfo = fluid.freezeRecursive({ + "screen-resolution": { width: 640, height: 480 }, + "available-resolutions": [ + { width: 640, height: 480 }, + { width: 1440, height: 900 }, + { width: 1680, height: 1050 } + ] +}); + +/** + * Return a mock of screen resolutions. + * + * @return {Object} Current and available screen resolutions. + */ +gpii.tests.platformReporter.reportOSinfo = function () { + return gpii.tests.platformReporter.OSinfo; +}; + +var platformReporter = gpii.tests.platformReporter(); + +jqUnit.module("Platform Reporter"); +jqUnit.test( + "Test getBasicOS()", + function () { + var basicOS = platformReporter.getBasicOS(); + jqUnit.assertDeepEq( + "Basic OS informaiton", 2, Object.keys(basicOS).length + ); + jqUnit.assertNotNull("ID property", basicOS.id); + jqUnit.assertNotNull("Version property", basicOS.version); + } +); +jqUnit.test( + "Test reportOSinfo()", + function () { + var OSinfo = platformReporter.reportOSinfo(); + jqUnit.assertDeepEq( + "Platform OS informaiton", + gpii.tests.platformReporter.OSinfo, + OSinfo + ); + } +); +jqUnit.test( + "Test reportPlatform()", + function () { + var platform = platformReporter.reportPlatform(); + jqUnit.assertEquals( + "OS ID", + platformReporter.getBasicOS().id, + platform.id + ); + jqUnit.assertEquals( + "OS Version", + platformReporter.getBasicOS().version, + platform.version + ); + jqUnit.assertDeepEq( + "Screen resolution", + gpii.tests.platformReporter.OSinfo["screen-resolution"], + platform["screen-resolution"] + ); + jqUnit.assertDeepEq( + "Available resolutions", + gpii.tests.platformReporter.OSinfo["available-resolutions"], + platform["available-resolutions"] + ); + } +); diff --git a/gpii/node_modules/deviceReporter/test/all-tests.js b/gpii/node_modules/deviceReporter/test/all-tests.js new file mode 100644 index 000000000..77ab0c5b0 --- /dev/null +++ b/gpii/node_modules/deviceReporter/test/all-tests.js @@ -0,0 +1,27 @@ +/** + * GPII Device Reporter Tests + * + * Copyright 2017 Inclusive Design Research Centre, OCAD University + * + * Licensed under the New BSD license. You may not use this file except in + * compliance with this License. + * + * You may obtain a copy of the License at + * https://github.com/gpii/universal/LICENSE.txt + */ +"use strict"; + +var fluid = require("infusion"), + kettle = fluid.require("kettle"); + +kettle.loadTestingSupport(); + +var testIncludes = [ + "./PlatformReporterTests.js" +]; + +var tests = []; + +fluid.each(testIncludes, function (path) { + tests = tests.concat(fluid.require(path, require)); +}); diff --git a/tests/all-tests.js b/tests/all-tests.js index 365302463..19dd00b56 100644 --- a/tests/all-tests.js +++ b/tests/all-tests.js @@ -79,7 +79,8 @@ var testIncludes = [ "../gpii/node_modules/settingsHandlers/test/WebSocketsSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/settingsHandlerUtilitiesTests.js", "../gpii/node_modules/singleInstance/test/SingleInstanceTests.js", - "../gpii/node_modules/userListeners/test/all-tests.js" + "../gpii/node_modules/userListeners/test/all-tests.js", + "../gpii/node_modules/deviceReporter/test/all-tests.js" ]; fluid.each(testIncludes, function (path) { From 7cded49ffb274b006523d9a4fb1469ccc2cc067e Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Wed, 2 Aug 2017 09:36:04 -0400 Subject: [PATCH 2/6] GPII-3120: Modified PlatformReporter to use context awareness Cherry-picked from 80264424: GPII-1939: Device Reporter reports additional OS specific information Renmaed the function for getting the OS specific information and fixed spelling. --- .../deviceReporter/src/DeviceReporter.js | 12 ++++++------ .../deviceReporter/test/PlatformReporterTests.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gpii/node_modules/deviceReporter/src/DeviceReporter.js b/gpii/node_modules/deviceReporter/src/DeviceReporter.js index ff8c8a6ad..fb681bbcd 100644 --- a/gpii/node_modules/deviceReporter/src/DeviceReporter.js +++ b/gpii/node_modules/deviceReporter/src/DeviceReporter.js @@ -182,9 +182,9 @@ fluid.defaults("gpii.platformReporter", { getBasicOS: "gpii.platformReporter.getBasicOS", reportPlatform: { funcName: "gpii.platformReporter.reportAll", - args: ["{that}", "{that}.reportOSinfo"] + args: ["{that}", "{that}.getOSspecifics"] }, - reportOSinfo: "fluid.identity" + getOSspecifics: "fluid.identity" } }); @@ -207,10 +207,10 @@ gpii.platformReporter.getBasicOS = function () { * and so on. * * @param that (Component) A platform reporter instance. - * @param reportOSinfo {Function} The context specific function to call to - * cquire OS specific platform information. + * @param getOSspecifics {Function} The context specific function to call to + * acquire OS specific platform information. */ -gpii.platformReporter.reportAll = function (that, reportOSinfo) { +gpii.platformReporter.reportAll = function (that, getOSspecifics) { var allInfo = that.getBasicOS(); - return Object.assign(allInfo, reportOSinfo()); + return Object.assign(allInfo, getOSspecifics()); }; diff --git a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js index 48985095f..ffa5dfb1c 100644 --- a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js +++ b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js @@ -23,7 +23,7 @@ fluid.registerNamespace("gpii.tests.platformReporter"); fluid.defaults("gpii.tests.platformReporter", { gradeNames: ["gpii.platformReporter", "gpii.contexts.test"], invokers: { - reportOSinfo: "gpii.tests.platformReporter.reportOSinfo" + getOSspecifics: "gpii.tests.platformReporter.getOSspecifics" } }); @@ -42,7 +42,7 @@ gpii.tests.platformReporter.OSinfo = fluid.freezeRecursive({ * * @return {Object} Current and available screen resolutions. */ -gpii.tests.platformReporter.reportOSinfo = function () { +gpii.tests.platformReporter.getOSspecifics = function () { return gpii.tests.platformReporter.OSinfo; }; @@ -61,9 +61,9 @@ jqUnit.test( } ); jqUnit.test( - "Test reportOSinfo()", + "Test getOSspecifics()", function () { - var OSinfo = platformReporter.reportOSinfo(); + var OSinfo = platformReporter.getOSspecifics(); jqUnit.assertDeepEq( "Platform OS informaiton", gpii.tests.platformReporter.OSinfo, From 1a48f21fb1d7d168595a239b16a60632e78832ca Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 21 Aug 2017 14:15:19 -0400 Subject: [PATCH 3/6] GPII-3120: Added context awareness to the PlatformReporter Cherry picked from 569642d: GPII-1939: Fixed lint error. From a0b539bc61011f107bf2c26ba5ac60f4789860e8 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 11 Sep 2017 10:10:19 -0400 Subject: [PATCH 4/6] GPII-3120: Using context awareness to implement the PlatformReporter Cherry picked from fcdec05: GPII-1939: Simplified context aware features Also, merged upstream GPII master branch into GPII-1939. --- .../deviceReporter/src/DeviceReporter.js | 15 ++++++------ .../test/PlatformReporterTests.js | 24 +++++++------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/gpii/node_modules/deviceReporter/src/DeviceReporter.js b/gpii/node_modules/deviceReporter/src/DeviceReporter.js index fb681bbcd..4014cd852 100644 --- a/gpii/node_modules/deviceReporter/src/DeviceReporter.js +++ b/gpii/node_modules/deviceReporter/src/DeviceReporter.js @@ -179,12 +179,11 @@ fluid.defaults("gpii.platformReporter", { } }, invokers: { - getBasicOS: "gpii.platformReporter.getBasicOS", reportPlatform: { funcName: "gpii.platformReporter.reportAll", - args: ["{that}", "{that}.getOSspecifics"] + args: ["{that}"] }, - getOSspecifics: "fluid.identity" + getBasicOS: "gpii.platformReporter.getBasicOS" } }); @@ -207,10 +206,10 @@ gpii.platformReporter.getBasicOS = function () { * and so on. * * @param that (Component) A platform reporter instance. - * @param getOSspecifics {Function} The context specific function to call to - * acquire OS specific platform information. + * @return (Object) An object that has properties describing platform + * features/capabilities; at least basic information such ss + * the version of the OS. */ -gpii.platformReporter.reportAll = function (that, getOSspecifics) { - var allInfo = that.getBasicOS(); - return Object.assign(allInfo, getOSspecifics()); +gpii.platformReporter.reportAll = function (that) { + return that.getBasicOS(); }; diff --git a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js index ffa5dfb1c..6e526815c 100644 --- a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js +++ b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js @@ -23,7 +23,10 @@ fluid.registerNamespace("gpii.tests.platformReporter"); fluid.defaults("gpii.tests.platformReporter", { gradeNames: ["gpii.platformReporter", "gpii.contexts.test"], invokers: { - getOSspecifics: "gpii.tests.platformReporter.getOSspecifics" + reportPlatform: { + funcName: "gpii.tests.platformReporter.reportAll", + args: ["{that}"] + } } }); @@ -40,10 +43,12 @@ gpii.tests.platformReporter.OSinfo = fluid.freezeRecursive({ /** * Return a mock of screen resolutions. * - * @return {Object} Current and available screen resolutions. + * @param that (Component) A platform reporter instance. + * @return {Object} Basic OS + current and available screen resolutions. */ -gpii.tests.platformReporter.getOSspecifics = function () { - return gpii.tests.platformReporter.OSinfo; +gpii.tests.platformReporter.reportAll = function (that) { + var allInfo = that.getBasicOS(); + return Object.assign(allInfo, gpii.tests.platformReporter.OSinfo); }; var platformReporter = gpii.tests.platformReporter(); @@ -60,17 +65,6 @@ jqUnit.test( jqUnit.assertNotNull("Version property", basicOS.version); } ); -jqUnit.test( - "Test getOSspecifics()", - function () { - var OSinfo = platformReporter.getOSspecifics(); - jqUnit.assertDeepEq( - "Platform OS informaiton", - gpii.tests.platformReporter.OSinfo, - OSinfo - ); - } -); jqUnit.test( "Test reportPlatform()", function () { From ce686e54990b657e42995a8a809a06deda60d461 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Mon, 18 Jun 2018 12:47:04 -0400 Subject: [PATCH 5/6] GPII-3120: Implement the PlatformReporter using context awareness. Fixed js-doc comments. --- gpii/node_modules/deviceReporter/src/DeviceReporter.js | 6 +++--- .../deviceReporter/test/PlatformReporterTests.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gpii/node_modules/deviceReporter/src/DeviceReporter.js b/gpii/node_modules/deviceReporter/src/DeviceReporter.js index 4014cd852..443898690 100644 --- a/gpii/node_modules/deviceReporter/src/DeviceReporter.js +++ b/gpii/node_modules/deviceReporter/src/DeviceReporter.js @@ -190,7 +190,7 @@ fluid.defaults("gpii.platformReporter", { /** * Returns the OS name and its version. * - * @return (Object) An object consisting of "id" and "version" properties. + * @return (Object) - An object consisting of "id" and "version" properties. */ gpii.platformReporter.getBasicOS = function () { return { @@ -205,8 +205,8 @@ gpii.platformReporter.getBasicOS = function () { * Returns platform information such as OS, OS version, screen resolution * and so on. * - * @param that (Component) A platform reporter instance. - * @return (Object) An object that has properties describing platform + * @param (Component) that - A platform reporter instance. + * @return (Object) - An object that has properties describing platform * features/capabilities; at least basic information such ss * the version of the OS. */ diff --git a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js index 6e526815c..d08c97f56 100644 --- a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js +++ b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js @@ -43,8 +43,8 @@ gpii.tests.platformReporter.OSinfo = fluid.freezeRecursive({ /** * Return a mock of screen resolutions. * - * @param that (Component) A platform reporter instance. - * @return {Object} Basic OS + current and available screen resolutions. + * @param (Component) that - A platform reporter instance. + * @return {Object} - Basic OS + current and available screen resolutions. */ gpii.tests.platformReporter.reportAll = function (that) { var allInfo = that.getBasicOS(); From e94b7c79bc1e7be92b82002206a4368ec5e1f587 Mon Sep 17 00:00:00 2001 From: Joseph Scheuhammer Date: Tue, 2 Jul 2019 10:25:23 -0400 Subject: [PATCH 6/6] GPII-3120: Fixed JSDoc comments --- gpii/node_modules/deviceReporter/src/DeviceReporter.js | 6 +++--- .../deviceReporter/test/PlatformReporterTests.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gpii/node_modules/deviceReporter/src/DeviceReporter.js b/gpii/node_modules/deviceReporter/src/DeviceReporter.js index 3814be172..e366e532e 100644 --- a/gpii/node_modules/deviceReporter/src/DeviceReporter.js +++ b/gpii/node_modules/deviceReporter/src/DeviceReporter.js @@ -177,7 +177,7 @@ fluid.defaults("gpii.platformReporter", { /** * Returns the OS name and its version. * - * @return (Object) - An object consisting of "id" and "version" properties. + * @return {Object} - An object consisting of "id" and "version" properties. */ gpii.platformReporter.getBasicOS = function () { return { @@ -192,8 +192,8 @@ gpii.platformReporter.getBasicOS = function () { * Returns platform information such as OS, OS version, screen resolution * and so on. * - * @param (Component) that - A platform reporter instance. - * @return (Object) - An object that has properties describing platform + * @param {Component} that - A platform reporter instance. + * @return {Object} - An object that has properties describing platform * features/capabilities; at least basic information such ss * the version of the OS. */ diff --git a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js index d08c97f56..e8095ed69 100644 --- a/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js +++ b/gpii/node_modules/deviceReporter/test/PlatformReporterTests.js @@ -43,7 +43,7 @@ gpii.tests.platformReporter.OSinfo = fluid.freezeRecursive({ /** * Return a mock of screen resolutions. * - * @param (Component) that - A platform reporter instance. + * @param {Component} that - A platform reporter instance. * @return {Object} - Basic OS + current and available screen resolutions. */ gpii.tests.platformReporter.reportAll = function (that) {