summaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qmltests/data
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2020-08-20 07:17:23 +0200
committerMichal Klocek <michal.klocek@qt.io>2020-09-22 11:05:20 +0200
commitcfda1a04cb7a0b389fc067fe2cccdbde93ebde27 (patch)
tree4c96c3857f8b87ab51560c738362fc249d25c826 /tests/auto/quick/qmltests/data
parentadaf70ce2b61590180207af34ad47ddd6fabafc2 (diff)
Introduce qml script collection and make webscript as basic type
In widget apis webenginescripts are value types and are managed by webenginescriptcollection. Introduce same concept in qml and make qquickwebenginescript a value type and reuse core userscript as private implementation. Rewrite webenginscript list handling. This patch is half baked since it does not include docs and tests for new api, however aim is to move script classes to core and reuse those in qml land. Therefore, new class introduced here is going to be removed in follow up patches, so all the missing parts will be added later. A new way of managing scripts in qml is as follows: * using collection with javascript dictionaries var script = { name: "FOO" sourceUrl: Qt.resolvedUrl("foo.js"), injectionPoint: WebEngineScript.DocumentReady } webEngineView.userScripts.collection = [ script1, script2 ]; * using collection with webscript basic type var script = WebEngine.script() script.name = "FOO" webEngineView.userScripts.collection = [ script ]; * using fine grain user script collection api with basic type var script = WebEngine.script() script.name = "FOO" webEngineView.userScripts.insert(script) Of course new api can be extended and we can provide more convince overloads. Note the main motivation here is to enable reuse webenginescript object created in c++ land, which is now passed as value in follow up patches. This changes reuses private apis of qml and will most likely require further changes when QTBUG-82443 is completed. [ChangeLog] WebEngineScript is a basic value type in qml, it is no longer declarative way of creating it, instead use WebEngine.script() Change-Id: I6a0ac3607e4522ccaefcec0a7d2986577d7e7024 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick/qmltests/data')
-rw-r--r--tests/auto/quick/qmltests/data/tst_userScripts.qml85
1 files changed, 46 insertions, 39 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_userScripts.qml b/tests/auto/quick/qmltests/data/tst_userScripts.qml
index f4fcc30ab..4d0bd28bf 100644
--- a/tests/auto/quick/qmltests/data/tst_userScripts.qml
+++ b/tests/auto/quick/qmltests/data/tst_userScripts.qml
@@ -31,32 +31,33 @@ import QtTest 1.0
import QtWebEngine 1.2
Item {
- WebEngineScript {
- id: changeDocumentTitleScript
- sourceUrl: Qt.resolvedUrl("change-document-title.js")
- injectionPoint: WebEngineScript.DocumentReady
+
+ function changeDocumentTitleScript() {
+ return { name: "changeDocumentTitleScript",
+ sourceUrl: Qt.resolvedUrl("change-document-title.js"),
+ injectionPoint: WebEngineScript.DocumentReady }
}
- WebEngineScript {
- id: appendDocumentTitleScript
- sourceUrl: Qt.resolvedUrl("append-document-title.js")
- injectionPoint: WebEngineScript.DocumentReady
+ function appendDocumentTitleScript() {
+ return { sourceUrl: Qt.resolvedUrl("append-document-title.js"),
+ injectionPoint: WebEngineScript.DocumentReady }
}
- WebEngineScript {
- id: bigUserScript
- sourceUrl: Qt.resolvedUrl("big-user-script.js")
- injectionPoint: WebEngineScript.DocumentReady
+ function bigUserScript() {
+ return { sourceUrl: Qt.resolvedUrl("big-user-script.js"),
+ injectionPoint: WebEngineScript.DocumentReady }
}
- WebEngineScript {
- id: scriptWithMetadata
- sourceUrl: Qt.resolvedUrl("script-with-metadata.js")
+ function scriptWithMetadata() {
+ var script = WebEngine.script()
+ script.sourceUrl = Qt.resolvedUrl("script-with-metadata.js")
+ return script
}
- WebEngineScript {
- id: scriptWithBadMatchMetadata
- sourceUrl: Qt.resolvedUrl("script-with-bad-match-metadata.js")
+ function scriptWithBadMatchMetadata() {
+ var script = WebEngine.script()
+ script.sourceUrl = Qt.resolvedUrl("script-with-bad-match-metadata.js")
+ return script
}
TestWebEngineView {
@@ -79,21 +80,22 @@ Item {
onNavigationRequested: {
var urlString = request.url.toString();
if (urlString.indexOf("test1.html") !== -1)
- userScripts = [ changeDocumentTitleScript ];
+ userScripts.collection = [ changeDocumentTitleScript() ];
else if (urlString.indexOf("test2.html") !== -1)
- userScripts = [ appendDocumentTitleScript ];
+ userScripts.collection = [ appendDocumentTitleScript() ];
else
- userScripts = [];
+ userScripts.collection = [];
}
}
TestCase {
name: "WebEngineViewUserScripts"
+
function init() {
webEngineView.url = "";
- webEngineView.userScripts = [];
- webEngineView.profile.userScripts = [];
+ webEngineView.userScripts.collection = [];
+ webEngineView.profile.userScripts.collection = [];
}
function test_oneScript() {
@@ -101,7 +103,8 @@ Item {
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "Test page 1");
- webEngineView.userScripts = [ changeDocumentTitleScript ];
+ webEngineView.userScripts.collection = [ changeDocumentTitleScript() ]
+
compare(webEngineView.title, "Test page 1");
webEngineView.reload();
@@ -112,7 +115,7 @@ Item {
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "New title");
- webEngineView.userScripts = [];
+ webEngineView.userScripts.collection = [];
compare(webEngineView.title, "New title");
webEngineView.reload();
@@ -124,23 +127,25 @@ Item {
webEngineView.url = Qt.resolvedUrl("test1.html");
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "Test page 1");
-
- webEngineView.userScripts = [ changeDocumentTitleScript, appendDocumentTitleScript ];
+ var script1 = changeDocumentTitleScript();
+ var script2 = appendDocumentTitleScript();
+ script2.injectionPoint = WebEngineScript.Deferred;
+ webEngineView.userScripts.collection = [ script1, script2 ];
// Make sure the scripts are loaded in order.
- appendDocumentTitleScript.injectionPoint = WebEngineScript.Deferred
webEngineView.reload();
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "New title with appendix");
- appendDocumentTitleScript.injectionPoint = WebEngineScript.DocumentReady
- changeDocumentTitleScript.injectionPoint = WebEngineScript.Deferred
+ script2.injectionPoint = WebEngineScript.DocumentReady
+ script1.injectionPoint = WebEngineScript.Deferred
+ webEngineView.userScripts.collection = [ script1, script2 ];
webEngineView.reload();
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "New title");
// Make sure we can remove scripts from the preload list.
- webEngineView.userScripts = [ appendDocumentTitleScript ];
+ webEngineView.userScripts.collection = [ script2 ];
webEngineView.reload();
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "Test page 1 with appendix");
@@ -163,17 +168,18 @@ Item {
}
function test_bigScript() {
- webEngineView.userScripts = [ bigUserScript ];
+ webEngineView.userScripts.collection = [ bigUserScript() ];
webEngineView.url = Qt.resolvedUrl("test1.html");
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView , "title", "Big user script changed title");
}
function test_parseMetadataHeader() {
- compare(scriptWithMetadata.name, "Test script");
- compare(scriptWithMetadata.injectionPoint, WebEngineScript.DocumentReady);
+ var script = scriptWithMetadata()
+ compare(script.name, "Test script");
+ compare(script.injectionPoint, WebEngineScript.DocumentReady);
- webEngineView.userScripts = [ scriptWithMetadata ];
+ webEngineView.userScripts.collection = [ script ];
// @include *data/test*.html
webEngineView.url = Qt.resolvedUrl("test1.html");
@@ -197,10 +203,11 @@ Item {
}
function test_dontInjectBadUrlPatternsEverywhere() {
- compare(scriptWithBadMatchMetadata.name, "Test bad match script");
- compare(scriptWithBadMatchMetadata.injectionPoint, WebEngineScript.DocumentReady);
+ var script = scriptWithBadMatchMetadata();
+ compare(script.name, "Test bad match script");
+ compare(script.injectionPoint, WebEngineScript.DocumentReady);
- webEngineView.userScripts = [ scriptWithBadMatchMetadata ];
+ webEngineView.userScripts.collection = [ script ];
// @match some:junk
webEngineView.url = Qt.resolvedUrl("test2.html");
@@ -209,7 +216,7 @@ Item {
}
function test_profileWideScript() {
- webEngineView.profile.userScripts = [ changeDocumentTitleScript ];
+ webEngineView.profile.userScripts.collection = [ changeDocumentTitleScript() ];
webEngineView.url = Qt.resolvedUrl("test1.html");
webEngineView.waitForLoadSucceeded();