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 |
|
18 #include <QtGui> |
|
19 #include <QtTest/QtTest> |
|
20 |
|
21 #include <hbapplication.h> |
|
22 #include <hbmainwindow.h> |
|
23 #include <hbaction.h> |
|
24 #include <hbtoolbar.h> |
|
25 #include <hbview.h> |
|
26 #include <hblineedit.h> |
|
27 #include <hbmessagebox.h> |
|
28 |
|
29 #include "dialpadtest.h" |
|
30 #include "dialpadtestutil.h" |
|
31 #include "dialpad.h" |
|
32 |
|
33 const int WAIT_TIME = 300; |
|
34 const int LONGPRESS_DURATION = 1000; |
|
35 |
|
36 // helper class |
|
37 class KeyEventCatcher : public QObject |
|
38 { |
|
39 public: |
|
40 bool eventFilter(QObject* watched, QEvent * event) |
|
41 { |
|
42 Q_UNUSED(watched); |
|
43 |
|
44 if (event->type() == QEvent::KeyPress) { |
|
45 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
46 mKeyPresses.append(keyEvent->key()); |
|
47 return false; |
|
48 } else if (event->type() == QEvent::KeyRelease) { |
|
49 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
50 mKeyReleases.append(keyEvent->key()); |
|
51 return false; |
|
52 } |
|
53 return false; |
|
54 } |
|
55 |
|
56 public: |
|
57 QList<int> mKeyPresses; |
|
58 QList<int> mKeyReleases; |
|
59 }; |
|
60 |
|
61 // test cases |
|
62 class mt_Dialpad : public QObject |
|
63 { |
|
64 Q_OBJECT |
|
65 |
|
66 private slots: |
|
67 void initTestCase(); |
|
68 void cleanupTestCase(); |
|
69 void cleanup(); |
|
70 |
|
71 void testNumericButtons(); |
|
72 void testNumericButtonLongPress(); |
|
73 void testBackspace(); |
|
74 void testAsteriskMultitap(); |
|
75 void testCallButton(); |
|
76 void testCloseGesture(); |
|
77 void testOpenDialogWhileButtonPressed(); |
|
78 void testTapOutsideDismiss(); |
|
79 |
|
80 #ifndef Q_OS_SYMBIAN |
|
81 void testCloseGestureLandscape(); |
|
82 void testOrientationChange(); |
|
83 #endif |
|
84 |
|
85 private: |
|
86 HbMainWindow* mMainWindow; |
|
87 Dialpad* mDialpad; |
|
88 KeyEventCatcher* mKeyCatcher; |
|
89 DialpadTestUtil* mUtil; |
|
90 }; |
|
91 |
|
92 void mt_Dialpad::initTestCase() |
|
93 { |
|
94 mMainWindow = new HbMainWindow; |
|
95 |
|
96 mKeyCatcher = new KeyEventCatcher; |
|
97 mMainWindow->installEventFilter(mKeyCatcher); |
|
98 |
|
99 mUtil = new DialpadTestUtil(*mMainWindow); |
|
100 |
|
101 mDialpad = new Dialpad(*mMainWindow); |
|
102 |
|
103 QRectF rect(mMainWindow->contentsRect()); |
|
104 rect.setHeight(rect.height()*0.7); |
|
105 rect.moveTop((mMainWindow->contentsRect().height()-rect.height())/2); |
|
106 |
|
107 mDialpad->resize(mMainWindow->layoutRect().width(), |
|
108 mMainWindow->layoutRect().height()/2); |
|
109 mDialpad->setPos(0,mMainWindow->layoutRect().height()/4); |
|
110 |
|
111 mMainWindow->show(); |
|
112 mDialpad->show(); |
|
113 mDialpad->hide(); |
|
114 } |
|
115 |
|
116 void mt_Dialpad::cleanupTestCase() |
|
117 { |
|
118 delete mDialpad; |
|
119 delete mMainWindow; |
|
120 delete mKeyCatcher; |
|
121 delete mUtil; |
|
122 } |
|
123 |
|
124 void mt_Dialpad::cleanup() |
|
125 { |
|
126 mKeyCatcher->mKeyPresses.clear(); |
|
127 mKeyCatcher->mKeyReleases.clear(); |
|
128 mDialpad->editor().setText(QString()); |
|
129 QTest::qWait( WAIT_TIME ); // delay between tests |
|
130 } |
|
131 |
|
132 void mt_Dialpad::testNumericButtons() |
|
133 { |
|
134 QSignalSpy aboutToOpenSpy( mDialpad, SIGNAL(aboutToOpen())); |
|
135 QSignalSpy aboutToCloseSpy( mDialpad, SIGNAL(aboutToClose())); |
|
136 |
|
137 QVERIFY(mDialpad->isOpen()==false); |
|
138 mDialpad->openDialpad(); |
|
139 QVERIFY(mDialpad->isOpen()==true); |
|
140 QVERIFY(aboutToOpenSpy.count()==1); |
|
141 QTest::qWait( 2*WAIT_TIME ); |
|
142 |
|
143 mUtil->mouseClickDialpad(Qt::Key_1); |
|
144 mUtil->mouseClickDialpad(Qt::Key_2); |
|
145 mUtil->mouseClickDialpad(Qt::Key_3); |
|
146 mUtil->mouseClickDialpad(Qt::Key_4); |
|
147 mUtil->mouseClickDialpad(Qt::Key_5); |
|
148 mUtil->mouseClickDialpad(Qt::Key_6); |
|
149 mUtil->mouseClickDialpad(Qt::Key_7); |
|
150 mUtil->mouseClickDialpad(Qt::Key_8); |
|
151 mUtil->mouseClickDialpad(Qt::Key_9); |
|
152 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
153 mUtil->mouseClickDialpad(Qt::Key_0); |
|
154 mUtil->mouseClickDialpad(Qt::Key_NumberSign); |
|
155 |
|
156 QVERIFY(mDialpad->editor().text()=="123456789*0#"); |
|
157 |
|
158 QVERIFY(mKeyCatcher->mKeyPresses.count()==12); |
|
159 QVERIFY(mKeyCatcher->mKeyReleases.count()==12); |
|
160 QVERIFY(mKeyCatcher->mKeyPresses.at(0)==Qt::Key_1); |
|
161 QVERIFY(mKeyCatcher->mKeyReleases.at(0)==Qt::Key_1); |
|
162 QVERIFY(mKeyCatcher->mKeyPresses.at(11)==Qt::Key_NumberSign); |
|
163 QVERIFY(mKeyCatcher->mKeyReleases.at(11)==Qt::Key_NumberSign); |
|
164 mDialpad->closeDialpad(); |
|
165 QVERIFY(mDialpad->isOpen()==false); |
|
166 QVERIFY(aboutToCloseSpy.count()==1); |
|
167 } |
|
168 |
|
169 void mt_Dialpad::testNumericButtonLongPress() |
|
170 { |
|
171 mDialpad->openDialpad(); |
|
172 QTest::qWait( WAIT_TIME ); |
|
173 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Press); |
|
174 QTest::qWait( LONGPRESS_DURATION ); |
|
175 mUtil->mouseClickDialpad(Qt::Key_1, DialpadTestUtil::Release); |
|
176 QVERIFY(mDialpad->editor().text()=="1"); |
|
177 mDialpad->closeDialpad(); |
|
178 } |
|
179 |
|
180 void mt_Dialpad::testBackspace() |
|
181 { |
|
182 mDialpad->openDialpad(); |
|
183 QTest::qWait( WAIT_TIME ); |
|
184 mUtil->mouseClickDialpad(Qt::Key_1); |
|
185 QVERIFY(mDialpad->editor().text()=="1"); |
|
186 mUtil->mouseClickDialpad(Qt::Key_Backspace); |
|
187 QVERIFY(mDialpad->editor().text()==""); |
|
188 QVERIFY(mKeyCatcher->mKeyPresses.count()==2); |
|
189 QVERIFY(mKeyCatcher->mKeyReleases.count()==2); |
|
190 QVERIFY(mKeyCatcher->mKeyPresses.at(1)==Qt::Key_Backspace); |
|
191 QVERIFY(mKeyCatcher->mKeyReleases.at(1)==Qt::Key_Backspace); |
|
192 // test repeats |
|
193 QTest::qWait( WAIT_TIME ); |
|
194 mUtil->mouseClickDialpad(Qt::Key_1); |
|
195 mUtil->mouseClickDialpad(Qt::Key_2); |
|
196 mUtil->mouseClickDialpad(Qt::Key_3); |
|
197 QVERIFY(mDialpad->editor().text()=="123"); |
|
198 mUtil->mouseClickDialpad(Qt::Key_Backspace, DialpadTestUtil::Press); |
|
199 QTest::qWait( 1500 ); |
|
200 mUtil->mouseClickDialpad(Qt::Key_Backspace, DialpadTestUtil::Release); |
|
201 QVERIFY(mDialpad->editor().text()==""); |
|
202 mDialpad->closeDialpad(); |
|
203 } |
|
204 |
|
205 void mt_Dialpad::testAsteriskMultitap() |
|
206 { |
|
207 mDialpad->openDialpad(); |
|
208 QTest::qWait( WAIT_TIME ); |
|
209 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
210 QVERIFY(mDialpad->editor().text()=="*"); |
|
211 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
212 QVERIFY(mDialpad->editor().text()=="+"); |
|
213 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
214 QVERIFY(mDialpad->editor().text()=="p"); |
|
215 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
216 QVERIFY(mDialpad->editor().text()=="w"); |
|
217 |
|
218 QVERIFY(mKeyCatcher->mKeyPresses.count()==4); |
|
219 QVERIFY(mKeyCatcher->mKeyReleases.count()==4); |
|
220 QVERIFY(mKeyCatcher->mKeyPresses.at(1)==Qt::Key_Asterisk); |
|
221 QVERIFY(mKeyCatcher->mKeyReleases.at(1)==Qt::Key_Asterisk); |
|
222 QVERIFY(mKeyCatcher->mKeyPresses.at(2)==Qt::Key_Asterisk); |
|
223 QVERIFY(mKeyCatcher->mKeyReleases.at(2)==Qt::Key_Asterisk); |
|
224 |
|
225 // Verify that the second char can't be + |
|
226 QTest::qWait(1000); |
|
227 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
228 QCOMPARE(mDialpad->editor().text(), QString("w*")); |
|
229 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
230 QCOMPARE(mDialpad->editor().text(), QString("wp")); |
|
231 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
232 QCOMPARE(mDialpad->editor().text(), QString("ww")); |
|
233 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
234 QCOMPARE(mDialpad->editor().text(), QString("w*")); |
|
235 |
|
236 // test entering two asterisk |
|
237 QTest::qWait(1000); |
|
238 mDialpad->editor().setText(QString()); |
|
239 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
240 QTest::qWait( 1000 ); // longer than short tap |
|
241 mUtil->mouseClickDialpad(Qt::Key_Asterisk); |
|
242 QCOMPARE(mDialpad->editor().text(), QString("**")); |
|
243 |
|
244 mDialpad->closeDialpad(); |
|
245 } |
|
246 |
|
247 void mt_Dialpad::testCallButton() |
|
248 { |
|
249 mDialpad->openDialpad(); |
|
250 QTest::qWait( WAIT_TIME ); |
|
251 mDialpad->setCallButtonEnabled(false); |
|
252 mUtil->mouseClickDialpad(Qt::Key_Yes); |
|
253 QVERIFY(mKeyCatcher->mKeyPresses.count()==0); |
|
254 QVERIFY(mKeyCatcher->mKeyReleases.count()==0); |
|
255 mDialpad->setCallButtonEnabled(true); |
|
256 mUtil->mouseClickDialpad(Qt::Key_Yes); |
|
257 QTest::qWait( WAIT_TIME ); |
|
258 QVERIFY(mKeyCatcher->mKeyPresses.count()==1); |
|
259 QVERIFY(mKeyCatcher->mKeyReleases.count()==1); |
|
260 QVERIFY(mKeyCatcher->mKeyPresses.at(0)==Qt::Key_Yes); |
|
261 QVERIFY(mKeyCatcher->mKeyReleases.at(0)==Qt::Key_Yes); |
|
262 mDialpad->closeDialpad(); |
|
263 } |
|
264 |
|
265 void mt_Dialpad::testCloseGesture() |
|
266 { |
|
267 // QTest::mouseMove() doesn't work |
|
268 } |
|
269 |
|
270 void mt_Dialpad::testOpenDialogWhileButtonPressed() |
|
271 { |
|
272 mDialpad->openDialpad(); |
|
273 QTest::qWait( WAIT_TIME ); |
|
274 mUtil->mouseClickDialpad(Qt::Key_5, DialpadTestUtil::Press); |
|
275 QTest::qWait( LONGPRESS_DURATION ); |
|
276 |
|
277 HbMessageBox* box = new HbMessageBox("Test dialog!"); |
|
278 box->setAttribute(Qt::WA_DeleteOnClose); |
|
279 box->setTimeout(1000); |
|
280 box->show(); |
|
281 QTest::qWait( 500 ); |
|
282 mUtil->mouseClickDialpad(Qt::Key_5, DialpadTestUtil::Release); |
|
283 QTest::qWait( 100 ); |
|
284 |
|
285 QVERIFY(mDialpad->editor().text()=="5"); |
|
286 QVERIFY(mKeyCatcher->mKeyPresses.at(0)==Qt::Key_5); |
|
287 QVERIFY(mKeyCatcher->mKeyReleases.at(0)==Qt::Key_5); |
|
288 mDialpad->closeDialpad(); |
|
289 } |
|
290 |
|
291 void mt_Dialpad::testTapOutsideDismiss() |
|
292 { |
|
293 mDialpad->openDialpad(); |
|
294 QTest::qWait( WAIT_TIME ); |
|
295 |
|
296 QPointF aboveTop = mDialpad->scenePos(); |
|
297 aboveTop.setY(aboveTop.y()-10); |
|
298 aboveTop.setX(aboveTop.x()+mDialpad->rect().center().x()); |
|
299 QPoint windowPos = mMainWindow->mapFromScene( aboveTop ); |
|
300 |
|
301 // test tap outside dismiss is OFF (default) |
|
302 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton, |
|
303 0, windowPos ); |
|
304 QTest::qWait( 500 ); |
|
305 QVERIFY(mDialpad->isVisible()); |
|
306 mDialpad->closeDialpad(); |
|
307 |
|
308 // test tap outside dismiss is ON |
|
309 mDialpad->setTapOutsideDismiss(true); |
|
310 mDialpad->openDialpad(); |
|
311 QTest::qWait( WAIT_TIME ); |
|
312 QTest::mouseClick( mMainWindow->viewport(), Qt::LeftButton, |
|
313 0, windowPos ); |
|
314 QTest::qWait( 500 ); |
|
315 QVERIFY(!mDialpad->isVisible()); |
|
316 } |
|
317 |
|
318 #ifndef Q_OS_SYMBIAN |
|
319 void mt_Dialpad::testCloseGestureLandscape() |
|
320 { |
|
321 /* |
|
322 // switch to landscape |
|
323 mMainWindow->setOrientation(Qt::Horizontal); |
|
324 mMainWindow->resize(640,360); |
|
325 QTest::qWait( 1000 ); |
|
326 |
|
327 mDialpad->resize(mMainWindow->layoutRect().width()/2, |
|
328 mMainWindow->layoutRect().height()); |
|
329 mDialpad->setPos(mMainWindow->layoutRect().width()/2,0); |
|
330 |
|
331 mDialpad->openDialpad(); |
|
332 |
|
333 // slow swipe |
|
334 QTest::qWait( WAIT_TIME ); |
|
335 mUtil->mouseClickDialpad(Qt::Key_4, Press, false); |
|
336 QTest::qWait( 500 ); // longer than swipe |
|
337 mUtil->mouseClickDialpad(Qt::Key_6, Release, false); |
|
338 QTest::qWait( 500 ); |
|
339 QVERIFY(mDialpad->isVisible()==true); |
|
340 |
|
341 // short swipe |
|
342 QTest::qWait( WAIT_TIME ); |
|
343 mUtil->mouseClickDialpad(Qt::Key_4, Press, false); |
|
344 QTest::qWait( 200 ); |
|
345 mUtil->mouseClickDialpad(Qt::Key_5, Release, false); |
|
346 QTest::qWait( 500 ); |
|
347 QVERIFY(mDialpad->isVisible()==true); |
|
348 |
|
349 // ok swipe |
|
350 mDialpad->editor().setText(QString()); |
|
351 QTest::qWait( WAIT_TIME ); |
|
352 mUtil->mouseClickDialpad(Qt::Key_4, Press, false); |
|
353 QTest::qWait( 200 ); |
|
354 mUtil->mouseClickDialpad(Qt::Key_6, Release, false); |
|
355 QVERIFY(mDialpad->editor().text()==""); |
|
356 QTest::qWait( 1000 ); |
|
357 QVERIFY(mDialpad->isVisible()==false);*/ |
|
358 } |
|
359 |
|
360 void mt_Dialpad::testOrientationChange() |
|
361 { |
|
362 mDialpad->openDialpad(); |
|
363 QTest::qWait( WAIT_TIME ); |
|
364 |
|
365 // test landscape |
|
366 mMainWindow->setOrientation(Qt::Horizontal); |
|
367 mMainWindow->resize(640,360); |
|
368 QTest::qWait( 1000 ); |
|
369 mDialpad->resize(mMainWindow->layoutRect().width()/2, |
|
370 mMainWindow->layoutRect().height()); |
|
371 mDialpad->setPos(mMainWindow->layoutRect().width()/2,0); |
|
372 QTest::qWait( 1000 ); |
|
373 |
|
374 QVERIFY(mDialpad->isVisible()==true); |
|
375 mUtil->mouseClickDialpad(Qt::Key_5); |
|
376 QVERIFY(mDialpad->editor().text()=="5"); |
|
377 QTest::qWait( 500 ); |
|
378 |
|
379 // test portrait |
|
380 mMainWindow->setOrientation(Qt::Vertical); |
|
381 mMainWindow->resize(360,640); |
|
382 mDialpad->resize(mMainWindow->layoutRect().width(), |
|
383 mMainWindow->layoutRect().height()/2); |
|
384 mDialpad->setPos(0,mMainWindow->layoutRect().height()/4); |
|
385 QTest::qWait( 1000 ); |
|
386 |
|
387 QVERIFY(mDialpad->isVisible()==true); |
|
388 mDialpad->editor().setText(""); |
|
389 mUtil->mouseClickDialpad(Qt::Key_5); |
|
390 QVERIFY(mDialpad->editor().text()=="5"); |
|
391 |
|
392 mDialpad->closeDialpad(); |
|
393 QTest::qWait( 500 ); |
|
394 QVERIFY(mDialpad->isVisible()==false); |
|
395 } |
|
396 |
|
397 #endif //Q_OS_SYMBIAN |
|
398 |
|
399 DIALPAD_TEST_MAIN(mt_Dialpad) |
|
400 #include "mt_dialpad.moc" |
|
401 |
|