author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QApplication> |
|
44 |
#include <QMessageBox> |
|
45 |
#include <QtTest/QtTest> |
|
46 |
#include <QSplashScreen> |
|
47 |
#include <QScrollBar> |
|
48 |
#include <QProgressDialog> |
|
49 |
#include <QSpinBox> |
|
50 |
||
51 |
#include <guitest.h> |
|
52 |
||
53 |
#ifdef Q_OS_MAC |
|
54 |
||
55 |
class tst_MacGui : public GuiTester |
|
56 |
{ |
|
57 |
Q_OBJECT |
|
58 |
private slots: |
|
59 |
void scrollbarPainting(); |
|
60 |
||
61 |
void dummy(); |
|
62 |
void splashScreenModality(); |
|
63 |
void nonModalOrder(); |
|
64 |
||
65 |
void spinBoxArrowButtons(); |
|
66 |
}; |
|
67 |
||
68 |
||
69 |
QPixmap grabWindowContents(QWidget * widget) |
|
70 |
{ |
|
71 |
return QPixmap::grabWindow(widget->winId()); |
|
72 |
} |
|
73 |
||
74 |
/* |
|
75 |
Test that vertical and horizontal mac-style scrollbars paint their |
|
76 |
entire area. |
|
77 |
*/ |
|
78 |
void tst_MacGui::scrollbarPainting() |
|
79 |
{ |
|
80 |
ColorWidget colorWidget; |
|
81 |
colorWidget.resize(400, 400); |
|
82 |
||
83 |
QSize scrollBarSize; |
|
84 |
||
85 |
QScrollBar verticalScrollbar(&colorWidget); |
|
86 |
verticalScrollbar.move(10, 10); |
|
87 |
scrollBarSize = verticalScrollbar.sizeHint(); |
|
88 |
scrollBarSize.setHeight(200); |
|
89 |
verticalScrollbar.resize(scrollBarSize); |
|
90 |
||
91 |
QScrollBar horizontalScrollbar(&colorWidget); |
|
92 |
horizontalScrollbar.move(30, 10); |
|
93 |
horizontalScrollbar.setOrientation(Qt::Horizontal); |
|
94 |
scrollBarSize = horizontalScrollbar.sizeHint(); |
|
95 |
scrollBarSize.setWidth(200); |
|
96 |
horizontalScrollbar.resize(scrollBarSize); |
|
97 |
||
98 |
colorWidget.show(); |
|
99 |
colorWidget.raise(); |
|
100 |
QTest::qWait(100); |
|
101 |
||
102 |
QPixmap pixmap = grabWindowContents(&colorWidget); |
|
103 |
||
104 |
QVERIFY(isContent(pixmap.toImage(), verticalScrollbar.geometry(), GuiTester::Horizontal)); |
|
105 |
QVERIFY(isContent(pixmap.toImage(), horizontalScrollbar.geometry(), GuiTester::Vertical)); |
|
106 |
} |
|
107 |
||
108 |
// When running the auto-tests on scruffy, the first enter-the-event-loop-and-wait-for-a-click |
|
109 |
// test that runs always times out, so we have this dummy test. |
|
110 |
void tst_MacGui::dummy() |
|
111 |
{ |
|
112 |
QPixmap pix(100, 100); |
|
113 |
QSplashScreen splash(pix); |
|
114 |
splash.show(); |
|
115 |
||
116 |
QMessageBox *box = new QMessageBox(); |
|
117 |
box->setText("accessible?"); |
|
118 |
box->show(); |
|
119 |
||
120 |
// Find the "OK" button and schedule a press. |
|
121 |
InterfaceChildPair interface = wn.find(QAccessible::Name, "OK", box); |
|
122 |
QVERIFY(interface.iface); |
|
123 |
const int delay = 1000; |
|
124 |
clickLater(interface, Qt::LeftButton, delay); |
|
125 |
||
126 |
// Show dialog and and enter event loop. |
|
127 |
connect(wn.getWidget(interface), SIGNAL(clicked()), SLOT(exitLoopSlot())); |
|
128 |
const int timeout = 4; |
|
129 |
QTestEventLoop::instance().enterLoop(timeout); |
|
130 |
} |
|
131 |
||
132 |
/* |
|
133 |
Test that a message box pops up in front of a QSplashScreen. |
|
134 |
*/ |
|
135 |
void tst_MacGui::splashScreenModality() |
|
136 |
{ |
|
137 |
QPixmap pix(300, 300); |
|
138 |
QSplashScreen splash(pix); |
|
139 |
splash.show(); |
|
140 |
||
141 |
QMessageBox box; |
|
142 |
//box.setWindowFlags(box.windowFlags() | Qt::WindowStaysOnTopHint); |
|
143 |
box.setText("accessible?"); |
|
144 |
box.show(); |
|
145 |
||
146 |
// Find the "OK" button and schedule a press. |
|
147 |
InterfaceChildPair interface = wn.find(QAccessible::Name, "OK", &box); |
|
148 |
QVERIFY(interface.iface); |
|
149 |
const int delay = 1000; |
|
150 |
clickLater(interface, Qt::LeftButton, delay); |
|
151 |
||
152 |
// Show dialog and and enter event loop. |
|
153 |
connect(wn.getWidget(interface), SIGNAL(clicked()), SLOT(exitLoopSlot())); |
|
154 |
const int timeout = 4; |
|
155 |
QTestEventLoop::instance().enterLoop(timeout); |
|
156 |
QVERIFY(QTestEventLoop::instance().timeout() == false); |
|
157 |
} |
|
158 |
||
159 |
class PrimaryWindowDialog : public QDialog |
|
160 |
{ |
|
161 |
Q_OBJECT |
|
162 |
public: |
|
163 |
PrimaryWindowDialog(); |
|
164 |
QWidget *secondaryWindow; |
|
165 |
QWidget *frontWidget; |
|
166 |
public slots: |
|
167 |
void showSecondaryWindow(); |
|
168 |
void test(); |
|
169 |
}; |
|
170 |
||
171 |
PrimaryWindowDialog::PrimaryWindowDialog() : QDialog(0) |
|
172 |
{ |
|
173 |
frontWidget = 0; |
|
174 |
secondaryWindow = new ColorWidget(this); |
|
175 |
secondaryWindow->setWindowFlags(Qt::Window); |
|
176 |
secondaryWindow->resize(400, 400); |
|
177 |
secondaryWindow->move(100, 100); |
|
178 |
QTimer::singleShot(1000, this, SLOT(showSecondaryWindow())); |
|
179 |
QTimer::singleShot(2000, this, SLOT(test())); |
|
180 |
QTimer::singleShot(3000, this, SLOT(close())); |
|
181 |
} |
|
182 |
||
183 |
void PrimaryWindowDialog::showSecondaryWindow() |
|
184 |
{ |
|
185 |
secondaryWindow->show(); |
|
186 |
} |
|
187 |
||
188 |
void PrimaryWindowDialog::test() |
|
189 |
{ |
|
190 |
frontWidget = QApplication::widgetAt(secondaryWindow->mapToGlobal(QPoint(100, 100))); |
|
191 |
} |
|
192 |
||
193 |
/* |
|
194 |
Test that a non-modal child window of a modal dialog is shown in front |
|
195 |
of the dialog even if the dialog becomes modal after the child window |
|
196 |
is created. |
|
197 |
*/ |
|
198 |
void tst_MacGui::nonModalOrder() |
|
199 |
{ |
|
200 |
clearSequence(); |
|
201 |
PrimaryWindowDialog primary; |
|
202 |
primary.resize(400, 400); |
|
203 |
primary.move(100, 100); |
|
204 |
primary.exec(); |
|
205 |
QCOMPARE(primary.frontWidget, primary.secondaryWindow); |
|
206 |
} |
|
207 |
||
208 |
/* |
|
209 |
Test that the QSpinBox buttons are correctly positioned with the Mac style. |
|
210 |
*/ |
|
211 |
void tst_MacGui::spinBoxArrowButtons() |
|
212 |
{ |
|
213 |
ColorWidget colorWidget; |
|
214 |
colorWidget.resize(200, 200); |
|
215 |
QSpinBox spinBox(&colorWidget); |
|
216 |
QSpinBox spinBox2(&colorWidget); |
|
217 |
spinBox2.move(0, 100); |
|
218 |
colorWidget.show(); |
|
219 |
QTest::qWait(100); |
|
220 |
||
221 |
// Grab an unfocused spin box. |
|
222 |
const QImage noFocus = grabWindowContents(&colorWidget).toImage(); |
|
223 |
||
224 |
// Set focus by clicking the less button. |
|
225 |
InterfaceChildPair lessInterface = wn.find(QAccessible::Name, "Less", &spinBox); |
|
226 |
QVERIFY(lessInterface.iface); |
|
227 |
const int delay = 500; |
|
228 |
clickLater(lessInterface, Qt::LeftButton, delay); |
|
229 |
const int timeout = 1; |
|
230 |
QTestEventLoop::instance().enterLoop(timeout); |
|
231 |
||
232 |
// Grab a focused spin box. |
|
233 |
const QImage focus = grabWindowContents(&colorWidget).toImage(); |
|
234 |
||
235 |
// Compare the arrow area of the less button to see if it moved. |
|
236 |
const QRect lessRect = lessInterface.iface->rect(lessInterface.possibleChild); |
|
237 |
const QRect lessLocalRect(colorWidget.mapFromGlobal(lessRect.topLeft()), colorWidget.mapFromGlobal(lessRect.bottomRight())); |
|
238 |
const QRect compareRect = lessLocalRect.adjusted(5, 3, -5, -7); |
|
239 |
QVERIFY(noFocus.copy(compareRect) == focus.copy(compareRect)); |
|
240 |
} |
|
241 |
||
242 |
QTEST_MAIN(tst_MacGui) |
|
243 |
||
244 |
#else |
|
245 |
||
246 |
QTEST_NOOP_MAIN |
|
247 |
||
248 |
#endif |
|
249 |
||
250 |
#include "tst_macgui.moc" |
|
251 |