diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-10-09 09:32:55 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-11-06 10:00:07 +0000 |
commit | be8c12a814cbed3f1fcb7097f6980fae6112cbc3 (patch) | |
tree | af713aee9739d9f994e5a9404d7995f7f2d1011b /tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | |
parent | fce0c120e4e67496e4a8d76398a8c105a76c42c4 (diff) |
Print JS console messages by default
Change the behavior of QWebEnginePage/WebEngineView
to print JavaScript console.warn and console.error messages
by default in a 'js' logging category. This matches also
the behavior for QtQml, where console messages end up in
a 'qml' logging category by default.
So far access to the JavaScript console required either use
of the remote debugging functionality, subclassing of
QWebEnginePage, or implementing a custom handler.
Anyhow, even then writing a seamless forwarding of
the data and metadata to the Qt message handler is
difficult. This patches implements this forwarding by
default.
The behavior can be changed by either setting up rules
for the 'js' category, e.g.
setFilterRules("js.*=false");
or by implementing onJavaScriptConsoleMessage(),
or overriding QWebEnginePage::javaScriptConsoleMessage.
[ChangeLog] Unhandled JS console messages are now
forwarded to to the Qt message handler inside a 'js'
category.
Change-Id: I5480383a80dcf7a122496f9b7915264ef9036db3
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index b29d8fae6..80445051c 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -25,18 +25,6 @@ #include <qwebengineview.h> #include "../util.h" -//#define DEBUG_SCRIPT_MESSAGES -#ifdef DEBUG_SCRIPT_MESSAGES -class WebEnginePage : public QWebEnginePage { - void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) { - qDebug() << level << message << lineNumber << sourceID; - } - -}; -#else -typedef QWebEnginePage WebEnginePage; -#endif - class tst_QWebEngineScript: public QObject { Q_OBJECT @@ -49,10 +37,9 @@ private Q_SLOTS: }; - void tst_QWebEngineScript::domEditing() { - WebEnginePage page; + QWebEnginePage page; QWebEngineView view; view.setPage(&page); QWebEngineScript s; @@ -88,7 +75,7 @@ void tst_QWebEngineScript::injectionPoint() s.setSourceCode("var foo = \"foobar\";"); s.setInjectionPoint(static_cast<QWebEngineScript::InjectionPoint>(injectionPoint)); s.setWorldId(QWebEngineScript::MainWorld); - WebEnginePage page; + QWebEnginePage page; page.scripts().insert(s); page.setHtml(QStringLiteral("<html><head><script> var contents;") + testScript + QStringLiteral("document.addEventListener(\"load\", setTimeout(function(event) {\ @@ -119,7 +106,7 @@ void tst_QWebEngineScript::injectionPoint_data() void tst_QWebEngineScript::scriptWorld() { - WebEnginePage page; + QWebEnginePage page; QWebEngineScript script; script.setInjectionPoint(QWebEngineScript::DocumentCreation); script.setWorldId(QWebEngineScript::MainWorld); @@ -138,7 +125,7 @@ void tst_QWebEngineScript::scriptWorld() void tst_QWebEngineScript::scriptModifications() { - WebEnginePage page; + QWebEnginePage page; QWebEngineScript script; script.setName(QStringLiteral("String1")); script.setInjectionPoint(QWebEngineScript::DocumentCreation); |