1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/hangui_iface.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +var user32; 1.5 +var sendMessage; 1.6 +var getDlgItem; 1.7 +var messageBox; 1.8 +var watcher; 1.9 + 1.10 +importScripts("hangui_common.js"); 1.11 +importScripts("dialog_watcher.js"); 1.12 + 1.13 +function initCTypes() { 1.14 + if (!user32) { 1.15 + user32 = ctypes.open("user32.dll"); 1.16 + } 1.17 + if (!getDlgItem) { 1.18 + getDlgItem = user32.declare("GetDlgItem", 1.19 + ctypes.winapi_abi, 1.20 + ctypes.uintptr_t, 1.21 + ctypes.uintptr_t, 1.22 + ctypes.int); 1.23 + } 1.24 + if (!sendMessage) { 1.25 + sendMessage = user32.declare("SendMessageW", 1.26 + ctypes.winapi_abi, 1.27 + ctypes.intptr_t, 1.28 + ctypes.uintptr_t, 1.29 + ctypes.uint32_t, 1.30 + ctypes.uintptr_t, 1.31 + ctypes.intptr_t); 1.32 + } 1.33 + if (!messageBox) { 1.34 + // Handy for debugging the test itself 1.35 + messageBox = user32.declare("MessageBoxW", 1.36 + ctypes.winapi_abi, 1.37 + ctypes.int, 1.38 + ctypes.uintptr_t, 1.39 + ctypes.jschar.ptr, 1.40 + ctypes.jschar.ptr, 1.41 + ctypes.uint32_t); 1.42 + } 1.43 + if (!watcher) { 1.44 + watcher = new DialogWatcher("Warning: Unresponsive plugin"); 1.45 + } 1.46 +} 1.47 + 1.48 +function postSuccess(params) { 1.49 + self.postMessage({"status": true, "params": params}); 1.50 +} 1.51 + 1.52 +function postFail(params, msg) { 1.53 + self.postMessage({"status": false, "params": params, "msg": msg}); 1.54 +} 1.55 + 1.56 +function onDialogStart(inparams, hwnd) { 1.57 + var params = Object.create(inparams); 1.58 + params.testName += " (Start)"; 1.59 + params.callback = null; 1.60 + if (!params.expectToFind) { 1.61 + postFail(params, "Dialog showed when we weren't expecting it to!"); 1.62 + return; 1.63 + } 1.64 + if (params.opCode == HANGUIOP_CANCEL) { 1.65 + sendMessage(hwnd, WM_CLOSE, 0, 0); 1.66 + } else if (params.opCode == HANGUIOP_COMMAND) { 1.67 + if (params.check) { 1.68 + var checkbox = getDlgItem(hwnd, IDC_NOFUTURE); 1.69 + if (!checkbox) { 1.70 + postFail(params, "Couldn't find checkbox"); 1.71 + return; 1.72 + } 1.73 + sendMessage(checkbox, BM_SETCHECK, BST_CHECKED, 0); 1.74 + sendMessage(hwnd, WM_COMMAND, (BN_CLICKED << 16) | IDC_NOFUTURE, checkbox); 1.75 + } 1.76 + var button = getDlgItem(hwnd, params.commandId); 1.77 + if (!button) { 1.78 + postFail(params, 1.79 + "GetDlgItem failed to find button with ID " + params.commandId); 1.80 + return; 1.81 + } 1.82 + sendMessage(hwnd, WM_COMMAND, (BN_CLICKED << 16) | params.commandId, button); 1.83 + } 1.84 + postSuccess(params); 1.85 +} 1.86 + 1.87 +function onDialogEnd(inparams) { 1.88 + var params = Object.create(inparams); 1.89 + params.testName += " (End)"; 1.90 + params.callback = inparams.callback; 1.91 + postSuccess(params); 1.92 +} 1.93 + 1.94 +self.onmessage = function(event) { 1.95 + initCTypes(); 1.96 + watcher.init(); 1.97 + var params = event.data; 1.98 + var timeout = params.timeoutMs; 1.99 + if (params.expectToFind) { 1.100 + watcher.onDialogStart = function(hwnd) { onDialogStart(params, hwnd); }; 1.101 + if (params.expectToClose) { 1.102 + watcher.onDialogEnd = function() { onDialogEnd(params); }; 1.103 + } 1.104 + } else { 1.105 + watcher.onDialogStart = null; 1.106 + watcher.onDialogEnd = null; 1.107 + } 1.108 + var result = watcher.processWindowEvents(timeout); 1.109 + if (result === null) { 1.110 + postFail(params, "Hook failed"); 1.111 + } else if (!result) { 1.112 + if (params.expectToFind) { 1.113 + postFail(params, "The dialog didn't show but we were expecting it to"); 1.114 + } else { 1.115 + postSuccess(params); 1.116 + } 1.117 + } 1.118 +} 1.119 + 1.120 +self.onerror = function(event) { 1.121 + var msg = "Error: " + event.message + " at " + event.filename + ":" + event.lineno; 1.122 + postFail(null, msg); 1.123 +}; 1.124 +