|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // defines test class: CTextModeTestCookies |
|
15 // |
|
16 // |
|
17 |
|
18 #include "T_Cookies.h" |
|
19 #include "examplecookiemanager.h" |
|
20 #include <http/ccookiefilterinterface.h> |
|
21 |
|
22 // User include |
|
23 #include "csrvaddrval.h" |
|
24 |
|
25 // Literals used in the file |
|
26 _LIT8(KHttpCookieSet1Url, "http://WapTestIP/perl/cookies/1/cookieset1.pl"); |
|
27 _LIT8(KHttpCookieSet2Url, "http://WapTestIP/perl/cookies/1/cookieset2.pl"); |
|
28 _LIT8(KHttpCookieSet3Url, "http://WapTestIP/perl/cookies/1/extra/cookieset3.pl"); |
|
29 _LIT8(KHttpCookieCheck1Url, "http://WapTestIP/perl/cookies/1/dumpform.pl"); |
|
30 _LIT8(KHttpCookieCheck2Url, "http://WapTestIP/perl/cookies/1/extra/dumpform.pl"); |
|
31 _LIT8(KHttpCookieWrongPathUrl, "http://WapTestIP/perl/cookies/2/wrongpath.pl"); |
|
32 _LIT8(KHttpCookieGoodDomainUrl, "http://WapTestName/perl/cookies/3/gooddomain.pl"); |
|
33 _LIT8(KHttpCookieBadDomainUrl, "http://WapTestName/perl/cookies/4/baddomain.pl"); |
|
34 _LIT8(KHttpCookieAmendDomainUrl, "http://WapTestName/perl/cookies/5/amenddomain.pl"); |
|
35 _LIT8(KHttpCookieNoExpiryUrl, "http://WapTestName/perl/cookies/6/noexpiry.pl"); |
|
36 _LIT8(KHttpCookie2Set1Url, "http://WapTestIP:9000/tryit?req=cook4.txt&resp=cook3.txt"); |
|
37 _LIT8(KHttpCookie2PortSetUrl, "http://WapTestIP:9000/tryit?req=portok1.txt&resp=portok2.txt"); |
|
38 _LIT8(KHttpCookie2BadPortSetUrl, "http://WapTestIP:9000/tryit?req=badport1.txt&resp=badport2.txt"); |
|
39 _LIT8(KHttpCookieSetTwiceUrl, "http://WapTestIP/perl/cookies/10/cookieset0.pl"); |
|
40 |
|
41 const TInt KErrCookieTestFailed = -7397; |
|
42 |
|
43 /** |
|
44 This function is called to create a new instance of the class |
|
45 CTextModeTestCookies |
|
46 |
|
47 @param aTestNumber The test number that has to be executed |
|
48 @param aIniSettingsFile The script file that holds the sections |
|
49 from which the value has to be retrieved |
|
50 @leave KErrNoMemory if there is no memory to allocate for the object |
|
51 */ |
|
52 CTextModeTestCookies* CTextModeTestCookies::NewL(TInt aTestNumber, CScriptFile* aIniSettingsFile) |
|
53 { |
|
54 CTextModeTestCookies* self = new(ELeave)CTextModeTestCookies(aTestNumber, aIniSettingsFile); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(self); |
|
58 return self; |
|
59 } |
|
60 |
|
61 /** |
|
62 Destructor |
|
63 */ |
|
64 CTextModeTestCookies::~CTextModeTestCookies() |
|
65 { |
|
66 delete iCookieManager; |
|
67 iTransArray.Close(); |
|
68 } |
|
69 |
|
70 /** |
|
71 This C++ constructor is called in the NewL function and is used to |
|
72 instantiate iTestNumber and iIniSettingsFile |
|
73 |
|
74 @param aTestNumber - The test number that has to be executed |
|
75 @param aIniSettingsFile - The script file that holds the sections |
|
76 from which the value has to be retrieved |
|
77 */ |
|
78 CTextModeTestCookies::CTextModeTestCookies(TInt aTestNumber, CScriptFile* aIniSettingsFile) : |
|
79 iIniSettingsFile(aIniSettingsFile), |
|
80 iTestNumber(aTestNumber) |
|
81 { |
|
82 // does nothing |
|
83 } |
|
84 |
|
85 /** |
|
86 This constructor is called in the NewL function and used by the class to |
|
87 construct self. Currently this has no functionality. In future this |
|
88 constructor can be used. |
|
89 */ |
|
90 void CTextModeTestCookies::ConstructL() |
|
91 { |
|
92 } |
|
93 |
|
94 /** |
|
95 This function is called to initiate the tests. |
|
96 It may leave with any of system wide error codes. |
|
97 */ |
|
98 void CTextModeTestCookies::DoRunL() |
|
99 { |
|
100 _LIT8(KProtocol, "HTTP/TCP"); |
|
101 |
|
102 // Open the HTTP session |
|
103 |
|
104 if (iTestNumber == 11) |
|
105 { |
|
106 // Tests fix for defect .. |
|
107 // INC036279 - RHTTPSession::OpenL() can cause multiple deletes of |
|
108 // iImplementation. If the callback to ConfigureSessionFiltersL() |
|
109 // (below) leaves then calls to RHTTPSession::Close() will panic as |
|
110 // iImplementation has already been deleted. |
|
111 |
|
112 TRAPD( err, iSession.OpenL(KProtocol(), this)); |
|
113 if (err) |
|
114 { |
|
115 iSession.Close(); |
|
116 User::Leave(err); |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 iSession.OpenL(KProtocol(), this); |
|
122 } |
|
123 |
|
124 CleanupClosePushL(iSession); |
|
125 |
|
126 switch(iTestNumber) |
|
127 { |
|
128 case 1: |
|
129 DoCookieTest1L(); |
|
130 break; |
|
131 case 2: |
|
132 DoCookieTest2L(); |
|
133 break; |
|
134 case 3: |
|
135 DoCookieTest3L(); |
|
136 break; |
|
137 case 4: |
|
138 DoCookieTest4L(); |
|
139 break; |
|
140 case 5: |
|
141 DoCookieTest5L(); |
|
142 break; |
|
143 case 6: |
|
144 DoCookieTest6L(); |
|
145 break; |
|
146 case 7: |
|
147 DoCookieTest7L(); |
|
148 break; |
|
149 case 8: |
|
150 DoCookieTest8L(); |
|
151 break; |
|
152 case 9: |
|
153 DoCookieTest9L(); |
|
154 break; |
|
155 case 10: |
|
156 DoCookieTest10L(); |
|
157 break; |
|
158 case 11: |
|
159 break; |
|
160 case 12: |
|
161 DoCookieTest12L(); |
|
162 break; |
|
163 default: |
|
164 __DEBUGGER(); // Invalid test number |
|
165 } |
|
166 |
|
167 // Close anything opened |
|
168 delete iCookieManager; |
|
169 iCookieManager = NULL; |
|
170 CleanupStack::PopAndDestroy(&iSession); //close iSession |
|
171 |
|
172 // If any transaction failed then fail the test |
|
173 User::LeaveIfError(iFailureError); |
|
174 } |
|
175 |
|
176 /** |
|
177 If a test is failed then is function is executed to log the error code |
|
178 with which the test failed |
|
179 |
|
180 @param aErr The error code with which the test failed. |
|
181 */ |
|
182 TInt CTextModeTestCookies::RunError(TInt aErr) |
|
183 { |
|
184 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
185 return KErrNone; |
|
186 } |
|
187 |
|
188 void CTextModeTestCookies::DoCancel() |
|
189 { |
|
190 } |
|
191 |
|
192 const TDesC& CTextModeTestCookies::TestName() |
|
193 { |
|
194 _LIT(KHeaderTestName,"CTextModeTestCookies"); |
|
195 return KHeaderTestName; |
|
196 } |
|
197 |
|
198 TInt CTextModeTestCookies::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
|
199 { |
|
200 _LIT(KLogDescription, "\nTest failed with error code %d on transaction ID=%d\n"); |
|
201 iEngine->Utils().LogIt(KLogDescription, aError, aTransaction.Id()); |
|
202 iFailureError = aError; |
|
203 CActiveScheduler::Stop(); |
|
204 return KErrNone; |
|
205 } |
|
206 |
|
207 void CTextModeTestCookies::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
208 { |
|
209 switch (aEvent.iStatus) |
|
210 { |
|
211 case THTTPEvent::EGotResponseHeaders: |
|
212 { |
|
213 // HTTP response headers have been received |
|
214 iEngine->Utils().LogIt(_L("<Got response headers>")); |
|
215 if (iTestNumber == 12) |
|
216 { |
|
217 ValidateResponseL(); |
|
218 } |
|
219 else |
|
220 { |
|
221 ValidateRequestL(); |
|
222 } |
|
223 } break; |
|
224 case THTTPEvent::ESubmit: |
|
225 { |
|
226 } break; |
|
227 case THTTPEvent::EGotResponseBodyData: |
|
228 { |
|
229 // Some (more) body data has been received (in the HTTP response) |
|
230 iEngine->Utils().LogIt(_L("<Got a chunk of data>")); |
|
231 ValidateBodyL(aTransaction); |
|
232 } break; |
|
233 case THTTPEvent::EResponseComplete: |
|
234 { |
|
235 // The transaction's response is complete |
|
236 iEngine->Utils().LogIt(_L("<Transaction Complete>")); |
|
237 } break; |
|
238 case THTTPEvent::ESucceeded: |
|
239 { |
|
240 // The transaction succeeded |
|
241 iEngine->Utils().LogIt(_L("<Transaction succeeded>")); |
|
242 aTransaction.Close(); |
|
243 if (--iOpenTransactionCount == 0) |
|
244 { |
|
245 CActiveScheduler::Stop(); |
|
246 } |
|
247 } break; |
|
248 case THTTPEvent::EFailed: |
|
249 { |
|
250 // The transaction failed so fail the test |
|
251 iEngine->Utils().LogIt(_L("<Transaction failed>")); |
|
252 aTransaction.Close(); |
|
253 if (--iOpenTransactionCount == 0) |
|
254 { |
|
255 CActiveScheduler::Stop(); |
|
256 } |
|
257 // If the failure error has already been set, keep it. Otherwise |
|
258 // set it to KErrCookieTestFailed |
|
259 if(iFailureError == KErrNone) |
|
260 { |
|
261 iFailureError = KErrCookieTestFailed; |
|
262 } |
|
263 } break; |
|
264 default: |
|
265 { |
|
266 _LIT(KLogDescription, "<unrecognised event> %d"); |
|
267 iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus); |
|
268 if (aEvent.iStatus < 0) |
|
269 { |
|
270 iFailureError = aEvent.iStatus; |
|
271 CActiveScheduler::Stop(); |
|
272 } |
|
273 } |
|
274 break; |
|
275 } |
|
276 } |
|
277 |
|
278 /** |
|
279 This function is called to create a new transaction array. |
|
280 It may leave with any of the system wide error codes. |
|
281 @param aUri The URI for which a Transaction has to be created. |
|
282 */ |
|
283 void CTextModeTestCookies::CreateTransArrayL(const TDesC8& aUri) |
|
284 { |
|
285 // Open the transactions for this test |
|
286 TBuf8<KMaxUrlBufSize> url; |
|
287 RStringF get = iSession.StringPool().StringF(HTTP::EGET, RHTTPSession::GetTable()); |
|
288 iOpenTransactionCount = 0; |
|
289 |
|
290 // create the transaction and submit |
|
291 url.Zero(); |
|
292 url.Format(aUri); |
|
293 TUriParser8 urlParser; |
|
294 urlParser.Parse(url); |
|
295 RHTTPTransaction tr = iSession.OpenTransactionL(urlParser, *this, get); |
|
296 CleanupClosePushL(tr); |
|
297 User::LeaveIfError(iTransArray.Append(tr)); |
|
298 CleanupStack::Pop(&tr); |
|
299 tr.SubmitL(); |
|
300 iOpenTransactionCount++; |
|
301 } |
|
302 |
|
303 void CTextModeTestCookies::ConfigureSessionFiltersL(TFilterConfigurationIterator* /*aFilterConfigIter*/) |
|
304 { |
|
305 if (iTestNumber == 11) |
|
306 { |
|
307 User::Leave(KErrNone); |
|
308 } |
|
309 |
|
310 iCookieManager = CExampleCookieManager::NewL(iSession.StringPool()); |
|
311 |
|
312 CCookieFilterInterface::InstallFilterL(iSession, iCookieManager); |
|
313 } |
|
314 |
|
315 void CTextModeTestCookies::ValidateBodyL(RHTTPTransaction aTransaction) |
|
316 { |
|
317 RHTTPResponse resp = aTransaction.Response(); |
|
318 MHTTPDataSupplier* body = resp.Body(); |
|
319 TPtrC8 data; |
|
320 body->GetNextDataPart(data); |
|
321 body->ReleaseData(); |
|
322 } |
|
323 |
|
324 /** |
|
325 This test gets two cookies and checks if the right cookies are sent. |
|
326 It may leave with any of the system wide error codes. |
|
327 */ |
|
328 void CTextModeTestCookies::DoCookieTest1L() |
|
329 { |
|
330 HBufC8* httpCookieSet1Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookieSet1Url(), iIniSettingsFile); |
|
331 CleanupStack::PushL(httpCookieSet1Url); |
|
332 |
|
333 HBufC8* httpCookieSet2Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookieSet2Url(), iIniSettingsFile); |
|
334 CleanupStack::PushL(httpCookieSet2Url); |
|
335 |
|
336 HBufC8* httpCookieCheck1Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookieCheck1Url(), iIniSettingsFile); |
|
337 CleanupStack::PushL(httpCookieCheck1Url); |
|
338 |
|
339 DoGenericCookieTestL(httpCookieSet1Url, httpCookieSet2Url, httpCookieCheck1Url); |
|
340 |
|
341 CleanupStack::PopAndDestroy(3, httpCookieSet1Url); // and httpCookieSet2Url, httpCookieCheck1Url |
|
342 } |
|
343 |
|
344 /** |
|
345 This test tries to get a cookie by passing the wrong path in the Url. |
|
346 It may leave with any of the system wide error codes |
|
347 */ |
|
348 void CTextModeTestCookies::DoCookieTest2L() |
|
349 { |
|
350 HBufC8* httpCookieWrongPathUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookieWrongPathUrl(), iIniSettingsFile); |
|
351 CleanupStack::PushL(httpCookieWrongPathUrl); |
|
352 |
|
353 DoGenericCookieTestL(httpCookieWrongPathUrl, NULL, NULL); |
|
354 |
|
355 CleanupStack::PopAndDestroy(httpCookieWrongPathUrl); |
|
356 } |
|
357 |
|
358 /** |
|
359 This test gets two cookies by passing a good domain (domain that is |
|
360 existing). |
|
361 It may leave with any of the system wide error codes. |
|
362 */ |
|
363 void CTextModeTestCookies::DoCookieTest3L() |
|
364 { |
|
365 HBufC8* httpCookieGoodDomainUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookieGoodDomainUrl(), iIniSettingsFile); |
|
366 CleanupStack::PushL(httpCookieGoodDomainUrl); |
|
367 |
|
368 DoGenericCookieTestL(httpCookieGoodDomainUrl, httpCookieGoodDomainUrl, NULL); |
|
369 |
|
370 CleanupStack::PopAndDestroy(httpCookieGoodDomainUrl); |
|
371 } |
|
372 |
|
373 /** |
|
374 This test gets a cookie by passing a bad domain (domain that is not |
|
375 existing). |
|
376 It may leave with any of the system wide error codes. |
|
377 */ |
|
378 void CTextModeTestCookies::DoCookieTest4L() |
|
379 { |
|
380 HBufC8* httpCookieBadDomainUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookieBadDomainUrl(), iIniSettingsFile); |
|
381 CleanupStack::PushL(httpCookieBadDomainUrl); |
|
382 |
|
383 DoGenericCookieTestL(httpCookieBadDomainUrl, NULL, NULL); |
|
384 |
|
385 CleanupStack::PopAndDestroy(httpCookieBadDomainUrl); |
|
386 } |
|
387 |
|
388 /** |
|
389 This test gets two cookies by passing a domain that has to be amended. |
|
390 It may leave with any of the system wide error codes. |
|
391 */ |
|
392 void CTextModeTestCookies::DoCookieTest5L() |
|
393 { |
|
394 HBufC8* httpCookieAmendDomainUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookieAmendDomainUrl(), iIniSettingsFile); |
|
395 CleanupStack::PushL(httpCookieAmendDomainUrl); |
|
396 |
|
397 DoGenericCookieTestL(httpCookieAmendDomainUrl, httpCookieAmendDomainUrl, NULL); |
|
398 |
|
399 CleanupStack::PopAndDestroy(httpCookieAmendDomainUrl); |
|
400 } |
|
401 |
|
402 /** |
|
403 This test gets a cookie that does not expire. |
|
404 It may leave with any of the system wide error codes. |
|
405 */ |
|
406 void CTextModeTestCookies::DoCookieTest6L() |
|
407 { |
|
408 HBufC8* httpCookieNoExpiryUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookieNoExpiryUrl(), iIniSettingsFile); |
|
409 CleanupStack::PushL(httpCookieNoExpiryUrl); |
|
410 |
|
411 DoGenericCookieTestL(httpCookieNoExpiryUrl, NULL, NULL); |
|
412 |
|
413 CleanupStack::PopAndDestroy(httpCookieNoExpiryUrl); |
|
414 } |
|
415 |
|
416 /** |
|
417 This test gets two cookies and checks if the right cookies are sent. |
|
418 It may leave with any of the system wide error codes. |
|
419 */ |
|
420 void CTextModeTestCookies::DoCookieTest7L() |
|
421 { |
|
422 HBufC8* httpCookieSet2Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookieSet2Url(), iIniSettingsFile); |
|
423 CleanupStack::PushL(httpCookieSet2Url); |
|
424 |
|
425 HBufC8* httpCookieSet3Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookieSet3Url(), iIniSettingsFile); |
|
426 CleanupStack::PushL(httpCookieSet3Url); |
|
427 |
|
428 HBufC8* httpCookieCheck2Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookieCheck2Url(), iIniSettingsFile); |
|
429 CleanupStack::PushL(httpCookieCheck2Url); |
|
430 |
|
431 DoGenericCookieTestL(httpCookieSet2Url, httpCookieSet3Url, httpCookieCheck2Url); |
|
432 |
|
433 CleanupStack::PopAndDestroy(3, httpCookieSet2Url); // and httpCookieSet3Url, httpCookieCheck2Url |
|
434 } |
|
435 |
|
436 /** |
|
437 This test gets two cookies. |
|
438 It may leave with any of the system wide error codes. |
|
439 */ |
|
440 void CTextModeTestCookies::DoCookieTest8L() |
|
441 { |
|
442 HBufC8* httpCookie2Set1Url = TSrvAddrVal::ReplaceHostNameL(KHttpCookie2Set1Url(), iIniSettingsFile); |
|
443 CleanupStack::PushL(httpCookie2Set1Url); |
|
444 |
|
445 DoGenericCookieTestL(httpCookie2Set1Url, httpCookie2Set1Url, NULL); |
|
446 |
|
447 CleanupStack::PopAndDestroy(httpCookie2Set1Url); |
|
448 } |
|
449 |
|
450 /** |
|
451 This test gets a cookie while the domain name is passed with port number |
|
452 and checks if the right cookie is sent. |
|
453 It may leave with any of the system wide error codes. |
|
454 */ |
|
455 void CTextModeTestCookies::DoCookieTest9L() |
|
456 { |
|
457 HBufC8* httpCookie2PortSetUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookie2PortSetUrl(), iIniSettingsFile); |
|
458 CleanupStack::PushL(httpCookie2PortSetUrl); |
|
459 |
|
460 DoGenericCookieTestL(httpCookie2PortSetUrl, NULL, httpCookie2PortSetUrl); |
|
461 |
|
462 CleanupStack::PopAndDestroy(httpCookie2PortSetUrl); |
|
463 } |
|
464 |
|
465 /** |
|
466 This test gets a cookie while the domain name is passed with bad port |
|
467 number. |
|
468 It may leave with any of the system wide error codes. |
|
469 */ |
|
470 void CTextModeTestCookies::DoCookieTest10L() |
|
471 { |
|
472 HBufC8* httpCookie2BadPortSetUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookie2BadPortSetUrl(), iIniSettingsFile); |
|
473 CleanupStack::PushL(httpCookie2BadPortSetUrl); |
|
474 |
|
475 DoGenericCookieTestL(httpCookie2BadPortSetUrl, NULL, NULL); |
|
476 |
|
477 CleanupStack::PopAndDestroy(httpCookie2BadPortSetUrl); |
|
478 } |
|
479 |
|
480 /** |
|
481 This test gets a cookie twice. |
|
482 It may leave with any of the system wide error codes. |
|
483 */ |
|
484 void CTextModeTestCookies::DoCookieTest12L() |
|
485 { |
|
486 HBufC8* httpCookieSetTwiceUrl = TSrvAddrVal::ReplaceHostNameL(KHttpCookieSetTwiceUrl(), iIniSettingsFile); |
|
487 CleanupStack::PushL(httpCookieSetTwiceUrl); |
|
488 |
|
489 DoGenericCookieTestL(httpCookieSetTwiceUrl, NULL, NULL); |
|
490 |
|
491 CleanupStack::PopAndDestroy(httpCookieSetTwiceUrl); |
|
492 } |
|
493 |
|
494 /** |
|
495 This function is called by all the cookie tests. This function is called |
|
496 3 times as it processes once for each parameter. i.e., First if executes |
|
497 for aCookie1, and comes back to this function and executes for aCookie2 and |
|
498 then comes back to execute for aCookie3. |
|
499 It may leave with any of the system wide error codes. |
|
500 |
|
501 @param aCookie1 The URI to get a cookie |
|
502 @param aCookie2 The URI to get a cookie |
|
503 @param aCookie3 The URI to check if we sent the correct cookies. |
|
504 */ |
|
505 void CTextModeTestCookies::DoGenericCookieTestL(const TDesC8* aCookie1, const TDesC8* aCookie2, const TDesC8* aCookie3) |
|
506 { |
|
507 if(aCookie1) |
|
508 { |
|
509 // Go to the first URI where we will get a cookie |
|
510 CreateTransArrayL(*aCookie1); |
|
511 iFailureError = KErrNone; |
|
512 CActiveScheduler::Start(); |
|
513 } |
|
514 |
|
515 if(aCookie2) |
|
516 { |
|
517 // Go to the second URI where we will get a cookie |
|
518 CreateTransArrayL(*aCookie2); |
|
519 iFailureError = KErrNone; |
|
520 CActiveScheduler::Start(); |
|
521 } |
|
522 |
|
523 if(aCookie3) |
|
524 { |
|
525 // Go to the third URI where we check that we sent the correct cookies |
|
526 CreateTransArrayL(*aCookie3); |
|
527 iFailureError = KErrNone; |
|
528 CActiveScheduler::Start(); |
|
529 } |
|
530 } |
|
531 |
|
532 /** |
|
533 This function is called to validate the request. |
|
534 |
|
535 @leave Leaves with a standard error |
|
536 */ |
|
537 void CTextModeTestCookies::ValidateRequestL() |
|
538 { |
|
539 const TInt transCount = iTransArray.Count(); |
|
540 RHTTPTransaction trans = iTransArray[transCount - 1]; |
|
541 RHTTPRequest request = trans.Request(); |
|
542 RHTTPHeaders headers = request.GetHeaderCollection(); |
|
543 |
|
544 CheckForCookiesL(headers, iTestNumber, transCount); |
|
545 } |
|
546 |
|
547 /** |
|
548 This function is called to validate the response. |
|
549 It may leave with any of the system wide error codes. |
|
550 */ |
|
551 void CTextModeTestCookies::ValidateResponseL() |
|
552 { |
|
553 const TInt transCount = iTransArray.Count(); |
|
554 RHTTPTransaction trans = iTransArray[transCount - 1]; |
|
555 RHTTPResponse response = trans.Response(); |
|
556 RHTTPHeaders headers = response.GetHeaderCollection(); |
|
557 |
|
558 CheckForSetCookiesL(headers, iTestNumber, transCount); |
|
559 } |
|
560 /** |
|
561 This function is called to check for the exisiting cookies. |
|
562 |
|
563 @leave KErrNotFound, if the set cookies are not found |
|
564 */ |
|
565 |
|
566 void CTextModeTestCookies::CheckForSetCookiesL(RHTTPHeaders aHeaders, TInt /*aTestNumber*/, TInt /*aTransNumber*/) |
|
567 { |
|
568 RStringF cookieHeaderFieldName = iSession.StringPool().StringF(HTTP::ESetCookie, iSession.GetTable()); |
|
569 |
|
570 const TInt numCookies = aHeaders.FieldPartsL(cookieHeaderFieldName); |
|
571 |
|
572 if (numCookies!=2) |
|
573 { |
|
574 User::Leave(KErrNotFound); |
|
575 } |
|
576 } |
|
577 |
|
578 /** |
|
579 This function is called to check for the exisiting cookies. |
|
580 |
|
581 @leave KErrNotFound, if the cookies being checked for are not found |
|
582 */ |
|
583 void CTextModeTestCookies::CheckForCookiesL(RHTTPHeaders aHeaders, TInt aTestNumber, TInt aTransNumber) |
|
584 { |
|
585 RStringF cookieHeaderFieldName = iSession.StringPool().StringF(HTTP::ECookie, iSession.GetTable()); |
|
586 |
|
587 const TInt numCookies = aHeaders.FieldPartsL(cookieHeaderFieldName); |
|
588 |
|
589 RStringF stringToMatch = StringToMatchL(aTestNumber, aTransNumber, 0); |
|
590 const TDesC8& matchDes = stringToMatch.DesC(); |
|
591 CleanupClosePushL(stringToMatch); |
|
592 |
|
593 TBool found = EFalse; |
|
594 if(stringToMatch != RStringF()) |
|
595 { |
|
596 THTTPHdrVal hdr; |
|
597 for(TInt index=0; (index<numCookies) && !found; ++index) |
|
598 { |
|
599 User::LeaveIfError(aHeaders.GetField(cookieHeaderFieldName, 0, hdr)); |
|
600 const TDesC8& hdrDes = hdr.StrF().DesC(); |
|
601 |
|
602 if(hdrDes.Find(matchDes) != KErrNotFound) |
|
603 { |
|
604 found = ETrue; |
|
605 } |
|
606 |
|
607 } |
|
608 if(!found) |
|
609 { |
|
610 User::Leave(KErrNotFound); |
|
611 } |
|
612 } |
|
613 |
|
614 CleanupStack::PopAndDestroy(&stringToMatch); |
|
615 } |
|
616 |
|
617 /** |
|
618 This function is called to get the strings that is to be matched for each test case |
|
619 |
|
620 @leave KErrCookieTestFailed, if the cookie count is more than what is expected. |
|
621 */ |
|
622 |
|
623 RStringF CTextModeTestCookies::StringToMatchL(TInt aTestNumber, TInt aTransNumber, TInt aCookieCount) |
|
624 { |
|
625 // To add to this function: |
|
626 // Add to the switch statement for the test you are writing and return a |
|
627 // string to search for in the cookie header (a good choice is the name of |
|
628 // the cookie you expect to find). If you do not expect to find a cookie |
|
629 // then make that check here and leave if you want to fail the test |
|
630 // (return RStringF() if you want to pass. |
|
631 // |
|
632 |
|
633 _LIT8(KTest1Trans1String, "TEST_PARTA"); |
|
634 _LIT8(KTest1Trans2String, "TEST_PARTB"); |
|
635 _LIT8(KTest3String, "TEST3"); |
|
636 _LIT8(KTest5String, "TEST5"); |
|
637 _LIT8(KTest6String, "TEST6"); |
|
638 _LIT8(KTest7Trans1String, "TEST_PARTB"); |
|
639 _LIT8(KTest7Trans2String, "TEST_PARTC"); |
|
640 _LIT8(KTest8String, "feroz"); |
|
641 _LIT8(KTest9String, "scooby"); |
|
642 _LIT8(KTest10String, "FOX"); |
|
643 _LIT8(KTest11String, "BADGER"); |
|
644 |
|
645 RStringF returnString; |
|
646 |
|
647 switch(aTestNumber) |
|
648 { |
|
649 case 1: |
|
650 if(aTransNumber == 2) |
|
651 { |
|
652 returnString = iSession.StringPool().OpenFStringL(KTest1Trans1String()); |
|
653 } |
|
654 else if(aTransNumber == 3) |
|
655 { |
|
656 returnString = iSession.StringPool().OpenFStringL(KTest1Trans2String()); |
|
657 } |
|
658 break; |
|
659 case 2: |
|
660 if(iCookieManager->CookieCount() != 0) |
|
661 { |
|
662 iFailureError = KErrCookieTestFailed; |
|
663 User::Leave(KErrCookieTestFailed); |
|
664 } |
|
665 break; |
|
666 case 3: |
|
667 if(aTransNumber == 2) |
|
668 { |
|
669 returnString = iSession.StringPool().OpenFStringL(KTest3String()); |
|
670 } |
|
671 break; |
|
672 case 4: |
|
673 if(iCookieManager->CookieCount() != 0) |
|
674 { |
|
675 iFailureError = KErrCookieTestFailed; |
|
676 User::Leave(KErrCookieTestFailed); |
|
677 } |
|
678 break; |
|
679 case 5: |
|
680 if(aTransNumber == 2) |
|
681 { |
|
682 returnString = iSession.StringPool().OpenFStringL(KTest5String()); |
|
683 } |
|
684 break; |
|
685 case 6: |
|
686 if(aTransNumber == 2) |
|
687 { |
|
688 returnString = iSession.StringPool().OpenFStringL(KTest6String()); |
|
689 } |
|
690 break; |
|
691 case 7: |
|
692 if(aTransNumber == 2) |
|
693 { |
|
694 returnString = iSession.StringPool().OpenFStringL(KTest7Trans1String()); |
|
695 } |
|
696 else if(aTransNumber == 3) |
|
697 { |
|
698 returnString = iSession.StringPool().OpenFStringL(KTest7Trans2String()); |
|
699 } |
|
700 break; |
|
701 case 8: |
|
702 if(aTransNumber == 2) |
|
703 { |
|
704 returnString = iSession.StringPool().OpenFStringL(KTest8String()); |
|
705 } |
|
706 break; |
|
707 case 9: |
|
708 if(aTransNumber == 3) |
|
709 { |
|
710 returnString = iSession.StringPool().OpenFStringL(KTest9String()); |
|
711 } |
|
712 break; |
|
713 case 10: |
|
714 if(iCookieManager->CookieCount() != 0) |
|
715 { |
|
716 iFailureError = KErrCookieTestFailed; |
|
717 User::Leave(KErrCookieTestFailed); |
|
718 } |
|
719 break; |
|
720 case 11: |
|
721 break; |
|
722 case 12: |
|
723 if (aCookieCount == 0) |
|
724 { |
|
725 returnString = iSession.StringPool().OpenFStringL(KTest10String()); |
|
726 } |
|
727 else |
|
728 { |
|
729 returnString = iSession.StringPool().OpenFStringL(KTest11String()); |
|
730 } |
|
731 break; |
|
732 default: |
|
733 break; |
|
734 } |
|
735 |
|
736 return returnString; |
|
737 } |