tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
--- a/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp	Fri Sep 17 08:34:18 2010 +0300
+++ b/tests/auto/declarative/qdeclarativefocusscope/tst_qdeclarativefocusscope.cpp	Mon Oct 04 01:19:32 2010 +0300
@@ -69,6 +69,7 @@
     void textEdit();
     void forceFocus();
     void noParentFocus();
+    void signalEmission();
 };
 
 /*
@@ -335,7 +336,7 @@
     view->setSource(QUrl::fromLocalFile(SRCDIR "/data/chain.qml"));
     QVERIFY(view->rootObject());
 
-    QVERIFY(view->rootObject()->property("focus1") == true);
+    QVERIFY(view->rootObject()->property("focus1") == false);
     QVERIFY(view->rootObject()->property("focus2") == false);
     QVERIFY(view->rootObject()->property("focus3") == true);
     QVERIFY(view->rootObject()->property("focus4") == true);
@@ -344,6 +345,61 @@
     delete view;
 }
 
+void tst_qdeclarativefocusscope::signalEmission()
+{
+    QDeclarativeView *view = new QDeclarativeView;
+    view->setSource(QUrl::fromLocalFile(SRCDIR "/data/signalEmission.qml"));
+
+    QDeclarativeRectangle *item1 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item1"));
+    QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2"));
+    QDeclarativeRectangle *item3 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item3"));
+    QDeclarativeRectangle *item4 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item4"));
+    QVERIFY(item1 != 0);
+    QVERIFY(item2 != 0);
+    QVERIFY(item3 != 0);
+    QVERIFY(item4 != 0);
+
+    view->show();
+    qApp->setActiveWindow(view);
+    qApp->processEvents();
+
+#ifdef Q_WS_X11
+    // to be safe and avoid failing setFocus with window managers
+    qt_x11_wait_for_window_manager(view);
+#endif
+
+    QVariant blue(QColor("blue"));
+    QVariant red(QColor("red"));
+
+    QVERIFY(view->hasFocus());
+    QVERIFY(view->scene()->hasFocus());
+    item1->setFocus(true);
+    QCOMPARE(item1->property("color"), red);
+    QCOMPARE(item2->property("color"), blue);
+    QCOMPARE(item3->property("color"), blue);
+    QCOMPARE(item4->property("color"), blue);
+
+    item2->setFocus(true);
+    QCOMPARE(item1->property("color"), blue);
+    QCOMPARE(item2->property("color"), red);
+    QCOMPARE(item3->property("color"), blue);
+    QCOMPARE(item4->property("color"), blue);
+
+    item3->setFocus(true);
+    QCOMPARE(item1->property("color"), blue);
+    QCOMPARE(item2->property("color"), red);
+    QCOMPARE(item3->property("color"), red);
+    QCOMPARE(item4->property("color"), blue);
+
+    item4->setFocus(true);
+    QCOMPARE(item1->property("color"), blue);
+    QCOMPARE(item2->property("color"), red);
+    QCOMPARE(item3->property("color"), blue);
+    QCOMPARE(item4->property("color"), red);
+
+    delete view;
+}
+
 QTEST_MAIN(tst_qdeclarativefocusscope)
 
 #include "tst_qdeclarativefocusscope.moc"