[gnome-desktop-testing/wip/functional: 12/12] Add startstopapps functional test
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop-testing/wip/functional: 12/12] Add startstopapps functional test
- Date: Thu, 30 May 2013 01:20:33 +0000 (UTC)
commit 007a57a5c3c6e3a83e33f6b72953a2f5ce68cbfb
Author: Colin Walters <walters verbum org>
Date: Wed May 29 21:19:54 2013 -0400
Add startstopapps functional test
Makefile-functional-tests.am | 25 +++++++++++
Makefile.am | 1 +
tests/functional/startstopapps.js | 80 +++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-functional-tests.am b/Makefile-functional-tests.am
new file mode 100644
index 0000000..cf953e2
--- /dev/null
+++ b/Makefile-functional-tests.am
@@ -0,0 +1,25 @@
+# Copyright (C) 2011,2013 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+insttestdir = $(datadir)/installed-tests/gnome-desktop-testing/
+insttest_DATA = tests/functional/startstopapps.test
+
+%.test: %.js Makefile
+ $(AM_V_GEN) (echo '[Test]' > $ tmp; \
+ echo 'Type=session-exclusive' >> $ tmp; \
+ echo 'Exec=$(pkglibexecdir)/installed-tests/$<' >> $ tmp; \
+ mv $ tmp $@)
diff --git a/Makefile.am b/Makefile.am
index fc30926..a377172 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,6 +42,7 @@ include src/libgsystem/Makefile-libgsystem.am
privlib_LTLIBRARIES += libgsystem.la
include Makefile-runner.am
+include Makefile-functional-tests.am
install-data-hook: $(INSTALL_DATA_HOOKS)
diff --git a/tests/functional/startstopapps.js b/tests/functional/startstopapps.js
new file mode 100755
index 0000000..54c681e
--- /dev/null
+++ b/tests/functional/startstopapps.js
@@ -0,0 +1,80 @@
+#!/usr/bin/env gjs
+
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Gio = imports.gi.Gio;
+
+const sessionBus = Gio.bus_get_sync(Gio.BusType.SESSION, null);
+
+const CLOSE_APPS = '%{apps}.forEach(function (id) {
Shell.AppSystem.get_default().lookup_app(id).request_quit(); });';
+const GET_APP_IDS = 'Shell.AppSystem.get_default().get_running().map(function (a) { return a.get_id(); });';
+
+const StartStopApps = new GObject.Class({
+ Name: 'StartStopApps',
+
+ _init: function(props) {
+ this._shell = Gio.DBusProxy.new_sync(sessionBus, 0, null,
+ "org.gnome.Shell", "/org/gnome/Shell",
+ "org.gnome.Shell", null);
+ },
+
+ _shellEval: function(code, cancellable) {
+ let res = this._shell.call_sync("Eval", GLib.Variant.new("(s)", [code]), 0, -1,
+ cancellable).deep_unpack();
+ let [success, result] = res;
+ if (!success)
+ throw new Error("Failed to eval " + code.substr(0, 20));
+ return result ? JSON.parse(result) : null;
+ },
+
+ _awaitRunningApp: function(appId, cancellable) {
+ let timeoutSecs = 10;
+ let i = 0;
+ for (let i = 0; i < timeoutSecs; i++) {
+ let runningApps = this._shellEval(GET_APP_IDS, cancellable);
+ for (let i = 0; i < runningApps.length; i++) {
+ if (runningApps[i] == appId)
+ return;
+ }
+ GLib.usleep(GLib.USEC_PER_SEC);
+ }
+ throw new Error("Failed to find running app " + appId + " after " + timeoutSecs + "s");
+ },
+
+ _testOneApp: function(app, cancellable) {
+ let appId = app.get_id();
+ print("testing appid=" + appId);
+ app.launch([], cancellable);
+ this._awaitRunningApp(appId, cancellable);
+ this._shellEval(CLOSE_APPS.replace('%{apps}', JSON.stringify([appId])), cancellable);
+ },
+
+ run: function(cancellable) {
+ let allApps = Gio.AppInfo.get_all();
+
+ let runningApps = this._shellEval(GET_APP_IDS, cancellable);
+ print("Closing running apps: " + runningApps);
+ this._shellEval(CLOSE_APPS.replace('%{apps}', JSON.stringify(runningApps)), cancellable);
+
+ for (let i = 0; i < allApps.length; i++) {
+ let app = allApps[i];
+ if (app.get_nodisplay())
+ continue;
+ // Ok, a gross hack; we should really be using gnome-menus
+ // to look up all apps. Or maybe fix Gio?
+ if (app.has_key('Categories') &&
+ app.get_string('Categories').indexOf('X-GNOME-Settings-Panel') >= 0)
+ continue;
+ this._testOneApp(app, cancellable);
+ }
+ }
+});
+
+function main() {
+ let cancellable = null;
+
+ let startstopapps = new StartStopApps();
+ startstopapps.run(cancellable);
+}
+
+main();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]