| 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521 |
3x
3x
3x
3x
3x
60x
3x
3x
3x
3x
3x
3x
3x
3x
101x
3x
3x
732x
631x
101x
101x
3x
3x
969x
969x
461x
508x
92x
3x
574x
2496x
989x
1507x
3x
574x
2496x
3x
969x
30x
30x
30x
30x
939x
3x
574x
574x
574x
574x
574x
574x
574x
574x
574x
574x
574x
3x
521x
3x
395x
395x
395x
2587x
395x
395x
3x
338x
3x
92x
3x
3x
3x
695x
695x
695x
695x
3x
92x
693x
693x
3x
631x
631x
631x
3x
3x
3x
3x
3x
3x
3x
60x
3x
6x
6x
3x
97x
5x
5x
5x
5x
5x
5x
5x
5x
3x
103x
37x
66x
103x
3x
3x
| /**
GPII Mock Definitions for all platform-specific components
Copyright 2017 Raising the Floor - International
Copyright 2013 OCAD University
Copyright 2014 Lucendo Development Ltd.
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 = fluid || require("infusion"),
gpii = fluid.registerNamespace("gpii");
fluid.defaults("gpii.test.common.exec", {
gradeNames: ["fluid.component"],
events: {
onExecExit: null
},
invokers: {
// exec:
}
});
// Maintains a mock model of currently executing processes
fluid.defaults("gpii.test.integration.exec", {
gradeNames: ["gpii.test.common.exec"],
members: {
processModel: [] // list of process objects
},
invokers: {
exec: {
funcName: "gpii.test.integration.exec.exec",
args: ["{that}", "{arguments}.0", "{arguments}.1"]
}
}
});
gpii.test.integration.exec.exec = function (that, processSpec /*, expected */) {
// TODO: actually determine that the required process was started using the mock model
that.events.onExecExit.fire(true, processSpec);
};
fluid.defaults("gpii.test.integration.mockHolder", {
gradeNames: "fluid.component",
// TODO: Namespace these distributions so they can be overridden
distributeOptions: [{
record: {
funcName: null,
func: "{gpii.test.integration.mockHolder}.nameResolver.resolveName"
},
target: "{that lifecycleManager > nameResolver}.options.invokers.resolveName"
}, {
record: { // TODO: appears that this distribution has always been broken
funcName: null,
func: "{gpii.test.integration.deviceReporterAware}.resolveName"
},
target: "{that deviceReporter > nameResolver}.options.invokers.resolveName"
}, {
record: {
funcName: null,
func: "{gpii.test.integration.mockHolder}.mockPlatformReporter.reportPlatform"
},
target: "{that deviceReporter platformReporter}.options.invokers.reportPlatform"
}, {
target: "{that lifecycleManager > variableResolver}.options.components.resolverConfig.type",
record: "gpii.test.integration.standardResolverConfig"
}],
components: {
exec: {
type: "gpii.test.integration.exec"
},
mockSettingsHandlers: {
type: "gpii.test.integration.mockSettingsHandlerRegistry.universal"
},
mockDeviceReporters: {
type: "gpii.test.integration.deviceReporterAware"
},
nameResolver: {
type: "fluid.component",
options: {
invokers: {
resolveName: {
funcName: "gpii.test.integration.resolveName",
args: ["{mockSettingsHandlers}", "{mockDeviceReporters}", "{arguments}.0", "{arguments}.1"]
}
}
}
}
}
});
fluid.defaults("gpii.test.integration.standardResolverConfig", {
gradeNames: "fluid.component",
resolvers: {
environment: "gpii.test.integration.environmentResolver"
}
});
// Return the environment variable name unmodified
gpii.test.integration.environmentResolver = fluid.identity;
fluid.defaults("gpii.test.integration.mockHolder.windows", {
gradeNames: ["gpii.test.integration.mockHolder"],
components: {
mockSettingsHandlers: {
type: "gpii.test.integration.mockSettingsHandlerRegistry.windows"
},
mockPlatformReporter: {
type: "gpii.test.integration.mockPlatformReporter",
options: {
platform: {
id: "win32",
version: "6.1.7601"
}
}
}
}
});
fluid.defaults("gpii.test.integration.mockHolder.linux", {
gradeNames: ["gpii.test.integration.mockHolder"],
components: {
mockSettingsHandlers: {
type: "gpii.test.integration.mockSettingsHandlerRegistry.linux"
},
mockPlatformReporter: {
type: "gpii.test.integration.mockPlatformReporter",
options: {
platform: {
id: "linux",
version: "2.6.26"
}
}
}
}
});
fluid.defaults("gpii.test.integration.mockHolder.android", {
gradeNames: ["gpii.test.integration.mockHolder"],
components: {
mockSettingsHandlers: {
type: "gpii.test.integration.mockSettingsHandlerRegistry.android"
},
mockPlatformReporter: {
type: "gpii.test.integration.mockPlatformReporter",
options: {
platform: {
id: "android",
version: "3.0.31"
}
}
}
}
});
fluid.defaults("gpii.test.integration.mockPlatformReporter", {
gradeNames: ["fluid.component"],
invokers: {
reportPlatform: {
funcName: "fluid.identity",
args: "{that}.options.platform"
}
}
});
gpii.test.integration.mockExecHandler = function (command, args) {
// TODO: we should record the executing process in a process model - ideally we should have a more reliable model of extracting what it is
fluid.log("Mock exec handler for command ", command, " args ", args);
};
fluid.defaults("gpii.test.integration.mockExecHandler", {
gradeNames: "fluid.function",
argumentMap: {
command: 0,
args: 1
}
});
gpii.test.integration.resolveName = function (settingsHandlerRegistry, deviceReporterAware, name, category) {
if (category === "settingsHandler") {
return settingsHandlerRegistry.resolveName(name);
} else Iif (category === "deviceReporter") {
return deviceReporterAware.resolveName(name);
} else {
return "gpii.test.integration.mockExecHandler";
}
};
// cf. much less sophisticated mock in LifecycleManagerTest.js
fluid.defaults("gpii.test.integration.mockSettingsHandler", {
gradeNames: ["fluid.component"],
members: {
settingsStore: {}
},
async: false,
// must be configured for each settingsHandler instance to resolve to a path within
// the options structure which determines a unique key for the particular payload
// can also resolve to a function which returns such a key given the options
optionsPathKey: null,
invokers: {
set: {
funcName: "gpii.test.integration.mockSettingsHandler.set",
args: ["{that}", "{arguments}.0"]
},
setImpl: {
funcName: "gpii.test.integration.mockSettingsHandler.setImpl",
args: ["{that}", "{arguments}.0"]
},
get: {
funcName: "gpii.test.integration.mockSettingsHandler.get",
args: ["{that}", "{arguments}.0"]
},
getImpl: {
funcName: "gpii.test.integration.mockSettingsHandler.getImpl",
args: ["{that}", "{arguments}.0"]
}
}
});
gpii.test.integration.resolveHandlerKey = function (that, payload) {
var pathKey = that.options.optionsPathKey;
if (typeof(pathKey) === "string") {
return fluid.get(payload.options, pathKey);
} else if (typeof(pathKey) === "function") {
return pathKey(payload.options);
}
};
gpii.test.integration.mockSettingsHandler.applySettings = function (store, settings) {
fluid.each(settings, function (value, key) {
if (value === undefined) {
delete store[key];
} else {
store[key] = value;
}
});
};
gpii.test.integration.mockSettingsHandler.makeSetReturn = function (oldStore, settings) {
return fluid.transform(settings, function (value, key) {
return {
oldValue: oldStore[key],
value: value
};
});
};
gpii.test.integration.mockSettingsHandler.returnAsyncResponse = function (value, isAsync) {
if (isAsync) {
var togo = fluid.promise();
gpii.invokeLater(function () {
togo.resolve(value);
}, 100);
return togo;
} else {
return value;
}
};
gpii.test.integration.mockSettingsHandler.setImpl = function (that, payload) {
var setSettings = function () {
var key = gpii.test.integration.resolveHandlerKey(that, payload);
var oldStore = fluid.copy(that.settingsStore[key]) || {};
var store = (that.settingsStore[key] = that.settingsStore[key] || {});
var applySettings = function () {
gpii.test.integration.mockSettingsHandler.applySettings(store, payload.settings);
};
Iif (that.options.delaying && !payload.options.mockSync) {
// behave, for example, like the real SPI settings handler - claim to apply settings immediately but don't actually do it till later
gpii.invokeLater(applySettings, 5000);
} else {
applySettings();
}
return gpii.test.integration.mockSettingsHandler.makeSetReturn(oldStore, payload.settings);
};
var togo = gpii.test.integration.mockSettingsHandler.returnAsyncResponse(setSettings(), that.options.async);
return togo;
};
gpii.test.integration.mockSettingsHandler.set = function (that, payload) {
return gpii.settingsHandlers.invokeSettingsHandler(that.setImpl, payload);
};
gpii.test.integration.mockSettingsHandler.getImpl = function (that, payload) {
var key = gpii.test.integration.resolveHandlerKey(that, payload);
var store = that.settingsStore[key] || {};
var response = fluid.transform(payload.settings, function (value, key) {
return store[key];
});
var togo = gpii.test.integration.mockSettingsHandler.returnAsyncResponse(response, that.options.asyncGet);
return togo;
};
gpii.test.integration.mockSettingsHandler.get = function (that, payload) {
return gpii.settingsHandlers.invokeSettingsHandler(that.getImpl, payload);
};
// The platform-specific registry of mock settings handlers
gpii.test.integration.registrySettingsHandlerKey = function (options) {
return options.hKey + "|" + options.path;
};
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry", {
gradeNames: ["fluid.component"],
rootPath: "gpii.test.integration.mockSettingsHandlers", // the global names for mocks will be deposited in here
members: {
settingsHandlers: {}
},
invokers: {
resolveName: {
funcName: "gpii.test.integration.mockSettingsHandlerRegistry.resolveName",
args: ["{that}", "{arguments}.0"]
}
},
listeners: {
"onCreate.populate": "gpii.test.integration.mockSettingsHandlerRegistry.populate"
}
});
gpii.test.integration.mockSettingsHandlers = {};
gpii.test.integration.mockSettingsHandlerRegistry.populateOne = function (that, mock, key) {
that.settingsHandlers[key] = mock;
// Mount the mock handler at a global path
var setPath = that.options.rootPath + "." + key + ".set";
fluid.setGlobalValue(setPath, mock.set);
fluid.setGlobalValue(that.options.rootPath + "." + key + ".get", mock.get);
};
gpii.test.integration.mockSettingsHandlerRegistry.populate = function (that) {
fluid.each(that.options.settingsHandlers, function (options, key) {
var mock = gpii.test.integration.mockSettingsHandler(options);
gpii.test.integration.mockSettingsHandlerRegistry.populateOne(that, mock, key);
});
};
gpii.test.integration.mockSettingsHandlerRegistry.resolveName = function (that, name) {
var mock = that.settingsHandlers[name];
Iif (!mock) {
var registered = fluid.keys(that.settingsHandlers).join(", ");
fluid.fail("Error in settings handler mock configuration - handler " + name +
" is not registered - registered handlers are " + registered);
} else {
return that.options.rootPath + "." + name;
}
};
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.universal", {
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry"],
settingsHandlers: {
"gpii.settingsHandlers.INISettingsHandler": {
optionsPathKey: "filename"
},
"gpii.settingsHandlers.XMLHandler": {
optionsPathKey: "filename"
},
"gpii.settingsHandlers.JSONSettingsHandler": {
optionsPathKey: "filename"
},
"gpii.settingsHandlers.webSockets" : {}
}
});
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.windows", {
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry.universal"],
settingsHandlers: {
"gpii.windows.registrySettingsHandler": {
optionsPathKey: gpii.test.integration.registrySettingsHandlerKey
},
"gpii.windows.spiSettingsHandler": {
// delaying: true,
optionsPathKey: "setAction"
},
"gpii.windows.displaySettingsHandler": {}
}
});
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.linux", {
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry.universal"],
settingsHandlers: {
"gpii.gsettings": {
optionsPathKey: "schema"
},
"gpii.orca": {
async: true,
asyncGet: true,
optionsPathKey: "user"
},
"gpii.alsa": {
optionsPathKey: "NONE"
},
"gpii.xrandr": {
optionsPathKey: "NONE"
}
}
});
fluid.defaults("gpii.test.integration.mockSettingsHandlerRegistry.android", {
gradeNames: ["gpii.test.integration.mockSettingsHandlerRegistry.universal"],
settingsHandlers: {
"gpii.androidSettings": {
optionsPathKey: "settingType"
},
"gpii.androidAudioManager.volume": {
optionsPathKey: "NONE"
},
"gpii.androidPersistentConfiguration": {
optionsPathKey: "NONE"
}
}
});
fluid.defaults("gpii.test.integration.deviceReporterAware", {
gradeNames: ["fluid.component"],
rootPath: "gpii.test.integration.deviceReporterAware.mockDeviceReporters",
members: {
mockDeviceReporters: {},
deviceReporters: {}
},
invokers: {
resolveName: {
funcName: "gpii.test.integration.deviceReporterAware.resolveName",
args: ["{that}", "{arguments}.0"]
}
},
listeners: {
onCreate: "gpii.test.integration.deviceReporterAware.populate"
}
});
gpii.test.integration.deviceReporterAware.mockDeviceReporters = {};
gpii.test.integration.deviceReporterAware.mockDeviceReporters.findNameInList = function (expectInstalled, name) {
return expectInstalled.some(function (el) { return el === name; });
};
gpii.test.integration.deviceReporterAware.mockDeviceReporters.registryKeyExists = function (expectInstalled, hKey, path, subPath) {
return expectInstalled.some(function (el) {
return el.hKey === hKey && el.path === path && el.subPath === subPath;
});
};
gpii.test.integration.deviceReporterAware.populate = function (that) {
fluid.each(that.options.deviceReporters, function (options, key) {
var mock = that.options.mockDeviceReporters[key];
Iif (!mock) {
var registered = fluid.keys(that.options.mockDeviceReporters).join(", ");
fluid.fail("Error in dynamic device reporter mock configuration - handler " + key +
" is not registered - registered handlers are " + registered);
}
var expectInstalled = [];
fluid.each(that.options.deviceReporters[key].expectInstalled, function (item) {
expectInstalled.push(item);
});
fluid.defaults(that.options.rootPath + "." + key, mock.defaults);
var mockedFunction = gpii.test.integration.deviceReporterAware.mockDeviceReporters[mock.mockFunc].bind(undefined, expectInstalled);
fluid.setGlobalValue(that.options.rootPath + "." + key, mockedFunction);
});
};
gpii.test.integration.deviceReporterAware.resolveName = function (that, name) {
var resolvedName;
if (name === "gpii.deviceReporter.alwaysInstalled") {
resolvedName = name;
} else {
resolvedName = that.options.rootPath + "." + name;
}
return resolvedName;
};
fluid.defaults("gpii.test.integration.deviceReporterAware.linux", {
gradeNames: ["gpii.test.integration.deviceReporterAware"],
mockDeviceReporters: {
"gpii.packageKit.find": {
mockFunc: "findNameInList",
defaults: {
gradeNames: "fluid.function",
argumentMap: {
name: 0
}
}
}
}
});
fluid.defaults("gpii.test.integration.deviceReporterAware.windows", {
gradeNames: "gpii.test.integration.deviceReporterAware",
mockDeviceReporters: {
"gpii.deviceReporter.registryKeyExists": {
mockFunc: "registryKeyExists",
defaults: {
gradeNames: "fluid.function",
argumentMap: {
hKey: 0,
path: 1,
subPath: 2
}
}
}
}
});
|