1
// nsIHttpChannelTests.cpp : implementation file
6
#include "nsIHttpChannelTests.h"
7
#include "BrowserImpl.h"
8
#include "BrowserFrm.h"
10
#include "ProfileMgr.h"
11
#include "ProfilesDlg.h"
14
#include "nsichanneltests.h"
15
#include "nsIHttpHeaderVisitor.h"
20
static char THIS_FILE[] = __FILE__;
23
/////////////////////////////////////////////////////////////////////////////
24
// nsIHttpChannelTests
26
CnsIHttpChannelTests::CnsIHttpChannelTests(nsIWebBrowser *mWebBrowser,
27
CBrowserImpl *mpBrowserImpl)
29
qaWebBrowser = mWebBrowser;
30
qaBrowserImpl = mpBrowserImpl;
33
CnsIHttpChannelTests::~CnsIHttpChannelTests()
37
class HeaderVisitor : public nsIHttpHeaderVisitor
41
NS_DECL_NSIHTTPHEADERVISITOR
44
virtual ~HeaderVisitor() {}
47
NS_IMPL_ISUPPORTS1(HeaderVisitor, nsIHttpHeaderVisitor)
50
HeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value)
52
FormatAndPrintOutput("VisitHeader header = ", PromiseFlatCString(header).get(), 1);
53
FormatAndPrintOutput("VisitHeader value = ", PromiseFlatCString(value).get(), 1);
57
/////////////////////////////////////////////////////////////////////////////
58
// CnsIHttpChannelTests message handlers
60
nsIHttpChannel * CnsIHttpChannelTests::GetHttpChannelObject(nsCAutoString theSpec)
62
NS_NewURI(getter_AddRefs(theURI), theSpec);
64
QAOutput("Didn't get URI object. Test failed.", 2);
65
NS_NewChannel(getter_AddRefs(theChannel), theURI, nsnull, nsnull);
67
QAOutput("Didn't get Channel object. GetChannelObject Test failed.", 2);
69
theHttpChannel = do_QueryInterface(theChannel);
71
QAOutput("Didn't get httpChannel object. Test failed.", 2);
73
return theHttpChannel;
76
void CnsIHttpChannelTests::OnStartTests(UINT nMenuID)
78
theSpec = "http://www.netscape.com";
79
theHttpChannel = GetHttpChannelObject(theSpec);
82
QAOutput("Didn't get nsIHttpChannel object. Test not run.", 1);
87
case ID_INTERFACES_NSIHTTPCHANNEL_RUNALLTESTS :
90
case ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTMETHOD :
91
SetRequestMethodTest(theHttpChannel, "PUT", 2);
93
case ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTMETHOD :
94
GetRequestMethodTest(theHttpChannel, 2);
96
case ID_INTERFACES_NSIHTTPCHANNEL_SETREFERRER :
97
SetReferrerTest(theHttpChannel, "https://www.sun.com", 2);
99
case ID_INTERFACES_NSIHTTPCHANNEL_GETREFERRER :
100
GetReferrerTest(theHttpChannel, 2);
102
case ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTHEADER :
103
SetRequestHeaderTest(theHttpChannel, "Content-Type", "text/html", 2);
105
case ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTHEADER :
106
GetRequestHeaderTest(theHttpChannel, "Content-Type", 2);
108
case ID_INTERFACES_NSIHTTPCHANNEL_VISITREQUESTHEADERS :
109
VisitRequestHeadersTest(theHttpChannel, 2);
111
case ID_INTERFACES_NSIHTTPCHANNEL_SETALLOWPIPELINING :
112
SetAllowPipeliningTest(theHttpChannel, PR_FALSE, 2);
114
case ID_INTERFACES_NSIHTTPCHANNEL_GETALLOWPIPELINING :
115
GetAllowPipeliningTest(theHttpChannel, 2);
117
case ID_INTERFACES_NSIHTTPCHANNEL_SETREDIRECTIONLIMIT :
118
SetRedirectionLimitTest(theHttpChannel, 100, 2);
120
case ID_INTERFACES_NSIHTTPCHANNEL_GETREDIRECTIONLIMIT :
121
GetRedirectionLimitTest(theHttpChannel, 2);
126
case ID_INTERFACES_NSIHTTPCHANNEL_GETRESPONSESTATUS :
127
GetResponseStatusTest(theHttpChannel, 2);
129
case ID_INTERFACES_NSIHTTPCHANNEL_GETRESPONSESTATUSTEXT :
130
GetResponseStatusTextTest(theHttpChannel, 2);
135
void CnsIHttpChannelTests::RunAllTests()
137
theSpec = "http://www.netscape.com";
138
theHttpChannel = GetHttpChannelObject(theSpec);
141
QAOutput("Didn't get nsIHttpChannel object. RunAllTests not run.", 1);
144
QAOutput(" nsIHttpChannel request tests:");
145
SetRequestMethodTest(theHttpChannel, "POST", 1);
146
GetRequestMethodTest(theHttpChannel, 1);
147
SetRequestMethodTest(theHttpChannel, "HEAD", 1);
148
GetRequestMethodTest(theHttpChannel, 1);
149
SetReferrerTest(theHttpChannel, "http://www.cisco.com", 1);
150
GetReferrerTest(theHttpChannel, 1);
151
SetRequestHeaderTest(theHttpChannel, "Cookie", "TheCookie", 1);
152
GetRequestHeaderTest(theHttpChannel, "Cookie", 1);
153
SetRequestHeaderTest(theHttpChannel, "Content-Type", "text/xml", 1);
154
GetRequestHeaderTest(theHttpChannel, "Content-Type", 1);
155
SetRequestHeaderTest(theHttpChannel, "Content-Length", "10000", 1);
156
GetRequestHeaderTest(theHttpChannel, "Content-Length", 1);
157
VisitRequestHeadersTest(theHttpChannel, 1);
158
SetAllowPipeliningTest(theHttpChannel, PR_FALSE, 1);
159
SetAllowPipeliningTest(theHttpChannel, PR_TRUE, 1);
160
GetAllowPipeliningTest(theHttpChannel, 1);
161
SetRedirectionLimitTest(theHttpChannel, 0, 1);
162
SetRedirectionLimitTest(theHttpChannel, 5, 1);
163
GetRedirectionLimitTest(theHttpChannel, 1);
165
// see nsIRequestObserver->OnStartRequest for Successful response tests
166
CnsIChannelTests *channelObj = new CnsIChannelTests(qaWebBrowser, qaBrowserImpl);
169
QAOutput("Didn't get nsIHttpChannel object. GetChannelObject not run.", 1);
172
theChannel = channelObj->GetChannelObject(theSpec);
175
QAOutput("Didn't get nsIChannel object. AsyncOpenTest not run.", 1);
178
channelObj->AsyncOpenTest(theChannel, 1);
182
void CnsIHttpChannelTests::SetRequestMethodTest(nsIHttpChannel *theHttpChannel,
183
const char * requestType,
187
// try "GET", "PUT", "HEAD", or "POST"
190
QAOutput("Didn't get nsIHttpChannel object. SetRequestMethodTest failed.", displayMode);
193
rv = theHttpChannel->SetRequestMethod(nsDependentCString(requestType));
194
RvTestResult(rv, "SetRequestMethod()", displayMode);
195
RvTestResultDlg(rv, "SetRequestMethod() test", true);
198
void CnsIHttpChannelTests::GetRequestMethodTest(nsIHttpChannel *theHttpChannel,
202
nsCAutoString method;
206
QAOutput("Didn't get nsIHttpChannel object. GetRequestMethodTest failed.", displayMode);
209
rv = theHttpChannel->GetRequestMethod(method);
210
RvTestResult(rv, "GetRequestMethod()", displayMode);
211
RvTestResultDlg(rv, "GetRequestMethod() test");
212
// if (method.Equals("POST")
213
FormatAndPrintOutput("GetRequestMethod method = ", method, displayMode);
216
void CnsIHttpChannelTests::SetReferrerTest(nsIHttpChannel *theHttpChannel,
221
nsCAutoString theSpec;
226
QAOutput("Didn't get nsIHttpChannel object. SetReferrerTest failed.", displayMode);
229
NS_NewURI(getter_AddRefs(theURI), theSpec);
231
QAOutput("Didn't get URI object. Test failed.", 2);
232
rv = theHttpChannel->SetReferrer(theURI);
233
RvTestResult(rv, "SetReferrer()", displayMode);
234
RvTestResultDlg(rv, "SetReferrer() test");
237
void CnsIHttpChannelTests::GetReferrerTest(nsIHttpChannel *theHttpChannel,
241
nsCAutoString theSpec;
245
QAOutput("Didn't get nsIHttpChannel object. GetReferrerTest failed.", displayMode);
248
rv = theHttpChannel->GetReferrer(getter_AddRefs(theURI));
249
RvTestResult(rv, "GetReferrer()", displayMode);
250
RvTestResultDlg(rv, "GetReferrer() test");
252
QAOutput("Didn't get nsIURI object. Test failed.", displayMode);
254
theURI->GetSpec(theSpec);
255
FormatAndPrintOutput("GetReferrerTest uri = ", theSpec, displayMode);
259
void CnsIHttpChannelTests::SetRequestHeaderTest(nsIHttpChannel *theHttpChannel,
260
const char *requestType,
261
const char *headerVal,
265
// try {"Content-Type","text/xml"}, {"Content-Length", 10000}, and
266
// {"Accept"), NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
269
QAOutput("Didn't get nsIHttpChannel object. SetRequestHeaderTest failed.", displayMode);
272
rv = theHttpChannel->SetRequestHeader(nsDependentCString(requestType),
273
nsDependentCString(headerVal),
275
RvTestResult(rv, "SetRequestHeader()", displayMode);
276
RvTestResultDlg(rv, "SetRequestHeader() test");
279
void CnsIHttpChannelTests::GetRequestHeaderTest(nsIHttpChannel *theHttpChannel,
280
const char *requestType,
284
nsCAutoString header;
285
// could be set to "referrer"
289
QAOutput("Didn't get nsIHttpChannel object. GetRequestHeaderTest failed.", displayMode);
292
rv = theHttpChannel->GetRequestHeader(nsDependentCString(requestType), header);
293
RvTestResult(rv, "GetRequestHeader()", displayMode);
294
RvTestResultDlg(rv, "GetRequestHeader() test");
295
FormatAndPrintOutput("GetRequestHeader type = ", header, displayMode);
298
void CnsIHttpChannelTests::VisitRequestHeadersTest(nsIHttpChannel *theHttpChannel,
301
// visitRequestHeaders()
304
QAOutput("Didn't get nsIHttpChannel object. VisitRequestHeadersTest failed.", displayMode);
307
HeaderVisitor *theVisitor = new HeaderVisitor();
309
QAOutput("Didn't get nsIHttpHeaderVisitor object. Test failed.", displayMode);
311
rv = theHttpChannel->VisitRequestHeaders(theVisitor);
312
RvTestResult(rv, "VisitRequestHeaders()", displayMode);
313
RvTestResultDlg(rv, "VisitRequestHeaders() test");
316
void CnsIHttpChannelTests::SetAllowPipeliningTest(nsIHttpChannel *theHttpChannel,
317
PRBool mAllowPipelining,
322
QAOutput("Didn't get nsIHttpChannel object. SetAllowPipeliningTest failed.", displayMode);
325
rv = theHttpChannel->SetAllowPipelining(mAllowPipelining);
326
RvTestResult(rv, "SetAllowPipelining()", displayMode);
327
RvTestResultDlg(rv, "SetAllowPipelining() test");
328
FormatAndPrintOutput("SetAllowPipelining value = ", mAllowPipelining, displayMode);
330
rv = theHttpChannel->GetAllowPipelining(&mAllowPipelining);
331
FormatAndPrintOutput("GetAllowPipelining value = ", mAllowPipelining, displayMode);
334
void CnsIHttpChannelTests::GetAllowPipeliningTest(nsIHttpChannel *theHttpChannel,
337
PRBool mAllowPipelining;
341
QAOutput("Didn't get nsIHttpChannel object. GetAllowPipeliningTest failed.", displayMode);
344
rv = theHttpChannel->GetAllowPipelining(&mAllowPipelining);
345
RvTestResult(rv, "GetAllowPipelining()", displayMode);
346
RvTestResultDlg(rv, "GetAllowPipelining() test");
347
FormatAndPrintOutput("GetAllowPipelining value = ", mAllowPipelining, displayMode);
350
void CnsIHttpChannelTests::SetRedirectionLimitTest(nsIHttpChannel *theHttpChannel,
351
PRUint32 mRedirectionLimit,
356
QAOutput("Didn't get nsIHttpChannel object. SetRedirectionLimitTest failed.", displayMode);
359
rv = theHttpChannel->SetRedirectionLimit(mRedirectionLimit);
360
RvTestResult(rv, "SetRedirectionLimit()", displayMode);
361
RvTestResultDlg(rv, "SetRedirectionLimit() test");
364
void CnsIHttpChannelTests::GetRedirectionLimitTest(nsIHttpChannel *theHttpChannel,
367
PRUint32 mRedirectionLimit;
371
QAOutput("Didn't get nsIHttpChannel object. GetRedirectionLimitTest failed.", displayMode);
374
rv = theHttpChannel->GetRedirectionLimit(&mRedirectionLimit);
375
RvTestResult(rv, "GetRedirectionLimit()", displayMode);
376
RvTestResultDlg(rv, "GetRedirectionLimit() test");
377
FormatAndPrintOutput("GetRedirectionLimit value = ", mRedirectionLimit, displayMode);
381
// called from OnStartRequest
383
void CnsIHttpChannelTests::CallResponseTests(nsIHttpChannel *theHttpChannel,
386
GetResponseStatusTest(theHttpChannel, displayMode);
387
GetResponseStatusTextTest(theHttpChannel, displayMode);
388
GetRequestSucceededTest(theHttpChannel, displayMode);
389
GetResponseHeaderTest(theHttpChannel, "Set-Cookie", displayMode);
390
SetResponseHeaderTest(theHttpChannel, "Refresh", "1001", PR_TRUE, displayMode);
391
GetResponseHeaderTest(theHttpChannel, "Refresh", displayMode);
392
SetResponseHeaderTest(theHttpChannel, "Set-Cookie", "MyCookie", PR_TRUE, displayMode);
393
GetResponseHeaderTest(theHttpChannel, "Set-Cookie", displayMode);
394
SetResponseHeaderTest(theHttpChannel, "Cache-control", "no-cache", PR_FALSE, displayMode);
395
GetResponseHeaderTest(theHttpChannel, "Cache-control", displayMode);
396
VisitResponseHeaderTest(theHttpChannel, displayMode);
397
IsNoStoreResponseTest(theHttpChannel, displayMode);
398
IsNoCacheResponseTest(theHttpChannel, displayMode);
401
void CnsIHttpChannelTests::GetResponseStatusTest(nsIHttpChannel *theHttpChannel,
404
PRUint32 mResponseStatus;
408
QAOutput("Didn't get nsIHttpChannel object. GetResponseStatusTest failed.", displayMode);
411
rv = theHttpChannel->GetResponseStatus(&mResponseStatus);
412
RvTestResult(rv, "GetResponseStatus()", displayMode);
413
FormatAndPrintOutput("GetResponseStatus value = ", mResponseStatus, displayMode);
416
void CnsIHttpChannelTests::GetResponseStatusTextTest(nsIHttpChannel *theHttpChannel,
423
QAOutput("Didn't get nsIHttpChannel object. GetResponseStatusTextTest failed.", displayMode);
426
rv = theHttpChannel->GetResponseStatusText(mText);
427
RvTestResult(rv, "GetResponseStatusText()", displayMode);
428
FormatAndPrintOutput("GetResponseStatusText = ", mText, displayMode);
432
void CnsIHttpChannelTests::GetRequestSucceededTest(nsIHttpChannel *theHttpChannel,
439
QAOutput("Didn't get nsIHttpChannel object. GetRequestSucceededTest failed.", displayMode);
442
rv = theHttpChannel->GetRequestSucceeded(&mRequest);
443
RvTestResult(rv, "GetRequestSucceeded()", displayMode);
444
FormatAndPrintOutput("GetRequestSucceeded = ", mRequest, displayMode);
447
void CnsIHttpChannelTests::GetResponseHeaderTest(nsIHttpChannel *theHttpChannel,
448
const char * responseType,
451
nsCAutoString mResponse;
455
QAOutput("Didn't get nsIHttpChannel object. GetResponseHeaderTest failed.", displayMode);
458
rv = theHttpChannel->GetResponseHeader(nsDependentCString(responseType), mResponse);
459
RvTestResult(rv, "GetResponseHeader()", displayMode);
460
FormatAndPrintOutput("GetResponseHeader = ", mResponse, displayMode);
461
FormatAndPrintOutput("GetResponseHeader response type = ", responseType, displayMode);
464
void CnsIHttpChannelTests::SetResponseHeaderTest(nsIHttpChannel *theHttpChannel,
465
const char * responseType,
467
PRBool merge, PRInt16 displayMode)
471
QAOutput("Didn't get nsIHttpChannel object. SetResponseHeaderTest failed.", displayMode);
474
rv = theHttpChannel->SetResponseHeader(nsDependentCString(responseType),
475
nsDependentCString(value), merge);
476
RvTestResult(rv, "SetResponseHeader()", displayMode);
477
FormatAndPrintOutput("SetResponseHeader value = ", value, displayMode);
478
FormatAndPrintOutput("SetResponseHeader response type = ", responseType, displayMode);
481
void CnsIHttpChannelTests::VisitResponseHeaderTest(nsIHttpChannel *theHttpChannel,
486
QAOutput("Didn't get nsIHttpChannel object. VisitResponseHeaderTest failed.", displayMode);
489
// visitResponseHeaders()
490
HeaderVisitor *theVisitor = new HeaderVisitor();
492
QAOutput("Didn't get nsIHttpHeaderVisitor object. Test failed.", displayMode);
494
rv = theHttpChannel->VisitResponseHeaders(theVisitor);
495
RvTestResult(rv, "VisitResponseHeaders()", displayMode);
498
void CnsIHttpChannelTests::IsNoStoreResponseTest(nsIHttpChannel *theHttpChannel,
505
QAOutput("Didn't get nsIHttpChannel object. IsNoStoreResponseTest failed.", displayMode);
508
rv = theHttpChannel->IsNoStoreResponse(&mNoResponse);
509
RvTestResult(rv, "IsNoStoreResponse()", displayMode);
510
FormatAndPrintOutput("IsNoStoreResponse = ", mNoResponse, displayMode);
513
void CnsIHttpChannelTests::IsNoCacheResponseTest(nsIHttpChannel *theHttpChannel,
520
QAOutput("Didn't get nsIHttpChannel object. IsNoCacheResponseTest failed.", displayMode);
523
rv = theHttpChannel->IsNoCacheResponse(&mNoResponse);
524
RvTestResult(rv, "IsNoCacheResponse()", displayMode);
525
FormatAndPrintOutput("IsNoCacheResponse = ", mNoResponse, displayMode);
b'\\ No newline at end of file'