|
1 var user32; |
|
2 var sendMessage; |
|
3 var getDlgItem; |
|
4 var messageBox; |
|
5 var watcher; |
|
6 |
|
7 importScripts("hangui_common.js"); |
|
8 importScripts("dialog_watcher.js"); |
|
9 |
|
10 function initCTypes() { |
|
11 if (!user32) { |
|
12 user32 = ctypes.open("user32.dll"); |
|
13 } |
|
14 if (!getDlgItem) { |
|
15 getDlgItem = user32.declare("GetDlgItem", |
|
16 ctypes.winapi_abi, |
|
17 ctypes.uintptr_t, |
|
18 ctypes.uintptr_t, |
|
19 ctypes.int); |
|
20 } |
|
21 if (!sendMessage) { |
|
22 sendMessage = user32.declare("SendMessageW", |
|
23 ctypes.winapi_abi, |
|
24 ctypes.intptr_t, |
|
25 ctypes.uintptr_t, |
|
26 ctypes.uint32_t, |
|
27 ctypes.uintptr_t, |
|
28 ctypes.intptr_t); |
|
29 } |
|
30 if (!messageBox) { |
|
31 // Handy for debugging the test itself |
|
32 messageBox = user32.declare("MessageBoxW", |
|
33 ctypes.winapi_abi, |
|
34 ctypes.int, |
|
35 ctypes.uintptr_t, |
|
36 ctypes.jschar.ptr, |
|
37 ctypes.jschar.ptr, |
|
38 ctypes.uint32_t); |
|
39 } |
|
40 if (!watcher) { |
|
41 watcher = new DialogWatcher("Warning: Unresponsive plugin"); |
|
42 } |
|
43 } |
|
44 |
|
45 function postSuccess(params) { |
|
46 self.postMessage({"status": true, "params": params}); |
|
47 } |
|
48 |
|
49 function postFail(params, msg) { |
|
50 self.postMessage({"status": false, "params": params, "msg": msg}); |
|
51 } |
|
52 |
|
53 function onDialogStart(inparams, hwnd) { |
|
54 var params = Object.create(inparams); |
|
55 params.testName += " (Start)"; |
|
56 params.callback = null; |
|
57 if (!params.expectToFind) { |
|
58 postFail(params, "Dialog showed when we weren't expecting it to!"); |
|
59 return; |
|
60 } |
|
61 if (params.opCode == HANGUIOP_CANCEL) { |
|
62 sendMessage(hwnd, WM_CLOSE, 0, 0); |
|
63 } else if (params.opCode == HANGUIOP_COMMAND) { |
|
64 if (params.check) { |
|
65 var checkbox = getDlgItem(hwnd, IDC_NOFUTURE); |
|
66 if (!checkbox) { |
|
67 postFail(params, "Couldn't find checkbox"); |
|
68 return; |
|
69 } |
|
70 sendMessage(checkbox, BM_SETCHECK, BST_CHECKED, 0); |
|
71 sendMessage(hwnd, WM_COMMAND, (BN_CLICKED << 16) | IDC_NOFUTURE, checkbox); |
|
72 } |
|
73 var button = getDlgItem(hwnd, params.commandId); |
|
74 if (!button) { |
|
75 postFail(params, |
|
76 "GetDlgItem failed to find button with ID " + params.commandId); |
|
77 return; |
|
78 } |
|
79 sendMessage(hwnd, WM_COMMAND, (BN_CLICKED << 16) | params.commandId, button); |
|
80 } |
|
81 postSuccess(params); |
|
82 } |
|
83 |
|
84 function onDialogEnd(inparams) { |
|
85 var params = Object.create(inparams); |
|
86 params.testName += " (End)"; |
|
87 params.callback = inparams.callback; |
|
88 postSuccess(params); |
|
89 } |
|
90 |
|
91 self.onmessage = function(event) { |
|
92 initCTypes(); |
|
93 watcher.init(); |
|
94 var params = event.data; |
|
95 var timeout = params.timeoutMs; |
|
96 if (params.expectToFind) { |
|
97 watcher.onDialogStart = function(hwnd) { onDialogStart(params, hwnd); }; |
|
98 if (params.expectToClose) { |
|
99 watcher.onDialogEnd = function() { onDialogEnd(params); }; |
|
100 } |
|
101 } else { |
|
102 watcher.onDialogStart = null; |
|
103 watcher.onDialogEnd = null; |
|
104 } |
|
105 var result = watcher.processWindowEvents(timeout); |
|
106 if (result === null) { |
|
107 postFail(params, "Hook failed"); |
|
108 } else if (!result) { |
|
109 if (params.expectToFind) { |
|
110 postFail(params, "The dialog didn't show but we were expecting it to"); |
|
111 } else { |
|
112 postSuccess(params); |
|
113 } |
|
114 } |
|
115 } |
|
116 |
|
117 self.onerror = function(event) { |
|
118 var msg = "Error: " + event.message + " at " + event.filename + ":" + event.lineno; |
|
119 postFail(null, msg); |
|
120 }; |
|
121 |