|
1 /** Copyright (c) 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 #include "t_tapplicationlauncher.h" |
|
17 |
|
18 #include <apgwgnam.h> |
|
19 #include <apgtask.h> |
|
20 |
|
21 #include <QtTest/QtTest> |
|
22 #include <QString> |
|
23 #include <QSystemSemaphore> |
|
24 |
|
25 #include <XQConversions> |
|
26 #include <qvaluespacesubscriber.h> |
|
27 |
|
28 #include <afactivities_global.h> |
|
29 #include <tstestutils.h> |
|
30 |
|
31 #include "afapplicationlauncher.h" |
|
32 |
|
33 const TUid KIconApplicationUid = {0xEd0b4e47}; |
|
34 const TUid KActivityApplicationUid = {0xEBADF00D}; |
|
35 const TUid KInvalidUid = {0xDEADBEEF}; |
|
36 const TUid KCorruptedApplicationUid = {0xE5C3B14E}; |
|
37 |
|
38 namespace { |
|
39 const char KIconApplicationName[] = "appwithicon"; |
|
40 } |
|
41 |
|
42 QTM_USE_NAMESPACE |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Test cases |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 void TestTApplicationLauncher::initTestCase() |
|
49 { |
|
50 QCOMPARE(mApaLsSession.Connect(), KErrNone); |
|
51 QCOMPARE(mWsSession.Connect(), KErrNone); |
|
52 } |
|
53 |
|
54 void TestTApplicationLauncher::cleanupTestCase() |
|
55 { |
|
56 mApaLsSession.Close(); |
|
57 mWsSession.Close(); |
|
58 } |
|
59 |
|
60 void TestTApplicationLauncher::testIsRunning() |
|
61 { |
|
62 TAfApplicationLauncher launcher(mApaLsSession, mWsSession); |
|
63 |
|
64 QVERIFY(!launcher.isRunning(KIconApplicationUid)); |
|
65 |
|
66 quint64 iconAppId; |
|
67 QVERIFY(TsTestUtils::startApplication(KIconApplicationName, iconAppId)); |
|
68 QVERIFY(launcher.isRunning(KIconApplicationUid)); |
|
69 |
|
70 QVERIFY(TsTestUtils::closeApplication(iconAppId)); |
|
71 QVERIFY(!launcher.isRunning(KIconApplicationUid)); |
|
72 } |
|
73 |
|
74 void TestTApplicationLauncher::testStartApp() |
|
75 { |
|
76 QSystemSemaphore semaphore("PublishActivityApp"); |
|
77 TAfApplicationLauncher launcher(mApaLsSession, mWsSession); |
|
78 |
|
79 QVERIFY(!launcher.isRunning(KActivityApplicationUid)); |
|
80 |
|
81 TRAPD(startError, launcher.startApplicationL(KActivityApplicationUid, KNullDesC())); |
|
82 QCOMPARE(startError, KErrNone); |
|
83 |
|
84 QVERIFY(semaphore.acquire()); |
|
85 |
|
86 QVERIFY(TsTestUtils::closeApplication(KActivityApplicationUid)); |
|
87 QVERIFY(!launcher.isRunning(KActivityApplicationUid)); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------- |
|
91 |
|
92 void TestTApplicationLauncher::testLaunchActivity_data() |
|
93 { |
|
94 QTest::addColumn<QString>("activityName"); |
|
95 |
|
96 QTest::newRow("normal") << "blahblahblah"; |
|
97 QTest::newRow("special characters") << "asd $&+,/:;=?@ \"<>#%{}|\\^~[]`asd"; |
|
98 } |
|
99 |
|
100 void TestTApplicationLauncher::testLaunchActivity() |
|
101 { |
|
102 QSystemSemaphore semaphore("PublishActivityApp"); |
|
103 |
|
104 TAfApplicationLauncher launcher(mApaLsSession, mWsSession); |
|
105 QVERIFY(!launcher.isRunning(KActivityApplicationUid)); |
|
106 |
|
107 QFETCH(QString, activityName); |
|
108 HBufC *uriDescriptor = XQConversions::qStringToS60Desc(QString(buildUri(KActivityApplicationUid, activityName).toEncoded())); |
|
109 TRAPD(startError, launcher.startApplicationL(KActivityApplicationUid, *uriDescriptor)); |
|
110 delete uriDescriptor; |
|
111 QCOMPARE(startError, KErrNone); |
|
112 semaphore.acquire(); |
|
113 |
|
114 QCOMPARE(QValueSpaceSubscriber("/PublishActivityApp/ActivityName").value().toString(), activityName); |
|
115 |
|
116 QVERIFY(TsTestUtils::closeApplication(KActivityApplicationUid)); |
|
117 QVERIFY(!launcher.isRunning(KIconApplicationUid)); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------- |
|
121 |
|
122 void TestTApplicationLauncher::testLeaveWhenUriIsInvalid() |
|
123 { |
|
124 TAfApplicationLauncher launcher(mApaLsSession, mWsSession); |
|
125 TRAPD(startError, launcher.startApplicationL(KInvalidUid, KNullDesC())); |
|
126 QCOMPARE(startError, KErrNotFound); |
|
127 } |
|
128 |
|
129 void TestTApplicationLauncher::testLeaveWhenApplicationIsCorrupted() |
|
130 { |
|
131 TAfApplicationLauncher launcher(mApaLsSession, mWsSession); |
|
132 |
|
133 // We're going to test Launcher behavior when someone tries to start |
|
134 // application with missing executable file |
|
135 TRAPD(startError, launcher.startApplicationL(KCorruptedApplicationUid, KNullDesC())); |
|
136 QCOMPARE(startError, KErrNotFound); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // Helper methods |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 QUrl TestTApplicationLauncher::buildUri(const TUid &uid, const QString &activityName) |
|
144 { |
|
145 QUrl uri; |
|
146 uri.setScheme("appto"); |
|
147 uri.setHost(QString("%1").arg(static_cast<uint>(uid.iUid), 8, 16, QChar('0'))); |
|
148 uri.addQueryItem(Af::KActivityUriNameKey, activityName); |
|
149 return uri; |
|
150 } |
|
151 |
|
152 bool TestTApplicationLauncher::sendToBackground(const TUid &uid) |
|
153 { |
|
154 TApaTaskList taskList(mWsSession); |
|
155 TApaTask task = taskList.FindApp(uid); |
|
156 bool taskExists = task.Exists(); |
|
157 if (taskExists) { |
|
158 task.SendToBackground(); |
|
159 } |
|
160 return taskExists; |
|
161 } |
|
162 |
|
163 TUid TestTApplicationLauncher::getForegroundAppUid() |
|
164 { |
|
165 // get all window groups |
|
166 RArray<RWsSession::TWindowGroupChainInfo> windowGroupList; |
|
167 CleanupClosePushL(windowGroupList); |
|
168 User::LeaveIfError(mWsSession.WindowGroupList(0, &windowGroupList)); |
|
169 |
|
170 if (windowGroupList.Count() == 0) { |
|
171 User::Leave(KErrNotFound); |
|
172 } |
|
173 |
|
174 // get uid of first window group |
|
175 CApaWindowGroupName* windowGroupName = CApaWindowGroupName::NewLC(mWsSession, windowGroupList[0].iId); |
|
176 TUid foregroundAppUid = windowGroupName->AppUid(); |
|
177 CleanupStack::PopAndDestroy(windowGroupName); |
|
178 CleanupStack::PopAndDestroy(&windowGroupList); |
|
179 |
|
180 return foregroundAppUid; |
|
181 } |
|
182 |
|
183 QTEST_MAIN(TestTApplicationLauncher) |