From 39124d8f0ed22f181d8697fb28d9f3a98db76334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= Date: Sat, 23 Apr 2016 17:43:35 +0200 Subject: [PATCH] Make window active before running a focus test Make sure the window is active before checking for a widget focus. This does not really affect CI, but when running tests locally, the WM may cause the test window to not be active making focus tests fail. --- .../messageviewerplugins/autotests/eventedittest.cpp | 10 ++++++++++ .../messageviewerplugins/autotests/noteedittest.cpp | 4 ++++ .../messageviewerplugins/autotests/todoedittest.cpp | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/plugins/messageviewerplugins/autotests/eventedittest.cpp b/plugins/messageviewerplugins/autotests/eventedittest.cpp index be611f17..e6f4a38a 100644 --- a/plugins/messageviewerplugins/autotests/eventedittest.cpp +++ b/plugins/messageviewerplugins/autotests/eventedittest.cpp @@ -142,6 +142,12 @@ void EventEditTest::shouldNotEmitWhenMessageIsNotChanged() void EventEditTest::shouldEmitEventWhenPressEnter() { MessageViewer::EventEdit edit; + edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); + QTest::qWaitForWindowExposed(&edit); + QVERIFY(edit.isVisible()); + KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); msg->subject(true)->fromUnicodeString(subject, "us-ascii"); @@ -173,6 +179,8 @@ void EventEditTest::shouldHideWidgetWhenPressEscape() { MessageViewer::EventEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); QLineEdit *eventedit = edit.findChild(QStringLiteral("eventedit")); eventedit->setFocus(); @@ -317,6 +325,8 @@ void EventEditTest::shouldSetFocusWhenWeCallTodoEdit() { MessageViewer::EventEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); QLineEdit *noteedit = edit.findChild(QStringLiteral("eventedit")); QVERIFY(noteedit); diff --git a/plugins/messageviewerplugins/autotests/noteedittest.cpp b/plugins/messageviewerplugins/autotests/noteedittest.cpp index 73e0a703..eef040fa 100644 --- a/plugins/messageviewerplugins/autotests/noteedittest.cpp +++ b/plugins/messageviewerplugins/autotests/noteedittest.cpp @@ -303,6 +303,8 @@ void NoteEditTest::shouldHideWidgetWhenPressEscape() { MessageViewer::NoteEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setFocus(); @@ -360,6 +362,8 @@ void NoteEditTest::shouldSetFocusWhenWeCallNoteEdit() { MessageViewer::NoteEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); diff --git a/plugins/messageviewerplugins/autotests/todoedittest.cpp b/plugins/messageviewerplugins/autotests/todoedittest.cpp index 9fcd9685..4121d845 100644 --- a/plugins/messageviewerplugins/autotests/todoedittest.cpp +++ b/plugins/messageviewerplugins/autotests/todoedittest.cpp @@ -253,6 +253,7 @@ void TodoEditTest::shouldClearAllWhenCloseWidget() { MessageViewer::TodoEdit edit; edit.show(); + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); KMime::Message::Ptr msg(new KMime::Message); @@ -310,6 +311,8 @@ void TodoEditTest::shouldHideWidgetWhenPressEscape() { MessageViewer::TodoEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); QLineEdit *noteedit = edit.findChild(QStringLiteral("noteedit")); noteedit->setFocus(); @@ -367,6 +370,8 @@ void TodoEditTest::shouldSetFocusWhenWeCallTodoEdit() { MessageViewer::TodoEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); @@ -407,6 +412,8 @@ void TodoEditTest::shouldHaveLineEditFocus() { MessageViewer::TodoEdit edit; edit.show(); + // make sure the window is active so we can test for focus + qApp->setActiveWindow(&edit); QTest::qWaitForWindowExposed(&edit); KMime::Message::Ptr msg(new KMime::Message); QString subject = QStringLiteral("Test Note"); -- GitLab