зеркало из https://github.com/mozilla/gecko-dev.git
Basic xpcshell test for testing IPDL
This commit is contained in:
Родитель
fcd4f6280c
Коммит
e46cbd79ac
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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();");
|
||||
}
|
Загрузка…
Ссылка в новой задаче