| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 |
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
4×
3×
1×
1×
1×
1×
1×
1×
1×
1×
2×
1×
1×
1×
1×
2×
2×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
3×
1×
1×
2×
2×
2×
2×
2×
1×
1×
| /*
* Built-in AT Unit 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
*/
"use strict";
var fluid = require("universal");
var jqUnit = fluid.require("node-jqunit");
var gpii = fluid.registerNamespace("gpii");
var shelljs = require("shelljs");
var path = require("path");
require("../registeredAT.js");
require("../../processHandling/processHandling.js");
fluid.registerNamespace("gpii.tests.windows.registeredAT");
var teardowns = [];
jqUnit.module("gpii.tests.windows.registeredAT", {
teardown: function () {
while (teardowns.length) {
teardowns.pop()();
}
}
});
gpii.tests.windows.registeredAT.atInfoTest = {
input: {
appName: "magnifierpane",
values: ["ATExe", "StartExe", "Description"]
},
expectedResult: {
"ATExe": "Magnify.exe",
"StartExe": "%SystemRoot%\\System32\\Magnify.exe",
"Description": "Screen Magnifier"
}
};
gpii.tests.windows.registeredAT.atEnableTest = {
input: {
appName: "gpii-atEnableTest-" + Math.random(),
regRoot: "HKEY_CURRENT_USER",
regPath: "Software\\Microsoft\\Windows NT\\CurrentVersion\\AccessibilityTemp"
},
expectedResults: {
enable: 3,
disable: 2
}
};
gpii.tests.windows.registeredAT.atStartStopTest = {
testData: {
appName: "gpii-atStartStopTest-" + Math.random(),
ATExe: "gpii-registered-at-test.exe",
StartExe: path.join(process.env.TEMP, "gpii-registered-at-test.exe"),
StartParams: "atTest /T 10 > nul"
}
};
gpii.tests.windows.registeredAT.atPendingTest = {
input: {
appName: "gpii-atPendingTest-" + Math.random(),
regRoot: "HKEY_CURRENT_USER",
regPath: "Software\\Microsoft\\Windows NT\\CurrentVersion\\AccessibilityTemp",
enable: 3,
disable: 2
}
};
jqUnit.asyncTest("Testing enableRegisteredAT", function () {
jqUnit.expect(2);
var testData = gpii.tests.windows.registeredAT.atEnableTest;
var removeValue = function () {
// Remove the temporary value
gpii.windows.writeRegistryKey(testData.input.regRoot, testData.input.regPath, testData.input.appName,
undefined, "REG_DWORD");
};
teardowns.push(removeValue);
removeValue();
var options = {
configOnly: true,
utilman: "echo hello"
};
var testAction = function (input, expected) {
return function () {
return gpii.windows.enableRegisteredAT(testData.input.appName, input, options).then(function () {
var result = gpii.windows.readRegistryKey(testData.input.regRoot, testData.input.regPath,
testData.input.appName, "REG_DWORD");
jqUnit.assertEquals("Checking registry for action value", expected, result.value);
});
};
};
fluid.promise.sequence([
testAction(true, testData.expectedResults.enable),
testAction(false, testData.expectedResults.disable),
function () {
jqUnit.start();
}
]);
});
jqUnit.test("Testing getATInformation", function () {
var testData = gpii.tests.windows.registeredAT.atInfoTest;
var at = gpii.windows.getATInformation(testData.input.appName, testData.input.values);
jqUnit.assertDeepEq("Checking result of getATInformation", testData.expectedResult, at);
});
jqUnit.asyncTest("Testing AT start and stop", function () {
jqUnit.expect(3);
var testData = gpii.tests.windows.registeredAT.atStartStopTest.testData;
// Take a copy of the built-in "waitfor" command, to ensure a unique process name.
shelljs.cp(path.join(process.env.SystemRoot, "/System32/waitfor.exe"), testData.StartExe);
// Remove it at the end
teardowns.push(function () {
gpii.windows.killProcessByName(testData.ATExe);
gpii.windows.waitForProcessTermination(testData.ATExe).then(function () {
shelljs.rm(testData.StartExe);
});
});
var pid = gpii.windows.findProcessByName(testData.ATExe);
jqUnit.assertEquals("The process should not already be running.", null, pid);
gpii.windows.startRegisteredAT(testData.appName, {atInfo: testData});
// Timeout waiting for the process start/end after 5 seconds.
var waitOptions = { timeout: 5000 };
// Wait for it to start.
gpii.windows.waitForProcessStart(testData.ATExe, waitOptions)
.then(function () {
jqUnit.assert("We just started the new process.");
// Tell the process to stop now.
gpii.windows.stopRegisteredAT(testData.appName, {atInfo: testData});
// Wait for it to die
gpii.windows.waitForProcessTermination(testData.ATExe, waitOptions)
.then(function () {
jqUnit.assert("Child process terminated.");
jqUnit.start();
}, function () {
jqUnit.fail("Process should have terminated.");
});
}, function () {
jqUnit.fail("Failed to detect process start.");
});
});
jqUnit.asyncTest("Testing pending AT", function () {
jqUnit.expect(3);
var testData = gpii.tests.windows.registeredAT.atPendingTest;
// Check for no pending actions.
gpii.windows.whilePendingAT({timeout: 0})
.then(function (value) {
jqUnit.assertNotEquals("No pending AT actions found.", "timeout", value);
});
var removeValue = function () {
// Remove the temporary value
gpii.windows.writeRegistryKey(testData.input.regRoot, testData.input.regPath, testData.input.appName,
undefined, "REG_DWORD");
};
teardowns.push(removeValue);
var actionCheck = function (action) {
return function () {
gpii.windows.writeRegistryKey(testData.input.regRoot, testData.input.regPath, testData.input.appName,
action, "REG_DWORD");
return gpii.windows.whilePendingAT({timeout: 0})
.then(function (value) {
jqUnit.assertEquals("A pending AT action should be found.", "timeout", value);
removeValue();
});
};
};
fluid.promise.sequence([
actionCheck(testData.input.enable),
actionCheck(testData.input.disable),
function () {
jqUnit.start();
}
]);
});
|