Adding initial test cases for nsIHttpChannel iface. Not part of the build.

This commit is contained in:
depstein%netscape.com 2002-12-28 04:43:56 +00:00
parent fae823b4df
commit ba7deeffbe
9 changed files with 312 additions and 9 deletions

View File

@ -71,7 +71,8 @@ REQUIRES = \
$(NULL)
CPPSRCS = \
nsIChannelTests.cpp \
nsIHttpChannelTests.cpp \
nsIChannelTests.cpp \
TestEmbed.cpp \
BrowserFrm.cpp \
BrowserFrameGlue.cpp \

View File

@ -130,7 +130,7 @@
#include "nsCRT.h"
#include "nsIURILoader.h"
#include "nsCURILoader.h"
#include "nsIHttpHeaderVisitor.h"
#include "nsIEditingSession.h"
#include "nsICommandManager.h"
#include "nsICommandParams.h"

View File

@ -73,6 +73,7 @@
#include "QaUtils.h"
#include "nsIIOService.h"
#include "nsIChannelTests.h"
#include "nsIHttpChannelTests.h"
#include <stdio.h>
#ifdef _DEBUG
@ -294,6 +295,14 @@ BEGIN_MESSAGE_MAP(CTests, CWnd)
ON_COMMAND(ID_INTERFACES_NSICOMMANDPARAMS_HASMOREELEMENTS, OnInterfacesNsicmdparams)
ON_COMMAND(ID_INTERFACES_NSICOMMANDPARAMS_FIRST, OnInterfacesNsicmdparams)
ON_COMMAND(ID_INTERFACES_NSICOMMANDPARAMS_GETNEXT, OnInterfacesNsicmdparams)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_RUNALLTESTS ,OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTMETHOD, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTMETHOD, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_SETREFERRER, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_GETREFERRER, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTHEADER, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTHEADER, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_NSIHTTPCHANNEL_VISITREQUESTHEADERS, OnInterfacesNsihttpchannel)
ON_COMMAND(ID_INTERFACES_RUNALLTESTCASES, OnInterfacesRunalltestcases)
//}}AFX_MSG_MAP
@ -754,12 +763,6 @@ void CTests::OnToolsRemoveAllGH()
void CTests::OnToolsTestYourMethod()
{
// place your test code here
if (myDialog.DoModal() == IDOK)
{
rv = qaWebNav->GetCurrentURI(getter_AddRefs(theURI));
GetTheUri(theURI, 1);
}
}
// ***********************************************************************
@ -954,6 +957,12 @@ void CTests::OnInterfacesNsichannel()
oChannelTests.OnStartTests(nCommandID);
}
void CTests::OnInterfacesNsihttpchannel()
{
CnsIHttpChannelTests oHttpChannelTests(qaWebBrowser, qaBrowserImpl);
oHttpChannelTests.OnStartTests(nCommandID);
}
//Run all interface test cases in automation
@ -1026,4 +1035,7 @@ void CTests::OnInterfacesRunalltestcases()
CnsIChannelTests oChannelTests(qaWebBrowser, qaBrowserImpl);
oChannelTests.OnStartTests(ID_INTERFACES_NSICHANNEL_RUNALLTESTS);
CnsIHttpChannelTests oHttpChannelTests(qaWebBrowser, qaBrowserImpl);
oHttpChannelTests.OnStartTests(ID_INTERFACES_NSIHTTPCHANNEL_RUNALLTESTS);
}

View File

@ -152,6 +152,7 @@ protected:
afx_msg void OnInterfacesNsicmdparams();
afx_msg void OnInterfacesRunalltestcases();
afx_msg void OnInterfacesNsichannel();
afx_msg void OnInterfacesNsihttpchannel();
//}}AFX_MSG

View File

