UNPKG

gpii-windows

Version:

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

357 lines (339 loc) 9.71 kB
/* * Tests for Sendkeys * * Copyright 2019 Raising the Floor - International * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * * The R&D leading to these results received funding from the * Department of Education - Grant H421A150005 (GPII-APCP). However, * these results do not necessarily represent the policy of the * Department of Education, and you should not assume endorsement by the * Federal Government. * * 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"); var jqUnit = fluid.require("node-jqunit"); var gpii = fluid.registerNamespace("gpii"); require("../src/sendKeys.js"); fluid.registerNamespace("gpii.tests.windows.sendKeys"); // These tests assume the '!' character is typed using shift + 1. This is the case for most western language layouts. gpii.tests.windows.sendKeys.getKeysTests = fluid.freezeRecursive({ // plain character "a": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: {} }, // plain character in braces "{a}": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: {} }, // character requiring shift key "A": { keyName: "A", virtualKey: "A".charCodeAt(0), args: [], modifiers: { 0x10: true // VK_SHIFT } }, // number "1": { keyName: "1", virtualKey: "1".charCodeAt(0), args: [], modifiers: {} }, // character requiring shift key "{!}": { keyName: "!", virtualKey: "1".charCodeAt(0), args: [], modifiers: { 0x10: true // VK_SHIFT } }, // space (literal) " ": { keyName: " ", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_SPACE, args: [], modifiers: {} }, // space (named) "{SPACE}": { keyName: "SPACE", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_SPACE, args: [], modifiers: {} }, // special key "{F5}": { keyName: "F5", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_F5, args: [], modifiers: {} }, // special key, checking case sensitivity "{HomE}": { keyName: "HOME", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_HOME, args: [], modifiers: {} }, // key with modifier "^c": { keyName: "c", virtualKey: "C".charCodeAt(0), args: [], modifiers: { 0x11: true // VK_CONTROL } }, // upper-case key with modifier (should be the same as the lowercase) "^C": { keyName: "c", virtualKey: "C".charCodeAt(0), args: [], modifiers: { 0x11: true // VK_CONTROL } }, // shift "+a": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: { 0x10: true // VK_SHIFT } }, // alt "!a": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: { 0x12: true // VK_MENU } }, // windows key "#a": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: { 0x5B: true // VK_LWIN } }, // several modifiers "+^a": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: { 0x10: true, // VK_SHIFT 0x11: true // VK_CONTROL } }, // all modifiers "+^!#a": { keyName: "a", virtualKey: "A".charCodeAt(0), args: [], modifiers: { 0x10: true, // VK_SHIFT 0x11: true, // VK_CONTROL 0x12: true, // VK_MENU 0x5B: true // VK_LWIN } }, // modifiers with special key "^!{Left}": { keyName: "LEFT", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_LEFT, args: [], modifiers: { 0x11: true, // VK_CONTROL 0x12: true // VK_MENU } }, // modifiers with character requiring modifier "^{!}": { keyName: "!", virtualKey: "1".charCodeAt(0), args: [], modifiers: { 0x10: true, // VK_SHIFT 0x11: true // VK_CONTROL } }, // modifiers with character requiring modifier already given "+{!}": { keyName: "!", virtualKey: "1".charCodeAt(0), args: [], modifiers: { 0x10: true // VK_SHIFT } }, // modifiers with character requiring modifier already given, and one extra "^+{!}": { keyName: "!", virtualKey: "1".charCodeAt(0), args: [], modifiers: { 0x10: true, // VK_SHIFT 0x11: true // VK_CONTROL } }, // modifiers for the same modifier key "^{Control}": { keyName: "CONTROL", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_CONTROL, args: [], modifiers: { 0x11: true // VK_CONTROL } }, // invalid key name "{unknown-key}": { keyName: "UNKNOWN-KEY", args: [], modifiers: {} }, // unicode "{U+1F4A9}": { keyName: "U+1F4A9", unicode: 0x1F4A9, args: [], modifiers: {} }, // unicode literal "\u2665": { keyName: "\u2665", unicode: 0x2665, args: [], modifiers: {} }, // key down "{shift down}": { keyName: "SHIFT", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_SHIFT, state: "down", args: [ "down" ], modifiers: {} }, // key up "{g UP}": { keyName: "g", virtualKey: "G".charCodeAt(0), state: "up", args: [ "UP" ], modifiers: {} }, // repetition "{F3 10}": { keyName: "F3", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_F3, count: 10, args: [ "10" ], modifiers: {} }, // repetition + state "{F4 5 down}": { keyName: "F4", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_F4, count: 5, state: "down", args: [ "5", "down" ], modifiers: {} }, // state + repetition "{F5 down 99}": { keyName: "F5", virtualKey: gpii.windows.API_constants.virtualKeyCodes.VK_F5, count: 99, state: "down", args: [ "down", "99" ], modifiers: {} }, // wait command "{wait window 10}": { keyName: "WAIT", command: gpii.windows.sendKeys.commands.wait, count: 10, args: [ "window", "10" ], modifiers: {} } }); // Tests only the resulting KeyPress.keyName field, as the actual key codes may vary with different keyboard layouts. gpii.tests.windows.sendKeys.parseTests = fluid.freezeRecursive({ "abc": [ "a", "b", "c"], "^a^b^c": [ "a", "b", "c"], "{a}b{c}": [ "a", "b", "c"], "{UP}a": [ "UP", "a"], "^{DOWN}b": [ "DOWN", "b"], "{{}": [ "{" ], "{}}": [ "}" ], "{{}{}}": [ "{", "}" ], "{}}{{}": [ "}", "{" ], "{}}{}}{{}{{}{}}{{}": [ "}" , "}" , "{" , "{" , "}" , "{" ], "{^}": [ "^" ], "^{^}": [ "^" ], "{fiXCaSe}": [ "FIXCASE" ], "{down down}": [ "DOWN" ], // parser is too forgiving "}": [ "}" ], "{": [ "{" ], "}}": [ "}", "}" ], "{{": [ "{", "{" ], "{{{}": [ "{{" ], "{a}}": [ "a", "}" ], "{{xy 5}": [ "{XY" ] }); // Tests the correct parsing of a single key. jqUnit.test("sendkeys.getKey", function () { gpii.windows.sendKeys.send("{wait 5}"); fluid.each(gpii.tests.windows.sendKeys.getKeysTests, function (key, keyText) { var result = gpii.windows.sendKeys.getKey(keyText); jqUnit.assertDeepEq("getKey(\"" + keyText + "\") should return the expected result.", key, result); }); }); // Tests the correct parsing of a sequence of keys. jqUnit.test("sendkeys.parse (using getKey tests)", function () { // Check the individual keys from the getKey test. fluid.each(gpii.tests.windows.sendKeys.getKeysTests, function (key, keyText) { var result = gpii.windows.sendKeys.parse(keyText); var expect = fluid.makeArray(key); jqUnit.assertDeepEq("parse(\"" + keyText + "\") should return the expected result.", expect, result); }); // Join them all together, and test as a single sequence. var allInput = ""; var allExpected = []; fluid.each(gpii.tests.windows.sendKeys.getKeysTests, function (key, keyText) { allInput += keyText; allExpected.push(key); }); var allResult = gpii.windows.sendKeys.parse(allInput); jqUnit.assertDeepEq("All getKey tests passed to parse() in one go should match all results joined", allExpected, allResult); }); // Tests the correct parsing of a sequence of keys. jqUnit.test("sendkeys.parse (using parse tests)", function () { // Check the individual keys from the getKey test. fluid.each(gpii.tests.windows.sendKeys.parseTests, function (expect, keySequence) { var result = gpii.windows.sendKeys.parse(keySequence); var keyNames = fluid.getMembers(result, "keyName"); jqUnit.assertDeepEq("parse(\"" + keySequence + "\") should return the expected keyNames.", expect, keyNames); }); });