M build-tests.xml

- comment in all tests

M classes_spec/org/mozilla/webclient/Navigation2.java
M classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java

- add loadFromStreamBlocking, until we have DocumentLoadListener working

M src_moz/InputStreamShim.cpp
M src_moz/InputStreamShim.h

- rollback the nsIAsyncInputStream changes.

M test/automated/src/classes/org/mozilla/webclient/NavigationTest.java

- test from a FileInputStream

M test/automated/src/classes/org/mozilla/webclient/RandomHTMLInputStream.java

- Allow notification when read completes.
This commit is contained in:
edburns%acm.org 2004-06-02 14:31:24 +00:00
parent 37b62cc2b0
commit c452a9072e
6 changed files with 95 additions and 100 deletions

View File

@ -29,6 +29,9 @@
package org.mozilla.webclient;
import java.io.InputStream;
import java.util.Properties;
public interface Navigation2 extends Navigation
{
@ -52,5 +55,10 @@ public void post(String absoluteUrl,
public void loadURLBlocking(String absoluteURL);
public void loadFromStreamBlocking(InputStream stream, String uri,
String contentType, int contentLength,
Properties loadInfo);
}
// end of interface Navigation2

View File

@ -134,6 +134,34 @@ public void loadURL(String absoluteURL)
}
});
}
public void loadFromStreamBlocking(InputStream stream, String uri,
String contentType, int contentLength,
Properties loadInfo) {
ParameterCheck.nonNull(stream);
ParameterCheck.nonNull(uri);
ParameterCheck.nonNull(contentType);
if (contentLength < -1 || contentLength == 0) {
throw new RangeException("contentLength value " + contentLength +
" is out of range. It is should be either -1 or greater than 0.");
}
final InputStream finalStream = stream;
final String finalUri = uri;
final String finalContentType = contentType;
final int finalContentLength = contentLength;
final Properties finalLoadInfo = loadInfo;
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
public Object run() {
nativeLoadFromStream(NavigationImpl.this.getNativeBrowserControl(),
finalStream, finalUri,
finalContentType,
finalContentLength, finalLoadInfo);
return null;
}
});
}
public void refresh(long loadFlags)
{
@ -247,7 +275,7 @@ public static void main(String [] args)
Log.setApplicationName("NavigationImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.7 2004/04/28 16:40:15 edburns%acm.org Exp $");
Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.8 2004/06/02 14:31:23 edburns%acm.org Exp $");
try {
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);

View File

@ -30,9 +30,6 @@
#include "ns_globals.h"
#include "nsIEventTarget.h"
#include "nsStreamUtils.h"
static const PRInt32 buffer_increment = 1024;
static const PRInt32 do_close_code = -524;
@ -41,8 +38,7 @@ InputStreamShim::InputStreamShim(jobject yourJavaStreamRef,
mJavaStream(yourJavaStreamRef), mContentLength(yourContentLength),
mBuffer(nsnull), mBufferLength(0), mCountFromJava(0),
mCountFromMozilla(0), mAvailable(0), mAvailableForMozilla(0), mNumRead(0),
mDoClose(PR_FALSE), mDidClose(PR_FALSE), mLock(nsnull),
mCloseStatus(NS_OK), mCallback(nsnull), mCallbackFlags(0)
mDoClose(PR_FALSE), mDidClose(PR_FALSE), mLock(nsnull)
{
NS_INIT_ISUPPORTS();
mLock = PR_NewLock();
@ -131,18 +127,6 @@ nsresult InputStreamShim::doReadFromJava()
}
rv = NS_OK;
// if we have bytes available for mozilla, and they it has requested
// a callback when bytes are available.
if (mCallback && 0 < mAvailableForMozilla
&& !(mCallbackFlags & WAIT_CLOSURE_ONLY)) {
rv = mCallback->OnInputStreamReady(this);
mCallback = nsnull;
mCallbackFlags = nsnull;
if (NS_FAILED(rv)) {
goto DRFJ_CLEANUP;
}
}
// finally, do another check for available bytes
if (NS_FAILED(doAvailable())) {
rv = NS_ERROR_FAILURE;
@ -296,6 +280,9 @@ InputStreamShim::doRead(void)
mCountFromJava += mNumRead;
mAvailableForMozilla = mCountFromJava - mCountFromMozilla;
}
printf("InputStreamShim::doRead: read %d bytes\n", mNumRead);
fflush(stdout);
rv = NS_OK;
#endif
@ -334,13 +321,6 @@ InputStreamShim::doClose(void)
}
rv = NS_OK;
#endif
if (mCallback && mAvailableForMozilla &&
!(mCallbackFlags & WAIT_CLOSURE_ONLY)) {
rv = mCallback->OnInputStreamReady(this);
mCallback = nsnull;
mCallbackFlags = nsnull;
}
mDidClose = PR_TRUE;
return rv;
}
@ -356,12 +336,10 @@ InputStreamShim::Available(PRUint32* aResult)
if (!aResult) {
return NS_ERROR_NULL_POINTER;
}
if (mDoClose) {
return mCloseStatus;
}
PR_ASSERT(mLock);
PR_Lock(mLock);
*aResult = mAvailableForMozilla;
// *aResult = mAvailableForMozilla;
*aResult = PR_UINT32_MAX;
rv = NS_OK;
PR_Unlock(mLock);
@ -375,7 +353,6 @@ InputStreamShim::Close()
PR_ASSERT(mLock);
PR_Lock(mLock);
mDoClose = PR_TRUE;
mCloseStatus = NS_BASE_STREAM_CLOSED;
rv = NS_OK;
PR_Unlock(mLock);
@ -391,17 +368,28 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
}
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: entering\n"));
if (mDoClose) {
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: exiting, already closed\n"));
return mCloseStatus;
}
*aNumRead = 0;
PR_ASSERT(mLock);
PR_ASSERT(mCountFromMozilla <= mCountFromJava);
PR_Lock(mLock);
// wait for java to load the buffer with some data
do {
if (mAvailableForMozilla == 0) {
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: wait for java: release lock\n"));
PR_Unlock(mLock);
PR_Sleep(PR_INTERVAL_MIN);
PR_Lock(mLock);
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: wait for java: acquire lock\n"));
}
else {
break;
}
} while ((!mDidClose) && (-1 != mNumRead));
if (mAvailableForMozilla) {
if (aCount <= (mCountFromJava - mCountFromMozilla)) {
// what she's asking for is less than or equal to what we have
@ -418,14 +406,13 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
mCountFromMozilla += (mCountFromJava - mCountFromMozilla);
}
mAvailableForMozilla -= *aNumRead;
rv = NS_OK;
}
else {
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: exiting, would block\n"));
rv = NS_BASE_STREAM_WOULD_BLOCK;
}
printf("InputStreamShim::Read: read %d bytes\n", *aNumRead);
fflush(stdout);
rv = NS_OK;
PR_Unlock(mLock);
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: exiting\n"));
@ -443,47 +430,9 @@ InputStreamShim::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32
NS_IMETHODIMP
InputStreamShim::IsNonBlocking(PRBool *_retval)
{
*_retval = PR_TRUE;
return NS_OK;
}
// NS_NOTREACHED("IsNonBlocking");
// return NS_ERROR_NOT_IMPLEMENTED;
NS_IMETHODIMP
InputStreamShim::CloseWithStatus(nsresult astatus)
{
this->Close();
mCloseStatus = astatus;
return NS_OK;
}
NS_IMETHODIMP
InputStreamShim::AsyncWait(nsIInputStreamCallback *aCallback,
PRUint32 aFlags, PRUint32 aRequestedCount,
nsIEventTarget *aEventTarget)
{
PR_Lock(mLock);
mCallback = nsnull;
mCallbackFlags = nsnull;
nsCOMPtr<nsIInputStreamCallback> proxy;
if (aEventTarget) {
nsresult rv = NS_NewInputStreamReadyEvent(getter_AddRefs(proxy),
aCallback, aEventTarget);
if (NS_FAILED(rv)) return rv;
aCallback = proxy;
}
if (NS_FAILED(mCloseStatus) ||
(mAvailableForMozilla && !(aFlags & WAIT_CLOSURE_ONLY))) {
// stream is already closed or readable; post event.
aCallback->OnInputStreamReady(this);
}
else {
// queue up callback object to be notified when data becomes available
mCallback = aCallback;
mCallbackFlags = aFlags;
}
PR_Unlock(mLock);
*_retval = PR_FALSE;
return NS_OK;
}

