From a80b36edbe963495bca270a178237bc91772eed4 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 12 Apr 2013 19:24:59 +0200 Subject: Fix the behavior for activeFocusOnTab in ApplicationWindow Autotests are included. Change-Id: Ib86919c5eb768534392ba78d18e8f4d1ddac03d3 Reviewed-by: Alan Alpert Reviewed-by: Jens Bache-Wiig --- .../applicationwindow/data/activefocusontab.qml | 82 ++++++++++++++++ .../applicationwindow/tst_applicationwindow.cpp | 109 +++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 tests/auto/applicationwindow/data/activefocusontab.qml (limited to 'tests/auto/applicationwindow') 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 #include #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 cleanup(created); + QVERIFY(created); + + QQuickWindow* window = qobject_cast(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(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(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(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(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 cleanup(created); + QVERIFY(created); + + QQuickWindow* window = qobject_cast(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(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(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(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(window->contentItem(), "sub2"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); +} + QTEST_MAIN(tst_applicationwindow) #include "tst_applicationwindow.moc" -- cgit v1.2.1