From e3378e1968d7740eb077562bea251759adf1d97e Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 8 Nov 2016 16:18:15 +0100 Subject: Wait for focus before key press in NewViewRequest::test_jsWindowOpen This patch is intended to fix flaky failure and factors focus related test functions out to TestWebEngineView. Task-number: QTBUG-56540 Change-Id: Id7e17c08a4a9e863389ae991c9cadc00379377db Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qmltests/BLACKLIST | 3 --- .../auto/quick/qmltests/data/TestWebEngineView.qml | 22 +++++++++++++++++++++- .../quick/qmltests/data/tst_focusOnNavigation.qml | 22 +--------------------- .../quick/qmltests/data/tst_keyboardEvents.qml | 20 -------------------- .../quick/qmltests/data/tst_newViewRequest.qml | 1 + 5 files changed, 23 insertions(+), 45 deletions(-) diff --git a/tests/auto/quick/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST index dea9f3ca1..035e49a83 100644 --- a/tests/auto/quick/qmltests/BLACKLIST +++ b/tests/auto/quick/qmltests/BLACKLIST @@ -1,9 +1,6 @@ [DesktopWebEngineViewLinkHovered::test_linkHovered] * -[NewViewRequest::test_jsWindowOpen] -* - [WebViewGeopermission::test_deniedGeolocationByUser] osx diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml index 0d2a34645..aa1f77942 100644 --- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml +++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml @@ -27,7 +27,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtTest 1.0 +import QtTest 1.1 import QtWebEngine 1.3 WebEngineView { @@ -62,7 +62,27 @@ WebEngineView { return predicate() } + function getActiveElementId() { + var activeElementId; + runJavaScript("document.activeElement.id", function(result) { + activeElementId = result; + }); + testCase.tryVerify(function() { return activeElementId != undefined }); + return activeElementId; + } + + function verifyElementHasFocus(element) { + testCase.tryVerify(function() { return getActiveElementId() == element; }, 5000, + "Element \"" + element + "\" has focus"); + } + + function setFocusToElement(element) { + runJavaScript("document.getElementById('" + element + "').focus()"); + verifyElementHasFocus(element); + } + TestResult { id: testResult } + TestCase { id: testCase } onLoadingChanged: { loadStatus = loadRequest.status diff --git a/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml b/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml index 15ec320a4..93410a727 100644 --- a/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml +++ b/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml @@ -77,29 +77,9 @@ Item { ] } - function getActiveElementId() { - var activeElementId; - webView.runJavaScript("document.activeElement.id", function(result) { - activeElementId = result; - }); - tryVerify(function() { return activeElementId != undefined }); - return activeElementId; - } - - function verifyElementHasFocus(element) { - tryVerify(function() { return getActiveElementId() == element; }, 5000, - "Element \"" + element + "\" has focus"); - - } - - function setFocusToElement(element) { - webView.runJavaScript("document.getElementById('" + element + "').focus()"); - verifyElementHasFocus(element); - } - function loadAndTriggerFocusAndCompare(data) { verify(webView.waitForLoadSucceeded()); - setFocusToElement("input"); + webView.setFocusToElement("input"); compare(webView.activeFocus, data.viewReceivedFocus); } diff --git a/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml b/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml index 7007a85ac..677727632 100644 --- a/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml +++ b/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml @@ -39,26 +39,6 @@ TestWebEngineView { name: "WebEngineViewKeyboardEvents" when: windowShown - function getActiveElementId() { - var activeElementId; - runJavaScript("document.activeElement.id", function(result) { - activeElementId = result; - }); - tryVerify(function() { return activeElementId != undefined }); - return activeElementId; - } - - function verifyElementHasFocus(element) { - tryVerify(function() { return getActiveElementId() == element; }, 5000, - "Element \"" + element + "\" has focus"); - - } - - function setFocusToElement(element) { - runJavaScript("document.getElementById('" + element + "').focus()"); - verifyElementHasFocus(element); - } - function isElementChecked(element) { var elementChecked; runJavaScript("document.getElementById('" + element + "').checked", function(result) { diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml index be56f3251..754a9e018 100644 --- a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml +++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml @@ -122,6 +122,7 @@ TestWebEngineView { " " + ""); verify(webEngineView.waitForLoadSucceeded()); + verifyElementHasFocus("popupButton"); keyPress(Qt.Key_Enter); tryCompare(newViewRequestedSpy, "count", 1); -- cgit v1.2.3