Methods Summary |
---|
public void | attachRequestHandle(RequestHandle requestHandle)Attach the RequestHandle to this handler
if (false) {
Log.v(LOGTAG, "TestEventHandler.attachRequestHandle(): " +
"requestHandle: " + requestHandle);
}
mRequestHandle = requestHandle;
|
public void | certificate(SslCertificate certificate)Implements the EventHandler certificate method called every
time a resource is loaded via a secure connection
|
public void | data(byte[] data, int len)Implements the EventHandler data method called when a server
sends content data
boolean mismatch = false;
if (false) {
Log.v(LOGTAG, "TestEventHandler: data() " + len + " bytes");
}
eventsReceived[TEST_DATA] = true;
if (notExpecting[TEST_DATA]) {
expectDetails.append("Data event received but not expected");
expectDetails.append("\r\n");
}
Log.v(LOGTAG, new String(data, 0, len));
if (expectDataLength != -1) {
if (expectDataLength == len) {
expectDataLength = -1;
} else {
expectDetails.append("expect data length mismatch expected:"+
expectDataLength+" got:"+len);
expectDetails.append("\r\n");
}
/* Check data only if length is the same */
if ((expectDataLength == -1) && expectData != null) {
for (int i = 0; i < len; i++) {
if (expectData[i] != data[i]) {
mismatch = true;
expectDetails.append("Expect data mismatch at byte "+
i+" expected:"+expectData[i]+" got:"+data[i]);
expectDetails.append("\r\n");
break;
}
}
}
}
if ((expectDataLength == -1) || !mismatch)
expects[TEST_DATA] = false;
|
public void | detachRequestHandle()Detach the RequestHandle
if (false) {
Log.v(LOGTAG, "TestEventHandler.detachRequestHandle(): " +
"requestHandle: " + mRequestHandle);
}
mRequestHandle = null;
|
public void | endData()Implements the EventHandler endData method called to
indicate completion or a request
if (false) {
Log.v(LOGTAG, "TestEventHandler: endData() called");
}
eventsReceived[TEST_ENDDATA] = true;
if (notExpecting[TEST_ENDDATA]) {
expectDetails.append("End data event received but not expected");
expectDetails.append("\r\n");
}
expects[TEST_ENDDATA] = false;
if (useLowLevel) {
if (delayResponse) {
synchronized (syncObj) {
syncObj.notifyAll();
}
} else {
if (netRunner != null) {
System.out.println("TestEventHandler: endData() stopping "+
netRunner);
netRunner.decrementRunCount();
}
}
}
|
public void | error(int id, java.lang.String description)Implements the EventHandler error method called when a server
sends header fields
if (false) {
Log.v(LOGTAG, "TestEventHandler: error() called Id:" + id +
" description " + description);
}
eventsReceived[TEST_ERROR] = true;
if (notExpecting[TEST_ERROR]) {
expectDetails.append("Error event received but not expected");
expectDetails.append("\r\n");
}
if (expectErrorId != -1) {
if (expectErrorId == id) {
expectErrorId = -1;
} else {
expectDetails.append("Error Id expected:"+expectErrorId+
" got:"+id);
expectDetails.append("\r\n");
}
}
if (expectErrorId == -1)
expects[TEST_ERROR] = false;
if (useLowLevel) {
if (delayResponse) {
synchronized (syncObj) {
syncObj.notifyAll();
}
} else {
if (netRunner != null) {
System.out.println("TestEventHandler: endData() stopping "+
netRunner);
netRunner.decrementRunCount();
}
}
}
|
public boolean | evaluateHeader(android.core.TestEventHandler$TestHeader h, java.lang.String value)
if (value == null) {
expects[TEST_HEADERS] = true;
System.out.print(" Missing! ");
expectDetails.append(" missing header " + h.name);
return false;
}
if (h.value == null) {
System.out.println("Expect value = null");
return true;
}
System.out.println("Expect value = " +
(h.value.toLowerCase()) + " got " +
value.toLowerCase());
if (!h.value.equalsIgnoreCase(value)) {
expectDetails.append("expect header value " + h.value +
" got " + value);
expects[TEST_HEADERS] = true;
return false;
}
return true;
|
public void | expectData()
expects[TEST_DATA] = true;
|
public void | expectData(int len)
expects[TEST_DATA] = true;
expectDataLength = len;
|
public void | expectData(byte[] data, int len)
expects[TEST_DATA] = true;
expectData = new byte[len];
expectDataLength = len;
for (int i = 0; i < len; i++) {
expectData[i] = data[i];
}
|
public void | expectEndData()
expects[TEST_ENDDATA] = true;
|
public void | expectError()
expects[TEST_ERROR] = true;
|
public void | expectError(int errorId)
expects[TEST_ERROR] = true;
expectErrorId = errorId;
|
public void | expectHeaderAdd(java.lang.String name)
expects[TEST_HEADERS] = true;
TestHeader h = new TestHeader(name.toLowerCase(), null);
expectHeaders.add(h);
|
public void | expectHeaderAdd(java.lang.String name, java.lang.String value)
expects[TEST_HEADERS] = true;
TestHeader h = new TestHeader(name.toLowerCase(), value);
expectHeaders.add(h);
|
public void | expectHeaders()
expects[TEST_HEADERS] = true;
|
public void | expectLocationChanged()
expects[TEST_LOCATION_CHANGED] = true;
|
public void | expectLocationChanged(java.lang.String newLocation)
expects[TEST_LOCATION_CHANGED] = true;
expectLocation = newLocation;
|
public void | expectLocationChanged(java.lang.String newLocation, boolean permanent)
expects[TEST_LOCATION_CHANGED] = true;
expectLocation = newLocation;
expectPermanent = permanent ? 1 : 0;
|
public void | expectNoData()
notExpecting[TEST_DATA] = true;
|
public void | expectNoEndData()
notExpecting[TEST_ENDDATA] = true;
|
public void | expectNoError()
notExpecting[TEST_ERROR] = true;
|
public void | expectNoHeaders()
notExpecting[TEST_HEADERS] = true;
|
public void | expectNoLocationChanged()
notExpecting[TEST_LOCATION_CHANGED] = true;
|
public void | expectNoRequestSent()
notExpecting[TEST_REQUEST_SENT] = true;
|
public void | expectNoSSLCertificateError()
notExpecting[TEST_SSL_CERTIFICATE_ERROR] = true;
|
public void | expectNoStatus()
notExpecting[TEST_STATUS] = true;
|
public boolean | expectPassed()Test to see if current expectations match recieved information
for (int i = 0; i < TEST_NUM_EXPECTS; i++) {
if (expects[i] == true) {
return false;
}
}
for (int i = 0; i < TEST_NUM_EXPECTS; i++) {
if (eventsReceived[i] && notExpecting[i]) {
return false;
}
}
return true;
|
public void | expectRequestSent()
expects[TEST_REQUEST_SENT] = true;
|
public void | expectSSLCertificateError()
expects[TEST_SSL_CERTIFICATE_ERROR] = true;
|
public void | expectSSLCertificateError(int errors)
expects[TEST_SSL_CERTIFICATE_ERROR] = true;
expectSslErrors = errors;
|
public void | expectSSLCertificateError(SslCertificate certificate)
expects[TEST_SSL_CERTIFICATE_ERROR] = true;
expectCertificate = certificate;
|
public void | expectStatus()
expects[TEST_STATUS] = true;
|
public void | expectStatus(int major, int minor, int code)
expects[TEST_STATUS] = true;
expectMajor = major;
expectMinor = minor;
expectCode = code;
|
public void | expectStatus(int code)
expects[TEST_STATUS] = true;
expectCode = code;
|
public java.lang.String | getFailureMessage()Return message indicating expectation failures
return expectDetails.toString();
|
public boolean | handleSslErrorRequest(SslError error)SSL certificate error callback. Handles SSL error(s) on the way
up to the user.
int primaryError = error.getPrimaryError();
if (false) {
Log.v(LOGTAG, "TestEventHandler: handleSslErrorRequest(): "+
" primary error:" + primaryError +
" certificate: " + error.getCertificate());
}
eventsReceived[TEST_SSL_CERTIFICATE_ERROR] = true;
if (notExpecting[TEST_SSL_CERTIFICATE_ERROR]) {
expectDetails.append("SSL Certificate error event received "+
"but not expected");
expectDetails.append("\r\n");
}
if (expectSslErrors != -1) {
if (expectSslErrors == primaryError) {
expectSslErrors = -1;
} else {
expectDetails.append("SslCertificateError id expected:"+
expectSslErrors+" got: " + primaryError);
expectDetails.append("\r\n");
}
}
// SslCertificate match here?
if (expectSslErrors == -1) // && expectSslCertificate == certificate?
expects[TEST_SSL_CERTIFICATE_ERROR] = false;
// return false so that we won't block the thread
return false;
|
public void | headers(Headers headers)Implements the EventHandler headers method called when a server
sends header fields
if (false) {
Log.v(LOGTAG, "TestEventHandler:headers()");
}
expects[TEST_HEADERS] = false;
if (notExpecting[TEST_HEADERS]) {
expectDetails.append("Header event received but not expected");
expectDetails.append("\r\n");
}
/* Check through headers received for matches with expected
* headers */
if (expectHeaders.isEmpty()) {
return;
}
for (int i = expectHeaders.size() - 1; i >= 0; i--) {
TestHeader h = expectHeaders.get(i);
System.out.println("Expected header name: " + h.name);
String s = null;
switch (h.name.hashCode()) {
case -1132779846:
s = Long.toString(headers.getContentLength());
break;
case 785670158:
s = headers.getContentType();
break;
case 2095084583:
s = headers.getContentEncoding();
break;
case 1901043637:
s = headers.getLocation();
break;
case -243037365:
s = headers.getWwwAuthenticate();
break;
case -301767724:
s = headers.getProxyAuthenticate();
break;
case -1267267485:
s = headers.getContentDisposition();
break;
case 1397189435:
s = headers.getAcceptRanges();
break;
case -1309235404:
s = headers.getExpires();
break;
case -208775662:
s = headers.getCacheControl();
break;
case 150043680:
s = headers.getLastModified();
break;
case 3123477:
s = headers.getEtag();
break;
case -775651618:
int ct = headers.getConnectionType();
if (ct == Headers.CONN_CLOSE) {
s = HTTP.CONN_CLOSE;
} else if (ct == Headers.CONN_KEEP_ALIVE) {
s = HTTP.CONN_KEEP_ALIVE;
}
break;
default:
s = null;
}
if (evaluateHeader(h, s)) {
expectHeaders.remove(i);
}
}
|
public void | locationChanged(java.lang.String newLocation, boolean permanent)Implements the EventHandler locationChanged method called when a server
sends a redirect message
if (false) {
Log.v(LOGTAG, "TestEventHandler: locationChanged() " +
newLocation + " permanent " + permanent);
}
eventsReceived[TEST_LOCATION_CHANGED] = true;
if (notExpecting[TEST_LOCATION_CHANGED]) {
expectDetails.append("Location changed event received but "+
"not expected");
expectDetails.append("\r\n");
}
if (expectLocation != null) {
if (expectLocation.equals(newLocation)) {
expectLocation = null;
} else {
expectDetails.append("Location expected:"+expectLocation+
" got:"+newLocation);
expectDetails.append("\r\n");
}
}
if (expectPermanent != -1) {
if (((expectPermanent == 0) && !permanent) ||
((expectPermanent == 1) && permanent)){
expectPermanent = -1;
} else {
expectDetails.append("Location permanent expected:"+
expectPermanent+" got"+permanent);
expectDetails.append("\r\n");
}
}
if ((expectLocation == null) && (expectPermanent == -1))
expects[TEST_LOCATION_CHANGED] = false;
|
public void | requestSent()Implementation of EventHandler method called when a request has been
sent. If the test is waiting for this call, it will be signalled,
otherwise this method will trigger the response to be read
automatically.
Log.v(LOGTAG, "TestEventHandler:requestSent()");
expects[TEST_REQUEST_SENT] = false;
eventsReceived[TEST_REQUEST_SENT] = true;
if (notExpecting[TEST_REQUEST_SENT]) {
expectDetails.append("Request sent event received but not expected");
expectDetails.append("\r\n");
}
if (useLowLevel) {
if (delayResponse) {
synchronized (syncObj) {
syncObj.notifyAll();
}
} else {
// mRequest.startReadingResponse();
}
}
|
public void | resetExpects()Reset all expectation values for re-use
expectMajor = -1;
expectMinor = -1;
expectCode = -1;
expectLocation = null;
expectPermanent = -1;
expectErrorId = -1;
expectSslErrors = -1;
expectCertificate = null;
expectDetails.setLength(0);
expectHeaders.clear();
for (int i = 0; i < TEST_NUM_EXPECTS; i++) {
expects[i] = false;
notExpecting[i] = false;
eventsReceived[i] = false;
}
for (int i = 0; i < expectDataLength; i++) {
expectData[i] = 0;
}
expectDataLength = -1;
|
public void | setNetRunner(LowLevelNetRunner runner)Use the low level net runner with no delayed response
setNetRunner(runner, false);
|
public void | setNetRunner(LowLevelNetRunner runner, boolean delayedResponse)Use the low level net runner and specify if the response
should be delayed
netRunner = runner;
useLowLevel = true;
delayResponse = delayedResponse;
if (!delayResponse)
netRunner.incrementRunCount();
|
public void | status(int major_version, int minor_version, int code, java.lang.String reason_phrase)Implements the EventHandler status method called when a server status
response is received.
if (false) {
Log.v(LOGTAG, "TestEventHandler:status() major: " + major_version +
" minor: " + minor_version +
" code: " + code +
" reason: " + reason_phrase);
}
eventsReceived[TEST_STATUS] = true;
if (notExpecting[TEST_STATUS]) {
expectDetails.append("Status event received but not expected");
expectDetails.append("\r\n");
}
majorVersion = major_version;
minorVersion = minor_version;
responseCode = code;
reasonPhrase = reason_phrase;
if (expectMajor != -1) {
if (expectMajor == major_version) {
expectMajor = -1;
} else {
expectDetails.append("Major version expected:"+expectMajor+
" got:"+major_version);
expectDetails.append("\r\n");
}
}
if (expectMinor != -1) {
if (expectMinor == minor_version) {
expectMinor = -1;
} else {
expectDetails.append("Minor version expected:"+expectMinor+
" got:"+minor_version);
expectDetails.append("\r\n");
}
}
if (expectCode != -1) {
if (expectCode == code) {
expectCode = -1;
} else {
expectDetails.append("Status code expected:"+expectCode+
" got:"+code);
expectDetails.append("\r\n");
}
}
if ((expectMajor == -1) && (expectMinor == -1) && (expectCode == -1)) {
expects[TEST_STATUS] = false;
} else {
System.out.println("MAJOR = "+expectMajor+" MINOR = "+expectMinor+
" CODE = "+expectCode);
}
|
public void | waitForRequestResponse()Enable this listeners Request object to read server responses.
This should only be used in conjunction with setDelayResponse(true)
if (!delayResponse || !useLowLevel) {
Log.d(LOGTAG, " Cant do this without delayReponse set ");
return;
}
//if (mRequest != null) {
// mRequest.startReadingResponse();
// }
/* Now wait for the response to be completed either through endData
* or an error
*/
synchronized (syncObj) {
try {
syncObj.wait();
} catch (InterruptedException e) {
}
}
|
public void | waitForRequestSent()Enable this listeners Request object to read server responses.
This should only be used in conjunction with setDelayResponse(true)
if (!delayResponse || !useLowLevel) {
Log.d(LOGTAG, " Cant do this without delayReponse set ");
return;
}
/* Now wait for the response to be completed either through endData
* or an error
*/
synchronized (syncObj) {
try {
syncObj.wait();
} catch (InterruptedException e) {
}
}
|