Stronger error checking for nsIChannel and nsIHttpChannel tests. Not part of the build.

This commit is contained in:
depstein%netscape.com 2003-02-27 01:39:35 +00:00
Родитель 725c515f9a
Коммит ad45550bcb
3 изменённых файлов: 187 добавлений и 5 удалений

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

@ -552,10 +552,10 @@ NS_IMETHODIMP CBrowserImpl::OnStartRequest(nsIRequest *request,
obj->PostAsyncTests(channel, 1);
}
else if (!obj && ctxt)
QAOutput("No object to run PostAsyncTests().", 1);
QAOutput("No object to run PostAsyncTests() for nsIChannel.", 1);
if (!httpObj)
QAOutput("No object to run GetResponseStatusTest().", 1);
QAOutput("No object to run CallResponseTests() for nsIHttpChannel.", 1);
else
{
QAOutput(" nsIHttpChannel response tests:");

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

@ -125,6 +125,11 @@ nsIURI * CnsIChannelTests::GetURIObject(nsCAutoString theSpec)
void CnsIChannelTests::SetOriginalURITest(nsIChannel *theChannel, nsCAutoString theSpec,
PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. SetOriginalURITest failed.", 2);
return;
}
theURI = GetURIObject(theSpec);
rv = theChannel->SetOriginalURI(theURI);
RvTestResult(rv, "SetOriginalURITest", displayMode);
@ -136,6 +141,11 @@ void CnsIChannelTests::SetOriginalURITest(nsIChannel *theChannel, nsCAutoString
void CnsIChannelTests::GetOriginalURITest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. GetOriginalURITest failed.", 2);
return;
}
rv = theChannel->GetOriginalURI(getter_AddRefs(theURI));
RvTestResult(rv, "GetOriginalURITest", displayMode);
if (displayMode == 1)
@ -150,6 +160,11 @@ void CnsIChannelTests::GetOriginalURITest(nsIChannel *theChannel, PRInt16 displa
void CnsIChannelTests::GetURITest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. GetURITest failed.", 2);
return;
}
rv = theChannel->GetURI(getter_AddRefs(theURI));
RvTestResult(rv, "GetURITest", displayMode);
if (displayMode == 1)
@ -164,6 +179,11 @@ void CnsIChannelTests::GetURITest(nsIChannel *theChannel, PRInt16 displayMode)
void CnsIChannelTests::SetOwnerTest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. SetOwnerTest failed.", 2);
return;
}
theSupports = do_QueryInterface(qaWebBrowser);
rv = theChannel->SetOwner(theChannel);
RvTestResult(rv, "SetOwner", displayMode);
@ -175,6 +195,11 @@ void CnsIChannelTests::SetOwnerTest(nsIChannel *theChannel, PRInt16 displayMode)
void CnsIChannelTests::GetOwnerTest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. GetOwnerTest failed.", 2);
return;
}
rv = theChannel->GetOwner(getter_AddRefs(theSupports));
RvTestResult(rv, "GetOwner", displayMode);
if (displayMode == 1)
@ -185,6 +210,11 @@ void CnsIChannelTests::GetOwnerTest(nsIChannel *theChannel, PRInt16 displayMode)
void CnsIChannelTests::SetNotificationsTest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. SetNotificationsTest failed.", 2);
return;
}
if (!qaWebBrowser)
{
QAOutput("Didn't get nsIWebBrowser object. SetNotificationsTest failed.", displayMode);
@ -201,6 +231,11 @@ void CnsIChannelTests::SetNotificationsTest(nsIChannel *theChannel, PRInt16 disp
void CnsIChannelTests::GetNotificationsTest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get Channel object. GetNotificationsTest failed.", 2);
return;
}
rv = theChannel->GetNotificationCallbacks(getter_AddRefs(theIRequestor));
RvTestResult(rv, "GetNotificationCallbacks", displayMode);
if (displayMode == 1)
@ -211,12 +246,12 @@ void CnsIChannelTests::GetNotificationsTest(nsIChannel *theChannel, PRInt16 disp
void CnsIChannelTests::GetSecurityInfoTest(nsIChannel *theChannel, PRInt16 displayMode)
{
theSupports = do_QueryInterface(qaWebBrowser);
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. GetSecurityInfoTest failed.", displayMode);
return;
}
theSupports = do_QueryInterface(qaWebBrowser);
rv = theChannel->GetSecurityInfo(getter_AddRefs(theSupports));
RvTestResult(rv, "GetSecurityInfo", displayMode);
if (!theSupports)
@ -225,6 +260,11 @@ void CnsIChannelTests::GetSecurityInfoTest(nsIChannel *theChannel, PRInt16 displ
void CnsIChannelTests::SetContentTypeTest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. SetContentTypeTest failed.", displayMode);
return;
}
rv = theChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
RvTestResult(rv, "SetContentType", displayMode);
}
@ -233,6 +273,11 @@ void CnsIChannelTests::GetContentTypeTest(nsIChannel *theChannel, PRInt16 displa
{
nsCAutoString contentType;
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. GetContentTypeTest failed.", displayMode);
return;
}
rv = theChannel->GetContentType(contentType);
RvTestResult(rv, "GetContentType", displayMode);
FormatAndPrintOutput("the content type = ", contentType, displayMode);
@ -242,6 +287,11 @@ void CnsIChannelTests::SetContentCharsetTest(nsIChannel *theChannel, PRInt16 dis
{
nsCAutoString charsetType;
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. SetContentCharsetTest failed.", displayMode);
return;
}
rv = theChannel->SetContentCharset(NS_LITERAL_CSTRING("ISO-8859-1"));
RvTestResult(rv, "SetContentCharset", displayMode);
}
@ -250,6 +300,11 @@ void CnsIChannelTests::GetContentCharsetTest(nsIChannel *theChannel, PRInt16 dis
{
nsCAutoString charsetType;
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. GetContentCharsetTest failed.", displayMode);
return;
}
rv = theChannel->GetContentCharset(charsetType);
RvTestResult(rv, "GetContentCharset", displayMode);
FormatAndPrintOutput("the charset type = ", charsetType, displayMode);
@ -260,6 +315,12 @@ void CnsIChannelTests::SetContentLengthTest(nsIChannel *theChannel, PRInt16 disp
PRInt32 contentLength;
contentLength = 10000;
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. SetContentLengthTest failed.", displayMode);
return;
}
rv = theChannel->SetContentLength(contentLength);
RvTestResult(rv, "SetContentLength", displayMode);
}
@ -268,6 +329,11 @@ void CnsIChannelTests::GetContentLengthTest(nsIChannel *theChannel, PRInt16 disp
{
PRInt32 contentLength;
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. GetContentLengthTest failed.", displayMode);
return;
}
rv = theChannel->GetContentLength(&contentLength);
RvTestResult(rv, "GetContentLength", displayMode);
FormatAndPrintOutput("the content length = ", contentLength, displayMode);
@ -275,6 +341,11 @@ void CnsIChannelTests::GetContentLengthTest(nsIChannel *theChannel, PRInt16 disp
void CnsIChannelTests::OpenTest(nsIChannel *theChannel, PRInt16 displayMode)
{
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. OpenTest failed.", displayMode);
return;
}
rv = theChannel->Open(getter_AddRefs(theInputStream));
RvTestResult(rv, "OpenTest", displayMode);
if (!theInputStream)
@ -286,7 +357,11 @@ void CnsIChannelTests::AsyncOpenTest(nsIChannel *theChannel, PRInt16 displayMode
nsCOMPtr<nsIStreamListener> listener(NS_STATIC_CAST(nsIStreamListener*, qaBrowserImpl));
nsCOMPtr<nsIWeakReference> thisListener(dont_AddRef(NS_GetWeakReference(listener)));
qaWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsIStreamListener));
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. AsyncOpenTest failed.", displayMode);
return;
}
if (!listener) {
QAOutput("Didn't get the stream listener object. AsyncOpenTest failed.", displayMode);
return;

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

@ -164,7 +164,17 @@ void CnsIHttpChannelTests::RunAllTests()
// see nsIRequestObserver->OnStartRequest for Successful response tests
CnsIChannelTests *channelObj = new CnsIChannelTests(qaWebBrowser, qaBrowserImpl);
if (!channelObj)
{
QAOutput("Didn't get nsIHttpChannel object. GetChannelObject not run.", 1);
return;
}
theChannel = channelObj->GetChannelObject(theSpec);
if (!theChannel)
{
QAOutput("Didn't get nsIChannel object. AsyncOpenTest not run.", 1);
return;
}
channelObj->AsyncOpenTest(theChannel, 1);
QAOutput("\n");
}
@ -175,6 +185,11 @@ void CnsIHttpChannelTests::SetRequestMethodTest(nsIHttpChannel *theHttpChannel,
{
// SetRequestMethod
// try "GET", "PUT", "HEAD", or "POST"
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. SetRequestMethodTest failed.", displayMode);
return;
}
rv = theHttpChannel->SetRequestMethod(nsDependentCString(requestType));
RvTestResult(rv, "SetRequestMethod()", displayMode);
RvTestResultDlg(rv, "SetRequestMethod() test", true);
@ -185,6 +200,12 @@ void CnsIHttpChannelTests::GetRequestMethodTest(nsIHttpChannel *theHttpChannel,
{
// GetRequestMethod
nsCAutoString method;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetRequestMethodTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetRequestMethod(method);
RvTestResult(rv, "GetRequestMethod()", displayMode);
RvTestResultDlg(rv, "GetRequestMethod() test");
@ -200,6 +221,11 @@ void CnsIHttpChannelTests::SetReferrerTest(nsIHttpChannel *theHttpChannel,
nsCAutoString theSpec;
theSpec = theUrl;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. SetReferrerTest failed.", displayMode);
return;
}
NS_NewURI(getter_AddRefs(theURI), theSpec);
if (!theURI)
QAOutput("Didn't get URI object. Test failed.", 2);
@ -214,6 +240,11 @@ void CnsIHttpChannelTests::GetReferrerTest(nsIHttpChannel *theHttpChannel,
// GetReferrer
nsCAutoString theSpec;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetReferrerTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetReferrer(getter_AddRefs(theURI));
RvTestResult(rv, "GetReferrer()", displayMode);
RvTestResultDlg(rv, "GetReferrer() test");
@ -233,6 +264,11 @@ void CnsIHttpChannelTests::SetRequestHeaderTest(nsIHttpChannel *theHttpChannel,
// SetRequestHeader
// try {"Content-Type","text/xml"}, {"Content-Length", 10000}, and
// {"Accept"), NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. SetRequestHeaderTest failed.", displayMode);
return;
}
rv = theHttpChannel->SetRequestHeader(nsDependentCString(requestType),
nsDependentCString(headerVal),
PR_FALSE);
@ -247,6 +283,12 @@ void CnsIHttpChannelTests::GetRequestHeaderTest(nsIHttpChannel *theHttpChannel,
// GetRequestHeader
nsCAutoString header;
// could be set to "referrer"
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetRequestHeaderTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetRequestHeader(nsDependentCString(requestType), header);
RvTestResult(rv, "GetRequestHeader()", displayMode);
RvTestResultDlg(rv, "GetRequestHeader() test");
@ -257,6 +299,11 @@ void CnsIHttpChannelTests::VisitRequestHeadersTest(nsIHttpChannel *theHttpChann
PRInt16 displayMode)
{
// visitRequestHeaders()
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. VisitRequestHeadersTest failed.", displayMode);
return;
}
HeaderVisitor *theVisitor = new HeaderVisitor();
if (!theVisitor)
QAOutput("Didn't get nsIHttpHeaderVisitor object. Test failed.", displayMode);
@ -270,6 +317,11 @@ void CnsIHttpChannelTests::SetAllowPipeliningTest(nsIHttpChannel *theHttpChanne
PRBool mAllowPipelining,
PRInt16 displayMode)
{
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. SetAllowPipeliningTest failed.", displayMode);
return;
}
rv = theHttpChannel->SetAllowPipelining(mAllowPipelining);
RvTestResult(rv, "SetAllowPipelining()", displayMode);
RvTestResultDlg(rv, "SetAllowPipelining() test");
@ -284,6 +336,11 @@ void CnsIHttpChannelTests::GetAllowPipeliningTest(nsIHttpChannel *theHttpChanne
{
PRBool mAllowPipelining;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetAllowPipeliningTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetAllowPipelining(&mAllowPipelining);
RvTestResult(rv, "GetAllowPipelining()", displayMode);
RvTestResultDlg(rv, "GetAllowPipelining() test");
@ -294,6 +351,11 @@ void CnsIHttpChannelTests::SetRedirectionLimitTest(nsIHttpChannel *theHttpChann
PRUint32 mRedirectionLimit,
PRInt16 displayMode)
{
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. SetRedirectionLimitTest failed.", displayMode);
return;
}
rv = theHttpChannel->SetRedirectionLimit(mRedirectionLimit);
RvTestResult(rv, "SetRedirectionLimit()", displayMode);
RvTestResultDlg(rv, "SetRedirectionLimit() test");
@ -304,6 +366,11 @@ void CnsIHttpChannelTests::GetRedirectionLimitTest(nsIHttpChannel *theHttpChann
{
PRUint32 mRedirectionLimit;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetRedirectionLimitTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetRedirectionLimit(&mRedirectionLimit);
RvTestResult(rv, "GetRedirectionLimit()", displayMode);
RvTestResultDlg(rv, "GetRedirectionLimit() test");
@ -336,6 +403,11 @@ void CnsIHttpChannelTests::GetResponseStatusTest(nsIHttpChannel *theHttpChannel,
{
PRUint32 mResponseStatus;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetResponseStatusTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetResponseStatus(&mResponseStatus);
RvTestResult(rv, "GetResponseStatus()", displayMode);
FormatAndPrintOutput("GetResponseStatus value = ", mResponseStatus, displayMode);
@ -346,6 +418,11 @@ void CnsIHttpChannelTests::GetResponseStatusTextTest(nsIHttpChannel *theHttpChan
{
nsCAutoString mText;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetResponseStatusTextTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetResponseStatusText(mText);
RvTestResult(rv, "GetResponseStatusText()", displayMode);
FormatAndPrintOutput("GetResponseStatusText = ", mText, displayMode);
@ -357,6 +434,11 @@ void CnsIHttpChannelTests::GetRequestSucceededTest(nsIHttpChannel *theHttpChanne
{
PRBool mRequest;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetRequestSucceededTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetRequestSucceeded(&mRequest);
RvTestResult(rv, "GetRequestSucceeded()", displayMode);
FormatAndPrintOutput("GetRequestSucceeded = ", mRequest, displayMode);
@ -368,6 +450,11 @@ void CnsIHttpChannelTests::GetResponseHeaderTest(nsIHttpChannel *theHttpChannel,
{
nsCAutoString mResponse;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. GetResponseHeaderTest failed.", displayMode);
return;
}
rv = theHttpChannel->GetResponseHeader(nsDependentCString(responseType), mResponse);
RvTestResult(rv, "GetResponseHeader()", displayMode);
FormatAndPrintOutput("GetResponseHeader = ", mResponse, displayMode);
@ -378,7 +465,12 @@ void CnsIHttpChannelTests::SetResponseHeaderTest(nsIHttpChannel *theHttpChannel,
const char * responseType,
const char * value,
PRBool merge, PRInt16 displayMode)
{ // Refresh
{
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. SetResponseHeaderTest failed.", displayMode);
return;
}
rv = theHttpChannel->SetResponseHeader(nsDependentCString(responseType),
nsDependentCString(value), merge);
RvTestResult(rv, "SetResponseHeader()", displayMode);
@ -389,6 +481,11 @@ void CnsIHttpChannelTests::SetResponseHeaderTest(nsIHttpChannel *theHttpChannel,
void CnsIHttpChannelTests::VisitResponseHeaderTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. VisitResponseHeaderTest failed.", displayMode);
return;
}
// visitResponseHeaders()
HeaderVisitor *theVisitor = new HeaderVisitor();
if (!theVisitor)
@ -403,6 +500,11 @@ void CnsIHttpChannelTests::IsNoStoreResponseTest(nsIHttpChannel *theHttpChannel,
{
PRBool mNoResponse;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. IsNoStoreResponseTest failed.", displayMode);
return;
}
rv = theHttpChannel->IsNoStoreResponse(&mNoResponse);
RvTestResult(rv, "IsNoStoreResponse()", displayMode);
FormatAndPrintOutput("IsNoStoreResponse = ", mNoResponse, displayMode);
@ -413,6 +515,11 @@ void CnsIHttpChannelTests::IsNoCacheResponseTest(nsIHttpChannel *theHttpChannel,
{
PRBool mNoResponse;
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. IsNoCacheResponseTest failed.", displayMode);
return;
}
rv = theHttpChannel->IsNoCacheResponse(&mNoResponse);
RvTestResult(rv, "IsNoCacheResponse()", displayMode);
FormatAndPrintOutput("IsNoCacheResponse = ", mNoResponse, displayMode);