Improve introspection into Scripting for KWin core/testing
Summary: This change introduces a Scripting::findScript method which returns the AbstractScript. Thus a test can load a script, retrieve it and trigger run on it. As the test would also need to know when finally the test is running a signal is introduced to notify about it. This makes the scripting ScreenEdgeTest way more reliable. The test had been failing on both build.kde.org and build.neon.kde.org due to not knowing when the script is loaded. Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D2497
This commit is contained in:
parent
7d7bbcc56a
commit
c3dfacc3dc
3 changed files with 23 additions and 8 deletions
|
@ -126,11 +126,14 @@ void ScreenEdgeTest::testEdge()
|
|||
const int id = Scripting::self()->loadScript(scriptToLoad);
|
||||
QVERIFY(id != -1);
|
||||
QVERIFY(Scripting::self()->isScriptLoaded(scriptToLoad));
|
||||
// TODO: a way to run the script without having to call the global start
|
||||
Scripting::self()->start();
|
||||
// give it some time to start - a callback would be nice
|
||||
QTest::qWait(100);
|
||||
|
||||
auto s = Scripting::self()->findScript(scriptToLoad);
|
||||
QVERIFY(s);
|
||||
QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged);
|
||||
QVERIFY(runningChangedSpy.isValid());
|
||||
s->run();
|
||||
QVERIFY(runningChangedSpy.wait());
|
||||
QCOMPARE(runningChangedSpy.count(), 1);
|
||||
QCOMPARE(runningChangedSpy.first().first().toBool(), true);
|
||||
// triggering the edge will result in show desktop being triggered
|
||||
QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged);
|
||||
QVERIFY(showDesktopSpy.isValid());
|
||||
|
|
|
@ -718,14 +718,19 @@ void KWin::Scripting::slotScriptsQueried()
|
|||
}
|
||||
|
||||
bool KWin::Scripting::isScriptLoaded(const QString &pluginName) const
|
||||
{
|
||||
return findScript(pluginName) != nullptr;
|
||||
}
|
||||
|
||||
KWin::AbstractScript *KWin::Scripting::findScript(const QString &pluginName) const
|
||||
{
|
||||
QMutexLocker locker(m_scriptsLock.data());
|
||||
foreach (AbstractScript *script, scripts) {
|
||||
if (script->pluginName() == pluginName) {
|
||||
return true;
|
||||
return script;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool KWin::Scripting::unloadScript(const QString &pluginName)
|
||||
|
|
|
@ -52,7 +52,7 @@ class Client;
|
|||
class ScriptUnloaderAgent;
|
||||
class WorkspaceWrapper;
|
||||
|
||||
class AbstractScript : public QObject
|
||||
class KWIN_EXPORT AbstractScript : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -149,6 +149,7 @@ private Q_SLOTS:
|
|||
|
||||
Q_SIGNALS:
|
||||
Q_SCRIPTABLE void print(const QString &text);
|
||||
void runningChanged(bool);
|
||||
|
||||
protected:
|
||||
QFile &scriptFile() {
|
||||
|
@ -158,7 +159,11 @@ protected:
|
|||
return m_running;
|
||||
}
|
||||
void setRunning(bool running) {
|
||||
if (m_running == running) {
|
||||
return;
|
||||
}
|
||||
m_running = running;
|
||||
emit runningChanged(m_running);
|
||||
}
|
||||
int scriptId() const {
|
||||
return m_scriptId;
|
||||
|
@ -357,6 +362,8 @@ public:
|
|||
QQmlEngine *qmlEngine();
|
||||
WorkspaceWrapper *workspaceWrapper() const;
|
||||
|
||||
AbstractScript *findScript(const QString &pluginName) const;
|
||||
|
||||
static Scripting *self();
|
||||
static Scripting *create(QObject *parent);
|
||||
|
||||
|
|
Loading…
Reference in a new issue