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
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
/* globals Ice, Test, URI, WorkerGlobalScope */
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "isSafari|isChrome|isWorker|isWindows|runController" }] */
function isSafari()
{
return (/^((?!chrome).)*safari/i).test(navigator.userAgent);
}
function isChrome()
{
//
// We need to check for Edge browser as it might include Chrome in its user agent.
//
return navigator.userAgent.indexOf("Edge/") === -1 &&
navigator.userAgent.indexOf("Chrome/") !== -1;
}
function isWorker()
{
return typeof WorkerGlobalScope !== 'undefined' && this instanceof WorkerGlobalScope;
}
function isWindows()
{
return navigator.userAgent.indexOf("Windows") != -1;
}
class Logger extends Ice.Logger
{
constructor(out)
{
super();
this._out = out;
}
write(message, indent)
{
if(indent)
{
message = message.replace(/\n/g, "\n ");
}
this._out.writeLine(message);
}
}
class ProcessI extends Test.Common.Process
{
constructor(promise, helper, output)
{
super();
this._promise = promise;
this._helper = helper;
this._output = output;
}
async waitReady()
{
await this._helper.waitReady();
}
async waitSuccess()
{
try
{
await this._promise;
this._helper.serverReady();
return 0;
}
catch(ex)
{
this._output.writeLine(`unexpected exception while running test: ${ex.toString()}`);
this._output.writeLine(ex.stack);
this._helper.serverReady(ex);
return 1;
}
}
terminate(current)
{
current.adapter.remove(current.id);
return this._output.get();
}
}
class ControllerHelper
{
constructor(exe, output)
{
if(exe === "Server" || exe === "ServerAMD")
{
this._serverReady = new Ice.Promise();
}
this._output = output;
}
serverReady(ex)
{
if(this._serverReady)
{
if(ex)
{
this._serverReady.reject(ex);
}
else
{
this._serverReady.resolve();
}
}
}
async waitReady()
{
if(this._serverReady)
{
await this._serverReady;
}
}
write(msg)
{
this._output.write(msg);
}
writeLine(msg)
{
this._output.writeLine(msg);
}
}
class ProcessControllerI extends Test.Common.BrowserProcessController
{
constructor(clientOutput, serverOutput, useWorker, scripts)
{
super();
this._clientOutput = clientOutput;
this._serverOutput = serverOutput;
this._useWorker = useWorker;
this._scripts = scripts;
}
start(testSuite, exe, args, current)
{
const es5 = document.location.pathname.indexOf("/es5/") !== -1;
let promise;
let out;
if(exe === "Server" || exe === "ServerAMD")
{
out = this._serverOutput;
}
else
{
out = this._clientOutput;
}
out.clear();
const helper = new ControllerHelper(exe, out);
if(this._useWorker)
{
const scripts = this._scripts;
promise = new Promise(
(resolve, reject) =>
{
const worker = new Worker(es5 ?
"/test/es5/Common/ControllerWorker.js" :
"/test/Common/ControllerWorker.js");
this._worker = worker;
worker.onmessage = function(e)
{
if(e.data.type == "write")
{
helper.write(e.data.message);
}
else if(e.data.type == "writeLine")
{
helper.writeLine(e.data.message);
}
else if(e.data.type == "ready")
{
helper.serverReady();
}
else if(e.data.type == "finished")
{
if(e.data.exception)
{
reject(e.data.exception);
}
else
{
resolve();
}
worker.terminate();
}
};
worker.postMessage({scripts: scripts, exe: exe, args: args});
});
}
else
{
const cls = Ice._require(exe)[exe];
const test = new cls();
test.setControllerHelper(helper);
promise = test.run(args);
}
return Test.Common.ProcessPrx.uncheckedCast(current.adapter.addWithUUID(new ProcessI(promise, helper, out)));
}
getHost()
{
return "127.0.0.1";
}
redirect(url, current)
{
current.con.close(Ice.ConnectionClose.Gracefully);
window.location.href = url;
}
}
async function runController(clientOutput, serverOutput, scripts)
{
class Output
{
constructor(output)
{
this.output = output;
}
write(msg)
{
const text = this.output.val();
this.output.val(text + msg);
}
writeLine(msg)
{
this.write(msg + "\n");
this.output.scrollTop(this.output.get(0).scrollHeight);
}
get()
{
return this.output.val();
}
clear()
{
this.output.val("");
}
}
const out = new Output(clientOutput);
const serverOut = new Output(serverOutput);
const uri = new URI(document.location.href);
const protocol = uri.protocol() === "http" ? "ws" : "wss";
const query = uri.search(true);
const port = query.port || 15002;
const worker = query.worker === "True";
const initData = new Ice.InitializationData();
initData.logger = new Logger(out);
initData.properties = Ice.createProperties();
initData.properties.setProperty("Ice.Override.ConnectTimeout", "1000");
async function registerProcessController(adapter, registry, processController)
{
try
{
await registry.ice_ping();
const connection = registry.ice_getCachedConnection();
connection.setAdapter(adapter);
connection.setACM(5, Ice.ACMClose.CloseOff, Ice.ACMHeartbeat.HeartbeatAlways);
connection.setCloseCallback(
() => out.writeLine("connection with process controller registry closed"));
await registry.setProcessController(Test.Common.ProcessControllerPrx.uncheckedCast(processController));
}
catch(ex)
{
if(ex instanceof Ice.ConnectFailedException)
{
setTimeout(() => registerProcessController(adapter, registry, processController), 2000);
}
else
{
out.writeLine("unexpected exception while connecting to process controller registry:\n" + ex.toString());
}
}
}
let comm;
try
{
comm = Ice.initialize(initData);
const str = `Util/ProcessControllerRegistry:${protocol} -h ${document.location.hostname} -p ${port}`;
const registry = Test.Common.ProcessControllerRegistryPrx.uncheckedCast(comm.stringToProxy(str));
const adapter = await comm.createObjectAdapter("");
const ident = new Ice.Identity("ProcessController", "Browser");
const processController = adapter.add(new ProcessControllerI(out, serverOut, worker, scripts), ident);
adapter.activate();
registerProcessController(adapter, registry, processController);
}
catch(ex)
{
out.writeLine("unexpected exception while creating controller:\n" + ex.toString());
comm.destroy();
}
}
|