|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "unittest_activitymanager.h" |
|
18 |
|
19 #include <QtTest/QtTest> |
|
20 #include <QVariant> |
|
21 #include <QTimer> |
|
22 |
|
23 #include "afactivities_global.h" |
|
24 #include "applicationlauncher_p.h" |
|
25 #include "afmanager.h" |
|
26 |
|
27 const char DefaultActivityName [] = "DefaultTestActivityName"; |
|
28 |
|
29 void TestActivityManager::init() |
|
30 { |
|
31 mServiceProvider = QSharedPointer<AfStorageProxy>(new AfStorageProxy()); |
|
32 mManager = new AfManager(mServiceProvider); |
|
33 } |
|
34 |
|
35 void TestActivityManager::cleanup() |
|
36 { |
|
37 delete mManager; |
|
38 mManager = NULL; |
|
39 } |
|
40 |
|
41 |
|
42 void TestActivityManager::testActivityList() |
|
43 { |
|
44 mManager->activitiesList(); |
|
45 } |
|
46 |
|
47 void TestActivityManager::testLaunchStartupCaseWithoutUri() |
|
48 { |
|
49 RProcess process; |
|
50 const int applicationId(process.SecureId().iId); |
|
51 QString activityId(DefaultActivityName); |
|
52 |
|
53 mManager->launchActivity(applicationId, activityId); |
|
54 |
|
55 // verify output |
|
56 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
57 QVERIFY(launcher); //sanity check |
|
58 QCOMPARE(launcher->startApplicationCalls.count(), 1); |
|
59 QCOMPARE(launcher->startApplicationCalls.first().value("applicationId").toUInt(), QVariant(applicationId).toUInt()); |
|
60 QCOMPARE(launcher->startApplicationCalls.first().value("uri").toUrl().queryItemValue(Af::KActivityUriNameKey), activityId); |
|
61 } |
|
62 |
|
63 void TestActivityManager::testLaunchRunningCaseWithoutUri() |
|
64 { |
|
65 ApplicationLauncherPrivate::isRunningReturnValue = true; |
|
66 RProcess process; |
|
67 const int applicationId(process.SecureId().iId); |
|
68 QString activityId(DefaultActivityName); |
|
69 |
|
70 mManager->launchActivity(applicationId, activityId); |
|
71 |
|
72 QVERIFY(applicationId == mServiceProvider->mLastCallParams.value("applicationId").toInt()); |
|
73 QCOMPARE(QUrl(mServiceProvider->mLastCallParams.value("activityUri").toString()).queryItemValue(Af::KActivityUriNameKey), activityId); |
|
74 |
|
75 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
76 QVERIFY(launcher); //sanity check |
|
77 QCOMPARE(launcher->startApplicationCalls.count(), 0); |
|
78 } |
|
79 |
|
80 void TestActivityManager::testLaunchStartupCaseUsingUris() |
|
81 { |
|
82 ApplicationLauncherPrivate::isRunningReturnValue = false; |
|
83 |
|
84 mManager->launchActivity(QUrl(QString("appto://EEEE0000?%1=TestName").arg(Af::KActivityUriNameKey))); |
|
85 |
|
86 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
87 QVERIFY(launcher); //sanity check |
|
88 QCOMPARE(launcher->startApplicationCalls.count(), 1); |
|
89 QCOMPARE(launcher->startApplicationCalls.first().value("applicationId").toUInt(), QVariant(0xEEEE0000).toUInt()); |
|
90 QCOMPARE(launcher->startApplicationCalls.first().value("uri").toUrl().queryItemValue(Af::KActivityUriNameKey), QString("TestName")); |
|
91 } |
|
92 |
|
93 void TestActivityManager::testLaunchRunningCaseUsingUris() |
|
94 { |
|
95 ApplicationLauncherPrivate::isRunningReturnValue = true; |
|
96 |
|
97 mManager->launchActivity(QUrl(QString("appto://EEEE0000?%1=TestName").arg(Af::KActivityUriNameKey))); |
|
98 |
|
99 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
100 QVERIFY(launcher); //sanity check |
|
101 QCOMPARE(launcher->startApplicationCalls.count(), 0); |
|
102 |
|
103 QVERIFY(0xEEEE0000 == mServiceProvider->mLastCallParams.value("applicationId").toInt()); |
|
104 QCOMPARE(QUrl(mServiceProvider->mLastCallParams.value("activityUri").toString()).queryItemValue(Af::KActivityUriNameKey), QString("TestName")); |
|
105 } |
|
106 |
|
107 void TestActivityManager::testLaunchRequestsWithInvalidUris() |
|
108 { |
|
109 // neither of the launchActivity() calls in this test should succeed, so the ActivityLauncher mock |
|
110 // won't be created and we can expect that ApplicationLauncherPrivate::instance will return the |
|
111 // same object through entire test. |
|
112 ApplicationLauncherPrivate *expectedLauncherInstance = ApplicationLauncherPrivate::instance; |
|
113 |
|
114 mManager->launchActivity(QUrl()); |
|
115 QVERIFY(ApplicationLauncherPrivate::instance == expectedLauncherInstance); |
|
116 |
|
117 mManager->launchActivity(QUrl("arrr://DEADDEAD?pirates=yes")); |
|
118 QVERIFY(ApplicationLauncherPrivate::instance == expectedLauncherInstance); |
|
119 |
|
120 mManager->launchActivity(QUrl("appto://kaboom")); |
|
121 QVERIFY(ApplicationLauncherPrivate::instance == expectedLauncherInstance); |
|
122 |
|
123 mManager->launchActivity(QUrl(QString("appto://?%1=TestName").arg(Af::KActivityUriNameKey))); |
|
124 QVERIFY(ApplicationLauncherPrivate::instance == expectedLauncherInstance); |
|
125 } |
|
126 |
|
127 void TestActivityManager::testStartApplicationWithoutActivity() |
|
128 { |
|
129 ApplicationLauncherPrivate::isRunningReturnValue = false; |
|
130 |
|
131 mManager->launchActivity(QUrl("appto://DEADBEEF")); |
|
132 |
|
133 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
134 QVERIFY(launcher); //sanity check |
|
135 QCOMPARE(launcher->startApplicationCalls.count(), 1); |
|
136 QCOMPARE(launcher->bringToForegroundCalls.count(), 0); |
|
137 |
|
138 QCOMPARE(launcher->startApplicationCalls.first().value("applicationId").toUInt(), QVariant(0xDEADBEEF).toUInt()); |
|
139 QCOMPARE(launcher->startApplicationCalls.first().value("uri").toUrl().queryItems().count(), 0); |
|
140 } |
|
141 |
|
142 void TestActivityManager::testSwitchApplicationToForegroundWithoutActivity() |
|
143 { |
|
144 ApplicationLauncherPrivate::isRunningReturnValue = true; |
|
145 |
|
146 mManager->launchActivity(QUrl("appto://DEADBEEF")); |
|
147 |
|
148 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
149 QVERIFY(launcher); //sanity check |
|
150 QCOMPARE(launcher->startApplicationCalls.count(), 0); |
|
151 |
|
152 QVERIFY(0xDEADBEEF == mServiceProvider->mLastCallParams.value("applicationId").toInt()); |
|
153 QCOMPARE(QUrl(mServiceProvider->mLastCallParams.value("activityUri").toString()).queryItemValue(Af::KActivityUriNameKey), QString()); |
|
154 } |
|
155 |
|
156 void TestActivityManager::testGetThumbnail() |
|
157 { |
|
158 QSignalSpy spy(mManager, SIGNAL(thumbnailReady(QPixmap, void *))); |
|
159 QEventLoop loop; |
|
160 connect(mManager, |
|
161 SIGNAL(thumbnailReady(QPixmap, void *)), |
|
162 &loop, |
|
163 SLOT(quit())); |
|
164 //mManager->getThumbnail(23459821); |
|
165 mManager->getThumbnail(QSize(128, 128), "somestring"); |
|
166 QTimer::singleShot(3000, &loop, SLOT(quit())); |
|
167 loop.exec(); |
|
168 QVERIFY(1==spy.count()); |
|
169 } |
|
170 |
|
171 void TestActivityManager::testUriWithTestRangeUid() |
|
172 { |
|
173 ApplicationLauncherPrivate::isRunningReturnValue = false; |
|
174 |
|
175 mManager->launchActivity(QUrl(QString("appto://EBADC0DE?%1=TestName").arg(Af::KActivityUriNameKey))); |
|
176 |
|
177 ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance; |
|
178 QVERIFY(launcher); //sanity check |
|
179 QCOMPARE(launcher->startApplicationCalls.count(), 1); |
|
180 QCOMPARE(launcher->startApplicationCalls.first().value("applicationId").toUInt(), QVariant(0xEBADC0DE).toUInt()); |
|
181 } |
|
182 |
|
183 QTEST_MAIN(TestActivityManager) |