|
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 <hbmainwindow.h> |
|
19 #include <hbinstance.h> |
|
20 #include <hbview.h> |
|
21 #include <hblistview.h> |
|
22 #include <hblistviewitem.h> |
|
23 #include <HbMenu> |
|
24 #include <HbAction> |
|
25 #include <qscopedpointer> |
|
26 |
|
27 #include "caentry.h" |
|
28 #include "caitemmodel.h" |
|
29 #include "hsmenuview.h" |
|
30 #include "hsmenuviewbuilder.h" |
|
31 #include "hsmenumodewrapper.h" |
|
32 #include "hsmenuevent.h" |
|
33 #include "hsallcollectionsstate.h" |
|
34 #include "hsmenueventtransition.h" |
|
35 #include "hsmainwindow.h" |
|
36 |
|
37 #include "t_hsaddtohomescreenmockstate.h" |
|
38 #include "t_hsmockmodel.h" |
|
39 #include "t_allcollectionsstate.h" |
|
40 |
|
41 class HsMainWindowMock : public HsMainWindow |
|
42 { |
|
43 virtual void setCurrentView(HbView *view); |
|
44 |
|
45 }; |
|
46 |
|
47 void HsMainWindowMock::setCurrentView(HbView *view) |
|
48 { |
|
49 Q_UNUSED(view); |
|
50 // do nothing |
|
51 } |
|
52 |
|
53 void MenuStatesTest::initTestCase() |
|
54 { |
|
55 // mWindow = NULL; |
|
56 } |
|
57 |
|
58 void MenuStatesTest::init() |
|
59 { |
|
60 // mWindow = new HbMainWindow; |
|
61 } |
|
62 |
|
63 void MenuStatesTest::cleanup() |
|
64 { |
|
65 qApp->processEvents(); |
|
66 // delete mWindow; |
|
67 // mWindow = NULL; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void MenuStatesTest::construction() |
|
74 { |
|
75 #ifdef Q_OS_SYMBIAN |
|
76 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
77 #ifdef UT_MEMORY_CHECK |
|
78 __UHEAP_MARK; |
|
79 #endif//UT_MEMORY_CHECK |
|
80 #endif//Q_OS_SYMBIAN |
|
81 { |
|
82 HsMenuViewBuilder builder; |
|
83 HsMenuModeWrapper menuMode; |
|
84 HsMainWindowMock mainWindow; |
|
85 QState *parent = new QState; |
|
86 |
|
87 HsAllCollectionsState *allCollectionsState = |
|
88 new HsAllCollectionsState(builder, |
|
89 menuMode, |
|
90 mainWindow, |
|
91 parent); |
|
92 |
|
93 QCOMPARE(allCollectionsState->mBackKeyAction, |
|
94 allCollectionsState->mMenuView->view()->navigationAction()); |
|
95 |
|
96 QVERIFY(allCollectionsState->mModel != |
|
97 static_cast<HsMenuItemModel *>(0)); |
|
98 delete parent; |
|
99 } |
|
100 #ifdef Q_OS_SYMBIAN |
|
101 #ifdef UT_MEMORY_CHECK |
|
102 __UHEAP_MARKEND; |
|
103 #endif//UT_MEMORY_CHECK |
|
104 #endif//Q_OS_SYMBIAN |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 |
|
111 void MenuStatesTest::addModeEnteredExited() |
|
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 HsMenuModeWrapper menuMode; |
|
122 QState *parent = new QState; |
|
123 HsMainWindowMock mainWindow; |
|
124 HsAllCollectionsState *allCollectionsState = |
|
125 new HsAllCollectionsState( |
|
126 builder, menuMode, mainWindow, parent); |
|
127 |
|
128 allCollectionsState->mMenuMode->setHsMenuMode(Hs::AddHsMenuMode); |
|
129 allCollectionsState->addModeEntered(); |
|
130 |
|
131 QCOMPARE(allCollectionsState->mMenuMode->getHsMenuMode(), |
|
132 Hs::AddHsMenuMode); |
|
133 delete parent; |
|
134 } |
|
135 #ifdef Q_OS_SYMBIAN |
|
136 #ifdef UT_MEMORY_CHECK |
|
137 __UHEAP_MARKEND; |
|
138 #endif//UT_MEMORY_CHECK |
|
139 #endif//Q_OS_SYMBIAN |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 |
|
146 void MenuStatesTest::normalModeEnteredExited() |
|
147 { |
|
148 #ifdef Q_OS_SYMBIAN |
|
149 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
150 #ifdef UT_MEMORY_CHECK |
|
151 __UHEAP_MARK; |
|
152 #endif//UT_MEMORY_CHECK |
|
153 #endif//Q_OS_SYMBIAN |
|
154 { |
|
155 HsMenuViewBuilder builder; |
|
156 HsMenuModeWrapper menuMode; |
|
157 HsMainWindowMock mainWindow; |
|
158 QState *parent = new QState; |
|
159 HsAllCollectionsState *allCollectionsState = new HsAllCollectionsState( |
|
160 builder, menuMode, mainWindow, parent); |
|
161 |
|
162 allCollectionsState->mMenuMode->setHsMenuMode(Hs::NormalHsMenuMode); |
|
163 allCollectionsState->normalModeEntered(); |
|
164 QCOMPARE(allCollectionsState->mMenuMode->getHsMenuMode(), |
|
165 Hs::NormalHsMenuMode); |
|
166 allCollectionsState->normalModeExited(); |
|
167 QCOMPARE(allCollectionsState->mMenuMode->getHsMenuMode(), |
|
168 Hs::NormalHsMenuMode); |
|
169 delete parent; |
|
170 } |
|
171 #ifdef Q_OS_SYMBIAN |
|
172 #ifdef UT_MEMORY_CHECK |
|
173 __UHEAP_MARKEND; |
|
174 #endif//UT_MEMORY_CHECK |
|
175 #endif//Q_OS_SYMBIAN |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void MenuStatesTest::createNewCollection() |
|
182 { |
|
183 #ifdef Q_OS_SYMBIAN |
|
184 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
185 #ifdef UT_MEMORY_CHECK |
|
186 __UHEAP_MARK; |
|
187 #endif//UT_MEMORY_CHECK |
|
188 #endif//Q_OS_SYMBIAN |
|
189 { |
|
190 HsMenuViewBuilder builder; |
|
191 HsMenuModeWrapper menuMode; |
|
192 HsMainWindowMock mainWindow; |
|
193 QStateMachine *machine = new QStateMachine(0); |
|
194 |
|
195 HsAllCollectionsState *allCollectionsState = |
|
196 new HsAllCollectionsState(builder, menuMode, mainWindow, machine); |
|
197 |
|
198 machine->setInitialState(allCollectionsState); |
|
199 |
|
200 AddToHomeScreenMockState *mockState = new AddToHomeScreenMockState(machine); |
|
201 |
|
202 // create a transition to the new child state which will be triggered by |
|
203 // an event with specified operation type |
|
204 HsMenuEventTransition *newCollectionTransition = new HsMenuEventTransition( |
|
205 HsMenuEvent::CreateCollection, allCollectionsState, mockState); |
|
206 |
|
207 allCollectionsState->addTransition(newCollectionTransition); |
|
208 |
|
209 allCollectionsState->scrollToBeginning(); |
|
210 allCollectionsState->stateEntered(); |
|
211 |
|
212 machine->start(); |
|
213 qApp->sendPostedEvents(); |
|
214 |
|
215 allCollectionsState->createNewCollection(); |
|
216 qApp->sendPostedEvents(); |
|
217 QVERIFY(mockState->enteredValue()); |
|
218 qApp->removePostedEvents(0); |
|
219 machine->stop(); |
|
220 delete machine; |
|
221 } |
|
222 #ifdef Q_OS_SYMBIAN |
|
223 #ifdef UT_MEMORY_CHECK |
|
224 __UHEAP_MARKEND; |
|
225 #endif//UT_MEMORY_CHECK |
|
226 #endif//Q_OS_SYMBIAN |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void MenuStatesTest::createArrangeCollection() |
|
234 { |
|
235 #ifdef Q_OS_SYMBIAN |
|
236 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
237 #ifdef UT_MEMORY_CHECK |
|
238 __UHEAP_MARK; |
|
239 #endif//UT_MEMORY_CHECK |
|
240 #endif//Q_OS_SYMBIAN |
|
241 { |
|
242 HsMenuViewBuilder builder; |
|
243 HsMenuModeWrapper menuMode; |
|
244 HsMainWindowMock mainWindow; |
|
245 QStateMachine *machine = new QStateMachine(0); |
|
246 HsAllCollectionsState *allCollectionsState = |
|
247 new HsAllCollectionsState(builder, menuMode, mainWindow, machine); |
|
248 |
|
249 machine->setInitialState(allCollectionsState); |
|
250 |
|
251 AddToHomeScreenMockState *mockState = new AddToHomeScreenMockState(machine); |
|
252 |
|
253 // create a transition to the new child state which will be triggered by |
|
254 // an event with specified operation type |
|
255 HsMenuEventTransition *transition = new HsMenuEventTransition( |
|
256 HsMenuEvent::ArrangeAllCollections, allCollectionsState, mockState); |
|
257 |
|
258 allCollectionsState->addTransition(transition); |
|
259 |
|
260 allCollectionsState->scrollToBeginning(); |
|
261 allCollectionsState->stateEntered(); |
|
262 machine->start(); |
|
263 qApp->sendPostedEvents(); |
|
264 |
|
265 allCollectionsState->createArrangeCollection(); |
|
266 qApp->sendPostedEvents(); |
|
267 |
|
268 QVERIFY(mockState->enteredValue()); |
|
269 qApp->removePostedEvents(0); |
|
270 machine->stop(); |
|
271 |
|
272 delete machine; |
|
273 } |
|
274 #ifdef Q_OS_SYMBIAN |
|
275 #ifdef UT_MEMORY_CHECK |
|
276 __UHEAP_MARKEND; |
|
277 #endif//UT_MEMORY_CHECK |
|
278 #endif//Q_OS_SYMBIAN |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void MenuStatesTest::listItemActivated() |
|
285 { |
|
286 #ifdef Q_OS_SYMBIAN |
|
287 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
288 #ifdef UT_MEMORY_CHECK |
|
289 __UHEAP_MARK; |
|
290 #endif//UT_MEMORY_CHECK |
|
291 #endif//Q_OS_SYMBIAN |
|
292 { |
|
293 HsMenuViewBuilder builder; |
|
294 HsMenuModeWrapper menuMode; |
|
295 HsMainWindowMock mainWindow; |
|
296 QStateMachine *machine = new QStateMachine(0); |
|
297 QState *parent = new QState(machine); |
|
298 |
|
299 HsAllCollectionsState *allCollectionsState = |
|
300 new HsAllCollectionsState(builder, menuMode, mainWindow, parent); |
|
301 |
|
302 allCollectionsState->scrollToBeginning(); |
|
303 allCollectionsState->stateEntered(); |
|
304 |
|
305 QVERIFY(allCollectionsState->mModel != NULL); |
|
306 QModelIndex applicationModelIndex = |
|
307 allCollectionsState->mModel->index(0, 0); |
|
308 |
|
309 allCollectionsState->openCollection(applicationModelIndex); |
|
310 |
|
311 allCollectionsState->stateExited(); |
|
312 |
|
313 qApp->processEvents(); |
|
314 delete machine; |
|
315 } |
|
316 #ifdef Q_OS_SYMBIAN |
|
317 #ifdef UT_MEMORY_CHECK |
|
318 __UHEAP_MARKEND; |
|
319 #endif//UT_MEMORY_CHECK |
|
320 #endif//Q_OS_SYMBIAN |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // --------------------------------------------------------------------------- |
|
325 |
|
326 void MenuStatesTest::listItemLongPressed() |
|
327 { |
|
328 #ifdef Q_OS_SYMBIAN |
|
329 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
330 #ifdef UT_MEMORY_CHECK |
|
331 __UHEAP_MARK; |
|
332 #endif//UT_MEMORY_CHECK |
|
333 #endif//Q_OS_SYMBIAN |
|
334 { |
|
335 QScopedPointer<HbMainWindow> wind(new HbMainWindow); |
|
336 |
|
337 HsMenuViewBuilder builder; |
|
338 HsMenuModeWrapper menuMode; |
|
339 HsMainWindowMock mainWindow; |
|
340 |
|
341 QStateMachine *machine = new QStateMachine(0); |
|
342 QState *parent = new QState(machine); |
|
343 |
|
344 HsAllCollectionsState *allCollectionsState = |
|
345 new HsAllCollectionsState(builder, menuMode, mainWindow, parent); |
|
346 |
|
347 allCollectionsState->scrollToBeginning(); |
|
348 allCollectionsState->stateEntered(); |
|
349 |
|
350 HbAbstractViewItem *item = new HbListViewItem; |
|
351 |
|
352 item->setModelIndex(allCollectionsState->mModel->index(0,0)); |
|
353 |
|
354 allCollectionsState->showContextMenu(item , |
|
355 QPointF(50,50)); |
|
356 |
|
357 uint flags = allCollectionsState->mModel->data(allCollectionsState->mModel->index(0, 0), |
|
358 CaItemModel::FlagsRole).value<EntryFlags> (); |
|
359 |
|
360 if (flags & RemovableEntryFlag) { |
|
361 QCOMPARE(allCollectionsState->mContextMenu->actions().length(), 4); |
|
362 } else { |
|
363 QCOMPARE(allCollectionsState->mContextMenu->actions().length(), 2); |
|
364 } |
|
365 |
|
366 |
|
367 QVERIFY(allCollectionsState->mContextMenu->testAttribute(Qt::WA_DeleteOnClose)); |
|
368 |
|
369 qApp->processEvents(); |
|
370 |
|
371 allCollectionsState->stateExited(); |
|
372 |
|
373 qApp->processEvents(); |
|
374 delete machine; |
|
375 delete item; |
|
376 } |
|
377 #ifdef Q_OS_SYMBIAN |
|
378 #ifdef UT_MEMORY_CHECK |
|
379 __UHEAP_MARKEND; |
|
380 #endif//UT_MEMORY_CHECK |
|
381 #endif//Q_OS_SYMBIAN |
|
382 } |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // --------------------------------------------------------------------------- |
|
386 // |
|
387 void MenuStatesTest::contextMenuAction() |
|
388 { |
|
389 #ifdef Q_OS_SYMBIAN |
|
390 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
391 #ifdef UT_MEMORY_CHECK |
|
392 __UHEAP_MARK; |
|
393 #endif//UT_MEMORY_CHECK |
|
394 #endif//Q_OS_SYMBIAN |
|
395 { |
|
396 QScopedPointer<QStateMachine> machine(new QStateMachine(0)); |
|
397 |
|
398 QScopedPointer<HbMainWindow> window(new HbMainWindow); |
|
399 |
|
400 HsMenuViewBuilder builder; |
|
401 HsMenuModeWrapper menuMode; |
|
402 HsMainWindow mainWindow; |
|
403 |
|
404 QScopedPointer<HsAllCollectionsState> allCollectionsState (new HsAllCollectionsState( |
|
405 builder, menuMode, mainWindow, machine.data())); |
|
406 |
|
407 |
|
408 // we will start from all apps view |
|
409 machine->setInitialState(allCollectionsState.data()); |
|
410 |
|
411 // create a state which is to be reached when add-to-home-screen |
|
412 // event is triggered |
|
413 AddToHomeScreenMockState addToHomeScreenState(machine.data()); |
|
414 |
|
415 // create a transition to the new child state which will be triggered by |
|
416 // an event with specified operation type |
|
417 HsMenuEventTransition addToHomeScreenTransition( |
|
418 HsMenuEvent::AddToHomeScreen, allCollectionsState.data(), &addToHomeScreenState); |
|
419 |
|
420 // prepare the state graph |
|
421 allCollectionsState->addTransition(&addToHomeScreenTransition); |
|
422 |
|
423 // MockModel object is to provide CaEntry representing widget |
|
424 // the object will be deleted on destruction of allAppsState |
|
425 MockModel *allCollectionsMockModel = new MockModel; |
|
426 allCollectionsState->mModel = allCollectionsMockModel; |
|
427 allCollectionsState->mMenuView->setModel(allCollectionsMockModel); |
|
428 |
|
429 machine->start(); |
|
430 qApp->sendPostedEvents(); |
|
431 |
|
432 HbAction *action = new HbAction("test_addtohomescreen"); |
|
433 action->setData(Hs::AddToHomeScreenContextAction); |
|
434 allCollectionsState->mContextModelIndex = allCollectionsMockModel->fixedIndex(); |
|
435 |
|
436 allCollectionsState->contextMenuAction(action); |
|
437 |
|
438 qApp->sendPostedEvents(); |
|
439 |
|
440 QVERIFY(addToHomeScreenState.enteredValue()); |
|
441 |
|
442 machine->stop(); |
|
443 qApp->removePostedEvents(0); |
|
444 |
|
445 allCollectionsState->stateExited(); |
|
446 |
|
447 qApp->processEvents(); |
|
448 |
|
449 delete action; |
|
450 } |
|
451 #ifdef Q_OS_SYMBIAN |
|
452 #ifdef UT_MEMORY_CHECK |
|
453 __UHEAP_MARKEND; |
|
454 #endif//UT_MEMORY_CHECK |
|
455 #endif//Q_OS_SYMBIAN |
|
456 } |
|
457 |
|
458 // --------------------------------------------------------------------------- |
|
459 // --------------------------------------------------------------------------- |
|
460 |
|
461 void MenuStatesTest::addModeSlots() |
|
462 { |
|
463 #ifdef Q_OS_SYMBIAN |
|
464 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
465 #ifdef UT_MEMORY_CHECK |
|
466 __UHEAP_MARK; |
|
467 #endif//UT_MEMORY_CHECK |
|
468 #endif//Q_OS_SYMBIAN |
|
469 { |
|
470 HsMenuViewBuilder builder; |
|
471 QScopedPointer<QStateMachine> machine(new QStateMachine(0)); |
|
472 HsMenuModeWrapper menuMode; |
|
473 HsMainWindowMock mainWindow; |
|
474 menuMode.setHsMenuMode(Hs::AddHsMenuMode); |
|
475 QScopedPointer<HsAllCollectionsState> allCollectionsState( |
|
476 new HsAllCollectionsState(builder, menuMode, mainWindow, machine.data())); |
|
477 |
|
478 { |
|
479 // we will start from all apps view |
|
480 machine->setInitialState(allCollectionsState.data()); |
|
481 |
|
482 // create a state which is to be reached when add-to-home-screen |
|
483 // event is triggered |
|
484 AddToHomeScreenMockState addToHomeScreenState(machine.data()); |
|
485 |
|
486 // create a transition to the new child state which will be triggered by |
|
487 // an event with specified operation type |
|
488 HsMenuEventTransition addToHomeScreenTransition( |
|
489 HsMenuEvent::AddToHomeScreen, allCollectionsState.data(), &addToHomeScreenState); |
|
490 |
|
491 // prepare the state graph |
|
492 allCollectionsState->addTransition(&addToHomeScreenTransition); |
|
493 |
|
494 // MockModel object is to provide CaEntry representing widget |
|
495 // the object will be deleted on destruction of allAppsState |
|
496 allCollectionsState->scrollToBeginning(); |
|
497 allCollectionsState->stateEntered(); |
|
498 |
|
499 |
|
500 machine->start(); |
|
501 qApp->sendPostedEvents(); |
|
502 |
|
503 allCollectionsState->addActivated(allCollectionsState->mModel->index(0,0)); |
|
504 |
|
505 qApp->sendPostedEvents(); |
|
506 |
|
507 QVERIFY(addToHomeScreenState.enteredValue()); |
|
508 machine->stop(); |
|
509 qApp->removePostedEvents(0); |
|
510 } |
|
511 } |
|
512 #ifdef Q_OS_SYMBIAN |
|
513 #ifdef UT_MEMORY_CHECK |
|
514 __UHEAP_MARKEND; |
|
515 #endif//UT_MEMORY_CHECK |
|
516 #endif//Q_OS_SYMBIAN |
|
517 } |
|
518 |
|
519 // --------------------------------------------------------------------------- |
|
520 // --------------------------------------------------------------------------- |
|
521 // |
|
522 #ifdef Q_OS_SYMBIAN |
|
523 void MenuStatesTest::openTaskSwitcher() |
|
524 { |
|
525 #ifdef Q_OS_SYMBIAN |
|
526 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
527 #ifdef UT_MEMORY_CHECK |
|
528 __UHEAP_MARK; |
|
529 #endif//UT_MEMORY_CHECK |
|
530 #endif//Q_OS_SYMBIAN |
|
531 { |
|
532 HsMenuViewBuilder builder; |
|
533 HsMenuModeWrapper menuMode; |
|
534 HsMainWindowMock mainWindow; |
|
535 QStateMachine *machine = new QStateMachine(0); |
|
536 QState *parent = new QState(machine); |
|
537 menuMode.setHsMenuMode(Hs::AddHsMenuMode); |
|
538 HsAllCollectionsState *allCollectionsState = |
|
539 new HsAllCollectionsState(builder, menuMode, mainWindow, parent); |
|
540 |
|
541 QVERIFY(allCollectionsState->openTaskSwitcher()); |
|
542 delete machine; |
|
543 } |
|
544 #ifdef Q_OS_SYMBIAN |
|
545 #ifdef UT_MEMORY_CHECK |
|
546 __UHEAP_MARKEND; |
|
547 #endif//UT_MEMORY_CHECK |
|
548 #endif//Q_OS_SYMBIAN |
|
549 } |
|
550 #endif//Q_OS_SYMBIAN |
|
551 |
|
552 QTEST_MAIN(MenuStatesTest) |
|
553 |