diff options
author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2016-06-03 02:41:21 -0700 |
---|---|---|
committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2016-07-07 08:41:35 +0000 |
commit | 9bb9076c50048913075f11692f784ebb959d63cf (patch) | |
tree | 4a27e9eb3c7bd767963505f14ac0c703c811338c /tests/auto/quick | |
parent | 800365f6faad962a4dd2e71173527d285a3f62b5 (diff) |
Parse metadata block in user scripts
This allows WebEngine to build up user script objects from the
metadata section of their source code. It also implements @include,
@exclude and @match rules for restricting script injection to given
URL patterns.
Change-Id: Ic7b3023c0143643bfbf71adbfa25a8022b223fcf
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qmltests/data/script-with-metadata.js | 10 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_userScripts.qml | 22 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/quick/qmltests/data/script-with-metadata.js b/tests/auto/quick/qmltests/data/script-with-metadata.js new file mode 100644 index 000000000..4dcf50f55 --- /dev/null +++ b/tests/auto/quick/qmltests/data/script-with-metadata.js @@ -0,0 +1,10 @@ +// ==UserScript== +// @name Test script +// @homepageURL http://www.qt.io/ +// @description Test script with metadata block +// @include *test*.html +// @exclude *test2.html +// @run-at document-end +// ==/UserScript== + +document.title = "New title"; diff --git a/tests/auto/quick/qmltests/data/tst_userScripts.qml b/tests/auto/quick/qmltests/data/tst_userScripts.qml index d4f1222f9..dbad8cd56 100644 --- a/tests/auto/quick/qmltests/data/tst_userScripts.qml +++ b/tests/auto/quick/qmltests/data/tst_userScripts.qml @@ -49,6 +49,11 @@ Item { injectionPoint: WebEngineScript.DocumentReady } + WebEngineScript { + id: scriptWithMetadata + sourceUrl: Qt.resolvedUrl("script-with-metadata.js") + } + TestWebEngineView { id: webEngineView width: 400 @@ -151,5 +156,22 @@ Item { webEngineView.waitForLoadSucceeded(); compare(webEngineView.title, "Big user script changed title"); } + + function test_parseMetadataHeader() { + compare(scriptWithMetadata.name, "Test script"); + compare(scriptWithMetadata.injectionPoint, WebEngineScript.DocumentReady); + + webEngineView.userScripts = [ scriptWithMetadata ]; + + // @include *test*.html + webEngineView.url = Qt.resolvedUrl("test1.html"); + webEngineView.waitForLoadSucceeded(); + compare(webEngineView.title, "New title"); + + // @exclude *test2.html + webEngineView.url = Qt.resolvedUrl("test2.html"); + webEngineView.waitForLoadSucceeded(); + compare(webEngineView.title, "Test page with huge link area"); + } } } |