@ -0,0 +1,197 @@
// nsIHttpChannelTests.cpp : implementation file
//
#include "stdafx.h"
#include "testembed.h"
#include "nsIHttpChannelTests.h"
#include "BrowserImpl.h"
#include "BrowserFrm.h"
#include "UrlDialog.h"
#include "ProfileMgr.h"
#include "ProfilesDlg.h"
#include "QaUtils.h"
#include "Tests.h"
#include "nsichanneltests.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// nsIHttpChannelTests
CnsIHttpChannelTests::CnsIHttpChannelTests(nsIWebBrowser *mWebBrowser,
CBrowserImpl *mpBrowserImpl)
{
qaWebBrowser = mWebBrowser;
qaBrowserImpl = mpBrowserImpl;
}
CnsIHttpChannelTests::~CnsIHttpChannelTests()
{
}
/////////////////////////////////////////////////////////////////////////////
// CnsIHttpChannelTests message handlers
nsIHttpChannel * CnsIHttpChannelTests::GetHttpChannelObject(nsCAutoString theSpec)
{
NS_NewURI(getter_AddRefs(theURI), theSpec);
if (!theURI)
QAOutput("Didn't get URI object. Test failed.", 2);
NS_NewChannel(getter_AddRefs(theChannel), theURI, nsnull, nsnull);
if (!theChannel)
QAOutput("Didn't get Channel object. GetChannelObject Test failed.", 2);
theHttpChannel = do_QueryInterface(theChannel);
if (!theHttpChannel)
QAOutput("Didn't get httpChannel object. Test failed.", 2);
return theHttpChannel;
}
void CnsIHttpChannelTests::OnStartTests(UINT nMenuID)
{
theSpec = "http://www.netscape.com";
theHttpChannel = GetHttpChannelObject(theSpec);
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. Test not run.", 1);
return;
}
switch(nMenuID)
{
case ID_INTERFACES_NSIHTTPCHANNEL_RUNALLTESTS :
RunAllTests();
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTMETHOD :
SetRequestMethodTest(theHttpChannel, 2);
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTMETHOD :
GetRequestMethodTest(theHttpChannel, 2);
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_SETREFERRER :
SetReferrerTest(theHttpChannel, 2);
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_GETREFERRER :
GetReferrerTest(theHttpChannel, 2);
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTHEADER :
SetRequestHeaderTest(theHttpChannel, 2);
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTHEADER :
GetRequestHeaderTest(theHttpChannel, 2);
break ;
case ID_INTERFACES_NSIHTTPCHANNEL_VISITREQUESTHEADERS :
VisitRequestHeadersTest(theHttpChannel, 2);
break;
}
}
void CnsIHttpChannelTests::RunAllTests()
{
theSpec = "http://www.netscape.com";
theHttpChannel = GetHttpChannelObject(theSpec);
if (!theHttpChannel)
{
QAOutput("Didn't get nsIHttpChannel object. RunAllTests not run.", 1);
return;
}
SetRequestMethodTest(theHttpChannel, 1);
GetRequestMethodTest(theHttpChannel, 1);
SetReferrerTest(theHttpChannel, 1);
GetReferrerTest(theHttpChannel, 1);
SetRequestHeaderTest(theHttpChannel, 1);
GetRequestHeaderTest(theHttpChannel, 1);
VisitRequestHeadersTest(theHttpChannel, 1);
QAOutput("\n");
}
void CnsIHttpChannelTests::SetRequestMethodTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// SetRequestMethod
// try "GET", "PUT", "HEAD", or "POST"
rv = theHttpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
RvTestResult(rv, "SetRequestMethod()", displayMode);
}
void CnsIHttpChannelTests::GetRequestMethodTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// GetRequestMethod
nsCAutoString method;
rv = theHttpChannel->GetRequestMethod(method);
RvTestResult(rv, "GetRequestMethod()", displayMode);
// if (method.Equals("POST")
FormatAndPrintOutput("GetRequestMethod method = ", method, displayMode);
}
void CnsIHttpChannelTests::SetReferrerTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// SetReferrer
nsCAutoString theSpec;
theSpec = "http://www.cisco.com";
NS_NewURI(getter_AddRefs(theURI), theSpec);
if (!theURI)
QAOutput("Didn't get URI object. Test failed.", 2);
rv = theHttpChannel->SetReferrer(theURI);
RvTestResult(rv, "SetReferrer()", displayMode);
}
void CnsIHttpChannelTests::GetReferrerTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// GetReferrer
nsCAutoString theSpec;
rv = theHttpChannel->GetReferrer(getter_AddRefs(theURI));
RvTestResult(rv, "GetReferrer()", displayMode);
if (!theURI)
QAOutput("Didn't get nsIURI object. Test failed.", displayMode);
else {
theURI->GetSpec(theSpec);
FormatAndPrintOutput("GetReferrerTest uri = ", theSpec, displayMode);
}
}
void CnsIHttpChannelTests::SetRequestHeaderTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// SetRequestHeader
// try {"Content-Type","text/xml"}, {"Content-Length", 10000}, and
// {"Accept"), NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
const char *headerVal = "TheCookie";
rv = theHttpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cookie"),
nsDependentCString(headerVal),
PR_FALSE);
RvTestResult(rv, "SetRequestHeader()", displayMode);
}
void CnsIHttpChannelTests::GetRequestHeaderTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// GetRequestHeader
nsCAutoString header;
// could be set to "referrer"
rv = theHttpChannel->GetRequestHeader(NS_LITERAL_CSTRING("Cookie"), header);
RvTestResult(rv, "GetRequestHeader()", displayMode);
FormatAndPrintOutput("GetRequestHeader type = ", header, displayMode);
}
void CnsIHttpChannelTests::VisitRequestHeadersTest(nsIHttpChannel *theHttpChannel,
PRInt16 displayMode)
{
// visitRequestHeaders()
nsCOMPtr<nsIHttpHeaderVisitor> theVisitor;
if (!theVisitor)
QAOutput("Didn't get nsIHttpHeaderVisitor object. Test failed.", displayMode);
rv = theHttpChannel->VisitRequestHeaders(theVisitor);
RvTestResult(rv, "VisitRequestHeaders()", displayMode);
}

