diff options
Diffstat (limited to 'tests/auto/quick/qmltests/data')
15 files changed, 687 insertions, 191 deletions
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/favicon-candidates-gray.html b/tests/auto/quick/qmltests/data/favicon-candidates-gray.html index 3cbc4a4c3..ebea35b02 100644 --- a/tests/auto/quick/qmltests/data/favicon-candidates-gray.html +++ b/tests/auto/quick/qmltests/data/favicon-candidates-gray.html @@ -11,11 +11,11 @@ <h1>Gray Candidate Favicons Test</h1> <table style="width:100%"> <tr> - <td align="center"><img src="icons/gray16.png" height="16" width="16" /></td> - <td align="center"><img src="icons/gray32.png" height="32" width="32" /></td> - <td align="center"><img src="icons/gray64.png" height="64" width="64" /></td> - <td align="center"><img src="icons/gray128.png" height="128" width="128" /></td> - <td align="center"><img src="icons/gray255.png" height="255" width="255" /></td> + <td align="center"><img src="icons/gray16.png" height="16" width="16" border="1" /></td> + <td align="center"><img src="icons/gray32.png" height="32" width="32" border="1" /></td> + <td align="center"><img src="icons/gray64.png" height="64" width="64" border="1" /></td> + <td align="center"><img src="icons/gray128.png" height="128" width="128" border="1" /></td> + <td align="center"><img src="icons/gray255.png" height="255" width="255" border="1" /></td> </tr> <tr> <td align="center">16x16</td> diff --git a/tests/auto/quick/qmltests/data/favicon-multi-gray.html b/tests/auto/quick/qmltests/data/favicon-multi-gray.html index 9b9b7432d..24b71640f 100644 --- a/tests/auto/quick/qmltests/data/favicon-multi-gray.html +++ b/tests/auto/quick/qmltests/data/favicon-multi-gray.html @@ -7,11 +7,11 @@ <h1>Gray Multi-sized Favicon Test</h1> <table style="width:100%"> <tr> - <td align="center"><img src="icons/gray16.png" height="16" width="16" /></td> - <td align="center"><img src="icons/gray32.png" height="32" width="32" /></td> - <td align="center"><img src="icons/gray64.png" height="64" width="64" /></td> - <td align="center"><img src="icons/gray128.png" height="128" width="128" /></td> - <td align="center"><img src="icons/gray255.png" height="255" width="255" /></td> + <td align="center"><img src="icons/gray16.png" height="16" width="16" border="1" /></td> + <td align="center"><img src="icons/gray32.png" height="32" width="32" border="1" /></td> + <td align="center"><img src="icons/gray64.png" height="64" width="64" border="1" /></td> + <td align="center"><img src="icons/gray128.png" height="128" width="128" border="1" /></td> + <td align="center"><img src="icons/gray255.png" height="255" width="255" border="1" /></td> </tr> <tr> <td align="center">16x16</td> diff --git a/tests/auto/quick/qmltests/data/keyboardEvents.html b/tests/auto/quick/qmltests/data/keyboardEvents.html new file mode 100644 index 000000000..d536d849f --- /dev/null +++ b/tests/auto/quick/qmltests/data/keyboardEvents.html @@ -0,0 +1,98 @@ +<html> +<head> + <style> + div { + width: 300px; + margin-bottom: 10px; + } + + #div_container { + display: inline-block; + } + + #div_container div { + width: 100px; + height: 100px; + border: 2px solid black; + padding: 10px; + margin: 0 10px 0 10px; + float: left; + } + + #div_container div:focus { + border: 2px solid red; + } + + #form_container span { + display: block; + padding-bottom: 10px; + } + + #form_container label { + float: left; + text-align: right; + width: 50px; + margin-right: 20px; + } + </style> +</head> + +<body onload="document.getElementById('first_div').focus()"> + <div id="div_container"> + <div id="first_div" tabindex="0">First</div> + <div id="second_div" tabindex="0">Second</div> + </div> + + <div id="form_container"> + <form><fieldset> + <legend>Form</legend> + + <span> + <label for="text_input">text</label> + <input id="text_input" type="text" /> + </span> + + <span> + <input id="radio1" type="radio" name="radio">radio1</input> + <input id="radio2" type="radio" name="radio">radio2</input> + </span> + + <span> + <input id="checkbox1" type="checkbox" name="checkbox1" checked="true">checkbox1</input> + <input id="checkbox2" type="checkbox" name="checkbox2" checked="true">checkbox2</input> + </span> + + <span> + <label for="number_input">number</label> + <input id="number_input" type="number" min="0" max="10" value="5" /> + </span> + + <span> + <label for="range_input">range</label> + <input id="range_input" type="range" min="0" max="10" value="5" /> + </span> + + <span> + <label for="search_input">search</label> + <input id="search_input" type="search" value="test" /> + </span> + + <input id="submit_button" type="submit" value="Submit" /> + </fieldset></form> + </div> + + <div> + <select id="combobox"> + <option value="a">a</option> + <option value="b">b</option> + <option value="c">c</option> + </select> + </div> + + <div> + <a id="first_hyperlink" href="">First</a> + <br /> + <a id="second_hyperlink" href="">Second</a> + </div> +</body> +</html> diff --git a/tests/auto/quick/qmltests/data/redirect.html b/tests/auto/quick/qmltests/data/redirect.html index 914e5e35a..44eb6cd28 100644 --- a/tests/auto/quick/qmltests/data/redirect.html +++ b/tests/auto/quick/qmltests/data/redirect.html @@ -1,8 +1,9 @@ <!doctype html> <html> <head> -<meta http-equiv="refresh" content="2; url=test1.html" + <meta http-equiv="refresh" content="2; url=test1.html"> </head> <body> + Redirecting to test1.html </body> </html> diff --git a/tests/auto/quick/qmltests/data/tst_findText.qml b/tests/auto/quick/qmltests/data/tst_findText.qml index 904a8feb2..4761513c1 100644 --- a/tests/auto/quick/qmltests/data/tst_findText.qml +++ b/tests/auto/quick/qmltests/data/tst_findText.qml @@ -107,5 +107,24 @@ TestWebEngineView { tryCompare(webEngineView, "matchCount", 0) verify(findFailed) } + + function test_findTextAfterNotFound() { + var findFlags = 0 + webEngineView.url = Qt.resolvedUrl("about:blank") + verify(webEngineView.waitForLoadSucceeded()) + + webEngineView.clear() + webEngineView.findText("hello", findFlags, webEngineView.findTextCallback) + tryCompare(webEngineView, "matchCount", 0) + verify(findFailed) + + webEngineView.url = Qt.resolvedUrl("test1.html") + verify(webEngineView.waitForLoadSucceeded()) + + webEngineView.clear() + webEngineView.findText("hello", findFlags, webEngineView.findTextCallback) + tryCompare(webEngineView, "matchCount", 1) + verify(!findFailed) + } } } diff --git a/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml b/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml index ce0fa2e31..93410a727 100644 --- a/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml +++ b/tests/auto/quick/qmltests/data/tst_focusOnNavigation.qml @@ -67,8 +67,6 @@ Item { TestCase { name: "WebEngineViewFocusOnNavigation" when: windowShown - function init() { - } function test_focusOnNavigation_data() { return [ @@ -79,18 +77,9 @@ Item { ] } - function triggerJavascriptFocus() { - var callbackCalled = false; - webView.runJavaScript("document.getElementById(\"input\").focus()", function(result) { - callbackCalled = true; - }); - wait(100); - verify(callbackCalled); - } - function loadAndTriggerFocusAndCompare(data) { verify(webView.waitForLoadSucceeded()); - triggerJavascriptFocus(); + 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 new file mode 100644 index 000000000..677727632 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_keyboardEvents.qml @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtWebEngine 1.4 + +TestWebEngineView { + id: webEngineView + width: 350 + height: 480 + + TestCase { + name: "WebEngineViewKeyboardEvents" + when: windowShown + + function isElementChecked(element) { + var elementChecked; + runJavaScript("document.getElementById('" + element + "').checked", function(result) { + elementChecked = result; + }); + tryVerify(function() { return elementChecked != undefined; }); + return elementChecked; + } + + function verifyElementChecked(element, expected) { + tryVerify(function() { return expected == isElementChecked(element); }, 5000, + "Element \"" + element + "\" is " + (expected ? "" : "not") + " checked"); + } + + function getElementValue(element) { + var elementValue; + runJavaScript("document.getElementById('" + element + "').value", function(result) { + elementValue = result; + }); + tryVerify(function() { return elementValue != undefined; }); + return elementValue; + } + + function compareElementValue(element, expected) { + tryVerify(function() { return expected == getElementValue(element); }, 5000, + "Value of element \"" + element + "\" is \"" + expected + "\""); + } + + function test_keyboardEvents() { + webEngineView.url = Qt.resolvedUrl("keyboardEvents.html"); + verify(webEngineView.waitForLoadSucceeded()); + + var elements = [ + "first_div", "second_div", + "text_input", "radio1", "checkbox1", "checkbox2", + "number_input", "range_input", "search_input", + "submit_button", "combobox", "first_hyperlink", "second_hyperlink" + ]; + + // Iterate over the elements of the test page with the Tab key. This tests whether any + // element blocks the in-page navigation by Tab. + for (var i = 0; i < elements.length; ++i) { + verifyElementHasFocus(elements[i]) + keyPress(Qt.Key_Tab); + } + + // Move back to the radio buttons with the Shift+Tab key combination + for (var i = 0; i < 10; ++i) + keyPress(Qt.Key_Tab, Qt.ShiftModifier); + verifyElementHasFocus("radio2"); + + // Test the Space key by checking a radio button + verifyElementChecked("radio2", false); + keyClick(Qt.Key_Space); + verifyElementChecked("radio2", true); + + // Test the Left key by switching the radio button + verifyElementChecked("radio1", false); + keyPress(Qt.Key_Left); + verifyElementHasFocus("radio1"); + verifyElementChecked("radio1", true); + + // Test the Space key by unchecking a checkbox + setFocusToElement("checkbox1"); + verifyElementChecked("checkbox1", true); + keyClick(Qt.Key_Space); + verifyElementChecked("checkbox1", false); + + // Test the Up and Down keys by changing the value of a spinbox + setFocusToElement("number_input"); + compareElementValue("number_input", 5); + keyPress(Qt.Key_Up); + compareElementValue("number_input", 6); + keyPress(Qt.Key_Down); + compareElementValue("number_input", 5); + + // Test the Left, Right, Home, PageUp, End and PageDown keys by changing the value of a slider + setFocusToElement("range_input"); + compareElementValue("range_input", 5); + keyPress(Qt.Key_Left); + compareElementValue("range_input", 4); + keyPress(Qt.Key_Right); + compareElementValue("range_input", 5); + keyPress(Qt.Key_Home); + compareElementValue("range_input", 0); + keyPress(Qt.Key_PageUp); + compareElementValue("range_input", 1); + keyPress(Qt.Key_End); + compareElementValue("range_input", 10); + keyPress(Qt.Key_PageDown); + compareElementValue("range_input", 9); + + // Test the Escape key by removing the content of a search field + setFocusToElement("search_input"); + compareElementValue("search_input", "test"); + keyPress(Qt.Key_Escape); + compareElementValue("search_input", ""); + + // Test the alpha keys by changing the values in a combobox + setFocusToElement("combobox"); + compareElementValue("combobox", "a"); + keyPress(Qt.Key_B); + compareElementValue("combobox", "b"); + // Must wait with the second key press to simulate selection of another element + wait(1000); + keyPress(Qt.Key_C); + compareElementValue("combobox", "c"); + + // Test the Enter key by loading a page with a hyperlink + setFocusToElement("first_hyperlink"); + keyPress(Qt.Key_Enter); + verify(webEngineView.waitForLoadSucceeded()); + } + } +} diff --git a/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml index ae60e5f5e..e0a8c0a41 100644 --- a/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml +++ b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml @@ -52,24 +52,26 @@ TestWebEngineView { onTriggered: parent.when = true } + function getPressedModifiers() { + var pressedModifiers; + runJavaScript("getPressedModifiers()", function(result) { + pressedModifiers = result; + }); + tryVerify(function() { return pressedModifiers != undefined }); + return pressedModifiers; + } + function test_keyboardModifierMapping() { webEngineView.url = Qt.resolvedUrl("keyboardModifierMapping.html") waitForLoadSucceeded(); titleSpy.wait() - var callbackCalled = false; // Alt keyPress(Qt.Key_Alt); titleSpy.wait() - runJavaScript("getPressedModifiers()", function(result) { - compare(result, "alt:pressed ctrl:no meta:no"); - callbackCalled = true; - }); - wait(100); - verify(callbackCalled); + compare(getPressedModifiers(), "alt:pressed ctrl:no meta:no"); keyRelease(Qt.Key_Alt) titleSpy.wait() - callbackCalled = false; // Ctrl // On mac Qt automatically translates Meta to Ctrl and vice versa. @@ -78,36 +80,18 @@ TestWebEngineView { // For testing we assume that the flag Qt::AA_MacDontSwapCtrlAndMeta is NOT set. keyPress(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control); titleSpy.wait() - runJavaScript("getPressedModifiers()", function(result) { - compare(result, "alt:released ctrl:pressed meta:no"); - callbackCalled = true; - }); - wait(100); - verify(callbackCalled); + compare(getPressedModifiers(), "alt:released ctrl:pressed meta:no"); keyRelease(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control); titleSpy.wait() - callbackCalled = false; // Meta (Command on Mac) keyPress(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta); titleSpy.wait() - runJavaScript("getPressedModifiers()", function(result) { - compare(result, "alt:released ctrl:released meta:pressed"); - callbackCalled = true; - }); - wait(100); - verify(callbackCalled); + compare(getPressedModifiers(), "alt:released ctrl:released meta:pressed"); keyRelease(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta); titleSpy.wait() - callbackCalled = false; - runJavaScript("getPressedModifiers()", function(result) { - compare(result, "alt:released ctrl:released meta:released"); - callbackCalled = true; - }); - wait(100); - verify(callbackCalled); - callbackCalled = false; + compare(getPressedModifiers(), "alt:released ctrl:released meta:released"); } } } diff --git a/tests/auto/quick/qmltests/data/tst_loadUrl.qml b/tests/auto/quick/qmltests/data/tst_loadUrl.qml index 3ce03df70..2a43e1577 100644 --- a/tests/auto/quick/qmltests/data/tst_loadUrl.qml +++ b/tests/auto/quick/qmltests/data/tst_loadUrl.qml @@ -35,152 +35,249 @@ TestWebEngineView { width: 400 height: 300 - property var lastUrl - property bool watchProgress: false - property int numLoadStarted: 0 - property int numLoadSucceeded: 0 + property var loadRequestArray: [] - focus: true - - onLoadProgressChanged: { - if (watchProgress && webEngineView.loadProgress != 100) { - watchProgress = false - url = '' - } + onLoadingChanged: { + loadRequestArray.push({ + "status": loadRequest.status, + "url": loadRequest.url, + "activeUrl": webEngineView.url + }); } - onLoadingChanged: { - if (loadRequest.status == WebEngineView.LoadStartedStatus) - ++numLoadStarted - if (loadRequest.status == WebEngineView.LoadSucceededStatus) - ++numLoadSucceeded + function clear() { + // Reset loadStatus for waitForLoadSucceded + webEngineView.loadStatus = null; + loadRequestArray = []; } TestCase { name: "WebEngineViewLoadUrl" when: windowShown + function init() { + webEngineView.clear(); + } + function test_loadIgnoreEmptyUrl() { - var url = Qt.resolvedUrl("test1.html") - - webEngineView.url = url - verify(webEngineView.waitForLoadSucceeded()) - compare(numLoadStarted, 1) - compare(numLoadSucceeded, 1) - compare(webEngineView.url, url) - - lastUrl = webEngineView.url - webEngineView.url = '' - wait(1000) - compare(numLoadStarted, 1) - compare(numLoadSucceeded, 1) - compare(webEngineView.url, lastUrl) - - webEngineView.url = 'about:blank' - verify(webEngineView.waitForLoadSucceeded()) - compare(numLoadStarted, 2) - compare(numLoadSucceeded, 2) - compare(webEngineView.url, 'about:blank') + var url = Qt.resolvedUrl("test1.html"); + webEngineView.url = url; + verify(webEngineView.waitForLoadSucceeded()); + compare(loadRequestArray[0].status, WebEngineView.LoadStartedStatus); + compare(loadRequestArray[1].status, WebEngineView.LoadSucceededStatus); + compare(loadRequestArray.length, 2); + compare(webEngineView.url, url); + webEngineView.clear(); + + var lastUrl = webEngineView.url; + webEngineView.url = ""; + wait(1000); + compare(loadRequestArray.length, 0); + compare(webEngineView.url, lastUrl); + webEngineView.clear(); + + var aboutBlank = "about:blank"; + webEngineView.url = aboutBlank; + verify(webEngineView.waitForLoadSucceeded()); + compare(loadRequestArray[0].status, WebEngineView.LoadStartedStatus); + compare(loadRequestArray[1].status, WebEngineView.LoadSucceededStatus); + compare(loadRequestArray.length, 2); + compare(webEngineView.url, aboutBlank); + webEngineView.clear(); // It shouldn't interrupt any ongoing load when an empty url is used. - watchProgress = true - webEngineView.url = url - webEngineView.waitForLoadSucceeded() - compare(numLoadStarted, 3) - compare(numLoadSucceeded, 3) - verify(!watchProgress) - compare(webEngineView.url, url) + var watchProgress = true; + var handleLoadProgress = function() { + if (webEngineView.loadProgress != 100) { + webEngineView.url = ""; + watchProgress = false; + } + } + webEngineView.loadProgressChanged.connect(handleLoadProgress); + webEngineView.url = url; + verify(webEngineView.waitForLoadSucceeded()); + compare(loadRequestArray[0].status, WebEngineView.LoadStartedStatus); + compare(loadRequestArray[1].status, WebEngineView.LoadSucceededStatus); + compare(loadRequestArray.length, 2); + verify(!watchProgress); + compare(webEngineView.url, url); + webEngineView.loadProgressChanged.disconnect(handleLoadProgress); + webEngineView.clear(); } function test_urlProperty() { - WebEngine.settings.errorPageEnabled = false + WebEngine.settings.errorPageEnabled = false; - var url = Qt.resolvedUrl("test1.html") + var loadRequest = null; - webEngineView.url = url - compare(webEngineView.url, url) - verify(webEngineView.waitForLoadSucceeded()) - compare(webEngineView.url, url) + // Test succeeded load + var url = Qt.resolvedUrl("test1.html"); + webEngineView.url = url; + tryCompare(loadRequestArray, "length", 2); - var bogusSite = "http://www.somesitethatdoesnotexist.abc/" - webEngineView.url = bogusSite - compare(webEngineView.url, bogusSite) - verify(webEngineView.waitForLoadFailed()) - compare(webEngineView.url, url) + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, url); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.activeUrl, url); + webEngineView.clear(); + + // Test failed load + var bogusSite = "http://www.somesitethatdoesnotexist.abc/"; + webEngineView.url = bogusSite; + tryCompare(loadRequestArray, "length", 2); + + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, bogusSite); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadFailedStatus); + compare(loadRequest.activeUrl, url); + webEngineView.clear(); + + // Test page redirection + var redirectUrl = Qt.resolvedUrl("redirect.html"); + webEngineView.url = redirectUrl; + tryCompare(loadRequestArray, "length", 4); - webEngineView.url = "about:blank" // Reset from previous test - verify(webEngineView.waitForLoadSucceeded()) + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, redirectUrl); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.activeUrl, redirectUrl); + loadRequest = loadRequestArray[2]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, redirectUrl); + loadRequest = loadRequestArray[3]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.activeUrl, url); + webEngineView.clear(); + // Test clicking on a hyperlink + var linkUrl = Qt.resolvedUrl("link.html"); + webEngineView.url = linkUrl; + tryCompare(loadRequestArray, "length", 2); + + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, linkUrl); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.activeUrl, linkUrl); + webEngineView.clear(); + + var lastUrl = webEngineView.url; + mouseClick(webEngineView, 10, 10, Qt.LeftButton, Qt.NoModifiers, 50); + tryCompare(loadRequestArray, "length", 2); + + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.url, url); + compare(loadRequest.activeUrl, lastUrl); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.url, url); + compare(loadRequest.activeUrl, url); + webEngineView.clear(); + } + + function test_loadDataUrl() { + WebEngine.settings.errorPageEnabled = false; + + var loadRequest = null; + + // Test load of a data URL + var dataUrl = "data:text/html,foo"; + webEngineView.url = dataUrl; + tryCompare(loadRequestArray, "length", 2); + + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, dataUrl); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.activeUrl, dataUrl); + webEngineView.clear(); + + // Test loadHtml after a failed load + var aboutBlank = "about:blank"; + webEngineView.url = aboutBlank; // Reset from previous test + verify(webEngineView.waitForLoadSucceeded()); + webEngineView.clear(); + + var bogusSite = "http://www.somesitethatdoesnotexist.abc/"; var handleLoadFailed = function(loadRequest) { if (loadRequest.status == WebEngineView.LoadFailedStatus) { - webEngineView.loadHtml("load failed", bogusSite) - // Since the load did not succeed the active url is the - // url of the previous successful load. - compare(webEngineView.url, "about:blank") - compare(loadRequest.url, bogusSite) + // loadHtml constructs data URL + webEngineView.loadHtml("load failed", bogusSite); + compare(loadRequest.url, bogusSite); } } - webEngineView.loadingChanged.connect(handleLoadFailed) + webEngineView.loadingChanged.connect(handleLoadFailed); webEngineView.url = bogusSite - compare(webEngineView.url, bogusSite) - verify(webEngineView.waitForLoadSucceeded()) - compare(webEngineView.url, bogusSite) - webEngineView.loadingChanged.disconnect(handleLoadFailed) - - var dataUrl = "data:text/html,foo" - webEngineView.url = dataUrl - compare(webEngineView.url, dataUrl) - verify(webEngineView.waitForLoadSucceeded()) // data:text/html,foo is loaded - compare(webEngineView.url, dataUrl) - - var redirectUrl = Qt.resolvedUrl("redirect.html") - webEngineView.url = redirectUrl - compare(webEngineView.url, redirectUrl) - verify(webEngineView.waitForLoadSucceeded()) // redirect.html is loaded - compare(webEngineView.url, redirectUrl) - verify(webEngineView.waitForLoadSucceeded()) // test1.html is loaded - compare(webEngineView.url, url) - - var linkUrl = Qt.resolvedUrl("link.html") - webEngineView.url = linkUrl - compare(webEngineView.url, linkUrl) - verify(webEngineView.waitForLoadSucceeded()) - compare(webEngineView.url, linkUrl) - - var handleLoadRequest = function(loadRequest) { - if (loadRequest.status == WebEngineView.LoadStartedStatus) { - compare(webEngineView.url, lastUrl) - compare(loadRequest.url, url) - } - if (loadRequest.status == WebEngineView.LoadSuceededStatus) { - compare(webEngineView.url, loadRequest.url) - compare(webEngineView.url, url) - } - } - lastUrl = webEngineView.url - webEngineView.loadingChanged.connect(handleLoadRequest) - mouseClick(webEngineView, 10, 10, Qt.LeftButton, Qt.NoModifiers, 50) - verify(webEngineView.waitForLoadSucceeded()) - compare(webEngineView.url, url) - webEngineView.loadingChanged.disconnect(handleLoadRequest) + tryCompare(loadRequestArray, "length", 4); + webEngineView.loadingChanged.disconnect(handleLoadFailed); + + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, bogusSite); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadFailedStatus); + // Since the load did not succeed the active url is the + // URL of the previous successful load. + compare(loadRequest.activeUrl, aboutBlank); + loadRequest = loadRequestArray[2]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.activeUrl, aboutBlank); + loadRequest = loadRequestArray[3]; + compare(loadRequest.status, WebEngineView.LoadSucceededStatus); + compare(loadRequest.activeUrl, bogusSite); + webEngineView.clear(); + } + + function test_QTBUG_56661() { + var url = Qt.resolvedUrl("test1.html"); + + // Warm up phase + webEngineView.url = url; + verify(webEngineView.waitForLoadSucceeded()); + + // Load data URL + var dataUrl = "data:text/html,foo"; + webEngineView.url = dataUrl; + verify(webEngineView.waitForLoadSucceeded()); + + // WebEngine should not try to execute user scripts in the + // render frame of the warm up phase otherwise the renderer + // crashes. + webEngineView.url = url; + verify(webEngineView.waitForLoadSucceeded()); } function test_stopStatus() { - var url = Qt.resolvedUrl("test1.html") + var loadRequest = null; - var handleLoadRequest = function(loadRequest) { - if (loadRequest.status == WebEngineView.LoadStoppedStatus) { - compare(webEngineView.url, url) - compare(loadRequest.url, url) - } + var handleLoadStarted = function(loadRequest) { + if (loadRequest.status == WebEngineView.LoadStartedStatus) + webEngineView.stop(); } - webEngineView.loadingChanged.connect(handleLoadRequest) - webEngineView.url = url - compare(webEngineView.url, url) - webEngineView.stop() - verify(webEngineView.waitForLoadStopped()) - compare(webEngineView.url, url) - webEngineView.loadingChanged.disconnect(handleLoadRequest) + webEngineView.loadingChanged.connect(handleLoadStarted); + var url = Qt.resolvedUrl("test1.html"); + webEngineView.url = url; + tryCompare(loadRequestArray, "length", 2); + webEngineView.loadingChanged.disconnect(handleLoadStarted); + + loadRequest = loadRequestArray[0]; + compare(loadRequest.status, WebEngineView.LoadStartedStatus); + compare(loadRequest.url, url); + compare(loadRequest.activeUrl, url); + loadRequest = loadRequestArray[1]; + compare(loadRequest.status, WebEngineView.LoadStoppedStatus); + compare(loadRequest.url, url); + compare(loadRequest.activeUrl, url); + webEngineView.clear(); } } } diff --git a/tests/auto/quick/qmltests/data/tst_navigationRequested.qml b/tests/auto/quick/qmltests/data/tst_navigationRequested.qml index 5013f2fbe..b1c94e601 100644 --- a/tests/auto/quick/qmltests/data/tst_navigationRequested.qml +++ b/tests/auto/quick/qmltests/data/tst_navigationRequested.qml @@ -83,9 +83,6 @@ TestWebEngineView { when: windowShown function init() { - // Workaround for QTBUG-56223 - mouseClick(webEngineView, 0, 0) - attributes.clear() navigationSpy.clear() shouldIgnoreLinkClicks = false diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml new file mode 100644 index 000000000..754a9e018 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtWebEngine 1.2 + +TestWebEngineView { + id: webEngineView + width: 200 + height: 400 + + property var newViewRequest: null + property var dialog: null + + SignalSpy { + id: newViewRequestedSpy + target: webEngineView + signalName: "newViewRequested" + } + + onNewViewRequested: { + newViewRequest = { + "destination": request.destination, + "userInitiated": request.userInitiated + }; + + dialog = Qt.createQmlObject( + "import QtQuick.Window 2.0\n" + + "Window {\n" + + " width: 100; height: 100\n" + + " visible: true; flags: Qt.Dialog\n" + + " property alias webEngineView: webView\n" + + " TestWebEngineView { id: webView; anchors.fill: parent }\n" + + "}", webEngineView); + + request.openIn(dialog.webEngineView); + } + + TestCase { + id: test + name: "NewViewRequest" + when: windowShown + + function init() { + webEngineView.url = Qt.resolvedUrl("about:blank"); + verify(webEngineView.waitForLoadSucceeded()); + + newViewRequestedSpy.clear(); + newViewRequest = null; + } + + function cleanup() { + if (dialog) + dialog.destroy(); + } + + function test_jsWindowOpen() { + // Open an empty page in a new tab + webEngineView.loadHtml( + "<html><head><script>" + + " function popup() { window.open(''); }" + + "</script></head>" + + "<body onload='popup()'></body></html>"); + verify(webEngineView.waitForLoadSucceeded()); + tryCompare(newViewRequestedSpy, "count", 1); + + compare(newViewRequest.destination, WebEngineView.NewViewInTab); + verify(!newViewRequest.userInitiated); + + verify(dialog.webEngineView.waitForLoadSucceeded); + compare(dialog.webEngineView.url, ""); + newViewRequestedSpy.clear(); + dialog.destroy(); + + // Open an empty page in a new dialog + webEngineView.loadHtml( + "<html><head><script>" + + " function popup() { window.open('', '_blank', 'width=200,height=100'); }" + + "</script></head>" + + "<body onload='popup()'></body></html>"); + verify(webEngineView.waitForLoadSucceeded()); + tryCompare(newViewRequestedSpy, "count", 1); + + compare(newViewRequest.destination, WebEngineView.NewViewInDialog); + verify(!newViewRequest.userInitiated); + verify(dialog.webEngineView.waitForLoadSucceeded); + newViewRequestedSpy.clear(); + dialog.destroy(); + + // Open an empty page in a new dialog by user + webEngineView.loadHtml( + "<html><head><script>" + + " function popup() { window.open('', '_blank', 'width=200,height=100'); }" + + "</script></head>" + + "<body onload=\"document.getElementById('popupButton').focus();\">" + + " <button id='popupButton' onclick='popup()'>Pop Up!</button>" + + "</body></html>"); + verify(webEngineView.waitForLoadSucceeded()); + verifyElementHasFocus("popupButton"); + keyPress(Qt.Key_Enter); + tryCompare(newViewRequestedSpy, "count", 1); + + compare(newViewRequest.destination, WebEngineView.NewViewInDialog); + verify(newViewRequest.userInitiated); + verify(dialog.webEngineView.waitForLoadSucceeded); + newViewRequestedSpy.clear(); + dialog.destroy(); + } + } +} + diff --git a/tests/auto/quick/qmltests/data/tst_settings.qml b/tests/auto/quick/qmltests/data/tst_settings.qml index aa3a6dc60..0c37d9569 100644 --- a/tests/auto/quick/qmltests/data/tst_settings.qml +++ b/tests/auto/quick/qmltests/data/tst_settings.qml @@ -56,7 +56,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("javascript.html"); verify(webEngineView.waitForLoadSucceeded()); - compare(webEngineView.title, "New Title"); + tryCompare(webEngineView, "title", "New Title"); } function test_javascriptDisabled() { @@ -64,7 +64,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("javascript.html"); verify(webEngineView.waitForLoadSucceeded()); - compare(webEngineView.title, "Original Title"); + tryCompare(webEngineView, "title", "Original Title"); } function test_localStorageDisabled() { @@ -73,7 +73,7 @@ TestWebEngineView { webEngineView.url = Qt.resolvedUrl("localStorage.html"); verify(webEngineView.waitForLoadSucceeded()); - compare(webEngineView.title, "Original Title"); + tryCompare(webEngineView, "title", "Original Title"); } function test_localStorageEnabled() { @@ -84,7 +84,7 @@ TestWebEngineView { verify(webEngineView.waitForLoadSucceeded()); webEngineView.reload(); verify(webEngineView.waitForLoadSucceeded()); - compare(webEngineView.title, "New Title"); + tryCompare(webEngineView, "title", "New Title"); } function test_settingsAffectCurrentViewOnly() { @@ -100,8 +100,8 @@ TestWebEngineView { webEngineView2.url = testUrl; verify(webEngineView2.waitForLoadSucceeded()); - compare(webEngineView.title, "New Title"); - compare(webEngineView2.title, "New Title"); + tryCompare(webEngineView, "title", "New Title"); + tryCompare(webEngineView2, "title", "New Title"); webEngineView.settings.javascriptEnabled = false; @@ -110,8 +110,8 @@ TestWebEngineView { webEngineView2.url = testUrl; verify(webEngineView2.waitForLoadSucceeded()); - compare(webEngineView.title, "Original Title"); - compare(webEngineView2.title, "New Title"); + tryCompare(webEngineView, "title", "Original Title"); + tryCompare(webEngineView2, "title", "New Title"); webEngineView2.destroy(); } diff --git a/tests/auto/quick/qmltests/data/tst_unhandledKeyEventPropagation.qml b/tests/auto/quick/qmltests/data/tst_unhandledKeyEventPropagation.qml index 87ef16aa2..906dc1658 100644 --- a/tests/auto/quick/qmltests/data/tst_unhandledKeyEventPropagation.qml +++ b/tests/auto/quick/qmltests/data/tst_unhandledKeyEventPropagation.qml @@ -68,12 +68,10 @@ Item { keyPress(Qt.Key_Left) keyRelease(Qt.Key_Left) - for (var i = 0; i < 20 && parentItem.releaseEvents.length < 3; i++) - wait(100) - - compare(parentItem.pressEvents.length, 1) + tryCompare(parentItem.pressEvents, "length", 1) compare(parentItem.pressEvents[0], Qt.Key_Left) - compare(parentItem.releaseEvents.length, 3) + + tryCompare(parentItem.releaseEvents, "length", 3) compare(parentItem.releaseEvents[0], Qt.Key_A) compare(parentItem.releaseEvents[1], Qt.Key_Left) compare(parentItem.releaseEvents[2], Qt.Key_Left) diff --git a/tests/auto/quick/qmltests/data/tst_viewSource.qml b/tests/auto/quick/qmltests/data/tst_viewSource.qml index 79b097b80..8076d99f8 100644 --- a/tests/auto/quick/qmltests/data/tst_viewSource.qml +++ b/tests/auto/quick/qmltests/data/tst_viewSource.qml @@ -74,7 +74,7 @@ TestWebEngineView { function test_viewSource() { webEngineView.url = Qt.resolvedUrl("test1.html"); verify(webEngineView.waitForLoadSucceeded()); - compare(webEngineView.title, "Test page 1"); + tryCompare(webEngineView, "title", "Test page 1"); // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117 //verify(webEngineView.canViewSource, true); @@ -83,14 +83,14 @@ TestWebEngineView { tryCompare(newViewRequestedSpy, "count", 1); verify(webEngineView.waitForLoadSucceeded()); // The first titleChanged signal is emitted by adoptWebContents() - tryCompare(titleChangedSpy, "count", 2); + tryVerify(function() { return titleChangedSpy.count >= 2; }); compare(viewRequest.destination, WebEngineView.NewViewInTab); verify(viewRequest.userInitiated); // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117 //verify(!webEngineView.canViewSource); - compare(webEngineView.title, "test1.html"); + tryCompare(webEngineView, "title", "test1.html"); compare(webEngineView.url, "view-source:" + Qt.resolvedUrl("test1.html")); } @@ -114,14 +114,14 @@ TestWebEngineView { if (row.loadSucceed) { verify(webEngineView.waitForLoadSucceeded()); - tryCompare(titleChangedSpy, "count", 1); + tryVerify(function() { return titleChangedSpy.count >= 1; }); } else { verify(webEngineView.waitForLoadFailed()); - tryCompare(titleChangedSpy, "count", 2); + tryVerify(function() { return titleChangedSpy.count >= 2; }); } compare(webEngineView.url, row.url); - compare(webEngineView.title, row.title); + tryCompare(webEngineView, "title", row.title); // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117 //verify(!webEngineView.canViewSource); } |