View File

@ -22,17 +22,14 @@
#ifndef InputStreamShim_h
#define InputStreamShim_h
#include "nsIAsyncInputStream.h"
#include "nsCOMPtr.h"
#include "nsIInputStream.h"
#include <jni.h>
class InputStreamShimActionEvent;
struct PRLock;
class InputStreamShim : public nsIAsyncInputStream
class InputStreamShim : public nsIInputStream
{
public:
InputStreamShim(jobject yourJavaStreamRef,
@ -79,9 +76,7 @@ private:
// nsIInputStream methods
NS_DECL_NSIINPUTSTREAM
// nsIAsyncInputStream
NS_DECL_NSIASYNCINPUTSTREAM
protected:
/**
@ -179,12 +174,6 @@ protected:
*/
PRLock *mLock;
nsresult mCloseStatus;
nsCOMPtr<nsIInputStreamCallback> mCallback;
PRUint32 mCallbackFlags;
};
#endif // InputStreamShim_h

View File

@ -1,5 +1,5 @@
/*
* $Id: NavigationTest.java,v 1.5 2004/04/28 16:40:15 edburns%acm.org Exp $
* $Id: NavigationTest.java,v 1.6 2004/06/02 14:31:24 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -35,6 +35,7 @@ import java.awt.Frame;
import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;
// NavigationTest.java
@ -89,10 +90,14 @@ public class NavigationTest extends WebclientTestCase {
assertTrue(-1 != selection.toString().indexOf("This test file is for the NavigationTest."));
System.out.println("Selection is: " + selection.toString());
RandomHTMLInputStream rhis = new RandomHTMLInputStream(5, false);
nav.loadFromStream(rhis, "http://randomstream.com/",
"text/html", -1, null);
// try loading from a FileInputStream
FileInputStream fis = new FileInputStream(testPage);
nav.loadFromStreamBlocking(fis, "http://somefile.com/",
"text/html", -1, null);
currentPage.selectAll();
selection = currentPage.getSelection();
assertTrue(-1 != selection.toString().indexOf("This test file is for the NavigationTest."));
System.out.println("Selection is: " + selection.toString());
frame.setVisible(false);

View File

@ -211,6 +211,14 @@ public int read(byte[] b, int off, int len) throws IOException
numRead = max;
available -= max;
}
try {
synchronized(this) {
this.notify();
}
}
catch (Exception e) {
throw new IOException("RandomHTMLInputStream: Can't notify listeners");
}
}
else {
@ -254,6 +262,14 @@ public void close() throws IOException
throw new IOException("It's time for an IOException!");
}
isClosed = true;
try {
synchronized(this) {
this.notify();
}
}
catch (Exception e) {
throw new IOException("RandomHTMLInputStream: Can't notify listeners");
}
}
private boolean shouldThrowException()