From 58cd21c0aa7a9dc5a18ea411dcf462a2ee8193f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Fri, 24 Apr 2020 12:42:25 +0200 Subject: Fix setting WebEngineView.audioMuted before initialization Fixes: QTBUG-83732 Change-Id: Ie07a1ecf87b214436ab7cea07003ddd5aeaedda3 Reviewed-by: Allan Sandfeld Jensen --- src/webengine/api/qquickwebengineview.cpp | 13 +++-- src/webengine/api/qquickwebengineview_p_p.h | 1 + tests/auto/quick/qmltests/data/tst_audioMuted.qml | 63 +++++++++++++++++++++++ tests/auto/quick/qmltests/qmltests.pro | 1 + 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 tests/auto/quick/qmltests/data/tst_audioMuted.qml diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index c56014a57..804d81e54 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -129,6 +129,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , devicePixelRatio(QGuiApplication::primaryScreen()->devicePixelRatio()) , m_webChannel(0) , m_webChannelWorld(0) + , m_defaultAudioMuted(false) , m_isBeingAdopted(false) , m_backgroundColor(Qt::white) , m_zoomFactor(1.0) @@ -906,6 +907,9 @@ void QQuickWebEngineViewPrivate::initializationFinished() adapter->setWebChannel(m_webChannel, m_webChannelWorld); #endif + if (m_defaultAudioMuted != adapter->isAudioMuted()) + adapter->setAudioMuted(m_defaultAudioMuted); + if (devToolsView && devToolsView->d_ptr->adapter) adapter->openDevToolsFrontend(devToolsView->d_ptr->adapter); @@ -1426,15 +1430,18 @@ void QQuickWebEngineView::setBackgroundColor(const QColor &color) bool QQuickWebEngineView::isAudioMuted() const { const Q_D(QQuickWebEngineView); - return d->adapter->isAudioMuted(); + if (d->adapter->isInitialized()) + return d->adapter->isAudioMuted(); + return d->m_defaultAudioMuted; } void QQuickWebEngineView::setAudioMuted(bool muted) { Q_D(QQuickWebEngineView); - bool wasAudioMuted = d->adapter->isAudioMuted(); + bool wasAudioMuted = isAudioMuted(); + d->m_defaultAudioMuted = muted; d->adapter->setAudioMuted(muted); - if (wasAudioMuted != d->adapter->isAudioMuted()) + if (wasAudioMuted != isAudioMuted()) Q_EMIT audioMutedChanged(muted); } diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index e696f6a0c..12a991ffa 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -217,6 +217,7 @@ public: QPointer inspectedView; QPointer devToolsView; uint m_webChannelWorld; + bool m_defaultAudioMuted; bool m_isBeingAdopted; mutable QQuickWebEngineAction *actions[QQuickWebEngineView::WebActionCount]; QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick *widget = nullptr; diff --git a/tests/auto/quick/qmltests/data/tst_audioMuted.qml b/tests/auto/quick/qmltests/data/tst_audioMuted.qml new file mode 100644 index 000000000..c626d07a0 --- /dev/null +++ b/tests/auto/quick/qmltests/data/tst_audioMuted.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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: view + width: 400 + height: 400 + + SignalSpy { + id: spy + target: view + signalName: "audioMutedChanged" + } + + TestCase { + id: test + name: "WebEngineViewAudioMuted" + + function test_audioMuted() { + compare(view.audioMuted, false); + view.audioMuted = true; + view.url = "about:blank"; + verify(view.waitForLoadSucceeded()); + compare(view.audioMuted, true); + compare(spy.count, 1); + compare(spy.signalArguments[0][0], true); + view.audioMuted = false; + compare(view.audioMuted, false); + compare(spy.count, 2); + compare(spy.signalArguments[1][0], false); + } + } +} + diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index 0b3ff7c7e..5c57f7ad9 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -31,6 +31,7 @@ OTHER_FILES += \ $$PWD/data/titleupdate.js \ $$PWD/data/tst_action.qml \ $$PWD/data/tst_activeFocusOnPress.qml \ + $$PWD/data/tst_audioMuted.qml \ $$PWD/data/tst_contextMenu.qml \ $$PWD/data/tst_desktopBehaviorLoadHtml.qml \ $$PWD/data/tst_download.qml \ -- cgit v1.2.3