90
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
#include <QSignalSpy>
|
|
19 |
|
|
20 |
#include <HbMainWindow>
|
|
21 |
#include <HbInstance>
|
|
22 |
#include <HbView>
|
|
23 |
#include <HbListView>
|
|
24 |
#include <HbListViewItem>
|
|
25 |
#include <HbSearchPanel>
|
|
26 |
#include <HbMenu>
|
|
27 |
#include <HbAction>
|
|
28 |
#include <HbPushButton>
|
|
29 |
#include <HbLabel>
|
|
30 |
#include <qscopedpointer>
|
|
31 |
|
|
32 |
#include <caentry.h>
|
|
33 |
#include <caitemmodel.h>
|
|
34 |
#include <hsmenuevent.h>
|
|
35 |
#include "hsmenuview.h"
|
|
36 |
#include "hsinstalledappsstate.h"
|
|
37 |
#include "hsmainwindow.h"
|
|
38 |
#include "hsmenuitemmodel.h"
|
97
|
39 |
#include "hsscene.h"
|
90
|
40 |
|
|
41 |
#include "hsmenueventtransition.h"
|
|
42 |
#include "t_installedappsstate.h"
|
|
43 |
#include "t_hsaddtohomescreenmockstate.h"
|
|
44 |
|
|
45 |
|
97
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
90
|
50 |
class HsMainWindowMock : public HsMainWindow
|
|
51 |
{
|
|
52 |
virtual void setCurrentView(HbView *view);
|
|
53 |
|
|
54 |
};
|
|
55 |
|
97
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
90
|
60 |
void HsMainWindowMock::setCurrentView(HbView *view)
|
|
61 |
{
|
|
62 |
Q_UNUSED(view);
|
|
63 |
// do nothing
|
|
64 |
}
|
|
65 |
|
97
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
90
|
70 |
void MenuStatesTest::cleanup()
|
|
71 |
{
|
|
72 |
qApp->processEvents();
|
|
73 |
}
|
|
74 |
|
|
75 |
// ---------------------------------------------------------------------------
|
97
|
76 |
//
|
90
|
77 |
// ---------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
void MenuStatesTest::construction()
|
|
80 |
{
|
|
81 |
#ifdef Q_OS_SYMBIAN
|
|
82 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
83 |
#ifdef UT_MEMORY_CHECK
|
|
84 |
__UHEAP_MARK;
|
|
85 |
#endif//UT_MEMORY_CHECK
|
|
86 |
#endif//Q_OS_SYMBIAN
|
|
87 |
{
|
|
88 |
HsMenuViewBuilder builder;
|
|
89 |
HsMainWindowMock mainWindow;
|
|
90 |
|
|
91 |
QScopedPointer<QState> parent(new QState);
|
|
92 |
|
|
93 |
QScopedPointer<HsInstalledAppsState> allAppsState(
|
|
94 |
new HsInstalledAppsState(builder, mainWindow, parent.data()));
|
|
95 |
|
|
96 |
|
|
97 |
QVERIFY(!allAppsState->mModel);
|
|
98 |
}
|
|
99 |
#ifdef Q_OS_SYMBIAN
|
|
100 |
#ifdef UT_MEMORY_CHECK
|
|
101 |
__UHEAP_MARKEND;
|
|
102 |
#endif//UT_MEMORY_CHECK
|
|
103 |
#endif//Q_OS_SYMBIAN
|
|
104 |
}
|
|
105 |
|
|
106 |
// ---------------------------------------------------------------------------
|
97
|
107 |
//
|
90
|
108 |
// ---------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
#ifdef Q_OS_SYMBIAN
|
|
111 |
void MenuStatesTest::openTaskSwitcher()
|
|
112 |
{
|
|
113 |
#ifdef Q_OS_SYMBIAN
|
|
114 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
115 |
#ifdef UT_MEMORY_CHECK
|
|
116 |
__UHEAP_MARK;
|
|
117 |
#endif//UT_MEMORY_CHECK
|
|
118 |
#endif//Q_OS_SYMBIAN
|
|
119 |
{
|
|
120 |
HsMenuViewBuilder builder;
|
|
121 |
HsMainWindowMock mainWindow;
|
|
122 |
|
|
123 |
QScopedPointer<QState> parent(new QState);
|
|
124 |
|
|
125 |
QScopedPointer<HsInstalledAppsState> installedAppsState (
|
|
126 |
new HsInstalledAppsState(builder, mainWindow, parent.data()));
|
|
127 |
|
|
128 |
QVERIFY(installedAppsState->openTaskSwitcher());
|
|
129 |
}
|
|
130 |
#ifdef Q_OS_SYMBIAN
|
|
131 |
#ifdef UT_MEMORY_CHECK
|
|
132 |
__UHEAP_MARKEND;
|
|
133 |
#endif//UT_MEMORY_CHECK
|
|
134 |
#endif//Q_OS_SYMBIAN
|
|
135 |
}
|
|
136 |
#endif//Q_OS_SYMBIAN
|
|
137 |
|
|
138 |
// ---------------------------------------------------------------------------
|
97
|
139 |
//
|
90
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
//
|
|
142 |
#ifdef Q_OS_SYMBIAN
|
|
143 |
void MenuStatesTest::openInstallationLog()
|
|
144 |
{
|
|
145 |
#ifdef Q_OS_SYMBIAN
|
|
146 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
147 |
#ifdef UT_MEMORY_CHECK
|
|
148 |
__UHEAP_MARK;
|
|
149 |
#endif//UT_MEMORY_CHECK
|
|
150 |
#endif//Q_OS_SYMBIAN
|
|
151 |
{
|
|
152 |
HsMenuViewBuilder builder;
|
|
153 |
HsMainWindowMock mainWindow;
|
|
154 |
QStateMachine *machine = new QStateMachine(0);
|
|
155 |
|
|
156 |
HsInstalledAppsState *installedAppsState =
|
|
157 |
new HsInstalledAppsState(builder, mainWindow, machine);
|
|
158 |
|
|
159 |
machine->setInitialState(installedAppsState);
|
|
160 |
|
|
161 |
AddToHomeScreenMockState *mockState = new AddToHomeScreenMockState(machine);
|
|
162 |
|
|
163 |
// create a transition to the new child state which will be triggered by
|
|
164 |
// an event with specified operation type
|
|
165 |
HsMenuEventTransition *newCollectionTransition = new HsMenuEventTransition(
|
|
166 |
HsMenuEvent::ShowInstallationLog, installedAppsState, mockState);
|
|
167 |
|
|
168 |
installedAppsState->addTransition(newCollectionTransition);
|
|
169 |
|
|
170 |
installedAppsState->stateEntered();
|
|
171 |
|
|
172 |
machine->start();
|
|
173 |
qApp->sendPostedEvents();
|
|
174 |
|
|
175 |
installedAppsState->openInstallationLog();
|
|
176 |
QTest::qWait(5000);
|
|
177 |
|
|
178 |
QVERIFY(mockState->enteredValue());
|
|
179 |
qApp->removePostedEvents(0);
|
|
180 |
machine->stop();
|
|
181 |
delete machine;
|
|
182 |
}
|
|
183 |
#ifdef Q_OS_SYMBIAN
|
|
184 |
#ifdef UT_MEMORY_CHECK
|
|
185 |
__UHEAP_MARKEND;
|
|
186 |
#endif//UT_MEMORY_CHECK
|
|
187 |
#endif//Q_OS_SYMBIAN
|
|
188 |
}
|
|
189 |
#endif//Q_OS_SYMBIAN
|
|
190 |
|
|
191 |
// ---------------------------------------------------------------------------
|
97
|
192 |
//
|
90
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void MenuStatesTest::stateEnteredExited()
|
|
196 |
{
|
|
197 |
#ifdef Q_OS_SYMBIAN
|
|
198 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
199 |
#ifdef UT_MEMORY_CHECK
|
|
200 |
__UHEAP_MARK;
|
|
201 |
#endif//UT_MEMORY_CHECK
|
|
202 |
#endif//Q_OS_SYMBIAN
|
|
203 |
{
|
|
204 |
int fakeId = 2;
|
|
205 |
QString fakeCollectionType("fakeCollectionType");
|
|
206 |
|
|
207 |
HsMenuViewBuilder builder;
|
|
208 |
HsMainWindowMock mainWindow;
|
|
209 |
|
|
210 |
QScopedPointer<QState> parent(new QState);
|
|
211 |
|
|
212 |
HsInstalledAppsState *installedAppsState =
|
|
213 |
new HsInstalledAppsState(builder, mainWindow, parent.data());
|
|
214 |
|
|
215 |
QVariantMap params;
|
|
216 |
params.insert(Hs::itemIdKey, fakeId);
|
|
217 |
params.insert(Hs::entryTypeNameKey, fakeCollectionType);
|
|
218 |
QEvent *event = new HsMenuEvent(
|
|
219 |
HsMenuEvent::BackFromInstalledView, params);
|
|
220 |
installedAppsState->onEntry(event);
|
|
221 |
delete event;
|
|
222 |
event = NULL;
|
|
223 |
QCOMPARE(installedAppsState->mCollectionId, fakeId);
|
|
224 |
QCOMPARE(installedAppsState->mCollectionType, fakeCollectionType);
|
|
225 |
|
|
226 |
installedAppsState->stateEntered();
|
|
227 |
|
|
228 |
QVERIFY(installedAppsState->mModel);
|
|
229 |
|
|
230 |
installedAppsState->mContextMenu = new HbMenu();
|
|
231 |
installedAppsState->mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
|
|
232 |
|
|
233 |
QVERIFY(!installedAppsState->mMenuView->view()->menu()->isEmpty());
|
|
234 |
|
|
235 |
installedAppsState->stateExited();
|
|
236 |
|
|
237 |
QVERIFY(!installedAppsState->mMenuView->view()->menu()->isEmpty());
|
|
238 |
}
|
|
239 |
#ifdef Q_OS_SYMBIAN
|
|
240 |
#ifdef UT_MEMORY_CHECK
|
|
241 |
__UHEAP_MARKEND;
|
|
242 |
#endif//UT_MEMORY_CHECK
|
|
243 |
#endif//Q_OS_SYMBIAN
|
|
244 |
}
|
97
|
245 |
|
90
|
246 |
// ---------------------------------------------------------------------------
|
97
|
247 |
//
|
90
|
248 |
// ---------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
void MenuStatesTest::emptyLabelVisibility()
|
|
251 |
{
|
|
252 |
#ifdef Q_OS_SYMBIAN
|
|
253 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
254 |
#ifdef UT_MEMORY_CHECK
|
|
255 |
__UHEAP_MARK;
|
|
256 |
#endif//UT_MEMORY_CHECK
|
|
257 |
#endif//Q_OS_SYMBIAN
|
|
258 |
{
|
|
259 |
HsMenuViewBuilder builder;
|
|
260 |
HsMainWindowMock mainWindow;
|
|
261 |
QScopedPointer<QStateMachine> machine(new QStateMachine(0));
|
|
262 |
HsInstalledAppsState *installedAppsState =
|
|
263 |
new HsInstalledAppsState(builder, mainWindow, machine.data());
|
|
264 |
|
|
265 |
installedAppsState->stateEntered();
|
|
266 |
|
|
267 |
QVERIFY(installedAppsState->mModel);
|
|
268 |
|
|
269 |
installedAppsState->setEmptyLabelVisibility(true);
|
|
270 |
|
|
271 |
QCOMPARE(installedAppsState->mMenuView->mBuilder.mStateContext,
|
|
272 |
HsInstalledAppsContext);
|
|
273 |
QCOMPARE(installedAppsState->mMenuView->mBuilder.mOperationalContext,
|
|
274 |
HsEmptyLabelContext);
|
|
275 |
|
|
276 |
|
|
277 |
installedAppsState->setEmptyLabelVisibility(false);
|
|
278 |
|
|
279 |
QCOMPARE(installedAppsState->mMenuView->mBuilder.mStateContext,
|
|
280 |
HsInstalledAppsContext);
|
|
281 |
QCOMPARE(installedAppsState->mMenuView->mBuilder.mOperationalContext,
|
|
282 |
HsItemViewContext);
|
|
283 |
}
|
|
284 |
#ifdef Q_OS_SYMBIAN
|
|
285 |
#ifdef UT_MEMORY_CHECK
|
|
286 |
__UHEAP_MARKEND;
|
|
287 |
#endif//UT_MEMORY_CHECK
|
|
288 |
#endif//Q_OS_SYMBIAN
|
|
289 |
}
|
|
290 |
|
|
291 |
// ---------------------------------------------------------------------------
|
97
|
292 |
//
|
90
|
293 |
// ---------------------------------------------------------------------------
|
|
294 |
//
|
|
295 |
void MenuStatesTest::listItemLongPressed()
|
|
296 |
{
|
|
297 |
#ifdef Q_OS_SYMBIAN
|
|
298 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
299 |
#ifdef UT_MEMORY_CHECK
|
|
300 |
__UHEAP_MARK;
|
|
301 |
#endif//UT_MEMORY_CHECK
|
|
302 |
#endif//Q_OS_SYMBIAN
|
|
303 |
{
|
97
|
304 |
//QScopedPointer<HbMainWindow> window(new HbMainWindow);
|
|
305 |
//HsScene::setInstance( new HsScene(window.data()) );
|
|
306 |
|
90
|
307 |
HsMenuViewBuilder builder;
|
97
|
308 |
HsMainWindowMock mainWindow;
|
90
|
309 |
|
|
310 |
QScopedPointer<QState> parent(new QState);
|
|
311 |
|
|
312 |
HsInstalledAppsState *installedAppsState =
|
|
313 |
new HsInstalledAppsState(builder, mainWindow, parent.data());
|
|
314 |
|
|
315 |
installedAppsState->stateEntered();
|
|
316 |
QVERIFY(installedAppsState->mModel);
|
|
317 |
|
|
318 |
QScopedPointer<HbAbstractViewItem> item(new HbListViewItem);
|
|
319 |
|
|
320 |
QVERIFY(installedAppsState->mModel != NULL);
|
|
321 |
|
|
322 |
// to ensure that we have at least one item in model assign
|
|
323 |
// installedAppsState with All Applications Model..
|
|
324 |
installedAppsState->mModel = HsMenuService::getAllApplicationsModel();
|
|
325 |
|
|
326 |
if( installedAppsState->mModel->rowCount() > 0 )
|
|
327 |
{
|
|
328 |
QModelIndex itemModelIndex = installedAppsState->mModel->index(0, 0);
|
|
329 |
|
|
330 |
QSharedPointer<CaEntry> entry
|
|
331 |
= installedAppsState->mModel->entry(itemModelIndex);
|
|
332 |
|
|
333 |
entry->setAttribute(Hs::componentIdAttributeName, QString("0"));
|
|
334 |
entry->setFlags(entry->flags() | RemovableEntryFlag);
|
|
335 |
|
|
336 |
item->setModelIndex(itemModelIndex);
|
|
337 |
|
|
338 |
installedAppsState->showContextMenu(item.data() , QPointF(50,50));
|
|
339 |
|
|
340 |
QCOMPARE(installedAppsState->mContextMenu->actions().length(), 2);
|
|
341 |
|
|
342 |
Hs::HsContextAction uninstallAction = static_cast<Hs::HsContextAction>(
|
|
343 |
installedAppsState->mContextMenu->actions()[0]->data().toInt());
|
|
344 |
QCOMPARE(uninstallAction, Hs::UninstallContextAction);
|
|
345 |
|
|
346 |
Hs::HsContextAction detailsAction = static_cast<Hs::HsContextAction>(
|
|
347 |
installedAppsState->mContextMenu->actions()[1]->data().toInt());
|
|
348 |
QCOMPARE(detailsAction, Hs::AppDetailsContextAction);
|
|
349 |
|
|
350 |
installedAppsState->mContextMenu->close();
|
|
351 |
|
|
352 |
} else {
|
|
353 |
QWARN("No item in Installed App View");
|
|
354 |
}
|
|
355 |
|
|
356 |
installedAppsState->stateExited();
|
|
357 |
|
|
358 |
qApp->processEvents();
|
|
359 |
|
|
360 |
}
|
|
361 |
#ifdef Q_OS_SYMBIAN
|
|
362 |
#ifdef UT_MEMORY_CHECK
|
|
363 |
__UHEAP_MARKEND;
|
|
364 |
#endif//UT_MEMORY_CHECK
|
|
365 |
#endif//Q_OS_SYMBIAN
|
|
366 |
}
|
|
367 |
|
|
368 |
// ---------------------------------------------------------------------------
|
97
|
369 |
//
|
90
|
370 |
// ---------------------------------------------------------------------------
|
|
371 |
//
|
|
372 |
void MenuStatesTest::latestOldestOnTopMenuAction()
|
|
373 |
{
|
|
374 |
#ifdef Q_OS_SYMBIAN
|
|
375 |
User::ResetInactivityTime();//it should help for Viewserver11 panic
|
|
376 |
#ifdef UT_MEMORY_CHECK
|
|
377 |
__UHEAP_MARK;
|
|
378 |
#endif//UT_MEMORY_CHECK
|
|
379 |
#endif//Q_OS_SYMBIAN
|
|
380 |
{
|
|
381 |
HsMenuViewBuilder builder;
|
|
382 |
HsMainWindowMock mainWindow;
|
|
383 |
QScopedPointer<QStateMachine> machine(new QStateMachine(0));
|
|
384 |
HsInstalledAppsState *installedAppsState =
|
|
385 |
new HsInstalledAppsState(builder, mainWindow, machine.data());
|
|
386 |
|
|
387 |
installedAppsState->stateEntered();
|
|
388 |
|
|
389 |
QVERIFY(installedAppsState->mModel);
|
|
390 |
|
|
391 |
// model must have some items
|
|
392 |
delete installedAppsState->mModel;
|
|
393 |
installedAppsState->mModel = HsMenuService::getAllApplicationsModel(Hs::OldestOnTopHsSortAttribute);
|
|
394 |
|
|
395 |
installedAppsState->setMenuOptions();
|
|
396 |
|
|
397 |
installedAppsState->latestOnTopMenuAction();
|
|
398 |
|
|
399 |
QCOMPARE(installedAppsState->mSortAttribute,
|
|
400 |
Hs::OldestOnTopHsSortAttribute);
|
|
401 |
|
|
402 |
installedAppsState->oldestOnTopMenuAction();
|
|
403 |
QCOMPARE(installedAppsState->mSortAttribute,
|
|
404 |
Hs::LatestOnTopHsSortAttribute);
|
|
405 |
|
|
406 |
delete installedAppsState;
|
|
407 |
}
|
|
408 |
#ifdef Q_OS_SYMBIAN
|
|
409 |
#ifdef UT_MEMORY_CHECK
|
|
410 |
__UHEAP_MARKEND;
|
|
411 |
#endif//UT_MEMORY_CHECK
|
|
412 |
#endif//Q_OS_SYMBIAN
|
|
413 |
}
|
|
414 |
|
|
415 |
|
|
416 |
QTEST_MAIN(MenuStatesTest)
|
|
417 |
|