|
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 // Author: Leon.Clarke@symbian.com |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include "Tc8.h" |
|
20 #include <http.h> |
|
21 #include "testservers.h" |
|
22 |
|
23 CHttpTestCase8::CHttpTestCase8(CScriptFile* aIniSettingsFile) : |
|
24 CHttpTestTransBase(), |
|
25 iIniSettingsFile(aIniSettingsFile) |
|
26 { |
|
27 } |
|
28 |
|
29 void CHttpTestCase8::DoRunL() |
|
30 { |
|
31 // Literals used in the function |
|
32 _LIT8(KWapTestUrl, "http://WapTestIP/perl/protected/dumpform.pl"); |
|
33 |
|
34 // Replace the host name in the URL |
|
35 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
36 CleanupStack::PushL(newUrl8); |
|
37 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
38 |
|
39 TUriParser8 testURI; |
|
40 testURI.Parse(newUrlPtr8); |
|
41 |
|
42 //open a Session |
|
43 RHTTPSession mySession; |
|
44 mySession.OpenL(); |
|
45 CleanupClosePushL(mySession); |
|
46 iEngine->Utils().LogIt(_L("Session Created(TC8)")); |
|
47 iEngine->Utils().LogIt(_L("Session parameters: Default")); |
|
48 // Install the authorisation plugin. |
|
49 InstallAuthenticationL(mySession); |
|
50 //Get the mySession'string pool handle; |
|
51 iMyStrP = mySession.StringPool(); |
|
52 //Create , open and push in the CS a Transaction in mySession |
|
53 RHTTPTransaction myTransaction; |
|
54 myTransaction = mySession.OpenTransactionL(testURI, *this, mySession.StringPool().StringF(HTTP::EPOST,RHTTPSession::GetTable())); |
|
55 CleanupClosePushL(myTransaction); |
|
56 iEngine->Utils().LogIt(_L("Transaction Created in mySession")); |
|
57 //Get a handle of the request in myTransaction |
|
58 RHTTPRequest myRequest = myTransaction.Request(); |
|
59 RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); |
|
60 // provide some headers |
|
61 THTTPHdrVal v2(iMyStrP.OpenFStringL(_L8("text/plain"))); |
|
62 THTTPHdrVal v3(iMyStrP.OpenFStringL(_L8("text/html"))); |
|
63 THTTPHdrVal v4(6); |
|
64 myHeaders.SetFieldL(iMyStrP.OpenFStringL(_L8("Accept")),v2 ); |
|
65 myHeaders.SetFieldL(iMyStrP.OpenFStringL(_L8("Content-Type")), v3); |
|
66 myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength, RHTTPSession::GetTable()),v4); |
|
67 iEngine->Utils().LogIt(_L("Testing Authentication. Method:Post")); |
|
68 myRequest.SetBody(*this); |
|
69 myTransaction.SubmitL(); |
|
70 CActiveScheduler::Start(); |
|
71 myTransaction.Close(); |
|
72 iEngine->Utils().LogIt(_L("Transaction terminated\n")); |
|
73 mySession.Close(); |
|
74 iEngine->Utils().LogIt(_L("Session terminated")); |
|
75 if (iTestFail==1) |
|
76 { |
|
77 User::Leave(-1); |
|
78 } |
|
79 CleanupStack::Pop(2); // mySession,myTansaction |
|
80 CleanupStack::PopAndDestroy(newUrl8); |
|
81 } |
|
82 |
|
83 TInt CHttpTestCase8::RunError(TInt aErr) |
|
84 { |
|
85 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aErr); |
|
86 return KErrNone; |
|
87 } |
|
88 |
|
89 void CHttpTestCase8::DoCancel() |
|
90 { |
|
91 } |
|
92 |
|
93 CHttpTestCase8::~CHttpTestCase8() |
|
94 { |
|
95 } |
|
96 |
|
97 /** set this object active */ |
|
98 void CHttpTestCase8::CompleteOwnRequest() |
|
99 { |
|
100 TRequestStatus* stat = &iStatus; |
|
101 User::RequestComplete(stat,KErrNone); |
|
102 if (!IsActive()) |
|
103 SetActive(); |
|
104 } |
|
105 |
|
106 |
|
107 |
|
108 /** sets base test name. |
|
109 @param void |
|
110 @return string - the test name |
|
111 */ |
|
112 const TDesC& CHttpTestCase8::TestName() |
|
113 { |
|
114 _LIT(KHeaderTestName,"Test Case 8 "); |
|
115 return KHeaderTestName; |
|
116 } |
|
117 |
|
118 TInt CHttpTestCase8::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, |
|
119 const THTTPEvent& /*aEvent*/) |
|
120 { |
|
121 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 void CHttpTestCase8::MHFRunL(RHTTPTransaction aTransaction, |
|
126 const THTTPEvent& aEvent) |
|
127 { |
|
128 switch (aEvent.iStatus) |
|
129 { |
|
130 case THTTPEvent::EGotResponseHeaders: |
|
131 { |
|
132 // HTTP response headers have been received |
|
133 iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n")); |
|
134 TInt statusCode = aTransaction.Response().StatusCode(); |
|
135 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
136 DumpRespHeaders(aTransaction); |
|
137 iEngine->SetCurrentStatusCode(statusCode); |
|
138 if (iExpectedStatusCode != statusCode) |
|
139 { |
|
140 iTestFail=1; |
|
141 iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n")); |
|
142 } |
|
143 } break; |
|
144 case THTTPEvent::EGotResponseBodyData: |
|
145 { |
|
146 // Some (more) body data has been received (in the HTTP response) |
|
147 iEngine->Utils().LogIt(_L("<Got some body data>\n")); |
|
148 // for each chunk of data received we have to empty the buffer before |
|
149 // to be able to receive |
|
150 MHTTPDataSupplier* body = aTransaction.Response().Body(); |
|
151 body->ReleaseData(); |
|
152 } break; |
|
153 case THTTPEvent::EResponseComplete: |
|
154 { |
|
155 // The transaction's response is complete |
|
156 iEngine->Utils().LogIt(_L("<EResponseComplete received >\n")); |
|
157 } break; |
|
158 case THTTPEvent::ESucceeded: |
|
159 { |
|
160 iEngine->Utils().LogIt(_L("<ESucceeded received from the VF>\n")); |
|
161 CActiveScheduler::Stop(); |
|
162 } break; |
|
163 default: |
|
164 { |
|
165 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
166 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
167 { |
|
168 iTestFail=1; |
|
169 iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n")); |
|
170 iEngine->PressAnyKey(); |
|
171 CActiveScheduler::Stop(); |
|
172 } |
|
173 } |
|
174 break; |
|
175 } |
|
176 } |
|
177 |
|
178 TBool CHttpTestCase8::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword) |
|
179 { |
|
180 iEngine->Utils().LogIt(_L("Supplying credentials")); |
|
181 iEngine->Utils().DumpData(aURI.UriDes()); |
|
182 iEngine->Utils().DumpData(aRealm.DesC()); |
|
183 iEngine->Utils().DumpData(aAuthenticationType.DesC()); |
|
184 _LIT8(KScooby, "scooby"); |
|
185 _LIT8(KDoo, "doo"); |
|
186 RStringPool p = aRealm.Pool(); |
|
187 aUsername = p.OpenStringL(KScooby); |
|
188 aPassword = p.OpenStringL(KDoo); |
|
189 return ETrue; |
|
190 } |