From d3594ece0111a5ea04efd1318bc97fd843d4f861 Mon Sep 17 00:00:00 2001 From: "depstein%netscape.com" Date: Sat, 30 Jun 2001 00:26:31 +0000 Subject: [PATCH] Updated nsIRequest methods; added nsIStreamObserver implementations git-svn-id: svn://10.0.0.236/trunk@98338 18797224-902f-48f8-a5cc-f745e15eee43 --- .../embedding/qa/testembed/BrowserImpl.cpp | 46 ++- mozilla/embedding/qa/testembed/BrowserImpl.h | 22 +- .../qa/testembed/BrowserImplWebPrgrsLstnr.cpp | 15 +- mozilla/embedding/qa/testembed/Tests.cpp | 293 ++++++++++++++---- mozilla/embedding/qa/testembed/Tests.h | 8 + 5 files changed, 293 insertions(+), 91 deletions(-) diff --git a/mozilla/embedding/qa/testembed/BrowserImpl.cpp b/mozilla/embedding/qa/testembed/BrowserImpl.cpp index b1ec197083f..626f078bb41 100644 --- a/mozilla/embedding/qa/testembed/BrowserImpl.cpp +++ b/mozilla/embedding/qa/testembed/BrowserImpl.cpp @@ -18,7 +18,8 @@ * Rights Reserved. * * Contributor(s): - * Chak Nanga + * Chak Nanga + * David Epstein */ // File Overview.... @@ -68,6 +69,7 @@ #include "BrowserImpl.h" #include "QaUtils.h" +#include "Tests.h" CBrowserImpl::CBrowserImpl() { @@ -112,6 +114,8 @@ NS_INTERFACE_MAP_BEGIN(CBrowserImpl) NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsISHistoryListener) // de: added 5/11 + NS_INTERFACE_MAP_ENTRY(nsIStreamListener) // de: added 6/29 + NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) // de: added 6/29 NS_INTERFACE_MAP_END //***************************************************************************** @@ -142,6 +146,7 @@ NS_IMETHODIMP CBrowserImpl::SetStatus(PRUint32 aType, const PRUnichar* aStatus) return NS_ERROR_FAILURE; m_pBrowserFrameGlue->UpdateStatusBarText(aStatus); +// CQaUtils::QAOutput("nsIWebBrowserChrome::SetStatus().", 1); return NS_OK; } @@ -237,7 +242,7 @@ NS_IMETHODIMP CBrowserImpl::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) return NS_ERROR_FAILURE; m_pBrowserFrameGlue->SetBrowserFrameSize(aCX, aCY); - CQaUtils::QAOutput("nsIWebBrowserChrome::SizeBrowserTo(): Browser resized.", 1); + CQaUtils::QAOutput("nsIWebBrowserChrome::SizeBrowserTo(): Browser sized.", 1); return NS_OK; } @@ -386,3 +391,40 @@ NS_IMETHODIMP CBrowserImpl::SetVisibility(PRBool aVisibility) return NS_OK; } +//***************************************************************************** +// CBrowserImpl::nsIStreamListener (used for nsIRequest) + +NS_IMETHODIMP CBrowserImpl::OnDataAvailable(nsIRequest *request, + nsISupports *ctxt, nsIInputStream *input, + PRUint32 offset, PRUint32 count) +{ + CQaUtils::QAOutput("Inside OnDataAvailable()."); + CTests::IsPendingReqTest(request); + CTests::GetStatusReqTest(request); + + CTests::SuspendReqTest(request); + CQaUtils::QAOutput("nsIRequest: Between Suspend and Resume."); + CTests::ResumeReqTest(request); + +// CTests::CancelReqTest(request); + + nsCOMPtr theLoadGroup(do_CreateInstance(NS_LOADGROUP_CONTRACTID)); + CTests::SetLoadGroupTest(request, theLoadGroup); + CTests::GetLoadGroupTest(request); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnStartRequest(nsIRequest *request, + nsISupports *ctxt) +{ + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnStopRequest(nsIRequest *request, + nsISupports *ctxt, nsresult rv) +{ + return NS_OK; +} + +//***************************************************************************** diff --git a/mozilla/embedding/qa/testembed/BrowserImpl.h b/mozilla/embedding/qa/testembed/BrowserImpl.h index f433947c905..73a8cd6c71a 100644 --- a/mozilla/embedding/qa/testembed/BrowserImpl.h +++ b/mozilla/embedding/qa/testembed/BrowserImpl.h @@ -27,15 +27,16 @@ #include "IBrowserFrameGlue.h" #include "nsIWebBrowserChromeFocus.h" -class CBrowserImpl : public nsIInterfaceRequestor, - public nsIWebBrowserChrome, - public nsIWebBrowserChromeFocus, - public nsIEmbeddingSiteWindow, - public nsIWebProgressListener, - public nsIContextMenuListener, - public nsSupportsWeakReference, - public nsISHistoryListener - // de: added this in 5/11 +class CBrowserImpl : + public nsIInterfaceRequestor, + public nsIWebBrowserChrome, + public nsIWebBrowserChromeFocus, + public nsIEmbeddingSiteWindow, + public nsIWebProgressListener, + public nsIContextMenuListener, + public nsSupportsWeakReference, + public nsISHistoryListener, // de: added this in 5/11 + public nsIStreamListener // de: added this in 6/29 { public: CBrowserImpl(); @@ -52,7 +53,8 @@ public: NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSICONTEXTMENULISTENER NS_DECL_NSISHISTORYLISTENER // de: added this in 5/11 - + NS_DECL_NSISTREAMLISTENER // de: added this in 6/29 + NS_DECL_NSIREQUESTOBSERVER // de: added this in 6/29 protected: PBROWSERFRAMEGLUE m_pBrowserFrameGlue; diff --git a/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp b/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp index e3a4cf6538a..5994c0dfb45 100644 --- a/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp +++ b/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp @@ -136,10 +136,6 @@ NS_IMETHODIMP CBrowserImpl::OnStateChange(nsIWebProgress *progress, nsIRequest * strcpy(theStateType, "STATE_STOP"); displayMode = 2; - CTests::SuspendReqTest(request); // nsIRequest::Suspend() test - CQaUtils::QAOutput("Between Suspend and Resume."); - CTests::ResumeReqTest(request); // nsIRequest::Resume() test - m_pBrowserFrameGlue->UpdateBusyState(PR_FALSE); m_pBrowserFrameGlue->UpdateProgress(0, 100); // Clear the prog bar m_pBrowserFrameGlue->UpdateStatusBarText(nsnull); // Clear the status bar @@ -157,20 +153,13 @@ NS_IMETHODIMP CBrowserImpl::OnStateChange(nsIWebProgress *progress, nsIRequest * { strcpy(theStateType, "STATE_START"); - // nsIRequest tests + // a few nsIRequest tests CTests::IsPendingReqTest(request); CTests::GetStatusReqTest(request); CTests::SuspendReqTest(request); CQaUtils::QAOutput("Between Suspend and Resume."); CTests::ResumeReqTest(request); -/* -// CTests::CancelReqTest(request); - - nsCOMPtr theLoadGroup(do_CreateInstance(NS_LOADGROUP_CONTRACTID)); -// CTests::SetLoadGroupTest(request, theLoadGroup); // getting a crash. investigate! -// CTests::GetLoadGroupTest(request); -*/ } else if (progressStateFlags & STATE_REDIRECTING) strcpy(theStateType, "STATE_REDIRECTING"); @@ -296,7 +285,7 @@ CBrowserImpl::OnStatusChange(nsIWebProgress* aWebProgress, CQaUtils::RequestName(aRequest, stringMsg); // status result test -// CQaUtils::RvTestResult(aStatus, "OnStatusChange(): status result test", 2); + CQaUtils::RvTestResult(aStatus, "OnStatusChange(): status result test", 2); // web progress DOMWindow test CQaUtils::WebProgDOMWindowTest(aWebProgress, "OnStatusChange()", 1); diff --git a/mozilla/embedding/qa/testembed/Tests.cpp b/mozilla/embedding/qa/testembed/Tests.cpp index e780d15deb4..e2b76d769b7 100644 --- a/mozilla/embedding/qa/testembed/Tests.cpp +++ b/mozilla/embedding/qa/testembed/Tests.cpp @@ -608,8 +608,7 @@ void CTests::GetCountTest(nsISHistory *theSessionHistory, PRInt32 *numEntries) if (!(*numEntries)) CQaUtils::QAOutput("numEntries for GetCount() invalid. Test failed.", 1); else { - strMsg.Format("numEntries = %d", *numEntries); - AfxMessageBox(strMsg); + CQaUtils::FormatAndPrintOutput("number of entries = ", *numEntries, 2); CQaUtils::RvTestResult(rv, "GetCount() (count attribute) test", 2); } } @@ -635,8 +634,7 @@ void CTests::GetMaxLengthTest(nsISHistory *theSessionHistory, PRInt32 *theMaxLen if (!(*theMaxLength)) CQaUtils::QAOutput("theMaxLength for GetMaxLength() invalid. Test failed.", 1); else { - strMsg.Format("theMaxLength = %d", *theMaxLength); - AfxMessageBox(strMsg); + CQaUtils::FormatAndPrintOutput("theMaxLength = ", *theMaxLength, 2); CQaUtils::RvTestResult(rv, "GetMaxLength() (MaxLength attribute) test", 2); } } @@ -977,26 +975,65 @@ void CTests::GetSHTest() void CTests::OnInterfacesNsirequest() { - CUrlDialog myDialog; - nsCString stringMsg; - CQaUtils::QAOutput("Begin nsIRequest tests.", 2); + // note: individual nsIRequest tests are called in: + // 1) BrowserImplWebProgLstner.cpp, nsIWebProgressListener::OnStateChange(). + // 2) BrowserImpl.cpp, nsIStreamListener::OnDataAvailable() - if (myDialog.DoModal() == IDOK) + nsCString theSpec; + nsCOMPtr theURI; + nsCOMPtr theChannel; + nsCOMPtr theLoadGroup(do_CreateInstance(NS_LOADGROUP_CONTRACTID)); + nsCOMPtr theDefaultRequest; + + CQaUtils::QAOutput("Start nsIRequest tests.", 2); + + theSpec = "http://www.netscape.com"; + CQaUtils::FormatAndPrintOutput("the uri spec = ", theSpec, 2); + + rv = NS_NewURI(getter_AddRefs(theURI), theSpec); + if (!theURI) { - // add web prog listener to track requests & invoke nsIRequest methods - nsWeakPtr weakling( - dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, qaBrowserImpl)))); - qaWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener)); - - // invoke a request. request picked up in OnStateChange(). - strcpy(theUrl, myDialog.m_urlfield); - qaWebNav->LoadURI(NS_ConvertASCIItoUCS2(theUrl).GetUnicode(), - nsIWebNavigation::LOAD_FLAGS_NONE); + CQaUtils::QAOutput("We didn't get the URI. Test failed.", 1); + return; } + else + CQaUtils::RvTestResult(rv, "NS_NewURI", 1); + + rv = NS_OpenURI(getter_AddRefs(theChannel), theURI, nsnull, theLoadGroup); + if (!theChannel) + { + CQaUtils::QAOutput("We didn't get the Channel. Test failed.", 1); + return; + } + else if (!theLoadGroup) + { + CQaUtils::QAOutput("We didn't get the Load Group. Test failed.", 2); + return; + } + else + CQaUtils::RvTestResult(rv, "NS_OpenURI", 1); +/* + IsPendingReqTest(theChannel); + GetStatusReqTest(theChannel); + + SuspendReqTest(theChannel); + CQaUtils::QAOutput("nsIRequest: Between Suspend and Resume."); + ResumeReqTest(theChannel); + +// CancelReqTest(theChannel); + + SetLoadGroupTest(theChannel, theLoadGroup); + GetLoadGroupTest(theChannel); +*/ + + nsCOMPtr sListener(NS_STATIC_CAST(nsIStreamListener*, qaBrowserImpl)); + nsCOMPtr thisListener(dont_AddRef(NS_GetWeakReference(sListener))); + qaWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsIStreamListener)); + + rv = theChannel->AsyncOpen(sListener, nsnull); + CQaUtils::RvTestResult(rv, "AsyncOpen()", 1); - // note: individual nsIRequest tests are called in BrowserImplWebProgLstner.cpp, OnStateChange(). - } void CTests::IsPendingReqTest(nsIRequest *request) @@ -1073,101 +1110,225 @@ void CTests::GetLoadGroupTest(nsIRequest *request) CQaUtils::RvTestResult(rv, "nsIRequest:: LoadGroups' GetRequests() rv test", 1); } +// *********** 2nd set of implementations for nsIRequest methods ********* +// ******************* Using nsIChannel as the impl object *************** + +void CTests::IsPendingReqTest(nsIChannel *channel) +{ + PRBool reqPending; + nsresult rv; + + rv = channel->IsPending(&reqPending); + CQaUtils::RvTestResult(rv, "nsIRequest::IsPending() rv test", 1); + + if (!reqPending) + CQaUtils::QAOutput("Pending request = false.", 1); + else + CQaUtils::QAOutput("Pending request = true.", 1); +} + +void CTests::GetStatusReqTest(nsIChannel *channel) +{ + nsresult theStatusError; + nsresult rv; + + rv = channel->GetStatus(&theStatusError); + CQaUtils::RvTestResult(rv, "nsIRequest::GetStatus() test", 1); + CQaUtils::RvTestResult(rv, "the returned status error test", 1); + +} + +void CTests::SuspendReqTest(nsIChannel *channel) +{ + nsresult rv; + + rv = channel->Suspend(); + CQaUtils::RvTestResult(rv, "nsIRequest::Suspend() test", 1); +} + +void CTests::ResumeReqTest(nsIChannel *channel) +{ + nsresult rv; + + rv = channel->Resume(); + CQaUtils::RvTestResult(rv, "nsIRequest::Resume() test", 1); +} + +void CTests::CancelReqTest(nsIChannel *channel) +{ + nsresult rv; + nsresult status = NS_BINDING_ABORTED; + + rv = channel->Cancel(status); + CQaUtils::RvTestResult(rv, "nsIRequest::Cancel() rv test", 1); + CQaUtils::RvTestResult(status, "nsIRequest::Cancel() status test", 1); +} + +void CTests::SetLoadGroupTest(nsIChannel *channel, + nsILoadGroup *theLoadGroup) +{ + nsresult rv; + nsCOMPtr theSimpEnum; + + rv = channel->SetLoadGroup(theLoadGroup); + CQaUtils::RvTestResult(rv, "nsIRequest::SetLoadGroup() rv test", 1); +} + +void CTests::GetLoadGroupTest(nsIChannel *channel) +{ + nsCOMPtr theLoadGroup; + nsresult rv; + nsCOMPtr theSimpEnum; + + rv = channel->GetLoadGroup(getter_AddRefs(theLoadGroup)); + CQaUtils::RvTestResult(rv, "nsIRequest::GetLoadGroup() rv test", 1); + + rv = theLoadGroup->GetRequests(getter_AddRefs(theSimpEnum)); + CQaUtils::RvTestResult(rv, "nsIRequest:: LoadGroups' GetRequests() rv test", 1); +} + // *********************************************************************** //DHARMA - nsIClipboardCommands // Checking the paste() method. void CTests::OnPasteTest() { - // AfxMessageBox("testing paste command"); + CQaUtils::QAOutput("testing paste command", 1); nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->Paste(); + if (clipCmds) + { + rv = clipCmds->Paste(); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::Paste()' rv test", 1); + + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the copySelection() method. void CTests::OnCopyTest() { -// AfxMessageBox("testing copyselection command"); - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->CopySelection(); + CQaUtils::QAOutput("testing copyselection command"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->CopySelection(); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::CopySelection()' rv test", 1); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the selectAll() method. void CTests::OnSelectAllTest() { - AfxMessageBox("testing selectall method"); - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->SelectAll(); + CQaUtils::QAOutput("testing selectall method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->SelectAll(); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::SelectAll()' rv test", 1); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the selectNone() method. void CTests::OnSelectNoneTest() { - AfxMessageBox("testing selectnone method"); - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->SelectNone(); + CQaUtils::QAOutput("testing selectnone method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->SelectNone(); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::SelectNone()' rv test", 1); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the cutSelection() method. void CTests::OnCutSelectionTest() { -// AfxMessageBox("testing cutselection method"); - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->CutSelection(); + CQaUtils::QAOutput("testing cutselection method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->CutSelection(); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::CutSelection()' rv test", 1); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } + // Checking the copyLinkLocation() method. void CTests::copyLinkLocationTest() { -// AfxMessageBox("testing cutselection method"); - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->CopyLinkLocation(); + CQaUtils::QAOutput("testing CopyLinkLocation method", 2); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->CopyLinkLocation(); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::CopyLinkLocation()' rv test", 1); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the canCopySelection() method. void CTests::canCopySelectionTest() { - PRBool canCopySelection = PR_FALSE; - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->CanCopySelection(&canCopySelection); + PRBool canCopySelection = PR_FALSE; + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->CanCopySelection(&canCopySelection); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::CanCopySelection()' rv test", 1); - if(canCopySelection) - AfxMessageBox("The selection you made Can be copied"); - else - AfxMessageBox("Either you did not make a selection or The selection you made Cannot be copied"); + if(canCopySelection) + CQaUtils::QAOutput("The selection you made Can be copied", 2); + else + CQaUtils::QAOutput("Either you did not make a selection or The selection you made Cannot be copied", 2); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the canCutSelection() method. void CTests::canCutSelectionTest() { - PRBool canCutSelection = PR_FALSE; - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->CanCutSelection(&canCutSelection); + PRBool canCutSelection = PR_FALSE; + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->CanCutSelection(&canCutSelection); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::CanCutSelection()' rv test", 1); - if(canCutSelection) - AfxMessageBox("The selection you made Can be cut"); - else - AfxMessageBox("Either you did not make a selection or The selection you made Cannot be cut"); + if(canCutSelection) + CQaUtils::QAOutput("The selection you made Can be cut", 2); + else + CQaUtils::QAOutput("Either you did not make a selection or The selection you made Cannot be cut", 2); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } // Checking the canPaste() method. void CTests::canPasteTest() { - PRBool canPaste = PR_FALSE; - nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); - if (clipCmds) - clipCmds->CanPaste(&canPaste); + PRBool canPaste = PR_FALSE; + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + { + rv = clipCmds->CanPaste(&canPaste); + CQaUtils::RvTestResult(rv, "nsIClipboardCommands::CanPaste()' rv test", 1); - if(canPaste) - AfxMessageBox("The clipboard contents can be pasted here"); - else - AfxMessageBox("The clipboard contents cannot be pasted here"); + if(canPaste) + CQaUtils::QAOutput("The clipboard contents can be pasted here", 2); + else + CQaUtils::QAOutput("The clipboard contents cannot be pasted here", 2); + } + else + CQaUtils::QAOutput("We didn't get the clipboard object.", 1); } //DHARMA diff --git a/mozilla/embedding/qa/testembed/Tests.h b/mozilla/embedding/qa/testembed/Tests.h index d5d6f2a822e..352c586c354 100644 --- a/mozilla/embedding/qa/testembed/Tests.h +++ b/mozilla/embedding/qa/testembed/Tests.h @@ -159,6 +159,14 @@ public: void static CancelReqTest(nsIRequest *); void static SetLoadGroupTest(nsIRequest *, nsILoadGroup *); void static GetLoadGroupTest(nsIRequest *); + + void static IsPendingReqTest(nsIChannel *); + void static GetStatusReqTest(nsIChannel *); + void static SuspendReqTest(nsIChannel *); + void static ResumeReqTest(nsIChannel *); + void static CancelReqTest(nsIChannel *); + void static SetLoadGroupTest(nsIChannel *, nsILoadGroup *); + void static GetLoadGroupTest(nsIChannel *); }; #endif //_TESTS_H