Basic xpcshell test for testing IPDL

This commit is contained in:
Ben Turner 2009-09-01 15:17:24 -07:00
parent 7ede298e42
commit a8e29d16e8
4 changed files with 104 additions and 2 deletions

View File

@ -167,8 +167,13 @@ MessagePump::ScheduleWork()
// Make sure the event loop wakes up.
if (mThread) {
mThread->Dispatch(mDummyEvent, NS_DISPATCH_NORMAL);
event_.Signal();
}
else {
// Some things (like xpcshell) don't use the app shell and so Run hasn't
// been called. We still need to wake up the main thread.
NS_DispatchToMainThread(mDummyEvent, NS_DISPATCH_NORMAL);
}
event_.Signal();
}
#ifdef DEBUG

View File

@ -61,13 +61,14 @@ CPPSRCS += \
XPCShellEnvironment.cpp \
$(NULL)
# For xpcshell error messages and nsDependentJSString
LOCAL_INCLUDES += \
-I$(topsrcdir)/js/src/xpconnect/shell \
-I$(topsrcdir)/dom/base \
$(NULL)
XPCSHELL_TESTS = tests
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,15 @@
function checkStatus(result) {
if (result == "Waiting") {
sendCommand("observer.status;", checkStatus);
return;
}
do_check_eq(result, "Success");
do_test_finished();
}
function run_test() {
do_test_pending();
sendCommand("load('test_ipcshell_child.js'); start(); observer.status;",
checkStatus);
}

View File

@ -0,0 +1,81 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
function WWObserver(watcher) {
this._watcher = watcher;
this._status = "Waiting";
}
WWObserver.prototype = {
_exit: function(status) {
var ok = (status == "Success");
this._status = status;
this._window = null;
this._watcher.unregisterNotification(this);
this._watcher = null;
if (!ok) {
throw new Error(this._status);
}
},
observe: function(subject, topic, data) {
switch (topic) {
case "domwindowopened":
this._window = subject.QueryInterface(Ci.nsIDOMJSWindow);
if (!this._window) {
this._exit("Error");
}
this._window.setTimeout(function doTimeout(window) {
window.QueryInterface(Ci.nsIDOMWindowInternal).close();
}, 2000, this._window);
break;
case "domwindowclosed":
if (subject.QueryInterface(Ci.nsIDOMJSWindow) != this._window) {
this._exit("Error");
}
this._exit("Success");
break;
default:
this._exit("Error");
}
},
get status() {
return this._status;
}
};
var observer = null;
function start(standalone) {
var windowCreator = Cc["@mozilla.org/toolkit/app-startup;1"].
getService(Ci.nsIWindowCreator);
var windowWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
windowWatcher.setWindowCreator(windowCreator);
observer = new WWObserver(windowWatcher);
windowWatcher.registerNotification(observer, standalone);
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
getService(Ci.nsIPromptService);
promptService.alert(null, "Howdy!", "This window will close automatically.");
}
function maybeExit() {
if (observer.status != "Waiting") {
do_check_eq(observer.status, "Success");
do_test_finished();
return;
}
do_timeout(100, "maybeExit();");
}
function run_test() {
do_test_pending();
start();
do_timeout(100, "maybeExit();");
}