[gnome-continuous/wip/apptest: 10/13] applicationstest: Extract the icons for every app tested



commit 339ba148da0e4ccf01aab29587fc3479c9c5b624
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Nov 13 14:07:48 2013 -0500

    applicationstest: Extract the icons for every app tested
    
    So we can display them on the web page...

 src/js/tasks/task-applicationstest.js    |   34 +++++++++++++++++++++++----
 src/tests/gnome-continuous-startstopapps |   37 +++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/src/js/tasks/task-applicationstest.js b/src/js/tasks/task-applicationstest.js
index 6faf5e8..04d19b3 100644
--- a/src/js/tasks/task-applicationstest.js
+++ b/src/js/tasks/task-applicationstest.js
@@ -64,20 +64,44 @@ const TaskApplicationsTest = new Lang.Class({
         }
     },
 
+    _extractIcon: function(appId, iconTuple, cancellable) {
+        let [ext, iconBytes] = iconTuple;
+
+        if (!iconBytes.length)
+            return null;
+
+        let iconDir = Gio.File.new_for_path('icons');
+        GSystem.file_ensure_directory(iconDir, true, null);
+
+        let icon = iconDir.get_child(appId + ext);
+        let s = icon.replace(null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, cancellable);
+        s.write_bytes(iconBytes.toGBytes(), cancellable);
+        s.close(cancellable);
+        return icon;
+    },
+
     _onCommandChannelAsyncMessage: function(msgId, value) {
         if (msgId == 'TestingAppStart') {
-            this._testingApp = value.deep_unpack();
-            print("got testingAppStart id=" + this._testingApp);
-            this._allApps[this._testingApp] = {'state': 'running'};
+            let [appId, iconTuple] = value.deep_unpack();
+            print("got testingAppStart id=" + appId);
+            this._testingApp = appId;
+            let app = {};
+            let icon = this._extractIcon(appId, iconTuple, null);
+            if (icon)
+                app.icon = this.workdir.get_relative_path(icon);
+            app.state = 'running';
+            this._allApps[this._testingApp] = app;
             this._testingAppCoredumped = false;
         } else if (msgId == 'TestingAppTimedOut') {
             print("got TestingAppTimedOut");
-            this._allApps[this._testingApp] = {'state': 'timeout'};
+            let app = this._allApps[this._testingApp];
+            app.state = 'timeout';
             this._testingApp = null;
         } else if (msgId == 'TestingAppComplete') {
+            let app = this._allApps[this._testingApp];
             let successfulStr = !this._testingAppCoredumped ? 'success' : 'failed';
             print("got TestingAppComplete success=" + successfulStr);
-            this._allApps[this._testingApp] = {'state': successfulStr};
+            app.state = successfulStr;
             this._testingApp = null;
         } else {
             print("Got unknown asyncmessage: " + msgId);
diff --git a/src/tests/gnome-continuous-startstopapps b/src/tests/gnome-continuous-startstopapps
index a5ccad8..bfa1f88 100644
--- a/src/tests/gnome-continuous-startstopapps
+++ b/src/tests/gnome-continuous-startstopapps
@@ -17,16 +17,50 @@
 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 // Boston, MA 02111-1307, USA.
 
+const Gtk = imports.gi.Gtk;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 
+Gtk.init(null);
+
 const sessionBus = Gio.bus_get_sync(Gio.BusType.SESSION, null);
 
 const CLOSE_ALL_APPS = 'Shell.AppSystem.get_default().get_running().forEach(function (app) { 
app.request_quit(); });';
 const GET_APP_IDS = 'Shell.AppSystem.get_default().get_running().map(function (a) { return a.get_id(); });';
 
+function getExtension(filename) {
+    let parts = filename.split('.');
+
+    // No extension
+    if (parts.length == 1)
+        return '';
+
+    return parts[parts.length - 1];
+}
+
+function getAppIcon(app) {
+    const ICON_SIZE = 256;
+
+    let icon = app.get_icon();
+    if (!icon)
+        return ['', []];
+
+    let theme = Gtk.IconTheme.get_default();
+    let info = theme.lookup_by_gicon(icon, ICON_SIZE, 0);
+    if (!info)
+        return ['', []];
+
+    try {
+        let [success, byteArray] = GLib.file_get_contents(info.get_filename());
+        let extension = getExtension(GLib.path_get_basename(info.get_filename()));
+        return [('.' + extension), byteArray.toGBytes()];
+    } catch(e) {
+        return ['', []];
+    }
+}
+
 const StartStopApps = new GObject.Class({
     Name: 'StartStopApps',
     
@@ -75,7 +109,8 @@ const StartStopApps = new GObject.Class({
 
         this._shellEval(CLOSE_ALL_APPS, this._cancellable);
 
-        this._sendAsyncMessage('TestingAppStart', GLib.Variant.new("s", appid));
+        let icon = getAppIcon(this._testingApp);
+        this._sendAsyncMessage('TestingAppStart', GLib.Variant.new("(s(say))", [appid, icon]));
         this._testingApp.launch([], this._cancellable);
         this._appCheckRunningIterations = 0;
         this._appCheckRunningTimeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]