diff options
author | Liang Qi <liang.qi@digia.com> | 2013-04-12 19:24:59 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-15 19:03:00 +0200 |
commit | a80b36edbe963495bca270a178237bc91772eed4 (patch) | |
tree | 85f9d67294c5ee7f3f9e03abb666159689a731f2 /tests/auto/applicationwindow | |
parent | 2d4ec664426004bab4e40e89038f3c9f835c93e7 (diff) | |
download | qtquickcontrols-a80b36edbe963495bca270a178237bc91772eed4.tar.gz |
Fix the behavior for activeFocusOnTab in ApplicationWindow
Autotests are included.
Change-Id: Ib86919c5eb768534392ba78d18e8f4d1ddac03d3
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'tests/auto/applicationwindow')
-rw-r--r-- | tests/auto/applicationwindow/data/activefocusontab.qml | 82 | ||||
-rw-r--r-- | tests/auto/applicationwindow/tst_applicationwindow.cpp | 109 |
2 files changed, 191 insertions, 0 deletions
diff --git a/tests/auto/applicationwindow/data/activefocusontab.qml b/tests/auto/applicationwindow/data/activefocusontab.qml new file mode 100644 index 00000000..4ca3a250 --- /dev/null +++ b/tests/auto/applicationwindow/data/activefocusontab.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.1 +import QtQuick.Controls 1.0 + +ApplicationWindow { + title: "Test Application Window" + width: 100 + height: 100 + Item { + id: main + objectName: "main" + width: 100 + height: 100 + //focus: true + Column { + anchors.fill: parent + id: column + objectName: "column" + Item { + id: sub1 + objectName: "sub1" + activeFocusOnTab: true + width: 100 + height: 50 + Rectangle { + anchors.fill: parent + color: parent.activeFocus ? "red" : "black" + } + } + Item { + id: sub2 + objectName: "sub2" + activeFocusOnTab: true + width: 100 + height: 50 + Rectangle { + anchors.fill: parent + color: parent.activeFocus ? "red" : "black" + } + } + } + } +} diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp index cc81dbe5..53f603c2 100644 --- a/tests/auto/applicationwindow/tst_applicationwindow.cpp +++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp @@ -47,6 +47,9 @@ #include <QtQuick/qquickview.h> #include <QtQuick/private/qquickitem_p.h> #include "../shared/util.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickVisualTestUtil; class tst_applicationwindow : public QQmlDataTest { @@ -55,6 +58,8 @@ public: private slots: void qmlCreation(); + void activeFocusOnTab1(); + void activeFocusOnTab2(); }; void tst_applicationwindow::qmlCreation() @@ -82,6 +87,110 @@ void tst_applicationwindow::qmlCreation() QVERIFY(!toolBar); } +void tst_applicationwindow::activeFocusOnTab1() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("activefocusontab.qml")); + QObject* created = component.create(); + QScopedPointer<QObject> cleanup(created); + QVERIFY(created); + + QQuickWindow* window = qobject_cast<QQuickWindow*>(created); + QVERIFY(window); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + + QQuickItem* contentItem = window->contentItem(); + QVERIFY(contentItem); + QVERIFY(contentItem->hasActiveFocus()); + + QQuickItem* item = findItem<QQuickItem>(window->contentItem(), "sub1"); + QVERIFY(item); + QVERIFY(!item->hasActiveFocus()); + + // Tab: contentItem->sub1 + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem<QQuickItem>(window->contentItem(), "sub1"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + // Tab: sub1->sub2 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem<QQuickItem>(window->contentItem(), "sub2"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + // Tab: sub2->sub1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem<QQuickItem>(window->contentItem(), "sub1"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); +} + +void tst_applicationwindow::activeFocusOnTab2() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("activefocusontab.qml")); + QObject* created = component.create(); + QScopedPointer<QObject> cleanup(created); + QVERIFY(created); + + QQuickWindow* window = qobject_cast<QQuickWindow*>(created); + QVERIFY(window); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + + QQuickItem* contentItem = window->contentItem(); + QVERIFY(contentItem); + QVERIFY(contentItem->hasActiveFocus()); + + QQuickItem* item = findItem<QQuickItem>(window->contentItem(), "sub2"); + QVERIFY(item); + QVERIFY(!item->hasActiveFocus()); + + // BackTab: contentItem->sub2 + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem<QQuickItem>(window->contentItem(), "sub2"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + // BackTab: sub2->sub1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem<QQuickItem>(window->contentItem(), "sub1"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + // BackTab: sub1->sub2 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem<QQuickItem>(window->contentItem(), "sub2"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); +} + QTEST_MAIN(tst_applicationwindow) #include "tst_applicationwindow.moc" |