tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
--- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp	Fri Sep 17 08:34:18 2010 +0300
+++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp	Mon Oct 04 01:19:32 2010 +0300
@@ -43,9 +43,11 @@
 #include <QtDeclarative/qdeclarativeengine.h>
 #include <QtDeclarative/qdeclarativeview.h>
 #include <QtDeclarative/qdeclarativeitem.h>
+#include <QtDeclarative/qdeclarativecontext.h>
 #include <QtGui/qmenubar.h>
 #include "../../../shared/util.h"
 #include "qmlruntime.h"
+#include "deviceorientation.h"
 #include "../../../shared/util.h"
 
 #ifdef Q_OS_SYMBIAN
@@ -67,7 +69,7 @@
     tst_QDeclarativeViewer();
 
 private slots:
-    void orientation();
+    void runtimeContextProperty();
     void loading();
     void fileBrowser();
     void resizing();
@@ -94,7 +96,7 @@
     QCOMPARE(viewer->size(), viewer->sizeHint()); \
 }
 
-void tst_QDeclarativeViewer::orientation()
+void tst_QDeclarativeViewer::runtimeContextProperty()
 {
     QDeclarativeViewer *viewer = new QDeclarativeViewer();
     QVERIFY(viewer);
@@ -103,17 +105,30 @@
     QVERIFY(viewer->menuBar());
     QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject());
     QVERIFY(rootItem);
+    QObject *runtimeObject = qvariant_cast<QObject*>(viewer->view()->engine()->rootContext()->contextProperty("runtime"));
+    QVERIFY(runtimeObject);
+    
+    // test isActiveWindow property
+    QVERIFY(!runtimeObject->property("isActiveWindow").toBool());
+    
     viewer->show();
-
     QApplication::setActiveWindow(viewer);
     QTest::qWaitForWindowShown(viewer);
     QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer));
 
+    QVERIFY(runtimeObject->property("isActiveWindow").toBool());
+    
     TEST_INITIAL_SIZES(viewer);
 
+    // test orientation property
+    QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::Portrait));
+
     viewer->rotateOrientation();
     qApp->processEvents();
 
+    QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::Landscape));
+    QCOMPARE(rootItem->width(), 300.0);
+
     QCOMPARE(rootItem->width(), 300.0);
     QCOMPARE(rootItem->height(), 200.0);
     QTRY_COMPARE(viewer->view()->size(), QSize(300, 200));
@@ -124,6 +139,8 @@
     viewer->rotateOrientation();
     qApp->processEvents();
 
+    QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::PortraitInverted));
+
     QCOMPARE(rootItem->width(), 200.0);
     QCOMPARE(rootItem->height(), 300.0);
     QTRY_COMPARE(viewer->view()->size(), QSize(200, 300));
@@ -131,6 +148,19 @@
     QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer)));
     QCOMPARE(viewer->size(), viewer->sizeHint());
 
+    viewer->rotateOrientation();
+    qApp->processEvents();
+
+    QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::LandscapeInverted));
+
+    viewer->rotateOrientation();
+    qApp->processEvents();
+
+    QCOMPARE(runtimeObject->property("orientation").toInt(), int(DeviceOrientation::Portrait));
+
+    viewer->hide();
+    QVERIFY(!runtimeObject->property("isActiveWindow").toBool());
+
     delete viewer;
 }