|
1 // Copyright (c) 2010 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 @file |
|
18 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 #include "t_forceregstep.h" |
|
22 #include <e32base.h> |
|
23 #include <e32cmn.h> |
|
24 #include "T_SisFileInstaller.h" |
|
25 #include <apgtask.h> |
|
26 #include <apgnotif.h> |
|
27 #include <e32property.h> |
|
28 #include<usif/scr/appregentries.h> |
|
29 #include "testableapalssession.h" |
|
30 |
|
31 _LIT(KForceRegApp1SisFile, "z:\\apparctest\\apparctestsisfiles\\ForceRegApp1.sis"); |
|
32 _LIT(KForceRegApp1Component, "ForceRegApp1"); |
|
33 |
|
34 _LIT(KForceRegMultipleAppsSisFile, "z:\\apparctest\\apparctestsisfiles\\ForceRegMultipleApps.sis"); |
|
35 _LIT(KForceRegMultipleAppsComponent, "ForceRegMultipleApps"); |
|
36 |
|
37 _LIT(KForceRegApp2SisFile, "z:\\apparctest\\apparctestsisfiles\\ForceRegApp2.sis"); |
|
38 _LIT(KForceRegApp2Component, "ForceRegApp2"); |
|
39 |
|
40 const TUint KForceRegistratioWaitTime=5000000; //5s |
|
41 const TUid KUidForceRegApp2={0xA0001001}; |
|
42 _LIT(KTestClientNotificationThreadName, "TestClientNotificationThreadName"); |
|
43 |
|
44 |
|
45 CT_ForceRegStep::~CT_ForceRegStep() |
|
46 /** |
|
47 Destructor |
|
48 */ |
|
49 { |
|
50 } |
|
51 |
|
52 CT_ForceRegStep::CT_ForceRegStep() |
|
53 /** |
|
54 Constructor |
|
55 */ |
|
56 { |
|
57 // Call base class method to set up the human readable name for logging |
|
58 SetTestStepName(KT_ForceRegStep); |
|
59 } |
|
60 |
|
61 TVerdict CT_ForceRegStep::doTestStepPreambleL() |
|
62 /** |
|
63 @return - TVerdict code |
|
64 Override of base class virtual |
|
65 */ |
|
66 { |
|
67 |
|
68 //Create property which is used for communication between test and force registered applications. |
|
69 TInt error; |
|
70 error=RProperty::Define(KPropertyCategory, KForceRegTestPropertyKey, RProperty::EInt); |
|
71 if((error != KErrNone) && (error != KErrAlreadyExists)) |
|
72 User::Leave(error); |
|
73 |
|
74 SetTestStepResult(EPass); |
|
75 return TestStepResult(); |
|
76 } |
|
77 |
|
78 TVerdict CT_ForceRegStep::doTestStepPostambleL() |
|
79 /** |
|
80 @return - TVerdict code |
|
81 Override of base class virtual |
|
82 */ |
|
83 { |
|
84 RProperty::Delete(KPropertyCategory, KForceRegTestPropertyKey); |
|
85 |
|
86 return TestStepResult(); |
|
87 } |
|
88 |
|
89 |
|
90 TVerdict CT_ForceRegStep::doTestStepL() |
|
91 { |
|
92 RunTestCases(); |
|
93 return TestStepResult(); |
|
94 } |
|
95 |
|
96 |
|
97 void CT_ForceRegStep::RunTestCases() |
|
98 { |
|
99 RTestableApaLsSession ls; |
|
100 User::LeaveIfError(ls.Connect()); |
|
101 RPointerArray<TDesC> regFiles; |
|
102 //Check the earlier force registration API is not supported |
|
103 TEST(ls.ForceRegistration(regFiles) == KErrNotSupported); |
|
104 |
|
105 CSisFileInstaller sisFileInstaller; |
|
106 TApaAppInfo info; |
|
107 TUid uid1 = {0xA0001000}; |
|
108 TInt err = ls.GetAppInfo(info, uid1); |
|
109 if(err == KErrNone) |
|
110 { |
|
111 sisFileInstaller.UninstallSisL(KForceRegApp1Component); |
|
112 } |
|
113 |
|
114 TUid uid2 = {0xA0001001}; |
|
115 err = ls.GetAppInfo(info, uid2); |
|
116 if(err == KErrNone) |
|
117 { |
|
118 sisFileInstaller.UninstallSisL(KForceRegApp2Component); |
|
119 } |
|
120 |
|
121 //Wait if apparc updating the applist |
|
122 TRequestStatus applistChangeStatus; |
|
123 ls.SetNotify(ETrue, applistChangeStatus); |
|
124 User::WaitForRequest(applistChangeStatus); |
|
125 |
|
126 //DONT_CHECK is used because when an application is installed the updated application |
|
127 //information is added in the session objects. This causes increase of memory at server side. |
|
128 //As there can be multiple applications registered with apparc for applist change notifications, |
|
129 //its not possible to clear the information in all the session objects. |
|
130 HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestSingleForceRegistration(ls), NO_CLEANUP); |
|
131 HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestMultipleForceRegistration(ls), NO_CLEANUP); |
|
132 HEAP_TEST_LS_SESSION(ls, 0, 0, TestForceRegistrationSecurity(ls), NO_CLEANUP); |
|
133 //HEAP_TEST_LS_SESSION(ls, 0, 0, TestForceRegistrationWhenInstallationFailed(ls), NO_CLEANUP); |
|
134 HEAP_TEST_LS_SESSION(ls, 0, DONT_CHECK, TestForceRegistrationAndNoClientNotification(ls), NO_CLEANUP); |
|
135 ls.Close(); |
|
136 } |
|
137 |
|
138 |
|
139 /** |
|
140 @SYMTestCaseID APPFWK-APPARC-0106 |
|
141 |
|
142 |
|
143 @SYMTestCaseDesc Tests whether force registration works with a sis file which has single run on install |
|
144 application. |
|
145 |
|
146 @SYMTestPriority High |
|
147 |
|
148 @SYMTestStatus Implemented |
|
149 |
|
150 @SYMTestActions 1. Attaches to a property which will be set by force registered (or run on install) |
|
151 application when it got executed. |
|
152 2. Installs sis file which has run on install application. |
|
153 3. Waits till the run on install application changes the propery or a timer expires. |
|
154 4. Checks the property is changed by run on install application. |
|
155 |
|
156 @SYMTestExpectedResults The property is changed by run on install application. |
|
157 */ |
|
158 void CT_ForceRegStep::TestSingleForceRegistration(RTestableApaLsSession &aLs) |
|
159 { |
|
160 INFO_PRINTF1(_L("TestSingleForceRegistration test started...........")); |
|
161 RProperty forceRegStatus; |
|
162 User::LeaveIfError(forceRegStatus.Attach(KPropertyCategory, KForceRegTestPropertyKey, EOwnerThread)); |
|
163 CleanupClosePushL(forceRegStatus); |
|
164 |
|
165 TRequestStatus forceRegStatusChange; |
|
166 TRequestStatus forceRegWait; //Timer expiration status |
|
167 |
|
168 //Timer to wait for definite time. |
|
169 RTimer timerToWait; |
|
170 User::LeaveIfError(timerToWait.CreateLocal()); |
|
171 CleanupClosePushL(timerToWait); |
|
172 timerToWait.After(forceRegWait, KForceRegistratioWaitTime); |
|
173 |
|
174 //The property value will be changed by forceregistered application when its executed. |
|
175 forceRegStatus.Subscribe(forceRegStatusChange); |
|
176 |
|
177 INFO_PRINTF1(_L("Install forceregapp1 application")); |
|
178 //Install the forceregapp1 |
|
179 CSisFileInstaller sisFileInstaller; |
|
180 INFO_PRINTF2(_L("Installing sis file from -> %S"), &KForceRegApp1SisFile); |
|
181 sisFileInstaller.InstallSisL(KForceRegApp1SisFile); |
|
182 |
|
183 INFO_PRINTF1(_L("Wait till the timer expires or force registered application changes the property")); |
|
184 //Wait till the property is changed by forceregapp1 or till timer expires |
|
185 User::WaitForRequest(forceRegWait, forceRegStatusChange); |
|
186 |
|
187 TInt value; |
|
188 forceRegStatus.Get(value); |
|
189 INFO_PRINTF2(_L("Property value: %d"), value); |
|
190 //Check the property value is changed by forceregapp1 |
|
191 TEST(value == KForceRegApp1Executed); |
|
192 |
|
193 INFO_PRINTF1(_L("Uninstall forceregapp1 application")); |
|
194 //Uninstall the forceregapp1 |
|
195 sisFileInstaller.UninstallSisAndWaitForAppListUpdateL(KForceRegApp1Component); |
|
196 CleanupStack::PopAndDestroy(2); //forceRegStatus, timerToWait |
|
197 INFO_PRINTF1(_L("TestSingleForceRegistration test ended...........")); |
|
198 } |
|
199 |
|
200 |
|
201 /** |
|
202 @SYMTestCaseID APPFWK-APPARC-0106 |
|
203 |
|
204 |
|
205 @SYMTestCaseDesc Tests whether force registration works with a sis file which has multiple run on install |
|
206 applications. |
|
207 |
|
208 @SYMTestPriority High |
|
209 |
|
210 @SYMTestStatus Implemented |
|
211 |
|
212 @SYMTestActions 1. Attaches to a property which will be set by force registered (or run on install) |
|
213 application when it got executed. |
|
214 2. Installs sis file which has multiple run on install applications. |
|
215 3. Waits till the run on install applications changes the propery or a timer expires. |
|
216 4. Checks the property is changed by run on install applications. |
|
217 |
|
218 @SYMTestExpectedResults The property is changed by run on install applications. |
|
219 */ |
|
220 |
|
221 void CT_ForceRegStep::TestMultipleForceRegistration(RTestableApaLsSession &aLs) |
|
222 { |
|
223 INFO_PRINTF1(_L("TestMultipleForceRegistration test started...........")); |
|
224 RProperty forceRegStatus; |
|
225 User::LeaveIfError(forceRegStatus.Attach(KPropertyCategory, KForceRegTestPropertyKey, EOwnerThread)); |
|
226 //Set the property to a KStopForceRegApp2 to make the forceregapp2 to exit. |
|
227 forceRegStatus.Set(KStopForceRegApp2); |
|
228 |
|
229 TRequestStatus forceRegApp1Executed, forceRegApp2Executed; |
|
230 TRequestStatus forceRegWait; |
|
231 |
|
232 //Timer to wait for definite time. |
|
233 RTimer timeToWait; |
|
234 User::LeaveIfError(timeToWait.CreateLocal()); |
|
235 timeToWait.After(forceRegWait, KForceRegistratioWaitTime); |
|
236 //The property value will be changed by forceregistered application. Subscribe to property change. |
|
237 forceRegStatus.Subscribe(forceRegApp1Executed); |
|
238 |
|
239 INFO_PRINTF1(_L("Install forceregapp1 and forceregapp2 application")); |
|
240 //Install the forceregapp1 |
|
241 CSisFileInstaller sisFileInstaller; |
|
242 INFO_PRINTF2(_L("Installing sis file from -> %S"), &KForceRegMultipleAppsSisFile); |
|
243 sisFileInstaller.InstallSisL(KForceRegMultipleAppsSisFile); |
|
244 |
|
245 INFO_PRINTF1(_L("Wait till the timer expires or force registered applications changes the property")); |
|
246 User::WaitForRequest(forceRegWait, forceRegApp1Executed); |
|
247 |
|
248 TInt value; |
|
249 forceRegStatus.Get(value); |
|
250 |
|
251 //If the property value is not as expected, wait till the forceregapp2 is executed. |
|
252 if(value != (KForceRegApp1Executed|KForceRegApp2Executed|KStopForceRegApp2)) |
|
253 { |
|
254 forceRegStatus.Subscribe(forceRegApp2Executed); |
|
255 forceRegWait=KRequestPending; |
|
256 timeToWait.After(forceRegWait, KForceRegistratioWaitTime); |
|
257 User::WaitForRequest(forceRegWait, forceRegApp2Executed); |
|
258 } |
|
259 |
|
260 forceRegStatus.Get(value); |
|
261 INFO_PRINTF2(_L("Property value: %d"), value); |
|
262 //Check whether both force registered applications executed. |
|
263 TEST(value == (KForceRegApp1Executed|KForceRegApp2Executed|KStopForceRegApp2)); |
|
264 |
|
265 INFO_PRINTF1(_L("Uninstall forceregapp1 and forceregapp2 application")); |
|
266 sisFileInstaller.UninstallSisAndWaitForAppListUpdateL(KForceRegMultipleAppsComponent); |
|
267 forceRegStatus.Close(); |
|
268 //Wait for time so that appac completes applist cache creation. |
|
269 User::After(2000000); |
|
270 } |
|
271 |
|
272 |
|
273 /** |
|
274 @SYMTestCaseID APPFWK-APPARC-0106 |
|
275 |
|
276 |
|
277 @SYMTestCaseDesc Tests force registration security. Force registration can only be used by SWI. |
|
278 |
|
279 @SYMTestPriority High |
|
280 |
|
281 @SYMTestStatus Implemented |
|
282 |
|
283 @SYMTestActions 1. Creates dummy application information. |
|
284 2. Call the force registration with this application info. |
|
285 3. Check return value is KErrNotSupported. |
|
286 |
|
287 @SYMTestExpectedResults ForceRegistration should return KErrNotSupported if other Software Installer |
|
288 trying to use it. |
|
289 */ |
|
290 |
|
291 void CT_ForceRegStep::TestForceRegistrationSecurity(RTestableApaLsSession &aLs) |
|
292 { |
|
293 INFO_PRINTF1(_L("TestForceRegistrationSecurity test started...........")); |
|
294 Usif::CApplicationRegistrationData *appData=Usif::CApplicationRegistrationData::NewL(); |
|
295 CleanupStack::PushL(appData); |
|
296 RPointerArray<Usif::CApplicationRegistrationData> appArray; |
|
297 |
|
298 INFO_PRINTF1(_L("Call ForceRegistration with empty TApaAppUpdate info array..........")); |
|
299 TEST(aLs.ForceRegistration(appArray)==KErrNone); |
|
300 appArray.AppendL(appData); |
|
301 INFO_PRINTF1(_L("Call ForceRegistration with TApaAppUpdate info array..........")); |
|
302 TEST(aLs.ForceRegistration(appArray)==KErrNotSupported); |
|
303 |
|
304 CleanupStack::PopAndDestroy(appData); |
|
305 appArray.Close(); |
|
306 INFO_PRINTF1(_L("TestForceRegistrationSecurity test ended...........")); |
|
307 } |
|
308 |
|
309 |
|
310 /** |
|
311 @SYMTestCaseID APPFWK-APPARC-0106 |
|
312 |
|
313 @SYMTestCaseDesc Tests force registered applications information removed from the applist if |
|
314 installation fails. |
|
315 |
|
316 @SYMTestPriority High |
|
317 |
|
318 @SYMTestStatus Implemented |
|
319 |
|
320 @SYMTestActions 1. Install sis file which has force registered application. |
|
321 2. Cancel the installation. |
|
322 2. Check the force registered application is not available in the applist. |
|
323 |
|
324 @SYMTestExpectedResults Force registered application information is removed from the applist |
|
325 */ |
|
326 |
|
327 void CT_ForceRegStep::TestForceRegistrationWhenInstallationFailed(RTestableApaLsSession &aLs) |
|
328 { |
|
329 INFO_PRINTF1(_L("TestForceRegistrationWhenInstallationFailed test started...........")); |
|
330 TApaAppInfo appInfo; |
|
331 TInt err; |
|
332 |
|
333 //Check whether the application is already in the applist. |
|
334 err=aLs.GetAppInfo(appInfo, KUidForceRegApp2); |
|
335 INFO_PRINTF2(_L("Error Code returned: %d"), err); |
|
336 TEST(err==KErrNotFound); |
|
337 |
|
338 CSisFileInstaller sisFileInstaller; |
|
339 RProperty forceRegStatus; |
|
340 User::LeaveIfError(forceRegStatus.Attach(KPropertyCategory, KForceRegTestPropertyKey, EOwnerThread)); |
|
341 TRequestStatus propertyStatus; |
|
342 forceRegStatus.Subscribe(propertyStatus); |
|
343 |
|
344 //Install ForceRegApp2 asynchronously |
|
345 TRequestStatus installStatus; |
|
346 INFO_PRINTF1(_L("Install the sis file which eventually cancelled by test")); |
|
347 err=KErrNone; |
|
348 INFO_PRINTF2(_L("Installing sis file from -> %S"), &KForceRegApp2SisFile); |
|
349 TRAP(err, sisFileInstaller.InstallSisAsynchronouslyL(KForceRegApp2SisFile, installStatus)); |
|
350 TEST(err == KErrNone); |
|
351 |
|
352 //ForceRegApp2 is run on install application. The property is changed when the application executed. |
|
353 User::WaitForRequest(propertyStatus); |
|
354 |
|
355 //Make ForceRegApp2 to exit by adding KStopForceRegApp2 to property. |
|
356 TInt value; |
|
357 forceRegStatus.Get(value); |
|
358 value |= KStopForceRegApp2; |
|
359 forceRegStatus.Set(value); |
|
360 forceRegStatus.Close(); |
|
361 |
|
362 //Cancel the installation. |
|
363 sisFileInstaller.CancelInstallation(); |
|
364 User::WaitForRequest(installStatus); |
|
365 sisFileInstaller.Close(); |
|
366 |
|
367 User::After(2000000); |
|
368 INFO_PRINTF2(_L("Installation ended with error code: %d"), installStatus.Int()); |
|
369 TEST(installStatus.Int() != KErrNone); |
|
370 |
|
371 //Check the force registered application is no longer exists in the applist. |
|
372 err=aLs.GetAppInfo(appInfo, KUidForceRegApp2); |
|
373 INFO_PRINTF2(_L("Error Code returned: %d"), err); |
|
374 TEST(err==KErrNotFound); |
|
375 INFO_PRINTF1(_L("TestForceRegistrationWhenInstallationFailed test ended...........")); |
|
376 } |
|
377 |
|
378 TInt TestClientNotificationThread(TAny* aPtr); |
|
379 |
|
380 /** |
|
381 @SYMTestCaseID APPFWK-APPARC-0106 |
|
382 |
|
383 |
|
384 @SYMTestCaseDesc Tests if applist is changed due to force registration, apparc will not notify the |
|
385 clients. |
|
386 |
|
387 @SYMTestPriority High |
|
388 |
|
389 @SYMTestStatus Implemented |
|
390 |
|
391 @SYMTestActions 1. Start TestClientNotificationThread which registers with apparc for applist change |
|
392 notification and waits till applist change notification occurs or a timer expires. |
|
393 Once any of the event occurs, then changes the property to make the forceregapp2 to |
|
394 exit and makes the status of applist change reflects in property. |
|
395 2. Installs a sis file which has run on install forcereg1 and forcereg2 applications |
|
396 3. Waits till the TestClientNotificationThread exits. |
|
397 4. Checks whether applist change notification recieved or not. |
|
398 |
|
399 @SYMTestExpectedResults Apparc does not notify clients about applist change which occur due to force registration. |
|
400 */ |
|
401 |
|
402 void CT_ForceRegStep::TestForceRegistrationAndNoClientNotification(RTestableApaLsSession &aLs) |
|
403 { |
|
404 INFO_PRINTF1(_L("TestForceRegistrationAndNoClientNotification test started...........")); |
|
405 RProperty forceRegStatus; |
|
406 User::LeaveIfError(forceRegStatus.Attach(KPropertyCategory, KForceRegTestPropertyKey, EOwnerThread)); |
|
407 forceRegStatus.Set(0); |
|
408 |
|
409 TBuf<0x100> threadName(KTestClientNotificationThreadName); |
|
410 RThread thread; |
|
411 |
|
412 INFO_PRINTF1(_L("Start TestClientNotificationThread thread")); |
|
413 User::LeaveIfError(thread.Create(threadName, TestClientNotificationThread, 0x1000, NULL, (TAny*) this)); |
|
414 CleanupClosePushL(thread); |
|
415 TRequestStatus status; |
|
416 thread.Logon(status); |
|
417 thread.Resume(); |
|
418 |
|
419 INFO_PRINTF1(_L("Install sis file")); |
|
420 //Install the forceregapp1 |
|
421 CSisFileInstaller sisFileInstaller; |
|
422 INFO_PRINTF2(_L("Installing sis file from -> %S"), &KForceRegMultipleAppsSisFile); |
|
423 sisFileInstaller.InstallSisL(KForceRegMultipleAppsSisFile); |
|
424 |
|
425 INFO_PRINTF1(_L("Waiting till TestClientNotificationThread thread exits")); |
|
426 User::WaitForRequest(status); |
|
427 |
|
428 TInt value; |
|
429 forceRegStatus.Get(value); |
|
430 INFO_PRINTF2(_L("Property value: %d"), value); |
|
431 TEST(!(value & KApplistChanged)); |
|
432 INFO_PRINTF1(_L("Uninstall sis file")); |
|
433 sisFileInstaller.UninstallSisL(KForceRegMultipleAppsComponent); |
|
434 CleanupStack::PopAndDestroy(); |
|
435 forceRegStatus.Close(); |
|
436 INFO_PRINTF1(_L("TestForceRegistrationAndNoClientNotification test ended...........")); |
|
437 } |
|
438 |
|
439 /* |
|
440 * TestClientNotificationThread registers with apparc for applist change notification and waits till applist |
|
441 * change notification occurs or a timer expires. Once any of the event occurs, then changes the property to |
|
442 * make the forceregapp2 to exit and makes the status of applist change reflects in property. |
|
443 */ |
|
444 |
|
445 TInt TestClientNotificationThread(TAny* aPtr) |
|
446 { |
|
447 RApaLsSession ls; |
|
448 User::LeaveIfError(ls.Connect()); |
|
449 TRequestStatus applistChangeStatus, timeOutStatus; |
|
450 ls.SetNotify(EFalse, applistChangeStatus); |
|
451 |
|
452 //Timer to wait for definite time. |
|
453 RTimer timeToWait; |
|
454 User::LeaveIfError(timeToWait.CreateLocal()); |
|
455 timeToWait.After(timeOutStatus, KForceRegistratioWaitTime); |
|
456 User::WaitForRequest(applistChangeStatus, timeOutStatus); |
|
457 |
|
458 RProperty forceRegStatus; |
|
459 User::LeaveIfError(forceRegStatus.Attach(KPropertyCategory, KForceRegTestPropertyKey, EOwnerThread)); |
|
460 TInt status; |
|
461 forceRegStatus.Get(status); |
|
462 |
|
463 if(applistChangeStatus.Int() == MApaAppListServObserver::EAppListChanged) |
|
464 status |= KApplistChanged; |
|
465 |
|
466 status |= KStopForceRegApp2; |
|
467 forceRegStatus.Set(status); |
|
468 forceRegStatus.Close(); |
|
469 |
|
470 return(KErrNone); |
|
471 } |