Merge lp:~midori/midori/asynAutocompleterTest into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: gue5t gue5t
Approved revision: 6551
Merged at revision: 6600
Proposed branch: lp:~midori/midori/asynAutocompleterTest
Merge into: lp:midori
Diff against target: 101 lines (+41/-43)
1 file modified
tests/completion.vala (+41/-43)
To merge this branch: bzr merge lp:~midori/midori/asynAutocompleterTest
Reviewer Review Type Date Requested Status
gue5t gue5t Approve
Review via email: mp+203432@code.launchpad.net

Commit message

Port autocompleter test to async job

To post a comment you must log in.
Revision history for this message
gue5t gue5t (gue5t) wrote :

This looks good, but could you explain why it's happening? Does it test ordering better if it tests completions asynchronously?

Revision history for this message
Cris Dywan (kalikiana) wrote :

The completions are asynchronous by design so this gets rid of the loop.iteration calls in favour of taking the results when they come.

Revision history for this message
RabbitBot (rabbitbot-a) wrote :

Voting does not meet specified criteria. Required: Approve >= 1. Got: 1 Pending.

Revision history for this message
gue5t gue5t (gue5t) wrote :

That makes sense, it seems like a nice cleanup.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/completion.vala'
2--- tests/completion.vala 2014-01-25 21:04:57 +0000
3+++ tests/completion.vala 2014-03-04 00:25:23 +0000
4@@ -43,48 +43,46 @@
5 }
6 }
7
8-void completion_autocompleter () {
9- var app = new Midori.App ();
10- var autocompleter = new Midori.Autocompleter (app);
11- assert (!autocompleter.can_complete (""));
12- var completion = new TestCompletion ();
13- autocompleter.add (completion);
14- completion.test_can_complete = false;
15- assert (!autocompleter.can_complete (""));
16- completion.test_can_complete = true;
17- assert (autocompleter.can_complete (""));
18-
19- completion.test_suggestions = 0;
20- autocompleter.complete.begin ("");
21- var loop = MainContext.default ();
22- do { loop.iteration (true); } while (loop.pending ());
23- assert (autocompleter.model.iter_n_children (null) == 0);
24-
25- completion.test_suggestions = 1;
26- autocompleter.complete.begin ("");
27- do { loop.iteration (true); } while (loop.pending ());
28- assert (autocompleter.model.iter_n_children (null) == 1);
29-
30- /* Order */
31- completion.test_suggestions = 2;
32- autocompleter.complete.begin ("");
33- do { loop.iteration (true); } while (loop.pending ());
34- assert (autocompleter.model.iter_n_children (null) == 2);
35- Gtk.TreeIter iter_first;
36- autocompleter.model.get_iter_first (out iter_first);
37- string title;
38- autocompleter.model.get (iter_first, Midori.Autocompleter.Columns.MARKUP, out title);
39- if (title != "First")
40- error ("Expected %s but got %s", "First", title);
41-
42- /* Cancellation */
43- autocompleter.complete.begin ("");
44- completion.test_suggestions = 3;
45- autocompleter.complete.begin ("");
46- do { loop.iteration (true); } while (loop.pending ());
47- int n = autocompleter.model.iter_n_children (null);
48- if (n != 3)
49- error ("Expected %d but got %d", 3, n);
50+class CompletionAutocompleter : Midori.Test.Job {
51+ public static void test () { new CompletionAutocompleter ().run_sync (); }
52+ public override async void run (Cancellable cancellable) throws GLib.Error {
53+ var app = new Midori.App ();
54+ var autocompleter = new Midori.Autocompleter (app);
55+ assert (!autocompleter.can_complete (""));
56+ var completion = new TestCompletion ();
57+ autocompleter.add (completion);
58+ completion.test_can_complete = false;
59+ assert (!autocompleter.can_complete (""));
60+ completion.test_can_complete = true;
61+ assert (autocompleter.can_complete (""));
62+
63+ completion.test_suggestions = 0;
64+ yield autocompleter.complete ("");
65+ assert (autocompleter.model.iter_n_children (null) == 0);
66+
67+ completion.test_suggestions = 1;
68+ yield autocompleter.complete ("");
69+ assert (autocompleter.model.iter_n_children (null) == 1);
70+
71+ /* Order */
72+ completion.test_suggestions = 2;
73+ yield autocompleter.complete ("");
74+ assert (autocompleter.model.iter_n_children (null) == 2);
75+ Gtk.TreeIter iter_first;
76+ autocompleter.model.get_iter_first (out iter_first);
77+ string title;
78+ autocompleter.model.get (iter_first, Midori.Autocompleter.Columns.MARKUP, out title);
79+ if (title != "First")
80+ error ("Expected %s but got %s", "First", title);
81+
82+ /* Cancellation */
83+ yield autocompleter.complete ("");
84+ completion.test_suggestions = 3;
85+ yield autocompleter.complete ("");
86+ int n = autocompleter.model.iter_n_children (null);
87+ if (n != 3)
88+ error ("Expected %d but got %d", 3, n);
89+ }
90 }
91
92 class CompletionHistory : Midori.Test.Job {
93@@ -140,7 +138,7 @@
94 Midori.Test.init (ref args);
95 Midori.App.setup (ref args, null);
96 Midori.Paths.init (Midori.RuntimeMode.NORMAL, null);
97- Test.add_func ("/completion/autocompleter", completion_autocompleter);
98+ Test.add_func ("/completion/autocompleter", CompletionAutocompleter.test);
99 Test.add_func ("/completion/history", CompletionHistory.test);
100 Test.add_func ("/completion/location-action", completion_location_action);
101 Test.run ();

Subscribers

People subscribed via source and target branches

to all changes: