|
1 // Copyright (c) 2006-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 // The following test cases test the funtionality of RuleBased plugins framework. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include <apacmdln.h> |
|
25 #include <apgwgnam.h> |
|
26 |
|
27 #include "appfwk_test.h" |
|
28 #include "T_EndTaskStep.h" |
|
29 #include "TEndTaskTestApp/EndTaskTestAppExternalInterface.h" |
|
30 |
|
31 CTEndTaskStep::CTEndTaskStep() |
|
32 { |
|
33 // Call base class method to set up the human readable name for logging |
|
34 SetTestStepName(KT_EndTaskStep); |
|
35 } |
|
36 |
|
37 CTEndTaskStep::~CTEndTaskStep() |
|
38 { |
|
39 } |
|
40 |
|
41 void CTEndTaskStep::ExecuteL() |
|
42 { |
|
43 RApaLsSession theLs; |
|
44 User::LeaveIfError(theLs.Connect()); |
|
45 CleanupClosePushL(theLs); |
|
46 |
|
47 User::LeaveIfError(iWs.Connect()); |
|
48 CleanupClosePushL(iWs); |
|
49 |
|
50 EndTaskTest1L(theLs); |
|
51 EndTaskTest2L(theLs); |
|
52 EndTaskTest3L(theLs); |
|
53 |
|
54 CleanupStack::PopAndDestroy(); //iWs.Close(); |
|
55 CleanupStack::PopAndDestroy(&theLs); |
|
56 } |
|
57 |
|
58 /** |
|
59 @SYMTestCaseID APPFWK-APPARC-0057 |
|
60 |
|
61 @SYMDEF PDEF092171 |
|
62 |
|
63 @SYMTestCaseDesc Test case for defect "TApaTask::EndTask() allows any application kill any task" |
|
64 |
|
65 @SYMTestPriority High |
|
66 |
|
67 @SYMTestStatus Implemented |
|
68 |
|
69 @SYMTestActions Launch and close both a standard and a system application using TApaTask::EndTask(). |
|
70 |
|
71 @SYMTestExpectedResults The app should be launched and closed accordingly |
|
72 */ |
|
73 void CTEndTaskStep::EndTaskTest1L(RApaLsSession& aLs) |
|
74 { |
|
75 INFO_PRINTF1(_L("Test case 1 started")); |
|
76 |
|
77 // Launch App |
|
78 const TUid appUid = {KUidEndTaskAppUid}; |
|
79 TEST(KErrNone == LaunchAppL(aLs, appUid)); |
|
80 |
|
81 // Get a handle to App |
|
82 TApaTaskList taskList(iWs); |
|
83 TApaTask task1 = taskList.FindApp(appUid); |
|
84 TEST(task1.Exists()); |
|
85 |
|
86 // Close it |
|
87 task1.EndTask(); |
|
88 User::After(500000); |
|
89 TApaTask refresh1 = taskList.FindApp(appUid); |
|
90 TEST(!refresh1.Exists()); |
|
91 |
|
92 // |
|
93 // Now do the same again but with a system app |
|
94 // |
|
95 |
|
96 // Launch App |
|
97 TEST(KErrNone == LaunchAppL(aLs, appUid)); |
|
98 |
|
99 // Get a handle to App |
|
100 TApaTask task2 = taskList.FindApp(appUid); |
|
101 TEST(task2.Exists()); |
|
102 |
|
103 // Mark as a system app |
|
104 TWsEvent event; |
|
105 event.SetType(EEndTaskTestAppSetSystem); |
|
106 iWs.SendEventToWindowGroup(task2.WgId(), event); |
|
107 |
|
108 // Close it |
|
109 task2.EndTask(); |
|
110 User::After(500000); |
|
111 TApaTask refresh2 = taskList.FindApp(appUid); |
|
112 TEST(!refresh2.Exists()); |
|
113 |
|
114 INFO_PRINTF1(_L("Test case 1 finished")); |
|
115 } |
|
116 |
|
117 |
|
118 /** |
|
119 @SYMTestCaseID APPFWK-APPARC-0058 |
|
120 |
|
121 @SYMDEF PDEF092171 |
|
122 |
|
123 @SYMTestCaseDesc Test case for defect "TApaTask::EndTask() allows any application kill any task" |
|
124 |
|
125 @SYMTestPriority High |
|
126 |
|
127 @SYMTestStatus Implemented |
|
128 |
|
129 @SYMTestActions Try to close a systemapp from a process that do not have PwrMgmt |
|
130 |
|
131 @SYMTestExpectedResults The app should be closed accordingly |
|
132 */ |
|
133 void CTEndTaskStep::EndTaskTest2L(RApaLsSession& aLs) |
|
134 { |
|
135 INFO_PRINTF1(_L("Test case 2 started")); |
|
136 |
|
137 // Launch App |
|
138 const TUid appUid = {KUidEndTaskAppUid}; |
|
139 TEST(KErrNone == LaunchAppL(aLs, appUid)); |
|
140 |
|
141 // Get a handle to App |
|
142 TApaTaskList taskList(iWs); |
|
143 TApaTask task = taskList.FindApp(appUid); |
|
144 TEST(task.Exists()); |
|
145 |
|
146 // Mark as a system task |
|
147 TWsEvent event; |
|
148 event.SetType(EEndTaskTestAppSetSystem); |
|
149 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
150 |
|
151 // Call TApaTask::EndTask() on the systemtask from an arbitrary process which don't have PwrMgmt |
|
152 event.SetType(ECallEndTaskWithoutPwrMgmt); |
|
153 APPFWK_NEGATIVE_PLATSEC_START; |
|
154 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
155 APPFWK_NEGATIVE_PLATSEC_FINISH; |
|
156 User::After(500000); |
|
157 TApaTask refresh = taskList.FindApp(appUid); |
|
158 TEST(refresh.Exists()); // application should have stayed open |
|
159 |
|
160 // Close app from this process (which do have PwrMgmt) |
|
161 task.EndTask(); |
|
162 User::After(500000); |
|
163 TApaTask refresh2 = taskList.FindApp(appUid); |
|
164 TEST(!refresh2.Exists()); |
|
165 |
|
166 INFO_PRINTF1(_L("Test case 2 finished")); |
|
167 } |
|
168 |
|
169 /** |
|
170 @SYMTestCaseID APPFWK-APPARC-0059 |
|
171 |
|
172 @SYMDEF PDEF092171 |
|
173 |
|
174 @SYMTestCaseDesc Test case for defect "TApaTask::EndTask() allows any application kill any task" |
|
175 |
|
176 @SYMTestPriority High |
|
177 |
|
178 @SYMTestStatus Implemented |
|
179 |
|
180 @SYMTestActions Launch and close application using wserv APIs (way of faking new secure close-message) |
|
181 |
|
182 @SYMTestExpectedResults This test should pass if the process doesn't have PowerMgmt |
|
183 */ |
|
184 void CTEndTaskStep::EndTaskTest3L(RApaLsSession& aLs) |
|
185 { |
|
186 INFO_PRINTF1(_L("Test case 3 started")); |
|
187 |
|
188 // Launch App |
|
189 const TUid appUid = {KUidEndTaskAppUid}; |
|
190 TEST(KErrNone == LaunchAppL(aLs, appUid)); |
|
191 |
|
192 // Get a handle to App |
|
193 TApaTaskList taskList(iWs); |
|
194 TApaTask task = taskList.FindApp(appUid); |
|
195 TEST(task.Exists()); |
|
196 |
|
197 // Mark as a system app |
|
198 TWsEvent event; |
|
199 event.SetType(EEndTaskTestAppSetSystem); |
|
200 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
201 |
|
202 // First variant should be sorted by CCoeAppUi::HandleWsEventL |
|
203 event.SetType(ESimulateHackerAttack1); |
|
204 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
205 User::After(500000); |
|
206 TApaTask refresh = taskList.FindApp(appUid); |
|
207 TEST(refresh.Exists()); |
|
208 |
|
209 if(refresh.Exists()) |
|
210 { |
|
211 // Second variant should be handled by wserv's Client::CommandL |
|
212 event.SetType(ESimulateHackerAttack2); |
|
213 APPFWK_NEGATIVE_PLATSEC_START; |
|
214 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
215 APPFWK_NEGATIVE_PLATSEC_FINISH; |
|
216 User::After(500000); |
|
217 TApaTask refresh2 = taskList.FindApp(appUid); |
|
218 TEST(refresh2.Exists()); |
|
219 |
|
220 if(refresh2.Exists()) |
|
221 { |
|
222 // Third variant should also be handled by wserv's Client::CommandL in another switch-case |
|
223 event.SetType(ESimulateHackerAttack3); |
|
224 APPFWK_NEGATIVE_PLATSEC_START; |
|
225 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
226 APPFWK_NEGATIVE_PLATSEC_FINISH; |
|
227 User::After(500000); |
|
228 TApaTask refresh3 = taskList.FindApp(appUid); |
|
229 TEST(refresh3.Exists()); |
|
230 |
|
231 if(refresh3.Exists()) |
|
232 { |
|
233 // Remove system property |
|
234 event.SetType(EEndTaskTestAppSetNormal); |
|
235 iWs.SendEventToWindowGroup(task.WgId(), event); |
|
236 |
|
237 // Close app |
|
238 task.EndTask(); |
|
239 User::After(500000); |
|
240 TApaTask refresh5 = taskList.FindApp(appUid); |
|
241 TEST(!refresh5.Exists()); |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 INFO_PRINTF1(_L("Test case 3 finished")); |
|
247 } |
|
248 |
|
249 /** |
|
250 The function is used to launch an app whose UID is supplied as its second input parameter. |
|
251 The function returns KErrNone upon success, KErrGeneral otherwise. |
|
252 */ |
|
253 TInt CTEndTaskStep::LaunchAppL(RApaLsSession& aLs, const TUid& aAppUid) |
|
254 { |
|
255 TApaAppInfo info; |
|
256 TFileName fileName; |
|
257 User::LeaveIfError(aLs.GetAppInfo(info, aAppUid)); |
|
258 |
|
259 //Wait 1 sec for function to complete |
|
260 User::After(1000000); |
|
261 fileName = info.iFullName; |
|
262 CApaCommandLine* cmdLn = CApaCommandLine::NewLC(); |
|
263 cmdLn->SetDocumentNameL(KNullDesC); //need to start without resource file |
|
264 cmdLn->SetExecutableNameL(fileName); |
|
265 |
|
266 TThreadId threadId; |
|
267 TRequestStatus status = KRequestPending; |
|
268 TInt result = aLs.StartApp(*cmdLn, threadId, &status); |
|
269 User::WaitForRequest(status); |
|
270 CleanupStack::PopAndDestroy(cmdLn); |
|
271 return result; |
|
272 } |
|
273 |
|
274 TVerdict CTEndTaskStep::doTestStepL() |
|
275 { |
|
276 INFO_PRINTF1(_L("TEndTaskStep test started....")); |
|
277 |
|
278 __UHEAP_MARK; |
|
279 TRAPD(err, ExecuteL()); |
|
280 if(err != KErrNone) |
|
281 { |
|
282 INFO_PRINTF2(_L("execute tests ended with return value '%d'"), err); |
|
283 TEST(EFalse); |
|
284 } |
|
285 __UHEAP_MARKEND; |
|
286 |
|
287 INFO_PRINTF1(_L(".... TEndTaskStep test finished!!")); |
|
288 return TestStepResult(); |
|
289 } |