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