dom/plugins/test/mochitest/hangui_iface.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial