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