Merge lp:~mikemc/unity-scope-click/queued-downloads into lp:unity-scope-click

Proposed by Mike McCracken
Status: Merged
Approved by: Mike McCracken
Approved revision: 90
Merged at revision: 89
Proposed branch: lp:~mikemc/unity-scope-click/queued-downloads
Merge into: lp:unity-scope-click
Diff against target: 130 lines (+69/-9)
2 files modified
src/click-scope.vala (+12/-4)
src/test-click-webservice.vala (+57/-5)
To merge this branch: bzr merge lp:~mikemc/unity-scope-click/queued-downloads
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
dobey (community) Approve
Review via email: mp+198110@code.launchpad.net

Commit message

When opening a preview, check if there's a download in progress

Description of the change

When opening a preview, check if there's a download in progress

To post a comment you must log in.
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Mike McCracken (mikemc) wrote :

Approved with just dobey's review because this is actually alecu's branch, see:
https://code.launchpad.net/~mikemc/unity-scope-click/queued-downloads/+merge/198110

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/click-scope.vala'
2--- src/click-scope.vala 2013-12-06 16:00:49 +0000
3+++ src/click-scope.vala 2013-12-06 18:32:27 +0000
4@@ -154,7 +154,7 @@
5 return preview;
6 }
7
8- async Unity.Preview build_installing_preview (Unity.ScopeResult result, string progress_source) {
9+ protected async virtual Unity.Preview build_installing_preview (Unity.ScopeResult result, string progress_source) {
10 Unity.Preview preview = yield build_app_preview (result);
11
12 // When the progressbar is shown by the preview in the dash no buttons should be shown.
13@@ -191,15 +191,23 @@
14 }
15 }
16
17- async Unity.ActivationResponse? activate_async (Unity.ScopeResult result, Unity.SearchMetadata metadata, string? action_id) {
18+ internal virtual string? get_progress_source (string app_id) {
19+ return get_download_progress(app_id);
20+ }
21+
22+ internal async Unity.ActivationResponse? activate_async (Unity.ScopeResult result, Unity.SearchMetadata metadata, string? action_id) {
23 var app_id = result.metadata.get(METADATA_APP_ID).get_string();
24 Unity.Preview preview = null;
25 string next_url = null;
26
27 try {
28- debug ("action started: %s", action_id);
29+ debug ("action started: %s for app_id: %s", action_id, app_id);
30 if (action_id == null) {
31- if (uri_is_click_install(result.uri)) {
32+ var progress_source = get_progress_source(app_id);
33+ debug ("Progress source: %s", progress_source);
34+ if (progress_source != null) {
35+ preview = yield build_installing_preview (result, progress_source);
36+ } else if (uri_is_click_install(result.uri)) {
37 preview = yield build_uninstalled_preview (result);
38 } else {
39 debug ("Let the dash launch the app: %s", result.uri);
40
41=== modified file 'src/test-click-webservice.vala'
42--- src/test-click-webservice.vala 2013-12-06 16:00:49 +0000
43+++ src/test-click-webservice.vala 2013-12-06 18:32:27 +0000
44@@ -261,7 +261,7 @@
45 Unity.ResultType.DEFAULT,
46 "application/x-desktop",
47 "", "", "", metadata);
48-
49+
50 scope.build_purchasing_preview.begin(fake_result, (obj, res) => {
51 mainloop.quit ();
52 try {
53@@ -272,14 +272,65 @@
54 new Variant.string("FAKE_APP_ID")));
55 assert(preview_has_action(preview, "purchase_succeeded", "*** purchase_succeeded"));
56 assert(preview_has_action(preview, "purchase_failed", "*** purchase_failed"));
57-
58+
59 } catch (GLib.Error e) {
60 error ("Exception caught building purchasing preview: %s", e.message);
61 }
62 });
63-
64- assert (run_with_timeout (mainloop, 10000));
65- }
66+
67+ assert (run_with_timeout (mainloop, 10000));
68+ }
69+
70+ public static Unity.ScopeResult create_fake_result () {
71+ uint fake_category = 0;
72+ var fake_result_type = Unity.ResultType.DEFAULT;
73+ var fake_metadata = new HashTable<string, Variant> (str_hash, str_equal);
74+ fake_metadata.insert(METADATA_APP_ID, new GLib.Variant.string("fake_app_id"));
75+ fake_metadata.insert(METADATA_PRICE, new GLib.Variant.string("0"));
76+ return Unity.ScopeResult.create("fake_uri", "fake_icon_hint", fake_category,
77+ fake_result_type, "fake_mimetype", "fake_title",
78+ "fake_comment", "fake_dnd_uri", fake_metadata);
79+ }
80+
81+ class FakeClickScope : ClickScope {
82+ public bool preview_is_installing = false;
83+ protected async override Unity.Preview build_installing_preview (Unity.ScopeResult result, string progress_source) {
84+ preview_is_installing = true;
85+ var fake_icon = null;
86+ var fake_screenshot = null;
87+ var preview = new Unity.ApplicationPreview ("fake_title", "fake_subtitle", "fake_description", fake_icon, fake_screenshot);
88+ return preview;
89+ }
90+
91+ internal override string? get_progress_source(string app_id) {
92+ if (app_id == "fake_app_id") {
93+ return "fake_progress_source";
94+ }
95+ return null;
96+ }
97+ }
98+
99+ public static void test_scope_in_progress ()
100+ {
101+ MainLoop mainloop = new MainLoop ();
102+ var scope = new FakeClickScope ();
103+ var result = create_fake_result ();
104+ var metadata = new Unity.SearchMetadata();
105+ string action_id = null;
106+
107+ assert (!scope.preview_is_installing);
108+ scope.activate_async.begin(result, metadata, action_id, (obj, res) => {
109+ mainloop.quit ();
110+ try {
111+ var response = scope.activate_async.end (res);
112+ } catch (GLib.Error e) {
113+ error ("Failure in activate_async: %s", e.message);
114+ }
115+ });
116+ assert (run_with_timeout (mainloop, 10000));
117+ assert (scope.preview_is_installing);
118+ }
119+
120
121 public static int main (string[] args)
122 {
123@@ -296,6 +347,7 @@
124 Test.add_data_func ("/Unit/ClickChecker/Test_Click_GetDotDesktop", test_click_get_dotdesktop);
125 Test.add_data_func ("/Unit/ClickChecker/Test_Scope_Build_Purchasing_Preview",
126 test_scope_build_purchasing_preview);
127+ Test.add_data_func ("/Unit/ClickChecker/Test_Scope_InProgress", test_scope_in_progress);
128 return Test.run ();
129 }
130 }

Subscribers

People subscribed via source and target branches

to all changes: