UNPKG

gpii-windows

Version:

Components of the GPII personalization infrastructure for use on Microsoft's "Windows" ™

200 lines (152 loc) 7.38 kB
/*! Windows SystemParametersInfo Settings Handler Copyright 2012 Antranig Basman Copyright 2012 Astea Solutions AD 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 */ "use strict"; var fluid = require("gpii-universal"), jqUnit = fluid.require("node-jqunit"), gpii = fluid.registerNamespace("gpii"), $ = fluid.registerNamespace("jQuery"), path = require("path"), os = require("os"); require("../src/SpiSettingsHandler.js"); jqUnit.module("SpiSettingsHandler Module"); var testPayloads = ["testMouseTrails", "testFilterKeys", "testMouse", "testMouseClickLock", "testLogFont", // Commented out for GPII-2001 - test now stall extremely often // "testNonClientMetrics", "testStickyKeys", "testHighContrast", "testHighContrastToEmpty", "testMouseKeys", "testToggleKeys", "testUnderlineShortcuts", "testAudioDescription", "testNotificationDuration"]; fluid.each(testPayloads, function (name) { jqUnit.asyncTest("SpiSettingsHandler test - " + name, function () { var payload = require(__dirname + "/" + name); var expectedSettings = payload.settings; var expectedCount = 1 + fluid.keys(expectedSettings).length; jqUnit.expect(expectedCount); var oldSettings = gpii.windows.spi.getImpl(payload); return gpii.windows.spi.setImpl(payload) .then(function (newSettings) { for (var currentSetting in expectedSettings) { var expected = expectedSettings[currentSetting]; jqUnit.assertDeepEq("Assert " + name + ": " + currentSetting, expected, newSettings[currentSetting].newValue); payload.settings[currentSetting].value = oldSettings[currentSetting].value; } gpii.windows.spi.setImpl(payload).then(function () { jqUnit.assertDeepEq(name + " restored", oldSettings, gpii.windows.spi.getImpl(payload)); jqUnit.start(); }); }, function (reason) { jqUnit.fail(reason && reason.message); jqUnit.start(); }); }); }); jqUnit.asyncTest("SpiSettingsHandler API test - ", function () { var testData = require(__dirname + "/testAPI.json"); jqUnit.expect(2); var oldSettings = gpii.resolveSync(gpii.windows.spiSettingsHandler.get(testData.set.payload)); // Set the initial settings to a known state var work = []; fluid.each(testData.init, function (initPayload) { work.push(function () { return gpii.windows.spi.setImpl(initPayload); }); }); fluid.promise.sequence(work) .then(function () { // Test get functionality: var result = gpii.windows.spiSettingsHandler.get(testData.get.payload); jqUnit.assertDeepEq("Checking that GET returns the correct payload", testData.get.expectedResult, gpii.resolveSync(result)); // Test set functionality: gpii.windows.spiSettingsHandler.set(testData.set.payload) .then(function (result2) { jqUnit.assertDeepEq("Checking that SET returns the correct payload", testData.set.expectedResult, result2); // Restore original settings gpii.windows.spiSettingsHandler.set($.extend(true, {}, testData.set.payload, oldSettings)); jqUnit.start(); }); }); }); var highContrastThemes = [ { file: "%SystemRoot%\\resources\\Ease of Access Themes\\hc1.theme", expect: "High Contrast #1" }, { file: "%SystemRoot%\\resources\\Ease of Access Themes\\hc2.theme", expect: "High Contrast #2" }, { file: "%SystemRoot%\\resources\\Ease of Access Themes\\hcwhite.theme", expect: "High Contrast White" }, { file: "%SystemRoot%\\resources\\Ease of Access Themes\\hcblack.theme", expect: "High Contrast Black" }, { file: __dirname + "/test1.theme", expect: "hard coded display name" }, { file: __dirname + "/test2.theme", expect: undefined } ]; jqUnit.test("Testing setHighContrastTheme", function () { // See what the setHighContrastTheme returns. fluid.each(highContrastThemes, function (test) { var file = test.file.replace("%SystemRoot%", process.env.SystemRoot); var result = gpii.windows.spiSettingsHandler.setHighContrastTheme(file, null, null, true); jqUnit.assertEquals("setHighContrastTheme must return the expected result, file=" + file, test.expect, result); }); }); jqUnit.test("Testing saveTheme", function () { var currentTheme = "C:\\Windows\\Resources\\Themes\\aero.theme"; var tempTheme = path.join(os.tmpdir(), "gpii-test.theme"); var desktopRestore = {}; var desktopTest = { Wallpaper: "test value for Wallpaper", TileWallpaper: "test value for TileWallpaper", WallpaperStyle: "test value for WallpaperStyle" }; var preContrastRestore = gpii.windows.readRegistryKey( "HKEY_CURRENT_USER", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\HighContrast", "Pre-High Contrast Scheme", "REG_SZ").value; try { // Set the settings that the saveTheme() saves. fluid.each(desktopTest, function (value, key) { // Save the value, for restoration. desktopRestore[key] = gpii.windows.readRegistryKey("HKEY_CURRENT_USER", "Control Panel\\Desktop", key, "REG_SZ").value; // Set it to something different. gpii.windows.writeRegistryKey("HKEY_CURRENT_USER", "Control Panel\\Desktop", key, value, "REG_SZ"); }); gpii.windows.spiSettingsHandler.saveTheme(currentTheme, tempTheme); // Check the settings have been stored to the file var themeData = gpii.iniFile.readFile(tempTheme); var desktop = themeData["Control Panel\\Desktop"]; jqUnit.assertTrue(".theme file should contain the desktop section", !!desktop); fluid.each(desktopTest, function (value, key) { jqUnit.assertEquals("The " + key + " setting must be what was written", value, desktop[key]); }); var preContrast = gpii.windows.readRegistryKey( "HKEY_CURRENT_USER", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\HighContrast", "Pre-High Contrast Scheme", "REG_SZ").value; jqUnit.assertEquals("'Pre-High Contrast Scheme' should be set to the new file", tempTheme, preContrast); } finally { // Restore the registry gpii.windows.writeRegistryKey( "HKEY_CURRENT_USER", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\HighContrast", "Pre-High Contrast Scheme", preContrastRestore, "REG_SZ"); fluid.each(desktopRestore, function (value, key) { gpii.windows.writeRegistryKey("HKEY_CURRENT_USER", "Control Panel\\Desktop", key, value, "REG_SZ"); }); } });