Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / nsirequest.cpp
bloba951cf195efa36cd86a01cf5ecbac92d534ed004
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * David Epstein <depstein@netscape.com>
24 * Ashish Bhatt <ashishbhatt@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 // File Overview....
42 // Test cases for the nsiRequest Interface
44 #include "stdafx.h"
45 #include "TestEmbed.h"
46 #include "BrowserImpl.h"
47 #include "BrowserFrm.h"
48 #include "UrlDialog.h"
49 #include "ProfileMgr.h"
50 #include "ProfilesDlg.h"
51 #include "QaUtils.h"
52 #include "nsirequest.h"
53 #include <stdio.h>
56 /////////////////////////////////////////////////////////////////////////////
57 // CNsIRequest
60 CNsIRequest::CNsIRequest(nsIWebBrowser* mWebBrowser,CBrowserImpl *mpBrowserImpl)
62 qaWebBrowser = mWebBrowser ;
63 qaBrowserImpl = mpBrowserImpl ;
67 CNsIRequest::~CNsIRequest()
72 /////////////////////////////////////////////////////////////////////////////
73 // CNsIRequest message handlers
74 // ***********************************************************************
75 // ***********************************************************************
76 // nsIRequest iface
78 // table columns corrsp to: pending, status, suspend, resume, cancel,
79 // setLoadGroup & getLoadGroup tests respectively.
81 Element ReqTable[] = {
82 {"http://www.netscape.com/", 1, 1, 0, 0, 0, 1, 1},
83 {"http://www.yahoo.com/", 0, 0, 1, 1, 0, 0, 0},
84 {"http://www.cisco.com/", 0, 0, 0, 0, 1, 0, 0},
85 {"http://www.sun.com/", 0, 0, 0, 0, 0, 1, 1},
86 {"http://www.intel.com/", 1, 1, 1, 0, 0, 0, 0},
87 {"http://www.aol.com/", 0, 1, 0, 0, 0, 1, 1},
88 {"https://www.yahoo.com/", 1, 1, 1, 1, 0, 1, 1},
89 {"data:text/plain;charset=iso-8859-7,%be%fg%be",
90 1, 1, 1, 1, 0, 1, 1},
91 {"file://C|/Program Files/", 1, 1, 1, 1, 0, 1, 1},
92 {"ftp://ftp.netscape.com/", 1, 1, 1, 1, 0, 1, 1},
93 {"ftp://ftp.mozilla.org/", 0, 0, 0, 0, 1, 0, 0},
96 void CNsIRequest::OnStartTests(UINT nMenuID)
98 if (nMenuID == ID_INTERFACES_NSIREQUEST_RUNALLTESTS)
99 RunAllTests(9);
100 else
101 RunIndividualTests(nMenuID, 9);
104 void CNsIRequest::RunIndividualTests(UINT nMenuID, int reqTotal)
106 nsCOMPtr<nsIChannel> theChannel;
107 nsCOMPtr<nsILoadGroup> theLoadGroup(do_CreateInstance(NS_LOADGROUP_CONTRACTID));
108 nsCOMPtr<nsIURI> theURI;
109 if (!theLoadGroup)
111 QAOutput("We didn't get the Load Group. Test failed.", 2);
112 return;
114 int i=0;
116 QAOutput("Start selected nsIRequest test.", 2);
118 for (i=0; i<reqTotal; i++)
120 // nsIRequest individual tests
122 QAOutput("********** Individual nsIRequest test begins. **********");
124 theChannel = GetTheChannel(i, theLoadGroup);
125 nsCOMPtr<nsIRequest> theRequest = do_QueryInterface(theChannel);
127 switch(nMenuID)
130 case ID_INTERFACES_NSIREQUEST_GETNAME :
131 break;
132 case ID_INTERFACES_NSIREQUEST_ISPENDING :
133 IsPendingReqTest(theRequest);
134 break;
135 case ID_INTERFACES_NSIREQUEST_GETSTATUS :
136 GetStatusReqTest(theRequest);
137 break;
138 case ID_INTERFACES_NSIREQUEST_CANCEL :
139 CancelReqTest(theRequest);
140 break;
141 case ID_INTERFACES_NSIREQUEST_SUSPEND :
142 SuspendReqTest(theRequest);
143 break;
144 case ID_INTERFACES_NSIREQUEST_RESUME :
145 ResumeReqTest(theRequest);
146 break;
147 case ID_INTERFACES_NSIREQUEST_GETLOADGROUP :
148 GetLoadGroupTest(theRequest);
149 break;
150 case ID_INTERFACES_NSIREQUEST_SETLOADGROUP :
151 SetLoadGroupTest(theRequest, theLoadGroup);
152 break;
153 case ID_INTERFACES_NSIREQUEST_GETLOADFLAGS :
154 break;
155 case ID_INTERFACES_NSIREQUEST_SETLOADFLAGS :
156 break;
159 } // end for loop
163 void CNsIRequest::RunAllTests(int reqTotal)
165 // note: nsIRequest tests are called:
166 // 1) in BrowserImpl.cpp, nsIStreamListener::OnDataAvailable()
167 // 2) as individual tests below
169 nsCOMPtr<nsIChannel> theChannel;
170 nsCOMPtr<nsILoadGroup> theLoadGroup(do_CreateInstance(NS_LOADGROUP_CONTRACTID));
171 if (!theLoadGroup)
173 QAOutput("We didn't get the Load Group. Test failed.", 2);
174 return;
177 int i=0;
179 QAOutput("Start nsIRequest tests.", 1);
181 for (i=0; i<reqTotal; i++)
183 // nsIRequest individual tests
185 QAOutput("********** Individual nsIRequest test begins. **********");
187 theChannel = GetTheChannel(i, theLoadGroup);
188 nsCOMPtr<nsIRequest> theRequest = do_QueryInterface(theChannel);
190 if (ReqTable[i].reqPend == TRUE)
191 IsPendingReqTest(theRequest);
193 if (ReqTable[i].reqStatus == TRUE)
194 GetStatusReqTest(theRequest);
196 if (ReqTable[i].reqSuspend == TRUE)
197 SuspendReqTest(theRequest);
199 if (ReqTable[i].reqResume == TRUE)
200 ResumeReqTest(theRequest);
202 if (ReqTable[i].reqCancel == TRUE)
203 CancelReqTest(theRequest);
205 if (ReqTable[i].reqSetLoadGroup == TRUE)
206 SetLoadGroupTest(theRequest, theLoadGroup);
208 if (ReqTable[i].reqGetLoadGroup == TRUE)
209 GetLoadGroupTest(theRequest);
211 QAOutput("- - - - - - - - - - - - - - - - - - - - -", 1);
212 } // end for loop
213 QAOutput("End nsIRequest tests.", 1);
217 nsIChannel * CNsIRequest::GetTheChannel(int i, nsILoadGroup *theLoadGroup)
219 nsCAutoString theSpec, retURI;
220 nsCOMPtr<nsIURI> theURI;
221 nsCOMPtr<nsIChannel> theChannel;
223 theSpec = ReqTable[i].theUrl;
224 FormatAndPrintOutput("the input uri = ", theSpec, 1);
226 rv = NS_NewURI(getter_AddRefs(theURI), theSpec);
228 if (!theURI)
230 QAOutput("We didn't get the URI. Test failed.", 1);
231 return nsnull;
233 else {
234 retURI = GetTheURI(theURI, 1);
235 // simple string compare to see if input & output URLs match
236 if (strcmp(ReqTable[i].theUrl, retURI.get()) == 0)
237 QAOutput("The in/out URIs MATCH.", 1);
238 else
239 QAOutput("The in/out URIs don't MATCH.", 1);
240 RvTestResult(rv, "NS_NewURI", 1);
241 RvTestResultDlg(rv, "NS_NewURI", true);
244 rv = NS_NewChannel(getter_AddRefs(theChannel), theURI, nsnull, theLoadGroup);
245 if (!theChannel)
247 QAOutput("We didn't get the Channel. Test failed.", 1);
248 return nsnull;
250 else {
251 RvTestResult(rv, "NS_NewChannel", 1);
252 RvTestResultDlg(rv, "NS_NewChannel");
255 nsCOMPtr<nsIStreamListener> listener(static_cast<nsIStreamListener*>(qaBrowserImpl));
256 nsCOMPtr<nsIWeakReference> thisListener(do_GetWeakReference(listener));
257 qaWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsIStreamListener));
259 if (!listener) {
260 QAOutput("We didn't get the listener for AsyncOpen(). Test failed.", 1);
261 return nsnull;
263 // this calls nsIStreamListener::OnDataAvailable()
264 rv = theChannel->AsyncOpen(listener, nsnull);
265 RvTestResult(rv, "AsyncOpen()", 1);
266 RvTestResultDlg(rv, "AsyncOpen()");
268 return theChannel;
272 void CNsIRequest::IsPendingReqTest(nsIRequest *request)
274 PRBool reqPending;
275 nsresult rv;
277 rv = request->IsPending(&reqPending);
278 RvTestResult(rv, "nsIRequest::IsPending() rv test", 1);
279 RvTestResultDlg(rv, "nsIRequest::IsPending() rv test()");
281 if (!reqPending)
282 QAOutput("Pending request = false.", 1);
283 else
284 QAOutput("Pending request = true.", 1);
287 void CNsIRequest::GetStatusReqTest(nsIRequest *request)
289 nsresult theStatusError;
290 nsresult rv;
292 rv = request->GetStatus(&theStatusError);
293 RvTestResult(rv, "nsIRequest::GetStatus() test", 1);
294 RvTestResultDlg(rv, "nsIRequest::GetStatus() test");
295 RvTestResult(theStatusError, "the returned status error test", 1);
296 RvTestResultDlg(theStatusError, "the returned status error test");
299 void CNsIRequest::SuspendReqTest(nsIRequest *request)
301 nsresult rv;
303 rv = request->Suspend();
304 RvTestResult(rv, "nsIRequest::Suspend() test", 1);
305 RvTestResultDlg(rv, "nsIRequest::Suspend() test");
308 void CNsIRequest::ResumeReqTest(nsIRequest *request)
310 nsresult rv;
312 rv = request->Resume();
313 RvTestResult(rv, "nsIRequest::Resume() test", 1);
314 RvTestResultDlg(rv, "nsIRequest::Resume() test");
317 void CNsIRequest::CancelReqTest(nsIRequest *request)
319 nsresult rv;
320 nsresult status = NS_BINDING_ABORTED;
322 rv = request->Cancel(status);
323 RvTestResult(rv, "nsIRequest::Cancel() rv test", 1);
324 RvTestResultDlg(rv, "nsIRequest::Cancel() test");
325 RvTestResult(status, "nsIRequest::Cancel() status test", 1);
326 RvTestResultDlg(status, "nsIRequest::Cancel() status test");
329 void CNsIRequest::SetLoadGroupTest(nsIRequest *request,
330 nsILoadGroup *theLoadGroup)
332 nsresult rv;
333 nsCOMPtr<nsISimpleEnumerator> theSimpEnum;
335 rv = request->SetLoadGroup(theLoadGroup);
336 RvTestResult(rv, "nsIRequest::SetLoadGroup() rv test", 1);
337 RvTestResultDlg(rv, "nsIRequest::SetLoadGroup() rv test");
340 void CNsIRequest::GetLoadGroupTest(nsIRequest *request)
342 nsCOMPtr<nsILoadGroup> theLoadGroup;
343 nsresult rv;
344 nsCOMPtr<nsISimpleEnumerator> theSimpEnum;
346 rv = request->GetLoadGroup(getter_AddRefs(theLoadGroup));
347 RvTestResult(rv, "nsIRequest::GetLoadGroup() rv test", 1);
348 RvTestResultDlg(rv, "nsIRequest::GetLoadGroup() rv test");
350 rv = theLoadGroup->GetRequests(getter_AddRefs(theSimpEnum));
351 RvTestResult(rv, "nsIRequest:: LoadGroups' GetRequests() rv test", 1);
352 RvTestResultDlg(rv, "nsIRequest:: LoadGroups' GetRequests() rv test");