From 447359d89db188c73dc8f7dc3f2c628cc3bbd302 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Wed, 23 Jun 2004 19:58:12 +0000 Subject: [PATCH] Next really will be to get POST working. A test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerImpl.java - Forgot to add this. M classes_spec/org/mozilla/webclient/impl/wrapper_native/HistoryImpl.java M src_moz/HistoryImpl.cpp - push through can{back,forward}(), forward(). M test/automated/src/classes/org/mozilla/webclient/HistoryTest.java - exercise new methods. git-svn-id: svn://10.0.0.236/trunk@158380 18797224-902f-48f8-a5cc-f745e15eee43 --- .../impl/wrapper_native/HistoryImpl.java | 61 ++++---- .../java/webclient/src_moz/HistoryImpl.cpp | 132 ++++++++---------- .../webclient/DocumentLoadListenerImpl.java | 48 +++++++ .../org/mozilla/webclient/HistoryTest.java | 17 ++- 4 files changed, 153 insertions(+), 105 deletions(-) create mode 100644 mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerImpl.java diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/HistoryImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/HistoryImpl.java index 063436cc155..93532ae7b49 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/HistoryImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/HistoryImpl.java @@ -91,12 +91,16 @@ public boolean canBack() { getWrapperFactory().verifyInitialized(); Assert.assert_it(-1 != getNativeBrowserControl()); - boolean result = false; - synchronized(getBrowserControl()) { - result = nativeCanBack(getNativeBrowserControl()); - } - return result; + Boolean result = (Boolean) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + boolean canBack = nativeCanBack(getNativeBrowserControl()); + return new Boolean(canBack); + } + }); + + return result.booleanValue(); } public HistoryEntry [] getBackList() @@ -127,30 +131,38 @@ public void clearHistory() throw new UnimplementedException("\nUnimplementedException -----\n API Function History::clearHistory has not yet been implemented.\n"); } - - public void forward() { getWrapperFactory().verifyInitialized(); Assert.assert_it(-1 != getNativeBrowserControl()); - synchronized(getBrowserControl()) { - nativeForward(getNativeBrowserControl()); - } + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + nativeForward(getNativeBrowserControl()); + return null; + } + }); } - + public boolean canForward() { getWrapperFactory().verifyInitialized(); Assert.assert_it(-1 != getNativeBrowserControl()); - boolean result = false; - synchronized(getBrowserControl()) { - result = nativeCanForward(getNativeBrowserControl()); - } - return result; + Boolean result = (Boolean) + NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { + public Object run() { + boolean canForward = nativeCanForward(getNativeBrowserControl()); + return new Boolean(canForward); + } + }); + + return result.booleanValue(); } + + + public HistoryEntry [] getForwardList() { HistoryEntry [] result = null; @@ -275,21 +287,4 @@ public native int nativeGetHistoryLength(int webShellPtr); public native String nativeGetURLForIndex(int webShellPtr, int historyIndex); -// ----VERTIGO_TEST_START - -// -// Test methods -// - -public static void main(String [] args) -{ - Assert.setEnabled(true); - Log.setApplicationName("HistoryImpl"); - Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: HistoryImpl.java,v 1.4 2004-06-23 19:21:05 edburns%acm.org Exp $"); - -} - -// ----VERTIGO_TEST_END - } // end of class HistoryImpl diff --git a/mozilla/java/webclient/src_moz/HistoryImpl.cpp b/mozilla/java/webclient/src_moz/HistoryImpl.cpp index a6a143185cd..a0fab79e574 100644 --- a/mozilla/java/webclient/src_moz/HistoryImpl.cpp +++ b/mozilla/java/webclient/src_moz/HistoryImpl.cpp @@ -55,38 +55,80 @@ Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeBack return; } -/******************* - JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeCanBack (JNIEnv *env, jobject obj, jint nativeBCPtr) { jboolean result = JNI_FALSE; - JNIEnv * pEnv = env; - jobject jobj = obj; - void * voidResult; - // PRBool voidResult; + JNIEnv * pEnv = env; + jobject jobj = obj; - NativeBrowserControl* initContext = (NativeBrowserControl *) nativeBCPtr; + NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr; - if (initContext == nsnull) { - ::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellCanBack"); - return result; - } + if (nativeBrowserControl == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeCanBack"); + return result; + } - if (initContext->initComplete) { - wsCanBackEvent * actionEvent = - new wsCanBackEvent(initContext->webNavigation); - PLEvent * event = (PLEvent*) *actionEvent; - - voidResult = ::util_PostSynchronousEvent(initContext, event); - - result = (PR_FALSE == ((PRBool) voidResult)) ? JNI_FALSE : JNI_TRUE; + nsresult rv = + nativeBrowserControl->mNavigation->GetCanGoBack((PRBool *) &result); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: Can't GetCanGoBack"); } return result; } +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeForward +(JNIEnv *env, jobject obj, jint nativeBCPtr) +{ + JNIEnv * pEnv = env; + jobject jobj = obj; + + NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr; + + if (nativeBrowserControl == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeForward"); + return; + } + + nsresult rv = + nativeBrowserControl->mNavigation->GoForward(); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: Can't GoForward"); + } + + return; +} + +JNIEXPORT jboolean +JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeCanForward +(JNIEnv *env, jobject obj, jint nativeBCPtr) +{ + jboolean result = JNI_FALSE; + JNIEnv * pEnv = env; + jobject jobj = obj; + + NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr; + + if (nativeBrowserControl == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeCanForward"); + return result; + } + + nsresult rv = + nativeBrowserControl->mNavigation->GetCanGoForward((PRBool *) &result); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: Can't GetCanGoForward"); + } + + return result; +} + + +/******************* + JNIEXPORT jobjectArray JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeGetBackList (JNIEnv *env, jobject obj, jint nativeBCPtr) { @@ -102,58 +144,6 @@ Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeClearHistory } -JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeForward -(JNIEnv *env, jobject obj, jint nativeBCPtr) -{ - JNIEnv * pEnv = env; - jobject jobj = obj; - - NativeBrowserControl* initContext = (NativeBrowserControl *) nativeBCPtr; - - if (initContext == nsnull) { - ::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellForward"); - return; - } - - if (initContext->initComplete) { - wsForwardEvent * actionEvent = - new wsForwardEvent(initContext->webNavigation); - PLEvent * event = (PLEvent*) *actionEvent; - - ::util_PostEvent(initContext, event); - } - - return; -} - -JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeCanForward -(JNIEnv *env, jobject obj, jint nativeBCPtr) -{ - jboolean result = JNI_FALSE; - JNIEnv * pEnv = env; - jobject jobj = obj; - void * voidResult; - - NativeBrowserControl* initContext = (NativeBrowserControl *) nativeBCPtr; - - if (initContext == nsnull) { - ::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to raptorWebShellCanForward"); - return result; - } - - if (initContext->initComplete) { - wsCanForwardEvent * actionEvent = - new wsCanForwardEvent(initContext->webNavigation); - PLEvent * event = (PLEvent*) *actionEvent; - - voidResult = ::util_PostSynchronousEvent(initContext, event); - - result = (PR_FALSE == ((PRBool) voidResult)) ? JNI_FALSE : JNI_TRUE; - } - - return result; -} - JNIEXPORT jobjectArray JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_HistoryImpl_nativeGetForwardList (JNIEnv *env, jobject obj, jint nativeBCPtr) { diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerImpl.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerImpl.java new file mode 100644 index 00000000000..a21e2c96a35 --- /dev/null +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/DocumentLoadListenerImpl.java @@ -0,0 +1,48 @@ +/* + * $Id: DocumentLoadListenerImpl.java,v 1.1 2004-06-23 19:58:12 edburns%acm.org Exp $ + */ + +/* + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun + * Microsystems, Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): Ed Burns <edburns@acm.org> + */ + +package org.mozilla.webclient; + +public abstract class DocumentLoadListenerImpl implements DocumentLoadListener { + + public void eventDispatched(WebclientEvent event) { + if (event instanceof DocumentLoadEvent) { + switch ((int) event.getType()) { + case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK): + doEndCheck(); + break; + case ((int) DocumentLoadEvent.PROGRESS_URL_LOAD_EVENT_MASK): + doProgressCheck(); + break; + } + } + } + + public void doEndCheck() {} + + public void doProgressCheck() {} + } + diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/HistoryTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/HistoryTest.java index 5702efa57e8..b1bcf2791a1 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/HistoryTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/HistoryTest.java @@ -1,5 +1,5 @@ /* - * $Id: HistoryTest.java,v 1.1 2004-06-23 19:21:06 edburns%acm.org Exp $ + * $Id: HistoryTest.java,v 1.2 2004-06-23 19:58:12 edburns%acm.org Exp $ */ /* @@ -135,6 +135,9 @@ public class HistoryTest extends WebclientTestCase { // load four files. // HistoryTest.keepWaiting = true; + + assertTrue(!history.canBack()); + assertTrue(!history.canForward()); nav.loadURL("http://localhost:5243/HistoryTest0.html"); // keep waiting until the previous load completes @@ -143,6 +146,8 @@ public class HistoryTest extends WebclientTestCase { } HistoryTest.keepWaiting = true; + assertTrue(!history.canBack()); + assertTrue(!history.canForward()); nav.loadURL("http://localhost:5243/HistoryTest1.html"); // keep waiting until the previous load completes @@ -151,6 +156,8 @@ public class HistoryTest extends WebclientTestCase { } HistoryTest.keepWaiting = true; + assertTrue(history.canBack()); + assertTrue(!history.canForward()); nav.loadURL("http://localhost:5243/HistoryTest2.html"); // keep waiting until the previous load completes @@ -159,6 +166,8 @@ public class HistoryTest extends WebclientTestCase { } HistoryTest.keepWaiting = true; + assertTrue(history.canBack()); + assertTrue(!history.canForward()); nav.loadURL("http://localhost:5243/HistoryTest3.html"); // keep waiting until the previous load completes @@ -180,6 +189,8 @@ public class HistoryTest extends WebclientTestCase { HistoryTest.keepWaiting = true; historyListener.setStringToVerify("This is page 2 of the history test."); + assertTrue(history.canBack()); + assertTrue(!history.canForward()); history.back(); // keep waiting until the previous load completes @@ -189,6 +200,8 @@ public class HistoryTest extends WebclientTestCase { HistoryTest.keepWaiting = true; historyListener.setStringToVerify("This is page 1 of the history test."); + assertTrue(history.canBack()); + assertTrue(history.canForward()); history.back(); // keep waiting until the previous load completes @@ -198,6 +211,8 @@ public class HistoryTest extends WebclientTestCase { HistoryTest.keepWaiting = true; historyListener.setStringToVerify("This is page 0 of the history test."); + assertTrue(history.canBack()); + assertTrue(history.canForward()); history.back(); // keep waiting until the previous load completes