Merge lp:~mikemc/unity-scope-click/fix-1262780-use-dotdesktop into lp:unity-scope-click

Proposed by Mike McCracken
Status: Merged
Approved by: dobey
Approved revision: 98
Merged at revision: 97
Proposed branch: lp:~mikemc/unity-scope-click/fix-1262780-use-dotdesktop
Merge into: lp:unity-scope-click
Diff against target: 175 lines (+68/-9)
3 files modified
src/click-interface.vala (+6/-3)
src/click-scope.vala (+5/-6)
src/test-click-webservice.vala (+57/-0)
To merge this branch: bzr merge lp:~mikemc/unity-scope-click/fix-1262780-use-dotdesktop
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
dobey (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+199730@code.launchpad.net

Commit message

- Send correct application:/// url to preview after install (LP: #1262780)

Description of the change

- Send correct application:/// url to preview after install (LP: #1262780)

Reinstate use of url generated from dot-desktop filename so that the "Open" button shown by the preview after install works.

Adds a few tests to verify correct installed preview generation.

Also avoids logging two lines for each installed app every time we get the list, which is fairly often.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/click-interface.vala'
2--- src/click-interface.vala 2013-12-04 13:31:52 +0000
3+++ src/click-interface.vala 2013-12-19 23:53:33 +0000
4@@ -106,7 +106,7 @@
5 return versions;
6 }
7
8- public async string get_dotdesktop (string app_id) throws ClickError {
9+ public virtual async string get_dotdesktop (string app_id) throws ClickError {
10 foreach (var element in yield get_manifests()) {
11 var manifest = element.get_object();
12 var pkg_name = manifest.get_string_member("name");
13@@ -115,7 +115,10 @@
14 var hooks = manifest.get_object_member("hooks");
15 foreach (var app_name in hooks.get_members()) {
16 // FIXME: "Primary app" is not defined yet, so we take the first one
17- return "%s_%s_%s.desktop".printf(pkg_name, app_name, version);
18+ var ddstr = "%s_%s_%s.desktop".printf(pkg_name, app_name, version);
19+ debug ("get_dotdesktop: using first of %u hooks members, returning %s",
20+ hooks.get_members().length(), ddstr);
21+ return ddstr;
22 }
23 }
24 }
25@@ -123,7 +126,7 @@
26 throw new ClickError.EXEC_FAILURE(msg);
27 }
28
29- public async bool can_uninstall (string app_id) {
30+ public virtual async bool can_uninstall (string app_id) {
31 const string REMOVABLE_FIELD = "_removable";
32 GLib.List<weak Json.Node> manifests;
33 try {
34
35=== modified file 'src/click-scope.vala'
36--- src/click-scope.vala 2013-12-17 20:17:01 +0000
37+++ src/click-scope.vala 2013-12-19 23:53:33 +0000
38@@ -148,10 +148,10 @@
39 return preview;
40 }
41
42- async Unity.Preview build_installed_preview (Unity.ScopeResult result) {
43+ public async Unity.Preview build_installed_preview (Unity.ScopeResult result, string application_uri) {
44 var app_id = result.metadata.get(METADATA_APP_ID).get_string();
45 Unity.Preview preview = yield build_app_preview (result);
46- preview.add_action (new Unity.PreviewAction (ACTION_OPEN_CLICK + ":" + result.uri, ("Open"), null));
47+ preview.add_action (new Unity.PreviewAction (ACTION_OPEN_CLICK + ":" + application_uri, ("Open"), null));
48
49 if (yield click_if.can_uninstall (app_id)) {
50 preview.add_action (new Unity.PreviewAction (ACTION_UNINSTALL_CLICK, ("Uninstall"), null));
51@@ -192,7 +192,7 @@
52 if (uri_is_click_install(result.uri)) {
53 return yield build_uninstalled_preview (result);
54 } else {
55- return yield build_installed_preview (result);
56+ return yield build_installed_preview (result, result.uri);
57 }
58 }
59
60@@ -236,7 +236,7 @@
61 // application name *must* be in path part of URL as host part
62 // might get lowercased
63 var application_uri = "application:///" + dotdesktop;
64- preview = yield build_installed_preview (result);
65+ preview = yield build_installed_preview (result, application_uri);
66 } else if (action_id.has_prefix(ACTION_OPEN_CLICK)) {
67 var application_uri = action_id.split(":", 2)[1];
68 debug ("Let the dash launch the app: %s", application_uri);
69@@ -386,7 +386,6 @@
70
71 private void add_app (App app, int category)
72 {
73- debug (app.title);
74 var uri = app.uri;
75 var comment = "";
76 var dnd_uri = uri;
77@@ -403,8 +402,8 @@
78 var result = Unity.ScopeResult.create(uri, app.icon_url, category, Unity.ResultType.DEFAULT, mimetype, app.title, comment, dnd_uri, metadata);
79
80 var download_progress = get_download_progress(app.app_id);
81- debug ("download progress source for app %s: %s", app.app_id, download_progress);
82 if (download_progress != null) {
83+ debug ("download in progress for %s: progress source path = %s", app.app_id, download_progress);
84 result.metadata.insert("show_progressbar", new Variant.boolean(true));
85 result.metadata.insert("progressbar_source", new GLib.Variant.string(download_progress));
86 }
87
88=== modified file 'src/test-click-webservice.vala'
89--- src/test-click-webservice.vala 2013-12-19 19:58:49 +0000
90+++ src/test-click-webservice.vala 2013-12-19 23:53:33 +0000
91@@ -17,6 +17,7 @@
92 using Assertions;
93
94 const string FAKE_APP_ID = "FAKE_APP_ID";
95+const string FAKE_DOT_DESKTOP = "FAKE_DOT_DESKTOP";
96 const string FAKE_OBJECT_PATH = "/com/fake/object";
97 const string FAKE_DOWNLOAD_ERROR_MESSAGE = "fake generic download error message";
98 const string FAKE_CREDS_ERROR_MESSAGE = "fake creds error message";
99@@ -121,6 +122,15 @@
100 parser.load_from_data (FAKE_APP_MANIFEST);
101 return parser.get_root().get_array().get_elements();
102 }
103+
104+ public override async string get_dotdesktop (string app_id) throws ClickError {
105+ return FAKE_DOT_DESKTOP;
106+ }
107+
108+ public bool fake_can_uninstall = true;
109+ public override async bool can_uninstall (string app_id) {
110+ return fake_can_uninstall;
111+ }
112 }
113
114 public static void test_click_architecture ()
115@@ -420,6 +430,49 @@
116 assert (run_with_timeout (mainloop, 10000));
117 }
118
119+ public static void test_scope_build_installed_preview_with_uninstall ()
120+ {
121+ do_test_build_installed_preview_uninstall (true);
122+ }
123+
124+ public static void test_scope_build_installed_preview_without_uninstall ()
125+ {
126+ do_test_build_installed_preview_uninstall (false);
127+ }
128+
129+ private static void do_test_build_installed_preview_uninstall (bool can_uninstall)
130+ {
131+ MainLoop mainloop = new MainLoop ();
132+ ClickScope scope = new ClickScope ();
133+ scope.webservice = new FakeClickWebservice ();
134+ scope.click_if = new FakeClickInterface ();
135+ ((FakeClickInterface) scope.click_if).fake_can_uninstall = can_uninstall;
136+
137+ var metadata = new HashTable<string, Variant> (str_hash, str_equal);
138+ metadata.insert(METADATA_APP_ID, new GLib.Variant.string(FAKE_APP_ID));
139+ var fake_result = Unity.ScopeResult.create("", "", 0,
140+ Unity.ResultType.DEFAULT,
141+ "application/x-desktop",
142+ "", "", "", metadata);
143+
144+ string fake_app_uri = "application:///" + FAKE_DOT_DESKTOP;
145+ scope.build_installed_preview.begin(fake_result, fake_app_uri, (obj, res) => {
146+ mainloop.quit ();
147+ try {
148+ var preview = scope.build_installed_preview.end(res);
149+ assert(preview_has_action(preview, "open_click:" + fake_app_uri, "Open"));
150+
151+ bool has_uninstall = preview_has_action(preview, "uninstall_click", "Uninstall");
152+ assert(can_uninstall == has_uninstall);
153+
154+ } catch (GLib.Error e) {
155+ error ("Exception caught building installed preview: %s", e.message);
156+ }
157+ });
158+
159+ assert (run_with_timeout (mainloop, 10000));
160+ }
161+
162 public static Unity.ScopeResult create_fake_result () {
163 uint fake_category = 0;
164 var fake_result_type = Unity.ResultType.DEFAULT;
165@@ -488,6 +541,10 @@
166 Test.add_data_func ("/Unit/ClickChecker/Test_Click_GetDotDesktop", test_click_get_dotdesktop);
167 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Purchasing_Preview",
168 test_scope_build_purchasing_preview);
169+ Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Installed_Preview_With_Uninstall",
170+ test_scope_build_installed_preview_with_uninstall);
171+ Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Installed_Preview_Without_Uninstall",
172+ test_scope_build_installed_preview_without_uninstall);
173 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_InProgress", test_scope_in_progress);
174 return Test.run ();
175 }

Subscribers

People subscribed via source and target branches

to all changes: