e5fcad3 by Lars Knoll at 2009-03-23 1
/****************************************************************************
2
**
89c08c0 by Jason McDonald at 2012-01-11 3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
04e3b30 by Jason McDonald at 2009-09-09 4
** All rights reserved.
858c70f by Jason McDonald at 2009-06-16 5
** Contact: Nokia Corporation (qt-info@nokia.com)
e5fcad3 by Lars Knoll at 2009-03-23 6
**
7
** This file is part of the test suite of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
1eea52e by Jyri Tahtela at 2011-05-13 11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
e5fcad3 by Lars Knoll at 2009-03-23 17
**
04e3b30 by Jason McDonald at 2009-09-09 18
** In addition, as a special exception, Nokia gives you certain additional
1eea52e by Jyri Tahtela at 2011-05-13 19
** rights. These rights are described in the Nokia Qt LGPL Exception
04e3b30 by Jason McDonald at 2009-09-09 20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
e5fcad3 by Lars Knoll at 2009-03-23 21
**
1eea52e by Jyri Tahtela at 2011-05-13 22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
309db73 by Jason McDonald at 2009-08-31 29
**
1eea52e by Jyri Tahtela at 2011-05-13 30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
309db73 by Jason McDonald at 2009-08-31 33
**
34
**
35
**
36
**
e5fcad3 by Lars Knoll at 2009-03-23 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
56b3499 by Rohan McGovern at 2009-08-06 55
class tst_MacGui : public GuiTester
e5fcad3 by Lars Knoll at 2009-03-23 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
{
41ba7d4 by Norwegian Rock Cat at 2009-05-19 71
    return QPixmap::grabWindow(widget->winId());
e5fcad3 by Lars Knoll at 2009-03-23 72
}
73
74
/*
75
    Test that vertical and horizontal mac-style scrollbars paint their
76
    entire area.
77
*/
56b3499 by Rohan McGovern at 2009-08-06 78
void tst_MacGui::scrollbarPainting()
e5fcad3 by Lars Knoll at 2009-03-23 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.
56b3499 by Rohan McGovern at 2009-08-06 110
void tst_MacGui::dummy()
e5fcad3 by Lars Knoll at 2009-03-23 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
*/
56b3499 by Rohan McGovern at 2009-08-06 135
void tst_MacGui::splashScreenModality()
e5fcad3 by Lars Knoll at 2009-03-23 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
*/
56b3499 by Rohan McGovern at 2009-08-06 198
void tst_MacGui::nonModalOrder()
e5fcad3 by Lars Knoll at 2009-03-23 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
*/
56b3499 by Rohan McGovern at 2009-08-06 211
void tst_MacGui::spinBoxArrowButtons()
e5fcad3 by Lars Knoll at 2009-03-23 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
56b3499 by Rohan McGovern at 2009-08-06 242
QTEST_MAIN(tst_MacGui)
e5fcad3 by Lars Knoll at 2009-03-23 243
244
#else
245
246
QTEST_NOOP_MAIN
247
248
#endif
249
56b3499 by Rohan McGovern at 2009-08-06 250
#include "tst_macgui.moc"
251