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
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// vrhosttest.cpp
// Definition of testing and validation functions that are exported from this
// dll
#include "vrhostex.h"
#include "VRShMem.h"
#include <stdio.h>
#include "windows.h"
static const char s_pszSharedEvent[] = "vrhost_test_event_signal";
static const DWORD s_dwWFSO_WAIT = 20000;
void SampleExport() { printf("vrhost.cpp hello world\n"); }
// For testing ShMem as Manager and Service:
// The two processes should output the steps, synchronously, to validate
// 2-way communication via VRShMem as follows
// 01 mgr: create mgr
// 02 mgr: wait for signal
// 03 svc: create svc
// 04 svc: send signal
// 05 svc: wait for signal
// 06 mgr: push browser
// 07 mgr: send signal
// 08 mgr: wait for signal
// 09 svc: pull browser
// 10 svc: verify data
// 11 svc: push system
// 12 svc: send signal
// 13 svc: wait for signal
// 14 mgr: pull system
// 15 mgr: verify data
// 16 mgr: push window
// 17 mgr: send signal
// 18 mgr: wait for signal
// 19 svc: pull window
// 20 svc: verify data
// 21 svc: push window
// 22 svc: send signal
// 23 mgr: pull window
// 24 mgr: verify data
// 25 return
// These tests can be run with two instances of vrtesthost.exe, one first
// running with -testmgr and the second running with -testsvc.
// TODO: Bug 1563235 - Convert vrtesthost.exe tests into unit tests
// For testing VRShMem as the Manager (i.e., the one who creates the
// shmem). The sequence of how it tests with the service is listed above.
void TestTheManager() {
printf("TestTheManager Start\n");
MOZ_ASSERT(GetLastError() == 0,
"TestTheManager should start with no OS errors");
HANDLE hEvent = ::CreateEventA(nullptr, // lpEventAttributes
FALSE, // bManualReset
FALSE, // bInitialState
s_pszSharedEvent // lpName
);
printf("\n01 mgr: create mgr\n");
mozilla::gfx::VRShMem shmem(nullptr, true /*aRequiresMutex*/);
shmem.CreateShMem(true /*aCreateOnSharedMemory*/);
printf("02 mgr: wait for signal\n");
::WaitForSingleObject(hEvent, s_dwWFSO_WAIT);
// Set some state to verify on the other side
mozilla::gfx::VRBrowserState browserState = {0};
browserState.presentationActive = true;
browserState.layerState[0].type =
mozilla::gfx::VRLayerType::LayerType_2D_Content;
browserState.hapticState[0].controllerIndex = 987;
printf("06 mgr: push browser\n");
shmem.PushBrowserState(browserState, true);
printf("07 mgr: send signal\n");
::SetEvent(hEvent);
printf("08 mgr: wait for signal\n");
::WaitForSingleObject(hEvent, s_dwWFSO_WAIT);
printf("14 mgr: pull system\n");
mozilla::gfx::VRSystemState state;
shmem.PullSystemState(state.displayState, state.sensorState,
state.controllerState, state.enumerationCompleted,
nullptr);
printf(
"15 mgr: verify data\n"
"\tstate.enumerationCompleted = %d\n"
"\tstate.displayState.displayName = \"%s\"\n"
"\tstate.controllerState[1].hand = %hhu\n"
"\tstate.sensorState.inputFrameID = %llu\n",
state.enumerationCompleted, state.displayState.displayName,
state.controllerState[1].hand, state.sensorState.inputFrameID);
// Test the WindowState functions as the host
mozilla::gfx::VRWindowState windowState = {0};
strcpy(windowState.signalName, "randomsignalstring");
windowState.dxgiAdapterHost = 99;
windowState.heightHost = 42;
windowState.widthHost = 24;
printf("16 mgr: push window\n");
shmem.PushWindowState(windowState);
printf("17 mgr: send signal\n");
::SetEvent(hEvent);
printf("18 mgr: wait for signal\n");
::WaitForSingleObject(hEvent, s_dwWFSO_WAIT);
printf("23 mgr: pull window\n");
shmem.PullWindowState(windowState);
printf(
"24 svc: verify data\n"
"\tstate.hwndFx = 0x%llX\n"
"\tstate.heightFx = %d\n"
"\tstate.widthFx = %d\n"
"\tstate.textureHandle = %p\n",
windowState.hwndFx, windowState.heightFx, windowState.widthFx,
windowState.textureFx);
shmem.CloseShMem();
printf("TestTheManager complete");
fflush(nullptr);
}
// For testing VRShMem as the Service (i.e., the one who consumes the
// shmem). The sequence of how it tests with the service is listed above.
void TestTheService() {
printf("TestTheService Start\n");
MOZ_ASSERT(GetLastError() == 0,
"TestTheService should start with no OS errors");
// Handle created by TestTheManager above.
HANDLE hEvent = ::OpenEventA(EVENT_ALL_ACCESS, // dwDesiredAccess
FALSE, // bInheritHandle
s_pszSharedEvent // lpName
);
printf("\n03 svc: create svc\n");
mozilla::gfx::VRShMem shmem(nullptr, true /*aRequiresMutex*/);
shmem.JoinShMem();
printf("04 svc: send signal\n");
::SetEvent(hEvent);
printf("05 svc: wait for signal\n");
::WaitForSingleObject(hEvent, s_dwWFSO_WAIT);
printf("09 svc: pull browser\n");
mozilla::gfx::VRBrowserState state;
shmem.PullBrowserState(state);
printf(
"10 svc: verify data\n"
"\tstate.presentationActive = %d\n"
"\tstate.layerState[0].type = %hu\n"
"\tstate.hapticState[0].controllerIndex = %d\n",
state.presentationActive, state.layerState[0].type,
state.hapticState[0].controllerIndex);
// Set some state to verify on the other side
mozilla::gfx::VRSystemState systemState;
systemState.enumerationCompleted = true;
strncpy(systemState.displayState.displayName, "test from vrservice shmem",
mozilla::gfx::kVRDisplayNameMaxLen);
systemState.controllerState[1].hand = mozilla::gfx::ControllerHand::Left;
systemState.sensorState.inputFrameID = 1234567;
printf("11 svc: push system\n");
shmem.PushSystemState(systemState);
printf("12 svc: send signal\n");
::SetEvent(hEvent);
printf("13 svc: wait for signal\n");
::WaitForSingleObject(hEvent, s_dwWFSO_WAIT);
// Test the WindowState functions as Firefox
printf("19 svc: pull window\n");
mozilla::gfx::VRWindowState windowState;
shmem.PullWindowState(windowState);
printf(
"20 svc: verify data\n"
"\tstate.signalName = \"%s\"\n"
"\tstate.dxgiAdapterHost = %d\n"
"\tstate.heightHost = %d\n"
"\tstate.widthHost = %d\n",
windowState.signalName, windowState.dxgiAdapterHost,
windowState.heightHost, windowState.widthHost);
windowState.hwndFx = 0x1234;
windowState.heightFx = 1234;
windowState.widthFx = 4321;
windowState.textureFx = (HANDLE)0x77777;
printf("21 svc: push window\n");
shmem.PushWindowState(windowState);
printf("22 svc: send signal\n");
::SetEvent(hEvent);
shmem.LeaveShMem();
printf("TestTheService complete");
fflush(nullptr);
}
DWORD TestWaitForVREventThreadProc(_In_ LPVOID lpParameter) {
// WaitForVREvent
printf("\nStarting TestWaitForVREventThreadProc\n");
PFN_WAITFORVREVENT fnWaitForVRMsg = (PFN_WAITFORVREVENT)lpParameter;
uint32_t nVRWindowID = 0;
uint32_t eventType = 0;
uint32_t eventData1 = 0;
uint32_t eventData2 = 0;
while (eventType != 2) { // FxEvent_SHUTDOWN
fnWaitForVRMsg(nVRWindowID, eventType, eventData1, eventData2);
printf(
"\nWaitForVRMessage:\n\tvrWindowID: %d\n\teventType: %d\n\teventData1: "
"%d\n\teventData2: %d\n",
nVRWindowID, eventType, eventData1, eventData2);
}
printf("\nReturning from TestWaitForVREventThreadProc\n");
return 0;
}
// This function tests the export CreateVRWindow by outputting the return values
// from the call to the console, as well as testing CloseVRWindow after the data
// is retrieved.
void TestCreateVRWindow() {
printf("TestCreateVRWindow Start\n");
// Cache function calls to test real-world export and usage
HMODULE hVRHost = ::GetModuleHandleA("vrhost.dll");
PFN_CREATEVRWINDOW fnCreate =
(PFN_CREATEVRWINDOW)::GetProcAddress(hVRHost, "CreateVRWindow");
PFN_CLOSEVRWINDOW fnClose =
(PFN_CLOSEVRWINDOW)::GetProcAddress(hVRHost, "CloseVRWindow");
PFN_SENDUIMSG fnSendMsg =
(PFN_SENDUIMSG)::GetProcAddress(hVRHost, "SendUIMessageToVRWindow");
PFN_WAITFORVREVENT fnWaitForVRMsg =
(PFN_WAITFORVREVENT)::GetProcAddress(hVRHost, "WaitForVREvent");
// Create the VR Window and store data from creation
char currentDir[MAX_PATH] = {0};
char currentDirProfile[MAX_PATH] = {0};
DWORD currentDirLength =
::GetCurrentDirectoryA(ARRAYSIZE(currentDir), currentDir);
currentDir[currentDirLength] = '\\';
int err = sprintf_s(currentDirProfile, ARRAYSIZE(currentDirProfile),
"%svrhosttest-profile", currentDir);
if (err > 0) {
printf("Starting Firefox from %s\n", currentDir);
UINT windowId;
HANDLE hTex;
UINT width;
UINT height;
fnCreate(currentDir, currentDirProfile, 0, 100, 200, &windowId, &hTex,
&width, &height);
// Now that the Fx window is created, start a new thread to wait for VR
// events to be sent from it
DWORD dwTid;
HANDLE hThreadWait = CreateThread(nullptr, 0, TestWaitForVREventThreadProc,
(void*)fnWaitForVRMsg, 0, &dwTid);
// Wait for Fx to finish launch
#ifdef DEBUG
::Sleep(5000);
#else
::Sleep(2000);
#endif
printf(
"1. Simulating a click on the Home button, which should look "
"pressed\n");
POINT pt;
pt.x = 180;
pt.y = 700;
fnSendMsg(windowId, WM_LBUTTONDOWN, 0, POINTTOPOINTS(pt));
::Sleep(3000);
fnSendMsg(windowId, WM_LBUTTONUP, 0, POINTTOPOINTS(pt));
printf(
"2. Simulating hovering across the URL bar, which should turn "
"blue\n");
pt.x = 600;
for (int i = 0; i < 100; ++i) {
pt.x++;
fnSendMsg(windowId, WM_MOUSEMOVE, 0, POINTTOPOINTS(pt));
::Sleep(5);
}
printf(
"3. Simulating clicking inside the URL bar, which should "
"highlight the text\n");
pt.x = 700;
pt.y = 700;
fnSendMsg(windowId, WM_LBUTTONDOWN, 0, POINTTOPOINTS(pt));
fnSendMsg(windowId, WM_LBUTTONUP, 0, POINTTOPOINTS(pt));
::Sleep(3000);
printf("4. Type some UTF16 characters in the URL bar\n");
fnSendMsg(windowId, WM_CHAR, 0x4E64, 0);
fnSendMsg(windowId, WM_CHAR, 0x312D, 0);
fnSendMsg(windowId, WM_CHAR, 0x0BB9, 0);
fnSendMsg(windowId, WM_CHAR, 0x2745, 0);
printf(
"5. Simulating clicking outside the URL bar, which should "
"send a keyboard blur event\n");
pt.x = 20;
pt.y = 20;
fnSendMsg(windowId, WM_LBUTTONDOWN, 0, POINTTOPOINTS(pt));
fnSendMsg(windowId, WM_LBUTTONUP, 0, POINTTOPOINTS(pt));
::Sleep(1000);
printf("6. Simulating scrolling the web content down and then up\n");
pt.x = 100;
pt.y = 100;
for (int i = -20; i < 10; ++i) {
fnSendMsg(windowId, WM_MOUSEWHEEL,
MAKELONG(0, (i < 0) ? -WHEEL_DELTA : WHEEL_DELTA),
POINTTOPOINTS(pt));
::Sleep(100);
}
::Sleep(5000);
// Close the Firefox VR Window
fnClose(windowId, true);
// Wait for the VR event thread to return
::WaitForSingleObject(hThreadWait, INFINITE);
// Print output from CreateVRWindow
printf(
"\n\nTestCreateVRWindow End:\n"
"\twindowId = 0x%X\n"
"\thTex = 0x%p\n"
"\twidth = %d\n"
"\theight = %d\n",
windowId, hTex, width, height);
printf("\n***Note: profile folder created at %s***\n", currentDirProfile);
}
}
|