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