90
|
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: Main test class for hsHomeScreenStatePlugin library.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "t_hsmenuworkerstateplugin.h"
|
|
20 |
|
|
21 |
#include <hbmainwindow.h>
|
|
22 |
#include <HbMessageBox>
|
|
23 |
#include <HbAction>
|
|
24 |
|
|
25 |
#include <QGraphicsItem>
|
|
26 |
#include <qstatemachine.h>
|
|
27 |
|
|
28 |
#include "hsmenuitemmodel.h"
|
|
29 |
#include "hsmenuservice.h"
|
|
30 |
#include "hscontentservice.h"
|
|
31 |
#include "hsshortcutservice.h"
|
|
32 |
#include "hsmenuworkerstate.h"
|
|
33 |
#include "hsaddtohomescreenstate.h"
|
|
34 |
#include "hsdialogcontroller.h"
|
|
35 |
#include "hsapp_defs.h"
|
|
36 |
#include "hspage.h"
|
|
37 |
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
97
|
40 |
//
|
90
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
void MenuStatesTest::AddToHomeScreenState_construction()
|
|
44 |
{
|
|
45 |
#ifdef Q_OS_SYMBIAN
|
|
46 |
#ifdef UT_MEMORY_CHECK
|
|
47 |
__UHEAP_MARK;
|
|
48 |
#endif//UT_MEMORY_CHECK
|
|
49 |
#endif//Q_OS_SYMBIAN
|
|
50 |
{
|
|
51 |
QState *parent = new QState();
|
|
52 |
|
|
53 |
HsAddToHomeScreenState *as1 = new HsAddToHomeScreenState(parent);
|
|
54 |
|
|
55 |
HsAddToHomeScreenState *as2 = new HsAddToHomeScreenState(parent);
|
|
56 |
|
|
57 |
QString on1 = as1->objectName();
|
|
58 |
QString on2 = as2->objectName();
|
|
59 |
QVERIFY(on1 == on2);
|
|
60 |
}
|
|
61 |
#ifdef Q_OS_SYMBIAN
|
|
62 |
#ifdef UT_MEMORY_CHECK
|
|
63 |
__UHEAP_MARKEND;
|
|
64 |
#endif//UT_MEMORY_CHECK
|
|
65 |
#endif//Q_OS_SYMBIAN
|
|
66 |
}
|
|
67 |
|
|
68 |
// ---------------------------------------------------------------------------
|
97
|
69 |
//
|
90
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
void MenuStatesTest::AddToHomeScreenState_onEntry()
|
|
73 |
{
|
|
74 |
#ifdef Q_OS_SYMBIAN
|
|
75 |
#ifdef UT_MEMORY_CHECK
|
|
76 |
__UHEAP_MARK;
|
|
77 |
#endif//UT_MEMORY_CHECK
|
|
78 |
#endif//Q_OS_SYMBIAN
|
|
79 |
{
|
|
80 |
const QString SHORTCUT_WIDGET_URI("hsshortcutwidgetplugin");
|
|
81 |
|
|
82 |
HsAddToHomeScreenState addToHomeScreenState;
|
|
83 |
|
|
84 |
QScopedPointer<HsMenuItemModel>
|
|
85 |
model(HsMenuService::getAllApplicationsModel(
|
|
86 |
Hs::DescendingNameHsSortAttribute));
|
|
87 |
|
|
88 |
const QString clockWidgetName("Clock");
|
|
89 |
|
|
90 |
int clockId = 0;
|
|
91 |
int appId = 0;
|
|
92 |
for (int i = 0; i< model->rowCount(); ++i) {
|
|
93 |
const QString textRole = model->data((model->index(i)),
|
|
94 |
CaItemModel::TextRole).toString();
|
|
95 |
const QString entryTypeName = model->data((model->index(i)),
|
|
96 |
CaItemModel::TypeRole).toString();
|
|
97 |
|
|
98 |
if (entryTypeName == Hs::applicationTypeName) {
|
|
99 |
appId = model->data((model->index(i)), CaItemModel::IdRole).toInt();
|
|
100 |
}
|
|
101 |
|
|
102 |
if((entryTypeName == Hs::widgetTypeName) && (textRole == clockWidgetName)) {
|
|
103 |
clockId = model->data((model->index(i)),
|
|
104 |
CaItemModel::IdRole).toInt();
|
|
105 |
}
|
|
106 |
}
|
97
|
107 |
QVERIFY(clockId != 0);
|
90
|
108 |
const QString clockWidgetUri("hsclockwidgetplugin");
|
|
109 |
|
|
110 |
QVariantMap eventAttributes;
|
|
111 |
|
|
112 |
eventAttributes.insert(Hs::widgetUriAttributeName,
|
|
113 |
clockWidgetUri);
|
|
114 |
|
|
115 |
eventAttributes.insert(Hs::entryTypeNameKey, Hs::widgetTypeName);
|
|
116 |
|
|
117 |
eventAttributes.insert(Hs::itemIdKey, clockId);
|
|
118 |
|
|
119 |
HsMenuEvent *addWidgetEvent =
|
|
120 |
new HsMenuEvent(HsMenuEvent::AddToHomeScreen, eventAttributes);
|
|
121 |
|
|
122 |
addToHomeScreenState.onEntry(addWidgetEvent);
|
|
123 |
|
|
124 |
{
|
|
125 |
QCOMPARE(HsContentService::instance()->mParams["uri"].toString(),
|
|
126 |
clockWidgetUri);
|
|
127 |
}
|
|
128 |
|
|
129 |
eventAttributes.remove(Hs::itemIdKey);
|
|
130 |
eventAttributes.insert(Hs::itemIdKey, appId);
|
|
131 |
|
|
132 |
HsMenuEvent *addShortcutEvent =
|
|
133 |
new HsMenuEvent(HsMenuEvent::AddToHomeScreen, eventAttributes);
|
|
134 |
|
|
135 |
addToHomeScreenState.onEntry(addShortcutEvent);
|
|
136 |
|
|
137 |
{
|
|
138 |
QCOMPARE(HsContentService::instance()->mParams["uri"].toString(),
|
|
139 |
SHORTCUT_WIDGET_URI);
|
|
140 |
}
|
|
141 |
|
|
142 |
delete addWidgetEvent;
|
|
143 |
delete addShortcutEvent;
|
|
144 |
}
|
|
145 |
#ifdef Q_OS_SYMBIAN
|
|
146 |
#ifdef UT_MEMORY_CHECK
|
|
147 |
__UHEAP_MARKEND;
|
|
148 |
#endif//UT_MEMORY_CHECK
|
|
149 |
#endif//Q_OS_SYMBIAN
|
|
150 |
}
|
|
151 |
|
|
152 |
// ---------------------------------------------------------------------------
|
97
|
153 |
//
|
90
|
154 |
// ---------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void MenuStatesTest::AddToHomeScreenState_onEntry_2()
|
|
157 |
{
|
|
158 |
#ifdef Q_OS_SYMBIAN
|
|
159 |
#ifdef UT_MEMORY_CHECK
|
|
160 |
__UHEAP_MARK;
|
|
161 |
#endif//UT_MEMORY_CHECK
|
|
162 |
#endif//Q_OS_SYMBIAN
|
|
163 |
{
|
|
164 |
const QString SHORTCUT_WIDGET_URI("hsshortcutwidgetplugin");
|
|
165 |
|
|
166 |
HsAddToHomeScreenState addToHomeScreenState;
|
|
167 |
|
|
168 |
QScopedPointer<HsMenuItemModel>
|
|
169 |
model(HsMenuService::getAllApplicationsModel(
|
|
170 |
Hs::DescendingNameHsSortAttribute));
|
|
171 |
|
|
172 |
const QString clockWidgetUri("homescreen.nokia.com/widget/clock");
|
|
173 |
|
|
174 |
CaEntry item( ItemEntryRole );
|
|
175 |
item.setText( "TestTemplateAppWithUri" );
|
|
176 |
item.setEntryTypeName(Hs::templatedApplicationTypeName);
|
|
177 |
item.setAttribute(Hs::widgetUriAttributeName, clockWidgetUri);
|
|
178 |
QSharedPointer<CaEntry> newItem = CaService::instance()->createEntry( item );
|
|
179 |
QVERIFY(!newItem.isNull());
|
|
180 |
QVERIFY(newItem->id());
|
|
181 |
|
|
182 |
QVariantMap eventAttributes;
|
|
183 |
eventAttributes.insert(Hs::entryTypeNameKey, Hs::templatedApplicationTypeName);
|
|
184 |
eventAttributes.insert(Hs::itemIdKey, newItem->id());
|
|
185 |
eventAttributes.insert(Hs::widgetUriAttributeName, clockWidgetUri);
|
|
186 |
|
|
187 |
HsMenuEvent *addWidgetEvent =
|
|
188 |
new HsMenuEvent(HsMenuEvent::AddToHomeScreen, eventAttributes);
|
|
189 |
|
|
190 |
addToHomeScreenState.onEntry(addWidgetEvent);
|
|
191 |
|
|
192 |
{
|
|
193 |
QCOMPARE(HsContentService::instance()->mParams["uri"].toString(), clockWidgetUri);
|
|
194 |
}
|
|
195 |
|
|
196 |
QVERIFY(CaService::instance()->removeEntry(newItem->id()));
|
|
197 |
|
|
198 |
delete addWidgetEvent;
|
|
199 |
}
|
|
200 |
#ifdef Q_OS_SYMBIAN
|
|
201 |
#ifdef UT_MEMORY_CHECK
|
|
202 |
__UHEAP_MARKEND;
|
|
203 |
#endif//UT_MEMORY_CHECK
|
|
204 |
#endif//Q_OS_SYMBIAN
|
|
205 |
}
|
|
206 |
|
|
207 |
// ---------------------------------------------------------------------------
|
97
|
208 |
//
|
90
|
209 |
// ---------------------------------------------------------------------------
|
|
210 |
//
|
|
211 |
void MenuStatesTest::AddToHomeScreenState_onEntry_3()
|
|
212 |
{
|
|
213 |
#ifdef Q_OS_SYMBIAN
|
|
214 |
#ifdef UT_MEMORY_CHECK
|
|
215 |
__UHEAP_MARK;
|
|
216 |
#endif//UT_MEMORY_CHECK
|
|
217 |
#endif//Q_OS_SYMBIAN
|
|
218 |
{
|
|
219 |
const QString SHORTCUT_WIDGET_URI("hsshortcutwidgetplugin");
|
|
220 |
|
|
221 |
HsAddToHomeScreenState addToHomeScreenState;
|
|
222 |
|
|
223 |
QScopedPointer<HsMenuItemModel>
|
|
224 |
model(HsMenuService::getAllApplicationsModel(
|
|
225 |
Hs::DescendingNameHsSortAttribute));
|
|
226 |
|
|
227 |
const QString clockWidgetName("Clock");
|
|
228 |
|
|
229 |
int clockId = 0;
|
|
230 |
|
|
231 |
for (int i = 0; i< model->rowCount(); ++i) {
|
|
232 |
const QString textRole = model->data((model->index(i)),
|
|
233 |
CaItemModel::TextRole).toString();
|
|
234 |
|
|
235 |
if(textRole == clockWidgetName) {
|
|
236 |
clockId = model->data((model->index(i)),
|
|
237 |
CaItemModel::IdRole).toInt();
|
|
238 |
}
|
|
239 |
}
|
|
240 |
|
|
241 |
CaEntry item( ItemEntryRole );
|
|
242 |
item.setText( "TestTemplateAppWithoutUri" );
|
|
243 |
item.setEntryTypeName(Hs::templatedApplicationTypeName);
|
|
244 |
QSharedPointer<CaEntry> newItem = CaService::instance()->createEntry( item );
|
|
245 |
QVERIFY(newItem->id());
|
|
246 |
|
|
247 |
|
|
248 |
QVariantMap eventAttributes;
|
|
249 |
eventAttributes.insert(Hs::entryTypeNameKey, Hs::templatedApplicationTypeName);
|
|
250 |
eventAttributes.insert(Hs::itemIdKey, newItem->id());
|
|
251 |
|
|
252 |
HsMenuEvent *addWidgetEvent =
|
|
253 |
new HsMenuEvent(HsMenuEvent::AddToHomeScreen, eventAttributes);
|
|
254 |
|
|
255 |
addToHomeScreenState.onEntry(addWidgetEvent);
|
|
256 |
|
|
257 |
QVERIFY(CaService::instance()->removeEntry(newItem->id()));
|
|
258 |
|
|
259 |
delete addWidgetEvent;
|
|
260 |
}
|
|
261 |
#ifdef Q_OS_SYMBIAN
|
|
262 |
#ifdef UT_MEMORY_CHECK
|
|
263 |
__UHEAP_MARKEND;
|
|
264 |
#endif//UT_MEMORY_CHECK
|
|
265 |
#endif//Q_OS_SYMBIAN
|
|
266 |
}
|
|
267 |
|
|
268 |
// ---------------------------------------------------------------------------
|
97
|
269 |
//
|
90
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
void MenuStatesTest::AddToHomeScreenState_onEntry_4()
|
|
273 |
{
|
|
274 |
#ifdef Q_OS_SYMBIAN
|
|
275 |
#ifdef UT_MEMORY_CHECK
|
|
276 |
__UHEAP_MARK;
|
|
277 |
#endif//UT_MEMORY_CHECK
|
|
278 |
#endif//Q_OS_SYMBIAN
|
|
279 |
{
|
|
280 |
const QString SHORTCUT_WIDGET_URI("hsshortcutwidgetplugin");
|
|
281 |
|
|
282 |
HsAddToHomeScreenState addToHomeScreenState;
|
|
283 |
|
|
284 |
QScopedPointer<HsMenuItemModel>
|
|
285 |
model(HsMenuService::getAllApplicationsModel(
|
|
286 |
Hs::DescendingNameHsSortAttribute));
|
|
287 |
|
|
288 |
const QString clockWidgetUri("homescreen.nokia.com/widget/clock");
|
|
289 |
|
|
290 |
CaEntry item( ItemEntryRole );
|
|
291 |
item.setText( "TestParametrizedTemplateAppWithUri" );
|
|
292 |
item.setEntryTypeName(Hs::templatedApplicationTypeName);
|
|
293 |
item.setAttribute(Hs::widgetUriAttributeName, clockWidgetUri);
|
|
294 |
// add widget param atrib to entry
|
|
295 |
item.setAttribute(QString(Hs::widgetParam+QString("caEntryId")), QString("12"));
|
|
296 |
QSharedPointer<CaEntry> newItem = CaService::instance()->createEntry( item );
|
|
297 |
QVERIFY(!newItem.isNull());
|
|
298 |
QVERIFY(newItem->id());
|
|
299 |
|
|
300 |
QVariantMap eventAttributes;
|
|
301 |
eventAttributes.insert(Hs::entryTypeNameKey, Hs::templatedApplicationTypeName);
|
|
302 |
eventAttributes.insert(Hs::itemIdKey, newItem->id());
|
|
303 |
eventAttributes.insert(Hs::widgetUriAttributeName, clockWidgetUri);
|
|
304 |
|
|
305 |
QVariantMap widgetParams;
|
|
306 |
widgetParams.insert(QString(Hs::widgetParam+QString("mcsId")), QString("12"));
|
|
307 |
eventAttributes.insert(Hs::widgetParam,widgetParams);
|
|
308 |
|
|
309 |
HsMenuEvent *addWidgetEvent =
|
|
310 |
new HsMenuEvent(HsMenuEvent::AddToHomeScreen, eventAttributes);
|
|
311 |
|
|
312 |
addToHomeScreenState.onEntry(addWidgetEvent);
|
|
313 |
|
|
314 |
{
|
|
315 |
QCOMPARE(HsContentService::instance()->mParams["uri"].toString(),
|
|
316 |
clockWidgetUri);
|
|
317 |
}
|
|
318 |
|
|
319 |
QVERIFY(CaService::instance()->removeEntry(newItem->id()));
|
|
320 |
|
|
321 |
delete addWidgetEvent;
|
|
322 |
}
|
|
323 |
#ifdef Q_OS_SYMBIAN
|
|
324 |
#ifdef UT_MEMORY_CHECK
|
|
325 |
__UHEAP_MARKEND;
|
|
326 |
#endif//UT_MEMORY_CHECK
|
|
327 |
#endif//Q_OS_SYMBIAN
|
|
328 |
}
|
|
329 |
|
|
330 |
// ---------------------------------------------------------------------------
|
97
|
331 |
//
|
90
|
332 |
// ---------------------------------------------------------------------------
|
|
333 |
//
|
|
334 |
void MenuStatesTest::AddToHomeScreenState_showMessageWidgetCorrupted()
|
|
335 |
{
|
|
336 |
#ifdef Q_OS_SYMBIAN
|
|
337 |
#ifdef UT_MEMORY_CHECK
|
|
338 |
__UHEAP_MARK;
|
|
339 |
#endif//UT_MEMORY_CHECK
|
|
340 |
#endif//Q_OS_SYMBIAN
|
|
341 |
{
|
|
342 |
QScopedPointer<HsAddToHomeScreenState> as(new HsAddToHomeScreenState());
|
|
343 |
|
|
344 |
as->showMessageWidgetCorrupted();
|
|
345 |
checkDialogController();
|
|
346 |
}
|
|
347 |
#ifdef Q_OS_SYMBIAN
|
|
348 |
#ifdef UT_MEMORY_CHECK
|
|
349 |
__UHEAP_MARKEND;
|
|
350 |
#endif//UT_MEMORY_CHECK
|
|
351 |
#endif//Q_OS_SYMBIAN
|
|
352 |
}
|
|
353 |
|
|
354 |
void MenuStatesTest::AddToHomeScreenState_openHomeScreen()
|
|
355 |
{
|
|
356 |
#ifdef Q_OS_SYMBIAN
|
|
357 |
#ifdef UT_MEMORY_CHECK
|
|
358 |
__UHEAP_MARK;
|
|
359 |
#endif//UT_MEMORY_CHECK
|
|
360 |
#endif//Q_OS_SYMBIAN
|
|
361 |
{
|
|
362 |
QScopedPointer<HsAddToHomeScreenState> as(new HsAddToHomeScreenState());
|
|
363 |
QSignalSpy spy(as.data(), SIGNAL(exit()));
|
|
364 |
as->openHomeScreen();
|
|
365 |
QCOMPARE(spy.count(), 1);
|
|
366 |
}
|
|
367 |
#ifdef Q_OS_SYMBIAN
|
|
368 |
#ifdef UT_MEMORY_CHECK
|
|
369 |
__UHEAP_MARKEND;
|
|
370 |
#endif//UT_MEMORY_CHECK
|
|
371 |
#endif//Q_OS_SYMBIAN
|
|
372 |
}
|
|
373 |
|