1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
quickinspectortest2.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Volker Krause <volker.krause@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include "basequicktest.h"
#include "testhelpers.h"
#include <plugins/quickinspector/quickinspectorinterface.h>
#include <common/objectbroker.h>
#include <common/remoteviewinterface.h>
#include <common/remoteviewframe.h>
#include <QAbstractItemModelTester>
#include <QItemSelectionModel>
#include <QQuickItem>
using namespace GammaRay;
using namespace TestHelpers;
class QuickInspectorTest2 : public BaseQuickTest
{
Q_OBJECT
protected:
bool ignoreNonExposedView() const override
{
return true;
}
private slots:
static void initTestCase()
{
qRegisterMetaType<QItemSelection>();
}
void init() override
{
BaseQuickTest::init();
itemModel = ObjectBroker::model(QStringLiteral("com.kdab.GammaRay.QuickItemModel"));
QVERIFY(itemModel);
new QAbstractItemModelTester(itemModel, view());
sgModel = ObjectBroker::model(QStringLiteral("com.kdab.GammaRay.QuickSceneGraphModel"));
QVERIFY(sgModel);
new QAbstractItemModelTester(sgModel, view());
inspector = ObjectBroker::object<QuickInspectorInterface *>();
QVERIFY(inspector);
inspector->setServerSideDecorationsEnabled(false);
inspector->selectWindow(0);
QTest::qWait(1);
}
static void testPreviewFetchingThrottler_data()
{
QTest::addColumn<bool>("clientIsReplying", nullptr);
QTest::newRow("no-reply") << false;
QTest::newRow("reply") << true;
}
void testPreviewFetchingThrottler()
{
QFETCH(bool, clientIsReplying);
auto remoteView = ObjectBroker::object<RemoteViewInterface *>(QStringLiteral(
"com.kdab.GammaRay.QuickRemoteView"));
QVERIFY(remoteView);
QVERIFY(showSource(QStringLiteral("qrc:/manual/rotationinvariant.qml")));
if (!isViewExposed())
return;
auto rootItem = view()->rootObject();
QVERIFY(rootItem);
Probe::instance()->selectObject(rootItem, QPoint());
// RemoteViewServer throttle the requests with an interval of qRound(1000.0 / 60.0)
const qreal throttlerInterval = qRound(1000.0 / 60.0);
if (clientIsReplying) {
connect(remoteView, &RemoteViewInterface::frameUpdated,
remoteView, &RemoteViewInterface::clientViewUpdated, Qt::UniqueConnection);
} else {
disconnect(remoteView, &RemoteViewInterface::frameUpdated,
remoteView, &RemoteViewInterface::clientViewUpdated);
}
QSignalSpy requestedSpy(remoteView, SIGNAL(requestUpdate()));
QVERIFY(requestedSpy.isValid());
QSignalSpy updatedSpy(remoteView, &RemoteViewInterface::frameUpdated);
QVERIFY(updatedSpy.isValid());
// Testing static scene only send 1 frame
for (int i = 0; i < 3; ++i) {
remoteView->setViewActive(true);
// Activating the view trigger an update request
QVERIFY(waitForSignal(&updatedSpy, true));
QVERIFY(requestedSpy.size() == 1 || requestedSpy.size() == 2); // should be 1, but we might see spurious repaints on windows
QVERIFY(updatedSpy.size() == 1 || updatedSpy.size() == 2);
if (!clientIsReplying)
remoteView->clientViewUpdated();
requestedSpy.clear();
updatedSpy.clear();
if (clientIsReplying) {
// The client is answering clientViewUpdated automatically.
// For 1 request and multiple client answers the server should only send 1 frame.
view()->update();
QVERIFY(waitForSignal(&updatedSpy, true));
for (int j = 0; j < 3; ++j) {
// The automatic clientViewUpdated answer is only done for frame sent.
// Let manually trigger answers.
QTest::qWait(throttlerInterval);
remoteView->clientViewUpdated();
}
QVERIFY(waitForSignal(&requestedSpy, true));
QVERIFY(requestedSpy.size() == 1 || requestedSpy.size() == 2);
QVERIFY(updatedSpy.size() == 1 || updatedSpy.size() == 2);
} else {
// The client is not answering with clientViewUpdated automatically.
// Only 1 request and 1 frame sent should trigger.
for (int i = 0; i < 3; ++i) {
view()->update();
QTest::qWait(throttlerInterval);
QVERIFY(waitForSignal(&updatedSpy, true));
}
QVERIFY(requestedSpy.size() == 1 || requestedSpy.size() == 2);
QVERIFY(updatedSpy.size() == 1 || updatedSpy.size() == 2);
}
requestedSpy.clear();
updatedSpy.clear();
remoteView->setViewActive(false);
}
// Our animation properties
const qreal animationInterval = throttlerInterval;
const qreal animationDuration = 100.0;
// Qml try to render @ ~60fps
const qreal maxPossibleQmlRequests =
clientIsReplying ? animationDuration / 1000.0 * 60.0 : 1.0;
const qreal maxPossibleThrottledRequests =
clientIsReplying ? qMin(maxPossibleQmlRequests, animationDuration / throttlerInterval) : 1.0;
// Testing dynamic scene
for (int i = 0; i < 3; i++) {
remoteView->setViewActive(true);
// Activating the view trigger an update request
QVERIFY(waitForSignal(&updatedSpy, true));
QCOMPARE(requestedSpy.size(), 1);
QCOMPARE(updatedSpy.size(), 1);
if (!clientIsReplying)
remoteView->clientViewUpdated();
requestedSpy.clear();
updatedSpy.clear();
// We rotate our rendering every animationInterval-ms for animationDuration-ms
rootItem->setProperty("interval", qRound(animationInterval));
rootItem->setProperty("animated", true);
QTest::qWait(qRound(animationDuration));
// Wait to process pending requests...
rootItem->setProperty("animated", false);
QTest::qWait(qRound(animationDuration));
QVERIFY(requestedSpy.size() <= qRound(maxPossibleThrottledRequests * 1.05) + 1);
QVERIFY(updatedSpy.size() <= qRound(maxPossibleThrottledRequests * 1.05) + 1);
QCOMPARE(requestedSpy.size(), updatedSpy.size());
requestedSpy.clear();
updatedSpy.clear();
remoteView->setViewActive(false);
}
}
private:
QAbstractItemModel *itemModel;
QAbstractItemModel *sgModel;
QuickInspectorInterface *inspector;
};
QTEST_MAIN(QuickInspectorTest2)
#include "quickinspectortest2.moc"
|