This checkin demonstrates that navigation.loadFromStream() works, at

least in the case of a FileInputStream.  I still can't get the
RandomHTMLInputStream to work.  I'm still waiting on a response from
Darin Fisher on that one.

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 17:26:49 +00:00
Родитель 94e3b55fe4
Коммит 67db434000
3 изменённых файлов: 53 добавлений и 43 удалений

Просмотреть файл

@ -29,8 +29,9 @@
#include "prthread.h"
#include "ns_globals.h"
#include "nsMemory.h"
static const PRInt32 buffer_increment = 1024;
static const PRInt32 buffer_increment = 5120;
static const PRInt32 do_close_code = -524;
InputStreamShim::InputStreamShim(jobject yourJavaStreamRef,
@ -55,7 +56,7 @@ InputStreamShim::~InputStreamShim()
PR_Lock(mLock);
delete [] mBuffer;
nsMemory::Free(mBuffer);
mBuffer = nsnull;
mBufferLength = 0;
@ -101,8 +102,6 @@ nsresult InputStreamShim::doReadFromJava()
nsresult rv = NS_ERROR_FAILURE;
PR_ASSERT(mLock);
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::doReadFromJava: entering\n"));
PR_Lock(mLock);
@ -145,8 +144,6 @@ nsresult InputStreamShim::doReadFromJava()
PR_Unlock(mLock);
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::doReadFromJava: exiting\n"));
return rv;
}
@ -195,15 +192,12 @@ InputStreamShim::doRead(void)
return NS_ERROR_NOT_AVAILABLE;
}
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::doRead: entering\n"));
PR_ASSERT(0 != mAvailable);
// if we don't have a buffer, create one
if (!mBuffer) {
if (0 < mContentLength) {
mBuffer = new char[mContentLength];
mBuffer = (char *) nsMemory::Alloc(mContentLength);
mBufferLength = mContentLength;
}
else {
@ -218,7 +212,7 @@ InputStreamShim::doRead(void)
mBufferLength = buffer_increment +
(bufLengthCalc * buffer_increment);
}
mBuffer = new char[mBufferLength];
mBuffer = (char *) nsMemory::Alloc(mBufferLength);
}
if (!mBuffer) {
@ -233,14 +227,22 @@ InputStreamShim::doRead(void)
if (mBufferLength < (mCountFromJava + mAvailable)) {
// create the new buffer
char *tBuffer = new char[mBufferLength + buffer_increment];
char *tBuffer = (char *) nsMemory::Alloc(mBufferLength +
buffer_increment);
if (!tBuffer) {
return NS_ERROR_FAILURE;
tBuffer = (char *) malloc(mBufferLength +
buffer_increment);
if (!tBuffer) {
mDoClose = PR_TRUE;
return NS_ERROR_NOT_AVAILABLE;
}
}
// copy the old buffer into the new buffer
memcpy(tBuffer, mBuffer, mBufferLength);
// delete the old buffer
delete [] mBuffer;
nsMemory::Free(mBuffer);
// update mBuffer;
mBuffer = tBuffer;
// update our bufferLength
@ -280,15 +282,10 @@ InputStreamShim::doRead(void)
mCountFromJava += mNumRead;
mAvailableForMozilla = mCountFromJava - mCountFromMozilla;
}
printf("InputStreamShim::doRead: read %d bytes\n", mNumRead);
fflush(stdout);
rv = NS_OK;
#endif
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::doRead: exiting\n"));
return rv;
}
@ -366,8 +363,7 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
if (!aBuffer || !aNumRead) {
return NS_ERROR_NULL_POINTER;
}
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("InputStreamShim::Read: entering\n"));
*aNumRead = 0;
PR_ASSERT(mLock);
PR_ASSERT(mCountFromMozilla <= mCountFromJava);
@ -377,13 +373,13 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
// 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"));
if (mDoClose) {
PR_Unlock(mLock);
return NS_OK;
}
}
else {
break;
@ -408,14 +404,8 @@ InputStreamShim::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead)
mAvailableForMozilla -= *aNumRead;
}
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"));
return rv;
}

Просмотреть файл

@ -1,5 +1,5 @@
/*
* $Id: NavigationTest.java,v 1.6 2004/06/02 14:31:24 edburns%acm.org Exp $
* $Id: NavigationTest.java,v 1.7 2004/06/02 17:26:49 edburns%acm.org Exp $
*/
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
@ -59,6 +59,7 @@ public class NavigationTest extends WebclientTestCase {
public void testNavigation() throws Exception {
BrowserControl firstBrowserControl = null;
Selection selection = null;
BrowserControlFactory.setAppData(getBrowserBinDir());
firstBrowserControl = BrowserControlFactory.newBrowserControl();
assertNotNull(firstBrowserControl);
@ -75,35 +76,53 @@ public class NavigationTest extends WebclientTestCase {
Navigation2 nav = (Navigation2)
firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
assertNotNull(nav);
File testPage = new File(getBrowserBinDir(),
"../../java/webclient/test/automated/src/test/NavigationTest.txt");
System.out.println("Loading url: " + testPage.toURL().toString());
nav.loadURLBlocking(testPage.toURL().toString());
CurrentPage2 currentPage = (CurrentPage2)
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
assertNotNull(currentPage);
File testPage = new File(getBrowserBinDir(),
"../../java/webclient/test/automated/src/test/NavigationTest.txt");
// try loading a file: url
System.out.println("Loading url: " + testPage.toURL().toString());
nav.loadURL(testPage.toURL().toString());
Thread.currentThread().sleep(1000);
currentPage.selectAll();
Selection selection = currentPage.getSelection();
selection = currentPage.getSelection();
assertTrue(-1 != selection.toString().indexOf("This test file is for the NavigationTest."));
System.out.println("Selection is: " + selection.toString());
// try loading from a FileInputStream
FileInputStream fis = new FileInputStream(testPage);
nav.loadFromStreamBlocking(fis, "http://somefile.com/",
"text/html", -1, null);
nav.loadFromStream(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());
// try loading from the dreaded RandomHTMLInputStream
RandomHTMLInputStream rhis = new RandomHTMLInputStream(5, false);
nav.loadFromStreamBlocking(rhis, "http://randomstream.com/",
"text/html", -1, null);
boolean keepWaiting = true;
//while (keepWaiting) {
Thread.currentThread().sleep(8000);
// }
currentPage.selectAll();
selection = currentPage.getSelection();
System.out.println("Selection is: " + selection.toString());
frame.setVisible(false);
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
BrowserControlFactory.appTerminate();
assertTrue(-1 != selection.toString().indexOf("START Random Data"));
assertTrue(-1 != selection.toString().indexOf("END Random Data"));
}
}

Просмотреть файл

@ -104,7 +104,7 @@ public RandomHTMLInputStream(int yourNumReads, boolean yourRandomExceptions)
ParameterCheck.greaterThan(yourNumReads, 1);
randomExceptions = yourRandomExceptions;
random = new Random();
random = new Random(1234);
Assert.assert_it(null != random);
isClosed = false;
@ -226,6 +226,7 @@ public int read(byte[] b, int off, int len) throws IOException
if (random.nextBoolean()) {
try {
System.out.println("RandomHTMLInputStream:: sleeping");
System.out.flush();
Thread.sleep(3000);
}
catch (Exception e) {