diff --git a/java/dist/build.xml b/java/dist/build.xml index af30c710ba7..09bc6074cbe 100644 --- a/java/dist/build.xml +++ b/java/dist/build.xml @@ -259,9 +259,18 @@ + + + + + + + + + + @@ -279,7 +290,14 @@ + + + + + + + diff --git a/java/dist/javadoc.css b/java/dist/javadoc.css new file mode 100755 index 00000000000..fc265122f29 --- /dev/null +++ b/java/dist/javadoc.css @@ -0,0 +1,19 @@ +/* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */ +.java .de1, .java .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;} +.java {font-family: monospace;} +.java .imp {font-weight: bold; color: red;} +.java li {background: #ffffff;} +.java li.li2 {background: #f4f4f4;} +.java .kw1 {color: #b1b100;} +.java .kw2 {color: #000000; font-weight: bold;} +.java .kw3 {color: #aaaadd; font-weight: bold;} +.java .kw4 {color: #993333;} +.java .co1 {color: #808080; font-style: italic;} +.java .co2 {color: #a1a100;} +.java .coMULTI {color: #808080; font-style: italic;} +.java .es0 {color: #000099; font-weight: bold;} +.java .br0 {color: #66cc66;} +.java .st0 {color: #ff0000;} +.java .nu0 {color: #cc66cc;} +.java .me1 {color: #006600;} +.java .me2 {color: #006600;} diff --git a/java/dist/netbeans/build.xml b/java/dist/netbeans/build.xml index ca2af049e28..c3313b8706a 100755 --- a/java/dist/netbeans/build.xml +++ b/java/dist/netbeans/build.xml @@ -209,6 +209,8 @@ ${so.prefix}xul.${so.extension}. + @@ -218,6 +220,7 @@ ${so.prefix}xul.${so.extension}. + diff --git a/java/dom/jni/Makefile.in b/java/dom/jni/Makefile.in index 1a1022b9e8e..500f4ad0b99 100644 --- a/java/dom/jni/Makefile.in +++ b/java/dom/jni/Makefile.in @@ -77,7 +77,7 @@ EXTRA_LIBS += \ include $(topsrcdir)/config/config.mk -DEFINES += -DMOZILLA_INTERNAL_API +DEFINES += -DMOZILLA_INTERNAL_API -DFORCE_PR_LOG ifeq ($(OS_ARCH),Darwin) INCLUDES += -I$(MOZ_JDKHOME)/include diff --git a/java/dom/jni/javaDOMEventsGlobals.cpp b/java/dom/jni/javaDOMEventsGlobals.cpp index ce5b39dc0db..0204d452818 100644 --- a/java/dom/jni/javaDOMEventsGlobals.cpp +++ b/java/dom/jni/javaDOMEventsGlobals.cpp @@ -26,6 +26,8 @@ #include "nsIDOMEvent.h" #include "nsIDOMUIEvent.h" +#include "nsCOMPtr.h" + jclass JavaDOMEventsGlobals::eventClass = NULL; jclass JavaDOMEventsGlobals::uiEventClass = NULL; jclass JavaDOMEventsGlobals::eventListenerClass = NULL; @@ -47,6 +49,9 @@ static NS_DEFINE_IID(kIDOMUIEventIID, NS_IDOMUIEVENT_IID); void JavaDOMEventsGlobals::Initialize(JNIEnv *env) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("JavaDOMEventsGlobals::Initialize: Beginning initialization")); + eventClass = env->FindClass("org/mozilla/dom/events/EventImpl"); if (!eventClass) { JavaDOMGlobals::ThrowException(env, "Class org.mozilla.dom.events.EventImpl not found"); @@ -116,6 +121,10 @@ void JavaDOMEventsGlobals::Initialize(JNIEnv *env) mouseEventClass = (jclass) env->NewGlobalRef(mouseEventClass); if (!mouseEventClass) return; + + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("JavaDOMEventsGlobals::Initialize: Completed Successfully")); + } void JavaDOMEventsGlobals::Destroy(JNIEnv *env) @@ -175,19 +184,18 @@ static jboolean isEventOfType(const char* const* types, nsString &type) } jobject JavaDOMEventsGlobals::CreateEventSubtype(JNIEnv *env, - nsIDOMEvent *event) + nsIDOMEvent *eventIn) { jobject jevent; jclass clazz = eventClass; - nsISupports *isupports; - void *target; + nsCOMPtr event = eventIn; + nsCOMPtr uiEvent; nsresult rv; - - isupports = (nsISupports *) event; + uiEvent = do_QueryInterface(event, &rv); + //check whenever our Event is UIEvent - rv = isupports->QueryInterface(kIDOMUIEventIID, (void **) &target); - if (!NS_FAILED(rv) && target) { + if (NS_SUCCEEDED(rv) && uiEvent) { // At the moment DOM2 draft specifies set of UIEvent subclasses // However Mozilla still presents these events as nsUIEvent // So we need a cludge to determine proper java class to be created @@ -232,8 +240,6 @@ jobject JavaDOMEventsGlobals::CreateEventSubtype(JNIEnv *env, clazz = uiEventClass; } - event->Release(); - event = (nsIDOMEvent *) target; } PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, @@ -247,14 +253,13 @@ jobject JavaDOMEventsGlobals::CreateEventSubtype(JNIEnv *env, return NULL; } - env->SetLongField(jevent, eventPtrFID, (jlong) event); + env->SetLongField(jevent, eventPtrFID, (jlong) event.get()); if (env->ExceptionOccurred()) { PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, ("JavaDOMEventGlobals::CreateEventSubtype: failed to set native ptr %x\n", - (jlong) event)); + (jlong) event.get())); return NULL; } - event->AddRef(); return jevent; } diff --git a/java/dom/jni/nativeDOMProxyListener.cpp b/java/dom/jni/nativeDOMProxyListener.cpp index 88fb9d0580c..559282c3b5a 100644 --- a/java/dom/jni/nativeDOMProxyListener.cpp +++ b/java/dom/jni/nativeDOMProxyListener.cpp @@ -27,6 +27,8 @@ #include"nsIDOMEventListener.h" #include"javaDOMEventsGlobals.h" +#include "nsCOMPtr.h" + static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIDOMEventListener, NS_IDOMEVENTLISTENER_IID); @@ -59,10 +61,11 @@ NativeDOMProxyListener::~NativeDOMProxyListener() } } -NS_IMETHODIMP NativeDOMProxyListener::HandleEvent(nsIDOMEvent* aEvent) +NS_IMETHODIMP NativeDOMProxyListener::HandleEvent(nsIDOMEvent* aEventIn) { jobject jevent; JNIEnv *env; + nsCOMPtr aEvent = aEventIn; if (vm->AttachCurrentThread(&env, NULL) != 0) { PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, @@ -78,10 +81,17 @@ NS_IMETHODIMP NativeDOMProxyListener::HandleEvent(nsIDOMEvent* aEvent) return NS_ERROR_FAILURE; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NativeDOMProxyListener::HandleEvent About to call into java.\n listener: %p\n eventListenerHandleEventMID: %p\n jevent: %p\n", listener, JavaDOMEventsGlobals::eventListenerHandleEventMID, jevent)); + env->CallVoidMethod(listener, JavaDOMEventsGlobals::eventListenerHandleEventMID, jevent); + PR_LOG(JavaDOMGlobals::log, PR_LOG_WARNING, + ("NativeDOMProxyListener::HandleEvent returned from java")); + + if (env->ExceptionOccurred()) { PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR, ("NativeDOMProxyListener::HandleEvent: failed to call EventListener %x\n", diff --git a/java/dom/jni/org_mozilla_dom_events_MouseEventImpl.cpp b/java/dom/jni/org_mozilla_dom_events_MouseEventImpl.cpp index 297ec48d40b..88558cfa3b0 100644 --- a/java/dom/jni/org_mozilla_dom_events_MouseEventImpl.cpp +++ b/java/dom/jni/org_mozilla_dom_events_MouseEventImpl.cpp @@ -21,11 +21,15 @@ #include "prlog.h" #include "nsIDOMNode.h" +#include "nsIDOMEvent.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMEventTarget.h" #include "javaDOMEventsGlobals.h" #include "org_mozilla_dom_events_MouseEventImpl.h" +#include "nsCOMPtr.h" + + /* * Class: org_mozilla_dom_events_MouseEventImpl * Method: getAltKey @@ -34,21 +38,28 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetAltKey (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetAltKey: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, - "MouseEvent.getAltKey: NULL pointer"); + "MouseEvent.getAltKey: NULL pointer"); return JNI_FALSE; } PRBool altKey = PR_FALSE; - nsresult rv = event->GetAltKey(&altKey); + rv = event->GetAltKey(&altKey); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getAltKey: failed", rv); return JNI_FALSE; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetAltKey: result: %d", altKey)); return (altKey == PR_TRUE) ? JNI_TRUE : JNI_FALSE; @@ -63,21 +74,28 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetA JNIEXPORT jshort JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetButton (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetButton: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, "MouseEvent.getButton: NULL pointer"); return 0; } PRUint16 code = 0; - nsresult rv = event->GetButton(&code); + rv = event->GetButton(&code); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getButton: failed", rv); return 0; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetButton: result: %d", code)); return (jshort) code; } @@ -90,21 +108,28 @@ JNIEXPORT jshort JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetBut JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetClientX (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetClientX: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, "MouseEvent.getClientX: NULL pointer"); - return 0; + return JNI_FALSE; } PRInt32 clientX = 0; - nsresult rv = event->GetClientX(&clientX); + rv = event->GetClientX(&clientX); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getClientX: failed", rv); return 0; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetClientX: result: %d", clientX)); return (jint) clientX; } @@ -117,21 +142,28 @@ JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetClien JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetClientY (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetClientY: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, "MouseEvent.getClientY: NULL pointer"); - return 0; + return JNI_FALSE; } PRInt32 clientY = 0; - nsresult rv = event->GetClientY(&clientY); + rv = event->GetClientY(&clientY); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getClientY: failed", rv); return 0; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetClientY: result: %d", clientY)); return (jint) clientY; } @@ -145,21 +177,28 @@ JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetClien JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetCtrlKey (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetCtrlKey: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, "MouseEvent.getCtrlKey: NULL pointer"); return JNI_FALSE; } PRBool ctrlKey = PR_FALSE; - nsresult rv = event->GetCtrlKey(&ctrlKey); + rv = event->GetCtrlKey(&ctrlKey); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getCtrlKey: failed", rv); return JNI_FALSE; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetCtrlKey: result: %d", ctrlKey)); return (ctrlKey == PR_TRUE) ? JNI_TRUE : JNI_FALSE; } @@ -173,21 +212,28 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetC JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetMetaKey (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetMetaKey: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, "MouseEvent.getMetaKey: NULL pointer"); return JNI_FALSE; } PRBool metaKey = PR_FALSE; - nsresult rv = event->GetMetaKey(&metaKey); + rv = event->GetMetaKey(&metaKey); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getMetaKey: failed", rv); return JNI_FALSE; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetMetaKey: result: %d", metaKey)); return (metaKey == PR_TRUE) ? JNI_TRUE : JNI_FALSE; } @@ -201,21 +247,28 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetM JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetScreenX (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetScreenX: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, - "MouseEvent.getScreenX: NULL pointer\n"); - return 0; + "MouseEvent.getScreenX: NULL pointer"); + return JNI_FALSE; } PRInt32 screenX = 0; - nsresult rv = event->GetScreenX(&screenX); + rv = event->GetScreenX(&screenX); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getScreenX: failed", rv); return 0; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetScreenX: result: %d", screenX)); return (jint) screenX; } @@ -228,21 +281,28 @@ JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetScree JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetScreenY (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetScreenY: cannot QI to nsIDOMMouseEvent from nsIDOMEvent")); JavaDOMGlobals::ThrowException(env, "MouseEvent.getScreenY: NULL pointer"); - return 0; + return JNI_FALSE; } PRInt32 screenY = 0; - nsresult rv = event->GetScreenY(&screenY); + rv = event->GetScreenY(&screenY); if (NS_FAILED(rv)) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getScreenY: failed", rv); return 0; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetScreenY: result: %d", screenY)); return (jint) screenY; } @@ -256,8 +316,15 @@ JNIEXPORT jint JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetScree JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetShiftKey (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetShiftKey: eventPtr: %p", eventPtr)); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetShiftKey: QI nsCOMPtr from: %p, rv: %d", eventPtr, rv)); + if (!event) { JavaDOMGlobals::ThrowException(env, "MouseEvent.getShiftKey: NULL pointer"); @@ -265,12 +332,16 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetS } PRBool shiftKey = PR_FALSE; - nsresult rv = event->GetShiftKey(&shiftKey); + rv = event->GetShiftKey(&shiftKey); if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetShiftKey: rv: %d", rv)); JavaDOMGlobals::ThrowException(env, "MouseEvent.getShiftKey: failed", rv); return JNI_FALSE; } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::nativeGetShiftKey: result: %d", shiftKey)); return (shiftKey == PR_TRUE) ? JNI_TRUE : JNI_FALSE; } @@ -283,29 +354,51 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetS JNIEXPORT jobject JNICALL Java_org_mozilla_dom_events_MouseEventImpl_nativeGetRelatedTarget (JNIEnv *env, jobject jthis) { - nsIDOMMouseEvent* event = (nsIDOMMouseEvent*) - env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); - if (!event) { - JavaDOMGlobals::ThrowException(env, - "MouseEvent.getRelatedNode: NULL pointer"); - return NULL; - } + nsresult rv = NS_OK; + nsIDOMEvent *eventPtr = (nsIDOMEvent*) + env->GetLongField(jthis, JavaDOMEventsGlobals::eventPtrFID); + nsCOMPtr event = do_QueryInterface(eventPtr, &rv); - nsIDOMEventTarget* ret = nsnull; - nsresult rv = event->GetRelatedTarget(&ret); - if (NS_FAILED(rv)) { - JavaDOMGlobals::ThrowException(env, - "MouseEvent.getRelatedNode: failed", rv); - return NULL; - } - if (!ret) - return NULL; + if (!event || NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::getRelatedTarget: cannot QI nsIDOMMouseEvent from nsIDOMEvent")); + JavaDOMGlobals::ThrowException(env, + "MouseEvent.getRelatedNode: NULL pointer"); + return NULL; + } + + nsCOMPtr ret = nsnull; + rv = event->GetRelatedTarget(getter_AddRefs(ret)); + if (NS_FAILED(rv)) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::getRelatedTarget: cannot get related target")); - nsIDOMNode* node = nsnull; - rv = ret->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); - printf("========== rv:%x node:%x", rv, node); -// return JavaDOMGlobals::CreateNodeSubtype(env, ret); - return JavaDOMGlobals::CreateNodeSubtype(env, node); + JavaDOMGlobals::ThrowException(env, + "MouseEvent.getRelatedNode: failed", rv); + return NULL; + } + if (!ret) { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::getRelatedTarget: related target is null")); + + return NULL; + } + + nsCOMPtr node = nsnull; + node = do_QueryInterface(ret, &rv); + jobject result = nsnull; + if (NS_SUCCEEDED(rv) && node) { + result = JavaDOMGlobals::CreateNodeSubtype(env, node); + } + else { + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::getRelatedTarget: can't QI nsIDOMNode from nsIDOMEventTarget")); + + } + PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG, + ("MouseEventImpl::getRelatedTarget: returning %p", result)); + + return result; } /* diff --git a/java/dom/src/Makefile.in b/java/dom/src/Makefile.in index 67be1095174..77a82b7611d 100644 --- a/java/dom/src/Makefile.in +++ b/java/dom/src/Makefile.in @@ -105,7 +105,7 @@ EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) include $(topsrcdir)/config/rules.mk -DEFINES += -DMOZILLA_INTERNAL_API +DEFINES += -DMOZILLA_INTERNAL_API -DFORCE_PR_LOG edburns: @echo $(XPCOM_LIBS) diff --git a/java/webclient/classes_spec/org/mozilla/mcp/MCP.java b/java/webclient/classes_spec/org/mozilla/mcp/MCP.java index f7d59971983..8a88ed8e9ab 100755 --- a/java/webclient/classes_spec/org/mozilla/mcp/MCP.java +++ b/java/webclient/classes_spec/org/mozilla/mcp/MCP.java @@ -1,5 +1,5 @@ /* - * $Id: MCP.java,v 1.7 2007-03-13 06:21:44 edburns%acm.org Exp $ + * $Id: MCP.java,v 1.8 2007-03-14 21:02:13 edburns%acm.org Exp $ */ /* @@ -51,7 +51,10 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * + *

The main class for the Mozilla Control Program. Please see the package description for an + * overview.

+ * @author edburns */ public class MCP { @@ -60,12 +63,12 @@ public class MCP { public MCP() { } - public static final String MCP_LOG = "org.mozilla.mcp"; - public static final String MCP_LOG_STRINGS = "org.mozilla.mcp.MCPLogStrings"; + private static final String MCP_LOG = "org.mozilla.mcp"; + private static final String MCP_LOG_STRINGS = "org.mozilla.mcp.MCPLogStrings"; - public static final Logger LOGGER = getLogger(MCP_LOG); + private static final Logger LOGGER = getLogger(MCP_LOG); - static Logger getLogger( String loggerName ) { + private static Logger getLogger( String loggerName ) { return Logger.getLogger(loggerName, MCP_LOG_STRINGS ); } @@ -212,31 +215,76 @@ public class MCP { } return pageInfoListener; } + + /** + + *

Add the argument AjaxListener to this MCP + * instance.

+ + */ public void addAjaxListener(AjaxListener listener) { getEventRegistration().addDocumentLoadListener(listener); } + /** + + *

Remove the argument AjaxListener to this MCP + * instance.

+ + */ public void removeAjaxListener(AjaxListener listener) { getEventRegistration().removeDocumentLoadListener(listener); } + /** + + *

Add the argument MouseListener to the + * Canvas for this MCP instance.

+ + */ public void addMouseListener(MouseListener listener) { getBrowserControlCanvas().addMouseListener(listener); } + /** + + *

Remove the argument MouseListener from the + * Canvas for this MCP instance.

+ + */ public void removeMouseListener(MouseListener listener) { getBrowserControlCanvas().removeMouseListener(listener); } + /** + + *

Add the argument KeyListener to the + * Canvas for this MCP instance.

+ + */ public void addKeyListener(KeyListener listener) { getBrowserControlCanvas().addKeyListener(listener); } + /** + + *

Remove the argument KeyListener from the + * Canvas for this MCP instance.

+ + */ public void removeKeyListener(KeyListener listener) { getBrowserControlCanvas().removeKeyListener(listener); } + /** + + *

Return the Webclient BrowserControl instance used + * by this MCP instance. This is useful for operations + * that require more complex browser control than that offered by + * MCP.

+ + */ public BrowserControl getBrowserControl() { if (!initialized) { IllegalStateException ise = new IllegalStateException("Not initialized. Call setAppData()"); @@ -264,6 +312,15 @@ public class MCP { } return browserControl; } + + /** + + *

Return the realized and visible java.awt.Frame + * containing the actual browser window. There is no need to put + * this Frame inside of any surrounding Swing or AWT windows. It is + * sufficient to stand alone.

+ + */ public Frame getRealizedVisibleBrowserWindow() { if (null == frame) { @@ -288,11 +345,50 @@ public class MCP { } return frame; } + + /** + + *

Make invisible, and delete the BrowserControl + * instance for this MCP instance. Reset internal state of the + * instance so that a subsequent call to {@link + * #getRealizedVisibleBrowserWindow} will create a new + * Frame.

+ + */ public void deleteBrowserControl() { getRealizedVisibleBrowserWindow().setVisible(false); BrowserControlFactory.deleteBrowserControl(getBrowserControl()); + browserControl = null; + navigation = null; + eventRegistration = null; + canvas = null; + pageInfoListener = null; + frame = null; + x = 0; + y = 0; + width = 1280; + height = 960; + initialized = false; + robot = null; + treeDumper = null; + if (null != latch) { + latch.countDown(); + } + latch = null; } + + /** + + *

Return the DOM Element with the given id or name. + * First, Document.getElementById() is called, passing + * the argument id. If an element is found, it is + * returned. Otherwise, the document is traversed and the first + * element encountered with a name equal to the argument + * id is returned. If no such element exists, + * null is returned.

+ + */ public Element findElement(String id) { Element result = null; @@ -309,12 +405,32 @@ public class MCP { return result; } + + /** + + *

Return true if and only if the argument + * toFind occurs within the current page. Case is not + * significant. Users desiring more detailed find behavior should + * use {@link #getBrowserControl} to obtain a reference to the + * CurrentPage interface, which has more advanced + * methods pertaining to the current page.

+ + */ public boolean findInPage(String toFind) { boolean found = false; - found = getCurrentPage().find(toFind, true, true); + found = getCurrentPage().find(toFind, true, false); return found; } + + /** + + *

Find the DOM element within the current page matching the + * argument id using {@link #findElement}. Use + * java.awt.Robot to click the element. Return + * immediately after clicking the element.

+ + */ public void clickElement(String id) { Element element = findElement(id); @@ -345,6 +461,16 @@ public class MCP { throw new IllegalStateException("Unable to click element " + id); } } + + /** + + *

Find the DOM element within the current page matching the + * argument id using {@link #findElement}. Use + * java.awt.Robot to click the element. Block until the + * document load triggered by the click has completed.

+ + */ + public void blockingClickElement(String idOrName) { synchronized (this) { @@ -359,6 +485,13 @@ public class MCP { } } } + + /** + + *

Load the url, blocking until the load has completed.

+ + */ + public void blockingLoad(String url) { Navigation2 nav = getNavigation(); diff --git a/java/webclient/classes_spec/org/mozilla/mcp/mcp.jpg b/java/webclient/classes_spec/org/mozilla/mcp/mcp.jpg new file mode 100755 index 00000000000..3531a5bf3f2 Binary files /dev/null and b/java/webclient/classes_spec/org/mozilla/mcp/mcp.jpg differ diff --git a/java/webclient/classes_spec/org/mozilla/mcp/package.html b/java/webclient/classes_spec/org/mozilla/mcp/package.html new file mode 100755 index 00000000000..e351479769c --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/mcp/package.html @@ -0,0 +1,200 @@ + + + + + + + + org.mozilla.mcp + + + + + +

Mozilla Control Program

+ + Master Control Program, from TRON + +

This package is a simple layer on top of the Webclient API to enable automated +testing of web applications using software such as JUnit or TestNG. It fulfills a similar role as +HtmlUnit or HttpUnit, but unlike those two, MCP has a real browser +behind it. MCP also fulfills a similar role as Selenium. However, +unlike Selenium, MCP allows you to make assertions about the response +content of actual XMLHttpRequest responses, including getting an actual +DOM instance of the response XML.

+ +

The main class in the package is MCP. An +instance of MCP corresponds to one browser window. Methods +doing the following obvious tasks are provided:

+ +
+ + + +

Here is a code excerpt that illustrates the use of MCP and JUnit to +test a JSF application that uses Project Dynamic +Faces for Ajax.

+ + +
  1. enum TestFeature {
  2. +
  3.     RECEIVED_END_AJAX_EVENT,
  4. +
  5.     HAS_MAP,
  6. +
  7.     HAS_VALID_PARTIAL_RESPONSE,
  8. +
  9.     HAS_VALID_READYSTATE,
  10. +
  11.     STOP_WAITING
  12. +
  13. }
  14. +
  15.  
  16. +
  17. public void testCardemo() throws Exception {
  18. +
  19.    
  20. +
  21.     MCP mcp = new MCP();
  22. +
  23.     try {
  24. +
  25.         mcp.setAppData(getBrowserBinDir());
  26. +
  27.     }
  28. +
  29.     catch (Exception e) {
  30. +
  31.         fail();
  32. +
  33.     }
  34. +
  35.    
  36. +
  37.     mcp.getRealizedVisibleBrowserWindow();
  38. +
  39.     final BitSet bitSet = new BitSet();
  40. +
  41.     AjaxListener listener = new AjaxListener() {
  42. +
  43.       public void endAjax(Map eventMap) {
  44. +
  45.           bitSet.flip(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal());
  46. +
  47.           if (null != eventMap) {
  48. +
  49.               bitSet.flip(TestFeature.HAS_MAP.ordinal());
  50. +
  51.           }
  52. +
  53.           String responseText = (String) eventMap.get("responseText");
  54. +
  55.           if (null != responseText) {
  56. +
  57.               if (-1 != responseText.indexOf("<partial-response>") &&
  58. +
  59.                   -1 != responseText.indexOf("</partial-response>")) {
  60. +
  61.                   bitSet.flip(TestFeature.
  62. +
  63.                     HAS_VALID_PARTIAL_RESPONSE.ordinal());
  64. +
  65.               }
  66. +
  67.           }
  68. +
  69.           String readyState = (String) eventMap.get("readyState");
  70. +
  71.           bitSet.set(TestFeature.HAS_VALID_READYSTATE.ordinal(),
  72. +
  73.                      null != readyState && readyState.equals("4"));
  74. +
  75.           bitSet.flip(TestFeature.STOP_WAITING.ordinal());
  76. +
  77.           
  78. +
  79.       }
  80. +
  81.     };
  82. +
  83.     mcp.addAjaxListener(listener);
  84. +
  85.    
  86. +
  87.     // Load the main page of the app
  88. +
  89.     mcp.blockingLoad("http://javaserver.org/jsf-ajax-cardemo/faces/chooseLocale.jsp");
  90. +
  91.     // Choose the "German" language button
  92. +
  93.     mcp.blockingClickElement("j_id_id73:Germany");
  94. +
  95.     // Choose the roadster
  96. +
  97.     mcp.blockingClickElement("j_id_id18:j_id_id43");
  98. +
  99.     // Sample the Basis-Preis and Ihr Preis before the ajax transaction
  100. +
  101.     Element pricePanel = mcp.findElement("j_id_id10:zone1");
  102. +
  103.     assertNotNull(pricePanel);
  104. +
  105.     String pricePanelText = pricePanel.getTextContent();
  106. +
  107.    
  108. +
  109.     assertNotNull(pricePanelText);
  110. +
  111.     assertTrue(pricePanelText.matches("(?s).*Basis-Preis\\s*15700.*"));
  112. +
  113.     assertTrue(pricePanelText.matches("(?s).*Ihr Preis\\s*15700.*"));
  114. +
  115.    
  116. +
  117.     // Choose the "Tempomat" checkbox
  118. +
  119.     bitSet.clear();
  120. +
  121.     mcp.clickElement("j_id_id10:j_id_id63j_id_1");
  122. +
  123.    
  124. +
  125.     while (!bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
  126. +
  127.         Thread.currentThread().sleep(5000);
  128. +
  129.     }
  130. +
  131.    
  132. +
  133.     // assert that the ajax transaction succeeded
  134. +
  135.     assertTrue(bitSet.get(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal()));
  136. +
  137.     assertTrue(bitSet.get(TestFeature.HAS_MAP.ordinal()));
  138. +
  139.     assertTrue(bitSet.get(TestFeature.HAS_VALID_PARTIAL_RESPONSE.ordinal()));
  140. +
  141.     assertTrue(bitSet.get(TestFeature.HAS_VALID_READYSTATE.ordinal()));
  142. +
  143.     bitSet.clear();
  144. +
  145.    
  146. +
  147.     // Sample the Basis-Preis and Ihr-Preis after the ajax transaction
  148. +
  149.     pricePanel = mcp.findElement("j_id_id10:zone1");
  150. +
  151.     assertNotNull(pricePanel);
  152. +
  153.     pricePanelText = pricePanel.getTextContent();
  154. +
  155.    
  156. +
  157.     assertNotNull(pricePanelText);
  158. +
  159.     assertTrue(pricePanelText.matches("(?s).*Basis-Preis\\s*15700.*"));
  160. +
  161.     assertTrue(pricePanelText.matches("(?s).*Ihr Preis\\s*16600.*"));
  162. +
  163.    
  164. +
  165.     mcp.deleteBrowserControl();
  166. +
  167. }
+ + + + diff --git a/java/webclient/classes_spec/org/mozilla/webclient/WebclientFactory.java b/java/webclient/classes_spec/org/mozilla/webclient/WebclientFactory.java index e38b6f431e9..ba404493e0d 100644 --- a/java/webclient/classes_spec/org/mozilla/webclient/WebclientFactory.java +++ b/java/webclient/classes_spec/org/mozilla/webclient/WebclientFactory.java @@ -30,9 +30,12 @@ import java.io.File; import java.io.FileNotFoundException; /** - *

Do per-app one-time initialization and shutdown, as well as being - * the factory for per-window {@link BrowserControl} instances. This - * interface allows a pluggable webclient API implementation. The + * + *

An implementation for this interface must be provided by the + * Webclient implementation. This interface is not to be called by the + * end user. Do per-app one-time initialization and shutdown, as well + * as being the factory for per-window {@link BrowserControl} instances. + * This interface allows a pluggable webclient API implementation. The * static methods in {@link BrowserControlFactory} call through to * methods on this interface. The implementation of this interface must * be a singleton and its the lifetime must be the same as the diff --git a/java/webclient/src_moz/Makefile.in b/java/webclient/src_moz/Makefile.in index d81c34543b3..5b7adb6af42 100644 --- a/java/webclient/src_moz/Makefile.in +++ b/java/webclient/src_moz/Makefile.in @@ -178,7 +178,7 @@ endif include $(topsrcdir)/config/rules.mk -DEFINES += -DMOZILLA_INTERNAL_API +DEFINES += -DMOZILLA_INTERNAL_API -DFORCE_PR_LOG ifdef MOZ_ENABLE_GTK ifndef MOZ_MONOLITHIC_TOOLKIT diff --git a/java/webclient/src_share/Makefile.in b/java/webclient/src_share/Makefile.in index 1b8e0840b21..ce00cbc7617 100644 --- a/java/webclient/src_share/Makefile.in +++ b/java/webclient/src_share/Makefile.in @@ -48,7 +48,7 @@ FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk -DEFINES += -DMOZILLA_INTERNAL_API +DEFINES += -DMOZILLA_INTERNAL_API -DFORCE_PR_LOG ifneq ($(BAL_INTERFACE),) INCLUDES := -I../bal -I../bal/solaris $(INCLUDES)