41 |
41 |
42 #include <qtest.h> |
42 #include <qtest.h> |
43 #include <QtDeclarative/qdeclarativeengine.h> |
43 #include <QtDeclarative/qdeclarativeengine.h> |
44 #include <QtDeclarative/qdeclarativeview.h> |
44 #include <QtDeclarative/qdeclarativeview.h> |
45 #include <QtDeclarative/qdeclarativeitem.h> |
45 #include <QtDeclarative/qdeclarativeitem.h> |
|
46 #include <QtDeclarative/qdeclarativecontext.h> |
46 #include <QtGui/qmenubar.h> |
47 #include <QtGui/qmenubar.h> |
47 #include "../../../shared/util.h" |
48 #include "../../../shared/util.h" |
48 #include "qmlruntime.h" |
49 #include "qmlruntime.h" |
|
50 #include "deviceorientation.h" |
49 #include "../../../shared/util.h" |
51 #include "../../../shared/util.h" |
50 |
52 |
51 #ifdef Q_OS_SYMBIAN |
53 #ifdef Q_OS_SYMBIAN |
52 // In Symbian OS test data is located in applications private dir |
54 // In Symbian OS test data is located in applications private dir |
53 #define SRCDIR "." |
55 #define SRCDIR "." |
92 QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); \ |
94 QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); \ |
93 QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); \ |
95 QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); \ |
94 QCOMPARE(viewer->size(), viewer->sizeHint()); \ |
96 QCOMPARE(viewer->size(), viewer->sizeHint()); \ |
95 } |
97 } |
96 |
98 |
97 void tst_QDeclarativeViewer::orientation() |
99 void tst_QDeclarativeViewer::runtimeContextProperty() |
98 { |
100 { |
99 QDeclarativeViewer *viewer = new QDeclarativeViewer(); |
101 QDeclarativeViewer *viewer = new QDeclarativeViewer(); |
100 QVERIFY(viewer); |
102 QVERIFY(viewer); |
101 viewer->open(SRCDIR "/data/orientation.qml"); |
103 viewer->open(SRCDIR "/data/orientation.qml"); |
102 QVERIFY(viewer->view()); |
104 QVERIFY(viewer->view()); |
103 QVERIFY(viewer->menuBar()); |
105 QVERIFY(viewer->menuBar()); |
104 QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); |
106 QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); |
105 QVERIFY(rootItem); |
107 QVERIFY(rootItem); |
|
108 QObject *runtimeObject = qvariant_cast<QObject*>(viewer->view()->engine()->rootContext()->contextProperty("runtime")); |
|
109 QVERIFY(runtimeObject); |
|
110 |
|
111 // test isActiveWindow property |
|
112 QVERIFY(!runtimeObject->property("isActiveWindow").toBool()); |
|
113 |
106 viewer->show(); |
114 viewer->show(); |
107 |
|
108 QApplication::setActiveWindow(viewer); |
115 QApplication::setActiveWindow(viewer); |
109 QTest::qWaitForWindowShown(viewer); |
116 QTest::qWaitForWindowShown(viewer); |
110 QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); |
117 QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); |
111 |
118 |
|
119 QVERIFY(runtimeObject->property("isActiveWindow").toBool()); |
|
120 |
112 TEST_INITIAL_SIZES(viewer); |
121 TEST_INITIAL_SIZES(viewer); |
113 |
122 |
|
123 // test orientation property |
|
124 QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::Portrait)); |
|
125 |
114 viewer->rotateOrientation(); |
126 viewer->rotateOrientation(); |
115 qApp->processEvents(); |
127 qApp->processEvents(); |
|
128 |
|
129 QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::Landscape)); |
|
130 QCOMPARE(rootItem->width(), 300.0); |
116 |
131 |
117 QCOMPARE(rootItem->width(), 300.0); |
132 QCOMPARE(rootItem->width(), 300.0); |
118 QCOMPARE(rootItem->height(), 200.0); |
133 QCOMPARE(rootItem->height(), 200.0); |
119 QTRY_COMPARE(viewer->view()->size(), QSize(300, 200)); |
134 QTRY_COMPARE(viewer->view()->size(), QSize(300, 200)); |
120 QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(300, 200)); |
135 QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(300, 200)); |
122 QCOMPARE(viewer->size(), viewer->sizeHint()); |
137 QCOMPARE(viewer->size(), viewer->sizeHint()); |
123 |
138 |
124 viewer->rotateOrientation(); |
139 viewer->rotateOrientation(); |
125 qApp->processEvents(); |
140 qApp->processEvents(); |
126 |
141 |
|
142 QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::PortraitInverted)); |
|
143 |
127 QCOMPARE(rootItem->width(), 200.0); |
144 QCOMPARE(rootItem->width(), 200.0); |
128 QCOMPARE(rootItem->height(), 300.0); |
145 QCOMPARE(rootItem->height(), 300.0); |
129 QTRY_COMPARE(viewer->view()->size(), QSize(200, 300)); |
146 QTRY_COMPARE(viewer->view()->size(), QSize(200, 300)); |
130 QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); |
147 QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); |
131 QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); |
148 QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); |
132 QCOMPARE(viewer->size(), viewer->sizeHint()); |
149 QCOMPARE(viewer->size(), viewer->sizeHint()); |
133 |
150 |
|
151 viewer->rotateOrientation(); |
|
152 qApp->processEvents(); |
|
153 |
|
154 QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::LandscapeInverted)); |
|
155 |
|
156 viewer->rotateOrientation(); |
|
157 qApp->processEvents(); |
|
158 |
|
159 QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::Portrait)); |
|
160 |
|
161 viewer->hide(); |
|
162 QVERIFY(!runtimeObject->property("isActiveWindow").toBool()); |
|
163 |
134 delete viewer; |
164 delete viewer; |
135 } |
165 } |
136 |
166 |
137 void tst_QDeclarativeViewer::loading() |
167 void tst_QDeclarativeViewer::loading() |
138 { |
168 { |