View File

@ -0,0 +1,64 @@
#if !defined(AFX_NSIHTTPCHANNELTESTS_H__A7985BC6_9A57_453F_BEE4_17A083131427__INCLUDED_)
#define AFX_NSIHTTPCHANNELTESTS_H__A7985BC6_9A57_453F_BEE4_17A083131427__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// nsIHttpChannelTests.h : header file
//
#include "Tests.h"
/////////////////////////////////////////////////////////////////////////////
// nsIHttpChannelTests window
class CnsIHttpChannelTests
{
// Construction
public:
CnsIHttpChannelTests(nsIWebBrowser* mWebBrowser, CBrowserImpl *mpBrowserImpl);
// Attributes
nsIHttpChannel * GetHttpChannelObject(nsCAutoString);
void OnStartTests(UINT nMenuID);
void RunAllTests();
void SetRequestMethodTest(nsIHttpChannel *, PRInt16);
void GetRequestMethodTest(nsIHttpChannel *, PRInt16);
void SetReferrerTest(nsIHttpChannel *, PRInt16);
void GetReferrerTest(nsIHttpChannel *, PRInt16);
void SetRequestHeaderTest(nsIHttpChannel *, PRInt16);
void GetRequestHeaderTest(nsIHttpChannel *, PRInt16);
void VisitRequestHeadersTest(nsIHttpChannel *, PRInt16 );
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(nsIHttpChannelTests)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CnsIHttpChannelTests();
// Generated message map functions
protected:
private:
CBrowserImpl *qaBrowserImpl;
nsCOMPtr<nsIWebBrowser> qaWebBrowser;
nsCOMPtr<nsIChannel> theChannel;
nsCOMPtr<nsIURI> theURI;
nsCOMPtr<nsIHttpChannel> theHttpChannel;
nsCAutoString theSpec;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_NSIHTTPCHANNELTESTS_H__A7985BC6_9A57_453F_BEE4_17A083131427__INCLUDED_)

View File

@ -292,6 +292,14 @@
#define ID_INTERFACES_NSICHANNEL_GETCONTENTLENGTH 33025
#define ID_INTERFACES_NSICHANNEL_OPEN 33026
#define ID_INTERFACES_NSICHANNEL_ASYNCOPEN 33027
#define ID_INTERFACES_NSIHTTPCHANNEL_RUNALLTESTS 33031
#define ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTMETHOD 33032
#define ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTMETHOD 33033
#define ID_INTERFACES_NSIHTTPCHANNEL_SETREFERRER 33034
#define ID_INTERFACES_NSIHTTPCHANNEL_GETREFERRER 33035
#define ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTHEADER 33036
#define ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTHEADER 33038
#define ID_INTERFACES_NSIHTTPCHANNEL_VISITREQUESTHEADERS 33039
#define ID_CLIPBOARDCMD_PASTE 42789
#define ID_CLIPBOARDCMD_COPYSELECTION 42790
#define ID_CLIPBOARDCMD_SELECTALL 42791
@ -308,7 +316,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 153
#define _APS_NEXT_COMMAND_VALUE 33028
#define _APS_NEXT_COMMAND_VALUE 33039
#define _APS_NEXT_CONTROL_VALUE 1033
#define _APS_NEXT_SYMED_VALUE 101
#endif

Binary file not shown.

View File

@ -640,6 +640,26 @@ BEGIN
MENUITEM "GetNext", ID_INTERFACES_NSICOMMANDPARAMS_GETNEXT
END
POPUP "nsIHttpChannel"
BEGIN
MENUITEM "Run All Tests", ID_INTERFACES_NSIHTTPCHANNEL_RUNALLTESTS
MENUITEM SEPARATOR
MENUITEM "SetRequestMethod", ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTMETHOD
MENUITEM "GetRequestMethod", ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTMETHOD
MENUITEM "SetReferrer", ID_INTERFACES_NSIHTTPCHANNEL_SETREFERRER
MENUITEM "GetReferrer", ID_INTERFACES_NSIHTTPCHANNEL_GETREFERRER
MENUITEM "SetRequestHeader", ID_INTERFACES_NSIHTTPCHANNEL_SETREQUESTHEADER
MENUITEM "GetRequestHeader", ID_INTERFACES_NSIHTTPCHANNEL_GETREQUESTHEADER
MENUITEM "VisitRequestHeaders", ID_INTERFACES_NSIHTTPCHANNEL_VISITREQUESTHEADERS
END
END
POPUP "T&ools"
BEGIN