|
1 // Copyright (c) 2001-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 // |
|
15 |
|
16 |
|
17 #include "CHttpAccepTtestBase.h" |
|
18 #include <http.h> |
|
19 |
|
20 const TInt KNothingExpected = 0; |
|
21 |
|
22 |
|
23 CHttpAcceptTestBase::CHttpAcceptTestBase() |
|
24 { |
|
25 iExpectedStatusCode=KNothingExpected; |
|
26 iExpectedError=KNothingExpected; |
|
27 |
|
28 |
|
29 } |
|
30 |
|
31 void CHttpAcceptTestBase::DoRunL() |
|
32 { |
|
33 iOpenTransactionCount = 0; |
|
34 CleanupStack::PushL ( TCleanupItem ( CHttpAcceptTestBase::Cleanup, this ) ); |
|
35 OpenTestSessionL(); // set up session and transaction here |
|
36 |
|
37 iTransaction.SubmitL(); |
|
38 CleanupStack::Pop (); |
|
39 CActiveScheduler::Start(); |
|
40 CloseTestSession(); // close any strings, transaction and session |
|
41 if (iTestFail==1) |
|
42 { |
|
43 User::Leave(KErrNoMemory); |
|
44 } |
|
45 } |
|
46 |
|
47 TInt CHttpAcceptTestBase::RunError(TInt aErr) |
|
48 { |
|
49 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
50 return KErrNone; |
|
51 } |
|
52 |
|
53 void CHttpAcceptTestBase::DoCancel() |
|
54 {} |
|
55 |
|
56 CHttpAcceptTestBase::~CHttpAcceptTestBase() |
|
57 {} |
|
58 |
|
59 void CHttpAcceptTestBase::Cleanup ( TAny* aPtr ) |
|
60 { |
|
61 CHttpAcceptTestBase& httpTestBase = *( CHttpAcceptTestBase* )aPtr; |
|
62 httpTestBase.CloseTestSession (); |
|
63 } |
|
64 |
|
65 |
|
66 /** set this object active */ |
|
67 void CHttpAcceptTestBase::CompleteOwnRequest() |
|
68 { |
|
69 TRequestStatus* stat = &iStatus; |
|
70 User::RequestComplete(stat,KErrNone); |
|
71 if (!IsActive()) |
|
72 SetActive(); |
|
73 } |
|
74 |
|
75 |
|
76 TInt CHttpAcceptTestBase::MHFRunError(TInt aError, |
|
77 RHTTPTransaction /*aTransaction*/, |
|
78 const THTTPEvent& /*aEvent*/) |
|
79 { |
|
80 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
81 return KErrNone; |
|
82 } |
|
83 |
|
84 |
|
85 // validates a response against all expected outcomes |
|
86 void CHttpAcceptTestBase::Validate(RHTTPTransaction aTransaction) |
|
87 { |
|
88 if (iExpectedNumberRedirects) |
|
89 { |
|
90 THTTPHdrVal hdr; |
|
91 TBool hasValue; |
|
92 RStringPool strP = aTransaction.Session().StringPool(); |
|
93 hasValue = aTransaction.PropertySet().Property(strP.StringF(HTTP::ERedirectCount,RHTTPSession::GetTable()), hdr); |
|
94 if (hasValue && hdr.Int() != iExpectedNumberRedirects) |
|
95 { |
|
96 iTestFail = 1; |
|
97 iEngine->Utils().LogIt(_L("<Number of Redirects don't match expected number>\n")); |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 void CHttpAcceptTestBase::MHFRunL(RHTTPTransaction aTransaction, |
|
103 const THTTPEvent& aEvent) |
|
104 { |
|
105 if (aEvent.iStatus < 0) |
|
106 { |
|
107 if (aEvent.iStatus == iExpectedError) |
|
108 { |
|
109 iEngine->Utils().LogIt(_L("<The error event %d was expected>\n"), aEvent.iStatus); |
|
110 iExpectError = ETrue; |
|
111 } |
|
112 else |
|
113 { |
|
114 iTestFail = 1; |
|
115 iEngine->Utils().LogIt(_L("<The error event %d was not expected>\n"), aEvent.iStatus); |
|
116 } |
|
117 if ( aEvent.iStatus != KErrNoMemory ) |
|
118 return; |
|
119 } |
|
120 |
|
121 switch (aEvent.iStatus) |
|
122 { |
|
123 case THTTPEvent::EGotResponseHeaders: |
|
124 { |
|
125 // HTTP response headers have been received |
|
126 iEngine->Utils().LogIt(_L("<EGotResponseHeaders (%d)\n"),aEvent.iStatus); |
|
127 |
|
128 TInt statusCode = aTransaction.Response().StatusCode(); |
|
129 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
130 DumpRespHeaders(aTransaction); |
|
131 iEngine->SetCurrentStatusCode(aTransaction.Response().StatusCode()); |
|
132 if (iExpectedStatusCode !=KNothingExpected && iExpectedStatusCode != aTransaction.Response().StatusCode() && |
|
133 iExpectedStatusCode < THTTPEvent::ERedirectedPermanently) |
|
134 { |
|
135 iTestFail= ETrue; |
|
136 iEngine->Utils().LogIt(_L("<Unexpected status code: %d, Expected was %d>\n"), statusCode,iExpectedStatusCode); |
|
137 } |
|
138 else |
|
139 { |
|
140 iTestFail = EFalse; |
|
141 } |
|
142 // To verify ETransferEncoding header field is removed from the response header |
|
143 // on receiving the value of EChunked in it |
|
144 THTTPHdrVal tmpVal; |
|
145 RStringPool strP = aTransaction.Session().StringPool(); |
|
146 |
|
147 if(aTransaction.Response().GetHeaderCollection().GetField(strP.StringF( |
|
148 HTTP::ETransferEncoding,RHTTPSession::GetTable()),0,tmpVal) == KErrNone) |
|
149 { |
|
150 if(tmpVal.StrF().Index(RHTTPSession::GetTable()) == HTTP::EChunked ) |
|
151 { |
|
152 iEngine->Utils().LogIt(_L("EChunked Detected in Header. Hence the Test Fails")); |
|
153 iTestFail= ETrue; |
|
154 } |
|
155 } |
|
156 } break; |
|
157 case THTTPEvent::EGotResponseBodyData: |
|
158 { |
|
159 // Some (more) body data has been received (in the HTTP response) |
|
160 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received (%d)>\n"),aEvent.iStatus); |
|
161 // for each chunk of data received we have to empty the buffer before to be able to receive |
|
162 MHTTPDataSupplier* body = aTransaction.Response().Body(); |
|
163 body->ReleaseData(); |
|
164 } break; |
|
165 case THTTPEvent::EResponseComplete: |
|
166 { |
|
167 // The transaction's response is complete |
|
168 iEngine->Utils().LogIt(_L("<EResponseComplete received (%d)>\n"),aEvent.iStatus); |
|
169 } break; |
|
170 case THTTPEvent::ESucceeded: |
|
171 { |
|
172 if (iExpectedError < 0 && (!iExpectError)) |
|
173 { |
|
174 iEngine->Utils().LogIt(_L("<Expected Error Code Not Recieved (%d)>\n"),iExpectedError); |
|
175 iTestFail = ETrue; |
|
176 } |
|
177 else |
|
178 { |
|
179 iTestFail = EFalse; |
|
180 } |
|
181 iEngine->Utils().LogIt(_L("<ESucceeded received from the VF (%d)>\n"),aEvent.iStatus); |
|
182 if (--iOpenTransactionCount == 0) |
|
183 CActiveScheduler::Stop(); |
|
184 } break; |
|
185 case THTTPEvent::EFailed: |
|
186 { |
|
187 iEngine->Utils().LogIt(_L("<EFailed received from the VF (%d)>\n"),aEvent.iStatus); |
|
188 Validate(aTransaction); |
|
189 if (--iOpenTransactionCount == 0) |
|
190 CActiveScheduler::Stop(); |
|
191 } break; |
|
192 case KErrHttpRequestHasBody: |
|
193 iEngine->Utils().LogIt(_L("<KErrHttpRequestHasBody received from the VF (%d)>\n"),aEvent.iStatus); |
|
194 break; |
|
195 case KErrHttpEntityHeaderMissingContentType: |
|
196 iEngine->Utils().LogIt(_L("<KErrHttpEntityHeaderMissingContentType received from the VF (%d)>\n"),aEvent.iStatus); |
|
197 break; |
|
198 case KErrHttpRequestBodyMissing: |
|
199 { |
|
200 iEngine->Utils().LogIt(_L("<KErrHttpRequestBodyMissing received from the VF(%d)>\n"),aEvent.iStatus); |
|
201 } break; |
|
202 case KErrTimedOut: //-33 |
|
203 { |
|
204 iEngine->Utils().LogIt(_L("<KErrTimedOut received from the VF (%d)>\n"),aEvent.iStatus); |
|
205 if ((iExpectedError != 0) && (iExpectedError != KErrTimedOut)) |
|
206 { |
|
207 iTestFail = 1; |
|
208 iEngine->Utils().LogIt(_L("<The event received will cause a failure (%d)>\n"),aEvent.iStatus); |
|
209 } |
|
210 } break; |
|
211 case KErrHttpRedirectExceededLimit: |
|
212 { |
|
213 iEngine->Utils().LogIt(_L("<KErrHttpRedirectExceededLimit received (%d)>\n"),aEvent.iStatus); |
|
214 if ((iExpectedError != 0) && (iExpectedError != KErrHttpRedirectExceededLimit)) |
|
215 { |
|
216 iTestFail = 1; |
|
217 iEngine->Utils().LogIt(_L("<The event received will cause a failure>\n")); |
|
218 } |
|
219 } break; |
|
220 case KErrHttpRedirectNoLocationField: |
|
221 { |
|
222 iEngine->Utils().LogIt(_L("<KErrHttpRedirectNoLocationField received (%d)>\n"),aEvent.iStatus); |
|
223 if ((iExpectedError != 0) && (iExpectedError != KErrHttpRedirectNoLocationField)) |
|
224 { |
|
225 iTestFail = 1; |
|
226 iEngine->Utils().LogIt(_L("<The event received will cause a failure>\n")); |
|
227 } |
|
228 } break; |
|
229 |
|
230 // 301( Moved Permanently) or 302(Found) or 307(Temporary Redirect) status code is |
|
231 // obtained for a transaction with a method other than GET or HEAD and hence this event |
|
232 // has been sent by the filter. |
|
233 case THTTPEvent::ERedirectRequiresConfirmation: |
|
234 { |
|
235 iEngine->Utils().LogIt(_L("<Redirect requires confirmation (%d)>\n"),aEvent.iStatus); |
|
236 // Client has opted to Submit the transaction |
|
237 if(iExpectedStatusCode==200) |
|
238 aTransaction.SubmitL(); |
|
239 else |
|
240 // client has opted to close the transaction |
|
241 { |
|
242 if (--iOpenTransactionCount == 0) |
|
243 CActiveScheduler::Stop(); |
|
244 } |
|
245 } break; |
|
246 case THTTPEvent::EGotResponseTrailerHeaders: |
|
247 { |
|
248 iEngine->Utils().LogIt(_L("<EGotResponseTrailerHeaders received (%d)>\n"),aEvent.iStatus); |
|
249 } |
|
250 break; |
|
251 default: |
|
252 { |
|
253 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
254 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
255 { |
|
256 iTestFail=1; |
|
257 iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n")); |
|
258 iEngine->PressAnyKey(); |
|
259 } |
|
260 } |
|
261 break; |
|
262 } |
|
263 } |